Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/facebook/luaffifb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2015-05-13 21:45:22 +0300
committerSam Gross <colesbury@gmail.com>2015-05-13 21:45:22 +0300
commitfb4b9e359d250da31ba03fcfd6b96adcab4dece3 (patch)
treeefd7ae3c834ab34bdc379f14794e09f508e0aa6c
parent979209db65f5c2fda1080aca7d8b52fd3872fc07 (diff)
Include uservalue for complex numbers returned from C functions.
Complex numbers have uservalues because we enabled setting metatables on complex numbers.
-rw-r--r--call_x64.h40
-rw-r--r--call_x64win.h40
-rw-r--r--call_x86.dasc10
-rw-r--r--call_x86.h38
-rw-r--r--test.lua6
5 files changed, 74 insertions, 60 deletions
diff --git a/call_x64.h b/call_x64.h
index 029d132..5cd1fbf 100644
--- a/call_x64.h
+++ b/call_x64.h
@@ -13,7 +13,7 @@
* Copyright (c) 2011 James R. McKaskill. See license in ffi.h
*/
-static const unsigned char build_actionlist[2022] = {
+static const unsigned char build_actionlist[2016] = {
248,10,184,1,0,0,0,76,139,109,252,240,76,139,101,252,248,72,137,252,236,93,
195,255,248,11,232,251,1,0,72,185,237,237,137,1,184,0,0,0,0,76,139,109,252,
240,76,139,101,252,248,72,137,252,236,93,195,255,248,12,102,15,214,68,36,
@@ -106,12 +106,12 @@ static const unsigned char build_actionlist[2022] = {
72,137,68,36,32,232,251,1,0,72,185,237,237,137,1,72,186,237,237,72,199,198,
0,0,0,0,76,137,231,232,251,1,7,72,139,76,36,32,72,137,8,252,233,244,10,255,
102,15,214,68,36,32,232,251,1,0,72,185,237,237,137,1,72,186,237,237,72,199,
- 198,0,0,0,0,76,137,231,232,251,1,7,72,139,76,36,32,72,137,8,252,233,244,10,
- 255,102,15,214,76,36,40,102,15,214,68,36,32,232,251,1,0,72,185,237,237,137,
- 1,72,186,237,237,72,199,198,0,0,0,0,76,137,231,232,251,1,7,72,139,76,36,40,
- 72,137,72,8,72,139,76,36,32,72,137,8,252,233,244,10,255,252,233,244,11,255,
- 252,233,244,13,255,252,233,244,14,255,252,233,244,15,255,252,243,15,90,192,
- 252,233,244,12,255
+ 198,237,76,137,231,232,251,1,7,72,139,76,36,32,72,137,8,252,233,244,10,255,
+ 102,15,214,76,36,40,102,15,214,68,36,32,232,251,1,0,72,185,237,237,137,1,
+ 72,186,237,237,72,199,198,237,76,137,231,232,251,1,7,72,139,76,36,40,72,137,
+ 72,8,72,139,76,36,32,72,137,8,252,233,244,10,255,252,233,244,11,255,252,233,
+ 244,13,255,252,233,244,14,255,252,233,244,15,255,252,243,15,90,192,252,233,
+ 244,12,255
};
static const char *const globnames[] = {
@@ -1127,23 +1127,25 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
break;
case COMPLEX_FLOAT_TYPE:
- num_upvals++;
- dasm_put(Dst, 1883, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32));
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1883, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals));
break;
case COMPLEX_DOUBLE_TYPE:
- num_upvals++;
- dasm_put(Dst, 1930, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32));
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1927, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals));
break;
case VOID_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1992);
+ dasm_put(Dst, 1986);
break;
case BOOL_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1997);
+ dasm_put(Dst, 1991);
break;
case INT8_TYPE:
@@ -1153,7 +1155,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1376);
}
- dasm_put(Dst, 2002);
+ dasm_put(Dst, 1996);
break;
case INT16_TYPE:
@@ -1163,27 +1165,27 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1384);
}
- dasm_put(Dst, 2002);
+ dasm_put(Dst, 1996);
break;
case INT32_TYPE:
case ENUM_TYPE:
lua_pop(L, 1);
if (mbr_ct->is_unsigned) {
- dasm_put(Dst, 2007);
+ dasm_put(Dst, 2001);
} else {
- dasm_put(Dst, 2002);
+ dasm_put(Dst, 1996);
}
break;
case FLOAT_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 2012);
+ dasm_put(Dst, 2006);
break;
case DOUBLE_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 2017);
+ dasm_put(Dst, 2011);
break;
default:
diff --git a/call_x64win.h b/call_x64win.h
index 6151207..9a7dc75 100644
--- a/call_x64win.h
+++ b/call_x64win.h
@@ -13,7 +13,7 @@
* Copyright (c) 2011 James R. McKaskill. See license in ffi.h
*/
-static const unsigned char build_actionlist[1965] = {
+static const unsigned char build_actionlist[1959] = {
248,10,184,1,0,0,0,76,139,109,252,240,76,139,101,252,248,72,137,252,236,93,
195,255,248,11,232,251,1,0,72,185,237,237,137,1,184,0,0,0,0,76,139,109,252,
240,76,139,101,252,248,72,137,252,236,93,195,255,248,12,102,15,214,68,36,
@@ -102,12 +102,12 @@ static const unsigned char build_actionlist[1965] = {
76,36,32,72,137,8,252,233,244,10,255,72,137,68,36,32,232,251,1,0,72,185,237,
237,137,1,73,184,237,237,72,199,194,0,0,0,0,76,137,225,232,251,1,7,72,139,
76,36,32,72,137,8,252,233,244,10,255,102,15,214,68,36,32,232,251,1,0,72,185,
- 237,237,137,1,73,184,237,237,72,199,194,0,0,0,0,76,137,225,232,251,1,7,72,
- 139,76,36,32,72,137,8,252,233,244,10,255,102,15,214,76,36,40,102,15,214,68,
- 36,32,232,251,1,0,72,185,237,237,137,1,73,184,237,237,72,199,194,0,0,0,0,
- 76,137,225,232,251,1,7,72,139,76,36,40,72,137,72,8,72,139,76,36,32,72,137,
- 8,252,233,244,10,255,252,233,244,11,255,252,233,244,13,255,252,233,244,14,
- 255,252,233,244,15,255,252,243,15,90,192,252,233,244,12,255
+ 237,237,137,1,73,184,237,237,72,199,194,237,76,137,225,232,251,1,7,72,139,
+ 76,36,32,72,137,8,252,233,244,10,255,102,15,214,76,36,40,102,15,214,68,36,
+ 32,232,251,1,0,72,185,237,237,137,1,73,184,237,237,72,199,194,237,76,137,
+ 225,232,251,1,7,72,139,76,36,40,72,137,72,8,72,139,76,36,32,72,137,8,252,
+ 233,244,10,255,252,233,244,11,255,252,233,244,13,255,252,233,244,14,255,252,
+ 233,244,15,255,252,243,15,90,192,252,233,244,12,255
};
static const char *const globnames[] = {
@@ -1113,23 +1113,25 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
break;
case COMPLEX_FLOAT_TYPE:
- num_upvals++;
- dasm_put(Dst, 1826, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32));
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1826, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals));
break;
case COMPLEX_DOUBLE_TYPE:
- num_upvals++;
- dasm_put(Dst, 1873, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32));
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1870, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals));
break;
case VOID_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1935);
+ dasm_put(Dst, 1929);
break;
case BOOL_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1940);
+ dasm_put(Dst, 1934);
break;
case INT8_TYPE:
@@ -1139,7 +1141,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1357);
}
- dasm_put(Dst, 1945);
+ dasm_put(Dst, 1939);
break;
case INT16_TYPE:
@@ -1149,27 +1151,27 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1365);
}
- dasm_put(Dst, 1945);
+ dasm_put(Dst, 1939);
break;
case INT32_TYPE:
case ENUM_TYPE:
lua_pop(L, 1);
if (mbr_ct->is_unsigned) {
- dasm_put(Dst, 1950);
+ dasm_put(Dst, 1944);
} else {
- dasm_put(Dst, 1945);
+ dasm_put(Dst, 1939);
}
break;
case FLOAT_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1955);
+ dasm_put(Dst, 1949);
break;
case DOUBLE_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1960);
+ dasm_put(Dst, 1954);
break;
default:
diff --git a/call_x86.dasc b/call_x86.dasc
index bd0b749..ca2414c 100644
--- a/call_x86.dasc
+++ b/call_x86.dasc
@@ -1474,7 +1474,8 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
break;
case COMPLEX_FLOAT_TYPE:
- num_upvals++;
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
|.if X64
| // complex floats are returned as two floats packed into xmm0
| movq qword [rsp+32], xmm0
@@ -1485,7 +1486,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
|.endif
|
| get_errno
- | call_rrp extern push_cdata, L_ARG, 0, mbr_ct
+ | call_rrp extern push_cdata, L_ARG, lua_upvalueindex(num_upvals), mbr_ct
|
| // ((complex_float*) cdata) = val
|.if X64
@@ -1502,14 +1503,15 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
break;
case COMPLEX_DOUBLE_TYPE:
- num_upvals++;
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
|.if X64
| // complex doubles are returned as xmm0 and xmm1
| movq qword [rsp+40], xmm1
| movq qword [rsp+32], xmm0
|
| get_errno
- | call_rrp extern push_cdata, L_ARG, 0, mbr_ct
+ | call_rrp extern push_cdata, L_ARG, lua_upvalueindex(num_upvals), mbr_ct
|
| // ((complex_double*) cdata)->real = val0
| // ((complex_double*) cdata)->imag = val1
diff --git a/call_x86.h b/call_x86.h
index cea3a86..97a9270 100644
--- a/call_x86.h
+++ b/call_x86.h
@@ -13,7 +13,7 @@
* Copyright (c) 2011 James R. McKaskill. See license in ffi.h
*/
-static const unsigned char build_actionlist[1803] = {
+static const unsigned char build_actionlist[1800] = {
248,10,184,1,0,0,0,139,117,252,248,139,125,252,252,137,252,236,93,195,255,
248,11,232,251,1,0,185,237,137,1,184,0,0,0,0,139,117,252,248,139,125,252,
252,137,252,236,93,195,255,248,12,221,92,36,4,232,251,1,0,185,237,137,1,137,
@@ -93,11 +93,11 @@ static const unsigned char build_actionlist[1803] = {
1,7,139,76,36,32,137,8,252,233,244,10,255,137,84,36,36,137,68,36,32,232,251,
1,0,185,237,137,1,199,68,36,8,237,199,68,36,4,0,0,0,0,137,60,36,232,251,1,
7,139,76,36,36,139,84,36,32,137,72,4,137,16,252,233,244,10,255,137,68,36,
- 32,137,84,36,36,232,251,1,0,185,237,137,1,199,68,36,8,237,199,68,36,4,0,0,
- 0,0,137,60,36,232,251,1,7,139,76,36,32,137,8,139,76,36,36,137,72,4,252,233,
- 244,10,255,131,252,236,4,232,251,1,0,185,237,137,1,252,233,244,10,255,252,
- 233,244,11,255,252,233,244,13,255,252,233,244,14,255,252,233,244,15,255,252,
- 233,244,12,255
+ 32,137,84,36,36,232,251,1,0,185,237,137,1,199,68,36,8,237,199,68,36,4,237,
+ 137,60,36,232,251,1,7,139,76,36,32,137,8,139,76,36,36,137,72,4,252,233,244,
+ 10,255,131,252,236,4,232,251,1,0,185,237,137,1,252,233,244,10,255,252,233,
+ 244,11,255,252,233,244,13,255,252,233,244,14,255,252,233,244,15,255,252,233,
+ 244,12,255
};
static const char *const globnames[] = {
@@ -1096,23 +1096,25 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
break;
case COMPLEX_FLOAT_TYPE:
- num_upvals++;
- dasm_put(Dst, 1707, perr, mbr_ct);
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1707, perr, mbr_ct, lua_upvalueindex(num_upvals));
break;
case COMPLEX_DOUBLE_TYPE:
- num_upvals++;
- dasm_put(Dst, 1761, perr);
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1758, perr);
break;
case VOID_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1778);
+ dasm_put(Dst, 1775);
break;
case BOOL_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1783);
+ dasm_put(Dst, 1780);
break;
case INT8_TYPE:
@@ -1122,7 +1124,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1364);
}
- dasm_put(Dst, 1788);
+ dasm_put(Dst, 1785);
break;
case INT16_TYPE:
@@ -1132,27 +1134,27 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1372);
}
- dasm_put(Dst, 1788);
+ dasm_put(Dst, 1785);
break;
case INT32_TYPE:
case ENUM_TYPE:
lua_pop(L, 1);
if (mbr_ct->is_unsigned) {
- dasm_put(Dst, 1793);
+ dasm_put(Dst, 1790);
} else {
- dasm_put(Dst, 1788);
+ dasm_put(Dst, 1785);
}
break;
case FLOAT_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1798);
+ dasm_put(Dst, 1795);
break;
case DOUBLE_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1798);
+ dasm_put(Dst, 1795);
break;
default:
diff --git a/test.lua b/test.lua
index b562327..ec37967 100644
--- a/test.lua
+++ b/test.lua
@@ -900,5 +900,11 @@ assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6 7 8.5 9 10 11")
ffi.C.test_call_pppppiiifii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7, 8, 9.5, 10, 11)
assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6 7 8 9.5 10 11")
+local sum = ffi.C.add_dc(ffi.new('complex', 1, 2), ffi.new('complex', 3, 5))
+assert(ffi.istype('complex', sum))
+
+sum = ffi.C.add_fc(ffi.new('complex float', 1, 2), ffi.new('complex float', 3, 5))
+assert(ffi.istype('complex float', sum))
+
print('Test PASSED')