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.
This commit is contained in:
Robert Edmonds 2014-01-13 15:30:11 -05:00
parent 8cd5f6764b
commit 8216865a46
2 changed files with 0 additions and 27 deletions

View File

@ -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;
}

View File

@ -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 {