Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED
- From: Patrick Masotta <masottaus@xxxxxxxxx>
- To: luajit@xxxxxxxxxxxxx
- Date: Sat, 30 Jun 2012 07:35:01 -0700 (PDT)
I just got a better patch for correctly taking
local buf = ffi.new("char[?]",0, "HELLO WORLD")
where 0 means "please take the length from the init string"
file: lib_ffi.c
function : LJLIB_CF(ffi_new) LJLIB_REC(.)
...
if ((info & CTF_VLA)) {
o++;
sz = lj_ctype_vlsize(cts, ct, (CTSize)ffi_checkint(L, 2));
+ {//patmod
+ if(sz==0)
+ {
+ TValue *o = L->base + 3-1; //L->base + narg-1;
+ if (tvisstr(o))
+ {
+ GCstr *str = strV(o);
+ sz = str->len+1;
+ }
+ }
+ }//patmod
}
...
This patch kicks in if size is declared as 0 and the init parameter is now a
LUA string. (it does not depend on strlen())
local test = ffi.new("char[?]", 0, "12345\0xyz");
mr.gui.Log(0,"test size= %d", ffi.sizeof(test));
>Test size= 10
it has not been extensively tested yet but so far it works ok
Other related posts:
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Peter Cawley
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Robert G. Jakabosky
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Michal Kottman
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Paulo Matias
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Robert G. Jakabosky
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Robert G. Jakabosky
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Robert G. Jakabosky
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Claire Lewis
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Claire Lewis
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Javier Guerra Giraldez
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Coda Highland
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Adam Strzelecki
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Coda Highland
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Geoff Leyland
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Geoff Leyland
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Dimiter 'malkia' Stanev
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Claire Lewis
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Sean Conner
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- dcharno
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Craig Barnes
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Patrick Masotta
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- Adam Strzelecki
- » Re: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED - Patrick Masotta
- » RE: newbie: local buf = ffi.new("char[?]", "HELLO WORLD") fails PROBABLY SOLVED- William Adams