From 5bd51c2e08c3a7779751d2a442605b141d98ee39 Mon Sep 17 00:00:00 2001 From: doomchild Date: Wed, 9 Mar 2011 12:23:48 -0600 Subject: [PATCH] updated to use the allocator callbacks correctly --- library/modules/Buildings_C.cpp | 2 +- library/modules/Creatures_C.cpp | 6 +-- library/modules/Items_C.cpp | 7 +++- library/modules/Materials_C.cpp | 60 +++++++++++++++++++++--------- library/modules/Position_C.cpp | 4 +- library/modules/Translation_C.cpp | 62 +------------------------------ 6 files changed, 55 insertions(+), 86 deletions(-) diff --git a/library/modules/Buildings_C.cpp b/library/modules/Buildings_C.cpp index ed3e3e74e..5fee4677a 100644 --- a/library/modules/Buildings_C.cpp +++ b/library/modules/Buildings_C.cpp @@ -81,7 +81,7 @@ t_customWorkshop* Buildings_ReadCustomWorkshopTypes(DFHackObject* b_Ptr) if(!((DFHack::Buildings*)b_Ptr)->ReadCustomWorkshopTypes(bTypes)) return NULL; - (*alloc_t_customWorkshop_buffer_callback)(cw_Ptr, bTypes.size()); + (*alloc_t_customWorkshop_buffer_callback)(&cw_Ptr, bTypes.size()); if(cw_Ptr == NULL) return NULL; diff --git a/library/modules/Creatures_C.cpp b/library/modules/Creatures_C.cpp index 297a15460..b34c6e8d9 100644 --- a/library/modules/Creatures_C.cpp +++ b/library/modules/Creatures_C.cpp @@ -86,7 +86,7 @@ t_material* Creatures_ReadJob(DFHackObject* cPtr, const t_creature* furball) t_material* buf = NULL; - (*alloc_t_material_buffer_callback)(buf, mat.size()); + (*alloc_t_material_buffer_callback)(&buf, mat.size()); if(buf != NULL) { @@ -117,7 +117,7 @@ uint32_t* Creatures_ReadInventoryIdx(DFHackObject* cPtr, const uint32_t index) uint32_t* buf = NULL; - (*alloc_uint_buffer_callback)(buf, item.size()); + (*alloc_uint_buffer_callback)(&buf, item.size()); if(buf != NULL) { @@ -146,7 +146,7 @@ uint32_t* Creatures_ReadInventoryPtr(DFHackObject* cPtr, const uint32_t index) uint32_t* buf = NULL; - (*alloc_uint_buffer_callback)(buf, item.size()); + (*alloc_uint_buffer_callback)(&buf, item.size()); if(buf != NULL) { diff --git a/library/modules/Items_C.cpp b/library/modules/Items_C.cpp index bfc31f2f4..7b366aece 100644 --- a/library/modules/Items_C.cpp +++ b/library/modules/Items_C.cpp @@ -59,7 +59,8 @@ char* Items_getItemDescription(DFHackObject* items, uint32_t itemptr, DFHackObje if(desc.size() > 0) { char* buf = NULL; - (*alloc_char_buffer_callback)(buf,desc.size()); + + (*alloc_char_buffer_callback)(&buf, desc.size()); if(buf != NULL) { @@ -87,7 +88,9 @@ char* Items_getItemClass(DFHackObject* items, int32_t index) if(iclass.size() > 0) { char* buf = NULL; - (*alloc_char_buffer_callback)(buf, iclass.size()); + + (*alloc_char_buffer_callback)(&buf, iclass.size()); + if(buf != NULL) { size_t len = iclass.copy(buf, iclass.size()); diff --git a/library/modules/Materials_C.cpp b/library/modules/Materials_C.cpp index e8e42af76..c334e5595 100644 --- a/library/modules/Materials_C.cpp +++ b/library/modules/Materials_C.cpp @@ -32,7 +32,10 @@ int Materials_ReadInorganicMaterials(DFHackObject* mat) { if(mat != NULL) { - return ((DFHack::Materials*)mat)->ReadInorganicMaterials(); + if(((DFHack::Materials*)mat)->ReadInorganicMaterials() == true) + return 1; + else + return 0; } return -1; @@ -42,7 +45,10 @@ int Materials_ReadOrganicMaterials(DFHackObject* mat) { if(mat != NULL) { - return ((DFHack::Materials*)mat)->ReadOrganicMaterials(); + if(((DFHack::Materials*)mat)->ReadOrganicMaterials() == true) + return 1; + else + return 0; } return -1; @@ -52,7 +58,10 @@ int Materials_ReadWoodMaterials(DFHackObject* mat) { if(mat != NULL) { - return ((DFHack::Materials*)mat)->ReadWoodMaterials(); + if(((DFHack::Materials*)mat)->ReadWoodMaterials() == true) + return 1; + else + return 0; } return -1; @@ -62,7 +71,10 @@ int Materials_ReadPlantMaterials(DFHackObject* mat) { if(mat != NULL) { - return ((DFHack::Materials*)mat)->ReadPlantMaterials(); + if(((DFHack::Materials*)mat)->ReadPlantMaterials() == true) + return 1; + else + return 0; } return -1; @@ -72,7 +84,10 @@ int Materials_ReadCreatureTypes(DFHackObject* mat) { if(mat != NULL) { - return ((DFHack::Materials*)mat)->ReadCreatureTypes(); + if(((DFHack::Materials*)mat)->ReadCreatureTypes() == true) + return 1; + else + return 0; } return -1; @@ -82,7 +97,10 @@ int Materials_ReadCreatureTypesEx(DFHackObject* mat) { if(mat != NULL) { - return ((DFHack::Materials*)mat)->ReadCreatureTypesEx(); + if(((DFHack::Materials*)mat)->ReadCreatureTypesEx() == true) + return 1; + else + return 0; } return -1; @@ -92,7 +110,10 @@ int Materials_ReadDescriptorColors(DFHackObject* mat) { if(mat != NULL) { - return ((DFHack::Materials*)mat)->ReadDescriptorColors(); + if(((DFHack::Materials*)mat)->ReadDescriptorColors() == true) + return 1; + else + return 0; } return -1; @@ -102,7 +123,10 @@ int Materials_ReadOthers(DFHackObject* mat) { if(mat != NULL) { - return ((DFHack::Materials*)mat)->ReadOthers(); + if(((DFHack::Materials*)mat)->ReadOthers() == true) + return 1; + else + return 0; } return -1; @@ -237,7 +261,7 @@ t_matgloss* Materials_getInorganic(DFHackObject* mat) if(alloc_matgloss_buffer_callback == NULL) return NULL; - ((*alloc_matgloss_buffer_callback)(buf, materials->inorganic.size())); + ((*alloc_matgloss_buffer_callback)(&buf, materials->inorganic.size())); if(buf != NULL) { @@ -264,7 +288,7 @@ t_matgloss* Materials_getOrganic(DFHackObject* mat) if(alloc_matgloss_buffer_callback == NULL) return NULL; - ((*alloc_matgloss_buffer_callback)(buf, materials->organic.size())); + ((*alloc_matgloss_buffer_callback)(&buf, materials->organic.size())); if(buf != NULL) { @@ -291,7 +315,7 @@ t_matgloss* Materials_getTree(DFHackObject* mat) if(alloc_matgloss_buffer_callback == NULL) return NULL; - ((*alloc_matgloss_buffer_callback)(buf, materials->tree.size())); + ((*alloc_matgloss_buffer_callback)(&buf, materials->tree.size())); if(buf != NULL) { @@ -318,7 +342,7 @@ t_matgloss* Materials_getPlant(DFHackObject* mat) if(alloc_matgloss_buffer_callback == NULL) return NULL; - ((*alloc_matgloss_buffer_callback)(buf, materials->plant.size())); + ((*alloc_matgloss_buffer_callback)(&buf, materials->plant.size())); if(buf != NULL) { @@ -345,7 +369,7 @@ t_matgloss* Materials_getRace(DFHackObject* mat) if(alloc_matgloss_buffer_callback == NULL) return NULL; - ((*alloc_matgloss_buffer_callback)(buf, materials->race.size())); + ((*alloc_matgloss_buffer_callback)(&buf, materials->race.size())); if(buf != NULL) { @@ -374,12 +398,12 @@ c_creaturetype* Materials_getRaceEx(DFHackObject* mat) if(alloc_creaturetype_buffer_callback == NULL) return NULL; - ((*alloc_creaturetype_buffer_callback)(buf, matSize)); + ((*alloc_creaturetype_buffer_callback)(&buf, matSize)); if(buf != NULL) { for(int i = 0; i < matSize; i++) - CreatureTypeConvert(&materials->raceEx[i], &buf[i]); + CreatureTypeConvert(&materials->raceEx[i], &(buf[i])); return buf; } @@ -399,7 +423,7 @@ t_descriptor_color* Materials_getColor(DFHackObject* mat) { t_descriptor_color* buf = NULL; - ((*alloc_descriptor_buffer_callback)(buf, materials->color.size())); + ((*alloc_descriptor_buffer_callback)(&buf, materials->color.size())); if(buf != NULL) { @@ -423,7 +447,7 @@ t_matglossOther* Materials_getOther(DFHackObject* mat) { t_matglossOther* buf = NULL; - ((*alloc_matgloss_other_buffer_callback)(buf, materials->other.size())); + ((*alloc_matgloss_other_buffer_callback)(&buf, materials->other.size())); if(buf != NULL) { @@ -447,7 +471,7 @@ t_matgloss* Materials_getAllDesc(DFHackObject* mat) { t_matgloss* buf = NULL; - ((*alloc_matgloss_buffer_callback)(buf, materials->alldesc.size())); + ((*alloc_matgloss_buffer_callback)(&buf, materials->alldesc.size())); if(buf != NULL) { diff --git a/library/modules/Position_C.cpp b/library/modules/Position_C.cpp index 386bd1c5b..e3e4af199 100644 --- a/library/modules/Position_C.cpp +++ b/library/modules/Position_C.cpp @@ -104,7 +104,7 @@ t_hotkey* Position_ReadHotkeys(DFHackObject* pos) { t_hotkey* buf = NULL; - (*alloc_t_hotkey_buffer_callback)(buf, NUM_HOTKEYS); + (*alloc_t_hotkey_buffer_callback)(&buf, NUM_HOTKEYS); if(buf != NULL) { @@ -146,7 +146,7 @@ t_screen* Position_getScreenTiles(DFHackObject* pos, int32_t width, int32_t heig { t_screen* buf = NULL; - (*alloc_t_screen_buffer_callback)(buf, width * height); + (*alloc_t_screen_buffer_callback)(&buf, width * height); if(buf == NULL) return NULL; diff --git a/library/modules/Translation_C.cpp b/library/modules/Translation_C.cpp index 7032f26c5..64420ae33 100644 --- a/library/modules/Translation_C.cpp +++ b/library/modules/Translation_C.cpp @@ -58,64 +58,6 @@ int Translation_Finish(DFHackObject* trans) return -1; } -// char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int)) -// { - // if(trans != NULL) - // { - // std::string nameTrans = ((DFHack::Translation*)trans)->TranslateName(*name, true); - - // if(nameTrans.size() > 0) - // { - // char* buf = (*char_buffer_create)(nameTrans.size()); - - // if(buf != NULL) - // { - // size_t len = nameTrans.copy(buf, nameTrans.size()); - - // if(len > 0) - // buf[len] = '\0'; - // else - // buf[0] = '\0'; - // } - - // return buf; - // } - // else - // return NULL; - // } - - // return NULL; -// } - -// char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_name* name, char* (*char_buffer_create)(int)) -// { - // if(trans != NULL) - // { - // std::string nameTrans = ((DFHack::Translation*)trans)->TranslateName(*name, false); - - // if(nameTrans.size() > 0) - // { - // char* buf = (*char_buffer_create)(nameTrans.size()); - - // if(buf != NULL) - // { - // size_t len = nameTrans.copy(buf, nameTrans.size()); - - // if(len > 0) - // buf[len] = '\0'; - // else - // buf[0] = '\0'; - // } - - // return buf; - // } - // else - // return NULL; - // } - - // return NULL; -// } - char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name* name) { if(trans != NULL) @@ -126,7 +68,7 @@ char* Translation_TranslateNameEnglish(DFHackObject* trans, const DFHack::t_name { char* buf = NULL; - (*alloc_char_buffer_callback)(buf, nameTrans.size()); + (*alloc_char_buffer_callback)(&buf, nameTrans.size()); if(buf != NULL) { @@ -157,7 +99,7 @@ char* Translation_TranslateNameNonEnglish(DFHackObject* trans, const DFHack::t_n { char* buf = NULL; - (*alloc_char_buffer_callback)(buf, nameTrans.size()); + (*alloc_char_buffer_callback)(&buf, nameTrans.size()); if(buf != NULL) {