$OpenBSD: patch-base_src_common_SDR_c,v 1.1 2003/05/23 13:22:14 todd Exp $
--- base/src/common/SDR.c.orig	Sun Apr  6 16:03:43 2003
+++ base/src/common/SDR.c	Thu May 22 17:46:42 2003
@@ -100,13 +100,14 @@ static ocmoff_t file_stream_gets(SDR_str
 static Buffer *file_stream_asBuffer(SDR_stream *s);
 static void file_stream_reread(SDR_stream *s);
 static void file_stream_close(SDR_stream *s);
+typedef uintptr_t * GC_PTR;
 static void file_stream_finalizer(GC_PTR obj, GC_PTR data);
 
 static SDR_stream*
 stream_openfile(const char *fileName, uint32_t mode, uint32_t format)
 {
   FILE *f;
-  SDR_stream *strm = (SDR_stream *) GC_MALLOC(sizeof(SDR_stream));
+  SDR_stream *strm = (SDR_stream *) malloc(sizeof(SDR_stream));
 
   assert(mode == MODE_RSTREAM || mode == MODE_WSTREAM);
   
@@ -129,7 +130,7 @@ stream_openfile(const char *fileName, ui
   strm->state = f;
 
 #ifdef NEW_FILE_STREAM
-  strm->rwbuf = GC_MALLOC_ATOMIC(RWBUFSZ);
+  strm->rwbuf = malloc(RWBUFSZ);
   if (mode == MODE_WSTREAM) {
     strm->rwlim = strm->rwbuf + RWBUFSZ;
     strm->rwptr = strm->rwbuf;
@@ -154,8 +155,6 @@ stream_openfile(const char *fileName, ui
   strm->reread = file_stream_reread;
   strm->close = file_stream_close;
 
-  GC_REGISTER_FINALIZER(strm, file_stream_finalizer, 0, 0, 0);
-
   return strm;
 }
 
@@ -352,7 +351,7 @@ static void mem_stream_close(SDR_stream 
 SDR_stream*
 stream_createMemory(uint32_t format)
 {
-  SDR_stream *strm = (SDR_stream *) GC_MALLOC(sizeof(SDR_stream));
+  SDR_stream *strm = (SDR_stream *) malloc(sizeof(SDR_stream));
 
   strm->name   = "<memory (out)>";
   strm->mode   = MODE_WSTREAM;
@@ -366,7 +365,7 @@ stream_createMemory(uint32_t format)
   strm->state = 0;
 
 #ifdef NEW_MEMORY_STREAM
-  strm->rwbuf = GC_MALLOC_ATOMIC(RWBUFSZ);
+  strm->rwbuf = malloc(RWBUFSZ);
   strm->rwlim = strm->rwbuf + RWBUFSZ;
   strm->rwptr = strm->rwbuf;
 
@@ -400,7 +399,7 @@ stream_createMemory(uint32_t format)
 SDR_stream*
 stream_fromMemory(const char *buffer, uint32_t len, uint32_t format)
 {
-  SDR_stream *strm = (SDR_stream *) GC_MALLOC(sizeof(SDR_stream));
+  SDR_stream *strm = (SDR_stream *) malloc(sizeof(SDR_stream));
 
   strm->name   = "<memory (in)>";
   strm->mode   = MODE_RSTREAM;
@@ -416,7 +415,7 @@ stream_fromMemory(const char *buffer, ui
   strm->state = 0;
 
 #ifdef NEW_MEMORY_STREAM
-  strm->rwbuf = GC_MALLOC_ATOMIC(RWBUFSZ);
+  strm->rwbuf = malloc(RWBUFSZ);
   strm->rwlim = strm->rwbuf + len;
   strm->rwptr = strm->rwbuf;
 
@@ -461,9 +460,9 @@ mem_stream_wflush(SDR_stream *s)
     assert(bufLen > 0);
 
     if (s->state)
-      s->state = GC_REALLOC(s->state, s->len + bufLen);
+      s->state = realloc(s->state, s->len + bufLen);
     else
-      s->state = GC_MALLOC_ATOMIC(RWBUFSZ);
+      s->state = malloc(RWBUFSZ);
 
     memcpy(((char *)s->state) + s->len, s->rwbuf, bufLen);
 
@@ -498,9 +497,9 @@ mem_stream_putc(SDR_stream *s, int c)
   if (s->bound == s->len) {
     s->bound += RWBUFSZ;
     if (bp)
-      bp = GC_REALLOC(bp, s->bound);
+      bp = realloc(bp, s->bound);
     else
-      bp = GC_MALLOC_ATOMIC(s->bound);
+      bp = malloc(s->bound);
   }
   bp[s->len] = c;
   
@@ -529,9 +528,9 @@ mem_stream_puts(SDR_stream *s, const voi
     while (s->bound < s->len + len)
       s->bound += RWBUFSZ;
     if (bp)
-      bp = GC_REALLOC(bp, s->bound);
+      bp = realloc(bp, s->bound);
     else
-      bp = GC_MALLOC_ATOMIC(s->bound);
+      bp = malloc(s->bound);
   }
   
   memcpy(&bp[s->pos], vp, len);
@@ -649,7 +648,7 @@ static Buffer *buf_stream_asBuffer(SDR_s
 SDR_stream*
 stream_createBuffer(uint32_t format)
 {
-  SDR_stream *strm = (SDR_stream *) GC_MALLOC(sizeof(SDR_stream));
+  SDR_stream *strm = (SDR_stream *) malloc(sizeof(SDR_stream));
 
   strm->name   = "<buffer (in)>";
   strm->mode   = MODE_WSTREAM;
@@ -663,7 +662,7 @@ stream_createBuffer(uint32_t format)
   strm->state = buffer_create();
 
 #ifdef NEW_BUFFERED_STREAM
-  strm->rwbuf = GC_MALLOC_ATOMIC(RWBUFSZ);
+  strm->rwbuf = malloc(RWBUFSZ);
   strm->rwlim = strm->rwbuf + RWBUFSZ;
   strm->rwptr = strm->rwbuf;
 
@@ -697,7 +696,7 @@ stream_createBuffer(uint32_t format)
 SDR_stream*
 stream_fromBuffer(Buffer *buffer, uint32_t format)
 {
-  SDR_stream *strm = (SDR_stream *) GC_MALLOC(sizeof(SDR_stream));
+  SDR_stream *strm = (SDR_stream *) malloc(sizeof(SDR_stream));
 
   strm->name   = "<buffer (in)>";
   strm->mode   = MODE_RSTREAM;
@@ -712,7 +711,7 @@ stream_fromBuffer(Buffer *buffer, uint32
   strm->rwbuf = strm->rwlim = strm->rwptr = 0;
 
 #ifdef NEW_BUFFERED_STREAM
-  strm->rwbuf = GC_MALLOC_ATOMIC(RWBUFSZ);
+  strm->rwbuf = malloc(RWBUFSZ);
   strm->rwlim = strm->rwptr = strm->rwbuf; /* force rfill */
 
   strm->wflush = buf_stream_wflush;
@@ -899,7 +898,7 @@ static void sha1_stream_close(SDR_stream
 SDR_stream*
 stream_create_sha1(void)
 {
-  SDR_stream *strm = (SDR_stream *) GC_MALLOC(sizeof(SDR_stream));
+  SDR_stream *strm = (SDR_stream *) malloc(sizeof(SDR_stream));
 
   strm->name   = "<sha1 (out)>";
   strm->mode   = MODE_WSTREAM;
@@ -916,7 +915,7 @@ stream_create_sha1(void)
 #endif
 
 #ifdef NEW_MEMORY_STREAM
-  strm->rwbuf = GC_MALLOC_ATOMIC(RWBUFSZ);
+  strm->rwbuf = malloc(RWBUFSZ);
   strm->rwlim = strm->rwbuf + RWBUFSZ;
   strm->rwptr = strm->rwbuf;
 
@@ -1390,10 +1389,10 @@ stream_printf(SDR_stream *s, const char 
   return output_count;
 }
 
-const char *
+char *
 format(const char *fmt, ...)
 {
-  const char *str;
+  char *str;
 
   SDR_stream *s = stream_createMemory(SDR_RAW);
 
@@ -1984,7 +1983,7 @@ bin_w_bytes(const char *elem, SDR_stream
 static void *
 bin_r_bytes(const char *elem, SDR_stream *strm, uint32_t len)
 {
-  char * s = (char *) GC_MALLOC_ATOMIC(sizeof(char) * (len+1));
+  char * s = (char *) malloc(sizeof(char) * (len+1));
   s[len] = 0;
   
   if (stream_read(strm, s, len) < len)
@@ -2032,7 +2031,7 @@ bin_r_string(const char *elem, SDR_strea
   if (len == 0)
     return 0;
   else {
-    char * s = (char *) GC_MALLOC_ATOMIC (sizeof(char) * len);
+    char * s = (char *) malloc (sizeof(char) * len);
     s[len-1] = 0;
   
     if (stream_read(strm, s, len) < len)
@@ -2068,7 +2067,7 @@ bin_r_obname(const char *elem, SDR_strea
   if (len == 0)
     return 0;
   else {
-    char * s = (char *) GC_MALLOC_ATOMIC (sizeof(char) * len);
+    char * s = (char *) malloc (sizeof(char) * len);
     s[len-1] = 0;
   
     if (stream_read(strm, s, len) < len)
@@ -2179,7 +2178,7 @@ static texty_field*
 texty_get_field(const char *name, char ty, SDR_stream *strm)
 {
   int c;
-  texty_field* fld = (texty_field *) GC_MALLOC(sizeof(texty_field)); 
+  texty_field* fld = (texty_field *) malloc(sizeof(texty_field)); 
 
   /* Skip leading whitespace: */
   while(stream_peekc(strm) == ' ')
@@ -2352,8 +2351,9 @@ texty_r_u32(const char *elem, SDR_stream
 static void
 texty_w_u64(const char *elem, SDR_stream *strm, uint64_t num)
 {
+  char *nstr = xunsigned64_str(num);
   texty_do_indent(strm);
-  stream_printf(strm, "%s L %s\n", elem, xunsigned64_str(num));
+  stream_printf(strm, "%s L %s\n", elem, nstr);
 }
 
 static uint64_t
@@ -2387,9 +2387,11 @@ static void
 texty_w_buffer(const char *elem, SDR_stream *strm, const Buffer *buf)
 {
   ocmoff_t len = buffer_length(buf);
+  char *lstr = xunsigned64_str(len + 1);
   texty_do_indent(strm);
 
-  stream_printf(strm, "%s X %s", elem, xunsigned64_str(len + 1));
+  stream_printf(strm, "%s X %s", elem, lstr);
+  free(lstr);
   stream_putc(strm, '\n');
 
   if (len) {
@@ -2542,7 +2544,7 @@ encodeString(const void *vp, ocmoff_t le
 {
   ocmoff_t u;
   unsigned const char *bp = vp;
-  unsigned char *ostring = GC_MALLOC_ATOMIC(encodedLen + 1);
+  unsigned char *ostring = malloc(encodedLen + 1);
   unsigned char *op = ostring;
 
   ostring[encodedLen] = 0;
@@ -2661,7 +2663,7 @@ dtexty_get_field(const char *name, char 
   if(ty == 'S' || ty == 'B' || ty == 'N' || ty == 'O')
   {
     /* The decoded length cannot possibly be longer than the encoded length */
-    char* decoded_rep = GC_MALLOC_ATOMIC(fld->value);
+    char* decoded_rep = malloc(fld->value);
     char* start_of_decoded_rep = decoded_rep;
     char* encoded_rep = fld->rep;
 
