On Wed, 26 May 1999, Ion Popescu wrote:

> DmResizeRecord() should fail (give a Fatal error msg)
> if the record/handle is locked.

Well, I'd be happy if it has done - I'd know the answer then. Please
explain, then, how did it happen that the following example actually
passed well:

(It's just excerpt - two subroutines that are copying src record data into
dst record resizing dst before that. 'CurrentRecord' is global. CopyRecord
is called first and then it calls LockDataPtr (which leaves record data
handle locked and record unreleased. Two lines in CopyRecord that are
commented do prevention not to loose proper handle if it changes by
resizing, but I commented them now deliberately and IT WORKS!! You can see
that dst record data handle is locked during resizing but it doesn't show
any odd behaviour. I'm using CW R4 (win) and POSE 2.1d25.)
(PS. Ok, I know, there should be error checking. Sorry, it's just
example.)

//globals: CurrentRecord, CbxDB 

static Boolean CopyRecord(ULong SrcID,ULong DstID)
{
 Err    error;
 UInt   SrcIndex,DstIndex;
 VoidPtr        SrcPtr,DstPtr;
 VoidHand       newhandle;
 ULong  size;


 SrcPtr=LockDataPtr(SrcID);                             //find indexes
 SrcIndex=CurrentRecord;
 DstPtr=LockDataPtr(DstID);
 DstIndex=CurrentRecord;

 size=MemPtrSize(SrcPtr);                               //size of src

 //MemPtrUnlock(DstPtr);                                //unlock dst

 newhandle=DmResizeRecord(CbxDB,DstIndex,size);         //resize dst
 //DstPtr=MemHandleLock(newhandle);
 error=DmWrite(DstPtr,0,SrcPtr,size);

 MemPtrUnlock(SrcPtr);
//unlock and release all
 DmReleaseRecord(CbxDB,SrcIndex,true);
 MemPtrUnlock(DstPtr);
 DmReleaseRecord(CbxDB,DstIndex,true);
}



static Ptr LockDataPtr(ULong uniqueID)
{
 UInt           index;
 Err            error;

 error=DmFindRecordByID(CbxDB,uniqueID,&index);
 CurrentRecord=index;
 return(MemHandleLock(DmGetRecord(CbxDB,index)));
}






> Danko Radic wrote:
> > 
> > There were some words about handles thesedays, and I'd like to make
> > something clear.
> > When resizing record (DmResizeRecord) we should take (eventual) new handle
> > into further processing for the reasons described in manual (it can change
> > if there isn't enough space to do resizing etc.). Now, if I LOCK record's
> > handle BEFORE resizing (do some operations on data) and then resize record
> > and take new handle, what would happen with old handle when I call
> > MemPtrUnlock (and then DmReleaseRecord)? If it wewen't changed by
> > DmResize, it would be unlocked, but what would happen if it was?
> > 
> > See the next example (I'll skip obvious declarations, it's just shematic
> > example):
> > 
> >  error=DmFindRecordByID(sampleDB,uniqueID,&index);
> >  handle=MemHandleLock(DmGetRecord(sampleDB,index));
> >  ptr=LockDataPtr(SrcID);
> > 
> > //...doing some things on data...
> > 
> >  handle=DmResizeRecord(sampleDB,index,size);
> > 
> >  MemPtrUnlock(ptr);
> >  DmReleaseRecord(sampleDB,index,true);
> > 
> > Of course, it would be the best to unlock all and then do resizing, but
> > what if I don't?
> > 
> > Sorry for eventual mistyppos in the example above (I don't have manual
> > or code right now) but I think you got the idea.
> 
> 

Reply via email to