added rfx_realloc().
authorkramm <kramm>
Fri, 5 Nov 2004 17:34:15 +0000 (17:34 +0000)
committerkramm <kramm>
Fri, 5 Nov 2004 17:34:15 +0000 (17:34 +0000)
lib/rfxswf.c

index 8513966..3ee5c6e 100644 (file)
 
 // memory allocation
 
-void* rfxalloc(int size)
+void* rfx_alloc(int size)
 {
   void*ptr;
+  if(size == 0) {
+    *(int*)0 = 0xdead;
+    fprintf(stderr, "Warning: Zero alloc\n");
+    return 0;
+  }
+
+  ptr = malloc(size);
+  if(!ptr) {
+    fprintf(stderr, "FATAL: Out of memory\n");
+    /* TODO: we should send a signal, so that the debugger kicks in */
+    exit(1);
+  }
+  return ptr;
+}
+void* rfx_realloc(void*data, int size)
+{
+  void*ptr;
+  if(size == 0) {
+    *(int*)0 = 0xdead;
+    fprintf(stderr, "Warning: Zero realloc\n");
+    rfx_free(data);
+    return 0;
+  }
+  if(!data) {
+    ptr = malloc(size);
+  } else {
+    ptr = realloc(data, size);
+  }
+
+  if(!ptr) {
+    fprintf(stderr, "FATAL: Out of memory\n");
+    /* TODO: we should send a signal, so that the debugger kicks in */
+    exit(1);
+  }
+  return ptr;
+}
+void* rfx_calloc(int size)
+{
+  void*ptr;
+  if(size == 0) {
+    *(int*)0 = 0xdead;
+    fprintf(stderr, "Warning: Zero alloc\n");
+    return 0;
+  }
 #ifdef HAVE_CALLOC
   ptr = calloc(size);
 #else
   ptr = malloc(size);
-  memset(ptr, 0, size);
 #endif
   if(!ptr) {
     fprintf(stderr, "FATAL: Out of memory\n");
     /* TODO: we should send a signal, so that the debugger kicks in */
     exit(1);
   }
+#ifndef HAVE_CALLOC
+  memset(ptr, 0, size);
+#endif
   return ptr;
 }
 
-void rfxdealloc(void*ptr)
+void rfx_free(void*ptr)
 {
+  if(!ptr)
+    return;
   free(ptr);
 }
 
@@ -835,6 +883,13 @@ void swf_ResetTag(TAG*tag, U16 id)
     tag->id = id;
 }
 
+TAG* swf_CopyTag(TAG*tag, TAG*to_copy)
+{
+    tag = swf_InsertTag(tag, to_copy->id);
+    swf_SetBlock(tag, to_copy->data, to_copy->len);
+    return tag;
+}
+
 int swf_DeleteTag(TAG * t)
 { if (!t) return -1;