IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5216 for trunk/psLib/src/types


Ignore:
Timestamp:
Sep 30, 2005, 4:22:26 PM (21 years ago)
Author:
desonia
Message:

changed psArrayGet/psArraySet/psArrayRemove to do proper reference counting.

Location:
trunk/psLib/src/types
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psArray.c

    r5114 r5216  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2005-09-24 00:17:44 $
     11 *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2005-10-01 02:22:15 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4141    }
    4242
    43     psArrayElementFree(psArr);
     43    psArrayElementsFree(psArr);
    4444
    4545    psFree(psArr->data);
     
    9898{
    9999    if (array == NULL) {
    100         return array;
     100        int d = (delta > 0) ? delta : 10; // as spec'ed in SDRS.
     101        array = psArrayAlloc(d);
     102        array->n = 0;
    101103    }
    102104
     
    132134        if (psArrData[i] == data) {
    133135            memmove(&array->data[i],&array->data[i+1],(n-i-1)*sizeof(psPtr));
     136            psFree(data); // free the removed item (see Bug #449)
    134137            n--;
    135138            success = true;
     
    141144}
    142145
    143 void psArrayElementFree(psArray* psArr)
     146void psArrayElementsFree(psArray* psArr)
    144147{
    145148
     
    205208    }
    206209    psFree(array->data[position]);
    207     array->data[position] = data;
     210    array->data[position] = psMemIncrRefCounter(data);
    208211
    209212    return true;
     
    232235        return NULL;
    233236    }
    234     return array->data[position];
    235 }
    236 
    237 
    238 
    239 
     237    return psMemIncrRefCounter(array->data[position]);
     238}
  • trunk/psLib/src/types/psArray.h

    r5114 r5216  
    1 
    21/** @file  psArray.h
    32 *
     
    1211 *  @author Ross Harman, MHPCC
    1312 *
    14  *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-09-24 00:17:44 $
     13 *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2005-10-01 02:22:15 $
    1615 *
    1716 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    116115 *
    117116 */
    118 void psArrayElementFree(
     117void psArrayElementsFree(
    119118    psArray* psArr                     ///< Void pointer array to destroy.
    120119);
  • trunk/psLib/src/types/psList.c

    r5174 r5216  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-09-29 01:15:38 $
     8 *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2005-10-01 02:22:15 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    4141    pthread_mutex_lock(&list->p_lock);
    4242
    43     // remove the free function of iterators to avoid double removal from list
     43    // remove the associated iterators -- any references are invalid once psList is freed.
    4444    psArray* iterators = list->iterators;
    45     for (int i = 0; i < iterators->n; i++) {
    46         psMemSetDeallocator(iterators->data[i], NULL);
    47     }
    48 
    49     psFree(list->iterators);
     45    // ONLY orphan the iterators if the list iterators are about to be destroyed
     46    // a case where this is not the case is in psListSort.
     47    if (psMemGetRefCounter(iterators)  < 2) {
     48        for (int i = 0; i < iterators->n; i++) {
     49            // orphan iterators first to avoid any callbacks to dying list
     50            ((psListIterator*)iterators->data[i])->list = NULL;
     51            // remove all external references
     52            psMemSetRefCounter(iterators->data[i], 1);
     53        }
     54    }
     55    psFree(iterators);
    5056
    5157    for (psListElem* ptr = list->head; ptr != NULL;) {
     
    7177
    7278    // remove this iterator from the parent list
    73     psArrayRemove(iter->list->iterators,iter);
    74 
     79    if (iter->list != NULL) {
     80        psArray* iters = iter->list->iterators;
     81        for (int lcv = 0; lcv < iters->n; lcv++) {
     82            if (iters->data[lcv] == iter) {
     83                // following is done to match SDRS.
     84                iters->data[lcv] = iters->data[iters->n-1];
     85                iters->n--;
     86                break;
     87            }
     88        }
     89    }
    7590}
    7691
     
    164179    iter->mutable = mutable;
    165180
    166     // add to the list's array of iterators
    167     psArray* listIterators = list->iterators;
    168     int num = listIterators->n;
    169     if ( num >= listIterators->nalloc) {
    170         // need to resize the array to make more room for another iterator.
    171         list->iterators = psArrayRealloc(listIterators,listIterators->nalloc*2);
    172         listIterators = list->iterators;
    173     }
    174     listIterators->data[num] = iter;
    175     listIterators->n = num+1;
     181    // associate the iterator with the list
     182    list->iterators = psArrayAdd(list->iterators,0,iter);
     183    // don't want the list's array of iterators to hold a true reference
     184    psMemDecrRefCounter(iter);
    176185
    177186    if (! psListIteratorSet(iter,location)) {
    178187        psFree(iter);
    179         iter = NULL;
     188        return NULL;
    180189    }
    181190
  • trunk/psLib/src/types/psMetadataConfig.c

    r5174 r5216  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2005-09-29 01:15:38 $
     12*  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2005-10-01 02:22:15 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    995995        nextLevelInfo->name = psStringCopy(keyName);
    996996        // Add next level to levelArray
    997         levelArray = psArrayAdd(levelArray,1,nextLevelInfo);
     997        levelArray = psArrayAdd(levelArray,0,nextLevelInfo);
    998998        psFree(nextLevelInfo);
    999999        // Increment level counter
     
    11321132                        return false;
    11331133                    }
    1134                     psFree(lowerLevelInfo);
    11351134                    (*level)--;
    11361135                }
Note: See TracChangeset for help on using the changeset viewer.