From: Seven Du Date: Fri, 5 Sep 2014 23:17:44 +0000 (+0800) Subject: FS-6796 #comment avoid use c++ string since it causing troubles X-Git-Tag: v1.4.8~2^2~36 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1a4e6e3093ab6ba20e0bf8da5267ca9f9061f025;p=thirdparty%2Ffreeswitch.git FS-6796 #comment avoid use c++ string since it causing troubles --- diff --git a/src/include/switch_cpp.h b/src/include/switch_cpp.h index 2db54e8627..07c77ec54f 100644 --- a/src/include/switch_cpp.h +++ b/src/include/switch_cpp.h @@ -3,7 +3,6 @@ #ifdef __cplusplus -#include extern "C" { #endif #ifdef DOH @@ -150,9 +149,9 @@ SWITCH_DECLARE(bool) email(char *to, char *from, char *headers = NULL, char *bod SWITCH_DECLARE_CONSTRUCTOR Stream(void); SWITCH_DECLARE_CONSTRUCTOR Stream(switch_stream_handle_t *); virtual SWITCH_DECLARE_CONSTRUCTOR ~ Stream(); - SWITCH_DECLARE(std::string) read(); + SWITCH_DECLARE(const char *) read(int *len); SWITCH_DECLARE(void) write(const char *data); - SWITCH_DECLARE(void) raw_write(std::string data); + SWITCH_DECLARE(void) raw_write(const char *data, int len); SWITCH_DECLARE(const char *) get_data(void); }; diff --git a/src/mod/languages/mod_lua/Makefile.am b/src/mod/languages/mod_lua/Makefile.am index d727bf88b6..2a0b51e933 100644 --- a/src/mod/languages/mod_lua/Makefile.am +++ b/src/mod/languages/mod_lua/Makefile.am @@ -33,5 +33,4 @@ lua_wrap: 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 - sed -i -e 's/lua_strlen/lua_rawlen/' mod_lua_wrap.cpp diff --git a/src/mod/languages/mod_lua/freeswitch.i b/src/mod/languages/mod_lua/freeswitch.i index 4f50313588..a5c9d75a14 100644 --- a/src/mod/languages/mod_lua/freeswitch.i +++ b/src/mod/languages/mod_lua/freeswitch.i @@ -43,7 +43,8 @@ %newobject API::execute; %newobject API::executeString; -%include "std_string.i" +%include "typemaps.i" +%apply int *OUTPUT { int *len }; /** * tell swig to grok everything defined in these header files and diff --git a/src/mod/languages/mod_lua/mod_lua_wrap.cpp b/src/mod/languages/mod_lua/mod_lua_wrap.cpp index 1c761e892b..5c4483a240 100644 --- a/src/mod/languages/mod_lua/mod_lua_wrap.cpp +++ b/src/mod/languages/mod_lua/mod_lua_wrap.cpp @@ -2946,18 +2946,18 @@ fail: static int _wrap_Stream_raw_write(lua_State* L) { int SWIG_arg = -1; Stream *arg1 = (Stream *) 0 ; - std::string arg2 ; - + char *arg2 = (char *) 0 ; + SWIG_check_num_args("raw_write",2,2) if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("raw_write",1,"Stream *"); - if(!lua_isstring(L,2)) SWIG_fail_arg("raw_write",2,"std::string"); + if(!lua_isstring(L,2)) SWIG_fail_arg("raw_write",2,"char const *"); if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_Stream,0))){ SWIG_fail_ptr("Stream_raw_write",1,SWIGTYPE_p_Stream); } - (&arg2)->assign(lua_tostring(L,2),lua_rawlen(L,2)); - (arg1)->raw_write(arg2); + arg2 = (char *)lua_tostring(L, 2); + (arg1)->raw_write((char const *)arg2,lua_rawlen(L, 2)); SWIG_arg=0; return SWIG_arg; diff --git a/src/mod/languages/mod_lua/my_swigable_cpp.h b/src/mod/languages/mod_lua/my_swigable_cpp.h index 60538b7f91..80f689e56e 100644 --- a/src/mod/languages/mod_lua/my_swigable_cpp.h +++ b/src/mod/languages/mod_lua/my_swigable_cpp.h @@ -22,7 +22,10 @@ class Stream { Stream(void); Stream(switch_stream_handle_t *); virtual ~ Stream(); - string read(); + +%inline %{ + char *read(int *len); +%} void write(const char *data); void raw_write(void *data, int len); const char *get_data(void); diff --git a/src/switch_cpp.cpp b/src/switch_cpp.cpp index df45e6a1da..2702862027 100644 --- a/src/switch_cpp.cpp +++ b/src/switch_cpp.cpp @@ -532,22 +532,20 @@ SWITCH_DECLARE_CONSTRUCTOR Stream::~Stream() } /* WARNING!! you are not encouraged to use this unless you understand the risk!!! */ -SWITCH_DECLARE(std::string) Stream::read() +SWITCH_DECLARE(const char *) Stream::read(int *len) { uint8_t *buff; - this_check(std::string("")); - int len = 0; - this_check(std::string()); + this_check(NULL); - if (!stream_p->read_function) return std::string(); + if (!stream_p->read_function) return NULL; - buff = stream_p->read_function(stream_p, &len); + buff = stream_p->read_function(stream_p, len); - if (!buff) return std::string(); - if (len < 0) return std::string(); + if (!buff) return NULL; + if (len < 0) return NULL; - return std::string((const char *)buff, len); + return (const char *)buff; } SWITCH_DECLARE(void) Stream::write(const char *data) @@ -556,10 +554,10 @@ SWITCH_DECLARE(void) Stream::write(const char *data) stream_p->write_function(stream_p, "%s", data); } -SWITCH_DECLARE(void) Stream::raw_write(std::string data) +SWITCH_DECLARE(void) Stream::raw_write(const char *data, int len) { this_check_void(); - stream_p->raw_write_function(stream_p, (uint8_t *)data.c_str(), data.length()); + stream_p->raw_write_function(stream_p, (uint8_t *)data, len); } SWITCH_DECLARE(const char *)Stream::get_data()