Comments (25)
More Info.
I use luajit-2.0, if I replace (single file) common.c with with version 2.6.0, It will work fine.
It just diff std alloc or lua alloc.
from lrexlib.
Thanks very much for this bug report: I am calling the allocation function incorrectly, with the Lua state pointer as the first argument instead of the allocator's userdata. I will issue a fix ASAP. If you want to fix it yourself quickly, make sure the first argument passed to "lalloc" is always "ud".
from lrexlib.
Memo to self: Lua 5.2 has changed the interface too, and requires that I pass LUA_TUSERDATA instead of 0 as the third argument when allocating.
from lrexlib.
I have pushed a fix to git that should fix things for you; please let me know if it works (it's just a new version of common.c).
The change for Lua 5.2 doesn't actually matter with the default allocator, but I will fix it anyway and make a new release. (Also, this issue should not affect LuaJIT, which uses the Lua 5.1 API.)
from lrexlib.
clear, quickly, thanks very much.,
I think below need fix too.
lpcre.c(223): ud->match = (int *) Lmalloc (L, (ALG_NSUB(ud) + 1) * 3 * sizeof (int));
Not match.
lpcre.c(340): free (ud->match);
lpcre.c(280): free (buf);
lpcre.c(284): free (buf);
Not match with buf = (int*) Lmalloc (L, (argE.ovecsize + argE.wscount) * sizeof(int)); at line 263.
void *Lfree(lua_State *L, void *p) {
void *ud;
lua_Alloc lalloc = lua_getallocf(L, &ud);
p = lalloc(ud, p, LUA_TNIL, LUA_TNIL);
if(p != NULL)
luaL_error(L, "malloc failed");
return p;
}
from lrexlib.
Thanks for that, that was another brown-paper-bag bug where I'd failed to use the lua_Alloc function to free memory everywhere (there were problems in other modules too).
However, in the process of fixing it I found and fixed two other bugs, so it's not all bad!
Thanks very much again for the bug report; I'll make a new release as soon as I can.
from lrexlib.
cdd65f3
Sorry, Can't pass, Fail.
from lrexlib.
I'll need more information than that, all the tests pass for me now with LuaJIT or Lua.
from lrexlib.
rex_pcre.dll!Lpcre_gc(lua_State * L) 行 340 + 0xa 字节 C
luajit.dll!59b8f6d2()
luajit.dll!59b537d7()
rex_pcre.dll!buffer_pushresult(tagBuffer * buf) 行 145 + 0x14 字节 C
rex_pcre.dll!algf_gsub(lua_State * L) 行 420 C
luajit.dll!59b8f6d2()
Lmalloc will call lalloc which get by lua_getallocf, and implement in shared library.(On windows It's as a dll and with NDEBUG), but rex_pcre, complied with DEBUG. That means, a same mem pointer not same management.
So it creash. I think must keep malloc and free as a pair, can't assume all thing pass. Sorry for my Pool Language
from lrexlib.
[Don't worry about your English, I'm very grateful you are working in a language I speak!]
I need to understand better. Do you mean that if I allocate a pointer with lua_Alloc function (in Lua or LuaJIT DLL), the pointer is not valid in PCRE DLL? But this already happens, because strings, allocated with LuaJIT's allocator (which is not the system one, unless you compile LuaJIT with LUAJIT_USE_SYSMALLOC) are also passed to PCRE, but apparently they do not cause this problem.
from lrexlib.
Do you mean that if I allocate a pointer with lua_Alloc function (in Lua or LuaJIT DLL), the pointer is not valid in PCRE DLL?
Not this, Please Think this, I compile luajit with -DNDEBUG, but compile rex_pcre with -D_DEBUG,
When alloc, It will use a malloc function, but when free, because _DEBUG, free as a macro for debug API,
So alloc with a way, free with another way, different memory management mechanism. Cause crash.
persist to keep same memory management mechanism, can you understand my means. Please
Build it on windows with msvc2010.
from lrexlib.
Thank you for explaining, I understand better now.
But in lrexlib, every allocation is free'd with the allocator that malloc'd it.
So for example, if allocated with "malloc", then freed with "free". If allocated with lua_Alloc, then freed with lua_Alloc.
from lrexlib.
Yes, because can be changed by user, It will match with free on some conditions.
I often use rex_pcre, It's great, Thanks.
from lrexlib.
Sorry, what can be changed by user?
from lrexlib.
Sorry, what can be changed by user?
lua_State *lua_newstate (lua_Alloc f, void *ud);
Creates a new, independent state. Returns NULL if cannot create the state (due to lack of memory). The argument f is the allocator function; Lua does all memory allocation for this state through this function. The second argument, ud, is an opaque pointer that Lua simply passes to the allocator in every call.
If I write a lua_Alloc, to cache all memory, free will cause my app fail!
from lrexlib.
OK, I understand that the user can choose an allocator.
But, in lrexlib, always the same memory management mechanism is used for each block of memory, just as you ask.
from lrexlib.
So, for example, if you write lua_Alloc to cache all memory, that is OK: free is never called on a block created with lua_Alloc.
from lrexlib.
Let me be precise: in lpcre.c, lua_Alloc is used to allocate memory in two places:
Line 223: ud->match = (int *) Lmalloc (L, (ALG_NSUB(ud) + 1) * 3 * sizeof (int));
Line 267: buf = (int*) Lmalloc (L, bufsize);
These blocks are also freed with Lfree, at lines 286, 290 and 346. They are never freed in PCRE.
from lrexlib.
Similarly, all memory allocated by PCRE is freed with pcre_free.
from lrexlib.
I am sorry, I do not use Windows, and I cannot find the mistake. If you can find the mistake, I am happy to fix it.
Otherwise, you can choose the allocator to be the same always.
from lrexlib.
Thanks very much.
All test pass.
from lrexlib.
I don't understand, I didn't change anything!
Do you mean that you find the current code does work correctly for you?
from lrexlib.
Sorry, I fetch last master version from git, So all test pass.
from lrexlib.
That's very good news, thanks for your help!
from lrexlib.
fadff34 fix all my problems
Faint, If I check last code, will save your two hours time, So sorry.
from lrexlib.
Related Issues (20)
- Crash on large string HOT 3
- 2.8.0-1 returns a compilation error HOT 9
- Problem in nginx lua module.
- luarocks install error HOT 2
- PCRE_UTF8 support? HOT 2
- Problem with installing lrexlib-2.8.0-1 PCRE on Windows 10 HOT 1
- build fails using luarocks on centos 6 HOT 9
- Need to install in pure Lua environment HOT 3
- Feature request: support Intel Hyperscan HOT 2
- Compilation errors for PCRE2 binding HOT 2
- undefined symbol: luaopen_rex_pcre HOT 1
- Lrexlib Hello World? HOT 5
- Is there way to change MATCH_LIMIT settings for PCRE? HOT 4
- You may have to install PCRE2 in your system and/or pass PCRE2_DIR or PCRE2_INCDIR to the luarocks command.
- Lua 5.4 HOT 9
- Lua 5.3 error in rex_pcre.so - Symbol not found: _lua_newuserdata HOT 2
- Lua 5.2+ attempt to call a nil value (upvalue 'loadstring') HOT 1
- reference manual is 404. HOT 1
- lrexlib-posix doc/ is not readable by everyone HOT 3
- Cannot compile with luarocks under Windows
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 lrexlib.