]> granicus.if.org Git - graphviz/commitdiff
remove return value from vmfree
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 17 Jul 2021 00:37:51 +0000 (17:37 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 18 Jul 2021 22:13:34 +0000 (15:13 -0700)
There is no reasonable action for a caller to take based on a deallocation
request failing. This is inline with ISO C’s `free` having no return value.

lib/vmalloc/test.c
lib/vmalloc/vmalloc.c
lib/vmalloc/vmalloc.h

index baf5a5568b67051117368bc780cb16844c5aa95a..73352d917fdb2557f43827241e8ebed03dcceed5 100644 (file)
@@ -95,18 +95,15 @@ static void test_lifecycle(void) {
   assert(v->size == allocations_len);
 
   // free a few allocations out of order from that in which we allocated
-  int r = vmfree(v, p[3]);
-  assert(r == 0);
-  r = vmfree(v, p[6]);
-  assert(r == 0);
-  r = vmfree(v, p[5]);
-  assert(r == 0);
+  vmfree(v, p[3]);
+  vmfree(v, p[6]);
+  vmfree(v, p[5]);
 
   // the allocator should have correctly stopped tracking those pointers
   assert(v->size == allocations_len - 3);
 
   // free the rest of the allocations in one sweep
-  r = vmclear(v);
+  int r = vmclear(v);
   assert(r == 0);
 
   /* the allocator should have dropped all pointers it was tracking */
@@ -164,8 +161,7 @@ static void test_resize(void) {
   }
 
   // discard this
-  int r = vmfree(v, p);
-  assert(r == 0);
+  vmfree(v, p);
 
   // get a new pointer
   p = vmalloc(v, s);
@@ -204,7 +200,7 @@ static void test_resize(void) {
   }
 
   // clean up
-  r = vmclose(v);
+  int r = vmclose(v);
   assert(r == 0);
 }
 
@@ -239,10 +235,8 @@ static void test_strdup(void) {
   assert(strcmp(s, t) == 0);
 
   // discard these strings
-  int r = vmfree(v, s);
-  assert(r == 0);
-  r = vmfree(v, t);
-  assert(r == 0);
+  vmfree(v, s);
+  vmfree(v, t);
 
   /* vmstrdup does not assume the input string is mutable, so lets pass it a
    * non-writable string
@@ -255,7 +249,7 @@ static void test_strdup(void) {
   assert(strcmp(sc, t) == 0);
 
   // clean up
-  r = vmclose(v);
+  int r = vmclose(v);
   assert(r == 0);
 }
 
index 3134ab294e7a0e4aaac57c6da6fd11d147dd806a..2f203006ece1e66e1db44c59b1ee23670f0a1fde 100644 (file)
@@ -54,10 +54,10 @@ void *vmalloc(Vmalloc_t *vm, size_t size) {
   return p;
 }
 
-int vmfree(Vmalloc_t *vm, void *data) {
+void vmfree(Vmalloc_t *vm, void *data) {
 
   if (!data) { // ANSI-ism
-    return 0;
+    return;
   }
 
   // find the pointer we previously allocated
@@ -72,12 +72,11 @@ int vmfree(Vmalloc_t *vm, void *data) {
       // give this back to the underlying allocator
       free(data);
 
-      return 0;
+      return;
     }
   }
 
   // we did not find this pointer; free() of something we did not allocate
-  return -1;
 }
 
 void *vmresize(Vmalloc_t *vm, void *data, size_t size) {
index a2ee07d7ccab2f6afc5f2be4fa95653691bbd453..af5b94b5c91a466d6451f30228706fe23fe18dd9 100644 (file)
@@ -54,9 +54,8 @@ void *vmresize(Vmalloc_t *vm, void *data, size_t size);
  *
  * @param vm Region the pointer was originally allocated from
  * @param data The pointer originally received from vmalloc
- * @returns 0 on success
  */
-int vmfree(Vmalloc_t *vm, void *data);
+void vmfree(Vmalloc_t *vm, void *data);
 
     extern char *vmstrdup(Vmalloc_t *, const char *);