IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14921


Ignore:
Timestamp:
Sep 20, 2007, 1:48:47 PM (19 years ago)
Author:
eugene
Message:

updates to child handling

Location:
trunk/psLib/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageStructManip.c

    r14523 r14921  
    88 *  @author Robert DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2007-08-16 02:51:09 $
     10 *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2007-09-20 23:48:47 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2323
    2424#include "psMemory.h"
     25#include "psError.h"
     26#include "psAbort.h"
     27
    2528#include "psImageStructManip.h"
    26 #include "psError.h"
    27 
    2829
    2930// col0,row0 are the starting pixel in the input image coordinate frame
     
    9899    if (out != NULL) {
    99100        // if a child, need to orphan (disassociate from parent) first
    100         if (out->parent != NULL) {
    101             psArrayRemoveData(out->parent->children,psMemIncrRefCounter(out));
    102             // remove from parent's knowledge without triggering a free
    103             out->parent = NULL; // break link to parent
     101        psImage *parent = (psImage *) out->parent;
     102        if (parent != NULL) {
     103            // break the back-pointer first so we don't loop
     104            out->parent = NULL;
     105
     106            // drop my entry on my parent's array of children
     107            psArrayRemoveDataNoFree (out->parent->children, out);
     108
     109            // drop my reference to my old parent
     110            psFree (parent);
    104111        }
    105112
     113        // we recycle out->data.V
    106114        psFree(out->p_rawDataBuffer); // free the previous data reference
    107115    } else {
     
    117125    P_PSIMAGE_SET_ROW0(out, row0);
    118126
    119     out->parent = image;
     127    out->parent = psMemIncrRefCounter(image); // track references to parents
    120128    out->children = NULL;
    121129    out->p_rawDataBuffer = rawData;
     
    133141
    134142    // add output image as a child of the input image.
    135     image->children = psArrayAdd(image->children,16,out);
    136     psMemDecrRefCounter(out); // don't count the reference held by parent as a true reference
     143    image->children = psArrayAdd (image->children, 16, out);
     144    psFree (out); // the image->children array is an array of views only
    137145
    138146    return (out);
     
    307315                _("Can not operate on a NULL psImage."));
    308316        return NULL;
     317    }
     318
     319    if ((image->children != NULL) && (image->children->n > 0)) {
     320        psAbort ("cannot trim an image with outstanding children");
    309321    }
    310322
     
    345357    }
    346358
    347     psImageFreeChildren(image);
    348 
    349359    psU32 elementSize = PSELEMTYPE_SIZEOF(image->type.type);
    350360    psU32 numCols = col1-col0;
  • trunk/psLib/src/mathtypes/psImage.c

    r12813 r14921  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.129 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2007-04-12 18:52:57 $
     11 *  @version $Revision: 1.130 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2007-09-20 23:48:30 $
    1313 *
    1414 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2828#include "psError.h"
    2929#include "psAssert.h"
     30#include "psAbort.h"
     31
    3032#include "psImage.h"
    3133#include "psString.h"
     
    3840    }
    3941
    40     if (image->parent != NULL) {
    41         psMemBlock* ptr = ((psMemBlock*)image)-1;
    42         int ref = ptr->refCounter;
    43         ptr->refCounter = 2;  // make sure psFree is not retriggered
    44         psArrayRemoveData(image->parent->children,image);
    45         ptr->refCounter = ref; // restore previous count (not assuming zero, but should be)
    46 
    47         image->parent = NULL;
    48     }
    49 
    50     psImageFreeChildren(image);
    51 
     42    psImage *parent = (psImage *) image->parent;
     43
     44    // if I am a child, remove me from my parent's array of children
     45    if (parent != NULL) {
     46        // sanity check : a child cannot also be a parent
     47        if ((image->children != NULL) && (image->children->n > 0)) {
     48            psAbort ("psImage cannot be both child and parent!");
     49        }
     50
     51        // break the back-pointer first so we don't loop
     52        image->parent = NULL;
     53
     54        // drop my entry on my parent's array of children
     55        psArrayRemoveDataNoFree (parent->children, image);
     56       
     57        // drop my reference to my parent
     58        psFree (parent);
     59    }
     60   
     61    // sanity check: this function should never be reached if an image still has live children;
     62    // they should each be holding a pointer to the image, forcing the number of references to
     63    // be > 1.
     64    if (image->children && (image->children->n > 0)) {
     65        psAbort ("psImage memory management programming error : imageFree called on image with live children");
     66    }
     67
     68    psFree(image->children);
    5269    psFree(image->p_rawDataBuffer);
    5370    psFree(image->data.V);
     
    524541}
    525542
    526 
    527 int psImageFreeChildren(psImage* image)
    528 {
    529     psS32 numFreed = 0;
    530 
    531     if (image == NULL) {
    532         return numFreed;
    533     }
    534 
    535     if (image->children != NULL) {
    536         psImage** children = (psImage**)image->children->data;
    537         numFreed = image->children->n;
    538 
    539         // orphan the children first
    540         // (so psFree doesn't try to modify the parent's children array while I'm using it)
    541         for (psS32 i=0;i<numFreed;i++) {
    542             children[i]->parent = NULL;
    543         }
    544 
    545         psFree(image->children);
    546         image->children = NULL;
    547     }
    548 
    549     return numFreed;
    550 }
    551 
    552543bool p_psImagePrint (int fd,
    553544                     psImage *a,
Note: See TracChangeset for help on using the changeset viewer.