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-01 23:08:47 +0300
committerSam Gross <colesbury@gmail.com>2015-05-01 23:08:47 +0300
commit5520643c2750d2adac858392c94da9d02fe510c6 (patch)
tree511890992fd1cf0afe11ca0515ae46f1f55fab9d
parent279d859e7898ecbe0c92d30e5004c055d06d77e3 (diff)
Additional support for references.
-rw-r--r--ffi.c6
-rw-r--r--parser.c40
-rw-r--r--test.lua6
3 files changed, 29 insertions, 23 deletions
diff --git a/ffi.c b/ffi.c
index fa989e9..cbd39d0 100644
--- a/ffi.c
+++ b/ffi.c
@@ -605,7 +605,7 @@ void* check_typed_pointer(lua_State* L, int idx, int to_usr, const struct ctype*
/* any pointer can convert to void* */
goto suc;
- } else if (is_void_ptr(&ft) && ft.pointers == 1) {
+ } else if (is_void_ptr(&ft) && (ft.pointers || ft.is_reference)) {
/* void* can convert to any pointer */
goto suc;
@@ -980,7 +980,7 @@ static void set_value(lua_State* L, int idx, void* to, int to_usr, const struct
if (tt->is_array) {
set_array(L, idx, to, to_usr, tt, check_pointers);
- } else if (tt->pointers) {
+ } else if (tt->pointers || tt->is_reference) {
union {
uint8_t c[sizeof(void*)];
void* p;
@@ -1149,7 +1149,7 @@ static void get_variable_array_size(lua_State* L, int idx, struct ctype* ct)
static int is_scalar(struct ctype* ct)
{
int type = ct->type;
- if (ct->pointers) {
+ if (ct->pointers || ct->is_reference) {
return !ct->is_array;
}
return type != STRUCT_TYPE && type != UNION_TYPE && !IS_COMPLEX(type);
diff --git a/parser.c b/parser.c
index 7789f24..35c6180 100644
--- a/parser.c
+++ b/parser.c
@@ -380,26 +380,26 @@ static void calculate_member_position(lua_State* L, struct parser* P, struct cty
*pbitfield_type = mt->align_mask;
bit_offset += mt->bit_size;
-#elif defined OS_OSX
- /* OSX doesn't use containers and bitfields are not aligned. So
- * bitfields never add any padding, except for :0 which still forces
- * an alignment based off the type used with the :0 */
- if (mt->bit_size) {
- mt->offset = ct->base_size;
- mt->bit_offset = bit_offset;
- bit_offset += mt->bit_size;
- ct->base_size += bit_offset / CHAR_BIT;
- bit_offset = bit_offset % CHAR_BIT;
- } else {
- ct->base_size += (bit_offset + CHAR_BIT - 1) / CHAR_BIT;
- ct->base_size = ALIGN_UP(ct->base_size, mt->align_mask);
- bit_offset = 0;
- }
-
- if (!mt->has_member_name) {
- /* unnamed bitfields don't update the struct alignment */
- mt->align_mask = 0;
- }
+// #elif defined OS_OSX
+// /* OSX doesn't use containers and bitfields are not aligned. So
+// * bitfields never add any padding, except for :0 which still forces
+// * an alignment based off the type used with the :0 */
+// if (mt->bit_size) {
+// mt->offset = ct->base_size;
+// mt->bit_offset = bit_offset;
+// bit_offset += mt->bit_size;
+// ct->base_size += bit_offset / CHAR_BIT;
+// bit_offset = bit_offset % CHAR_BIT;
+// } else {
+// ct->base_size += (bit_offset + CHAR_BIT - 1) / CHAR_BIT;
+// ct->base_size = ALIGN_UP(ct->base_size, mt->align_mask);
+// bit_offset = 0;
+// }
+
+// if (!mt->has_member_name) {
+// /* unnamed bitfields don't update the struct alignment */
+// mt->align_mask = 0;
+// }
#elif defined __GNUC__
/* GCC tries to pack bitfields in as close as much as possible, but
diff --git a/test.lua b/test.lua
index 230c9cd..cbb721d 100644
--- a/test.lua
+++ b/test.lua
@@ -22,6 +22,7 @@ end
print('Running test')
ffi.cdef [[
+void print_g_date();
enum e8 {
FOO8,
BAR8,
@@ -269,6 +270,8 @@ struct bz_TNUM_ZNUM_BNUM {
int print_bz_TNUM_ZNUM_BNUM(size_t* sz, size_t* align, char* buf, struct bz_TNUM_ZNUM_BNUM* s);
]]
+ffi.C.print_g_date()
+
local i = ffi.C.i
local test_values = {
['void*'] = ffi.new('char[3]'),
@@ -466,6 +469,9 @@ for convention,c in pairs(dlls) do
end
local v = ffi.new('struct align_attr_def_' .. suffix, {0, test})
+ print(type)
+ print("Align " .. c['print_align_attr_def_' .. suffix](buf, v))
+ print(ffi.string(buf))
checkalign(type, v, c['print_align_attr_def_' .. suffix](buf, v))
end
end