summaryrefslogtreecommitdiff
path: root/databases/lua-sqlite3/patches/patch-libluasqlite3.c
blob: 0a18418fbd945a7858172160fcc61a752cba370b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
$NetBSD: patch-libluasqlite3.c,v 1.1 2014/05/03 13:01:24 alnsn Exp $

--- libluasqlite3.c.orig	2006-05-11 11:06:16.000000000 +0000
+++ libluasqlite3.c
@@ -302,10 +302,28 @@ static void report_error(lua_State * L, 
 #define checkint(L, narg)	( (int)		checknumber((L), (narg)) )
 #define checkdouble(L, narg)	( (double)	checknumber((L), (narg)) )
 
+#if LUA_VERSION_NUM >= 502 /* Lua 5.2 */
+#define stringlen(L, narg) lua_rawlen(L, narg)
+#else
+#define stringlen(L, narg) lua_strlen(L, narg)
+#endif
+
+/*
+ * Quote from http://www.lua.org/manual/5.2/manual.html#8.3:
+ * luaL_typerror was removed. Write your own version if you need it. 
+ */
+static int typerror(lua_State *L, int narg, const char *tname)
+{
+  const char *msg;
+
+  msg = lua_pushfstring(L, "%s expected, got %s", tname, luaL_typename(L, narg));
+  return luaL_argerror(L, narg, msg);
+}
+
 static void * checkudata(lua_State * L, int narg)
 {
   if (!lua_isuserdata(L, narg))
-    luaL_typerror(L, narg, "userdata");
+    typerror(L, narg, "userdata");
   return lua_touserdata(L, narg);
 }
 
@@ -330,7 +348,7 @@ static int checknilornoneorfunc(lua_Stat
     return 0;
   if (lua_isfunction(L, narg))
     return 1;
-  luaL_typerror(L, narg, "nil, none or function");
+  typerror(L, narg, "nil, none or function");
   return 0; /* never reached, make compiler happy... */
 }
 
@@ -348,14 +366,14 @@ FUNC( l_sqlite3_bind_null )
 
 FUNC( l_sqlite3_bind_text )
 {
-  lua_pushnumber(L, sqlite3_bind_text(checkstmt_stmt(L, 1), checkint(L, 2), checkstr(L, 3), lua_strlen(L, 3), SQLITE_TRANSIENT) );
+  lua_pushnumber(L, sqlite3_bind_text(checkstmt_stmt(L, 1), checkint(L, 2), checkstr(L, 3), stringlen(L, 3), SQLITE_TRANSIENT) );
   return 1;
 }
 
 
 FUNC( l_sqlite3_bind_blob )
 {
-  lua_pushnumber(L, sqlite3_bind_blob(checkstmt_stmt(L, 1), checkint(L, 2), checkstr(L, 3), lua_strlen(L, 3), SQLITE_TRANSIENT) );
+  lua_pushnumber(L, sqlite3_bind_blob(checkstmt_stmt(L, 1), checkint(L, 2), checkstr(L, 3), stringlen(L, 3), SQLITE_TRANSIENT) );
   return 1;
 }
 
@@ -420,7 +438,7 @@ FUNC( l_sqlite3_bind )
       break;
     
     case LUA_TSTRING:
-      lua_pushnumber(L, sqlite3_bind_text(stmt, index, lua_tostring(L, 3), lua_strlen(L, 3), SQLITE_TRANSIENT) );
+      lua_pushnumber(L, sqlite3_bind_text(stmt, index, lua_tostring(L, 3), stringlen(L, 3), SQLITE_TRANSIENT) );
       break;
     
     default:
@@ -764,7 +782,7 @@ FUNC( l_sqlite3_prepare )
   
   DB * db			= checkdb(L, 1);
   const char * sql		= checkstr(L, 2);
-  int sql_size			= lua_strlen(L, 2);
+  int sql_size			= stringlen(L, 2);
   const char * leftover		= 0;
   sqlite3_stmt * sqlite3_stmt 	= 0;
   int error, leftover_size;
@@ -898,7 +916,7 @@ static void func_callback_wrapper(int wh
   if (lua_pcall(L, values ? 3 : 1, 0, 0))
   {
     fprintf(stderr, "libluasqlite3: func_callback_wrapper: Warning: user function error: %s\n", lua_tostring(L, -1));
-    sqlite3_result_error(ctx, lua_tostring(L, -1), lua_strlen(L, -1));
+    sqlite3_result_error(ctx, lua_tostring(L, -1), stringlen(L, -1));
     lua_pop(L, 1);
   }
 }
@@ -1077,7 +1095,7 @@ FUNC( l_sqlite3_result_null )
 
 FUNC( l_sqlite3_result_error )
 {
-  sqlite3_result_error(checkcontext(L, 1), checkstr(L, 2), lua_strlen(L, 2));
+  sqlite3_result_error(checkcontext(L, 1), checkstr(L, 2), stringlen(L, 2));
   return 0;
 }
 
@@ -1111,14 +1129,14 @@ FUNC( l_sqlite3_result_number )
 
 FUNC( l_sqlite3_result_blob )
 {
-  sqlite3_result_blob(checkcontext(L, 1), checkstr(L, 2), lua_strlen(L, 2), SQLITE_TRANSIENT);
+  sqlite3_result_blob(checkcontext(L, 1), checkstr(L, 2), stringlen(L, 2), SQLITE_TRANSIENT);
   return 0;
 }
 
 
 FUNC( l_sqlite3_result_text )
 {
-  sqlite3_result_text(checkcontext(L, 1), checkstr(L, 2), lua_strlen(L, 2), SQLITE_TRANSIENT);
+  sqlite3_result_text(checkcontext(L, 1), checkstr(L, 2), stringlen(L, 2), SQLITE_TRANSIENT);
   return 0;
 }
 
@@ -1161,7 +1179,7 @@ FUNC( l_sqlite3_result )
       break;
     
     case LUA_TSTRING:
-      sqlite3_result_text(context, lua_tostring(L, 2), lua_strlen(L, 2), SQLITE_TRANSIENT);
+      sqlite3_result_text(context, lua_tostring(L, 2), stringlen(L, 2), SQLITE_TRANSIENT);
       break;
     
     default: