diff options
author | Guy Harris <gharris@sonic.net> | 2020-10-13 13:30:52 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2020-10-13 13:30:52 -0700 |
commit | 873e0796596db030257b660c2592518f72370580 (patch) | |
tree | dd3e8d43ba112f3ff837b5eab923bbf428900bc5 /epan/wslua | |
parent | c1950aa8cc5b1fe56bb108c5f9194de2743e6c56 (diff) |
No need for a local lua_State * variable in file handler routines.
Just use fh->L; the compiler will put that into a register if
appropriate. This removes one side-effect from
INIT_FILEHANDLER_ROUTINE().
Diffstat (limited to 'epan/wslua')
-rw-r--r-- | epan/wslua/wslua_file_handler.c | 118 |
1 files changed, 54 insertions, 64 deletions
diff --git a/epan/wslua/wslua_file_handler.c b/epan/wslua/wslua_file_handler.c index 5634f3d286..e5ec2c74cb 100644 --- a/epan/wslua/wslua_file_handler.c +++ b/epan/wslua/wslua_file_handler.c @@ -68,11 +68,10 @@ static gboolean in_routine = FALSE; g_warning("Error in file %s: no FileHandler %s routine reference", #name, #name); \ return retval; \ } \ - L = fh->L; \ - lua_settop(L,0); \ - push_error_handler(L, #name " routine"); \ - lua_rawgeti(L, LUA_REGISTRYINDEX, fh->name##_ref); \ - if (!lua_isfunction(L, -1)) { \ + lua_settop(fh->L,0); \ + push_error_handler(fh->L, #name " routine"); \ + lua_rawgeti(fh->L, LUA_REGISTRYINDEX, fh->name##_ref); \ + if (!lua_isfunction(fh->L, -1)) { \ g_warning("Error in file %s: no FileHandler %s routine function in Lua", #name, #name); \ return retval; \ } \ @@ -158,21 +157,20 @@ wslua_filehandler_open(wtap *wth, int *err, gchar **err_info) { FileHandler fh = (FileHandler)(wth->wslua_data); wtap_open_return_val retval = WTAP_OPEN_NOT_MINE; - lua_State* L = NULL; File *fp = NULL; CaptureInfo *fc = NULL; INIT_FILEHANDLER_ROUTINE(read_open,WTAP_OPEN_NOT_MINE); - create_wth_priv(L, wth); + create_wth_priv(fh->L, wth); - fp = push_File(L, wth->fh); - fc = push_CaptureInfo(L, wth, TRUE); + fp = push_File(fh->L, wth->fh); + fc = push_CaptureInfo(fh->L, wth, TRUE); errno = WTAP_ERR_CANT_OPEN; - switch ( lua_pcall(L,2,1,1) ) { + switch ( lua_pcall(fh->L,2,1,1) ) { case 0: - retval = (wtap_open_return_val)wslua_optboolint(L,-1,0); + retval = (wtap_open_return_val)wslua_optboolint(fh->L,-1,0); break; CASE_ERROR_ERRINFO("read_open") } @@ -223,7 +221,7 @@ wslua_filehandler_open(wtap *wth, int *err, gchar **err_info) } else if (retval == WTAP_OPEN_NOT_MINE) { /* not our file type */ - remove_wth_priv(L, wth); + remove_wth_priv(fh->L, wth); } else { /* not a valid return type */ @@ -234,7 +232,7 @@ wslua_filehandler_open(wtap *wth, int *err, gchar **err_info) retval = WTAP_OPEN_ERROR; } - lua_settop(L,0); + lua_settop(fh->L,0); return retval; } @@ -250,7 +248,6 @@ wslua_filehandler_read(wtap *wth, wtap_rec *rec, Buffer *buf, { FileHandler fh = (FileHandler)(wth->wslua_data); int retval = -1; - lua_State* L = NULL; File *fp = NULL; CaptureInfo *fc = NULL; FrameInfo *fi = NULL; @@ -265,11 +262,11 @@ wslua_filehandler_read(wtap *wth, wtap_rec *rec, Buffer *buf, g_free(rec->opt_comment); rec->opt_comment = NULL; - fp = push_File(L, wth->fh); - fc = push_CaptureInfo(L, wth, FALSE); - fi = push_FrameInfo(L, rec, buf); + fp = push_File(fh->L, wth->fh); + fc = push_CaptureInfo(fh->L, wth, FALSE); + fi = push_FrameInfo(fh->L, rec, buf); - switch ( lua_pcall(L,3,1,1) ) { + switch ( lua_pcall(fh->L,3,1,1) ) { case 0: /* * Return values for FileHandler:read(): @@ -278,12 +275,12 @@ wslua_filehandler_read(wtap *wth, wtap_rec *rec, Buffer *buf, * XXX handling of boolean true is not documented. Currently it will * succeed without advancing data offset. Should it fail instead? */ - if (lua_type(L, -1) == LUA_TNUMBER) { - *offset = wslua_togint64(L, -1); + if (lua_type(fh->L, -1) == LUA_TNUMBER) { + *offset = wslua_togint64(fh->L, -1); retval = 1; break; } - retval = wslua_optboolint(L,-1,0); + retval = wslua_optboolint(fh->L,-1,0); break; CASE_ERROR_ERRINFO("read") } @@ -293,7 +290,7 @@ wslua_filehandler_read(wtap *wth, wtap_rec *rec, Buffer *buf, (*fp)->expired = TRUE; (*fc)->expired = TRUE; (*fi)->expired = TRUE; - lua_settop(L,0); + lua_settop(fh->L,0); return (retval == 1); } @@ -308,7 +305,6 @@ wslua_filehandler_seek_read(wtap *wth, gint64 seek_off, { FileHandler fh = (FileHandler)(wth->wslua_data); int retval = -1; - lua_State* L = NULL; File *fp = NULL; CaptureInfo *fc = NULL; FrameInfo *fi = NULL; @@ -323,12 +319,12 @@ wslua_filehandler_seek_read(wtap *wth, gint64 seek_off, g_free(rec->opt_comment); rec->opt_comment = NULL; - fp = push_File(L, wth->random_fh); - fc = push_CaptureInfo(L, wth, FALSE); - fi = push_FrameInfo(L, rec, buf); - lua_pushnumber(L, (lua_Number)seek_off); + fp = push_File(fh->L, wth->random_fh); + fc = push_CaptureInfo(fh->L, wth, FALSE); + fi = push_FrameInfo(fh->L, rec, buf); + lua_pushnumber(fh->L, (lua_Number)seek_off); - switch ( lua_pcall(L,4,1,1) ) { + switch ( lua_pcall(fh->L,4,1,1) ) { case 0: /* * Return values for FileHandler:seek_read(): @@ -338,7 +334,7 @@ wslua_filehandler_seek_read(wtap *wth, gint64 seek_off, * (Other values are unspecified/undocumented, but happen to be * treated as success.) */ - retval = lua_toboolean(L, -1); + retval = lua_toboolean(fh->L, -1); break; CASE_ERROR_ERRINFO("seek_read") } @@ -348,7 +344,7 @@ wslua_filehandler_seek_read(wtap *wth, gint64 seek_off, (*fp)->expired = TRUE; (*fc)->expired = TRUE; (*fi)->expired = TRUE; - lua_settop(L,0); + lua_settop(fh->L,0); return (retval == 1); } @@ -359,16 +355,15 @@ static void wslua_filehandler_close(wtap *wth) { FileHandler fh = (FileHandler)(wth->wslua_data); - lua_State* L = NULL; File *fp = NULL; CaptureInfo *fc = NULL; INIT_FILEHANDLER_ROUTINE(read_close,); - fp = push_File(L, wth->fh); - fc = push_CaptureInfo(L, wth, FALSE); + fp = push_File(fh->L, wth->fh); + fc = push_CaptureInfo(fh->L, wth, FALSE); - switch ( lua_pcall(L,2,1,1) ) { + switch ( lua_pcall(fh->L,2,1,1) ) { case 0: break; CASE_ERROR("read_close") @@ -376,11 +371,11 @@ wslua_filehandler_close(wtap *wth) END_FILEHANDLER_ROUTINE(); - remove_wth_priv(L, wth); + remove_wth_priv(fh->L, wth); (*fp)->expired = TRUE; (*fc)->expired = TRUE; - lua_settop(L,0); + lua_settop(fh->L,0); return; } @@ -391,16 +386,15 @@ static void wslua_filehandler_sequential_close(wtap *wth) { FileHandler fh = (FileHandler)(wth->wslua_data); - lua_State* L = NULL; File *fp = NULL; CaptureInfo *fc = NULL; INIT_FILEHANDLER_ROUTINE(seq_read_close,); - fp = push_File(L, wth->fh); - fc = push_CaptureInfo(L, wth, FALSE); + fp = push_File(fh->L, wth->fh); + fc = push_CaptureInfo(fh->L, wth, FALSE); - switch ( lua_pcall(L,2,1,1) ) { + switch ( lua_pcall(fh->L,2,1,1) ) { case 0: break; CASE_ERROR("seq_read_close") @@ -410,7 +404,7 @@ wslua_filehandler_sequential_close(wtap *wth) (*fp)->expired = TRUE; (*fc)->expired = TRUE; - lua_settop(L,0); + lua_settop(fh->L,0); return; } @@ -433,15 +427,14 @@ wslua_filehandler_can_write_encap(int encap, void* data) { FileHandler fh = (FileHandler)(data); int retval = WTAP_ERR_UNWRITABLE_ENCAP; - lua_State* L = NULL; INIT_FILEHANDLER_ROUTINE(can_write_encap,WTAP_ERR_INTERNAL); - lua_pushnumber(L, encap); + lua_pushnumber(fh->L, encap); - switch ( lua_pcall(L,1,1,1) ) { + switch ( lua_pcall(fh->L,1,1,1) ) { case 0: - retval = wslua_optboolint(L,-1,WTAP_ERR_UNWRITABLE_ENCAP); + retval = wslua_optboolint(fh->L,-1,WTAP_ERR_UNWRITABLE_ENCAP); break; CASE_ERROR("can_write_encap") } @@ -475,25 +468,24 @@ wslua_filehandler_dump_open(wtap_dumper *wdh, int *err) { FileHandler fh = (FileHandler)(wdh->wslua_data); int retval = 0; - lua_State* L = NULL; File *fp = NULL; CaptureInfoConst *fc = NULL; INIT_FILEHANDLER_ROUTINE(write_open,0); - create_wdh_priv(L, wdh); + create_wdh_priv(fh->L, wdh); - fp = push_Wdh(L, wdh); - fc = push_CaptureInfoConst(L,wdh); + fp = push_Wdh(fh->L, wdh); + fc = push_CaptureInfoConst(fh->L,wdh); /* Reset err */ if (err) { *err = 0; } - switch ( lua_pcall(L,2,1,1) ) { + switch ( lua_pcall(fh->L,2,1,1) ) { case 0: - retval = wslua_optboolint(L,-1,0); + retval = wslua_optboolint(fh->L,-1,0); break; CASE_ERROR("write_open") } @@ -522,7 +514,7 @@ wslua_filehandler_dump_open(wtap_dumper *wdh, int *err) } else { /* not our file type? */ - remove_wdh_priv(L, wdh); + remove_wdh_priv(fh->L, wdh); } return retval; @@ -537,7 +529,6 @@ wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec, { FileHandler fh = (FileHandler)(wdh->wslua_data); int retval = -1; - lua_State* L = NULL; File *fp = NULL; CaptureInfoConst *fc = NULL; FrameInfoConst *fi = NULL; @@ -549,14 +540,14 @@ wslua_filehandler_dump(wtap_dumper *wdh, const wtap_rec *rec, *err = errno = 0; } - fp = push_Wdh(L, wdh); - fc = push_CaptureInfoConst(L,wdh); - fi = push_FrameInfoConst(L, rec, pd); + fp = push_Wdh(fh->L, wdh); + fc = push_CaptureInfoConst(fh->L,wdh); + fi = push_FrameInfoConst(fh->L, rec, pd); errno = WTAP_ERR_CANT_WRITE; - switch ( lua_pcall(L,3,1,1) ) { + switch ( lua_pcall(fh->L,3,1,1) ) { case 0: - retval = wslua_optboolint(L,-1,0); + retval = wslua_optboolint(fh->L,-1,0); break; CASE_ERROR("write") } @@ -578,7 +569,6 @@ wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err) { FileHandler fh = (FileHandler)(wdh->wslua_data); int retval = -1; - lua_State* L = NULL; File *fp = NULL; CaptureInfoConst *fc = NULL; @@ -589,20 +579,20 @@ wslua_filehandler_dump_finish(wtap_dumper *wdh, int *err) *err = errno = 0; } - fp = push_Wdh(L, wdh); - fc = push_CaptureInfoConst(L,wdh); + fp = push_Wdh(fh->L, wdh); + fc = push_CaptureInfoConst(fh->L,wdh); errno = WTAP_ERR_CANT_CLOSE; - switch ( lua_pcall(L,2,1,1) ) { + switch ( lua_pcall(fh->L,2,1,1) ) { case 0: - retval = wslua_optboolint(L,-1,0); + retval = wslua_optboolint(fh->L,-1,0); break; CASE_ERROR("write_close") } END_FILEHANDLER_ROUTINE(); - remove_wdh_priv(L, wdh); + remove_wdh_priv(fh->L, wdh); (*fp)->expired = TRUE; (*fc)->expired = TRUE; |