Skip to content

Commit

Permalink
Merge pull request #8 from samm-git/patch-1
Browse files Browse the repository at this point in the history
Use lua_pushinteger instead of lua_pushunsigned
  • Loading branch information
kaworu authored Mar 19, 2021
2 parents ea49e33 + f28f577 commit d6bebd0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
LUA_VER ?= 5.2
SONAME = lua_sysctl
BUILDDIR = build
SOLIB = ${BUILDDIR}/sysctl.so
DESTDIR ?= sysctl

LDFLAGS += -shared -Wl,-soname,${SONAME}
CFLAGS += -Wall -Wextra -fPIC `pkg-config --cflags lua-5.2`
CFLAGS += -Wall -Wextra -fPIC `pkg-config --cflags lua-${LUA_VER}`

all: ${SOLIB}

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ lua version if you want to build.

Reading:
```
> require('sysctl')
> sysctl = require('sysctl')
> val, type = sysctl.get('kern.ostype') -- reading a string
> print(val)
FreeBSD
Expand Down Expand Up @@ -61,7 +61,7 @@ avm 420396

Writting:
```
> require('sysctl')
> sysctl = require('sysctl')
> sysctl.set('security.bsd.see_other_uids', 0)
```

Expand Down
11 changes: 9 additions & 2 deletions src/lua_sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
#include "lauxlib.h"
#include "lualib.h"

/*
* lua 5.3+ define LUA_MAXINTEGER, but lua 5.2 does not. See
* https://www.lua.org/manual/5.2/manual.html#lua_Integer
*/
#ifndef LUA_MAXINTEGER
#define LUA_MAXINTEGER PTRDIFF_MAX
#endif

/* NOTE: our signature of oidfmt differ from sysctl.c because we check for the
buffer's size */
Expand Down Expand Up @@ -514,10 +521,10 @@ luaA_sysctl_get(lua_State *L)
else
lua_pushinteger(L, mv);
} else {
if (intlen > sizeof(lua_Unsigned))
if (umv > LUA_MAXINTEGER)
lua_pushnumber(L, umv);
else
lua_pushunsigned(L, umv);
lua_pushinteger(L, (lua_Integer)(umv));
}
lua_settable(L, -3);
len -= intlen;
Expand Down

0 comments on commit d6bebd0

Please sign in to comment.