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

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

CVSweb interface <joel.bertrand@systella.fr>