Skip to content

Commit

Permalink
Fix regression wrt Lua reinitialization (RhBug:1958095)
Browse files Browse the repository at this point in the history
Commit 2579d3e started storing the Lua
context in the spec, but this leads to problems as what is actually a
global context is now stored in two places, and can get out of sync.
So if you parse a spec, and then reset the global context, you get a
fancy segfault when the freeing the spec because it's pointing to
la-la-lua land.

Revert back to always using the global Lua handle.
  • Loading branch information
pmatilai committed May 7, 2021
1 parent a9678c2 commit 13c96b2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion build/parsePreamble.c
Expand Up @@ -321,7 +321,8 @@ int addSource(rpmSpec spec, int specline, const char *srcname, rpmTagVal tag)
rpmPushMacro(spec->macros, buf, NULL, p->fullSource, RMIL_SPEC);
free(buf);

addLuaSource(spec->lua, p);
rpmlua lua = rpmluaGetGlobalState();
addLuaSource(lua, p);

if (!nofetch && tryDownload(p))
return RPMRC_FAIL;
Expand Down
1 change: 0 additions & 1 deletion build/rpmbuild_internal.h
Expand Up @@ -138,7 +138,6 @@ struct rpmSpec_s {
Package sourcePackage;

rpmMacroContext macros;
rpmlua lua;
rpmstrPool pool;

StringBuf prep; /*!< %prep scriptlet. */
Expand Down
4 changes: 2 additions & 2 deletions build/spec.c
Expand Up @@ -249,7 +249,7 @@ rpmSpec newSpec(void)
spec->macros = rpmGlobalMacroContext;
spec->pool = rpmstrPoolCreate();

spec->lua = specLuaInit(spec);
specLuaInit(spec);
return spec;
}

Expand Down Expand Up @@ -298,7 +298,7 @@ rpmSpec rpmSpecFree(rpmSpec spec)

// only destroy lua tables if there are no BASpecs left
if (spec->recursing || spec->BACount == 0) {
spec->lua = specLuaFini(spec);
specLuaFini(spec);
}

spec->sources = freeSources(spec->sources);
Expand Down
2 changes: 1 addition & 1 deletion build/speclua.c
Expand Up @@ -25,7 +25,7 @@ void * specLuaInit(rpmSpec spec)

void * specLuaFini(rpmSpec spec)
{
rpmlua lua = spec->lua;
rpmlua lua = rpmluaGetGlobalState();
lua_State *L = rpmluaGetLua(lua);
for (const char **vp = luavars; vp && *vp; vp++) {
lua_pushnil(L);
Expand Down
7 changes: 6 additions & 1 deletion tests/rpmpython.at
Expand Up @@ -67,7 +67,7 @@ for iot in [ 'fpio', 'fdio', 'ufdio', 'gzdio' ]:
],
[])

RPMPY_TEST([spec parse],[
RPMPY_TEST([spec parse 1],[
# TODO: add a better test spec with sub-packages etc
spec = rpm.spec('${RPMDATA}/SPECS/hello.spec')
for (name, num, flags) in spec.sources:
Expand All @@ -82,6 +82,11 @@ hello-1.0-1
hello-1.0-1
])

RPMPY_TEST([spec parse 2],[
spec = rpm.spec('${RPMDATA}/SPECS/mini.spec')
rpm.reloadConfig()
])

RPMPY_TEST([basic header manipulation],[
h = rpm.hdr()
h['name'] = 'testpkg'
Expand Down

0 comments on commit 13c96b2

Please sign in to comment.