Annotation of rpl/src/gestion_objets.c, revision 1.88

1.1       bertrand    1: /*
                      2: ================================================================================
1.86      bertrand    3:   RPL/2 (R) version 4.1.11
1.77      bertrand    4:   Copyright (C) 1989-2012 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
1.33      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
1.6       bertrand   28:   Routines de gestion du nombre d'occurrences comme grandeur atomique
1.1       bertrand   29: ================================================================================
                     30:   entrées : structure sur l'état du processus et objet à afficher
                     31: --------------------------------------------------------------------------------
                     32:   sorties : chaine de caractères
                     33: --------------------------------------------------------------------------------
                     34:   effets de bord : néant
                     35: ================================================================================
                     36: */
                     37: 
                     38: static inline void
                     39: incrementation_atomique(struct_objet *s_objet)
                     40: {
                     41:    // Le mutex est sur l'objet.
                     42: 
                     43:    (*s_objet).nombre_occurrences++;
                     44: 
                     45:    BUG((*s_objet).nombre_occurrences <= 0,
                     46:            uprintf("Capacity exceeded %ld\n", (*s_objet).nombre_occurrences));
                     47: 
                     48:    return;
                     49: }
                     50: 
                     51: static inline long
                     52: decrementation_atomique(struct_objet *s_objet)
                     53: {
                     54:    // Le mutex est sur l'objet.
                     55: 
                     56:    (*s_objet).nombre_occurrences--;
                     57:    return((*s_objet).nombre_occurrences);
                     58: }
                     59: 
1.43      bertrand   60: void
1.1       bertrand   61: initialisation_objet(struct_objet *s_objet)
                     62: {
                     63:    pthread_mutexattr_t     attributs_mutex;
                     64: 
                     65:    pthread_mutexattr_init(&attributs_mutex);
                     66:    pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
                     67:    pthread_mutex_init(&((*s_objet).mutex), &attributs_mutex);
                     68:    pthread_mutexattr_destroy(&attributs_mutex);
                     69: 
                     70:    (*s_objet).nombre_occurrences = 1;
                     71: 
                     72:    return;
                     73: }
                     74: 
                     75: 
                     76: /*
                     77: ================================================================================
                     78:   Routines d'initialisation et de purge de l'allocateur
                     79: ================================================================================
                     80:   Entrées : structure sur l'état du processus et objet à afficher
                     81: --------------------------------------------------------------------------------
                     82:   Sorties : chaine de caractères
                     83: --------------------------------------------------------------------------------
                     84:   Effets de bord : néant
                     85: ================================================================================
                     86: */
                     87: 
                     88: void
                     89: initialisation_allocateur(struct_processus *s_etat_processus)
                     90: {
                     91:    (*s_etat_processus).estimation_taille_pile_tampon = 0;
                     92:    (*s_etat_processus).taille_pile_tampon = 0;
                     93:    (*s_etat_processus).pile_tampon = NULL;
                     94: 
                     95:    (*s_etat_processus).estimation_taille_pile_systeme_tampon = 0;
                     96:    (*s_etat_processus).taille_pile_systeme_tampon = 0;
                     97:    (*s_etat_processus).pile_systeme_tampon = NULL;
                     98: 
                     99:    (*s_etat_processus).taille_pile_objets = 0;
                    100:    (*s_etat_processus).pile_objets = NULL;
                    101: 
                    102:    (*s_etat_processus).pointeur_adr = 0;
                    103:    (*s_etat_processus).pointeur_bin = 0;
                    104:    (*s_etat_processus).pointeur_cpl = 0;
                    105:    (*s_etat_processus).pointeur_fct = 0;
                    106:    (*s_etat_processus).pointeur_int = 0;
                    107:    (*s_etat_processus).pointeur_mat = 0;
                    108:    (*s_etat_processus).pointeur_nom = 0;
                    109:    (*s_etat_processus).pointeur_rel = 0;
                    110:    (*s_etat_processus).pointeur_tab = 0;
                    111:    (*s_etat_processus).pointeur_vec = 0;
                    112:    (*s_etat_processus).pointeur_maillons = 0;
                    113: 
1.53      bertrand  114:    (*s_etat_processus).pointeur_variables_noeud = 0;
                    115:    (*s_etat_processus).pointeur_variables_feuille = 0;
                    116:    (*s_etat_processus).pointeur_variables_variable = 0;
                    117:    (*s_etat_processus).pointeur_variables_tableau_noeuds = 0;
                    118: 
1.1       bertrand  119:    return;
                    120: }
                    121: 
                    122: 
                    123: void
                    124: liberation_allocateur(struct_processus *s_etat_processus)
                    125: {
                    126:    int                 i;
                    127: 
                    128:    for(i = 0; i < (*s_etat_processus).pointeur_adr;
                    129:            free((*s_etat_processus).objets_adr[i++]));
                    130:    for(i = 0; i < (*s_etat_processus).pointeur_bin;
                    131:            free((*s_etat_processus).objets_bin[i++]));
                    132:    for(i = 0; i < (*s_etat_processus).pointeur_cpl;
                    133:            free((*s_etat_processus).objets_cpl[i++]));
                    134:    for(i = 0; i < (*s_etat_processus).pointeur_fct;
                    135:            free((*s_etat_processus).objets_fct[i++]));
                    136:    for(i = 0; i < (*s_etat_processus).pointeur_int;
                    137:            free((*s_etat_processus).objets_int[i++]));
                    138:    for(i = 0; i < (*s_etat_processus).pointeur_mat;
                    139:            free((*s_etat_processus).objets_mat[i++]));
                    140:    for(i = 0; i < (*s_etat_processus).pointeur_nom;
                    141:            free((*s_etat_processus).objets_nom[i++]));
                    142:    for(i = 0; i < (*s_etat_processus).pointeur_rel;
                    143:            free((*s_etat_processus).objets_rel[i++]));
                    144:    for(i = 0; i < (*s_etat_processus).pointeur_tab;
                    145:            free((*s_etat_processus).objets_tab[i++]));
                    146:    for(i = 0; i < (*s_etat_processus).pointeur_vec;
                    147:            free((*s_etat_processus).objets_vec[i++]));
                    148:    for(i = 0; i < (*s_etat_processus).pointeur_maillons;
                    149:            free((*s_etat_processus).maillons[i++]));
                    150: 
1.53      bertrand  151:    for(i = 0; i < (*s_etat_processus).pointeur_variables_noeud;
                    152:            free((*s_etat_processus).variables_noeud[i++]));
                    153:    for(i = 0; i < (*s_etat_processus).pointeur_variables_feuille;
                    154:            free((*s_etat_processus).variables_feuille[i++]));
                    155:    for(i = 0; i < (*s_etat_processus).pointeur_variables_variable;
                    156:            free((*s_etat_processus).variables_variable[i++]));
                    157:    for(i = 0; i < (*s_etat_processus).pointeur_variables_tableau_noeuds;
                    158:            free((*s_etat_processus).variables_tableau_noeuds[i++]));
                    159: 
1.1       bertrand  160:    {
                    161:        struct_liste_chainee        *l_element_courant;
                    162:        struct_liste_chainee        *l_element_suivant;
                    163: 
                    164:        l_element_courant = (*s_etat_processus).pile_tampon;
                    165: 
                    166:        while(l_element_courant != NULL)
                    167:        {
                    168:            l_element_suivant = (*l_element_courant).suivant;
                    169:            liberation(s_etat_processus, (*l_element_courant).donnee);
                    170:            free(l_element_courant);
                    171:            l_element_courant = l_element_suivant;
                    172:        }
                    173:    }
                    174: 
                    175:    {
                    176:        struct_liste_pile_systeme       *l_element_courant;
                    177:        struct_liste_pile_systeme       *l_element_suivant;
                    178: 
                    179:        l_element_courant = (*s_etat_processus).pile_systeme_tampon;
                    180: 
                    181:        while(l_element_courant != NULL)
                    182:        {
                    183:            l_element_suivant = (*l_element_courant).suivant;
                    184:            free(l_element_courant);
                    185:            l_element_courant = l_element_suivant;
                    186:        }
                    187:    }
                    188: 
                    189:    {
                    190:        struct_objet                *l_element_courant;
                    191:        struct_objet                *l_element_suivant;
                    192: 
                    193:        l_element_courant = (*s_etat_processus).pile_objets;
                    194: 
                    195:        while(l_element_courant != NULL)
                    196:        {
                    197:            l_element_suivant = (*l_element_courant).objet;
                    198: 
                    199:            if (pthread_mutex_destroy(&((*l_element_courant).mutex)) != 0)
                    200:            {
                    201:                (*s_etat_processus).erreur_systeme = d_es_processus;
                    202:                BUG(1, printf("Mutex error\n"));
                    203:                return;
                    204:            }
                    205: 
                    206:            free(l_element_courant);
                    207:            l_element_courant = l_element_suivant;
                    208:        }
                    209:    }
                    210: 
                    211:    return;
                    212: }
                    213: 
                    214: 
                    215: /*
                    216: ================================================================================
                    217:   Routine d'allocation d'un maillon d'un objet (liste, expression...)
                    218: ================================================================================
                    219:   Entrées : structure sur l'état du processus et objet à afficher
                    220: --------------------------------------------------------------------------------
                    221:   Sorties : chaine de caractères
                    222: --------------------------------------------------------------------------------
                    223:   Effets de bord : néant
                    224: ================================================================================
                    225: */
                    226: 
                    227: void *
                    228: allocation_maillon(struct_processus *s_etat_processus)
                    229: {
                    230:    struct_liste_chainee        *s_maillon;
                    231: 
                    232:    if ((*s_etat_processus).pointeur_maillons > 0)
                    233:    {
                    234:        s_maillon = (*s_etat_processus).maillons
                    235:                [--(*s_etat_processus).pointeur_maillons];
                    236:    }
                    237:    else
                    238:    {
                    239:        if ((s_maillon = malloc(sizeof(struct_liste_chainee))) == NULL)
                    240:        {
                    241:            return(NULL);
                    242:        }
                    243:    }
                    244: 
                    245:    return(s_maillon);
                    246: }
                    247: 
                    248: 
                    249: /*
                    250: ================================================================================
1.53      bertrand  251:   Routine de libération d'un maillon d'un objet (liste, expression...)
1.1       bertrand  252: ================================================================================
                    253:   Entrées : structure sur l'état du processus et objet à afficher
                    254: --------------------------------------------------------------------------------
                    255:   Sorties : chaine de caractères
                    256: --------------------------------------------------------------------------------
                    257:   Effets de bord : néant
                    258: ================================================================================
                    259: */
                    260: 
                    261: void
                    262: liberation_maillon(struct_processus *s_etat_processus,
                    263:        struct_liste_chainee *maillon)
                    264: {
                    265:    if ((*s_etat_processus).pointeur_maillons < TAILLE_CACHE)
                    266:    {
                    267:        (*s_etat_processus).maillons
                    268:                [(*s_etat_processus).pointeur_maillons++] = maillon;
                    269:    }
                    270:    else
                    271:    {
                    272:        free(maillon);
                    273:    }
                    274: 
                    275:    return;
                    276: }
                    277: 
                    278: 
                    279: /*
                    280: ================================================================================
                    281:   Routine d'allocation d'une structure *s_objet
                    282: ================================================================================
1.28      bertrand  283:   Entrées : structure sur l'état du processus et objet à allouer
1.1       bertrand  284: --------------------------------------------------------------------------------
                    285:   Sorties : chaine de caractères
                    286: --------------------------------------------------------------------------------
                    287:   Effets de bord : néant
                    288: ================================================================================
                    289: */
                    290: 
1.55      bertrand  291: struct_objet *
1.1       bertrand  292: allocation(struct_processus *s_etat_processus, enum t_type type)
                    293: {
                    294:    struct_objet            *s_objet;
                    295: 
1.28      bertrand  296:    if (pthread_mutex_lock(&((*s_etat_processus).mutex_allocation)) != 0)
                    297:    {
                    298:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    299:        return(NULL);
                    300:    }
                    301: 
1.1       bertrand  302:    if ((*s_etat_processus).pile_objets == NULL)
                    303:    {
1.28      bertrand  304:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0)
                    305:        {
                    306:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    307:            return(NULL);
                    308:        }
                    309: 
1.1       bertrand  310:        // Il n'existe aucune structure struct_objet disponible dans le cache.
                    311: 
                    312:        if ((s_objet = malloc(sizeof(struct_objet))) == NULL)
                    313:        {
                    314:            return(NULL);
                    315:        }
                    316: 
                    317:        initialisation_objet(s_objet);
                    318:    }
                    319:    else
                    320:    {
                    321:        // Récupération d'une structure dans le cache.
                    322: 
                    323:        s_objet = (*s_etat_processus).pile_objets;
                    324:        (*s_etat_processus).pile_objets = (*s_objet).objet;
                    325:        (*s_etat_processus).taille_pile_objets--;
                    326: 
                    327:        (*s_objet).nombre_occurrences = 1;
1.28      bertrand  328: 
                    329:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0)
                    330:        {
                    331:            (*s_etat_processus).erreur_systeme = d_es_processus;
                    332:            return(NULL);
                    333:        }
1.1       bertrand  334:    }
                    335: 
                    336:    (*s_objet).type = type;
                    337: 
                    338:    switch(type)
                    339:    {
                    340:        case ADR :
                    341:        {
                    342:            if ((*s_etat_processus).pointeur_adr > 0)
                    343:            {
                    344:                (*s_objet).objet = (*s_etat_processus).objets_adr
                    345:                        [--(*s_etat_processus).pointeur_adr];
                    346:            }
                    347:            else
                    348:            {
                    349:                if (((*s_objet).objet = malloc(sizeof(unsigned long))) == NULL)
                    350:                {
                    351:                    free(s_objet);
                    352:                    return(NULL);
                    353:                }
                    354:            }
                    355: 
                    356:            break;
                    357:        }
                    358: 
                    359:        case ALG :
                    360:        {
                    361:            (*s_objet).objet = NULL;
                    362:            break;
                    363:        }
                    364: 
                    365:        case BIN :
                    366:        {
                    367:            if ((*s_etat_processus).pointeur_bin > 0)
                    368:            {
                    369:                (*s_objet).objet = (*s_etat_processus).objets_bin
                    370:                        [--(*s_etat_processus).pointeur_bin];
                    371:            }
                    372:            else
                    373:            {
                    374:                if (((*s_objet).objet = malloc(sizeof(logical8))) == NULL)
                    375:                {
                    376:                    free(s_objet);
                    377:                    return(NULL);
                    378:                }
                    379:            }
                    380: 
                    381:            break;
                    382:        }
                    383: 
                    384:        case CHN :
                    385:        {
                    386:            (*s_objet).objet = NULL;
                    387:            break;
                    388:        }
                    389: 
                    390:        case CPL :
                    391:        {
                    392:            if ((*s_etat_processus).pointeur_cpl > 0)
                    393:            {
                    394:                (*s_objet).objet = (*s_etat_processus).objets_cpl
                    395:                        [--(*s_etat_processus).pointeur_cpl];
                    396:            }
                    397:            else
                    398:            {
                    399:                if (((*s_objet).objet = malloc(sizeof(struct_complexe16)))
                    400:                        == NULL)
                    401:                {
                    402:                    free(s_objet);
                    403:                    return(NULL);
                    404:                }
                    405:            }
                    406: 
                    407:            break;
                    408:        }
                    409: 
                    410:        case FCH :
                    411:        {
                    412:            if (((*s_objet).objet = malloc(sizeof(struct_fichier))) == NULL)
                    413:            {
                    414:                free(s_objet);
                    415:                return(NULL);
                    416:            }
                    417: 
                    418:            break;
                    419:        }
                    420: 
                    421:        case FCT :
                    422:        {
                    423:            if ((*s_etat_processus).pointeur_fct > 0)
                    424:            {
                    425:                (*s_objet).objet = (*s_etat_processus).objets_fct
                    426:                        [--(*s_etat_processus).pointeur_fct];
                    427:            }
                    428:            else
                    429:            {
                    430:                if (((*s_objet).objet = malloc(sizeof(struct_fonction)))
                    431:                        == NULL)
                    432:                {
                    433:                    free(s_objet);
                    434:                    return(NULL);
                    435:                }
                    436:            }
                    437: 
1.5       bertrand  438:            (*((struct_fonction *) (*s_objet).objet)).fonction = NULL;
1.1       bertrand  439:            (*((struct_fonction *) (*s_objet).objet)).prediction_saut = NULL;
1.5       bertrand  440:            (*((struct_fonction *) (*s_objet).objet)).prediction_execution
                    441:                    = d_faux;
1.1       bertrand  442:            break;
                    443:        }
                    444: 
                    445:        case INT :
                    446:        {
                    447:            if ((*s_etat_processus).pointeur_int > 0)
                    448:            {
                    449:                (*s_objet).objet = (*s_etat_processus).objets_int
                    450:                        [--(*s_etat_processus).pointeur_int];
                    451:            }
                    452:            else
                    453:            {
                    454:                if (((*s_objet).objet = malloc(sizeof(integer8))) == NULL)
                    455:                {
                    456:                    free(s_objet);
                    457:                    return(NULL);
                    458:                }
                    459:            }
                    460: 
                    461:            break;
                    462:        }
                    463: 
                    464:        case LST :
                    465:        {
                    466:            (*s_objet).objet = NULL;
                    467:            break;
                    468:        }
                    469: 
                    470:        case MCX :
                    471:        {
                    472:            if ((*s_etat_processus).pointeur_mat > 0)
                    473:            {
                    474:                (*s_objet).objet = (*s_etat_processus).objets_mat
                    475:                        [--(*s_etat_processus).pointeur_mat];
                    476:            }
                    477:            else
                    478:            {
                    479:                if (((*s_objet).objet = malloc(sizeof(struct_matrice))) == NULL)
                    480:                {
                    481:                    free(s_objet);
                    482:                    return(NULL);
                    483:                }
                    484:            }
                    485: 
                    486:            (*((struct_matrice *) (*s_objet).objet)).type = 'C';
                    487:            (*((struct_matrice *) (*s_objet).objet)).nombre_lignes = 0;
                    488:            (*((struct_matrice *) (*s_objet).objet)).nombre_colonnes = 0;
                    489:            (*((struct_matrice *) (*s_objet).objet)).tableau = NULL;
                    490:            break;
                    491:        }
                    492: 
                    493:        case MIN :
                    494:        {
                    495:            if ((*s_etat_processus).pointeur_mat > 0)
                    496:            {
                    497:                (*s_objet).objet = (*s_etat_processus).objets_mat
                    498:                        [--(*s_etat_processus).pointeur_mat];
                    499:            }
                    500:            else
                    501:            {
                    502:                if (((*s_objet).objet = malloc(sizeof(struct_matrice))) == NULL)
                    503:                {
                    504:                    free(s_objet);
                    505:                    return(NULL);
                    506:                }
                    507:            }
                    508: 
                    509:            (*((struct_matrice *) (*s_objet).objet)).type = 'I';
                    510:            (*((struct_matrice *) (*s_objet).objet)).nombre_lignes = 0;
                    511:            (*((struct_matrice *) (*s_objet).objet)).nombre_colonnes = 0;
                    512:            (*((struct_matrice *) (*s_objet).objet)).tableau = NULL;
                    513:            break;
                    514:        }
                    515: 
                    516:        case MRL :
                    517:        {
                    518:            if ((*s_etat_processus).pointeur_mat > 0)
                    519:            {
                    520:                (*s_objet).objet = (*s_etat_processus).objets_mat
                    521:                        [--(*s_etat_processus).pointeur_mat];
                    522:            }
                    523:            else
                    524:            {
                    525:                if (((*s_objet).objet = malloc(sizeof(struct_matrice))) == NULL)
                    526:                {
                    527:                    free(s_objet);
                    528:                    return(NULL);
                    529:                }
                    530:            }
                    531: 
                    532:            (*((struct_matrice *) (*s_objet).objet)).type = 'R';
                    533:            (*((struct_matrice *) (*s_objet).objet)).nombre_lignes = 0;
                    534:            (*((struct_matrice *) (*s_objet).objet)).nombre_colonnes = 0;
                    535:            (*((struct_matrice *) (*s_objet).objet)).tableau = NULL;
                    536:            break;
                    537:        }
                    538: 
                    539:        case MTX :
                    540:        {
                    541:            if (((*s_objet).objet = malloc(sizeof(struct_mutex))) == NULL)
                    542:            {
                    543:                free(s_objet);
                    544:                return(NULL);
                    545:            }
                    546: 
1.76      bertrand  547:            (*((struct_mutex *) (*s_objet).objet)).tid = pthread_self();
1.1       bertrand  548:            break;
                    549:        }
                    550: 
                    551:        case NOM :
                    552:        {
                    553:            if ((*s_etat_processus).pointeur_nom > 0)
                    554:            {
                    555:                (*s_objet).objet = (*s_etat_processus).objets_nom
                    556:                        [--(*s_etat_processus).pointeur_nom];
                    557:            }
                    558:            else
                    559:            {
                    560:                if (((*s_objet).objet = malloc(sizeof(struct_nom))) == NULL)
                    561:                {
                    562:                    free(s_objet);
                    563:                    return(NULL);
                    564:                }
                    565:            }
                    566: 
                    567:            break;
                    568:        }
                    569: 
                    570:        case NON :
                    571:        {
                    572:            (*s_objet).objet = NULL;
                    573:            break;
                    574:        }
                    575: 
                    576:        case PRC :
                    577:        {
                    578:            if (((*s_objet).objet = malloc(sizeof(struct_processus_fils)))
                    579:                    == NULL)
                    580:            {
                    581:                free(s_objet);
                    582:                return(NULL);
                    583:            }
                    584: 
                    585:            break;
                    586:        }
                    587: 
                    588:        case REL :
                    589:        {
                    590:            if ((*s_etat_processus).pointeur_rel > 0)
                    591:            {
                    592:                (*s_objet).objet = (*s_etat_processus).objets_rel
                    593:                        [--(*s_etat_processus).pointeur_rel];
                    594:            }
                    595:            else
                    596:            {
                    597:                if (((*s_objet).objet = malloc(sizeof(real8))) == NULL)
                    598:                {
                    599:                    free(s_objet);
                    600:                    return(NULL);
                    601:                }
                    602:            }
                    603: 
                    604:            break;
                    605:        }
                    606: 
                    607:        case RPN :
                    608:        {
                    609:            (*s_objet).objet = NULL;
                    610:            break;
                    611:        }
                    612: 
                    613:        case SCK :
                    614:        {
                    615:            if (((*s_objet).objet = malloc(sizeof(struct_socket))) == NULL)
                    616:            {
                    617:                free(s_objet);
                    618:                return(NULL);
                    619:            }
                    620: 
                    621:            break;
                    622:        }
                    623: 
                    624:        case SLB :
                    625:        {
                    626:            if (((*s_objet).objet = malloc(sizeof(struct_bibliotheque)))
                    627:                    == NULL)
                    628:            {
                    629:                free(s_objet);
                    630:                return(NULL);
                    631:            }
                    632: 
                    633:            break;
                    634:        }
                    635: 
                    636:        case SPH :
                    637:        {
                    638:            if (((*s_objet).objet = malloc(sizeof(struct_semaphore))) == NULL)
                    639:            {
                    640:                free(s_objet);
                    641:                return(NULL);
                    642:            }
                    643: 
                    644:            break;
                    645:        }
                    646: 
                    647:        case SQL :
                    648:        {
                    649:            if (((*s_objet).objet = malloc(sizeof(struct_connecteur_sql)))
                    650:                    == NULL)
                    651:            {
                    652:                free(s_objet);
                    653:                return(NULL);
                    654:            }
                    655: 
                    656:            break;
                    657:        }
                    658: 
                    659:        case TBL :
                    660:        {
                    661:            if ((*s_etat_processus).pointeur_tab > 0)
                    662:            {
                    663:                (*s_objet).objet = (*s_etat_processus).objets_tab
                    664:                        [--(*s_etat_processus).pointeur_tab];
                    665:            }
                    666:            else
                    667:            {
                    668:                if (((*s_objet).objet = malloc(sizeof(struct_tableau))) == NULL)
                    669:                {
                    670:                    free(s_objet);
                    671:                    return(NULL);
                    672:                }
                    673:            }
                    674: 
                    675:            (*((struct_tableau *) (*s_objet).objet)).nombre_elements = 0;
                    676:            (*((struct_tableau *) (*s_objet).objet)).elements = NULL;
                    677:            break;
                    678:        }
                    679: 
                    680:        case VCX :
                    681:        {
                    682:            if ((*s_etat_processus).pointeur_vec > 0)
                    683:            {
                    684:                (*s_objet).objet = (*s_etat_processus).objets_vec
                    685:                        [--(*s_etat_processus).pointeur_vec];
                    686:            }
                    687:            else
                    688:            {
                    689:                if (((*s_objet).objet = malloc(sizeof(struct_vecteur))) == NULL)
                    690:                {
                    691:                    free(s_objet);
                    692:                    return(NULL);
                    693:                }
                    694:            }
                    695: 
                    696:            (*((struct_vecteur *) (*s_objet).objet)).type = 'C';
                    697:            (*((struct_vecteur *) (*s_objet).objet)).taille = 0;
                    698:            (*((struct_vecteur *) (*s_objet).objet)).tableau = NULL;
                    699:            break;
                    700:        }
                    701: 
                    702:        case VIN :
                    703:        {
                    704:            if ((*s_etat_processus).pointeur_vec > 0)
                    705:            {
                    706:                (*s_objet).objet = (*s_etat_processus).objets_vec
                    707:                        [--(*s_etat_processus).pointeur_vec];
                    708:            }
                    709:            else
                    710:            {
                    711:                if (((*s_objet).objet = malloc(sizeof(struct_vecteur))) == NULL)
                    712:                {
                    713:                    free(s_objet);
                    714:                    return(NULL);
                    715:                }
                    716:            }
                    717: 
                    718:            (*((struct_vecteur *) (*s_objet).objet)).type = 'I';
                    719:            (*((struct_vecteur *) (*s_objet).objet)).taille = 0;
                    720:            (*((struct_vecteur *) (*s_objet).objet)).tableau = NULL;
                    721:            break;
                    722:        }
                    723: 
                    724:        case VRL :
                    725:        {
                    726:            if ((*s_etat_processus).pointeur_vec > 0)
                    727:            {
                    728:                (*s_objet).objet = (*s_etat_processus).objets_vec
                    729:                        [--(*s_etat_processus).pointeur_vec];
                    730:            }
                    731:            else
                    732:            {
                    733:                if (((*s_objet).objet = malloc(sizeof(struct_vecteur))) == NULL)
                    734:                {
                    735:                    free(s_objet);
                    736:                    return(NULL);
                    737:                }
                    738:            }
                    739: 
                    740:            (*((struct_vecteur *) (*s_objet).objet)).type = 'R';
                    741:            (*((struct_vecteur *) (*s_objet).objet)).taille = 0;
                    742:            (*((struct_vecteur *) (*s_objet).objet)).tableau = NULL;
                    743:            break;
                    744:        }
                    745: 
                    746:        default :
                    747:        {
                    748:            free(s_objet);
                    749:            BUG(1, printf("Allocation failure (type %d)\n", type));
                    750: 
                    751:            return(NULL);
                    752:        }
                    753:    }
                    754: 
                    755:    return(s_objet);
                    756: }
                    757: 
                    758: 
                    759: /*
                    760: ================================================================================
                    761:   Routine de libération d'une structure *s_objet
                    762: ================================================================================
                    763:   Entrées : structure sur l'état du processus et objet à afficher
                    764: --------------------------------------------------------------------------------
                    765:   Sorties : chaine de caractères
                    766: --------------------------------------------------------------------------------
                    767:   Effets de bord : néant
                    768: ================================================================================
                    769: */
                    770: 
                    771: void
                    772: liberation(struct_processus *s_etat_processus, struct_objet *s_objet)
                    773: {
                    774:    logical1                            drapeau;
                    775: 
                    776:    struct_liste_chainee                *l_element_courant;
                    777:    struct_liste_chainee                *l_element_suivant;
                    778: 
                    779:    unsigned long                       i;
                    780: 
                    781:    if (s_objet == NULL)
                    782:    {
                    783:        return;
                    784:    }
                    785: 
                    786:    if (pthread_mutex_lock(&((*s_objet).mutex)) != 0)
                    787:    {
                    788:        (*s_etat_processus).erreur_systeme = d_es_processus;
                    789:        return;
                    790:    }
                    791: 
                    792: #define return \
                    793:    if (pthread_mutex_unlock(&((*s_objet).mutex)) != 0) \
                    794:    { (*s_etat_processus).erreur_systeme = d_es_processus; return; } \
                    795:    return
                    796: 
                    797:    BUG((*s_objet).nombre_occurrences <= 0,
                    798:            pthread_mutex_unlock(&((*s_objet).mutex)),
                    799:            printf("(*s_objet).nombre_occurrences=%ld\n",
                    800:            (*s_objet).nombre_occurrences));
                    801: 
                    802:    switch((*s_objet).type)
                    803:    {
                    804:        case ADR :
                    805:        {
                    806:            if (decrementation_atomique(s_objet) > 0)
                    807:            {
                    808:                return;
                    809:            }
                    810: 
                    811:            if ((*s_etat_processus).pointeur_adr < TAILLE_CACHE)
                    812:            {
                    813:                (*s_etat_processus).objets_adr
                    814:                        [(*s_etat_processus).pointeur_adr++] = (*s_objet).objet;
                    815:            }
                    816:            else
                    817:            {
                    818:                free((unsigned long *) ((*s_objet).objet));
                    819:            }
                    820: 
                    821:            break;
                    822:        }
                    823: 
                    824:        case ALG :
                    825:        {
                    826:            l_element_courant = (struct_liste_chainee *) ((*s_objet).objet);
                    827: 
                    828:            if (decrementation_atomique(s_objet) > 0)
                    829:            { // Il reste un pointeur sur l'objet.
                    830:                while(l_element_courant != NULL)
                    831:                {
                    832:                    BUG((*(*l_element_courant).donnee).nombre_occurrences <= 1,
                    833:                            pthread_mutex_unlock(&((*s_objet).mutex)),
                    834:                            printf("(*(*l_element_courant).donnee)"
                    835:                            ".nombre_occurrences=%ld\n",
                    836:                            (*(*l_element_courant).donnee).nombre_occurrences));
                    837: 
                    838:                    liberation(s_etat_processus, (*l_element_courant).donnee);
                    839:                    l_element_courant = (*l_element_courant).suivant;
                    840:                }
                    841: 
                    842:                return;
                    843:            }
                    844:            else
                    845:            { // Il ne reste plus aucun pointeur sur l'objet.
                    846:                while(l_element_courant != NULL)
                    847:                {
                    848:                    l_element_suivant = (*l_element_courant).suivant;
                    849:                    liberation(s_etat_processus, (*l_element_courant).donnee);
                    850:                    liberation_maillon(s_etat_processus, l_element_courant);
                    851:                    l_element_courant = l_element_suivant;
                    852:                }
                    853:            }
                    854: 
                    855:            break;
                    856:        }
                    857: 
                    858:        case BIN :
                    859:        {
                    860:            if (decrementation_atomique(s_objet) > 0)
                    861:            {
                    862:                return;
                    863:            }
                    864: 
                    865:            if ((*s_etat_processus).pointeur_bin < TAILLE_CACHE)
                    866:            {
                    867:                (*s_etat_processus).objets_bin
                    868:                        [(*s_etat_processus).pointeur_bin++] = (*s_objet).objet;
                    869:            }
                    870:            else
                    871:            {
                    872:                free((logical8 *) ((*s_objet).objet));
                    873:            }
                    874: 
                    875:            break;
                    876:        }
                    877: 
                    878:        case CHN :
                    879:        {
                    880:            if (decrementation_atomique(s_objet) > 0)
                    881:            {
                    882:                return;
                    883:            }
                    884: 
                    885:            free((unsigned char *) ((*s_objet).objet));
                    886:            break;
                    887:        }
                    888: 
                    889:        case CPL :
                    890:        {
                    891:            if (decrementation_atomique(s_objet) > 0)
                    892:            {
                    893:                return;
                    894:            }
                    895: 
                    896:            if ((*s_etat_processus).pointeur_cpl < TAILLE_CACHE)
                    897:            {
                    898:                (*s_etat_processus).objets_cpl
                    899:                        [(*s_etat_processus).pointeur_cpl++] = (*s_objet).objet;
                    900:            }
                    901:            else
                    902:            {
                    903:                free((struct_complexe16 *) ((*s_objet).objet));
                    904:            }
                    905: 
                    906:            break;
                    907:        }
                    908: 
                    909:        case FCH :
                    910:        {
                    911:            if (decrementation_atomique(s_objet) > 0)
                    912:            {
1.18      bertrand  913:                BUG((*(*((struct_fichier *) (*s_objet).objet)).format)
                    914:                        .nombre_occurrences <= 1,
                    915:                        pthread_mutex_unlock(&((*s_objet).mutex)),
                    916:                        printf("(*(*((struct_fichier *) (*s_objet).objet))"
                    917:                        ".format).nombre_occurrences=%ld\n",
                    918:                        (*(*((struct_fichier *) (*s_objet).objet)).format)
                    919:                        .nombre_occurrences));
                    920: 
                    921:                liberation(s_etat_processus,
                    922:                        (*((struct_fichier *) (*s_objet).objet)).format);
1.1       bertrand  923:                return;
                    924:            }
                    925: 
                    926:            liberation(s_etat_processus,
                    927:                    (*((struct_fichier *) (*s_objet).objet)).format);
                    928:            free((unsigned char *) (*((struct_fichier *)
                    929:                    (*s_objet).objet)).nom);
                    930:            free((struct_fichier *) ((*s_objet).objet));
                    931:            break;
                    932:        }
                    933: 
                    934:        case FCT :
                    935:        {
                    936:            if (decrementation_atomique(s_objet) > 0)
                    937:            {
                    938:                return;
                    939:            }
                    940: 
                    941:            free((unsigned char *) (*((struct_fonction *)
                    942:                    (*s_objet).objet)).nom_fonction);
                    943: 
                    944:            if ((*s_etat_processus).pointeur_fct < TAILLE_CACHE)
                    945:            {
                    946:                (*s_etat_processus).objets_fct
                    947:                        [(*s_etat_processus).pointeur_fct++] = (*s_objet).objet;
                    948:            }
                    949:            else
                    950:            {
                    951:                free((struct_fonction *) (*s_objet).objet);
                    952:            }
                    953: 
                    954:            break;
                    955:        }
                    956: 
                    957:        case INT :
                    958:        {
                    959:            if (decrementation_atomique(s_objet) > 0)
                    960:            {
                    961:                return;
                    962:            }
                    963: 
                    964:            if ((*s_etat_processus).pointeur_int < TAILLE_CACHE)
                    965:            {
                    966:                (*s_etat_processus).objets_int
                    967:                        [(*s_etat_processus).pointeur_int++] = (*s_objet).objet;
                    968:            }
                    969:            else
                    970:            {
                    971:                free((integer8 *) ((*s_objet).objet));
                    972:            }
                    973: 
                    974:            break;
                    975:        }
                    976: 
                    977:        case LST :
                    978:        {
                    979:            l_element_courant = (struct_liste_chainee *) ((*s_objet).objet);
                    980: 
                    981:            if (decrementation_atomique(s_objet) > 0)
                    982:            { // Il reste un pointeur sur l'objet.
                    983:                while(l_element_courant != NULL)
                    984:                {
                    985:                    BUG((*(*l_element_courant).donnee).nombre_occurrences <= 1,
                    986:                            pthread_mutex_unlock(&((*s_objet).mutex)),
                    987:                            printf("(*(*l_element_courant).donnee)"
                    988:                            ".nombre_occurrences=%ld\n",
                    989:                            (*(*l_element_courant).donnee).nombre_occurrences));
                    990: 
                    991:                    liberation(s_etat_processus, (*l_element_courant).donnee);
                    992:                    l_element_courant = (*l_element_courant).suivant;
                    993:                }
                    994: 
                    995:                return;
                    996:            }
                    997:            else
                    998:            { // Il ne reste plus aucun pointeur sur l'objet.
                    999:                while(l_element_courant != NULL)
                   1000:                {
                   1001:                    l_element_suivant = (*l_element_courant).suivant;
                   1002:                    liberation(s_etat_processus, (*l_element_courant).donnee);
                   1003:                    liberation_maillon(s_etat_processus, l_element_courant);
                   1004:                    l_element_courant = l_element_suivant;
                   1005:                }
                   1006:            }
                   1007: 
                   1008:            break;
                   1009:        }
                   1010: 
                   1011:        case MIN :
                   1012:        {
                   1013:            if (decrementation_atomique(s_objet) > 0)
                   1014:            {
                   1015:                return;
                   1016:            }
                   1017: 
                   1018:            for(i = 0; i < (*((struct_matrice *)
                   1019:                    ((*s_objet).objet))).nombre_lignes; i++)
                   1020:            {
                   1021:                free(((integer8 **) (*((struct_matrice *)
                   1022:                        (*s_objet).objet)).tableau)[i]);
                   1023:            }
                   1024: 
                   1025:            free((integer8 **) (*((struct_matrice *)
                   1026:                    (*s_objet).objet)).tableau);
                   1027: 
                   1028:            if ((*s_etat_processus).pointeur_mat < TAILLE_CACHE)
                   1029:            {
                   1030:                (*s_etat_processus).objets_mat
                   1031:                        [(*s_etat_processus).pointeur_mat++] = (*s_objet).objet;
                   1032:            }
                   1033:            else
                   1034:            {
                   1035:                free((struct_matrice *) (*s_objet).objet);
                   1036:            }
                   1037: 
                   1038:            break;
                   1039:        }
                   1040: 
                   1041:        case MCX :
                   1042:        {
                   1043:            if (decrementation_atomique(s_objet) > 0)
                   1044:            {
                   1045:                return;
                   1046:            }
                   1047: 
                   1048:            for(i = 0; i < (*((struct_matrice *)
                   1049:                    ((*s_objet).objet))).nombre_lignes; i++)
                   1050:            {
                   1051:                free(((struct_complexe16 **) (*((struct_matrice *)
                   1052:                        (*s_objet).objet)).tableau)[i]);
                   1053:            }
                   1054: 
                   1055:            free((struct_complexe16 **) (*((struct_matrice *)
                   1056:                    (*s_objet).objet)).tableau);
                   1057: 
                   1058:            if ((*s_etat_processus).pointeur_mat < TAILLE_CACHE)
                   1059:            {
                   1060:                (*s_etat_processus).objets_mat
                   1061:                        [(*s_etat_processus).pointeur_mat++] = (*s_objet).objet;
                   1062:            }
                   1063:            else
                   1064:            {
                   1065:                free((struct_matrice *) (*s_objet).objet);
                   1066:            }
                   1067: 
                   1068:            break;
                   1069:        }
                   1070: 
                   1071:        case MRL :
                   1072:        {
                   1073:            if (decrementation_atomique(s_objet) > 0)
                   1074:            {
                   1075:                return;
                   1076:            }
                   1077: 
                   1078:            for(i = 0; i < (*((struct_matrice *)
                   1079:                    ((*s_objet).objet))).nombre_lignes; i++)
                   1080:            {
                   1081:                free(((real8 **) (*((struct_matrice *)
                   1082:                        (*s_objet).objet)).tableau)[i]);
                   1083:            }
                   1084: 
                   1085:            free((real8 **) (*((struct_matrice *) (*s_objet).objet)).tableau);
                   1086: 
                   1087:            if ((*s_etat_processus).pointeur_mat < TAILLE_CACHE)
                   1088:            {
                   1089:                (*s_etat_processus).objets_mat
                   1090:                        [(*s_etat_processus).pointeur_mat++] = (*s_objet).objet;
                   1091:            }
                   1092:            else
                   1093:            {
                   1094:                free((struct_matrice *) (*s_objet).objet);
                   1095:            }
                   1096: 
                   1097:            break;
                   1098:        }
                   1099: 
                   1100:        case MTX :
                   1101:        {
                   1102:            if (decrementation_atomique(s_objet) > 0)
                   1103:            {
                   1104:                return;
                   1105:            }
                   1106: 
1.76      bertrand 1107:            if (pthread_mutex_trylock(&((*((struct_mutex *)
                   1108:                    (*s_objet).objet)).mutex)) == 0)
                   1109:            {
                   1110:                // On a pu verrouiller le mutex. Il faut donc spécifier le tid.
                   1111:                (*((struct_mutex *) (*s_objet).objet)).tid = pthread_self();
                   1112:            }
                   1113: 
                   1114:            if (pthread_equal(pthread_self(),
                   1115:                    (*((struct_mutex *) (*s_objet).objet)).tid) != 0)
                   1116:            {
                   1117:                pthread_mutex_unlock(&((*((struct_mutex *)
                   1118:                        (*s_objet).objet)).mutex));
                   1119:            }
                   1120:            else
                   1121:            {
                   1122:                (*s_etat_processus).erreur_systeme =
                   1123:                        d_es_mutex_acquis_autre_thread;
                   1124:                return;
                   1125:            }
                   1126: 
                   1127:            pthread_mutex_destroy(&((*((struct_mutex *)
                   1128:                    (*s_objet).objet)).mutex));
1.1       bertrand 1129:            free((struct_mutex *) (*s_objet).objet);
                   1130:            break;
                   1131:        }
                   1132: 
                   1133:        case NOM :
                   1134:        {
                   1135:            if (decrementation_atomique(s_objet) > 0)
                   1136:            {
                   1137:                return;
                   1138:            }
                   1139: 
                   1140:            free((*((struct_nom *) (*s_objet).objet)).nom);
                   1141: 
                   1142:            if ((*s_etat_processus).pointeur_nom < TAILLE_CACHE)
                   1143:            {
                   1144:                (*s_etat_processus).objets_nom
                   1145:                        [(*s_etat_processus).pointeur_nom++] = (*s_objet).objet;
                   1146:            }
                   1147:            else
                   1148:            {
                   1149:                free((struct_nom *) (*s_objet).objet);
                   1150:            }
                   1151: 
                   1152:            break;
                   1153:        }
                   1154: 
                   1155:        case NON :
                   1156:        {
                   1157:            if (decrementation_atomique(s_objet) > 0)
                   1158:            {
                   1159:                return;
                   1160:            }
                   1161: 
                   1162:            break;
                   1163:        }
                   1164: 
                   1165:        case PRC :
                   1166:        {
                   1167:            if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
1.40      bertrand 1168:                    (*s_objet).objet)).thread).mutex_nombre_references)) != 0)
1.1       bertrand 1169:            {
                   1170:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1171:                return;
                   1172:            }
                   1173: 
                   1174:            (*(*((struct_processus_fils *) (*s_objet).objet)).thread)
                   1175:                    .nombre_references--;
                   1176: 
                   1177:            BUG((*(*((struct_processus_fils *) (*s_objet).objet)).thread)
1.24      bertrand 1178:                    .nombre_references < 0, uprintf(
                   1179:                    "(*(*((struct_processus_fils"
1.1       bertrand 1180:                    " *) (*s_objet).objet)).thread).nombre_references = %d\n",
                   1181:                    (int) (*(*((struct_processus_fils *) (*s_objet).objet))
                   1182:                    .thread).nombre_references));
                   1183: 
                   1184:            if ((*(*((struct_processus_fils *) (*s_objet).objet)).thread)
                   1185:                    .nombre_references == 0)
                   1186:            {
                   1187:                drapeau = d_vrai;
                   1188:            }
                   1189:            else
                   1190:            {
                   1191:                drapeau = d_faux;
                   1192:            }
                   1193: 
                   1194:            if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
1.40      bertrand 1195:                    (*s_objet).objet)).thread).mutex_nombre_references)) != 0)
1.1       bertrand 1196:            {
                   1197:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1198:                return;
                   1199:            }
                   1200: 
                   1201:            if (drapeau == d_vrai)
                   1202:            {
                   1203:                pthread_mutex_destroy(&((*(*((struct_processus_fils *)
                   1204:                        (*s_objet).objet)).thread).mutex));
1.40      bertrand 1205:                pthread_mutex_destroy(&((*(*((struct_processus_fils *)
                   1206:                        (*s_objet).objet)).thread).mutex_nombre_references));
1.1       bertrand 1207:                free((*((struct_processus_fils *) (*s_objet).objet)).thread);
                   1208:            }
                   1209: 
                   1210:            if (decrementation_atomique(s_objet) > 0)
                   1211:            {
1.28      bertrand 1212:                BUG(drapeau == d_vrai, uprintf("(*(*((struct_processus_fils"
                   1213:                        " *) (*s_objet).objet)).thread).nombre_references "
                   1214:                        "= 0 with nombre_occurrences > 0\n"));
1.1       bertrand 1215:                return;
                   1216:            }
                   1217: 
                   1218:            free((struct_processus_fils *) ((*s_objet).objet));
                   1219:            break;
                   1220:        }
                   1221: 
                   1222:        case REL :
                   1223:        {
                   1224:            if (decrementation_atomique(s_objet) > 0)
                   1225:            {
                   1226:                return;
                   1227:            }
                   1228: 
                   1229:            if ((*s_etat_processus).pointeur_rel < TAILLE_CACHE)
                   1230:            {
                   1231:                (*s_etat_processus).objets_rel
                   1232:                        [(*s_etat_processus).pointeur_rel++] = (*s_objet).objet;
                   1233:            }
                   1234:            else
                   1235:            {
                   1236:                free((real8 *) ((*s_objet).objet));
                   1237:            }
                   1238: 
                   1239:            break;
                   1240:        }
                   1241: 
                   1242:        case RPN :
                   1243:        {
                   1244:            l_element_courant = (struct_liste_chainee *) ((*s_objet).objet);
                   1245: 
                   1246:            if (decrementation_atomique(s_objet) > 0)
                   1247:            { // Il reste un pointeur sur l'objet.
                   1248:                while(l_element_courant != NULL)
                   1249:                {
                   1250:                    BUG((*(*l_element_courant).donnee).nombre_occurrences <= 1,
                   1251:                            pthread_mutex_unlock(&((*s_objet).mutex)),
                   1252:                            printf("(*(*l_element_courant).donnee)"
                   1253:                            ".nombre_occurrences=%ld\n",
                   1254:                            (*(*l_element_courant).donnee).nombre_occurrences));
                   1255: 
                   1256:                    liberation(s_etat_processus, (*l_element_courant).donnee);
                   1257:                    l_element_courant = (*l_element_courant).suivant;
                   1258:                }
                   1259: 
                   1260:                return;
                   1261:            }
                   1262:            else
                   1263:            { // Il ne reste plus aucun pointeur sur l'objet.
                   1264:                while(l_element_courant != NULL)
                   1265:                {
                   1266:                    l_element_suivant = (*l_element_courant).suivant;
                   1267:                    liberation(s_etat_processus, (*l_element_courant).donnee);
                   1268:                    liberation_maillon(s_etat_processus, l_element_courant);
                   1269:                    l_element_courant = l_element_suivant;
                   1270:                }
                   1271:            }
                   1272: 
                   1273:            break;
                   1274:        }
                   1275: 
                   1276:        case SCK :
                   1277:        {
                   1278:            if (decrementation_atomique(s_objet) > 0)
                   1279:            {
1.18      bertrand 1280:                BUG((*(*((struct_socket *) (*s_objet).objet)).format)
                   1281:                        .nombre_occurrences <= 1,
                   1282:                        pthread_mutex_unlock(&((*s_objet).mutex)),
                   1283:                        printf("(*(*((struct_socket *) (*s_objet).objet))"
                   1284:                        ".format).nombre_occurrences=%ld\n",
                   1285:                        (*(*((struct_socket *) (*s_objet).objet)).format)
                   1286:                        .nombre_occurrences));
                   1287: 
1.17      bertrand 1288:                liberation(s_etat_processus, (*((struct_socket *)
                   1289:                        (*s_objet).objet)).format);
1.1       bertrand 1290:                return;
                   1291:            }
                   1292: 
                   1293:            liberation(s_etat_processus, (*((struct_socket *)
                   1294:                    (*s_objet).objet)).format);
1.18      bertrand 1295: 
1.1       bertrand 1296:            free((unsigned char *) (*((struct_socket *) (*s_objet).objet))
                   1297:                    .adresse);
                   1298:            free((unsigned char *) (*((struct_socket *) (*s_objet).objet))
                   1299:                    .adresse_distante);
                   1300:            free((struct_socket *) ((*s_objet).objet));
                   1301:            break;
                   1302:        }
                   1303: 
                   1304:        case SLB :
                   1305:        {
                   1306:            if (decrementation_atomique(s_objet) > 0)
                   1307:            {
                   1308:                return;
                   1309:            }
                   1310: 
                   1311:            free((*((struct_bibliotheque *) (*s_objet).objet)).nom);
                   1312:            free((struct_bibliotheque *) (*s_objet).objet);
                   1313:            break;
                   1314:        }
                   1315: 
                   1316:        case SPH :
                   1317:        {
                   1318:            if (decrementation_atomique(s_objet) > 0)
                   1319:            {
                   1320:                return;
                   1321:            }
                   1322: 
                   1323:            free((*((struct_semaphore *) (*s_objet).objet)).nom);
                   1324:            free((struct_bibliotheque *) (*s_objet).objet);
                   1325:            break;
                   1326:        }
                   1327: 
                   1328:        case SQL :
                   1329:        {
                   1330:            if (decrementation_atomique(s_objet) > 0)
                   1331:            {
                   1332:                return;
                   1333:            }
                   1334: 
                   1335:            free((*((struct_connecteur_sql *) (*s_objet).objet)).type);
                   1336:            free((*((struct_connecteur_sql *) (*s_objet).objet)).locale);
                   1337:            free((struct_connecteur_sql *) (*s_objet).objet);
                   1338:            break;
                   1339:        }
                   1340: 
                   1341:        case TBL :
                   1342:        {
                   1343:            if (decrementation_atomique(s_objet) > 0)
                   1344:            {
                   1345:                for(i = 0; i < (*((struct_tableau *) (*s_objet).objet))
                   1346:                        .nombre_elements; i++)
                   1347:                {
                   1348:                    BUG((*((*((struct_tableau *)
                   1349:                            (*s_objet).objet)).elements[i]))
                   1350:                            .nombre_occurrences <= 1,
                   1351:                            pthread_mutex_unlock(&((*s_objet).mutex)),
                   1352:                            printf("(*((*((struct_tableau *) (*s_objet).objet))"
                   1353:                            ".element[%lu])).nombre_occurrences=%ld\n", i,
                   1354:                            (*((*((struct_tableau *) (*s_objet).objet))
                   1355:                            .elements[i])).nombre_occurrences));
                   1356:                    liberation(s_etat_processus, (*((struct_tableau *)
                   1357:                            (*s_objet).objet)).elements[i]);
                   1358:                }
                   1359: 
                   1360:                return;
                   1361:            }
                   1362: 
                   1363:            for(i = 0; i < (*((struct_tableau *) (*s_objet).objet))
                   1364:                    .nombre_elements; i++)
                   1365:            {
                   1366:                liberation(s_etat_processus, (*((struct_tableau *)
                   1367:                        (*s_objet).objet)).elements[i]);
                   1368:            }
                   1369: 
                   1370:            free((*((struct_tableau *) (*s_objet).objet)).elements);
                   1371: 
                   1372:            if ((*s_etat_processus).pointeur_tab < TAILLE_CACHE)
                   1373:            {
                   1374:                (*s_etat_processus).objets_tab
                   1375:                        [(*s_etat_processus).pointeur_tab++] = (*s_objet).objet;
                   1376:            }
                   1377:            else
                   1378:            {
                   1379:                free((struct_tableau *) (*s_objet).objet);
                   1380:            }
                   1381: 
                   1382:            break;
                   1383:        }
                   1384: 
                   1385:        case VIN :
                   1386:        {
                   1387:            if (decrementation_atomique(s_objet) > 0)
                   1388:            {
                   1389:                return;
                   1390:            }
                   1391: 
                   1392:            free((integer8 *) (*((struct_vecteur *) (*s_objet).objet)).tableau);
                   1393: 
                   1394:            if ((*s_etat_processus).pointeur_vec < TAILLE_CACHE)
                   1395:            {
                   1396:                (*s_etat_processus).objets_vec
                   1397:                        [(*s_etat_processus).pointeur_vec++] = (*s_objet).objet;
                   1398:            }
                   1399:            else
                   1400:            {
                   1401:                free((struct_vecteur *) (*s_objet).objet);
                   1402:            }
                   1403: 
                   1404:            break;
                   1405:        }
                   1406: 
                   1407:        case VCX :
                   1408:        {
                   1409:            if (decrementation_atomique(s_objet) > 0)
                   1410:            {
                   1411:                return;
                   1412:            }
                   1413: 
                   1414:            free((struct_complexe16 *) (*((struct_vecteur *)
                   1415:                    (*s_objet).objet)).tableau);
                   1416: 
                   1417:            if ((*s_etat_processus).pointeur_vec < TAILLE_CACHE)
                   1418:            {
                   1419:                (*s_etat_processus).objets_vec
                   1420:                        [(*s_etat_processus).pointeur_vec++] = (*s_objet).objet;
                   1421:            }
                   1422:            else
                   1423:            {
                   1424:                free((struct_vecteur *) (*s_objet).objet);
                   1425:            }
                   1426: 
                   1427:            break;
                   1428:        }
                   1429: 
                   1430:        case VRL :
                   1431:        {
                   1432:            if (decrementation_atomique(s_objet) > 0)
                   1433:            {
                   1434:                return;
                   1435:            }
                   1436: 
                   1437:            free((real8 *) (*((struct_vecteur *) (*s_objet).objet)).tableau);
                   1438: 
                   1439:            if ((*s_etat_processus).pointeur_vec < TAILLE_CACHE)
                   1440:            {
                   1441:                (*s_etat_processus).objets_vec
                   1442:                        [(*s_etat_processus).pointeur_vec++] = (*s_objet).objet;
                   1443:            }
                   1444:            else
                   1445:            {
                   1446:                free((struct_vecteur *) (*s_objet).objet);
                   1447:            }
                   1448: 
                   1449:            break;
                   1450:        }
                   1451: 
                   1452:        default :
                   1453:        {
                   1454:            if (pthread_mutex_unlock(&((*s_objet).mutex)) != 0)
                   1455:            {
                   1456:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1457:                return;
                   1458:            }
                   1459: 
                   1460:            if (pthread_mutex_destroy(&((*s_objet).mutex)) != 0)
                   1461:            {
                   1462:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   1463:                return;
                   1464:            }
                   1465: 
                   1466:            BUG(1, printf("Free failure (type %d)\n", (*s_objet).type));
                   1467:            return;
                   1468:        }
                   1469:    }
                   1470: 
                   1471: #undef return
                   1472: 
                   1473:    if (pthread_mutex_unlock(&((*s_objet).mutex)) != 0)
                   1474:    {
                   1475:        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1476:        return;
                   1477:    }
                   1478: 
1.28      bertrand 1479:    if (pthread_mutex_lock(&((*s_etat_processus).mutex_allocation)) != 0)
1.1       bertrand 1480:    {
1.28      bertrand 1481:        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1482:        return;
                   1483:    }
                   1484: 
                   1485:    if ((*s_etat_processus).taille_pile_objets < TAILLE_CACHE)
                   1486:    {
                   1487:        (*s_objet).objet = (*s_etat_processus).pile_objets;
                   1488:        (*s_etat_processus).pile_objets = s_objet;
                   1489:        (*s_etat_processus).taille_pile_objets++;
                   1490:    }
                   1491:    else
                   1492:    {
                   1493:        if (pthread_mutex_destroy(&((*s_objet).mutex)) != 0)
1.1       bertrand 1494:        {
1.28      bertrand 1495:            pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation));
                   1496:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   1497:            return;
1.1       bertrand 1498:        }
                   1499: 
1.28      bertrand 1500:        free(s_objet);
1.1       bertrand 1501:    }
1.28      bertrand 1502: 
                   1503:    if (pthread_mutex_unlock(&((*s_etat_processus).mutex_allocation)) != 0)
1.1       bertrand 1504:    {
1.28      bertrand 1505:        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1506:        return;
1.1       bertrand 1507:    }
                   1508: 
                   1509:    return;
                   1510: }
                   1511: 
                   1512: 
                   1513: /*
                   1514: ================================================================================
                   1515:   Routine de copie d'une structure *s_objet
                   1516: ================================================================================
                   1517:   Entrées : structure *s_objet à copier
                   1518:            type :
                   1519:                'P' : renvoie le même objet en incrémentant le nombre
                   1520:                      d'occurrence de chaque objet élémentaire ;
                   1521:                'O' : crée un nouvel objet en copiant chaque objet élémentaire ;
                   1522:                'N' : crée un nouvel objet mais les objets élémentaires
                   1523:                      sont réutilisés (voir 'P'). Dans le cas d'un objet
                   1524:                      élémentaire, 'N' et 'P' sont identiques.
                   1525:                'Q' : 'P' si nombre_occurrences vaut 1, 'O' sinon.
                   1526:                'R' : 'P' si nombre_occurrences vaut 1, 'N' sinon.
                   1527: --------------------------------------------------------------------------------
                   1528:   Sorties : structure identique (tous les objets sont copiés)
                   1529: --------------------------------------------------------------------------------
                   1530:   Effets de bord : néant
                   1531: ================================================================================
                   1532: */
                   1533: 
                   1534: struct_objet *
                   1535: copie_objet(struct_processus *s_etat_processus,
                   1536:        struct_objet *s_objet, unsigned char type)
                   1537: {
                   1538:    struct_liste_chainee        *l_element_base;
                   1539:    struct_liste_chainee        *l_element_courant;
                   1540:    struct_liste_chainee        *l_element_courant_ecriture;
                   1541:    struct_liste_chainee        *l_element_courant_lecture;
                   1542:    struct_liste_chainee        *l_element_suivant_ecriture;
                   1543:    struct_liste_chainee        *l_element_suivant_lecture;
                   1544: 
                   1545:    struct_objet                *s_nouvel_objet;
                   1546:    struct_objet                *s_objet_tampon;
                   1547: 
                   1548:    unsigned long               i;
                   1549:    unsigned long               j;
                   1550: 
                   1551:    if (pthread_mutex_lock(&((*s_objet).mutex)) != 0)
                   1552:    {
                   1553:        (*s_etat_processus).erreur_systeme = d_es_processus;
                   1554:        return(NULL);
                   1555:    }
                   1556: 
                   1557:    if (type == 'Q')
                   1558:    {
                   1559:        if ((*s_objet).nombre_occurrences == 1)
                   1560:        {
                   1561:            type = 'P';
                   1562:        }
                   1563:        else
                   1564:        {
                   1565:            type = 'O';
                   1566:        }
                   1567:    }
                   1568:    else if (type == 'R')
                   1569:    {
                   1570:        if ((*s_objet).nombre_occurrences == 1)
                   1571:        {
                   1572:            type = 'P';
                   1573:        }
                   1574:        else
                   1575:        {
                   1576:            type = 'N';
                   1577:        }
                   1578:    }
                   1579: 
                   1580: #define return(pointeur) \
                   1581:    if (pthread_mutex_unlock(&((*s_objet).mutex))) \
                   1582:        { (*s_etat_processus).erreur_systeme = d_es_processus; return(NULL); } \
                   1583:    return(pointeur)
                   1584: 
                   1585:    switch((*s_objet).type)
                   1586:    {
                   1587:        case ADR :
                   1588:        {
                   1589:            if (type != 'O')
                   1590:            {
                   1591:                incrementation_atomique(s_objet);
                   1592:                return(s_objet);
                   1593:            }
                   1594: 
                   1595:            if ((s_nouvel_objet = allocation(s_etat_processus, ADR)) == NULL)
                   1596:            {
                   1597:                return(NULL);
                   1598:            }
                   1599: 
                   1600:            (*((unsigned long *) ((*s_nouvel_objet).objet))) =
                   1601:                    (*((unsigned long *) ((*s_objet).objet)));
                   1602:            break;
                   1603:        }
                   1604: 
                   1605:        case ALG :
                   1606:        {
                   1607:            if (type != 'P')
                   1608:            {
                   1609:                if ((s_nouvel_objet = allocation(s_etat_processus, ALG))
                   1610:                        == NULL)
                   1611:                {
                   1612:                    return(NULL);
                   1613:                }
                   1614: 
                   1615:                l_element_courant_lecture = (struct_liste_chainee *)
                   1616:                        ((*s_objet).objet);
                   1617: 
                   1618:                l_element_base = NULL;
                   1619:                l_element_courant_ecriture = l_element_base;
                   1620: 
                   1621:                while(l_element_courant_lecture != NULL)
                   1622:                {
                   1623:                    s_objet_tampon = copie_objet(s_etat_processus,
                   1624:                            (*l_element_courant_lecture).donnee, type);
                   1625:                    l_element_suivant_ecriture = (struct_liste_chainee *)
                   1626:                            malloc(sizeof(struct_liste_chainee));
                   1627: 
                   1628:                    if ((s_objet_tampon == NULL) ||
                   1629:                            (l_element_suivant_ecriture == NULL))
                   1630:                    {
                   1631:                        l_element_courant_lecture = (struct_liste_chainee *)
                   1632:                                ((*s_nouvel_objet).objet);
                   1633: 
                   1634:                        while(l_element_courant_lecture != NULL)
                   1635:                        {
                   1636:                            l_element_suivant_lecture =
                   1637:                                    (*l_element_courant_lecture).suivant;
                   1638:                            liberation(s_etat_processus,
                   1639:                                    (*l_element_courant_lecture).donnee);
                   1640:                            free(l_element_courant_lecture);
                   1641:                            l_element_courant_lecture =
                   1642:                                    l_element_suivant_lecture;
                   1643:                        }
                   1644: 
                   1645:                        return(NULL);
                   1646:                    }
                   1647: 
                   1648:                    if (l_element_courant_ecriture == NULL)
                   1649:                    {
                   1650:                        l_element_base = l_element_suivant_ecriture;
                   1651:                    }
                   1652:                    else
                   1653:                    {
                   1654:                        (*l_element_courant_ecriture).suivant =
                   1655:                                l_element_suivant_ecriture;
                   1656:                    }
                   1657: 
                   1658:                    l_element_courant_ecriture = l_element_suivant_ecriture;
                   1659: 
                   1660:                    (*l_element_courant_ecriture).donnee = s_objet_tampon;
                   1661:                    (*l_element_courant_ecriture).suivant = NULL;
                   1662:                    l_element_courant_lecture =
                   1663:                            (*l_element_courant_lecture).suivant;
                   1664:                }
                   1665: 
                   1666:                (*s_nouvel_objet).objet = (void *) ((struct_liste_chainee *)
                   1667:                        l_element_base);
                   1668:            }
                   1669:            else // type == 'P'
                   1670:            {
                   1671:                incrementation_atomique(s_objet);
                   1672:                l_element_courant = (*s_objet).objet;
                   1673: 
                   1674:                while(l_element_courant != NULL)
                   1675:                {
                   1676:                    (*l_element_courant).donnee = copie_objet(s_etat_processus,
                   1677:                            (*l_element_courant).donnee, 'P');
                   1678:                    l_element_courant = (*l_element_courant).suivant;
                   1679:                }
                   1680: 
                   1681:                return(s_objet);
                   1682:            }
                   1683: 
                   1684:            break;
                   1685:        }
                   1686: 
                   1687:        case BIN :
                   1688:        {
                   1689:            if (type != 'O')
                   1690:            {
                   1691:                incrementation_atomique(s_objet);
                   1692:                return(s_objet);
                   1693:            }
                   1694: 
                   1695:            if ((s_nouvel_objet = allocation(s_etat_processus, BIN)) == NULL)
                   1696:            {
                   1697:                return(NULL);
                   1698:            }
                   1699: 
                   1700:            (*((logical8 *) ((*s_nouvel_objet).objet))) =
                   1701:                    (*((logical8 *) ((*s_objet).objet)));
                   1702:            break;
                   1703:        }
                   1704: 
                   1705:        case CHN :
                   1706:        {
                   1707:            if (type != 'O')
                   1708:            {
                   1709:                incrementation_atomique(s_objet);
                   1710:                return(s_objet);
                   1711:            }
                   1712: 
                   1713:            if ((s_nouvel_objet = allocation(s_etat_processus, CHN)) == NULL)
                   1714:            {
                   1715:                return(NULL);
                   1716:            }
                   1717: 
                   1718:            (*s_nouvel_objet).objet = (void *) ((unsigned char *)
                   1719:                    malloc((strlen((unsigned char *) ((*s_objet).objet)) + 1)
                   1720:                    * sizeof(unsigned char)));
                   1721: 
                   1722:            if ((*s_nouvel_objet).objet == NULL)
                   1723:            {
                   1724:                free(s_nouvel_objet);
                   1725:                return(NULL);
                   1726:            }
                   1727: 
                   1728:            strcpy((unsigned char *) ((*s_nouvel_objet).objet),
                   1729:                    (unsigned char *) ((*s_objet).objet));
                   1730:            break;
                   1731:        }
                   1732: 
                   1733:        case CPL :
                   1734:        {
                   1735:            if (type != 'O')
                   1736:            {
                   1737:                incrementation_atomique(s_objet);
                   1738:                return(s_objet);
                   1739:            }
                   1740: 
                   1741:            if ((s_nouvel_objet = allocation(s_etat_processus, CPL)) == NULL)
                   1742:            {
                   1743:                return(NULL);
                   1744:            }
                   1745: 
                   1746:            (*((struct_complexe16 *) ((*s_nouvel_objet).objet))) =
                   1747:                    (*((struct_complexe16 *) ((*s_objet).objet)));
                   1748:            break;
                   1749:        }
                   1750: 
                   1751:        case RPN :
                   1752:        {
                   1753:            if (type != 'P')
                   1754:            {
                   1755:                if ((s_nouvel_objet = allocation(s_etat_processus, RPN))
                   1756:                        == NULL)
                   1757:                {
                   1758:                    return(NULL);
                   1759:                }
                   1760: 
                   1761:                l_element_courant_lecture = (struct_liste_chainee *)
                   1762:                        ((*s_objet).objet);
                   1763: 
                   1764:                l_element_base = NULL;
                   1765:                l_element_courant_ecriture = l_element_base;
                   1766: 
                   1767:                while(l_element_courant_lecture != NULL)
                   1768:                {
                   1769:                    s_objet_tampon = copie_objet(s_etat_processus,
                   1770:                            (*l_element_courant_lecture).donnee, type);
                   1771:                    l_element_suivant_ecriture = (struct_liste_chainee *)
                   1772:                            malloc(sizeof(struct_liste_chainee));
                   1773: 
                   1774:                    if ((s_objet_tampon == NULL) ||
                   1775:                            (l_element_suivant_ecriture == NULL))
                   1776:                    {
                   1777:                        l_element_courant_lecture = (struct_liste_chainee *)
                   1778:                                ((*s_nouvel_objet).objet);
                   1779: 
                   1780:                        while(l_element_courant_lecture != NULL)
                   1781:                        {
                   1782:                            l_element_suivant_lecture =
                   1783:                                    (*l_element_courant_lecture).suivant;
                   1784:                            liberation(s_etat_processus,
                   1785:                                    (*l_element_courant_lecture).donnee);
                   1786:                            free(l_element_courant_lecture);
                   1787:                            l_element_courant_lecture =
                   1788:                                    l_element_suivant_lecture;
                   1789:                        }
                   1790: 
                   1791:                        return(NULL);
                   1792:                    }
                   1793: 
                   1794:                    if (l_element_courant_ecriture == NULL)
                   1795:                    {
                   1796:                        l_element_base = l_element_suivant_ecriture;
                   1797:                    }
                   1798:                    else
                   1799:                    {
                   1800:                        (*l_element_courant_ecriture).suivant =
                   1801:                                l_element_suivant_ecriture;
                   1802:                    }
                   1803: 
                   1804:                    l_element_courant_ecriture = l_element_suivant_ecriture;
                   1805: 
                   1806:                    (*l_element_courant_ecriture).donnee = s_objet_tampon;
                   1807:                    (*l_element_courant_ecriture).suivant = NULL;
                   1808:                    l_element_courant_lecture =
                   1809:                            (*l_element_courant_lecture).suivant;
                   1810:                }
                   1811: 
                   1812:                (*s_nouvel_objet).objet = (void *) ((struct_liste_chainee *)
                   1813:                        l_element_base);
                   1814:            }
                   1815:            else // type == 'P'
                   1816:            {
                   1817:                incrementation_atomique(s_objet);
                   1818:                l_element_courant = (*s_objet).objet;
                   1819: 
                   1820:                while(l_element_courant != NULL)
                   1821:                {
                   1822:                    (*l_element_courant).donnee = copie_objet(s_etat_processus,
                   1823:                            (*l_element_courant).donnee, 'P');
                   1824:                    l_element_courant = (*l_element_courant).suivant;
                   1825:                }
                   1826: 
                   1827:                return(s_objet);
                   1828:            }
                   1829: 
                   1830:            break;
                   1831:        }
                   1832: 
                   1833:        case FCH :
                   1834:        {
                   1835:            if (type == 'P')
                   1836:            {
                   1837:                incrementation_atomique(s_objet);
1.17      bertrand 1838: 
                   1839:                if (((*((struct_fichier *) ((*s_objet).objet))).format =
                   1840:                        copie_objet(s_etat_processus, (*((struct_fichier *)
                   1841:                        ((*s_objet).objet))).format, 'P')) == NULL)
                   1842:                {
                   1843:                    return(NULL);
                   1844:                }
                   1845: 
1.1       bertrand 1846:                return(s_objet);
                   1847:            }
                   1848: 
                   1849:            if ((s_nouvel_objet = allocation(s_etat_processus, FCH)) == NULL)
                   1850:            {
                   1851:                return(NULL);
                   1852:            }
                   1853: 
                   1854:            (*((struct_fichier *) ((*s_nouvel_objet).objet))).descripteur =
                   1855:                    (*((struct_fichier *) ((*s_objet).objet))).descripteur;
                   1856:            (*((struct_fichier *) ((*s_nouvel_objet).objet))).acces =
                   1857:                    (*((struct_fichier *) ((*s_objet).objet))).acces;
                   1858:            (*((struct_fichier *) ((*s_nouvel_objet).objet))).binaire =
                   1859:                    (*((struct_fichier *) ((*s_objet).objet))).binaire;
                   1860:            (*((struct_fichier *) ((*s_nouvel_objet).objet))).ouverture =
                   1861:                    (*((struct_fichier *) ((*s_objet).objet))).ouverture;
                   1862:            (*((struct_fichier *) ((*s_nouvel_objet).objet))).protection =
                   1863:                    (*((struct_fichier *) ((*s_objet).objet))).protection;
                   1864:            (*((struct_fichier *) ((*s_nouvel_objet).objet)))
                   1865:                    .position_clef = (*((struct_fichier *)
                   1866:                    ((*s_objet).objet))).position_clef;
                   1867:            (*((struct_fichier *) ((*s_nouvel_objet).objet))).pid =
                   1868:                    (*((struct_fichier *) ((*s_objet).objet))).pid;
                   1869:            (*((struct_fichier *) ((*s_nouvel_objet).objet))).tid =
                   1870:                    (*((struct_fichier *) ((*s_objet).objet))).tid;
                   1871: 
                   1872:            if (((*((struct_fichier *) ((*s_nouvel_objet).objet))).format =
                   1873:                    copie_objet(s_etat_processus, (*((struct_fichier *)
                   1874:                    ((*s_objet).objet))).format, type)) == NULL)
                   1875:            {
                   1876:                free((*s_nouvel_objet).objet);
                   1877:                free(s_nouvel_objet);
                   1878:                return(NULL);
                   1879:            }
                   1880: 
                   1881:            if (((*((struct_fichier *) ((*s_nouvel_objet).objet))).nom =
                   1882:                    (unsigned char *) malloc((strlen((*((struct_fichier *)
                   1883:                    ((*s_objet).objet))).nom) + 1) * sizeof(unsigned char)))
                   1884:                    == NULL)
                   1885:            {
                   1886:                liberation(s_etat_processus, (*((struct_fichier *)
                   1887:                        (*s_nouvel_objet).objet)).format);
                   1888:                free((*s_nouvel_objet).objet);
                   1889:                free(s_nouvel_objet);
                   1890:                return(NULL);
                   1891:            }
                   1892: 
                   1893:            strcpy((*((struct_fichier *) ((*s_nouvel_objet).objet))).nom,
                   1894:                    (*((struct_fichier *) ((*s_objet).objet))).nom);
                   1895:            break;
                   1896:        }
                   1897: 
                   1898:        case FCT :
                   1899:        {
                   1900:            if (type != 'O')
                   1901:            {
                   1902:                /*
                   1903:                 * Remise à zéro de la prédiction pour respecter la cohérence
                   1904:                 * du saut dans les cas EXSUB et OBSUB.
                   1905:                 */
                   1906: 
                   1907:                (*((struct_fonction *) ((*s_objet).objet)))
                   1908:                        .prediction_saut = NULL;
                   1909:                incrementation_atomique(s_objet);
                   1910:                return(s_objet);
                   1911:            }
                   1912: 
                   1913:            if ((s_nouvel_objet = allocation(s_etat_processus, FCT)) == NULL)
                   1914:            {
                   1915:                return(NULL);
                   1916:            }
                   1917: 
                   1918:            if (((*((struct_fonction *) ((*s_nouvel_objet).objet)))
                   1919:                    .nom_fonction = (unsigned char *)
                   1920:                    malloc((strlen((*((struct_fonction *)
                   1921:                    ((*s_objet).objet))).nom_fonction) + 1) *
                   1922:                    sizeof(unsigned char))) == NULL)
                   1923:            {
                   1924:                free(s_nouvel_objet);
                   1925:                return(NULL);
                   1926:            }
                   1927: 
                   1928:            strcpy((unsigned char *) (*((struct_fonction *)
                   1929:                    ((*s_nouvel_objet).objet))).nom_fonction,
                   1930:                    (unsigned char *) (*((struct_fonction *)
                   1931:                    ((*s_objet).objet))).nom_fonction);
                   1932:            (*((struct_fonction *) ((*s_nouvel_objet).objet)))
                   1933:                    .nombre_arguments = (*((struct_fonction *)
                   1934:                    ((*s_objet).objet))).nombre_arguments;
                   1935:            (*((struct_fonction *) ((*s_nouvel_objet).objet))).fonction =
                   1936:                    (*((struct_fonction *) ((*s_objet).objet))).fonction;
                   1937:            break;
                   1938:        }
                   1939: 
                   1940:        case INT :
                   1941:        {
                   1942:            if (type != 'O')
                   1943:            {
                   1944:                incrementation_atomique(s_objet);
                   1945:                return(s_objet);
                   1946:            }
                   1947: 
                   1948:            if ((s_nouvel_objet = allocation(s_etat_processus, INT)) == NULL)
                   1949:            {
                   1950:                return(NULL);
                   1951:            }
                   1952: 
                   1953:            (*((integer8 *) ((*s_nouvel_objet).objet))) =
                   1954:                    (*((integer8 *) ((*s_objet).objet)));
                   1955:            break;
                   1956:        }
                   1957: 
                   1958:        case LST :
                   1959:        {
                   1960:            if (type != 'P')
                   1961:            {
                   1962:                if ((s_nouvel_objet = allocation(s_etat_processus, LST))
                   1963:                        == NULL)
                   1964:                {
                   1965:                    return(NULL);
                   1966:                }
                   1967: 
                   1968:                l_element_courant_lecture = (struct_liste_chainee *)
                   1969:                        ((*s_objet).objet);
                   1970: 
                   1971:                l_element_base = NULL;
                   1972:                l_element_courant_ecriture = l_element_base;
                   1973: 
                   1974:                while(l_element_courant_lecture != NULL)
                   1975:                {
                   1976:                    s_objet_tampon = copie_objet(s_etat_processus,
                   1977:                            (*l_element_courant_lecture).donnee, type);
                   1978:                    l_element_suivant_ecriture = (struct_liste_chainee *)
                   1979:                            malloc(sizeof(struct_liste_chainee));
                   1980: 
                   1981:                    if ((s_objet_tampon == NULL) ||
                   1982:                            (l_element_suivant_ecriture == NULL))
                   1983:                    {
                   1984:                        l_element_courant_lecture = (struct_liste_chainee *)
                   1985:                                ((*s_nouvel_objet).objet);
                   1986: 
                   1987:                        while(l_element_courant_lecture != NULL)
                   1988:                        {
                   1989:                            l_element_suivant_lecture =
                   1990:                                    (*l_element_courant_lecture).suivant;
                   1991:                            liberation(s_etat_processus,
                   1992:                                    (*l_element_courant_lecture).donnee);
                   1993:                            free(l_element_courant_lecture);
                   1994:                            l_element_courant_lecture =
                   1995:                                    l_element_suivant_lecture;
                   1996:                        }
                   1997: 
                   1998:                        return(NULL);
                   1999:                    }
                   2000: 
                   2001:                    if (l_element_courant_ecriture == NULL)
                   2002:                    {
                   2003:                        l_element_base = l_element_suivant_ecriture;
                   2004:                    }
                   2005:                    else
                   2006:                    {
                   2007:                        (*l_element_courant_ecriture).suivant =
                   2008:                                l_element_suivant_ecriture;
                   2009:                    }
                   2010: 
                   2011:                    l_element_courant_ecriture = l_element_suivant_ecriture;
                   2012: 
                   2013:                    (*l_element_courant_ecriture).donnee = s_objet_tampon;
                   2014:                    (*l_element_courant_ecriture).suivant = NULL;
                   2015:                    l_element_courant_lecture =
                   2016:                            (*l_element_courant_lecture).suivant;
                   2017:                }
                   2018: 
                   2019:                (*s_nouvel_objet).objet = (void *) ((struct_liste_chainee *)
                   2020:                        l_element_base);
                   2021:            }
                   2022:            else
                   2023:            {
                   2024:                incrementation_atomique(s_objet);
                   2025:                l_element_courant = (*s_objet).objet;
                   2026: 
                   2027:                while(l_element_courant != NULL)
                   2028:                {
                   2029:                    (*l_element_courant).donnee = copie_objet(s_etat_processus,
                   2030:                            (*l_element_courant).donnee, 'P');
                   2031:                    l_element_courant = (*l_element_courant).suivant;
                   2032:                }
                   2033: 
                   2034:                return(s_objet);
                   2035:            }
                   2036: 
                   2037:            break;
                   2038:        }
                   2039: 
                   2040:        case MIN :
                   2041:        {
                   2042:            if (type != 'O')
                   2043:            {
                   2044:                incrementation_atomique(s_objet);
                   2045:                return(s_objet);
                   2046:            }
                   2047: 
                   2048:            if ((s_nouvel_objet = allocation(s_etat_processus, MIN)) == NULL)
                   2049:            {
                   2050:                return(NULL);
                   2051:            }
                   2052: 
                   2053:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau =
                   2054:                    (void **) ((integer8 **) malloc(
                   2055:                    ((*((struct_matrice *) ((*s_objet).objet))).nombre_lignes)
                   2056:                    * sizeof(integer8 *)));
                   2057: 
                   2058:            if ((*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau
                   2059:                    == NULL)
                   2060:            {
                   2061:                free((*s_nouvel_objet).objet);
                   2062:                free(s_nouvel_objet);
                   2063:                return(NULL);
                   2064:            }
                   2065: 
                   2066:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_colonnes =
                   2067:                    (*((struct_matrice *) ((*s_objet).objet))).nombre_colonnes;
                   2068:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_lignes =
                   2069:                    (*((struct_matrice *) ((*s_objet).objet))).nombre_lignes;
                   2070:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).type =
                   2071:                    (*((struct_matrice *) ((*s_objet).objet))).type;
                   2072: 
                   2073:            for(i = 0; i < (*((struct_matrice *)
                   2074:                    ((*s_objet).objet))).nombre_lignes; i++)
                   2075:            {
                   2076:                if ((((integer8 **) ((*((struct_matrice *)
                   2077:                        ((*s_nouvel_objet).objet))).tableau))[i] =
                   2078:                        (void *) ((integer8 *) malloc(
                   2079:                        ((*((struct_matrice *) ((*s_objet).objet)))
                   2080:                        .nombre_colonnes) * sizeof(integer8)))) == NULL)
                   2081:                {
                   2082:                    for(j = 0; j < i; j++)
                   2083:                    {
                   2084:                        free(((integer8 **) ((*((struct_matrice *)
                   2085:                                ((*s_nouvel_objet).objet))).tableau))[j]);
                   2086:                    }
                   2087: 
                   2088:                    free((*s_nouvel_objet).objet);
                   2089:                    free(s_nouvel_objet);
                   2090:                    return(NULL);
                   2091:                }
                   2092:            
                   2093:                for(j = 0; j < (*((struct_matrice *)
                   2094:                        ((*s_objet).objet))).nombre_colonnes; j++)
                   2095:                {
                   2096:                    ((integer8 **) ((*((struct_matrice *)
                   2097:                            ((*s_nouvel_objet).objet))).tableau))[i][j] =
                   2098:                            ((integer8 **) ((*((struct_matrice *)
                   2099:                            ((*s_objet).objet))).tableau))[i][j];
                   2100:                }
                   2101:            }      
                   2102: 
                   2103:            break;
                   2104:        }
                   2105: 
                   2106:        case MCX :
                   2107:        {
                   2108:            if (type != 'O')
                   2109:            {
                   2110:                incrementation_atomique(s_objet);
                   2111:                return(s_objet);
                   2112:            }
                   2113: 
                   2114:            if ((s_nouvel_objet = allocation(s_etat_processus, MCX))
                   2115:                    == NULL)
                   2116:            {
                   2117:                return(NULL);
                   2118:            }
                   2119: 
                   2120:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau =
                   2121:                    (void **) ((struct_complexe16 **) malloc(
                   2122:                    ((*((struct_matrice *) ((*s_objet).objet))).nombre_lignes)
                   2123:                    * sizeof(struct_complexe16 *)));
                   2124: 
                   2125:            if ((*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau
                   2126:                    == NULL)
                   2127:            {
                   2128:                free((*s_nouvel_objet).objet);
                   2129:                free(s_nouvel_objet);
                   2130:                return(NULL);
                   2131:            }
                   2132: 
                   2133:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_colonnes =
                   2134:                    (*((struct_matrice *) ((*s_objet).objet))).nombre_colonnes;
                   2135:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_lignes =
                   2136:                    (*((struct_matrice *) ((*s_objet).objet))).nombre_lignes;
                   2137:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).type =
                   2138:                    (*((struct_matrice *) ((*s_objet).objet))).type;
                   2139: 
                   2140:            for(i = 0; i < (*((struct_matrice *)
                   2141:                    ((*s_objet).objet))).nombre_lignes; i++)
                   2142:            {
                   2143:                if ((((struct_complexe16 **) ((*((struct_matrice *)
                   2144:                        ((*s_nouvel_objet).objet))).tableau))[i] =
                   2145:                        (void *) ((struct_complexe16 *) malloc(
                   2146:                        ((*((struct_matrice *) ((*s_objet).objet)))
                   2147:                        .nombre_colonnes) * sizeof(struct_complexe16))))
                   2148:                        == NULL)
                   2149:                {
                   2150:                    for(j = 0; j < i; j++)
                   2151:                    {
                   2152:                        free(((struct_complexe16 **) ((*((struct_matrice *)
                   2153:                                ((*s_nouvel_objet).objet))).tableau))[j]);
                   2154:                    }
                   2155: 
                   2156:                    free((*s_nouvel_objet).objet);
                   2157:                    free(s_nouvel_objet);
                   2158:                    return(NULL);
                   2159:                }
                   2160:            
                   2161:                for(j = 0; j < (*((struct_matrice *)
                   2162:                        ((*s_objet).objet))).nombre_colonnes; j++)
                   2163:                {
                   2164:                    ((struct_complexe16 **) ((*((struct_matrice *)
                   2165:                            ((*s_nouvel_objet).objet))).tableau))[i][j] =
                   2166:                            ((struct_complexe16 **) ((*((struct_matrice *)
                   2167:                            ((*s_objet).objet))).tableau))[i][j];
                   2168:                }
                   2169:            }
                   2170: 
                   2171:            break;
                   2172:        }
                   2173: 
                   2174:        case MRL :
                   2175:        {
                   2176:            if (type != 'O')
                   2177:            {
                   2178:                incrementation_atomique(s_objet);
                   2179:                return(s_objet);
                   2180:            }
                   2181: 
                   2182:            if ((s_nouvel_objet = allocation(s_etat_processus, MRL)) == NULL)
                   2183:            {
                   2184:                return(NULL);
                   2185:            }
                   2186: 
                   2187:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau = 
                   2188:                    (void **) ((real8 **) malloc(
                   2189:                    ((*((struct_matrice *) ((*s_objet).objet))).nombre_lignes)
                   2190:                    * sizeof(real8 *)));
                   2191: 
                   2192:            if ((*((struct_matrice *) ((*s_nouvel_objet).objet))).tableau
                   2193:                    == NULL)
                   2194:            {
                   2195:                free((*s_nouvel_objet).objet);
                   2196:                free(s_nouvel_objet);
                   2197:                return(NULL);
                   2198:            }
                   2199: 
                   2200:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_colonnes =
                   2201:                    (*((struct_matrice *) ((*s_objet).objet))).nombre_colonnes;
                   2202:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).nombre_lignes =
                   2203:                    (*((struct_matrice *) ((*s_objet).objet))).nombre_lignes;
                   2204:            (*((struct_matrice *) ((*s_nouvel_objet).objet))).type =
                   2205:                    (*((struct_matrice *) ((*s_objet).objet))).type;
                   2206: 
                   2207:            for(i = 0; i < (*((struct_matrice *)
                   2208:                    ((*s_objet).objet))).nombre_lignes; i++)
                   2209:            {
                   2210:                if ((((real8 **) ((*((struct_matrice *)
                   2211:                        ((*s_nouvel_objet).objet))).tableau))[i] =
                   2212:                        (void *) ((real8 *) malloc(
                   2213:                        ((*((struct_matrice *) ((*s_objet).objet)))
                   2214:                        .nombre_colonnes) * sizeof(real8)))) == NULL)
                   2215:                {
                   2216:                    for(j = 0; j < i; j++)
                   2217:                    {
                   2218:                        free(((real8 **) ((*((struct_matrice *)
                   2219:                                ((*s_nouvel_objet).objet))).tableau))[j]);
                   2220:                    }
                   2221: 
                   2222:                    free((*s_nouvel_objet).objet);
                   2223:                    free(s_nouvel_objet);
                   2224:                    return(NULL);
                   2225:                }
                   2226:            
                   2227:                for(j = 0; j < (*((struct_matrice *)
                   2228:                        ((*s_objet).objet))).nombre_colonnes; j++)
                   2229:                {
                   2230:                    ((real8 **) ((*((struct_matrice *)
                   2231:                            ((*s_nouvel_objet).objet))).tableau))[i][j] =
                   2232:                            ((real8 **) ((*((struct_matrice *)
                   2233:                            ((*s_objet).objet))).tableau))[i][j];
                   2234:                }
                   2235:            }
                   2236: 
                   2237:            break;
                   2238:        }
                   2239: 
                   2240:        case MTX :
                   2241:        {
1.75      bertrand 2242:            // La duplication d'un mutex renvoie le même objet.
                   2243:            incrementation_atomique(s_objet);
1.76      bertrand 2244:            return(s_objet);
1.1       bertrand 2245:        }
                   2246: 
                   2247:        case NOM :
                   2248:        {
                   2249:            if (type != 'O')
                   2250:            {
                   2251:                incrementation_atomique(s_objet);
                   2252:                return(s_objet);
                   2253:            }
                   2254: 
                   2255:            if ((s_nouvel_objet = allocation(s_etat_processus, NOM)) == NULL)
                   2256:            {
                   2257:                return(NULL);
                   2258:            }
                   2259: 
                   2260:            (*((struct_nom *) (*s_nouvel_objet).objet)).nom = malloc((
                   2261:                    strlen((*((struct_nom *) (*s_objet).objet)).nom) + 1) *
                   2262:                    sizeof(unsigned char));
                   2263: 
                   2264:            if ((*((struct_nom *) (*s_nouvel_objet).objet)).nom == NULL)
                   2265:            {
                   2266:                free((*s_nouvel_objet).objet);
                   2267:                free(s_nouvel_objet);
                   2268:                return(NULL);
                   2269:            }
                   2270: 
                   2271:            strcpy((*((struct_nom *) (*s_nouvel_objet).objet)).nom,
                   2272:                    (*((struct_nom *) (*s_objet).objet)).nom);
                   2273:            (*((struct_nom *) (*s_nouvel_objet).objet)).symbole =
                   2274:                    (*((struct_nom *) (*s_objet).objet)).symbole;
                   2275:            break;
                   2276:        }
                   2277: 
                   2278:        case NON :
                   2279:        {
                   2280:            if (type != 'O')
                   2281:            {
                   2282:                incrementation_atomique(s_objet);
                   2283:                return(s_objet);
                   2284:            }
                   2285: 
1.85      bertrand 2286:            // Un objet de type NON est un objet encapsulé dans une
                   2287:            // structure de type struct_objet. Elle peut très bien contenir
                   2288:            // une donnée, mais c'est à l'utilisateur de la libérer
                   2289:            // explicitement avec un free().
                   2290: 
1.1       bertrand 2291:            if ((s_nouvel_objet = allocation(s_etat_processus, NON)) == NULL)
                   2292:            {
                   2293:                return(NULL);
                   2294:            }
                   2295: 
1.85      bertrand 2296:            (*s_nouvel_objet).objet = (*s_objet).objet;
1.1       bertrand 2297:            break;
                   2298:        }
                   2299: 
                   2300:        case PRC :
                   2301:        {
                   2302:            if (pthread_mutex_lock(&((*(*((struct_processus_fils *)
1.40      bertrand 2303:                    (*s_objet).objet)).thread).mutex_nombre_references)) != 0)
1.1       bertrand 2304:            {
                   2305:                return(NULL);
                   2306:            }
                   2307: 
                   2308:            (*(*((struct_processus_fils *) (*s_objet).objet)).thread)
                   2309:                    .nombre_references++;
                   2310: 
                   2311:            if (pthread_mutex_unlock(&((*(*((struct_processus_fils *)
1.40      bertrand 2312:                    (*s_objet).objet)).thread).mutex_nombre_references)) != 0)
1.1       bertrand 2313:            {
                   2314:                return(NULL);
                   2315:            }
                   2316: 
                   2317:            if (type != 'O')
                   2318:            {
                   2319:                incrementation_atomique(s_objet);
                   2320:                return(s_objet);
                   2321:            }
                   2322: 
                   2323:            if ((s_nouvel_objet = allocation(s_etat_processus, PRC)) == NULL)
                   2324:            {
                   2325:                return(NULL);
                   2326:            }
                   2327: 
                   2328:            (*((struct_processus_fils *) (*s_nouvel_objet).objet)) =
                   2329:                    (*((struct_processus_fils *) (*s_objet).objet));
                   2330:            break;
                   2331:        }
                   2332: 
                   2333:        case REL :
                   2334:        {
                   2335:            if (type != 'O')
                   2336:            {
                   2337:                incrementation_atomique(s_objet);
                   2338:                return(s_objet);
                   2339:            }
                   2340: 
                   2341:            if ((s_nouvel_objet = allocation(s_etat_processus, REL)) == NULL)
                   2342:            {
                   2343:                return(NULL);
                   2344:            }
                   2345: 
                   2346:            (*((real8 *) ((*s_nouvel_objet).objet))) =
                   2347:                    (*((real8 *) ((*s_objet).objet)));
                   2348:            break;
                   2349:        }
                   2350: 
                   2351:        case SCK :
                   2352:        {
                   2353:            if (type == 'P')
                   2354:            {
                   2355:                incrementation_atomique(s_objet);
1.17      bertrand 2356: 
1.18      bertrand 2357:                if (((*((struct_socket *) ((*s_objet).objet)))
                   2358:                        .format = copie_objet(s_etat_processus,
                   2359:                        (*((struct_socket *) ((*s_objet).objet))).format, 'P'))
                   2360:                        == NULL)
1.17      bertrand 2361:                {
                   2362:                    return(NULL);
                   2363:                }
                   2364: 
1.1       bertrand 2365:                return(s_objet);
                   2366:            }
                   2367: 
                   2368:            if ((s_nouvel_objet = allocation(s_etat_processus, SCK)) == NULL)
                   2369:            {
                   2370:                return(NULL);
                   2371:            }
                   2372: 
                   2373:            (*((struct_socket *) ((*s_nouvel_objet).objet))).socket =
                   2374:                    (*((struct_socket *) ((*s_objet).objet))).socket;
                   2375:            (*((struct_socket *) ((*s_nouvel_objet).objet))).domaine =
                   2376:                    (*((struct_socket *) ((*s_objet).objet))).domaine;
                   2377:            (*((struct_socket *) ((*s_nouvel_objet).objet))).socket_en_ecoute =
                   2378:                    (*((struct_socket *) ((*s_objet).objet))).socket_en_ecoute;
                   2379:            (*((struct_socket *) ((*s_nouvel_objet).objet))).socket_connectee =
                   2380:                    (*((struct_socket *) ((*s_objet).objet))).socket_connectee;
                   2381:            (*((struct_socket *) ((*s_nouvel_objet).objet))).pid =
                   2382:                    (*((struct_socket *) ((*s_objet).objet))).pid;
                   2383:            (*((struct_socket *) ((*s_nouvel_objet).objet))).binaire =
                   2384:                    (*((struct_socket *) ((*s_objet).objet))).binaire;
                   2385:            (*((struct_socket *) ((*s_nouvel_objet).objet))).effacement =
                   2386:                    (*((struct_socket *) ((*s_objet).objet))).effacement;
                   2387:            (*((struct_socket *) ((*s_nouvel_objet).objet))).protection =
                   2388:                    (*((struct_socket *) ((*s_objet).objet))).protection;
                   2389:            (*((struct_socket *) ((*s_nouvel_objet).objet))).localisation =
                   2390:                    (*((struct_socket *) ((*s_objet).objet))).localisation;
                   2391:            (*((struct_socket *) ((*s_nouvel_objet).objet))).pid =
                   2392:                    (*((struct_socket *) ((*s_objet).objet))).pid;
                   2393:            (*((struct_socket *) ((*s_nouvel_objet).objet))).tid =
                   2394:                    (*((struct_socket *) ((*s_objet).objet))).tid;
                   2395: 
                   2396:            if (((*((struct_socket *) ((*s_nouvel_objet).objet))).format =
                   2397:                    copie_objet(s_etat_processus, (*((struct_socket *)
                   2398:                    ((*s_objet).objet))).format, type)) == NULL)
                   2399:            {
                   2400:                free((*s_nouvel_objet).objet);
                   2401:                free(s_nouvel_objet);
                   2402:                return(NULL);
                   2403:            }
                   2404: 
                   2405:            if (((*((struct_socket *) ((*s_nouvel_objet).objet))).adresse =
                   2406:                    (unsigned char *) malloc((strlen((*((struct_socket *)
                   2407:                    ((*s_objet).objet))).adresse) + 1) * sizeof(unsigned char)))
                   2408:                    == NULL)
                   2409:            {
                   2410:                liberation(s_etat_processus, (*((struct_fichier *)
                   2411:                        (*s_nouvel_objet).objet)).format);
                   2412:                free((*s_nouvel_objet).objet);
                   2413:                free(s_nouvel_objet);
                   2414:                return(NULL);
                   2415:            }
                   2416: 
                   2417:            strcpy((*((struct_socket *) ((*s_nouvel_objet).objet)))
                   2418:                    .adresse, (*((struct_socket *) ((*s_objet).objet)))
                   2419:                    .adresse);
                   2420: 
                   2421:            if (((*((struct_socket *) ((*s_nouvel_objet).objet)))
                   2422:                    .adresse_distante = malloc((strlen((*((struct_socket *)
                   2423:                    ((*s_objet).objet))).adresse_distante) + 1) *
                   2424:                    sizeof(unsigned char))) == NULL)
                   2425:            {
                   2426:                liberation(s_etat_processus, (*((struct_fichier *)
                   2427:                        (*s_nouvel_objet).objet)).format);
                   2428:                free((*s_nouvel_objet).objet);
                   2429:                free(s_nouvel_objet);
                   2430:                return(NULL);
                   2431:            }
                   2432: 
                   2433:            strcpy((*((struct_socket *) ((*s_nouvel_objet).objet)))
                   2434:                    .adresse_distante, (*((struct_socket *) ((*s_objet).objet)))
                   2435:                    .adresse_distante);
                   2436: 
                   2437:            strcpy((*((struct_socket *) ((*s_nouvel_objet).objet))).type,
                   2438:                    (*((struct_socket *) ((*s_objet).objet))).type);
                   2439:            break;
                   2440:        }
                   2441: 
                   2442:        case SLB :
                   2443:        {
                   2444:            if (type != 'O')
                   2445:            {
                   2446:                incrementation_atomique(s_objet);
                   2447:                return(s_objet);
                   2448:            }
                   2449: 
                   2450:            if ((s_nouvel_objet = allocation(s_etat_processus, SLB)) == NULL)
                   2451:            {
                   2452:                return(NULL);
                   2453:            }
                   2454: 
                   2455:            if (((*((struct_bibliotheque *) ((*s_nouvel_objet).objet))).nom =
                   2456:                    (unsigned char *) malloc((strlen((*((struct_bibliotheque *)
                   2457:                    ((*s_objet).objet))).nom) + 1) * sizeof(unsigned char)))
                   2458:                    == NULL)
                   2459:            {
                   2460:                free((*s_nouvel_objet).objet);
                   2461:                free(s_nouvel_objet);
                   2462:                return(NULL);
                   2463:            }
                   2464: 
                   2465:            strcpy((*((struct_bibliotheque *) ((*s_nouvel_objet).objet))).nom,
                   2466:                    (*((struct_bibliotheque *) ((*s_objet).objet))).nom);
                   2467: 
                   2468:            /*
                   2469:             * C'est objet est non modifiable et est un pointeur
                   2470:             * sur un objet système. Seul la référence est copiée.
                   2471:             */
                   2472: 
                   2473:            (*((struct_bibliotheque *) (*s_nouvel_objet).objet)).descripteur =
                   2474:                    (*((struct_bibliotheque *) (*s_objet).objet)).descripteur;
                   2475:            (*((struct_bibliotheque *) (*s_nouvel_objet).objet)).pid =
                   2476:                    (*((struct_bibliotheque *) (*s_objet).objet)).pid;
                   2477:            (*((struct_bibliotheque *) (*s_nouvel_objet).objet)).tid =
                   2478:                    (*((struct_bibliotheque *) (*s_objet).objet)).tid;
                   2479:            break;
                   2480:        }
                   2481: 
                   2482:        case SPH :
                   2483:        {
                   2484:            if (type != 'O')
                   2485:            {
                   2486:                incrementation_atomique(s_objet);
                   2487:                return(s_objet);
                   2488:            }
                   2489: 
                   2490:            if ((s_nouvel_objet = allocation(s_etat_processus, SPH)) == NULL)
                   2491:            {
                   2492:                return(NULL);
                   2493:            }
                   2494: 
                   2495:            if (((*((struct_semaphore *) (*s_nouvel_objet).objet)).nom =
                   2496:                    malloc((strlen((*((struct_semaphore *) (*s_objet).objet))
                   2497:                    .nom) + 1) * sizeof(unsigned char))) == NULL)
                   2498:            {
                   2499:                free((*s_nouvel_objet).objet);
                   2500:                free(s_nouvel_objet);
                   2501:                return(NULL);
                   2502:            }
                   2503: 
1.75      bertrand 2504:            (*((struct_semaphore *) (*s_nouvel_objet).objet)).semaphore =
                   2505:                    (*((struct_semaphore *) (*s_objet).objet)).semaphore;
1.1       bertrand 2506:            strcpy((*((struct_semaphore *) (*s_nouvel_objet).objet)).nom,
                   2507:                    (*((struct_semaphore *) (*s_objet).objet)).nom);
                   2508:            break;
                   2509:        }
                   2510: 
                   2511:        case SQL :
                   2512:        {
                   2513:            if (type != 'O')
                   2514:            {
                   2515:                incrementation_atomique(s_objet);
                   2516:                return(s_objet);
                   2517:            }
                   2518: 
                   2519:            if ((s_nouvel_objet = allocation(s_etat_processus, SQL)) == NULL)
                   2520:            {
                   2521:                return(NULL);
                   2522:            }
                   2523: 
                   2524:            (*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).pid =
                   2525:                    (*((struct_connecteur_sql *) (*s_objet).objet)).pid;
                   2526:            (*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).tid =
                   2527:                    (*((struct_connecteur_sql *) (*s_objet).objet)).tid;
                   2528:            (*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).descripteur =
                   2529:                    (*((struct_connecteur_sql *) (*s_objet).objet)).descripteur;
                   2530: 
                   2531:            if (((*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).type =
                   2532:                    malloc((strlen((*((struct_connecteur_sql *)
                   2533:                    (*s_objet).objet)).type) + 1) * sizeof(unsigned char)))
                   2534:                    == NULL)
                   2535:            {
                   2536:                free(s_nouvel_objet);
                   2537:                return(NULL);
                   2538:            }
                   2539: 
                   2540:            strcpy((*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).type,
                   2541:                    (*((struct_connecteur_sql *) (*s_objet).objet)).type);
                   2542: 
                   2543:            if ((*((struct_connecteur_sql *) (*s_objet).objet)).locale != NULL)
                   2544:            {
                   2545:                if (((*((struct_connecteur_sql *) (*s_nouvel_objet).objet))
                   2546:                        .locale = malloc((strlen((*((struct_connecteur_sql *)
                   2547:                        (*s_objet).objet)).locale) + 1) *
                   2548:                        sizeof(unsigned char))) == NULL)
                   2549:                {
                   2550:                    free((*((struct_connecteur_sql *) (*s_nouvel_objet).objet))
                   2551:                            .locale);
                   2552:                    free(s_nouvel_objet);
                   2553:                    return(NULL);
                   2554:                }
                   2555: 
                   2556:                strcpy((*((struct_connecteur_sql *) (*s_nouvel_objet).objet))
                   2557:                        .locale, (*((struct_connecteur_sql *)
                   2558:                        (*s_objet).objet)).locale);
                   2559:            }
                   2560:            else
                   2561:            {
                   2562:                (*((struct_connecteur_sql *) (*s_nouvel_objet).objet)).locale
                   2563:                        = NULL;
                   2564:            }
                   2565: 
                   2566:            break;
                   2567:        }
                   2568: 
                   2569:        case TBL :
                   2570:        {
                   2571:            if (type != 'P')
                   2572:            {
                   2573:                if ((s_nouvel_objet = allocation(s_etat_processus, TBL))
                   2574:                        == NULL)
                   2575:                {
                   2576:                    return(NULL);
                   2577:                }
                   2578: 
                   2579:                (*((struct_tableau *) (*s_nouvel_objet).objet))
                   2580:                        .nombre_elements = (*((struct_tableau *)
                   2581:                        (*s_objet).objet)).nombre_elements;
                   2582: 
                   2583:                if (((*((struct_tableau *) (*s_nouvel_objet).objet)).elements =
                   2584:                        malloc((*((struct_tableau *) (*s_objet).objet))
                   2585:                        .nombre_elements * sizeof(struct_objet *))) == NULL)
                   2586:                {
                   2587:                    return(NULL);
                   2588:                }
                   2589: 
                   2590:                for(i = 0; i < (*((struct_tableau *) (*s_objet).objet))
                   2591:                        .nombre_elements; i++)
                   2592:                {
                   2593:                    if (((*((struct_tableau *) (*s_nouvel_objet).objet))
                   2594:                            .elements[i] = copie_objet(s_etat_processus,
                   2595:                            (*((struct_tableau *) (*s_objet).objet))
                   2596:                            .elements[i], type)) == NULL)
                   2597:                    {
                   2598:                        for(j = 0; j < i; j++)
                   2599:                        {
                   2600:                            liberation(s_etat_processus, (*((struct_tableau *)
                   2601:                                    (*s_nouvel_objet).objet)).elements[j]);
                   2602:                        }
                   2603: 
                   2604:                        free((*((struct_tableau *) (*s_nouvel_objet).objet))
                   2605:                                .elements);
                   2606:                        free((*s_nouvel_objet).objet);
                   2607:                        free(s_nouvel_objet);
                   2608: 
                   2609:                        return(NULL);
                   2610:                    }
                   2611:                }
                   2612:            }
                   2613:            else
                   2614:            {
                   2615:                incrementation_atomique(s_objet);
                   2616: 
                   2617:                for(i = 0; i < (*((struct_tableau *) (*s_objet).objet))
                   2618:                        .nombre_elements; i++)
                   2619:                {
                   2620:                    (*((struct_tableau *) (*s_objet).objet)).elements[i] =
                   2621:                            copie_objet(s_etat_processus, (*((struct_tableau *)
                   2622:                            (*s_objet).objet)).elements[i], 'P');
                   2623:                }
                   2624: 
                   2625:                return(s_objet);
                   2626:            }
                   2627: 
                   2628:            break;
                   2629:        }
                   2630: 
                   2631:        case VIN :
                   2632:        {
                   2633:            if (type != 'O')
                   2634:            {
                   2635:                incrementation_atomique(s_objet);
                   2636:                return(s_objet);
                   2637:            }
                   2638: 
                   2639:            if ((s_nouvel_objet = allocation(s_etat_processus, VIN)) == NULL)
                   2640:            {
                   2641:                return(NULL);
                   2642:            }
                   2643: 
                   2644:            (*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau = 
                   2645:                    (void *) ((integer8 *) malloc(
                   2646:                    ((*((struct_vecteur *) ((*s_objet).objet))).taille)
                   2647:                    * sizeof(integer8)));
                   2648: 
                   2649:            if ((*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau
                   2650:                    == NULL)
                   2651:            {
                   2652:                free((*s_nouvel_objet).objet);
                   2653:                free(s_nouvel_objet);
                   2654:                return(NULL);
                   2655:            }
                   2656: 
                   2657:            (*((struct_vecteur *) ((*s_nouvel_objet).objet))).taille =
                   2658:                    (*((struct_vecteur *) ((*s_objet).objet))).taille;
                   2659:            (*((struct_vecteur *) ((*s_nouvel_objet).objet))).type =
                   2660:                    (*((struct_vecteur *) ((*s_objet).objet))).type;
                   2661: 
                   2662:            for(i = 0; i < (*((struct_vecteur *) ((*s_objet).objet))).taille;
                   2663:                    i++)
                   2664:            {
                   2665:                ((integer8 *) ((*((struct_vecteur *)
                   2666:                        ((*s_nouvel_objet).objet))).tableau))[i] =
                   2667:                        ((integer8 *) ((*((struct_vecteur *)
                   2668:                        ((*s_objet).objet))).tableau))[i];
                   2669:            }
                   2670: 
                   2671:            break;
                   2672:        }
                   2673: 
                   2674:        case VCX :
                   2675:        {
                   2676:            if (type != 'O')
                   2677:            {
                   2678:                incrementation_atomique(s_objet);
                   2679:                return(s_objet);
                   2680:            }
                   2681: 
                   2682:            if ((s_nouvel_objet = allocation(s_etat_processus, VCX)) == NULL)
                   2683:            {
                   2684:                return(NULL);
                   2685:            }
                   2686: 
                   2687:            (*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau = 
                   2688:                    (void *) ((struct_complexe16 *) malloc(
                   2689:                    ((*((struct_vecteur *) ((*s_objet).objet))).taille)
                   2690:                    * sizeof(struct_complexe16)));
                   2691: 
                   2692:            if ((*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau
                   2693:                    == NULL)
                   2694:            {
                   2695:                free((*s_nouvel_objet).objet);
                   2696:                free(s_nouvel_objet);
                   2697:                return(NULL);
                   2698:            }
                   2699: 
                   2700:            (*((struct_vecteur *) ((*s_nouvel_objet).objet))).taille =
                   2701:                    (*((struct_vecteur *) ((*s_objet).objet))).taille;
                   2702:            (*((struct_vecteur *) ((*s_nouvel_objet).objet))).type =
                   2703:                    (*((struct_vecteur *) ((*s_objet).objet))).type;
                   2704: 
                   2705:            for(i = 0; i < (*((struct_vecteur *) ((*s_objet).objet))).taille;
                   2706:                    i++)
                   2707:            {
                   2708:                ((struct_complexe16 *) ((*((struct_vecteur *)
                   2709:                        ((*s_nouvel_objet).objet))).tableau))[i] =
                   2710:                        ((struct_complexe16 *) ((*((struct_vecteur *)
                   2711:                        ((*s_objet).objet))).tableau))[i];
                   2712:            }
                   2713: 
                   2714:            break;
                   2715:        }
                   2716: 
                   2717:        case VRL :
                   2718:        {
                   2719:            if (type != 'O')
                   2720:            {
                   2721:                incrementation_atomique(s_objet);
                   2722:                return(s_objet);
                   2723:            }
                   2724: 
                   2725:            if ((s_nouvel_objet = allocation(s_etat_processus, VRL)) == NULL)
                   2726:            {
                   2727:                return(NULL);
                   2728:            }
                   2729: 
                   2730:            (*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau = 
                   2731:                    (void *) ((real8 *) malloc(
                   2732:                    ((*((struct_vecteur *) ((*s_objet).objet))).taille)
                   2733:                    * sizeof(real8)));
                   2734: 
                   2735:            if ((*((struct_vecteur *) ((*s_nouvel_objet).objet))).tableau
                   2736:                    == NULL)
                   2737:            {
                   2738:                free((*s_nouvel_objet).objet);
                   2739:                free(s_nouvel_objet);
                   2740:                return(NULL);
                   2741:            }
                   2742: 
                   2743:            (*((struct_vecteur *) ((*s_nouvel_objet).objet))).taille =
                   2744:                    (*((struct_vecteur *) ((*s_objet).objet))).taille;
                   2745:            (*((struct_vecteur *) ((*s_nouvel_objet).objet))).type =
                   2746:                    (*((struct_vecteur *) ((*s_objet).objet))).type;
                   2747: 
                   2748:            for(i = 0; i < (*((struct_vecteur *) ((*s_objet).objet))).taille;
                   2749:                    i++)
                   2750:            {
                   2751:                ((real8 *) ((*((struct_vecteur *)
                   2752:                        ((*s_nouvel_objet).objet))).tableau))[i] =
                   2753:                        ((real8 *) ((*((struct_vecteur *)
                   2754:                        ((*s_objet).objet))).tableau))[i];
                   2755:            }
                   2756: 
                   2757:            break;
                   2758:        }
                   2759: 
                   2760:        default :
                   2761:        {
                   2762:            return(NULL);
                   2763:        }
                   2764:    }
                   2765: 
                   2766:    return(s_nouvel_objet);
                   2767: 
                   2768: #undef return
                   2769: }
                   2770: 
                   2771: 
                   2772: /*
                   2773: ================================================================================
                   2774:   Routine de copie d'une structure de description d'un processus
                   2775: ================================================================================
                   2776:   Entrées : pointeur sur la structure de description d'un processus
                   2777: --------------------------------------------------------------------------------
                   2778:   Sorties : structure identique (tous les objets sont copiés)
                   2779: --------------------------------------------------------------------------------
                   2780:   Effets de bord : néant
                   2781: ================================================================================
                   2782: */
                   2783: 
                   2784: struct_processus *
                   2785: copie_etat_processus(struct_processus *s_etat_processus)
                   2786: {
                   2787:    pthread_mutexattr_t             attributs_mutex;
                   2788: 
                   2789:    struct_liste_chainee            *l_element_lecture;
                   2790:    struct_liste_chainee            *l_element_precedent;
                   2791:    struct_liste_chainee            *l_element_suivant;
                   2792: 
                   2793:    struct_processus                *s_nouvel_etat_processus;
                   2794: 
                   2795:    unsigned long                   i;
                   2796: 
                   2797:    if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
                   2798:    {
                   2799:        (*s_etat_processus).erreur_systeme = d_es_processus;
                   2800:        return(NULL);
                   2801:    }
                   2802: 
                   2803:    if ((s_nouvel_etat_processus = malloc(sizeof(struct_processus))) == NULL)
                   2804:    {
                   2805:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2806:        return(NULL);
                   2807:    }
                   2808: 
                   2809:    (*s_nouvel_etat_processus) = (*s_etat_processus);
                   2810: 
                   2811:    // On réinitialise l'allocateur.
                   2812: 
                   2813:    initialisation_allocateur(s_nouvel_etat_processus);
                   2814: 
                   2815:    /*
                   2816:     * (*s_etat_processus).definition_chainee,
                   2817:     * (*s_etat_processus).nom_fichier_source,
                   2818:     * (*s_etat_processus).nom_fichier_historique et
                   2819:     * (*s_etat_processus).chemin_fichier_temporaires
                   2820:     * n'ont aucune raison de changer.
                   2821:     */
                   2822: 
1.67      bertrand 2823:    pthread_mutexattr_init(&attributs_mutex);
                   2824:    pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
1.84      bertrand 2825:    (*s_nouvel_etat_processus).sections_critiques = 0;
1.69      bertrand 2826: 
1.71      bertrand 2827:    // Les sémaphores sont initialisés dans le nouveau thread. Il
                   2828:    // s'agit d'une limitation de l'implantation de l'émulation
                   2829:    // de sem_init().
1.1       bertrand 2830: 
1.60      bertrand 2831:    initialisation_contexte_cas(s_etat_processus);
                   2832: 
1.1       bertrand 2833:    (*s_nouvel_etat_processus).var_volatile_processus_pere = 0;
1.39      bertrand 2834:    (*s_nouvel_etat_processus).var_volatile_processus_racine = 0;
1.1       bertrand 2835:    (*s_nouvel_etat_processus).fichiers_graphiques = NULL;
                   2836:    (*s_nouvel_etat_processus).entree_standard = NULL;
                   2837:    (*s_nouvel_etat_processus).s_marques = NULL;
                   2838:    (*s_nouvel_etat_processus).requete_nouveau_plan = d_vrai;
                   2839:    (*s_nouvel_etat_processus).mise_a_jour_trace_requise = d_faux;
                   2840:    (*s_nouvel_etat_processus).nom_fichier_impression = NULL;
                   2841:    (*s_nouvel_etat_processus).expression_courante = NULL;
                   2842:    (*s_nouvel_etat_processus).objet_courant = NULL;
                   2843:    (*s_nouvel_etat_processus).processus_detache = d_faux;
1.3       bertrand 2844:    (*s_nouvel_etat_processus).evaluation_forcee = 'N';
1.1       bertrand 2845: 
                   2846:    (*s_nouvel_etat_processus).nombre_objets_envoyes_non_lus = 0;
                   2847:    (*s_nouvel_etat_processus).nombre_objets_injectes = 0;
                   2848:    (*s_nouvel_etat_processus).presence_fusible = d_faux;
                   2849:    (*s_nouvel_etat_processus).thread_fusible = 0;
                   2850:    (*s_nouvel_etat_processus).niveau_initial =
                   2851:            (*s_etat_processus).niveau_courant;
                   2852:    (*s_nouvel_etat_processus).presence_pipes = d_faux;
                   2853:    (*s_nouvel_etat_processus).debug_programme = d_faux;
                   2854:    (*s_nouvel_etat_processus).s_fichiers = NULL;
                   2855:    (*s_nouvel_etat_processus).s_connecteurs_sql = NULL;
                   2856: 
                   2857:    // On réinitialise toutes les interruptions.
                   2858: 
                   2859:    (*s_nouvel_etat_processus).traitement_interruption = 'N';
                   2860:    (*s_nouvel_etat_processus).traitement_interruptible = 'Y';
                   2861:    (*s_nouvel_etat_processus).nombre_interruptions_en_queue = 0;
                   2862:    (*s_nouvel_etat_processus).nombre_interruptions_non_affectees = 0;
                   2863: 
1.14      bertrand 2864:    (*s_nouvel_etat_processus).at_exit = NULL;
1.32      bertrand 2865:    (*s_nouvel_etat_processus).at_poke = NULL;
                   2866:    (*s_nouvel_etat_processus).traitement_at_poke = 'N';
1.13      bertrand 2867: 
1.1       bertrand 2868:    for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++)
                   2869:    {
                   2870:        (*s_nouvel_etat_processus).corps_interruptions[i] = NULL;
                   2871:        (*s_nouvel_etat_processus).masque_interruptions[i] = 'N';
                   2872:        (*s_nouvel_etat_processus).queue_interruptions[i] = 0;
                   2873:        (*s_nouvel_etat_processus).pile_origine_interruptions[i] = NULL;
                   2874:    }
                   2875: 
                   2876:    if ((*s_nouvel_etat_processus).generateur_aleatoire != NULL)
                   2877:    {
1.35      bertrand 2878:        if (((*s_nouvel_etat_processus).generateur_aleatoire =
                   2879:                gsl_rng_clone((*s_etat_processus).generateur_aleatoire))
                   2880:                == NULL)
                   2881:        {
                   2882:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2883:            return(NULL);
                   2884:        }
                   2885: 
                   2886:        gsl_rng_set((*s_nouvel_etat_processus).generateur_aleatoire,
                   2887:                gsl_rng_get((*s_etat_processus).generateur_aleatoire));
1.1       bertrand 2888:    }
                   2889: 
                   2890:    // Copie de la localisation
                   2891: 
                   2892:    if (((*s_nouvel_etat_processus).localisation = malloc((strlen(
                   2893:            (*s_etat_processus).localisation) + 1) * sizeof(unsigned char)))
                   2894:            == NULL)
                   2895:    {
                   2896:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2897:        return(NULL);
                   2898:    }
                   2899: 
                   2900:    strcpy((*s_nouvel_etat_processus).localisation,
                   2901:            (*s_etat_processus).localisation);
                   2902: 
                   2903:    if ((*s_etat_processus).indep != NULL)
                   2904:    {
                   2905:        if (((*s_nouvel_etat_processus).indep = copie_objet(s_etat_processus,
                   2906:                (*s_etat_processus).indep, 'P')) == NULL)
                   2907:        {
                   2908:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2909:            {
                   2910:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   2911:                return(NULL);
                   2912:            }
                   2913: 
                   2914:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2915:            return(NULL);
                   2916:        }
                   2917:    }
                   2918:    else
                   2919:    {
                   2920:        (*s_nouvel_etat_processus).indep = NULL;
                   2921:    }
                   2922: 
                   2923:    if ((*s_etat_processus).depend != NULL)
                   2924:    {
                   2925:        if (((*s_nouvel_etat_processus).depend = copie_objet(s_etat_processus, 
                   2926:                (*s_etat_processus).depend, 'P')) == NULL)
                   2927:        {
                   2928:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2929:            {
                   2930:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   2931:                return(NULL);
                   2932:            }
                   2933: 
                   2934:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2935:            return(NULL);
                   2936:        }
                   2937:    }
                   2938:    else
                   2939:    {
                   2940:        (*s_nouvel_etat_processus).depend = NULL;
                   2941:    }
                   2942: 
                   2943:    if ((*s_etat_processus).parametres_courbes_de_niveau != NULL)
                   2944:    {
                   2945:        if (((*s_nouvel_etat_processus).parametres_courbes_de_niveau =
                   2946:                copie_objet(s_etat_processus, (*s_etat_processus)
                   2947:                .parametres_courbes_de_niveau, 'P')) == NULL)
                   2948:        {
                   2949:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2950:            {
                   2951:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   2952:                return(NULL);
                   2953:            }
                   2954: 
                   2955:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2956:            return(NULL);
                   2957:        }
                   2958:    }
                   2959:    else
                   2960:    {
                   2961:        (*s_nouvel_etat_processus).parametres_courbes_de_niveau = NULL;
                   2962:    }
                   2963: 
                   2964:    (*s_nouvel_etat_processus).instruction_derniere_erreur = NULL;
                   2965: 
                   2966:    if (((*s_etat_processus).instruction_courante != NULL) &&
                   2967:            (*s_etat_processus).evaluation_expression_compilee == 'N')
                   2968:    {
                   2969:        if (((*s_nouvel_etat_processus).instruction_courante = malloc((strlen(
                   2970:                (*s_etat_processus).instruction_courante) + 1) *
                   2971:                sizeof(unsigned char))) == NULL)
                   2972:        {
                   2973:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2974:            {
                   2975:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   2976:                return(NULL);
                   2977:            }
                   2978: 
                   2979:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   2980:            return(NULL);
                   2981:        }
                   2982: 
                   2983:        strcpy((*s_nouvel_etat_processus).instruction_courante,
                   2984:                (*s_etat_processus).instruction_courante);
                   2985:    }
                   2986:    else
                   2987:    {
                   2988:        (*s_nouvel_etat_processus).instruction_courante = NULL;
                   2989:    }
                   2990: 
                   2991:    if ((*s_etat_processus).label_x != NULL)
                   2992:    {
                   2993:        if (((*s_nouvel_etat_processus).label_x = malloc((strlen(
                   2994:                (*s_etat_processus).label_x) + 1) *
                   2995:                sizeof(unsigned char))) == NULL)
                   2996:        {
                   2997:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   2998:            {
                   2999:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3000:                return(NULL);
                   3001:            }
                   3002: 
                   3003:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3004:            return(NULL);
                   3005:        }
                   3006: 
                   3007:        strcpy((*s_nouvel_etat_processus).label_x,
                   3008:                (*s_etat_processus).label_x);
                   3009:    }
                   3010:    else
                   3011:    {
                   3012:        (*s_nouvel_etat_processus).label_x = NULL;
                   3013:    }
                   3014: 
                   3015:    if ((*s_etat_processus).label_y != NULL)
                   3016:    {
                   3017:        if (((*s_nouvel_etat_processus).label_y = malloc((strlen(
                   3018:                (*s_etat_processus).label_y) + 1) *
                   3019:                sizeof(unsigned char))) == NULL)
                   3020:        {
                   3021:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3022:            {
                   3023:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3024:                return(NULL);
                   3025:            }
                   3026: 
                   3027:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3028:            return(NULL);
                   3029:        }
                   3030: 
                   3031:        strcpy((*s_nouvel_etat_processus).label_y,
                   3032:                (*s_etat_processus).label_y);
                   3033:    }
                   3034:    else
                   3035:    {
                   3036:        (*s_nouvel_etat_processus).label_y = NULL;
                   3037:    }
                   3038: 
                   3039:    if ((*s_etat_processus).label_z != NULL)
                   3040:    {
                   3041:        if (((*s_nouvel_etat_processus).label_z = malloc((strlen(
                   3042:                (*s_etat_processus).label_z) + 1) *
                   3043:                sizeof(unsigned char))) == NULL)
                   3044:        {
                   3045:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3046:            {
                   3047:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3048:                return(NULL);
                   3049:            }
                   3050: 
                   3051:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3052:            return(NULL);
                   3053:        }
                   3054: 
                   3055:        strcpy((*s_nouvel_etat_processus).label_z,
                   3056:                (*s_etat_processus).label_z);
                   3057:    }
                   3058:    else
                   3059:    {
                   3060:        (*s_nouvel_etat_processus).label_z = NULL;
                   3061:    }
                   3062: 
                   3063:    if ((*s_etat_processus).titre != NULL)
                   3064:    {
                   3065:        if (((*s_nouvel_etat_processus).titre = malloc((strlen(
                   3066:                (*s_etat_processus).titre) + 1) *
                   3067:                sizeof(unsigned char))) == NULL)
                   3068:        {
                   3069:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3070:            {
                   3071:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3072:                return(NULL);
                   3073:            }
                   3074: 
                   3075:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3076:            return(NULL);
                   3077:        }
                   3078: 
                   3079:        strcpy((*s_nouvel_etat_processus).titre,
                   3080:                (*s_etat_processus).titre);
                   3081:    }
                   3082:    else
                   3083:    {
                   3084:        (*s_nouvel_etat_processus).titre = NULL;
                   3085:    }
                   3086: 
                   3087:    if ((*s_etat_processus).legende != NULL)
                   3088:    {
                   3089:        if (((*s_nouvel_etat_processus).legende = malloc((strlen(
                   3090:                (*s_etat_processus).legende) + 1) *
                   3091:                sizeof(unsigned char))) == NULL)
                   3092:        {
                   3093:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3094:            {
                   3095:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3096:                return(NULL);
                   3097:            }
                   3098: 
                   3099:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3100:            return(NULL);
                   3101:        }
                   3102: 
                   3103:        strcpy((*s_nouvel_etat_processus).legende,
                   3104:                (*s_etat_processus).legende);
                   3105:    }
                   3106:    else
                   3107:    {
                   3108:        (*s_nouvel_etat_processus).legende = NULL;
                   3109:    }
                   3110: 
                   3111:    /*
                   3112:     * Copie de la table des variables
                   3113:     */
                   3114: 
1.51      bertrand 3115:    copie_arbre_variables(s_etat_processus, s_nouvel_etat_processus);
                   3116: 
                   3117:    if ((*s_nouvel_etat_processus).erreur_systeme != d_es)
1.1       bertrand 3118:    {
                   3119:        return(NULL);
                   3120:    }
                   3121: 
                   3122:    /*
                   3123:     * Copie de la pile opérationnelle
                   3124:     */
                   3125: 
                   3126:    (*s_nouvel_etat_processus).l_base_pile = NULL;
                   3127:    l_element_lecture = (*s_etat_processus).l_base_pile;
                   3128:    l_element_precedent = NULL;
                   3129: 
                   3130:    while(l_element_lecture != NULL)
                   3131:    {
                   3132:        if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
                   3133:        {
                   3134:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3135:            {
                   3136:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3137:                return(NULL);
                   3138:            }
                   3139: 
                   3140:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3141:            return(NULL);
                   3142:        }
                   3143: 
                   3144:        if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
                   3145:                (*l_element_lecture).donnee, 'P')) == NULL)
                   3146:        {
                   3147:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3148:            {
                   3149:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3150:                return(NULL);
                   3151:            }
                   3152: 
                   3153:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3154:            return(NULL);
                   3155:        }
                   3156: 
                   3157:        (*l_element_suivant).suivant = NULL;
                   3158: 
                   3159:        if ((*s_nouvel_etat_processus).l_base_pile == NULL)
                   3160:        {
                   3161:            (*s_nouvel_etat_processus).l_base_pile = l_element_suivant;
                   3162:        }
                   3163:        else
                   3164:        {
                   3165:            (*l_element_precedent).suivant = l_element_suivant;
                   3166:        }
                   3167: 
                   3168:        l_element_precedent = l_element_suivant;
                   3169:        l_element_lecture = (*l_element_lecture).suivant;
                   3170:    }
                   3171: 
                   3172:    /*
                   3173:     * Copie de la pile système
                   3174:     */
                   3175: 
                   3176:    (*s_nouvel_etat_processus).l_base_pile_systeme = NULL;
                   3177:    (*s_nouvel_etat_processus).hauteur_pile_systeme = 0;
                   3178: 
                   3179:    empilement_pile_systeme(s_nouvel_etat_processus);
                   3180: 
                   3181:    if ((*s_nouvel_etat_processus).erreur_systeme != d_es)
                   3182:    {
                   3183:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3184:        {
                   3185:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3186:            return(NULL);
                   3187:        }
                   3188: 
                   3189:        (*s_etat_processus).erreur_systeme =
                   3190:                (*s_nouvel_etat_processus).erreur_systeme;
                   3191:        return(NULL);
                   3192:    }
                   3193: 
                   3194:    (*(*s_nouvel_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
                   3195: 
                   3196:    /*
                   3197:     * On empile deux valeurs retour_definition pour pouvoir récupérer
                   3198:     * les variables dans le cas d'un programme compilé.
                   3199:     */
                   3200: 
                   3201:    empilement_pile_systeme(s_nouvel_etat_processus);
                   3202: 
                   3203:    if ((*s_nouvel_etat_processus).erreur_systeme != d_es)
                   3204:    {
                   3205:        if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3206:        {
                   3207:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3208:            return(NULL);
                   3209:        }
                   3210: 
                   3211:        (*s_etat_processus).erreur_systeme =
                   3212:                (*s_nouvel_etat_processus).erreur_systeme;
                   3213:        return(NULL);
                   3214:    }
                   3215: 
                   3216:    (*(*s_nouvel_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
                   3217: 
                   3218:    /*
                   3219:     * Destruction de la pile last pour le thread en cours.
                   3220:     */
                   3221: 
                   3222:    (*s_nouvel_etat_processus).l_base_pile_last = NULL;
                   3223:    (*s_nouvel_etat_processus).l_base_pile_processus = NULL;
                   3224: 
                   3225:    /*
                   3226:     * Copie des différents contextes
                   3227:     */
                   3228: 
1.66      bertrand 3229:    (*s_nouvel_etat_processus).pointeur_signal_lecture = d_faux;
                   3230:    (*s_nouvel_etat_processus).pointeur_signal_ecriture = d_faux;
                   3231: 
1.1       bertrand 3232:    (*s_nouvel_etat_processus).l_base_pile_contextes = NULL;
                   3233:    l_element_lecture = (*s_etat_processus).l_base_pile_contextes;
                   3234: 
                   3235:    while(l_element_lecture != NULL)
                   3236:    {
                   3237:        if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
                   3238:        {
                   3239:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3240:            {
                   3241:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3242:                return(NULL);
                   3243:            }
                   3244: 
                   3245:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3246:            return(NULL);
                   3247:        }
                   3248: 
                   3249:        if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
                   3250:                (*l_element_lecture).donnee, 'P')) == NULL)
                   3251:        {
                   3252:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3253:            {
                   3254:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3255:                return(NULL);
                   3256:            }
                   3257: 
                   3258:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3259:            return(NULL);
                   3260:        }
                   3261: 
                   3262:        (*l_element_suivant).suivant = NULL;
                   3263: 
                   3264:        if ((*s_nouvel_etat_processus).l_base_pile_contextes == NULL)
                   3265:        {
                   3266:            (*s_nouvel_etat_processus).l_base_pile_contextes =
                   3267:                    l_element_suivant;
                   3268:        }
                   3269:        else
                   3270:        {
                   3271:            (*l_element_precedent).suivant = l_element_suivant;
                   3272:        }
                   3273: 
                   3274:        l_element_precedent = l_element_suivant;
                   3275:        l_element_lecture = (*l_element_lecture).suivant;
                   3276:    }
                   3277: 
                   3278:    (*s_nouvel_etat_processus).l_base_pile_taille_contextes = NULL;
                   3279:    l_element_lecture = (*s_etat_processus).l_base_pile_taille_contextes;
                   3280: 
                   3281:    while(l_element_lecture != NULL)
                   3282:    {
                   3283:        if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
                   3284:        {
                   3285:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3286:            {
                   3287:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3288:                return(NULL);
                   3289:            }
                   3290: 
                   3291:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3292:            return(NULL);
                   3293:        }
                   3294: 
                   3295:        if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
                   3296:                (*l_element_lecture).donnee, 'P')) == NULL)
                   3297:        {
                   3298:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3299:            {
                   3300:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3301:                return(NULL);
                   3302:            }
                   3303: 
                   3304:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3305:            return(NULL);
                   3306:        }
                   3307: 
                   3308:        (*l_element_suivant).suivant = NULL;
                   3309: 
                   3310:        if ((*s_nouvel_etat_processus).l_base_pile_taille_contextes == NULL)
                   3311:        {
                   3312:            (*s_nouvel_etat_processus).l_base_pile_taille_contextes =
                   3313:                    l_element_suivant;
                   3314:        }
                   3315:        else
                   3316:        {
                   3317:            (*l_element_precedent).suivant = l_element_suivant;
                   3318:        }
                   3319: 
                   3320:        l_element_precedent = l_element_suivant;
                   3321:        l_element_lecture = (*l_element_lecture).suivant;
                   3322:    }
                   3323: 
                   3324:    /*
                   3325:     * Copies des piles s_sockets, s_bibliotheques et
                   3326:     * s_instructions_externes.
                   3327:     */
                   3328: 
                   3329:    (*s_nouvel_etat_processus).s_sockets = NULL;
                   3330:    l_element_lecture = (*s_etat_processus).s_sockets;
                   3331: 
                   3332:    while(l_element_lecture != NULL)
                   3333:    {
                   3334:        if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
                   3335:        {
                   3336:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3337:            {
                   3338:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3339:                return(NULL);
                   3340:            }
                   3341: 
                   3342:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3343:            return(NULL);
                   3344:        }
                   3345: 
                   3346:        if (((*l_element_suivant).donnee = copie_objet(s_etat_processus,
                   3347:                (*l_element_lecture).donnee, 'P')) == NULL)
                   3348:        {
                   3349:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3350:            {
                   3351:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3352:                return(NULL);
                   3353:            }
                   3354: 
                   3355:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3356:            return(NULL);
                   3357:        }
                   3358: 
                   3359:        (*l_element_suivant).suivant = NULL;
                   3360: 
                   3361:        if ((*s_nouvel_etat_processus).s_sockets == NULL)
                   3362:        {
                   3363:            (*s_nouvel_etat_processus).s_sockets = l_element_suivant;
                   3364:        }
                   3365:        else
                   3366:        {
                   3367:            (*l_element_precedent).suivant = l_element_suivant;
                   3368:        }
                   3369: 
                   3370:        l_element_precedent = l_element_suivant;
                   3371:        l_element_lecture = (*l_element_lecture).suivant;
                   3372:    }
                   3373: 
                   3374:    (*s_nouvel_etat_processus).s_bibliotheques = NULL;
                   3375:    l_element_precedent = NULL;
                   3376:    l_element_lecture = (*s_etat_processus).s_bibliotheques;
                   3377: 
                   3378:    while(l_element_lecture != NULL)
                   3379:    {
                   3380:        if ((l_element_suivant = malloc(sizeof(struct_liste_chainee))) == NULL)
                   3381:        {
                   3382:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3383:            {
                   3384:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3385:                return(NULL);
                   3386:            }
                   3387: 
                   3388:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3389:            return(NULL);
                   3390:        }
                   3391: 
                   3392:        if (((*l_element_suivant).donnee = malloc(sizeof(struct_bibliotheque)))
                   3393:                == NULL)
                   3394:        {
                   3395:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3396:            return(NULL);
                   3397:        }
                   3398: 
                   3399:        (*((struct_bibliotheque *) (*l_element_suivant).donnee)).descripteur 
                   3400:                = (*((struct_bibliotheque *) (*l_element_lecture).donnee))
                   3401:                .descripteur;
                   3402:        (*((struct_bibliotheque *) (*l_element_suivant).donnee)).pid 
                   3403:                = (*((struct_bibliotheque *) (*l_element_lecture).donnee)).pid;
                   3404:        (*((struct_bibliotheque *) (*l_element_suivant).donnee)).tid 
                   3405:                = (*((struct_bibliotheque *) (*l_element_lecture).donnee)).tid;
                   3406: 
                   3407:        if (((*((struct_bibliotheque *) (*l_element_suivant).donnee)).nom =
                   3408:                malloc((strlen((*((struct_bibliotheque *) (*l_element_lecture)
                   3409:                .donnee)).nom) + 1) * sizeof(unsigned char))) == NULL)
                   3410:        {
                   3411:            if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3412:            {
                   3413:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3414:                return(NULL);
                   3415:            }
                   3416: 
                   3417:            (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
                   3418:            return(NULL);
                   3419:        }
                   3420: 
                   3421:        strcpy((*((struct_bibliotheque *) (*l_element_suivant).donnee)).nom,
                   3422:                (*((struct_bibliotheque *) (*l_element_lecture).donnee)).nom);
                   3423: 
                   3424:        (*l_element_suivant).suivant = NULL;
                   3425: 
                   3426:        if ((*s_nouvel_etat_processus).s_bibliotheques == NULL)
                   3427:        {
                   3428:            (*s_nouvel_etat_processus).s_bibliotheques = l_element_suivant;
                   3429:        }
                   3430:        else
                   3431:        {
                   3432:            (*l_element_precedent).suivant = l_element_suivant;
                   3433:        }
                   3434: 
                   3435:        l_element_precedent = l_element_suivant;
                   3436:        l_element_lecture = (*l_element_lecture).suivant;
                   3437:    }
                   3438: 
                   3439:    if ((*s_etat_processus).nombre_instructions_externes != 0)
                   3440:    {
                   3441:        if (((*s_nouvel_etat_processus).s_instructions_externes =
                   3442:                malloc((*s_etat_processus).nombre_instructions_externes *
                   3443:                sizeof(struct_instruction_externe))) == NULL)
                   3444:        {
                   3445:            (*s_etat_processus).erreur_systeme = d_es_processus;
                   3446:            return(NULL);
                   3447:        }
                   3448: 
                   3449:        for(i = 0; i < (*s_etat_processus).nombre_instructions_externes; i++)
                   3450:        {
                   3451:            if (((*s_nouvel_etat_processus).s_instructions_externes[i].nom =
                   3452:                    malloc((strlen((*s_etat_processus).s_instructions_externes
                   3453:                    [i].nom) + 1) * sizeof(unsigned char))) == NULL)
                   3454:            {
                   3455:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3456:                return(NULL);
                   3457:            }
                   3458: 
                   3459:            strcpy((*s_nouvel_etat_processus).s_instructions_externes[i].nom,
                   3460:                    (*s_etat_processus).s_instructions_externes[i].nom);
                   3461: 
                   3462:            if (((*s_nouvel_etat_processus).s_instructions_externes[i]
                   3463:                    .nom_bibliotheque = malloc((strlen((*s_etat_processus)
                   3464:                    .s_instructions_externes[i].nom_bibliotheque) + 1) *
                   3465:                    sizeof(unsigned char))) == NULL)
                   3466:            {
                   3467:                (*s_etat_processus).erreur_systeme = d_es_processus;
                   3468:                return(NULL);
                   3469:            }
                   3470: 
                   3471:            strcpy((*s_nouvel_etat_processus).s_instructions_externes[i]
                   3472:                    .nom_bibliotheque, (*s_etat_processus)
                   3473:                    .s_instructions_externes[i].nom_bibliotheque);
                   3474: 
                   3475:            (*s_nouvel_etat_processus).s_instructions_externes[i]
                   3476:                    .descripteur_bibliotheque = (*s_etat_processus)
                   3477:                    .s_instructions_externes[i].descripteur_bibliotheque;
                   3478:        }
                   3479:    }
                   3480:    else
                   3481:    {
                   3482:        (*s_nouvel_etat_processus).s_instructions_externes = NULL;
                   3483:    }
                   3484: 
                   3485:    pthread_mutexattr_init(&attributs_mutex);
                   3486:    pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
                   3487:    pthread_mutex_init(&((*s_nouvel_etat_processus).mutex), &attributs_mutex);
                   3488:    pthread_mutexattr_destroy(&attributs_mutex);
                   3489: 
1.28      bertrand 3490:    pthread_mutexattr_init(&attributs_mutex);
                   3491:    pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL);
                   3492:    pthread_mutex_init(&((*s_nouvel_etat_processus).mutex_allocation),
                   3493:            &attributs_mutex);
                   3494:    pthread_mutexattr_destroy(&attributs_mutex);
                   3495: 
1.1       bertrand 3496:    if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
                   3497:    {
                   3498:        (*s_etat_processus).erreur_systeme = d_es_processus;
                   3499:        return(NULL);
                   3500:    }
                   3501: 
                   3502:    return(s_nouvel_etat_processus);
                   3503: 
                   3504: #undef return
                   3505: }
                   3506: 
1.6       bertrand 3507: 
                   3508: /*
                   3509: ================================================================================
                   3510:   Routines de debug
                   3511: ================================================================================
                   3512:   entrées :
                   3513: --------------------------------------------------------------------------------
                   3514:   sorties :
                   3515: --------------------------------------------------------------------------------
                   3516:   effets de bord : néant
                   3517: ================================================================================
                   3518: */
                   3519: 
                   3520: #ifdef DEBUG_MEMOIRE
                   3521: 
                   3522: #undef malloc
                   3523: #undef realloc
                   3524: #undef free
1.21      bertrand 3525: #undef fork
1.6       bertrand 3526: 
                   3527: #ifdef return
                   3528: #  undef return
                   3529: #endif
                   3530: 
1.16      bertrand 3531: #ifdef __BACKTRACE
1.21      bertrand 3532: #define    PROFONDEUR_PILE 64
1.6       bertrand 3533: #define return(a) { if (a == NULL) \
1.21      bertrand 3534:        { BACKTRACE(PROFONDEUR_PILE); \
                   3535:        fprintf(stderr, ">>> MEDITATION %d\n", __LINE__); } \
1.6       bertrand 3536:        return(a); } while(0)
1.16      bertrand 3537: #endif
1.6       bertrand 3538: 
1.21      bertrand 3539: #undef fprintf
                   3540: #define check(a, b) ((strcmp(#a, fonction) == 0) && (ligne == b))
                   3541: #undef CORE_DUMP
                   3542: 
1.6       bertrand 3543: typedef struct memoire
                   3544: {
                   3545:    void                *pointeur;
                   3546:    unsigned char       *fonction;
                   3547:    unsigned char       *argument;
                   3548:    unsigned long       ligne;
                   3549:    size_t              taille;
                   3550:    unsigned long long  ordre;
1.16      bertrand 3551: #  ifdef __BACKTRACE
                   3552:    void                *pile[PROFONDEUR_PILE];
                   3553:    int                 profondeur;
                   3554: #  endif
1.6       bertrand 3555:    struct memoire      *suivant;
                   3556: } struct_memoire;
                   3557: 
                   3558: static struct_memoire      *debug = NULL;
                   3559: static unsigned long long  ordre = 0;
1.21      bertrand 3560: static pthread_mutex_t     mutex_allocation;
                   3561: 
                   3562: void
                   3563: debug_memoire_initialisation()
                   3564: {
                   3565:    pthread_mutexattr_t         attributs_mutex;
                   3566: 
                   3567:    pthread_mutexattr_init(&attributs_mutex);
                   3568:    pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_RECURSIVE);
                   3569:    pthread_mutex_init(&mutex_allocation, &attributs_mutex);
                   3570:    pthread_mutexattr_destroy(&attributs_mutex);
1.6       bertrand 3571: 
1.21      bertrand 3572:    return;
                   3573: }
1.6       bertrand 3574: 
                   3575: void *
                   3576: debug_memoire_ajout(size_t taille, const unsigned char *fonction,
                   3577:        unsigned long ligne, const unsigned char *argument)
                   3578: {
                   3579:    struct_memoire  *ancienne_base;
                   3580: 
1.21      bertrand 3581:    void            *pointeur;
                   3582: 
1.6       bertrand 3583:    pthread_mutex_lock(&mutex_allocation);
                   3584: 
                   3585:    ancienne_base = debug;
                   3586: 
                   3587:    if ((debug = malloc(sizeof(struct_memoire))) == NULL)
                   3588:    {
                   3589:        pthread_mutex_unlock(&mutex_allocation);
                   3590:        return(NULL);
                   3591:    }
                   3592: 
                   3593:    if (((*debug).pointeur = malloc(taille)) == NULL)
                   3594:    {
                   3595:        pthread_mutex_unlock(&mutex_allocation);
                   3596:        return(NULL);
                   3597:    }
                   3598: 
                   3599:    (*debug).suivant = ancienne_base;
                   3600:    (*debug).ligne = ligne;
                   3601:    (*debug).taille = taille;
                   3602:    (*debug).ordre = ordre;
1.16      bertrand 3603: 
1.21      bertrand 3604:    pointeur = (*debug).pointeur;
                   3605: 
1.16      bertrand 3606: #  ifdef __BACKTRACE
                   3607:    (*debug).profondeur = backtrace((*debug).pile, PROFONDEUR_PILE);
                   3608: #  endif
1.6       bertrand 3609: 
                   3610:    if (((*debug).fonction = malloc((strlen(fonction) + 1) *
                   3611:            sizeof(unsigned char))) == NULL)
                   3612:    {
1.18      bertrand 3613:        pthread_mutex_unlock(&mutex_allocation);
1.6       bertrand 3614:        return(NULL);
                   3615:    }
                   3616: 
                   3617:    if (((*debug).argument = malloc((strlen(argument) + 1) *
                   3618:            sizeof(unsigned char))) == NULL)
                   3619:    {
1.18      bertrand 3620:        pthread_mutex_unlock(&mutex_allocation);
1.6       bertrand 3621:        return(NULL);
                   3622:    }
                   3623: 
                   3624:    strcpy((*debug).fonction, fonction);
                   3625:    strcpy((*debug).argument, argument);
                   3626: 
1.21      bertrand 3627:    memset((*debug).pointeur, 0, (*debug).taille);
                   3628: 
1.18      bertrand 3629:    pthread_mutex_unlock(&mutex_allocation);
1.6       bertrand 3630:    ordre++;
                   3631: 
1.21      bertrand 3632:    return(pointeur);
1.6       bertrand 3633: }
                   3634: 
                   3635: void *
                   3636: debug_memoire_modification(void *pointeur, size_t taille,
                   3637:        const unsigned char *fonction, unsigned long ligne,
                   3638:        const unsigned char *argument)
                   3639: {
                   3640:    struct_memoire  *element_courant;
                   3641: 
                   3642:    if (pointeur != NULL)
                   3643:    {
                   3644:        if (taille == 0)
                   3645:        {
1.21      bertrand 3646:            // Revient à free(). Il n'y a pas de parenthèses car on ne veut
                   3647:            // pas utiliser la macro return().
                   3648: 
1.6       bertrand 3649:            debug_memoire_retrait(pointeur);
1.21      bertrand 3650:            return NULL ;
1.6       bertrand 3651:        }
                   3652:        else
                   3653:        {
                   3654:            // Réallocation réelle
                   3655: 
                   3656:            pthread_mutex_lock(&mutex_allocation);
                   3657: 
                   3658:            element_courant = debug;
                   3659: 
                   3660:            while(element_courant != NULL)
                   3661:            {
                   3662:                if ((*element_courant).pointeur == pointeur)
                   3663:                {
                   3664:                    break;
                   3665:                }
                   3666: 
                   3667:                element_courant = (*element_courant).suivant;
                   3668:            }
                   3669: 
                   3670:            if (element_courant == NULL)
                   3671:            {
                   3672:                pthread_mutex_unlock(&mutex_allocation);
1.21      bertrand 3673: 
1.26      bertrand 3674:                uprintf("[%d-%llu] ILLEGAL POINTER (realloc)\n",
1.21      bertrand 3675:                        getpid(), (unsigned long long) pthread_self());
                   3676: #              ifdef __BACKTRACE
                   3677:                    BACKTRACE(PROFONDEUR_PILE);
                   3678: #              endif
                   3679: 
                   3680:                return(realloc(pointeur, taille));
1.6       bertrand 3681:            }
1.21      bertrand 3682:            else
1.6       bertrand 3683:            {
1.21      bertrand 3684:                if (((*element_courant).pointeur = realloc(pointeur, taille))
                   3685:                        == NULL)
                   3686:                {
                   3687:                    pthread_mutex_unlock(&mutex_allocation);
                   3688:                    return(NULL);
                   3689:                }
1.6       bertrand 3690: 
1.21      bertrand 3691:                (*element_courant).ligne = ligne;
                   3692:                (*element_courant).taille = taille;
                   3693:                free((*element_courant).fonction);
                   3694:                free((*element_courant).argument);
1.6       bertrand 3695: 
1.21      bertrand 3696:                if (((*element_courant).fonction = malloc((strlen(fonction)
                   3697:                        + 1) * sizeof(unsigned char))) == NULL)
                   3698:                {
                   3699:                    pthread_mutex_unlock(&mutex_allocation);
                   3700:                    return(NULL);
                   3701:                }
1.6       bertrand 3702: 
1.21      bertrand 3703:                if (((*element_courant).argument = malloc((strlen(argument)
                   3704:                        + 1) * sizeof(unsigned char))) == NULL)
                   3705:                {
                   3706:                    pthread_mutex_unlock(&mutex_allocation);
                   3707:                    return(NULL);
                   3708:                }
1.6       bertrand 3709: 
1.21      bertrand 3710:                strcpy((*element_courant).fonction, fonction);
                   3711:                strcpy((*element_courant).argument, argument);
1.6       bertrand 3712: 
1.21      bertrand 3713:                pthread_mutex_unlock(&mutex_allocation);
1.18      bertrand 3714: 
1.21      bertrand 3715:                return((*element_courant).pointeur);
                   3716:            }
1.6       bertrand 3717:        }
                   3718:    }
                   3719:    else
                   3720:    {
                   3721:        // Revient à malloc()
                   3722:        pointeur = debug_memoire_ajout(taille, fonction, ligne, argument);
                   3723:        return(pointeur);
                   3724:    }
                   3725: }
                   3726: 
                   3727: void
                   3728: debug_memoire_retrait(void *pointeur)
                   3729: {
                   3730:    struct_memoire  *element_courant;
                   3731:    struct_memoire  *element_precedent;
                   3732: 
                   3733:    pthread_mutex_lock(&mutex_allocation);
                   3734: 
                   3735:    element_courant = debug;
                   3736:    element_precedent = NULL;
                   3737: 
                   3738:    while(element_courant != NULL)
                   3739:    {
                   3740:        if ((*element_courant).pointeur == pointeur)
                   3741:        {
                   3742:            if (element_precedent == NULL)
                   3743:            {
                   3744:                debug = (*debug).suivant;
                   3745:            }
                   3746:            else
                   3747:            {
                   3748:                (*element_precedent).suivant = (*element_courant).suivant;
                   3749:            }
                   3750: 
1.21      bertrand 3751:            if (pointeur != NULL)
                   3752:            {
                   3753:                memset(pointeur, 0, (*element_courant).taille);
                   3754:            }
                   3755: 
1.6       bertrand 3756:            free((*element_courant).fonction);
                   3757:            free((*element_courant).argument);
                   3758:            free(element_courant);
                   3759: 
                   3760:            break;
                   3761:        }
                   3762: 
                   3763:        element_precedent = element_courant;
                   3764:        element_courant = (*element_courant).suivant;
                   3765:    }
                   3766: 
                   3767:    pthread_mutex_unlock(&mutex_allocation);
                   3768: 
1.21      bertrand 3769:    if (element_courant == NULL)
                   3770:    {
1.26      bertrand 3771:        uprintf("[%d-%llu] ILLEGAL POINTER (free)\n",
1.21      bertrand 3772:                getpid(), (unsigned long long) pthread_self());
                   3773: #      ifdef __BACKTRACE
                   3774:            BACKTRACE(PROFONDEUR_PILE);
                   3775: #      endif
                   3776:    }
                   3777: 
1.6       bertrand 3778:    free(pointeur);
                   3779:    return;
                   3780: }
                   3781: 
                   3782: void
1.17      bertrand 3783: debug_memoire_verification()
1.6       bertrand 3784: {
1.16      bertrand 3785: #  ifdef __BACKTRACE
                   3786:    char            **appels;
                   3787: 
                   3788:    int             j;
1.17      bertrand 3789: #  endif
1.16      bertrand 3790: 
1.6       bertrand 3791:    integer8        i;
                   3792: 
                   3793:    struct_memoire  *element_courant;
                   3794:    struct_memoire  *element_suivant;
                   3795: 
1.17      bertrand 3796:    fprintf(stderr, "[%d-%llu] LIST OF MEMORY LEAKS\n",
1.6       bertrand 3797:            getpid(), (unsigned long long) pthread_self());
                   3798: 
                   3799:    pthread_mutex_lock(&mutex_allocation);
                   3800: 
                   3801:    element_courant = debug;
                   3802:    i = 1;
                   3803: 
                   3804:    while(element_courant != NULL)
                   3805:    {
1.17      bertrand 3806:        fprintf(stderr, "[%d-%llu] MEDITATION %lld (%llu)\n", getpid(),
                   3807:                (unsigned long long) pthread_self(), i,
                   3808:                (*element_courant).ordre);
                   3809:        fprintf(stderr, "[%d-%llu] P: %p, F: %s(), L: %lu, S: %d\n",
                   3810:                getpid(), (unsigned long long) pthread_self(),
                   3811:                (*element_courant).pointeur,
                   3812:                (*element_courant).fonction, (*element_courant).ligne,
                   3813:                (int) (*element_courant).taille);
                   3814:        fprintf(stderr, "[%d-%llu] A: %s\n", getpid(),
                   3815:                (unsigned long long) pthread_self(),
                   3816:                (*element_courant).argument);
1.16      bertrand 3817: 
1.18      bertrand 3818:        if (strstr((*element_courant).argument, "sizeof(unsigned char)")
                   3819:                != NULL)
                   3820:        {
                   3821:            fprintf(stderr, "[%d-%llu] ", getpid(),
                   3822:                    (unsigned long long) pthread_self());
                   3823:            fprintf(stderr, "O: %s\n", (unsigned char *)
                   3824:                    (*element_courant).pointeur);
                   3825:        }
                   3826:        else if (strcmp((*element_courant).argument, "sizeof(struct_objet)")
                   3827:                == 0)
                   3828:        {
                   3829:            fprintf(stderr, "[%d-%llu] ", getpid(),
                   3830:                    (unsigned long long) pthread_self());
                   3831:            fprintf(stderr, "O: %d\n", (*((struct_objet *)
                   3832:                    (*element_courant).pointeur)).type);
                   3833:        }
                   3834:        else if (strcmp((*element_courant).argument,
                   3835:                "sizeof(struct_liste_chainee)") == 0)
                   3836:        {
                   3837:            fprintf(stderr, "[%d-%llu] ", getpid(),
                   3838:                    (unsigned long long) pthread_self());
                   3839:            fprintf(stderr, "O: data=%p next=%p\n", (*((struct_liste_chainee *)
                   3840:                    (*element_courant).pointeur)).donnee,
                   3841:                    (*((struct_liste_chainee *) (*element_courant).pointeur))
                   3842:                    .suivant);
                   3843:        }
                   3844: 
1.17      bertrand 3845: #      ifdef __BACKTRACE
                   3846:        appels = backtrace_symbols((*element_courant).pile,
                   3847:                (*element_courant).profondeur);
1.16      bertrand 3848: 
1.17      bertrand 3849:        fprintf(stderr, "[%d-%llu] BACKTRACE\n",
                   3850:                getpid(), (unsigned long long) pthread_self());
1.6       bertrand 3851: 
1.17      bertrand 3852:        if (appels != NULL)
                   3853:        {
                   3854:            for(j = 0; j < (*element_courant).profondeur; j++)
1.6       bertrand 3855:            {
1.17      bertrand 3856:                fprintf(stderr, "[%d-%llu] %s\n", getpid(),
                   3857:                        (unsigned long long) pthread_self(), appels[j]);
                   3858:            }
1.16      bertrand 3859: 
1.17      bertrand 3860:            free(appels);
                   3861:        }
                   3862: #      endif
1.16      bertrand 3863: 
1.17      bertrand 3864:        fprintf(stderr, "\n");
1.16      bertrand 3865: 
1.17      bertrand 3866:        i++;
1.6       bertrand 3867: 
                   3868:        element_suivant = (*element_courant).suivant;
1.17      bertrand 3869: 
                   3870: #      ifndef CORE_DUMP
1.6       bertrand 3871:        free((*element_courant).fonction);
                   3872:        free((*element_courant).argument);
                   3873:        free(element_courant);
1.17      bertrand 3874: #      endif
                   3875: 
1.6       bertrand 3876:        element_courant = element_suivant;
                   3877:    }
                   3878: 
                   3879:    pthread_mutex_unlock(&mutex_allocation);
1.21      bertrand 3880:    pthread_mutex_destroy(&mutex_allocation);
1.6       bertrand 3881: 
                   3882:    fprintf(stderr, "[%d-%llu] END OF LIST\n", getpid(),
                   3883:            (unsigned long long) pthread_self());
                   3884: 
                   3885:    return;
                   3886: }
                   3887: 
1.21      bertrand 3888: pid_t
                   3889: debug_fork()
                   3890: {
                   3891:    pid_t   pid;
                   3892: 
                   3893:    pthread_mutex_lock(&mutex_allocation);
                   3894:    pid = fork();
1.18      bertrand 3895: 
1.21      bertrand 3896:    if (pid == 0)
                   3897:    {
1.66      bertrand 3898:        liberation_queue_signaux(s_etat_processus);
                   3899:        creation_queue_signaux(s_etat_processus);
1.37      bertrand 3900: 
1.21      bertrand 3901:        pthread_mutex_destroy(&mutex_allocation);
                   3902:        debug_memoire_initialisation();
                   3903:    }
                   3904:    else
                   3905:    {
                   3906:        pthread_mutex_unlock(&mutex_allocation);
                   3907:    }
                   3908: 
                   3909:    // Pas de parenthèses pour ne pas remplacer return par sa macro.
                   3910:    return pid;
1.18      bertrand 3911: }
                   3912: 
                   3913: void
1.17      bertrand 3914: analyse_post_mortem()
                   3915: {
                   3916: #  ifdef CORE_DUMP
                   3917:    BUG(debug != NULL, uprintf("[%d-%llu] CREATE CORE DUMP FILE FOR "
                   3918:            "POST MORTEM ANALYZE\n", getpid(),
                   3919:            (unsigned long long) pthread_self()));
                   3920: #  endif
                   3921: 
                   3922:    return;
                   3923: }
                   3924: 
1.6       bertrand 3925: #endif
                   3926: 
1.1       bertrand 3927: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>