rpmlua.c   rpmlua.c 
skipping to change at line 16 skipping to change at line 16
#include <rpmiotypes.h> #include <rpmiotypes.h>
#include <rpmio.h> #include <rpmio.h>
#include <rpmmacro.h> #include <rpmmacro.h>
#include <rpmlog.h> #include <rpmlog.h>
#include <rpmurl.h> #include <rpmurl.h>
#include <rpmhook.h> #include <rpmhook.h>
#include <rpmcb.h> #include <rpmcb.h>
#include <argv.h> #include <argv.h>
#include <popt.h> /* XXX poptSaneFile test */ #include <popt.h> /* XXX poptSaneFile test */
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <lualib.h>
#ifdef WITH_SYCK #ifdef WITH_SYCK
LUALIB_API int luaopen_syck(lua_State *L) LUALIB_API int luaopen_syck(lua_State *L)
/*@modifies L @*/; /*@modifies L @*/;
#endif /* WITH_SYCK */ #endif /* WITH_SYCK */
#ifdef WITH_LUA_INTERNAL #ifdef WITH_LUA_INTERNAL
#include <llocal.h> #include <llocal.h>
#include <lposix.h> #include <lposix.h>
#include <lrexlib.h> #include <lrexlib.h>
#include <luuid.h> #include <luuid.h>
#include <lwrs.h> #include <lwrs.h>
#ifdef USE_LUA_CRYPTO /* XXX external lua modules instead. */ #ifdef USE_LUA_CRYPTO /* XXX external lua modules instead. */
#include <lcrypto.h> #include <lcrypto.h>
#include <lxplib.h> #include <lxplib.h>
#endif #endif
#ifdef USE_LUA_SOCKET /* XXX external lua modules instead. */ #ifdef USE_LUA_SOCKET /* XXX external lua modules instead. */
#include <luasocket.h> #include <luasocket.h>
#endif #endif
#endif #endif
#include <unistd.h>
#include <assert.h>
#define _RPMLUA_INTERNAL #define _RPMLUA_INTERNAL
#include "rpmlua.h" #include "rpmlua.h"
#include "debug.h" #include "debug.h"
/*@access rpmiob @*/ /*@access rpmiob @*/
#else /* WITH_LUA */ #else /* WITH_LUA */
#include <rpmio.h> #include <rpmio.h>
#endif #endif
skipping to change at line 63 skipping to change at line 60
int _rpmlua_debug = 0; int _rpmlua_debug = 0;
/*@unchecked@*/ /*@only@*/ /*@null@*/ /*@unchecked@*/ /*@only@*/ /*@null@*/
rpmioPool _rpmluaPool = NULL; rpmioPool _rpmluaPool = NULL;
/*@unchecked@*/ /*@only@*/ /*@null@*/ /*@unchecked@*/ /*@only@*/ /*@null@*/
rpmioPool _rpmluavPool = NULL; rpmioPool _rpmluavPool = NULL;
#ifdef WITH_LUA #ifdef WITH_LUA
/* XXX lua-5.2.0 retrofit destruction area. */
#if LUA_VERSION_NUM > 501
#define luaL_reg luaL_Reg
#define lua_strlen lua_rawlen
#define luaL_getn luaL_len
static int luaL_typerror(lua_State *L, int narg, const char *tname)
{
const char *msg = lua_pushfstring(L, "%s expected, got %s",
tname, luaL_typename(L, narg));
return luaL_argerror(L, narg, msg);
}
LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
const luaL_Reg *l, int nup);
#define luaopen_posix luaopen_posix_c
#define lua_open() luaL_newstate()
#endif
#if !defined(HAVE_VSNPRINTF) #if !defined(HAVE_VSNPRINTF)
static inline int vsnprintf(char * buf, /*@unused@*/ size_t nb, static inline int vsnprintf(char * buf, /*@unused@*/ size_t nb,
const char * fmt, va_list ap) const char * fmt, va_list ap)
{ {
return vsprintf(buf, fmt, ap); return vsprintf(buf, fmt, ap);
} }
#endif #endif
#define INITSTATE(_lua, lua) \ #define INITSTATE(_lua, lua) \
rpmlua lua = _lua ? _lua : \ rpmlua lua = _lua ? _lua : \
skipping to change at line 144 skipping to change at line 159
/*@-globs -mods@*/ /* XXX hide rpmGlobalMacroContext mods for now. */ /*@-globs -mods@*/ /* XXX hide rpmGlobalMacroContext mods for now. */
rpmlua rpmluaNew(void) rpmlua rpmluaNew(void)
{ {
rpmlua lua = rpmluaGetPool(_rpmluaPool); rpmlua lua = rpmluaGetPool(_rpmluaPool);
lua_State *L = lua_open(); lua_State *L = lua_open();
/*@-readonlytrans -nullassign @*/ /*@-readonlytrans -nullassign @*/
/*@observer@*/ /*@unchecked@*/ /*@observer@*/ /*@unchecked@*/
static const luaL_reg lualibs[] = { static const luaL_reg lualibs[] = {
/* standard LUA libraries */ /* standard LUA libraries */
{"", luaopen_base}, {"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package}, /* XXX 5.1.4 internal has not */
#if defined(LUA_COLIBNAME) && LUA_VERSION_NUM > 501
{LUA_COLIBNAME, luaopen_coroutine},
#endif
#if defined(LUA_TABLIBNAME)
{LUA_TABLIBNAME, luaopen_table}, {LUA_TABLIBNAME, luaopen_table},
#endif
#if defined(LUA_IOLIBNAME)
{LUA_IOLIBNAME, luaopen_io}, {LUA_IOLIBNAME, luaopen_io},
#endif
#if defined(LUA_OSLIBNAME)
{LUA_OSLIBNAME, luaopen_os}, {LUA_OSLIBNAME, luaopen_os},
#endif
#if defined(LUA_STRLIBNAME)
{LUA_STRLIBNAME, luaopen_string}, {LUA_STRLIBNAME, luaopen_string},
#endif
#if defined(LUA_BITLIBNAME) /* XXX lua >= 5.2.0 only */
{LUA_BITLIBNAME, luaopen_bit32},
#endif
#if defined(LUA_MATHLIBNAME)
{LUA_MATHLIBNAME, luaopen_math}, {LUA_MATHLIBNAME, luaopen_math},
#endif
#if defined(LUA_DBLIBNAME)
{LUA_DBLIBNAME, luaopen_debug}, {LUA_DBLIBNAME, luaopen_debug},
#endif
#if defined(LUA_LOADLIBNAME)
{LUA_LOADLIBNAME, luaopen_package},
#endif
#ifdef WITH_SYCK #ifdef WITH_SYCK
{"lsyck", luaopen_syck}, {"lsyck", luaopen_syck},
#endif /* WITH_SYCK */ #endif /* WITH_SYCK */
/* local LUA libraries (RPM only) */ /* local LUA libraries (RPM only) */
#ifdef WITH_LUA_INTERNAL #ifdef WITH_LUA_INTERNAL
{"posix", luaopen_posix}, {"posix", luaopen_posix},
{"rex_posix", luaopen_rex_posix}, {"rex_posix", luaopen_rex_posix},
{"rex_pcre", luaopen_rex_pcre}, {"rex_pcre", luaopen_rex_pcre},
{"uuid", luaopen_uuid}, {"uuid", luaopen_uuid},
{"wrs", luaopen_wrs}, {"wrs", luaopen_wrs},
skipping to change at line 202 skipping to change at line 238
lua_call(L, 1, 0); lua_call(L, 1, 0);
/*@=noeffectuncon@*/ /*@=noeffectuncon@*/
} }
{ const char * _lua_path = rpmGetPath(rpmluaPath, NULL); { const char * _lua_path = rpmGetPath(rpmluaPath, NULL);
if (_lua_path != NULL) { if (_lua_path != NULL) {
lua_pushliteral(L, "LUA_PATH"); lua_pushliteral(L, "LUA_PATH");
lua_pushstring(L, _lua_path); lua_pushstring(L, _lua_path);
_lua_path = _free(_lua_path); _lua_path = _free(_lua_path);
} }
} }
#if defined(LUA_GLOBALSINDEX)
lua_rawset(L, LUA_GLOBALSINDEX); lua_rawset(L, LUA_GLOBALSINDEX);
#else
lua_pushglobaltable(L);
#endif
lua_pushliteral(L, "print"); lua_pushliteral(L, "print");
lua_pushcfunction(L, rpm_print); lua_pushcfunction(L, rpm_print);
#if defined(LUA_GLOBALSINDEX)
lua_rawset(L, LUA_GLOBALSINDEX); lua_rawset(L, LUA_GLOBALSINDEX);
#else
lua_pushglobaltable(L);
#endif
rpmluaSetData(lua, "lua", lua); rpmluaSetData(lua, "lua", lua);
/* load all standard RPM Lua script files */ /* load all standard RPM Lua script files */
path_buf = xstrdup(rpmluaFiles); path_buf = xstrdup(rpmluaFiles);
for (path = path_buf; path != NULL && *path != '\0'; path = path_next) { for (path = path_buf; path != NULL && *path != '\0'; path = path_next) {
const char **av; const char **av;
struct stat st; struct stat st;
int ac, i; int ac, i;
/* locate start of next path element */ /* locate start of next path element */
skipping to change at line 339 skipping to change at line 383
INITSTATE(_lua, lua); INITSTATE(_lua, lua);
lua_State *L = lua->L; lua_State *L = lua->L;
if (var->listmode && lua->pushsize > 0) { if (var->listmode && lua->pushsize > 0) {
if (var->keyType != RPMLUAV_NUMBER || var->key.num == (double)0) { if (var->keyType != RPMLUAV_NUMBER || var->key.num == (double)0) {
var->keyType = RPMLUAV_NUMBER; var->keyType = RPMLUAV_NUMBER;
var->key.num = (double) luaL_getn(L, -1); var->key.num = (double) luaL_getn(L, -1);
} }
var->key.num++; var->key.num++;
} }
if (!var->listmode || lua->pushsize > 0) { if (!var->listmode || lua->pushsize > 0) {
#if defined(LUA_GLOBALSINDEX)
if (lua->pushsize == 0) if (lua->pushsize == 0)
lua_pushvalue(L, LUA_GLOBALSINDEX); lua_pushvalue(L, LUA_GLOBALSINDEX);
#endif
if (pushvar(L, var->keyType, &var->key) != -1) { if (pushvar(L, var->keyType, &var->key) != -1) {
if (pushvar(L, var->valueType, &var->value) != -1) if (pushvar(L, var->valueType, &var->value) != -1)
lua_rawset(L, -3); lua_rawset(L, -3);
else else
lua_pop(L, 1); lua_pop(L, 1);
} }
if (lua->pushsize == 0) if (lua->pushsize == 0)
lua_pop(L, 1); lua_pop(L, 1);
} }
} }
skipping to change at line 379 skipping to change at line 425
break; break;
} }
lua_pop(L, 1); lua_pop(L, 1);
} }
void rpmluaGetVar(rpmlua _lua, rpmluav var) void rpmluaGetVar(rpmlua _lua, rpmluav var)
{ {
INITSTATE(_lua, lua); INITSTATE(_lua, lua);
lua_State *L = lua->L; lua_State *L = lua->L;
if (!var->listmode) { if (!var->listmode) {
#if defined(LUA_GLOBALSINDEX)
if (lua->pushsize == 0) if (lua->pushsize == 0)
lua_pushvalue(L, LUA_GLOBALSINDEX); lua_pushvalue(L, LUA_GLOBALSINDEX);
#else
if (lua->pushsize == 0)
lua_pushglobaltable(L);
#endif
if (pushvar(L, var->keyType, &var->key) != -1) { if (pushvar(L, var->keyType, &var->key) != -1) {
lua_rawget(L, -2); lua_rawget(L, -2);
popvar(L, &var->valueType, &var->value); popvar(L, &var->valueType, &var->value);
} }
if (lua->pushsize == 0) if (lua->pushsize == 0)
lua_pop(L, 1); lua_pop(L, 1);
} else if (lua->pushsize > 0) { } else if (lua->pushsize > 0) {
(void) pushvar(L, var->keyType, &var->key); (void) pushvar(L, var->keyType, &var->key);
if (lua_next(L, -2) != 0) if (lua_next(L, -2) != 0)
popvar(L, &var->valueType, &var->value); popvar(L, &var->valueType, &var->value);
skipping to change at line 405 skipping to change at line 456
#define FINDKEY_CREATE 1 #define FINDKEY_CREATE 1
#define FINDKEY_REMOVE 2 #define FINDKEY_REMOVE 2
static int findkey(lua_State *L, int oper, const char *key, va_list va) static int findkey(lua_State *L, int oper, const char *key, va_list va)
/*@modifies L @*/ /*@modifies L @*/
{ {
char buf[BUFSIZ]; char buf[BUFSIZ];
const char *s, *e; const char *s, *e;
int ret = 0; int ret = 0;
(void) vsnprintf(buf, sizeof(buf), key, va); (void) vsnprintf(buf, sizeof(buf), key, va);
s = e = buf; s = e = buf;
#if defined(LUA_GLOBALSINDEX)
lua_pushvalue(L, LUA_GLOBALSINDEX); lua_pushvalue(L, LUA_GLOBALSINDEX);
#else
lua_pushglobaltable(L);
#endif
for (;;) { for (;;) {
if (*e == '\0' || *e == '.') { if (*e == '\0' || *e == '.') {
if (e != s) { if (e != s) {
lua_pushlstring(L, s, e-s); lua_pushlstring(L, s, e-s);
switch (oper) { switch (oper) {
case FINDKEY_REMOVE: case FINDKEY_REMOVE:
if (*e == '\0') { if (*e == '\0') {
lua_pushnil(L); lua_pushnil(L);
lua_rawset(L, -3); lua_rawset(L, -3);
lua_pop(L, 1); lua_pop(L, 1);
skipping to change at line 1209 skipping to change at line 1264
{"sleep", rpm_sleep}, {"sleep", rpm_sleep},
{"realpath", rpm_realpath}, {"realpath", rpm_realpath},
{"hostname", rpm_hostname}, {"hostname", rpm_hostname},
{NULL, NULL} {NULL, NULL}
}; };
/*@=readonlytrans =nullassign @*/ /*@=readonlytrans =nullassign @*/
static int luaopen_rpm(lua_State *L) static int luaopen_rpm(lua_State *L)
/*@modifies L @*/ /*@modifies L @*/
{ {
#if defined(LUA_GLOBALSINDEX)
lua_pushvalue(L, LUA_GLOBALSINDEX); lua_pushvalue(L, LUA_GLOBALSINDEX);
#else
lua_pushglobaltable(L);
#endif
luaL_openlib(L, "rpm", rpmlib, 0); luaL_openlib(L, "rpm", rpmlib, 0);
return 0; return 0;
} }
#endif /* WITH_LUA */ #endif /* WITH_LUA */
/*@=moduncon =mustmod =realcompare =sizeoftype @*/ /*@=moduncon =mustmod =realcompare =sizeoftype @*/
 End of changes. 23 change blocks. 
6 lines changed or deleted 65 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/