# HG changeset patch # User Some Random Person # Date 1337871193 25200 # Node ID d6da470bbd387c508d56a6b4b48e9b00e9d8154d # Parent c5d2f2a941333d81ff8b2d91b282ba61e8a75f96 fixed bug in pure c queue -- enlarges correctly now diff -r c5d2f2a94133 -r d6da470bbd38 PrivateQueue.c --- a/PrivateQueue.c Wed Mar 14 23:02:28 2012 -0700 +++ b/PrivateQueue.c Thu May 24 07:53:13 2012 -0700 @@ -26,11 +26,11 @@ PrivQueueStruc* makePrivQ() { PrivQueueStruc* retQ; - //This malloc is not safe to use inside VMS-language! - retQ = (PrivQueueStruc *) malloc( sizeof( PrivQueueStruc ) ); + //This malloc is not safe to use in wrapper lib nor app code! + retQ = (PrivQueueStruc *) VMS_int__malloc( sizeof( PrivQueueStruc ) ); - //This malloc is not safe to use inside VMS-language! - retQ->startOfData = malloc( 1024 * sizeof(void *) ); + //This malloc is not safe to use in wrapper lib nor app code! + retQ->startOfData = VMS_WL__malloc( 1024 * sizeof(void *) ); memset( retQ->startOfData, 0, 1024 * sizeof(void *) ); retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty retQ->insertPos = &(retQ->startOfData[1]); // so start pos's have to be @@ -42,10 +42,11 @@ void enlargePrivQ( PrivQueueStruc *Q ) - { int32 oldSize, newSize; + { int32 oldSize, newSize, topPartSize, bottPartSize; int8 *insertPos, *extractPos; int8 *oldStartOfData, *oldEndOfData, *newStartOfData, *newEndOfData; - int8 *insertOffsetBytes, *extractOffsetBytes; + int32 insertOffsetBytes, extractOffsetBytes; + int8 *copyStartAddr; oldStartOfData = (int8 *)Q->startOfData; oldEndOfData = (int8 *)Q->endOfData; @@ -53,14 +54,14 @@ extractPos = (int8 *)Q->extractPos; //TODO: verify these get number of bytes correct - insertOffsetBytes = insertPos - oldStartOfData; - extractOffsetBytes = extractPos - oldStartOfData); + insertOffsetBytes = (int32)(insertPos - oldStartOfData); + extractOffsetBytes = (int32)(extractPos - oldStartOfData); - oldSize = endOfData - startOfData + 1; //in bytes + oldSize = oldEndOfData - oldStartOfData + 1; //in bytes newSize = 2 * oldSize; - //This malloc is not safe to use inside VMS-language! - Q->startOfData = (void **)malloc( newSize ); + //This malloc is not safe to use in wrapper lib nor app code! + Q->startOfData = (void **)VMS_int__malloc( newSize ); newStartOfData = (int8 *)Q->startOfData; newEndOfData = newStartOfData + newSize; //all calcs in Bytes Q->endOfData = (void **)newEndOfData; @@ -75,7 +76,7 @@ //UNLESS the one case where old extract was at bottom and insert // was at top. //TODO: check that this is correct! - if( extractPos == startOfData && insertPos == endOfData ) + if( extractPos == oldStartOfData && insertPos == oldEndOfData ) { memcpy( newStartOfData, oldStartOfData, oldSize ); //oldSize is bytes Q->extractPos = Q->startOfData; //start of valid data @@ -83,22 +84,22 @@ } else //have to copy two parts separately, then calc positions { //TODO: check end-addr, sizes, and new positions carefully - + //copy top part, starting at extract up until end of data, - // into top of new array + // into top of new array topPartSize = oldEndOfData - extractPos + 1; //+1 includes extractPos - copyStartAddr = newEndOfData - topPartSize + 1;//+1 cancels other + copyStartAddr = newEndOfData - topPartSize + 1;//+1 cancels other memcpy( copyStartAddr, Q->extractPos, topPartSize ); - Q->extractPos = (void **)copyStartAddr; //extract just-copied data - + Q->extractPos = (void **)copyStartAddr; //extract just-copied data + //copy bottom part, from old start up to old insert, - // into bottom of new array + // into bottom of new array bottPartSize = oldSize - topPartSize - 1; //-1 for empty insertPos memcpy( newStartOfData, oldStartOfData, bottPartSize ); Q->insertPos = (void **)(newStartOfData + bottPartSize); } - //This free is not safe to use inside VMS-language! - free(oldStartOfData); + //This free is not safe to use in wrapper lib nor app code! + VMS_int__free(oldStartOfData); } @@ -163,7 +164,8 @@ /*Returns false when the queue was full. * have option of calling make_larger_PrivQ to make more room, then try again */ -int writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ) +bool32 +writeIfSpacePrivQ( void * in, PrivQueueStruc* Q ) { void **startOfData = Q->startOfData; void **endOfData = Q->endOfData; @@ -242,7 +244,7 @@ void freePrivQ( PrivQueueStruc *Q ) { - //This free is not safe to use inside VMS-language! - free( Q->startOfData ); - free( Q ); + //This free is not safe to use in wrapper lib nor app code! + VMS_int__free( Q->startOfData ); + VMS_int__free( Q ); } \ No newline at end of file diff -r c5d2f2a94133 -r d6da470bbd38 PrivateQueue.h --- a/PrivateQueue.h Wed Mar 14 23:02:28 2012 -0700 +++ b/PrivateQueue.h Thu May 24 07:53:13 2012 -0700 @@ -10,6 +10,7 @@ #include "VMS_impl/VMS_primitive_data_types.h" +#include "VMS_impl/Services_Offered_by_VMS/Memory_Handling/vmalloc.h" #define TRUE 1