[vlc-commits] [Git][videolan/vlc][master] 14 commits: lua: intf: remove forward declaration
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Tue Feb 21 10:42:04 UTC 2023
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
7f64311c by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: intf: remove forward declaration
- - - - -
f22e34a2 by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: intf: move static variable
The variable is only used once in the initialization, so move it to the
initialization right before its usage.
- - - - -
c4ab75b8 by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: intf: refactor error path
Refactor error path behind a goto, including the release of the lua
state and lua interrupt.
No functional changes.
- - - - -
11a335cf by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: intf: fix lua interrupt memory leak
Fix memory leak on the error path where the lua interrupt has been
allocated but not released.
- - - - -
7aa0e6e1 by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: meta: move static variable
The variable is only used once in the initialization, so move it to the
initialization right before its usage.
- - - - -
d4259192 by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: meta: remove trailing line
- - - - -
8922caa4 by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: meta: remove conditional for return value
The return value is simpler to read (better alignment) and understand
with || rather than separate conditional branches.
- - - - -
ce5a61d0 by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: meta: refactor as early return
- - - - -
e0d028ec by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: meta: refactor early return
- - - - -
efdbfdb6 by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: meta: reindent after last changes
- - - - -
375414da by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: services_discovery: move static variable
The variable is only used once in the initialization, so move it to the
initialization right before its usage.
- - - - -
e69380e4 by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: stream_filter: move static variables
The variables are only used once in the initialization, so move it to
the initialization right before their usage.
- - - - -
1f94211b by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: vlc: move manifest to the end of file
No functional changes.
- - - - -
013a1e4a by Alexandre Janniaux at 2023-02-21T10:24:59+00:00
lua: vlc: remove forward declaration
Now that the manifest is declared at the end of the file, there's no
need to forward declare the function it is using.
- - - - -
5 changed files:
- modules/lua/intf.c
- modules/lua/meta.c
- modules/lua/services_discovery.c
- modules/lua/stream_filter.c
- modules/lua/vlc.c
Changes:
=====================================
modules/lua/intf.c
=====================================
@@ -38,11 +38,6 @@
#include "vlc.h"
#include "libs.h"
-/*****************************************************************************
- * Prototypes
- *****************************************************************************/
-static void *Run( void * );
-
static const char * const ppsz_intf_options[] = { "intf", "config", NULL };
/*****************************************************************************
@@ -181,7 +176,22 @@ static char *StripPasswords( const char *psz_config )
return psz_log;
}
-static const luaL_Reg p_reg[] = { { NULL, NULL } };
+static void *Run(void *data)
+{
+ vlc_thread_set_name("vlc-lua-intf");
+
+ intf_thread_t *p_intf = data;
+ intf_sys_t *p_sys = p_intf->p_sys;
+ lua_State *L = p_sys->L;
+
+ if (vlclua_dofile(VLC_OBJECT(p_intf), L, p_sys->psz_filename))
+ {
+ msg_Err(p_intf, "Error loading script %s: %s", p_sys->psz_filename,
+ lua_tostring(L, lua_gettop(L)));
+ lua_pop(L, 1);
+ }
+ return NULL;
+}
static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
{
@@ -243,6 +253,7 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
luaL_openlibs( L );
/* register our functions */
+ static const luaL_Reg p_reg[] = { { NULL, NULL } };
luaL_register_namespace( L, "vlc", p_reg );
/* register submodules */
@@ -285,8 +296,7 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
{
msg_Warn( p_intf, "Error while setting the module search path for %s",
p_sys->psz_filename );
- lua_close( L );
- goto error;
+ goto error_lua;
}
/*
@@ -358,8 +368,7 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
{
msg_Err( p_intf, "Couldn't find lua interface script \"cli\", "
"needed by telnet wrapper" );
- lua_close( p_sys->L );
- goto error;
+ goto error_lua;
}
lua_pushstring( L, wrapped_file );
lua_setglobal( L, "wrapped_file" );
@@ -369,13 +378,12 @@ static int Start_LuaIntf( vlc_object_t *p_this, const char *name )
p_sys->L = L;
if( vlc_clone( &p_sys->thread, Run, p_intf ) )
- {
- vlclua_fd_cleanup( &p_sys->dtable );
- lua_close( p_sys->L );
- goto error;
- }
+ goto error_lua;
free( namebuf );
return VLC_SUCCESS;
+error_lua:
+ vlclua_fd_cleanup( &p_sys->dtable );
+ lua_close( p_sys->L );
error:
free( p_sys->psz_filename );
free( p_sys );
@@ -400,23 +408,6 @@ void Close_LuaIntf( vlc_object_t *p_this )
vlc_LogDestroy( p_intf->obj.logger );
}
-static void *Run( void *data )
-{
- vlc_thread_set_name("vlc-lua-intf");
-
- intf_thread_t *p_intf = data;
- intf_sys_t *p_sys = p_intf->p_sys;
- lua_State *L = p_sys->L;
-
- if( vlclua_dofile( VLC_OBJECT(p_intf), L, p_sys->psz_filename ) )
- {
- msg_Err( p_intf, "Error loading script %s: %s", p_sys->psz_filename,
- lua_tostring( L, lua_gettop( L ) ) );
- lua_pop( L, 1 );
- }
- return NULL;
-}
-
int Open_LuaIntf( vlc_object_t *p_this )
{
return Start_LuaIntf( p_this, NULL );
=====================================
modules/lua/meta.c
=====================================
@@ -38,8 +38,6 @@
/*****************************************************************************
* Init lua
*****************************************************************************/
-static const luaL_Reg p_reg[] = { { NULL, NULL } };
-
static lua_State * init( vlc_object_t *p_this, input_item_t * p_item, const char *psz_filename )
{
lua_State * L = luaL_newstate();
@@ -54,6 +52,7 @@ static lua_State * init( vlc_object_t *p_this, input_item_t * p_item, const char
/* Load Lua libraries */
luaL_openlibs( L ); /* XXX: Don't open all the libs? */
+ static const luaL_Reg p_reg[] = { { NULL, NULL } };
luaL_register_namespace( L, "vlc", p_reg );
luaopen_msg( L );
@@ -144,10 +143,8 @@ error:
*****************************************************************************/
static bool validate_scope( const luabatch_context_t *p_context, meta_fetcher_scope_t e_scope )
{
- if ( p_context->e_scope == FETCHER_SCOPE_ANY )
- return true;
- else
- return ( p_context->e_scope == e_scope );
+ return p_context->e_scope == FETCHER_SCOPE_ANY
+ || p_context->e_scope == e_scope;
}
static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
@@ -164,32 +161,31 @@ static int fetch_art( vlc_object_t *p_this, const char * psz_filename,
return i_ret;
}
- if(lua_gettop( L ))
+ if(lua_gettop(L) == 0)
{
- const char * psz_value;
-
- if( lua_isstring( L, -1 ) )
- {
- psz_value = lua_tostring( L, -1 );
- if( psz_value && *psz_value != 0 )
- {
- lua_Dbg( p_this, "setting arturl: %s", psz_value );
- input_item_SetArtURL ( p_context->p_item, psz_value );
- lua_close( L );
- return VLC_SUCCESS;
- }
- }
- else if( !lua_isnoneornil( L, -1 ) )
- {
- msg_Err( p_this, "Lua art fetcher script %s: "
- "didn't return a string", psz_filename );
- }
+ msg_Err(p_this, "Script went completely foobar");
+ goto error;
}
- else
+
+ if (!lua_isstring(L, -1))
{
- msg_Err( p_this, "Script went completely foobar" );
+ if (!lua_isnoneornil(L, -1))
+ msg_Err(p_this, "Lua art fetcher script %s: "
+ "didn't return a string", psz_filename);
+ goto error;
}
+ const char *psz_value = lua_tostring(L, -1);
+ if (psz_value && *psz_value != 0)
+ {
+ lua_Dbg(p_this, "setting arturl: %s", psz_value);
+ input_item_SetArtURL(p_context->p_item, psz_value);
+ }
+
+ lua_close(L);
+ return VLC_SUCCESS;
+
+error:
lua_close( L );
return VLC_EGENERIC;
}
@@ -277,4 +273,3 @@ int FindArt( meta_fetcher_t *p_finder )
return vlclua_scripts_batch_execute( VLC_OBJECT(p_finder), "meta"DIR_SEP"art",
&fetch_art, (void*)&context );
}
-
=====================================
modules/lua/services_discovery.c
=====================================
@@ -145,7 +145,6 @@ typedef struct
vlc_queue_t queue;
bool dead;
} services_discovery_sys_t;
-static const luaL_Reg p_reg[] = { { NULL, NULL } };
struct sd_query
{
@@ -203,6 +202,8 @@ int Open_LuaSD( vlc_object_t *p_this )
}
vlclua_set_this( L, p_sd );
luaL_openlibs( L );
+
+ static const luaL_Reg p_reg[] = { { NULL, NULL } };
luaL_register_namespace( L, "vlc", p_reg );
luaopen_input( L );
luaopen_msg( L );
=====================================
modules/lua/stream_filter.c
=====================================
@@ -99,24 +99,6 @@ static int vlclua_demux_readline( lua_State *L )
return 1;
}
-/*****************************************************************************
- *
- *****************************************************************************/
-/* Functions to register */
-static const luaL_Reg p_reg[] =
-{
- { "peek", vlclua_demux_peek },
- { NULL, NULL }
-};
-
-/* Functions to register for parse() function call only */
-static const luaL_Reg p_reg_parse[] =
-{
- { "read", vlclua_demux_read },
- { "readline", vlclua_demux_readline },
- { NULL, NULL }
-};
-
/*****************************************************************************
* Called through lua_scripts_batch_execute to call 'probe' on
* the script pointed by psz_filename.
@@ -138,6 +120,13 @@ static int probe_luascript(vlc_object_t *obj, const char *filename,
luaL_openlibs( L ); /* FIXME: Don't open all the libs? */
vlclua_set_this(L, s);
+
+ /* Functions to register */
+ static const luaL_Reg p_reg[] =
+ {
+ { "peek", vlclua_demux_peek },
+ { NULL, NULL }
+ };
luaL_register_namespace( L, "vlc", p_reg );
luaopen_msg( L );
luaopen_strings( L );
@@ -213,6 +202,13 @@ static int ReadDir(stream_t *s, input_item_node_t *node)
struct vlclua_playlist *sys = s->p_sys;
lua_State *L = sys->L;
+ /* Functions to register for parse() function call only */
+ static const luaL_Reg p_reg_parse[] =
+ {
+ { "read", vlclua_demux_read },
+ { "readline", vlclua_demux_readline },
+ { NULL, NULL }
+ };
luaL_register_namespace( L, "vlc", p_reg_parse );
lua_getglobal( L, "parse" );
=====================================
modules/lua/vlc.c
=====================================
@@ -72,88 +72,6 @@
#define TELNETPWD_LONGTEXT N_( "A single password restricts access " \
"to this interface." )
-static int vlc_sd_probe_Open( vlc_object_t * );
-
-vlc_module_begin ()
- set_shortname( N_("Lua") )
- set_description( N_("Lua interpreter") )
- set_subcategory( SUBCAT_INTERFACE_MAIN )
-
- add_bool( "lua", true, LUA_TEXT, NULL );
- add_string( "lua-intf", "dummy", INTF_TEXT, INTF_LONGTEXT )
- add_string( "lua-config", "", CONFIG_TEXT, CONFIG_LONGTEXT )
- set_capability( "interface", 0 )
- set_callbacks( Open_LuaIntf, Close_LuaIntf )
- add_shortcut( "luaintf" )
-
- add_submodule ()
- set_section( N_("Lua HTTP"), 0 )
- add_password("http-password", NULL, PASS_TEXT, PASS_LONGTEXT)
- add_string ( "http-src", NULL, SRC_TEXT, SRC_LONGTEXT )
- add_bool ( "http-index", false, INDEX_TEXT, INDEX_LONGTEXT )
- set_capability( "interface", 0 )
- set_callbacks( Open_LuaHTTP, Close_LuaIntf )
- add_shortcut( "luahttp", "http" )
- set_description( N_("Lua HTTP") )
-
- add_submodule ()
- set_section( N_("Lua Telnet"), 0 )
- add_string( "telnet-host", "localhost", TELNETHOST_TEXT,
- TELNETHOST_LONGTEXT )
- add_integer( "telnet-port", TELNETPORT_DEFAULT, TELNETPORT_TEXT,
- TELNETPORT_LONGTEXT )
- change_integer_range( 1, 65535 )
- add_password("telnet-password", NULL, TELNETPWD_TEXT,
- TELNETPWD_LONGTEXT)
- set_capability( "interface", 0 )
- set_callbacks( Open_LuaTelnet, Close_LuaIntf )
- set_description( N_("Lua Telnet") )
- add_shortcut( "luatelnet", "telnet" )
-
- add_submodule ()
- set_shortname( N_( "Lua Meta Fetcher" ) )
- set_description( N_("Fetch meta data using lua scripts") )
- set_capability( "meta fetcher", 10 )
- set_callback( FetchMeta )
-
- add_submodule ()
- set_shortname( N_( "Lua Meta Reader" ) )
- set_description( N_("Read meta data using lua scripts") )
- set_capability( "meta reader", 10 )
- set_callback( ReadMeta )
-
- add_submodule ()
- add_shortcut( "luaplaylist" )
- set_shortname( N_("Lua Playlist") )
- set_description( N_("Lua Playlist Parser Interface") )
- set_capability( "demux", 2 )
- set_callbacks( Import_LuaPlaylist, Close_LuaPlaylist )
-
- add_submodule ()
- set_shortname( N_( "Lua Art" ) )
- set_description( N_("Fetch artwork using lua scripts") )
- set_capability( "art finder", 10 )
- set_callback( FindArt )
-
- add_submodule ()
- set_shortname( N_("Lua Extension") )
- set_description( N_("Lua Extension") )
- add_shortcut( "luaextension" )
- set_capability( "extension", 1 )
- set_callbacks( Open_Extension, Close_Extension )
-
- add_submodule ()
- set_description( N_("Lua SD Module") )
- add_shortcut( "luasd" )
- set_capability( "services_discovery", 0 )
- add_string( "lua-sd", "", NULL, NULL )
- change_volatile()
- set_callbacks( Open_LuaSD, Close_LuaSD )
-
- VLC_SD_PROBE_SUBMODULE
-
-vlc_module_end ()
-
/*****************************************************************************
*
*****************************************************************************/
@@ -696,3 +614,83 @@ int vlclua_dofile( vlc_object_t *p_this, lua_State *L, const char *curi )
free( uri );
return i_ret;
}
+
+vlc_module_begin ()
+ set_shortname( N_("Lua") )
+ set_description( N_("Lua interpreter") )
+ set_subcategory( SUBCAT_INTERFACE_MAIN )
+
+ add_bool( "lua", true, LUA_TEXT, NULL );
+ add_string( "lua-intf", "dummy", INTF_TEXT, INTF_LONGTEXT )
+ add_string( "lua-config", "", CONFIG_TEXT, CONFIG_LONGTEXT )
+ set_capability( "interface", 0 )
+ set_callbacks( Open_LuaIntf, Close_LuaIntf )
+ add_shortcut( "luaintf" )
+
+ add_submodule ()
+ set_section( N_("Lua HTTP"), 0 )
+ add_password("http-password", NULL, PASS_TEXT, PASS_LONGTEXT)
+ add_string ( "http-src", NULL, SRC_TEXT, SRC_LONGTEXT )
+ add_bool ( "http-index", false, INDEX_TEXT, INDEX_LONGTEXT )
+ set_capability( "interface", 0 )
+ set_callbacks( Open_LuaHTTP, Close_LuaIntf )
+ add_shortcut( "luahttp", "http" )
+ set_description( N_("Lua HTTP") )
+
+ add_submodule ()
+ set_section( N_("Lua Telnet"), 0 )
+ add_string( "telnet-host", "localhost", TELNETHOST_TEXT,
+ TELNETHOST_LONGTEXT )
+ add_integer( "telnet-port", TELNETPORT_DEFAULT, TELNETPORT_TEXT,
+ TELNETPORT_LONGTEXT )
+ change_integer_range( 1, 65535 )
+ add_password("telnet-password", NULL, TELNETPWD_TEXT,
+ TELNETPWD_LONGTEXT)
+ set_capability( "interface", 0 )
+ set_callbacks( Open_LuaTelnet, Close_LuaIntf )
+ set_description( N_("Lua Telnet") )
+ add_shortcut( "luatelnet", "telnet" )
+
+ add_submodule ()
+ set_shortname( N_( "Lua Meta Fetcher" ) )
+ set_description( N_("Fetch meta data using lua scripts") )
+ set_capability( "meta fetcher", 10 )
+ set_callback( FetchMeta )
+
+ add_submodule ()
+ set_shortname( N_( "Lua Meta Reader" ) )
+ set_description( N_("Read meta data using lua scripts") )
+ set_capability( "meta reader", 10 )
+ set_callback( ReadMeta )
+
+ add_submodule ()
+ add_shortcut( "luaplaylist" )
+ set_shortname( N_("Lua Playlist") )
+ set_description( N_("Lua Playlist Parser Interface") )
+ set_capability( "demux", 2 )
+ set_callbacks( Import_LuaPlaylist, Close_LuaPlaylist )
+
+ add_submodule ()
+ set_shortname( N_( "Lua Art" ) )
+ set_description( N_("Fetch artwork using lua scripts") )
+ set_capability( "art finder", 10 )
+ set_callback( FindArt )
+
+ add_submodule ()
+ set_shortname( N_("Lua Extension") )
+ set_description( N_("Lua Extension") )
+ add_shortcut( "luaextension" )
+ set_capability( "extension", 1 )
+ set_callbacks( Open_Extension, Close_Extension )
+
+ add_submodule ()
+ set_description( N_("Lua SD Module") )
+ add_shortcut( "luasd" )
+ set_capability( "services_discovery", 0 )
+ add_string( "lua-sd", "", NULL, NULL )
+ change_volatile()
+ set_callbacks( Open_LuaSD, Close_LuaSD )
+
+ VLC_SD_PROBE_SUBMODULE
+
+vlc_module_end ()
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1aab2c6c62dedccdf79b846056faf699e37ed230...013a1e4a7f197041d1ce2b11f4f871eb0a28f596
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1aab2c6c62dedccdf79b846056faf699e37ed230...013a1e4a7f197041d1ce2b11f4f871eb0a28f596
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list