Changed g_strdup_printf -> ep_strdup_printf.

Use correct modifier for converting gint64 and guint64 to string.
Added __gc for Int64 and UInt64.
Fixed some indents.

svn path=/trunk/; revision=28655
This commit is contained in:
Stig Bjørlykke 2009-06-08 08:02:15 +00:00
parent 923b8ae800
commit b7207572ac
4 changed files with 77 additions and 61 deletions

View File

@ -249,9 +249,8 @@ WSLUA_METAMETHOD Listener_tostring(lua_State* L) {
if (!tap) return 0;
str = g_strdup_printf("Listener(%s) filter: %s",tap->name, tap->filter ? tap->filter : "NONE");
str = ep_strdup_printf("Listener(%s) filter: %s",tap->name, tap->filter ? tap->filter : "NONE");
lua_pushstring(L,str);
g_free(str);
return 1;
}

View File

@ -280,7 +280,7 @@ WSLUA_META Address_meta[] = {
int Address_register(lua_State *L) {
WSLUA_REGISTER_CLASS(Address);
WSLUA_REGISTER_CLASS(Address);
return 1;
}
@ -409,13 +409,13 @@ WSLUA_METHOD Column_clear(lua_State *L) {
WSLUA_METHOD Column_set(lua_State *L) {
/* Sets the text of a Column */
#define WSLUA_ARG_Column_set_TEXT 2 /* The text to which to set the Column */
Column c = checkColumn(L,1);
Column c = checkColumn(L,1);
const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_set_TEXT);
if (!(c && c->cinfo))
return 0;
return 0;
if (!s) WSLUA_ARG_ERROR(Column_set,TEXT,"must be a string");
if (!s) WSLUA_ARG_ERROR(Column_set,TEXT,"must be a string");
if (check_col(c->cinfo, c->col))
col_set_str(c->cinfo, c->col, s);
@ -429,11 +429,10 @@ WSLUA_METHOD Column_append(lua_State *L) {
Column c = checkColumn(L,1);
const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_append_TEXT);
if (!(c && c->cinfo))
return 0;
if (!s) WSLUA_ARG_ERROR(Column_append,TEXT,"must be a string");
if (!(c && c->cinfo))
return 0;
if (!s) WSLUA_ARG_ERROR(Column_append,TEXT,"must be a string");
if (check_col(c->cinfo, c->col))
col_append_str(c->cinfo, c->col, s);
@ -447,10 +446,10 @@ WSLUA_METHOD Column_preppend(lua_State *L) {
Column c = checkColumn(L,1);
const gchar* s = luaL_checkstring(L,WSLUA_ARG_Column_prepend_TEXT);
if (!(c && c->cinfo))
return 0;
if (!(c && c->cinfo))
return 0;
if (!s) WSLUA_ARG_ERROR(Column_prepend,TEXT,"must be a string");
if (!s) WSLUA_ARG_ERROR(Column_prepend,TEXT,"must be a string");
if (check_col(c->cinfo, c->col))
col_prepend_fstr(c->cinfo, c->col, "%s",s);
@ -475,7 +474,7 @@ WSLUA_META Column_meta[] = {
int Column_register(lua_State *L) {
WSLUA_REGISTER_CLASS(Column);
WSLUA_REGISTER_CLASS(Column);
return 1;
}
@ -490,7 +489,7 @@ WSLUA_CLASS_DEFINE(Columns,NOP,NOP);
WSLUA_METAMETHOD Columns__tostring(lua_State *L) {
lua_pushstring(L,"Columns");
WSLUA_RETURN(1);
/* The string "Columns", no real use, just for debugging purposes. */
/* The string "Columns", no real use, just for debugging purposes. */
}
WSLUA_METAMETHOD Columns__newindex(lua_State *L) {
@ -587,7 +586,7 @@ static const luaL_reg Columns_meta[] = {
int Columns_register(lua_State *L) {
WSLUA_REGISTER_META(Columns);
WSLUA_REGISTER_META(Columns);
return 1;
}
@ -830,42 +829,42 @@ typedef struct _pinfo_method_t {
static int Pinfo_hi(lua_State *L) {
Pinfo pinfo = checkPinfo(L,1);
Address addr = g_malloc(sizeof(address));
Address addr = g_malloc(sizeof(address));
if (!pinfo) return 0;
if (pinfo->expired) {
if (!pinfo) return 0;
if (pinfo->expired) {
luaL_error(L,"expired_pinfo");
return 0;
}
if (CMP_ADDRESS(&(pinfo->ws_pinfo->src), &(pinfo->ws_pinfo->dst) ) >= 0) {
COPY_ADDRESS(addr, &(pinfo->ws_pinfo->src));
} else {
COPY_ADDRESS(addr, &(pinfo->ws_pinfo->dst));
}
if (CMP_ADDRESS(&(pinfo->ws_pinfo->src), &(pinfo->ws_pinfo->dst) ) >= 0) {
COPY_ADDRESS(addr, &(pinfo->ws_pinfo->src));
} else {
COPY_ADDRESS(addr, &(pinfo->ws_pinfo->dst));
}
pushAddress(L,addr);
return 1;
pushAddress(L,addr);
return 1;
}
static int Pinfo_lo(lua_State *L) {
Pinfo pinfo = checkPinfo(L,1);
Address addr = g_malloc(sizeof(address));
Address addr = g_malloc(sizeof(address));
if (!pinfo) return 0;
if (pinfo->expired) {
if (!pinfo) return 0;
if (pinfo->expired) {
luaL_error(L,"expired_pinfo");
return 0;
}
if (CMP_ADDRESS(&(pinfo->ws_pinfo->src), &(pinfo->ws_pinfo->dst) ) < 0) {
COPY_ADDRESS(addr, &(pinfo->ws_pinfo->src));
} else {
COPY_ADDRESS(addr, &(pinfo->ws_pinfo->dst));
}
if (CMP_ADDRESS(&(pinfo->ws_pinfo->src), &(pinfo->ws_pinfo->dst) ) < 0) {
COPY_ADDRESS(addr, &(pinfo->ws_pinfo->src));
} else {
COPY_ADDRESS(addr, &(pinfo->ws_pinfo->dst));
}
pushAddress(L,addr);
return 1;
pushAddress(L,addr);
return 1;
}
@ -955,7 +954,7 @@ static const pinfo_method_t Pinfo_methods[] = {
/* WSLUA_ATTRIBUTE Pinfo_private_data RO Access to private data */
{"private_data", Pinfo_private_data, pushnil_param, PARAM_NONE},
{NULL,NULL,NULL,PARAM_NONE}
{NULL,NULL,NULL,PARAM_NONE}
};
@ -1041,7 +1040,7 @@ static const luaL_reg Pinfo_meta[] = {
};
int Pinfo_register(lua_State* L) {
WSLUA_REGISTER_META(Pinfo);
WSLUA_REGISTER_META(Pinfo);
outstanding_Pinfo = g_ptr_array_new();
outstanding_Column = g_ptr_array_new();
outstanding_Columns = g_ptr_array_new();

View File

@ -577,7 +577,7 @@ WSLUA_CONSTRUCTOR ProtoField_new(lua_State* L) { /* Creates a new field to be us
static int ProtoField_integer(lua_State* L, enum ftenum type) {
ProtoField f = g_malloc(sizeof(wslua_field_t));
const gchar* abbr = luaL_checkstring(L,1);
const gchar* abbr = luaL_checkstring(L,1);
const gchar* name = luaL_optstring(L,2,abbr);
base_display_e base = luaL_optint(L, 3, BASE_DEC);
value_string* vs = (lua_gettop(L) > 3) ? value_string_from_table(L,4) : NULL;
@ -591,7 +591,7 @@ static int ProtoField_integer(lua_State* L, enum ftenum type) {
}
f->hfid = -2;
f->ett = -1;
f->ett = -1;
f->name = g_strdup(name);
f->abbr = g_strdup(abbr);
f->type = type;
@ -832,10 +832,9 @@ PROTOFIELD_OTHER(bool,FT_BOOLEAN)
WSLUA_METAMETHOD ProtoField_tostring(lua_State* L) {
/* Returns a string w/ info about a protofiled (for debugging purposes) */
ProtoField f = checkProtoField(L,1);
gchar* s = g_strdup_printf("ProtoField(%i): %s %s %s %s %p %.8x %s",f->hfid,f->name,f->abbr,ftenum_to_string(f->type),base_to_string(f->base),f->vs,f->mask,f->blob);
gchar* s = ep_strdup_printf("ProtoField(%i): %s %s %s %s %p %.8x %s",f->hfid,f->name,f->abbr,ftenum_to_string(f->type),base_to_string(f->base),f->vs,f->mask,f->blob);
lua_pushstring(L,s);
g_free(s);
return 1;
}
@ -980,9 +979,8 @@ static int Proto_tostring(lua_State* L) {
if (!proto) return 0;
s = g_strdup_printf("Proto: %s",proto->name);
s = ep_strdup_printf("Proto: %s",proto->name);
lua_pushstring(L,s);
g_free(s);
return 1;
}

View File

@ -95,8 +95,8 @@ WSLUA_METAMETHOD ByteArray__concat(lua_State* L) {
ByteArray ba = checkByteArray(L,WSLUA_ARG_ByteArray__cat_FIRST);
ByteArray ba2 = checkByteArray(L,WSLUA_ARG_ByteArray__cat_SECOND);
if (! (ba && ba2) )
WSLUA_ERROR(ByteArray__cat,"Both arguments must be ByteArrays");
if (! (ba && ba2) )
WSLUA_ERROR(ByteArray__cat,"Both arguments must be ByteArrays");
g_byte_array_append(ba,ba2->data,ba2->len);
@ -110,8 +110,8 @@ WSLUA_METHOD ByteArray_prepend(lua_State* L) {
ByteArray ba = checkByteArray(L,1);
ByteArray ba2 = checkByteArray(L,WSLUA_ARG_ByteArray_prepend_PREPENDED);
if (! (ba && ba2) )
WSLUA_ERROR(ByteArray_prepend,"Both arguments must be ByteArrays");
if (! (ba && ba2) )
WSLUA_ERROR(ByteArray_prepend,"Both arguments must be ByteArrays");
g_byte_array_prepend(ba,ba2->data,ba2->len);
@ -125,8 +125,8 @@ WSLUA_METHOD ByteArray_append(lua_State* L) {
ByteArray ba = checkByteArray(L,1);
ByteArray ba2 = checkByteArray(L,WSLUA_ARG_ByteArray_append_APPENDED);
if (! (ba && ba2) )
WSLUA_ERROR(ByteArray_append,"Both arguments must be ByteArrays");
if (! (ba && ba2) )
WSLUA_ERROR(ByteArray_append,"Both arguments must be ByteArrays");
g_byte_array_append(ba,ba2->data,ba2->len);
@ -308,7 +308,7 @@ static const luaL_reg ByteArray_meta[] = {
};
int ByteArray_register(lua_State* L) {
WSLUA_REGISTER_CLASS(ByteArray);
WSLUA_REGISTER_CLASS(ByteArray);
return 1;
}
@ -564,7 +564,7 @@ static const luaL_reg Tvb_meta[] = {
};
int Tvb_register(lua_State* L) {
WSLUA_REGISTER_CLASS(Tvb);
WSLUA_REGISTER_CLASS(Tvb);
return 1;
}
@ -751,7 +751,6 @@ WSLUA_METHOD TvbRange_le_float(lua_State* L) {
WSLUA_METHOD TvbRange_ipv4(lua_State* L) {
/* Get an IPv4 Address from a TvbRange. */
TvbRange tvbr = checkTvbRange(L,1);
Address addr;
guint32* ip_addr;
@ -778,7 +777,6 @@ WSLUA_METHOD TvbRange_ipv4(lua_State* L) {
WSLUA_METHOD TvbRange_le_ipv4(lua_State* L) {
/* Get an Little Endian IPv4 Address from a TvbRange. */
TvbRange tvbr = checkTvbRange(L,1);
Address addr;
guint32* ip_addr;
@ -916,7 +914,7 @@ static const luaL_reg TvbRange_methods[] = {
{"le_float", TvbRange_le_float},
{"ether", TvbRange_ether},
{"ipv4", TvbRange_ipv4},
{"le_ipv4", TvbRange_le_ipv4},
{"le_ipv4", TvbRange_le_ipv4},
{"string", TvbRange_string},
{"bytes", TvbRange_bytes},
{"len", TvbRange_len},
@ -937,7 +935,7 @@ int TvbRange_register(lua_State* L) {
return 1;
}
WSLUA_CLASS_DEFINE(Int64,NOP,NOP);
WSLUA_CLASS_DEFINE(Int64,FAIL_ON_NULL("null int64"),NOP);
/*
Int64 represents a 64 bit integer.
Lua uses one single number representation which can be chosen at compile time and since
@ -949,16 +947,27 @@ WSLUA_CLASS_DEFINE(Int64,NOP,NOP);
WSLUA_METAMETHOD Int64__tostring(lua_State* L) {
/* Converts the Int64 into a string */
Int64 num = checkInt64(L,1);
lua_pushstring(L,g_strdup_printf("%ld",(long int)*(num)));
lua_pushstring(L,ep_strdup_printf("%" G_GINT64_MODIFIER "d",(gint64)*(num)));
return 1;
}
static int Int64__gc(lua_State* L) {
Int64 num = checkInt64(L,1);
if (!num) return 0;
g_free(num);
return 0;
}
static const luaL_reg Int64_methods[] = {
{ NULL, NULL }
};
static const luaL_reg Int64_meta[] = {
{"__tostring", Int64__tostring},
{"__tostring", Int64__tostring},
{"__gc", Int64__gc},
{ NULL, NULL }
};
@ -967,22 +976,33 @@ int Int64_register(lua_State* L) {
return 1;
}
WSLUA_CLASS_DEFINE(UInt64,NOP,NOP);
/* Int64 represents a 64 bit integer. */
WSLUA_CLASS_DEFINE(UInt64,FAIL_ON_NULL("null uint64"),NOP);
/* UInt64 represents a 64 bit unsigned integer. */
WSLUA_METAMETHOD UInt64__tostring(lua_State* L) {
/* Converts the UInt64 into a string */
UInt64 num = checkUInt64(L,1);
lua_pushstring(L,g_strdup_printf("%ld",(unsigned long int)*(num)));
lua_pushstring(L,ep_strdup_printf("%" G_GINT64_MODIFIER "u",(guint64)*(num)));
return 1;
}
static int UInt64__gc(lua_State* L) {
UInt64 num = checkUInt64(L,1);
if (!num) return 0;
g_free(num);
return 0;
}
static const luaL_reg UInt64_methods[] = {
{ NULL, NULL }
};
static const luaL_reg UInt64_meta[] = {
{"__tostring", UInt64__tostring},
{"__gc", UInt64__gc},
{ NULL, NULL }
};