From 2282d2489bd8db3cd4ddbe0dd813732bffcf6452 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 12 Aug 2009 13:47:24 -0700 Subject: Refactoring: unify upb_msg. The cost is that a upb_msg will now always have an overhead of 2*sizeof(void*). This is comparable to proto2 overhead. The benefit is that upb_msg is now self-describing, and read-only algorithms can now operate on a upb_msg regardless of the memory-management scheme. Also, upb_array and upb_string now know inherently if they own their associated memory, and upb_array has a generic pointer for memory management purposes like upb_msg does. --- src/upb_string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/upb_string.c') diff --git a/src/upb_string.c b/src/upb_string.c index bb40a62..7754936 100644 --- a/src/upb_string.c +++ b/src/upb_string.c @@ -14,8 +14,8 @@ bool upb_strreadfile(const char *filename, struct upb_string *data) { long size = ftell(f); if(size < 0) return false; if(fseek(f, 0, SEEK_SET) != 0) return false; - data->ptr = (char*)malloc(size); data->byte_len = size; + upb_stralloc(data, data->byte_len); if(fread(data->ptr, size, 1, f) != 1) { free(data->ptr); return false; -- cgit v1.2.3