Software /
code /
prosody
Comparison
util-src/encodings.c @ 1829:3d0db768be2f
util.encodings: Fixed an issue with cross-module memory deallocation (crashes on some windows versions).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Tue, 22 Sep 2009 22:21:15 +0500 |
parent | 896:2c0b9e3c11c3 |
child | 1844:a4a8fe2a560c |
child | 1854:7e055cc6bc90 |
comparison
equal
deleted
inserted
replaced
1813:2683cdaf6dc8 | 1829:3d0db768be2f |
---|---|
170 const char *s = luaL_checklstring(L, 1, &len); | 170 const char *s = luaL_checklstring(L, 1, &len); |
171 char* output = NULL; | 171 char* output = NULL; |
172 int ret = idna_to_ascii_8z(s, &output, 0); | 172 int ret = idna_to_ascii_8z(s, &output, 0); |
173 if (ret == IDNA_SUCCESS) { | 173 if (ret == IDNA_SUCCESS) { |
174 lua_pushstring(L, output); | 174 lua_pushstring(L, output); |
175 if (output) free(output); | 175 idn_free(output); |
176 return 1; | 176 return 1; |
177 } else { | 177 } else { |
178 lua_pushnil(L); | 178 lua_pushnil(L); |
179 if (output) free(output); | 179 idn_free(output); |
180 return 1; // TODO return error message | 180 return 1; // TODO return error message |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 static int Lidna_to_unicode(lua_State *L) /** idna.to_unicode(s) */ | 184 static int Lidna_to_unicode(lua_State *L) /** idna.to_unicode(s) */ |
187 const char *s = luaL_checklstring(L, 1, &len); | 187 const char *s = luaL_checklstring(L, 1, &len); |
188 char* output = NULL; | 188 char* output = NULL; |
189 int ret = idna_to_unicode_8z8z(s, &output, 0); | 189 int ret = idna_to_unicode_8z8z(s, &output, 0); |
190 if (ret == IDNA_SUCCESS) { | 190 if (ret == IDNA_SUCCESS) { |
191 lua_pushstring(L, output); | 191 lua_pushstring(L, output); |
192 if (output) free(output); | 192 idn_free(output); |
193 return 1; | 193 return 1; |
194 } else { | 194 } else { |
195 lua_pushnil(L); | 195 lua_pushnil(L); |
196 if (output) free(output); | 196 idn_free(output); |
197 return 1; // TODO return error message | 197 return 1; // TODO return error message |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 static const luaL_Reg Reg_idna[] = | 201 static const luaL_Reg Reg_idna[] = |