Permalink
Browse files

Changed allocator to produce more information when something goes wro…

…ng, refactored to use macro.
  • Loading branch information...
1 parent bee3a38 commit c82ead85291f9009a234234d20b21d5612320034 Caleb James DeLisle committed Feb 20, 2013
Showing with 444 additions and 385 deletions.
  1. +2 −2 admin/AdminClient.c
  2. +4 −4 admin/AdminLog.c
  3. +1 −1 admin/AuthorizedPasswords.c
  4. +3 −3 admin/Configurator.c
  5. +1 −1 admin/angel/Core_admin.c
  6. +1 −1 admin/angel/cjdroute2.c
  7. +2 −2 admin/testframework/AdminTestFramework.c
  8. +10 −10 benc/Dict.c
  9. +10 −10 benc/List.c
  10. +2 −2 benc/String.c
  11. +13 −13 benc/serialization/json/JsonBencSerializer.c
  12. +7 −7 benc/serialization/standard/StandardBencSerializer.c
  13. +12 −13 crypto/CryptoAuth.c
  14. +5 −5 crypto/test/CryptoAuth_test.c
  15. +8 −13 crypto/test/CryptoAuth_unit_test.c
  16. +1 −1 dht/AddressMapper.c
  17. +5 −5 dht/DHTModuleRegistry.c
  18. +8 −14 dht/ReplyModule.c
  19. +2 −2 dht/SerializationModule.c
  20. +2 −2 dht/dhtcore/Janitor.c
  21. +2 −2 dht/dhtcore/NodeCollector.h
  22. +7 −7 dht/dhtcore/NodeStore.c
  23. +11 −14 dht/dhtcore/RouterModule.c
  24. +2 −2 dht/dhtcore/RouterModule_admin.c
  25. +7 −7 dht/dhtcore/SearchStore.c
  26. +5 −6 dht/dhtcore/VersionList.c
  27. +2 −2 dht/dhtcore/test/TestFramework.h
  28. +2 −3 dht/test/address_mapper_lru_test.c
  29. +11 −12 interface/ETHInterface_admin.c
  30. +2 −2 interface/PipeInterface.c
  31. +7 −8 interface/SessionManager.c
  32. +10 −11 interface/UDPInterface_admin.c
  33. +2 −2 io/ArrayReader.c
  34. +2 −2 io/ArrayWriter.c
  35. +1 −1 io/FileReader.c
  36. +1 −1 io/FileWriter.c
  37. +18 −10 memory/Allocator.h
  38. +27 −14 memory/BufferAllocator.c
  39. +71 −40 memory/CanaryAllocator.c
  40. +1 −1 memory/CanaryAllocator.h
  41. +14 −5 memory/CanaryAllocator_pvt.h
  42. +49 −22 memory/MallocAllocator.c
  43. +1 −1 memory/test/CanaryAllocator_test.c
  44. +3 −3 memory/test/MallocAllocator_test.c
  45. +1 −1 net/Ducttape.c
  46. +11 −12 net/SwitchPinger.c
  47. +6 −7 net/SwitchPinger_admin.c
  48. +1 −1 net/test/DefaultInterfaceController_test.c
  49. +1 −1 switch/SwitchCore.c
  50. +1 −1 test/TestFramework.c
  51. +3 −3 test/cjdroute_injection_test.c
  52. +1 −1 test/cjdroute_routerPing_test.c
  53. +1 −1 test/threeNodes_test.c
  54. +1 −1 test/twoNodes_test.c
  55. +11 −14 tunnel/IpTunnel.c
  56. +2 −2 tunnel/IpTunnel_admin.c
  57. +3 −3 util/AverageRoller.c
  58. +18 −22 util/Map.h
  59. +5 −5 util/Pinger.c
  60. +2 −2 util/Process_FreeBSD.c
  61. +2 −2 util/Process_Illumos.c
  62. +2 −2 util/Process_Linux.c
  63. +2 −2 util/Process_OSX.c
  64. +2 −2 util/Process_OpenBSD.c
  65. +2 −2 util/Security_admin.c
  66. +2 −2 util/log/IndirectLog.c
  67. +2 −2 util/log/WriterLog.c
  68. +1 −1 util/test/Map_test.c
  69. +4 −4 wire/Message.h
View
@@ -201,13 +201,13 @@ struct AdminClient_Result* AdminClient_rpcCall(String* function,
String_CONST("aq"), String_OBJ(function), Dict_CONST(
String_CONST("args"), Dict_OBJ(&a), NULL
)));
- struct Result* res = alloc->clone(sizeof(struct Result), alloc, &(struct Result) {
+ struct Result* res = Allocator_clone(alloc, (&(struct Result) {
.public = {
.err = AdminClient_Error_NONE
},
.ctx = ctx,
.alloc = alloc
- });
+ }));
ctx->result = res;
doCall(&message, res, false);
return &res->public;
View
@@ -139,7 +139,7 @@ static Dict* makeLogMessage(struct Subscription* subscription,
time(&now);
Dict* out = Dict_new(alloc);
- char* buff = alloc->malloc(20, alloc);
+ char* buff = Allocator_malloc(alloc, 20);
Hex_encode((uint8_t*)buff, 20, subscription->streamId, 8);
Dict_putString(out, String_new("streamId", alloc), String_new(buff, alloc), alloc);
Dict_putInt(out, String_new("time", alloc), now, alloc);
@@ -163,7 +163,7 @@ static Dict* makeLogMessage(struct Subscription* subscription,
static void removeSubscription(struct AdminLog* log, struct Subscription* sub)
{
- sub->alloc->free(sub->alloc);
+ Allocator_free(sub->alloc);
log->subscriptionCount--;
if (log->subscriptionCount == 0) {
return;
@@ -287,14 +287,14 @@ static void unsubscribe(Dict* args, void* vcontext, String* txid)
struct Log* AdminLog_registerNew(struct Admin* admin, struct Allocator* alloc, struct Random* rand)
{
- struct AdminLog* log = alloc->clone(sizeof(struct AdminLog), alloc, &(struct AdminLog) {
+ struct AdminLog* log = Allocator_clone(alloc, (&(struct AdminLog) {
.pub = {
.callback = doLog
},
.admin = admin,
.alloc = alloc,
.rand = rand
- });
+ }));
Admin_registerFunction("AdminLog_subscribe", subscribe, log, true,
((struct Admin_FunctionArg[]) {
@@ -81,7 +81,7 @@ void AuthorizedPasswords_init(struct Admin* admin,
struct CryptoAuth* ca,
struct Allocator* allocator)
{
- struct Context* context = allocator->malloc(sizeof(struct Context), allocator);
+ struct Context* context = Allocator_malloc(allocator, sizeof(struct Context));
context->admin = admin;
context->allocator = allocator;
context->ca = ca;
View
@@ -113,7 +113,7 @@ static void authorizedPasswords(List* list, struct Context* ctx)
));
struct Allocator* child = Allocator_child(ctx->alloc);
rpcCall(String_CONST("AuthorizedPasswords_add"), &args, ctx, child);
- child->free(child);
+ Allocator_free(child);
}
}
@@ -157,7 +157,7 @@ static void udpInterface(Dict* config, struct Context* ctx)
struct Allocator* perCallAlloc = Allocator_child(ctx->alloc);
Dict_putString(value, String_CONST("address"), key, perCallAlloc);
rpcCall(String_CONST("UDPInterface_beginConnection"), value, ctx, perCallAlloc);
- perCallAlloc->free(perCallAlloc);
+ Allocator_free(perCallAlloc);
entry = entry->next;
}
@@ -264,7 +264,7 @@ static void ethInterface(Dict* config, struct Context* ctx)
struct Allocator* perCallAlloc = Allocator_child(ctx->alloc);
Dict_putString(value, String_CONST("macAddress"), key, perCallAlloc);
rpcCall(String_CONST("ETHInterface_beginConnection"), value, ctx, perCallAlloc);
- perCallAlloc->free(perCallAlloc);
+ Allocator_free(perCallAlloc);
entry = entry->next;
}
View
@@ -75,7 +75,7 @@ void Core_admin_register(uint8_t ipAddr[16],
struct Admin* admin,
struct EventBase* eventBase)
{
- struct Context* ctx = alloc->malloc(sizeof(struct Context), alloc);
+ struct Context* ctx = Allocator_malloc(alloc, sizeof(struct Context));
Bits_memcpyConst(ctx->ipAddr, ipAddr, 16);
ctx->ducttape = dt;
ctx->logger = logger;
View
@@ -110,7 +110,7 @@ static String* getCorePath(struct Allocator* alloc)
if (fileExists(tempOutput->bytes)) {
output = String_clone(tempOutput, alloc);
}
- alloc2->free(alloc2);
+ Allocator_free(alloc2);
return output;
}
@@ -191,15 +191,15 @@ struct AdminTestFramework* AdminTestFramework_setUp(int argc, char** argv)
Assert_always(client);
- return alloc->clone(sizeof(struct AdminTestFramework), alloc, &(struct AdminTestFramework) {
+ return Allocator_clone(alloc, (&(struct AdminTestFramework) {
.admin = admin,
.client = client,
.alloc = alloc,
.eventBase = eventBase,
.logger = logger,
.addr = Sockaddr_clone(udpAdmin->addr, alloc),
.angelInterface = &pi->generic
- });
+ }));
}
void AdminTestFramework_tearDown(struct AdminTestFramework* framework)
View
@@ -89,7 +89,7 @@ List* Dict_getList(const Dict* dictionary, const String* key)
/** @see Object.h */
Dict* Dict_new(const struct Allocator* allocator)
{
- return allocator->calloc(sizeof(Dict), 1, allocator);
+ return Allocator_calloc(allocator, sizeof(Dict), 1);
}
/**
@@ -126,7 +126,7 @@ static Object* putObject(Dict* dictionary,
prev_p = &(current->next);
current = current->next;
}
- struct Dict_Entry* entry = allocator->malloc(sizeof(struct Dict_Entry), allocator);
+ struct Dict_Entry* entry = Allocator_malloc(allocator, sizeof(struct Dict_Entry));
entry->key = key;
entry->val = value;
entry->next = current;
@@ -141,10 +141,10 @@ Object* Dict_putInt(Dict* dictionary,
int64_t value,
const struct Allocator* allocator)
{
- Object* v = allocator->clone(sizeof(Object), allocator, &(Object) {
+ Object* v = Allocator_clone(allocator, (&(Object) {
.type = Object_INTEGER,
.as.number = value
- });
+ }));
return putObject(dictionary, key, v, allocator);
}
@@ -157,10 +157,10 @@ Object* Dict_putString(Dict* dictionary,
if (key == NULL || value == NULL) {
return NULL;
}
- Object* v = allocator->clone(sizeof(Object), allocator, &(Object) {
+ Object* v = Allocator_clone(allocator, (&(Object) {
.type = Object_STRING,
.as.string = value
- });
+ }));
return putObject(dictionary, key, v, allocator);
}
@@ -173,11 +173,11 @@ Object* Dict_putList(Dict* dictionary,
if (key == NULL || value == NULL) {
return NULL;
}
- Object* v = allocator->clone(sizeof(Object), allocator, &(Object) {
+ Object* v = Allocator_clone(allocator, (&(Object) {
.type = Object_LIST,
/* Lists and dictionaries are double pointers so they have to be loaded. */
.as.list = value
- });
+ }));
return putObject(dictionary, key, v, allocator);
}
@@ -189,11 +189,11 @@ Object* Dict_putDict(Dict* dictionary,
if (key == NULL || value == NULL) {
return NULL;
}
- Object* v = allocator->clone(sizeof(Object), allocator, &(Object) {
+ Object* v = Allocator_clone(allocator, (&(Object) {
.type = Object_DICT,
/* Lists and dictionaries are double pointers so they have to be loaded. */
.as.dictionary = value
- });
+ }));
return putObject(dictionary, key, v, allocator);
}
View
@@ -31,11 +31,11 @@ int32_t List_size(const List* list)
static List* addObject(List* list, Object* item, const struct Allocator* allocator)
{
if (list == NULL) {
- List* newList = allocator->calloc(sizeof(List), 1, allocator);
+ List* newList = Allocator_calloc(allocator, sizeof(List), 1);
return addObject(newList, item, allocator);
}
- struct List_Item* entry = allocator->malloc(sizeof(struct List_Item), allocator);
+ struct List_Item* entry = Allocator_malloc(allocator, sizeof(struct List_Item));
entry->next = *list;
entry->elem = item;
*list = entry;
@@ -46,40 +46,40 @@ static List* addObject(List* list, Object* item, const struct Allocator* allocat
/** @see Object.h */
List* List_addInt(List* list, int64_t toAdd, const struct Allocator* allocator)
{
- Object* obj = allocator->clone(sizeof(Object), allocator, &(Object) {
+ Object* obj = Allocator_clone(allocator, (&(Object) {
.type = Object_INTEGER,
.as.number = toAdd
- });
+ }));
return addObject(list, obj, allocator);
}
/** @see Object.h */
List* List_addString(List* list, String* toAdd, const struct Allocator* allocator)
{
- Object* obj = allocator->clone(sizeof(Object), allocator, &(Object) {
+ Object* obj = Allocator_clone(allocator, (&(Object) {
.type = Object_STRING,
.as.string = toAdd
- });
+ }));
return addObject(list, obj, allocator);
}
/** @see Object.h */
List* List_addDict(List* list, Dict* toAdd, const struct Allocator* allocator)
{
- Object* obj = allocator->clone(sizeof(Object), allocator, &(Object) {
+ Object* obj = Allocator_clone(allocator, (&(Object) {
.type = Object_DICT,
.as.dictionary = toAdd
- });
+ }));
return addObject(list, obj, allocator);
}
/** @see Object.h */
List* List_addList(List* list, List* toAdd, const struct Allocator* allocator)
{
- Object* obj = allocator->clone(sizeof(Object), allocator, &(Object) {
+ Object* obj = Allocator_clone(allocator, (&(Object) {
.type = Object_LIST,
.as.list = toAdd
- });
+ }));
return addObject(list, obj, allocator);
}
View
@@ -30,15 +30,15 @@ String* String_new(const char* bytes, const struct Allocator* allocator)
/** @see Object.h */
String* String_newBinary(const char* bytes, size_t length, const struct Allocator* allocator)
{
- char* copy = allocator->malloc(length + 1, allocator);
+ char* copy = Allocator_malloc(allocator, length + 1);
// Make the string null terminated so it will print nicely.
copy[length] = '\0';
if (bytes != NULL) {
Bits_memcpy(copy, bytes, length);
} else {
Bits_memset(copy, '\0', length);
}
- String* string = allocator->malloc(sizeof(String), allocator);
+ String* string = Allocator_malloc(allocator, sizeof(String));
string->len = length;
string->bytes = copy;
return string;
@@ -109,10 +109,10 @@ static inline int parseString(const struct Reader* reader,
int curSize = BUFF_SZ;
struct Allocator* localAllocator = Allocator_child(allocator);
- uint8_t* buffer = localAllocator->malloc(curSize, localAllocator);
+ uint8_t* buffer = Allocator_malloc(localAllocator, curSize);
if (readUntil('"', reader) || reader->read(buffer, 1, reader)) {
printf("Unterminated string\n");
- localAllocator->free(localAllocator);
+ Allocator_free(localAllocator);
return OUT_OF_CONTENT_TO_READ;
}
for (int i = 0; i < BUFF_MAX - 1; i++) {
@@ -122,38 +122,38 @@ static inline int parseString(const struct Reader* reader,
uint8_t hex[2];
if (reader->read((char*)hex, 2, reader)) {
printf("Unexpected end of input parsing escape sequence\n");
- localAllocator->free(localAllocator);
+ Allocator_free(localAllocator);
return OUT_OF_CONTENT_TO_READ;
}
int byte = Hex_decodeByte(hex[0], hex[1]);
if (byte == -1) {
printf("Invalid escape \"%c%c\" after \"%.*s\"\n",hex[0],hex[1],i+1,buffer);
- localAllocator->free(localAllocator);
+ Allocator_free(localAllocator);
return UNPARSABLE;
}
buffer[i] = (uint8_t) byte;
} else if (buffer[i] == '"') {
*output = String_newBinary((char*)buffer, i, allocator);
- localAllocator->free(localAllocator);
+ Allocator_free(localAllocator);
return 0;
}
if (i == curSize - 1) {
curSize <<= 1;
- buffer = localAllocator->realloc(buffer, curSize, localAllocator);
+ buffer = Allocator_realloc(localAllocator, buffer, curSize);
}
if (reader->read(buffer + i + 1, 1, reader)) {
if (i+1 <= 20) {
printf("Unterminated string \"%.*s\"\n", i+1, buffer);
} else {
printf("Unterminated string starting with \"%.*s...\"\n", 20, buffer);
}
- localAllocator->free(localAllocator);
+ Allocator_free(localAllocator);
return OUT_OF_CONTENT_TO_READ;
}
}
printf("Maximum string length of %d bytes exceeded.\n",BUFF_SZ);
- localAllocator->free(localAllocator);
+ Allocator_free(localAllocator);
return UNPARSABLE;
#undef BUFF_SZ
@@ -337,7 +337,7 @@ static int32_t parseList(const struct Reader* reader,
if ((ret = parseGeneric(reader, allocator, &element)) != 0) {
return ret;
}
- thisEntry = allocator->malloc(sizeof(struct List_Item), allocator);
+ thisEntry = Allocator_malloc(allocator, sizeof(struct List_Item));
thisEntry->elem = element;
thisEntry->next = NULL;
@@ -437,7 +437,7 @@ static int32_t parseDictionary(const struct Reader* reader,
}
/* Allocate the entry. */
- entryPointer = allocator->malloc(sizeof(struct Dict_Entry), allocator);
+ entryPointer = Allocator_malloc(allocator, sizeof(struct Dict_Entry));
entryPointer->next = lastEntryPointer;
entryPointer->key = key;
@@ -479,7 +479,7 @@ static int32_t parseGeneric(const struct Reader* reader,
break;
}
- Object* out = allocator->malloc(sizeof(Object), allocator);
+ Object* out = Allocator_malloc(allocator, sizeof(Object));
switch (firstChar) {
case '0':
@@ -503,15 +503,15 @@ static int32_t parseGeneric(const struct Reader* reader,
case '[':;
// List.
- List* list = allocator->calloc(sizeof(List), 1, allocator);
+ List* list = Allocator_calloc(allocator, sizeof(List), 1);
ret = parseList(reader, allocator, list);
out->type = Object_LIST;
out->as.list = list;
break;
case '{':;
// Dictionary
- Dict* dict = allocator->calloc(sizeof(Dict), 1, allocator);
+ Dict* dict = Allocator_calloc(allocator, sizeof(Dict), 1);
ret = parseDictionary(reader, allocator, dict);
out->type = Object_DICT;
out->as.dictionary = dict;
Oops, something went wrong.

0 comments on commit c82ead8

Please sign in to comment.