Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Conversation

@HeinrichHartmann
Copy link

@HeinrichHartmann HeinrichHartmann commented Jun 1, 2016

On operating systems like Solaris and Illumos where the stack grows down, lightuserdata and user data cannot be assigned from the stack. This commit patch fixes this behaviour by moving the allocations to the heap (using calloc).

We also ran into symbol collisions (compile) when linking the library with our codebase. This is also addressed in a separate commit.

as provided by http://www.inf.puc-rio.br/~roberto/lpeg/ on 2016-05-26

`MD5 (lpeg-1.0.0.tar.gz) = 0aec64ccd13996202ad0c099e2877ece`
Solaris (OmniOS, Illumos) version of luajit does not support support
allocation of lightuserdata on the stack. This gives errors like this:

```
$ luajit test.lua
General tests for LPeg library
version 1.0.0
luajit: bad light userdata pointer
stack traceback:
        [C]: in function 'match'
        test.lua:58: in main chunk
        [C]: at 0x00402d50
```

This commit patch fixes this behavior by moving the allocations to the
heap.
const char *match (lua_State *L, const char *o, const char *s, const char *e,
Instruction *op, Capture *capture, int ptop) {
Stack stackbase[INITBACK];
Stack *stackbase = calloc(INITBACK, sizeof(Stack));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sanity check present in case of failure.

By using the assert macro the process will exit if calloc fails.  There
is little chance to recover from a failed allocation. Moreover assert()
is used at other places already.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants