Comments (7)
this doesn't even look like our bug, but possibly a bug in Lua itself (in its garbage collector)
you should try different versions as well, and make sure you have the latest version of 5.4 (currently 5.4.2)
from cffi-lua.
Thanks for the hints.
I tried with Lua 5.3.5 and now the segfaults seem to be captured resulting in aborts. E.g. I get the following error messages:
free(): invalid next size (normal)
Aborted
or
malloc(): invalid size (unsorted)
Aborted
Could these messages be generated by cfii
? Or by Lua itself? It would be helpful to see where in the Lua code this happens, e.g. with an error trace. But maybe that's not possible from an abort
?
I could not yet pinpoint the problem to a minimal example. Maybe it is related to my application mixing Lua and direct C allocations / free? In principle I only free
memory that was allocated with malloc
(if no bug in my app). But, for example I have cases where I do ptr = ffi.new('void *[1]')
and then I give over ptr
to a C library that allocates (frees) memory in ptr[0]
using malloc (free). I use ffi.gc
to ensure that memory is released when ptr
is garbage collected.
from cffi-lua.
well, might be our bug but without a testcase there isn't really anything i can do
these messages are generated by glibc's memory allocator
from cffi-lua.
@q66 I finally found out the reason of the memory errors in my application. It looks like structures with arrays of dimension larger than one have wrong size. E.g. the following currently fails with cffi-lua
but works with LuaJIT/ffi
:
local ffi = jit and require('ffi') or require('cffi')
ffi.cdef([[
struct transform {
double matrix[3][3];
};
]])
assert(ffi.sizeof('struct transform') == 3 * 3 * ffi.sizeof('double'))
The structure has a size of 3*8=24
instead of 3*3*8 =72
. I think that it really has a wrong size, i.e. ffi.sizeof
likely reports the actually allocated size but the allocated size is wrong (too small). I think so because I have corrupted memory due to overwriting the heap when using such constructs.
Note that ffi.sizeof('double [3][3]')
however seems to be correct, i.e. outside of a structure.
from cffi-lua.
I see, that would explain it...
from cffi-lua.
okay, that should be fixed now... thanks for reporting
from cffi-lua.
Thanks for the patch. It works fine now :)
from cffi-lua.
Related Issues (20)
- Segmentation fault when assigning a Lua callback to a C struct HOT 2
- Type comparison (istype) differs from LuaJIT HOT 4
- Defining NDEBUG macro causes ffi.sizeof struct to return 0 HOT 2
- global load `ffi.load(..., true)` not work on Windows HOT 3
- Switch build system to XMake? HOT 1
- MetaType __len not working correctly HOT 16
- `unsigned short int` throws an error
- Create a meson subproject wrap file for libffi HOT 3
- Failing FFI example HOT 6
- windows build issues HOT 4
- need support iOS HOT 1
- Problem with simple "typedef" HOT 2
- help with libcurl HOT 1
- [Question] C++14 vs ANSI C HOT 1
- Build with prebuilt Lua Version
- __new metamethod never called
- Instructions to build with MSVC
- Building for Android target
- Interaction between cffi and lgi causes crashes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cffi-lua.