changed callback signatures to allow for return codes

develop
doomchild 2010-05-27 12:34:43 -05:00
parent 6e91b7c9de
commit 3caac25145
3 changed files with 65 additions and 49 deletions

@ -41,31 +41,31 @@ using namespace DFHack;
extern "C" {
#endif
int8_t* (*alloc_byte_buffer_callback)(uint32_t) = NULL;
int16_t* (*alloc_short_buffer_callback)(uint32_t) = NULL;
int32_t* (*alloc_int_buffer_callback)(uint32_t) = NULL;
int (*alloc_byte_buffer_callback)(int8_t*, uint32_t) = NULL;
int (*alloc_short_buffer_callback)(int16_t*, uint32_t) = NULL;
int (*alloc_int_buffer_callback)(int32_t*, uint32_t) = NULL;
uint8_t* (*alloc_ubyte_buffer_callback)(uint32_t) = NULL;
uint16_t* (*alloc_ushort_buffer_callback)(uint32_t) = NULL;
uint32_t* (*alloc_uint_buffer_callback)(uint32_t) = NULL;
int (*alloc_ubyte_buffer_callback)(uint8_t*, uint32_t) = NULL;
int (*alloc_ushort_buffer_callback)(uint16_t*, uint32_t) = NULL;
int (*alloc_uint_buffer_callback)(uint32_t*, uint32_t) = NULL;
char* (*alloc_char_buffer_callback)(uint32_t) = NULL;
int (*alloc_char_buffer_callback)(char*, uint32_t) = NULL;
t_matgloss* (*alloc_matgloss_buffer_callback)(int) = NULL;
t_descriptor_color* (*alloc_descriptor_buffer_callback)(int) = NULL;
t_matglossOther* (*alloc_matgloss_other_buffer_callback)(int) = NULL;
int (*alloc_matgloss_buffer_callback)(t_matgloss*, uint32_t) = NULL;
int (*alloc_descriptor_buffer_callback)(t_descriptor_color*, uint32_t) = NULL;
int (*alloc_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t) = NULL;
c_colormodifier* (*alloc_empty_colormodifier_callback)(void) = NULL;
c_colormodifier* (*alloc_colormodifier_callback)(const char*, uint32_t) = NULL;
c_colormodifier* (*alloc_colormodifier_buffer_callback)(uint32_t) = NULL;
int (*alloc_empty_colormodifier_callback)(c_colormodifier*) = NULL;
int (*alloc_colormodifier_callback)(c_colormodifier*, const char*, uint32_t) = NULL;
int (*alloc_colormodifier_buffer_callback)(c_colormodifier*, uint32_t) = NULL;
c_creaturecaste* (*alloc_empty_creaturecaste_callback)(void) = NULL;
c_creaturecaste* (*alloc_creaturecaste_callback)(const char*, const char*, const char*, const char*, uint32_t, uint32_t) = NULL;
c_creaturecaste* (*alloc_creaturecaste_buffer_callback)(uint32_t) = NULL;
int (*alloc_empty_creaturecaste_callback)(c_creaturecaste*)= NULL;
int (*alloc_creaturecaste_callback)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t) = NULL;
int (*alloc_creaturecaste_buffer_callback)(c_creaturecaste*, uint32_t) = NULL;
c_creaturetype* (*alloc_empty_creaturetype_callback)(void) = NULL;
c_creaturetype* (*alloc_creaturetype_callback)(const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t) = NULL;
c_creaturetype* (*alloc_creaturetype_buffer_callback)(uint32_t) = NULL;
int (*alloc_empty_creaturetype_callback)(c_creaturetype*) = NULL;
int (*alloc_creaturetype_callback)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t) = NULL;
int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t) = NULL;
#ifdef __cplusplus
}
@ -76,7 +76,7 @@ int ColorListConvert(t_colormodifier* src, c_colormodifier* dest)
if(src == NULL)
return -1;
dest = ((*alloc_colormodifier_callback)(src->part, src->colorlist.size()));
((*alloc_colormodifier_callback)(dest, src->part, src->colorlist.size()));
copy(src->colorlist.begin(), src->colorlist.end(), dest->colorlist);
@ -88,7 +88,7 @@ int CreatureCasteConvert(t_creaturecaste* src, c_creaturecaste* dest)
if(src == NULL)
return -1;
dest = ((*alloc_creaturecaste_callback)(src->rawname, src->singular, src->plural, src->adjective, src->ColorModifier.size(), src->bodypart.size()));
((*alloc_creaturecaste_callback)(dest, src->rawname, src->singular, src->plural, src->adjective, src->ColorModifier.size(), src->bodypart.size()));
for(int i = 0; i < dest->colorModifierLength; i++)
ColorListConvert(&src->ColorModifier[i], &dest->ColorModifier[i]);
@ -103,7 +103,7 @@ int CreatureTypeConvert(t_creaturetype* src, c_creaturetype* dest)
if(src == NULL)
return -1;
dest = ((*alloc_creaturetype_callback)(src->rawname, src->castes.size(), src->extract.size(), src->tile_character, src->tilecolor.fore, src->tilecolor.back, src->tilecolor.bright));
((*alloc_creaturetype_callback)(dest, src->rawname, src->castes.size(), src->extract.size(), src->tile_character, src->tilecolor.fore, src->tilecolor.back, src->tilecolor.bright));
for(int i = 0; i < dest->castesCount; i++)
CreatureCasteConvert(&src->castes[i], &dest->castes[i]);

@ -33,19 +33,19 @@ distribution.
extern "C" {
#endif
DFHACK_EXPORT extern int8_t* (*alloc_byte_buffer_callback)(uint32_t);
DFHACK_EXPORT extern int16_t* (*alloc_short_buffer_callback)(uint32_t);
DFHACK_EXPORT extern int32_t* (*alloc_int_buffer_callback)(uint32_t);
DFHACK_EXPORT extern int (*alloc_byte_buffer_callback)(int8_t*, uint32_t);
DFHACK_EXPORT extern int (*alloc_short_buffer_callback)(int16_t*, uint32_t);
DFHACK_EXPORT extern int (*alloc_int_buffer_callback)(int32_t*, uint32_t);
DFHACK_EXPORT extern uint8_t* (*alloc_ubyte_buffer_callback)(uint32_t);
DFHACK_EXPORT extern uint16_t* (*alloc_ushort_buffer_callback)(uint32_t);
DFHACK_EXPORT extern uint32_t* (*alloc_uint_buffer_callback)(uint32_t);
DFHACK_EXPORT extern int (*alloc_ubyte_buffer_callback)(uint8_t*, uint32_t);
DFHACK_EXPORT extern int (*alloc_ushort_buffer_callback)(uint16_t*, uint32_t);
DFHACK_EXPORT extern int (*alloc_uint_buffer_callback)(uint32_t*, uint32_t);
DFHACK_EXPORT extern char* (*alloc_char_buffer_callback)(uint32_t);
DFHACK_EXPORT extern int (*alloc_char_buffer_callback)(char*, uint32_t);
DFHACK_EXPORT extern t_matgloss* (*alloc_matgloss_buffer_callback)(int);
DFHACK_EXPORT extern t_descriptor_color* (*alloc_descriptor_buffer_callback)(int);
DFHACK_EXPORT extern t_matglossOther* (*alloc_matgloss_other_buffer_callback)(int);
DFHACK_EXPORT extern int (*alloc_matgloss_buffer_callback)(t_matgloss*, uint32_t);
DFHACK_EXPORT extern int (*alloc_descriptor_buffer_callback)(t_descriptor_color*, uint32_t);
DFHACK_EXPORT extern int (*alloc_matgloss_other_buffer_callback)(t_matglossOther*, uint32_t);
struct c_colormodifier
{
@ -54,9 +54,9 @@ struct c_colormodifier
uint32_t colorlistLength;
};
DFHACK_EXPORT extern c_colormodifier* (*alloc_empty_colormodifier_callback)(void);
DFHACK_EXPORT extern c_colormodifier* (*alloc_colormodifier_callback)(const char*, uint32_t);
DFHACK_EXPORT extern c_colormodifier* (*alloc_colormodifier_buffer_callback)(uint32_t);
DFHACK_EXPORT extern int (*alloc_empty_colormodifier_callback)(c_colormodifier*);
DFHACK_EXPORT extern int (*alloc_colormodifier_callback)(c_colormodifier*, const char*, uint32_t);
DFHACK_EXPORT extern int (*alloc_colormodifier_buffer_callback)(c_colormodifier*, uint32_t);
struct c_creaturecaste
{
@ -72,9 +72,9 @@ struct c_creaturecaste
uint32_t bodypartLength;
};
DFHACK_EXPORT extern c_creaturecaste* (*alloc_empty_creaturecaste_callback)(void);
DFHACK_EXPORT extern c_creaturecaste* (*alloc_creaturecaste_callback)(const char*, const char*, const char*, const char*, uint32_t, uint32_t);
DFHACK_EXPORT extern c_creaturecaste* (*alloc_creaturecaste_buffer_callback)(uint32_t);
DFHACK_EXPORT extern int (*alloc_empty_creaturecaste_callback)(c_creaturecaste*);
DFHACK_EXPORT extern int (*alloc_creaturecaste_callback)(c_creaturecaste*, const char*, const char*, const char*, const char*, uint32_t, uint32_t);
DFHACK_EXPORT extern int (*alloc_creaturecaste_buffer_callback)(c_creaturecaste*, uint32_t);
struct c_creaturetype
{
@ -96,9 +96,9 @@ struct c_creaturetype
} tilecolor;
};
DFHACK_EXPORT extern c_creaturetype* (*alloc_empty_creaturetype_callback)(void);
DFHACK_EXPORT extern c_creaturetype* (*alloc_creaturetype_callback)(const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t);
DFHACK_EXPORT extern c_creaturetype* (*alloc_creaturetype_buffer_callback)(uint32_t);
DFHACK_EXPORT extern int (*alloc_empty_creaturetype_callback)(c_creaturetype*);
DFHACK_EXPORT extern int (*alloc_creaturetype_callback)(c_creaturetype*, const char*, uint32_t, uint32_t, uint8_t, uint16_t, uint16_t, uint16_t);
DFHACK_EXPORT extern int (*alloc_creaturetype_buffer_callback)(c_creaturetype*, uint32_t);
#ifdef __cplusplus
}

@ -220,7 +220,9 @@ t_matgloss* Materials_getInorganic(DFHackObject* mat)
if(materials->inorganic.size() > 0)
{
t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->inorganic.size()));
t_matgloss* buf;
((*alloc_matgloss_buffer_callback)(buf, materials->inorganic.size()));
if(buf != NULL)
{
@ -242,7 +244,9 @@ t_matgloss* Materials_getOrganic(DFHackObject* mat)
if(materials->organic.size() > 0)
{
t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->organic.size()));
t_matgloss* buf;
((*alloc_matgloss_buffer_callback)(buf, materials->organic.size()));
if(buf != NULL)
{
@ -264,7 +268,9 @@ t_matgloss* Materials_getTree(DFHackObject* mat)
if(materials->tree.size() > 0)
{
t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->tree.size()));
t_matgloss* buf;
((*alloc_matgloss_buffer_callback)(buf, materials->tree.size()));
if(buf != NULL)
{
@ -286,7 +292,9 @@ t_matgloss* Materials_getPlant(DFHackObject* mat)
if(materials->plant.size() > 0)
{
t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->plant.size()));
t_matgloss* buf;
((*alloc_matgloss_buffer_callback)(buf, materials->plant.size()));
if(buf != NULL)
{
@ -308,7 +316,9 @@ t_matgloss* Materials_getRace(DFHackObject* mat)
if(materials->race.size() > 0)
{
t_matgloss* buf = ((*alloc_matgloss_buffer_callback)(materials->race.size()));
t_matgloss* buf;
((*alloc_matgloss_buffer_callback)(buf, materials->race.size()));
if(buf != NULL)
{
@ -332,7 +342,9 @@ c_creaturetype* Materials_getRaceEx(DFHackObject* mat)
if(matSize > 0)
{
c_creaturetype* buf = ((*alloc_creaturetype_buffer_callback)(matSize));
c_creaturetype* buf;
((*alloc_creaturetype_buffer_callback)(buf, matSize));
if(buf != NULL)
{
@ -355,7 +367,9 @@ t_descriptor_color* Materials_getColor(DFHackObject* mat)
if(materials->color.size() > 0)
{
t_descriptor_color* buf = ((*alloc_descriptor_buffer_callback)(materials->color.size()));
t_descriptor_color* buf;
((*alloc_descriptor_buffer_callback)(buf, materials->color.size()));
if(buf != NULL)
{
@ -377,7 +391,9 @@ t_matglossOther* Materials_getOther(DFHackObject* mat)
if(materials->other.size() > 0)
{
t_matglossOther* buf = ((*alloc_matgloss_other_buffer_callback)(materials->other.size()));
t_matglossOther* buf;
((*alloc_matgloss_other_buffer_callback)(buf, materials->other.size()));
if(buf != NULL)
{