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

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

CVSweb interface <joel.bertrand@systella.fr>