]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
make luarun use a new pool every call
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 4 Sep 2009 15:27:36 +0000 (15:27 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 4 Sep 2009 15:27:36 +0000 (15:27 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14763 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/languages/mod_lua/freeswitch.i
src/mod/languages/mod_lua/freeswitch_lua.h
src/mod/languages/mod_lua/mod_lua.cpp
src/mod/languages/mod_lua/mod_lua_wrap.cpp

index 3745e09cb25ceaa19ff1f524afb1f2c7aaff141a..fc30cad17c74e6e6f22ae51e64b8d3784497b7ac 100644 (file)
@@ -18,6 +18,7 @@
 %}
 
 
+
 %ignore SwitchToMempool;   
 %newobject EventConsumer::pop;
 %newobject Session;
@@ -54,7 +55,7 @@ class Session : public CoreSession {
        virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
        void unsetInputCallback(void);
        void setInputCallback(char *cbfunc, char *funcargs = NULL);
-       void setHangupHook(char *func, char *arg = NULL);
+       void setHangupHook(char *func, char *arg);
        bool ready();
        int originate(CoreSession *a_leg_session, char *dest, int timeout);
        
index 6a6ffbff839d4652dbaa72604be708a9a25c0970..c2c580ccc8c1e3fbb1b5d4a64f73dc866da3b0c1 100644 (file)
@@ -32,7 +32,7 @@ class Session : public CoreSession {
        virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
        void unsetInputCallback(void);
        void setInputCallback(char *cbfunc, char *funcargs = NULL);
-       void setHangupHook(char *func, char *arg = NULL);
+       void setHangupHook(char *func, char *arg);
        bool ready();
        int originate(CoreSession *a_leg_session, char *dest, int timeout);
        
index b8a947dc4eb03c25aacca8613b1f069ace4b493f..4b3c5c1e18f79e127c491ef24dc7ac3a143b134d 100644 (file)
@@ -187,16 +187,22 @@ static int lua_parse_and_execute(lua_State * L, char *input_code)
        return error;
 }
 
+struct lua_thread_helper {
+       switch_memory_pool_t *pool;
+       char *input_code;
+};
+
 static void *SWITCH_THREAD_FUNC lua_thread_run(switch_thread_t *thread, void *obj)
 {
-       char *input_code = (char *) obj;
+       struct lua_thread_helper *lth = (struct lua_thread_helper *) obj;
+       switch_memory_pool_t *pool = lth->pool;
        lua_State *L = lua_init();      /* opens Lua */
 
-       lua_parse_and_execute(L, input_code);
+       lua_parse_and_execute(L, lth->input_code);
 
-       if (input_code) {
-               free(input_code);
-       }
+       lth = NULL;
+
+       switch_core_destroy_memory_pool(&pool);
 
        lua_uninit(L);
 
@@ -365,11 +371,18 @@ int lua_thread(const char *text)
 {
        switch_thread_t *thread;
        switch_threadattr_t *thd_attr = NULL;
+       switch_memory_pool_t *pool;
+       lua_thread_helper *lth;
+
+       switch_core_new_memory_pool(&pool);
+       lth = (lua_thread_helper *) switch_core_alloc(pool, sizeof(*lth));
+       lth->pool = pool;
+       lth->input_code = switch_core_strdup(lth->pool, text);
 
-       switch_threadattr_create(&thd_attr, globals.pool);
+       switch_threadattr_create(&thd_attr, lth->pool);
        switch_threadattr_detach_set(thd_attr, 1);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_thread_create(&thread, thd_attr, lua_thread_run, strdup(text), globals.pool);
+       switch_thread_create(&thread, thd_attr, lua_thread_run, lth, lth->pool);
 
        return 0;
 }
index b95163fdf84c50fc958a789c2e9a9caae923deb0..704154cb87ed43f536eca971781d932d9ed892cb 100644 (file)
@@ -7747,7 +7747,7 @@ static int _wrap_Session_setInputCallback(lua_State* L) {
 }
 
 
-static int _wrap_Session_setHangupHook__SWIG_0(lua_State* L) {
+static int _wrap_Session_setHangupHook(lua_State* L) {
   int SWIG_arg = -1;
   LUA::Session *arg1 = (LUA::Session *) 0 ;
   char *arg2 = (char *) 0 ;
@@ -7777,89 +7777,6 @@ fail:
 }
 
 
-static int _wrap_Session_setHangupHook__SWIG_1(lua_State* L) {
-  int SWIG_arg = -1;
-  LUA::Session *arg1 = (LUA::Session *) 0 ;
-  char *arg2 = (char *) 0 ;
-  
-  SWIG_check_num_args("setHangupHook",2,2)
-  if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("setHangupHook",1,"LUA::Session *");
-  if(!lua_isstring(L,2)) SWIG_fail_arg("setHangupHook",2,"char *");
-  
-  if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_LUA__Session,0))){
-    SWIG_fail_ptr("Session_setHangupHook",1,SWIGTYPE_p_LUA__Session);
-  }
-  
-  arg2 = (char *)lua_tostring(L, 2);
-  (arg1)->setHangupHook(arg2);
-  SWIG_arg=0;
-  
-  return SWIG_arg;
-  
-  if(0) SWIG_fail;
-  
-fail:
-  lua_error(L);
-  return SWIG_arg;
-}
-
-
-static int _wrap_Session_setHangupHook(lua_State* L) {
-  int argc;
-  int argv[4]={
-    1,2,3,4
-  };
-  
-  argc = lua_gettop(L);
-  if (argc == 2) {
-    int _v;
-    {
-      void *ptr;
-      if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_LUA__Session, 0)) {
-        _v = 0;
-      } else {
-        _v = 1;
-      }
-    }
-    if (_v) {
-      {
-        _v = lua_isstring(L,argv[1]);
-      }
-      if (_v) {
-        return _wrap_Session_setHangupHook__SWIG_1(L);
-      }
-    }
-  }
-  if (argc == 3) {
-    int _v;
-    {
-      void *ptr;
-      if (SWIG_isptrtype(L,argv[0])==0 || SWIG_ConvertPtr(L,argv[0], (void **) &ptr, SWIGTYPE_p_LUA__Session, 0)) {
-        _v = 0;
-      } else {
-        _v = 1;
-      }
-    }
-    if (_v) {
-      {
-        _v = lua_isstring(L,argv[1]);
-      }
-      if (_v) {
-        {
-          _v = lua_isstring(L,argv[2]);
-        }
-        if (_v) {
-          return _wrap_Session_setHangupHook__SWIG_0(L);
-        }
-      }
-    }
-  }
-  
-  lua_pushstring(L,"No matching function for overloaded 'Session_setHangupHook'");
-  lua_error(L);return 0;
-}
-
-
 static int _wrap_Session_ready(lua_State* L) {
   int SWIG_arg = -1;
   LUA::Session *arg1 = (LUA::Session *) 0 ;