From 8216865a46f514f94997e22c3a39ef6c51fd04e2 Mon Sep 17 00:00:00 2001 From: Robert Edmonds Date: Mon, 13 Jan 2014 15:30:11 -0500 Subject: [PATCH] protobuf-c: remove alloc_failed_warning and protobuf_c_out_of_memory in general, libraries shouldn't be responsible for terminating the program if memory allocation fails. if we need to allocate memory and can't, we should be returning a failure indicator, not providing a strange interface to the user for receiving a callback in the event of such an error. also in general, libraries should never write to stdout or stderr. this breaks the API/ABI and will require a note in the ChangeLog. --- protobuf-c/protobuf-c.c | 20 -------------------- protobuf-c/protobuf-c.h | 7 ------- 2 files changed, 27 deletions(-) diff --git a/protobuf-c/protobuf-c.c b/protobuf-c/protobuf-c.c index 5cafe02..51ae17a 100644 --- a/protobuf-c/protobuf-c.c +++ b/protobuf-c/protobuf-c.c @@ -81,7 +81,6 @@ do { \ } else if ((dst=((allocator)->alloc((allocator)->allocator_data,\ da__allocation_size))) == NULL) \ { \ - alloc_failed_warning(da__allocation_size, __FILE__, __LINE__);\ fail_code; \ } \ } while (0) @@ -118,25 +117,8 @@ do { \ unsigned protobuf_c_major = PROTOBUF_C_MAJOR; unsigned protobuf_c_minor = PROTOBUF_C_MINOR; -static void -alloc_failed_warning(unsigned size, const char *filename, unsigned line) -{ - fprintf(stderr, - "WARNING: out-of-memory allocating a block of size %u (%s:%u)\n", - size, filename, line); -} - /* --- allocator --- */ -static void -protobuf_c_out_of_memory_default(void) -{ - fprintf(stderr, "Out Of Memory!!!\n"); - abort(); -} - -void (*protobuf_c_out_of_memory)(void) = protobuf_c_out_of_memory_default; - static void * system_alloc(void *allocator_data, size_t size) { @@ -146,8 +128,6 @@ system_alloc(void *allocator_data, size_t size) if (size == 0) return NULL; rv = malloc(size); - if (rv == NULL) - protobuf_c_out_of_memory(); return rv; } diff --git a/protobuf-c/protobuf-c.h b/protobuf-c/protobuf-c.h index 7d68abe..dec2522 100644 --- a/protobuf-c/protobuf-c.h +++ b/protobuf-c/protobuf-c.h @@ -158,13 +158,6 @@ struct _ProtobufCAllocator */ extern PROTOBUF_C_API ProtobufCAllocator protobuf_c_default_allocator; /* settable */ -/* - * This is the function that our default allocators call when they run - * out-of-memory. The default behavior of this function is to terminate your - * program. - */ -extern PROTOBUF_C_API void (*protobuf_c_out_of_memory)(void); - /* --- append-only data buffer --- */ typedef struct _ProtobufCBuffer ProtobufCBuffer; struct _ProtobufCBuffer {