changeset 36:d6da470bbd38 pure_C

fixed bug in pure c queue -- enlarges correctly now
author Some Random Person <seanhalle@yahoo.com>
date Thu, 24 May 2012 07:53:13 -0700
parents c5d2f2a94133
children
files PrivateQueue.c PrivateQueue.h
diffstat 2 files changed, 27 insertions(+), 24 deletions(-) [+]
line diff
     1.1 --- a/PrivateQueue.c	Wed Mar 14 23:02:28 2012 -0700
     1.2 +++ b/PrivateQueue.c	Thu May 24 07:53:13 2012 -0700
     1.3 @@ -26,11 +26,11 @@
     1.4  PrivQueueStruc* makePrivQ()
     1.5   {
     1.6     PrivQueueStruc* retQ;
     1.7 -      //This malloc is not safe to use inside VMS-language!
     1.8 -   retQ = (PrivQueueStruc *) malloc( sizeof( PrivQueueStruc ) );
     1.9 +      //This malloc is not safe to use in wrapper lib nor app code!
    1.10 +   retQ = (PrivQueueStruc *) VMS_int__malloc( sizeof( PrivQueueStruc ) );
    1.11  
    1.12 -      //This malloc is not safe to use inside VMS-language!
    1.13 -   retQ->startOfData = malloc( 1024 * sizeof(void *) );
    1.14 +      //This malloc is not safe to use in wrapper lib nor app code!
    1.15 +   retQ->startOfData = VMS_WL__malloc( 1024 * sizeof(void *) );
    1.16     memset( retQ->startOfData, 0, 1024 * sizeof(void *) );
    1.17     retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty
    1.18     retQ->insertPos  = &(retQ->startOfData[1]); // so start pos's have to be
    1.19 @@ -42,10 +42,11 @@
    1.20  
    1.21  void
    1.22  enlargePrivQ( PrivQueueStruc *Q )
    1.23 - { int32  oldSize, newSize;
    1.24 + { int32  oldSize, newSize, topPartSize, bottPartSize;
    1.25     int8  *insertPos, *extractPos;
    1.26     int8  *oldStartOfData, *oldEndOfData, *newStartOfData, *newEndOfData;
    1.27 -   int8  *insertOffsetBytes, *extractOffsetBytes;
    1.28 +   int32  insertOffsetBytes, extractOffsetBytes;
    1.29 +   int8  *copyStartAddr;
    1.30  
    1.31     oldStartOfData = (int8 *)Q->startOfData;
    1.32     oldEndOfData   = (int8 *)Q->endOfData;
    1.33 @@ -53,14 +54,14 @@
    1.34     extractPos     = (int8 *)Q->extractPos;
    1.35     
    1.36        //TODO: verify these get number of bytes correct
    1.37 -   insertOffsetBytes  = insertPos  - oldStartOfData;
    1.38 -   extractOffsetBytes = extractPos - oldStartOfData);
    1.39 +   insertOffsetBytes  = (int32)(insertPos  - oldStartOfData);
    1.40 +   extractOffsetBytes = (int32)(extractPos - oldStartOfData);
    1.41     
    1.42 -   oldSize            = endOfData  - startOfData + 1; //in bytes
    1.43 +   oldSize            = oldEndOfData - oldStartOfData + 1; //in bytes
    1.44     newSize            = 2 * oldSize;
    1.45     
    1.46 -      //This malloc is not safe to use inside VMS-language!
    1.47 -   Q->startOfData     = (void **)malloc( newSize );
    1.48 +      //This malloc is not safe to use in wrapper lib nor app code!
    1.49 +   Q->startOfData     = (void **)VMS_int__malloc( newSize );
    1.50     newStartOfData     = (int8 *)Q->startOfData;
    1.51     newEndOfData       = newStartOfData + newSize; //all calcs in Bytes
    1.52     Q->endOfData       = (void **)newEndOfData;
    1.53 @@ -75,7 +76,7 @@
    1.54        //UNLESS the one case where old extract was at bottom and insert
    1.55        // was at top.
    1.56        //TODO: check that this is correct!
    1.57 -   if( extractPos == startOfData && insertPos == endOfData )
    1.58 +   if( extractPos == oldStartOfData && insertPos == oldEndOfData )
    1.59      {
    1.60        memcpy( newStartOfData, oldStartOfData, oldSize ); //oldSize is bytes
    1.61        Q->extractPos  = Q->startOfData; //start of valid data
    1.62 @@ -83,22 +84,22 @@
    1.63      }
    1.64     else //have to copy two parts separately, then calc positions
    1.65      {    //TODO: check end-addr, sizes, and new positions carefully
    1.66 -	
    1.67 +
    1.68           //copy top part, starting at extract up until end of data,
    1.69 -		 // into top of new array
    1.70 +         // into top of new array
    1.71        topPartSize = oldEndOfData - extractPos + 1; //+1 includes extractPos
    1.72 -	  copyStartAddr = newEndOfData - topPartSize + 1;//+1 cancels other
    1.73 +      copyStartAddr = newEndOfData - topPartSize + 1;//+1 cancels other
    1.74        memcpy( copyStartAddr, Q->extractPos, topPartSize );
    1.75 -	  Q->extractPos = (void **)copyStartAddr; //extract just-copied data
    1.76 -	  
    1.77 +      Q->extractPos = (void **)copyStartAddr; //extract just-copied data
    1.78 +  
    1.79           //copy bottom part, from old start up to old insert,
    1.80 -		 // into bottom of new array		 
    1.81 +         // into bottom of new array		 
    1.82        bottPartSize  = oldSize - topPartSize - 1; //-1 for empty insertPos
    1.83        memcpy( newStartOfData, oldStartOfData, bottPartSize );
    1.84        Q->insertPos  = (void **)(newStartOfData + bottPartSize);
    1.85      }
    1.86 -      //This free is not safe to use inside VMS-language!
    1.87 -   free(oldStartOfData);    
    1.88 +      //This free is not safe to use in wrapper lib nor app code!
    1.89 +   VMS_int__free(oldStartOfData);    
    1.90   }
    1.91  
    1.92  
    1.93 @@ -163,7 +164,8 @@
    1.94  /*Returns false when the queue was full.
    1.95   * have option of calling make_larger_PrivQ to make more room, then try again
    1.96   */
    1.97 -int writeIfSpacePrivQ( void * in, PrivQueueStruc* Q )
    1.98 +bool32
    1.99 +writeIfSpacePrivQ( void * in, PrivQueueStruc* Q )
   1.100   {
   1.101     void **startOfData = Q->startOfData;
   1.102     void **endOfData   = Q->endOfData;
   1.103 @@ -242,7 +244,7 @@
   1.104   void
   1.105   freePrivQ( PrivQueueStruc *Q )
   1.106    {
   1.107 -      //This free is not safe to use inside VMS-language!
   1.108 -    free( Q->startOfData );
   1.109 -	free( Q );
   1.110 +      //This free is not safe to use in wrapper lib nor app code!
   1.111 +    VMS_int__free( Q->startOfData );
   1.112 +	VMS_int__free( Q );
   1.113    }
   1.114 \ No newline at end of file
     2.1 --- a/PrivateQueue.h	Wed Mar 14 23:02:28 2012 -0700
     2.2 +++ b/PrivateQueue.h	Thu May 24 07:53:13 2012 -0700
     2.3 @@ -10,6 +10,7 @@
     2.4  
     2.5  
     2.6  #include "VMS_impl/VMS_primitive_data_types.h"
     2.7 +#include "VMS_impl/Services_Offered_by_VMS/Memory_Handling/vmalloc.h"
     2.8  
     2.9  
    2.10  #define TRUE     1