]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_lua] Move SWIG wrapper patches into ".i" typemaps, drop hack.diff (#3043) master
authorDmitry Verenitsin <morbit85@gmail.com>
Wed, 27 May 2026 22:34:53 +0000 (03:34 +0500)
committerGitHub <noreply@github.com>
Wed, 27 May 2026 22:34:53 +0000 (01:34 +0300)
A swig 4.1 regeneration dropped several hand-patched wrapper edits.
Express them (and the rest) as SWIG typemaps in `freeswitch.i` so they
survive reswig. `make reswig` now produces the final wrapper directly;
`hack.diff` and its `patch` step are removed.

Restored regressions:
- `setLUA(L)` on returned `Session`: a hangup hook or input callback on
a script-created `freeswitch.Session()` no longer crashes the process
- binary-safe `Stream::read` (`lua_pushlstring`)

Also moved to typemaps:
- `Dbh`/`JSON` self-pointer guards (`%typemap(check)`), now covering
every wrapper including four the hand-patch missed
- type-table isolation (`#define SWIG_TYPE_TABLE mod_lua`)

src/mod/languages/mod_lua/Makefile.am
src/mod/languages/mod_lua/freeswitch.i
src/mod/languages/mod_lua/hack.diff [deleted file]
src/mod/languages/mod_lua/mod_lua_wrap.cpp

index f898c8abfa29eee8caa67e6aeb3cfc5aec846a0d..d295cd19aac01a6b197c70dd1ed2fc5f3ae4efaf 100644 (file)
@@ -27,7 +27,6 @@ swigclean: clean
 mod_lua_wrap.cpp: mod_lua_extra.c
        swig -lua -c++ -I../../../../src/include -oh mod_lua_wrap.h -o mod_lua_wrap.cpp freeswitch.i
        echo "#include \"mod_lua_extra.c\"" >> mod_lua_wrap.cpp
-       patch -s -p0 -i hack.diff
 
 noinst_PROGRAMS = test/test_mod_lua
 
index 96a5f8c72275802ae2dc3eedfc8cca4673874ed9..d6e8711852a55d8c81004ca3f0078dea86a5baef 100644 (file)
@@ -1,4 +1,10 @@
 %module freeswitch
+
+/* Isolate this module's type table from other swig-lua modules (e.g. ESL). */
+%begin %{
+#define SWIG_TYPE_TABLE mod_lua
+%}
+
 %include ../../../../swig_common.i
 //%include "cstring.i"
 %include std_string.i
 }
 
 
+/* Stream::read returns binary data; preserve length and embedded NULs. */
+%typemap(out) const char *Stream::read %{ lua_pushlstring(L,(const char*)$1, (*arg2)); SWIG_arg++;%}
+
+/* Guard the self pointer in every Dbh/JSON method wrapper. */
+%typemap(check) LUA::Dbh *  %{ switch_assert($1);%}
+%typemap(check) LUA::JSON * %{ switch_assert($1);%}
+
 /**
  * tell swig to grok everything defined in these header files and
  * build all sorts of c wrappers and lua shadows of the c wrappers.
 
 
 namespace LUA {
+
+/* Bind Lua state into returned Session (needed by hangup/input callbacks). */
+%typemap(out) LUA::Session * {
+  SWIG_NewPointerObj(L, $1, $1_descriptor, $owner); SWIG_arg++;
+  if ($1) ($1)->setLUA(L);
+}
+
 class Session : public CoreSession {
  private:
        virtual void do_hangup_hook();
diff --git a/src/mod/languages/mod_lua/hack.diff b/src/mod/languages/mod_lua/hack.diff
deleted file mode 100644 (file)
index e3fe191..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
---- mod_lua_wrap.cpp.old       2025-07-09 10:36:02.165895047 +0000
-+++ mod_lua_wrap.cpp   2025-07-09 10:46:12.289624035 +0000
-@@ -9639,6 +9639,7 @@
-     }
-     
-     arg2 = (char *)lua_tostring(L, 2);
-+    switch_assert(arg1);
-     result = (bool)(arg1)->test_reactive(arg2);
-     lua_pushboolean(L,(int)(result!=0)); SWIG_arg++;
-     return SWIG_arg;
-@@ -9769,6 +9770,7 @@
-         (&arg3)->idx = 3;
-       }
-     }
-+    switch_assert(arg1);
-     result = (bool)(arg1)->query(arg2,arg3);
-     lua_pushboolean(L,(int)(result!=0)); SWIG_arg++;
-     return SWIG_arg;
-@@ -9798,6 +9800,7 @@
-     }
-     
-     arg3 = (char *)lua_tostring(L, 2);
-+    switch_assert(arg1);
-     result = (arg1)->query_rows(arg2,arg3);
-     {
-       SWIG_arg += result;
-@@ -9824,6 +9827,7 @@
-       SWIG_fail_ptr("Dbh_affected_rows",1,SWIGTYPE_p_LUA__Dbh);
-     }
-     
-+    switch_assert(arg1);
-     result = (int)(arg1)->affected_rows();
-     lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
-     return SWIG_arg;
-@@ -9848,6 +9852,7 @@
-       SWIG_fail_ptr("Dbh_last_error",1,SWIGTYPE_p_LUA__Dbh);
-     }
-     
-+    switch_assert(arg1);
-     result = (char *)(arg1)->last_error();
-     lua_pushstring(L,(const char *)result); SWIG_arg++;
-     return SWIG_arg;
-@@ -9871,6 +9876,7 @@
-       SWIG_fail_ptr("Dbh_clear_error",1,SWIGTYPE_p_LUA__Dbh);
-     }
-     
-+    switch_assert(arg1);
-     (arg1)->clear_error();
-     
-     return SWIG_arg;
-@@ -9898,6 +9904,7 @@
-     }
-     
-     arg2 = (char *)lua_tostring(L, 2);
-+    switch_assert(arg1);
-     result = (int)(arg1)->load_extension((char const *)arg2);
-     lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
-     return SWIG_arg;
-@@ -9998,6 +10005,7 @@
-     }
-     
-     arg2 = (char *)lua_tostring(L, 2);
-+    switch_assert(arg1);
-     result = (cJSON *)(arg1)->decode((char const *)arg2);
-     {
-       SWIG_arg += LUA::JSON::cJSON2LuaTable(L, result);
-@@ -10031,6 +10039,7 @@
-       (&arg2)->L = L;
-       (&arg2)->idx = 2;
-     }
-+    switch_assert(arg1);
-     result = (arg1)->encode(arg2);
-     lua_pushlstring(L,(&result)->data(),(&result)->size()); SWIG_arg++;
-     return SWIG_arg;
-@@ -10058,6 +10067,7 @@
-     }
-     
-     arg2 = (char *)lua_tostring(L, 2);
-+    switch_assert(arg1);
-     result = (cJSON *)(arg1)->execute((char const *)arg2);
-     {
-       SWIG_arg += LUA::JSON::cJSON2LuaTable(L, result);
-@@ -10091,6 +10101,7 @@
-       (&arg2)->L = L;
-       (&arg2)->idx = 2;
-     }
-+    switch_assert(arg1);
-     result = (cJSON *)(arg1)->execute(arg2);
-     {
-       SWIG_arg += LUA::JSON::cJSON2LuaTable(L, result);
-@@ -10175,6 +10186,7 @@
-     }
-     
-     arg2 = (char *)lua_tostring(L, 2);
-+    switch_assert(arg1);
-     result = (arg1)->execute2((char const *)arg2);
-     lua_pushlstring(L,(&result)->data(),(&result)->size()); SWIG_arg++;
-     return SWIG_arg;
-@@ -10205,6 +10217,7 @@
-       (&arg2)->L = L;
-       (&arg2)->idx = 2;
-     }
-+    switch_assert(arg1);
-     result = (arg1)->execute2(arg2);
-     lua_pushlstring(L,(&result)->data(),(&result)->size()); SWIG_arg++;
-     return SWIG_arg;
-@@ -10285,6 +10298,7 @@
-     }
-     
-     arg2 = (lua_toboolean(L, 2)!=0);
-+    switch_assert(arg1);
-     (arg1)->encode_empty_table_as_object(arg2);
-     
-     return SWIG_arg;
-@@ -10311,6 +10325,7 @@
-     }
-     
-     arg2 = (lua_toboolean(L, 2)!=0);
-+    switch_assert(arg1);
-     (arg1)->return_unformatted_json(arg2);
-     
-     return SWIG_arg;
index afe5d975cd69055052c1be99f26e0d41812b7100..c82d4fc373f3231c6d87e43b6370c8f0f69739d0 100644 (file)
@@ -6,6 +6,9 @@
  * the SWIG interface file instead.
  * ----------------------------------------------------------------------------- */
 
+#define SWIG_TYPE_TABLE mod_lua
+
+
 
 #define SWIG_VERSION 0x040100
 #define SWIGLUA
@@ -4307,7 +4310,7 @@ static int _wrap_Stream_read(lua_State* L) {
     }
     
     result = (char *)(arg1)->read(arg2);
-    lua_pushstring(L,(const char *)result); SWIG_arg++;
+    lua_pushlstring(L,(const char*)result, (*arg2)); SWIG_arg++;
     lua_pushnumber(L, (lua_Number) *arg2); SWIG_arg++;
     return SWIG_arg;
     
@@ -8401,7 +8404,10 @@ static int _wrap_new_Session__SWIG_0(lua_State* L) {
     
     SWIG_check_num_args("LUA::Session::Session",0,0)
     result = (LUA::Session *)new LUA::Session();
-    SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; 
+    {
+      SWIG_NewPointerObj(L, result, SWIGTYPE_p_LUA__Session, 1); SWIG_arg++;
+      if (result) (result)->setLUA(L);
+    }
     return SWIG_arg;
     
     fail: SWIGUNUSED;
@@ -8428,7 +8434,10 @@ static int _wrap_new_Session__SWIG_1(lua_State* L) {
     }
     
     result = (LUA::Session *)new LUA::Session(arg1,arg2);
-    SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; 
+    {
+      SWIG_NewPointerObj(L, result, SWIGTYPE_p_LUA__Session, 1); SWIG_arg++;
+      if (result) (result)->setLUA(L);
+    }
     return SWIG_arg;
     
     fail: SWIGUNUSED;
@@ -8448,7 +8457,10 @@ static int _wrap_new_Session__SWIG_2(lua_State* L) {
     if(!SWIG_lua_isnilstring(L,1)) SWIG_fail_arg("LUA::Session::Session",1,"char *");
     arg1 = (char *)lua_tostring(L, 1);
     result = (LUA::Session *)new LUA::Session(arg1);
-    SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; 
+    {
+      SWIG_NewPointerObj(L, result, SWIGTYPE_p_LUA__Session, 1); SWIG_arg++;
+      if (result) (result)->setLUA(L);
+    }
     return SWIG_arg;
     
     fail: SWIGUNUSED;
@@ -8472,7 +8484,10 @@ static int _wrap_new_Session__SWIG_3(lua_State* L) {
     }
     
     result = (LUA::Session *)new LUA::Session(arg1);
-    SWIG_NewPointerObj(L,result,SWIGTYPE_p_LUA__Session,1); SWIG_arg++; 
+    {
+      SWIG_NewPointerObj(L, result, SWIGTYPE_p_LUA__Session, 1); SWIG_arg++;
+      if (result) (result)->setLUA(L);
+    }
     return SWIG_arg;
     
     fail: SWIGUNUSED;
@@ -9525,6 +9540,7 @@ static int _wrap_Dbh_release(lua_State* L) {
       SWIG_fail_ptr("Dbh_release",1,SWIGTYPE_p_LUA__Dbh);
     }
     
+    switch_assert(arg1);
     result = (bool)(arg1)->release();
     lua_pushboolean(L,(int)(result!=0)); SWIG_arg++;
     return SWIG_arg;
@@ -9549,6 +9565,7 @@ static int _wrap_Dbh_connected(lua_State* L) {
       SWIG_fail_ptr("Dbh_connected",1,SWIGTYPE_p_LUA__Dbh);
     }
     
+    switch_assert(arg1);
     result = (bool)(arg1)->connected();
     lua_pushboolean(L,(int)(result!=0)); SWIG_arg++;
     return SWIG_arg;
@@ -9582,6 +9599,7 @@ static int _wrap_Dbh_test_reactive__SWIG_0(lua_State* L) {
     arg2 = (char *)lua_tostring(L, 2);
     arg3 = (char *)lua_tostring(L, 3);
     arg4 = (char *)lua_tostring(L, 4);
+    switch_assert(arg1);
     result = (bool)(arg1)->test_reactive(arg2,arg3,arg4);
     lua_pushboolean(L,(int)(result!=0)); SWIG_arg++;
     return SWIG_arg;
@@ -9612,6 +9630,7 @@ static int _wrap_Dbh_test_reactive__SWIG_1(lua_State* L) {
     
     arg2 = (char *)lua_tostring(L, 2);
     arg3 = (char *)lua_tostring(L, 3);
+    switch_assert(arg1);
     result = (bool)(arg1)->test_reactive(arg2,arg3);
     lua_pushboolean(L,(int)(result!=0)); SWIG_arg++;
     return SWIG_arg;