IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9086


Ignore:
Timestamp:
Oct 1, 2006, 8:05:53 PM (20 years ago)
Author:
drobbin
Message:

Minor debugging changes.

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

Legend:

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

    r8627 r9086  
    66 *  @author Robert Daniel DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2006-08-26 04:34:28 $
     8 *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2006-10-02 06:05:53 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3333static void listFree(psList* list)
    3434{
    35     if (list == NULL) {
    36         return;
    37     }
    38 
    39     // remove the associated iterators -- any references are invalid once psList is freed.
    40     psArray* iterators = list->iterators;
    41     // ONLY orphan the iterators if the list iterators are about to be destroyed
    42     // a case where this is not the case is in psListSort.
    43     if (psMemGetRefCounter(iterators)  < 2) {
    44         for (int i = 0; i < iterators->n; i++) {
    45             // orphan iterators first to avoid any callbacks to dying list
    46             ((psListIterator*)iterators->data[i])->list = NULL;
    47             // remove all external references
    48             psMemSetRefCounter(iterators->data[i], 1);
    49         }
    50     }
    51     psFree(iterators);
     35    if (list->iterators != NULL) {
     36
     37        // remove the associated iterators -- any references are invalid once psList is freed.
     38        psArray* iterators = list->iterators;
     39        // ONLY orphan the iterators if the list iterators are about to be destroyed
     40        // a case where this is not the case is in psListSort.
     41        if (psMemGetRefCounter(iterators)  < 2) {
     42            for (int i = 0; i < iterators->n; i++) {
     43                // orphan iterators first to avoid any callbacks to dying list
     44                ((psListIterator*)iterators->data[i])->list = NULL;
     45                // remove all external references
     46                psMemSetRefCounter(iterators->data[i], 1);
     47            }
     48        }
     49        psFree(iterators);
     50    }
    5251
    5352    for (psListElem* ptr = list->head; ptr != NULL;) {
     
    6362static void listIteratorFree(psListIterator* iter)
    6463{
    65     if (iter == NULL) {
    66         return;
    67     }
    68 
    6964    // remove this iterator from the parent list
    7065    if (iter->list != NULL) {
     
    151146}
    152147
    153 psListIterator* psListIteratorAlloc(psList* list, long location, bool mutable)
    154 {
     148psListIterator* psListIteratorAlloc(psList* list,
     149                                    long location,
     150                                    bool mutable)
     151{
     152    if (list == NULL) {
     153        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     154                _("Specified list is NULL."));
     155        return false;
     156    }
    155157    psListIterator* iter = psAlloc(sizeof(psListIterator));
    156158
     
    180182                       long location)
    181183{
    182     if (iterator == NULL) {
     184    if (iterator == NULL || iterator->list == NULL) {
    183185        return false;
    184186    }
     
    214216    int index = iterator->index;
    215217    if (cursor == NULL) {      // set the cursor to the head if it is NULL
    216         if (location > list->n/2) { // closer to tail or head?
    217             cursor = list->tail;
    218             index = list->n - 1;
    219         } else {
    220             cursor = list->head;
    221             index = 0;
    222         }
     218        //XXX: if location can't be >= n, it def. can't be greater than n/2.
     219        /*        if (location > list->n/2) { // closer to tail or head?
     220                    cursor = list->tail;
     221                    index = list->n - 1;
     222                } else {
     223        */
     224        cursor = list->head;
     225        index = 0;
     226        //        }
    223227    }
    224228
     
    243247}
    244248
    245 bool psListAdd(psList* list, long location, psPtr data)
     249bool psListAdd(psList* list,
     250               long location,
     251               psPtr data)
    246252{
    247253
     
    279285}
    280286
    281 bool psListAddAfter(psListIterator* iterator, void* data)
     287bool psListAddAfter(psListIterator* iterator,
     288                    void* data)
    282289{
    283290    if (data == NULL) {
     
    332339    list->n++;
    333340
    334     if (cursor == list->tail) {
    335         list->tail = elem;
    336     }
    337 
     341    //XXX: The following is unreachable.  cursor can't == list->tail unless cursor->next == NULL.
     342    // in which case list->tail will be set to elem.  (list->tail = elem;)
     343    /*    if (cursor == list->tail) {
     344            list->tail = elem;
     345        }
     346    */
    338347    psArray* iterators = list->iterators;
    339348    int index = iterator->index;
     
    348357}
    349358
    350 bool psListAddBefore(psListIterator* iterator, void* data)
     359bool psListAddBefore(psListIterator* iterator,
     360                     void* data)
    351361{
    352362    if (data == NULL) {
     
    401411    list->n++;
    402412
    403     if (cursor == list->head) {
    404         list->head = elem;
    405     }
    406 
     413    //XXX: The following is unreachable.  cursor can't == list->head unless cursor->prev == NULL.
     414    // in which case list->head will be set to elem.  (list->tail = elem;)
     415    /*   if (cursor == list->head) {
     416            list->head = elem;
     417        }
     418    */
    407419    psArray* iterators = list->iterators;
    408420    int index = iterator->index;
     
    469481}
    470482
    471 psPtr psListGet(psList* list, long location)
     483psPtr psListGet(psList* list,
     484                long location)
    472485{
    473486    if (list == NULL) {
     
    478491
    479492    if (list->head == NULL) { // list empty?
     493        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     494                _("Specified psList reference is empty."));
    480495        return NULL;
    481496    }
     
    527542    }
    528543    if ((iterator->cursor == NULL) && (!iterator->offEnd))  {
    529         psLogMsg(__func__,PS_LOG_WARN,"Attempt to get previous with itertator cursor NULL and offEnd false");
     544        psLogMsg(__func__,PS_LOG_WARN,
     545                 "Attempt to get previous element with NULL iterator cursor and offEnd=false");
    530546        return NULL;
    531547    }
     
    594610}
    595611
    596 psList* psListSort(psList* list, psComparePtrFunc func)
     612psList* psListSort(psList* list,
     613                   psComparePtrFunc func)
    597614{
    598615    psArray* arr;
  • trunk/psLib/src/types/psList.h

    r6505 r9086  
    77 *  @ingroup LinkedList
    88 *
    9  *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2006-03-02 23:04:22 $
     9 *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2006-10-02 06:05:53 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    139139);
    140140
    141 /** Adds an data item to a psList at position just before the list position given
     141/** Adds a data item to a psList at position just before the list position given
    142142 *
    143143 *  @return bool        TRUE if item was successfully added, otherwise FALSE.
    144144 */
    145145bool psListAddBefore(
    146     psListIterator* iterator,              ///< list position to add item to
     146    psListIterator* iterator,          ///< list position to add item to
    147147    psPtr data                         ///< data item to add.  If NULL, list is not modified.
    148148);
     
    154154bool psListRemove(
    155155    psList* list,                      ///< list to remove element from
    156     long location                     ///< index of item
     156    long location                      ///< index of item
    157157);
    158158
     
    175175psPtr psListGet(
    176176    psList* list,                      ///< list to retrieve element from
    177     long location                     ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL
     177    long location                      ///< index number, PS_LIST_HEAD, or PS_LIST_TAIL
    178178);
    179179
     
    202202 */
    203203psArray* psListToArray(
    204     const psList* list                      ///< List to convert
     204    const psList* list                 ///< List to convert
    205205);
    206206
     
    211211 */
    212212psList* psArrayToList(
    213     const psArray* array                       ///< vector to convert
     213    const psArray* array               ///< vector to convert
    214214);
    215215
Note: See TracChangeset for help on using the changeset viewer.