Last active
August 29, 2015 14:15
-
-
Save markrwilliams/3ee9484eddf745cbb615 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cffi | |
ffi = cffi.FFI() | |
ffi.cdef(''' | |
struct bad_struct { | |
uint64_t bad_uint64[2]; | |
}; | |
typedef struct bad_struct bad_struct_t; | |
static const uint64_t BAD_CONST; | |
bad_struct_t* bad_function(bad_struct_t* arg); | |
''') | |
lib = ffi.verify(''' | |
struct bad_struct { | |
uint64_t bad_uint64[2]; | |
}; | |
typedef struct bad_struct bad_struct_t; | |
static const uint64_t BAD_CONST = 1; | |
bad_struct_t* | |
bad_function(bad_struct_t* arg) | |
{ | |
arg->bad_uint64[0] = 1; | |
arg->bad_uint64[1] = 1; | |
return arg; | |
} | |
''') | |
def test(loop): | |
BAD_CONST = ffi.cast('uint64_t', lib.BAD_CONST) | |
bad_struct = ffi.new('bad_struct_t *') | |
bad_struct = lib.bad_function(bad_struct) | |
print bad_struct.bad_uint64[0], bad_struct.bad_uint64[1] | |
if loop: | |
for v in [BAD_CONST]: | |
print bad_struct.bad_uint64[0], bad_struct.bad_uint64[1] | |
else: | |
print bad_struct.bad_uint64[0], bad_struct.bad_uint64[1] | |
test(False) | |
test(True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment