aboutsummaryrefslogtreecommitdiffstats
path: root/main/lua-stringy/stringy-memcmp.patch
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2011-11-01 08:56:32 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2011-11-01 08:56:32 +0000
commit0135d232fffb15d577e77241d6c654ff6682ffcd (patch)
treebf6189d2e560a178107456b3356b2d1be8f8aa01 /main/lua-stringy/stringy-memcmp.patch
parent38789098b0f785e8055f6d84e7647ed32163dedd (diff)
downloadaports-0135d232fffb15d577e77241d6c654ff6682ffcd.tar.bz2
aports-0135d232fffb15d577e77241d6c654ff6682ffcd.tar.xz
main/lua-stringy: moved from testing
Diffstat (limited to 'main/lua-stringy/stringy-memcmp.patch')
-rw-r--r--main/lua-stringy/stringy-memcmp.patch64
1 files changed, 64 insertions, 0 deletions
diff --git a/main/lua-stringy/stringy-memcmp.patch b/main/lua-stringy/stringy-memcmp.patch
new file mode 100644
index 0000000000..d9019b79cc
--- /dev/null
+++ b/main/lua-stringy/stringy-memcmp.patch
@@ -0,0 +1,64 @@
+--- ./stringy.c.orig
++++ ./stringy.c
+@@ -8,49 +8,27 @@
+
+
+ static int endswith(lua_State *L) {
+- const char *string = luaL_checkstring(L, 1);
+- int string_len = lua_objlen(L, 1);
++ size_t string_len, token_len;
++ const char *string = luaL_checklstring(L, 1, &string_len);
++ const char *token = luaL_checklstring(L, 2, &token_len);
++ int end = 0;
+
+- const char *token = luaL_checkstring(L, 2);
+- int token_len = lua_objlen(L, 2);
+-
+- int ti = token_len, si = string_len, end = 1;
+ if(token_len <= string_len){
+- while(ti > 0) {
+- if(string[--si] != token[--ti]){
+- end = 0;
+- break;
+-
+- }
+- }
++ string += string_len - token_len;
++ end = memcmp(string, token, token_len) == 0;
+ }
+- else {
+- end = 0;
+- }
+ lua_pushboolean(L, end);
+ return 1;
+ }
+
+ static int startswith(lua_State *L) {
+- const char *string = luaL_checkstring(L, 1);
+- int string_len = lua_objlen(L, 1);
++ size_t string_len, token_len;
++ const char *string = luaL_checklstring(L, 1, &string_len);
++ const char *token = luaL_checklstring(L, 2, &token_len);
++ int start = 0;
+
+- const char *token = luaL_checkstring(L, 2);
+- int token_len = lua_objlen(L, 2);
+- int i, start = 1;
+- // please make this less ugly...
+- if(token_len <= string_len){
+- while(i < token_len) {
+- if(string[i] != token[i]){
+- start = 0;
+- break;
+- }
+- i++;
+- }
+- }
+- else {
+- start = 0;
+- }
++ if(token_len <= string_len)
++ start = memcmp(string, token, token_len) == 0;
+ lua_pushboolean(L, start);
+ return 1;
+ }