This may (or may not) have introduced some
memory leaks because of converting rpmlua and rpmluav
to usage mutexes (i.e. to refcounted data).

But the change should not introduce segfaults.

The code paths are too complicated and too dependent
on usage for me to do by examination or by simple
testing.

I have checked --eval %{lua:...} with the lsyck unit test and
a hello world. But --eval itself has immediate process
and exit behavior which prevents me from drilling
out leaks with valgrind (valgrind shows leaks yes).

73 de Jeff

On Apr 8, 2009, at 2:09 AM, Jeff Johnson wrote:

 RPM Package Manager, CVS Repository
 http://rpm5.org/cvs/
____________________________________________________________________________

 Server: rpm5.org                         Name:   Jeff Johnson
 Root:   /v/rpm/cvs                       Email:  j...@rpm5.org
 Module: rpm                              Date:   08-Apr-2009 08:09:59
 Branch: HEAD                             Handle: 2009040806095801

 Modified files:
   rpm                     CHANGES
   rpm/rpmio               poptIO.c rpmio.c rpmlua.c rpmlua.h

 Log:
   - yarn: convert rpmluav to usage mutex with refcounts
   - yarn: convert rpmlua to usage mutex with refcounts

 Summary:
   Revision    Changes     Path
   1.2909      +2  -0      rpm/CHANGES
   1.40        +7  -1      rpm/rpmio/poptIO.c
   1.184       +6  -0      rpm/rpmio/rpmio.c
   2.69        +65 -26     rpm/rpmio/rpmlua.c
   2.16        +2  -0      rpm/rpmio/rpmlua.h
____________________________________________________________________________

 patch -p0 <<'@@ .'
 Index: rpm/CHANGES
= = = = = = ======================================================================
 $ cvs diff -u -r1.2908 -r1.2909 CHANGES
 --- rpm/CHANGES        7 Apr 2009 23:32:59 -0000       1.2908
 +++ rpm/CHANGES        8 Apr 2009 06:09:58 -0000       1.2909
 @@ -1,5 +1,7 @@

  5.2a3 -> 5.2a4:
 +    - jbj: yarn: convert rpmluav to usage mutex with refcounts
 +    - jbj: yarn: convert rpmlua to usage mutex with refcounts
- jbj: python: wire-up %post -p <python>. arg1/arg2, persistent interp, todo++. - jbj: python: wire-up %{python:...}. the string result is bogus, todo++.
      - jbj: python: add --with-pythonembed for embedding python.
 @@ .
 patch -p0 <<'@@ .'
 Index: rpm/rpmio/poptIO.c
= = = = = = ======================================================================
 $ cvs diff -u -r1.39 -r1.40 poptIO.c
 --- rpm/rpmio/poptIO.c 7 Apr 2009 22:57:48 -0000       1.39
 +++ rpm/rpmio/poptIO.c 8 Apr 2009 06:09:59 -0000       1.40
 @@ -66,6 +66,8 @@
  /*...@unchecked@*/
  extern int _rpmiob_debug;
  /*...@unchecked@*/
 +extern int _rpmlua_debug;
 +/*...@unchecked@*/
  extern int _rpmperl_debug;
  /*...@unchecked@*/
  extern int _rpmpython_debug;
 @@ -411,13 +413,17 @@
        N_("Debug rpmio I/O"), NULL},
{ "rpmiobdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmiob_debug, -1,
        N_("Debug rpmio I/O buffers"), NULL},
 +#ifdef WITH_LUA
+ { "rpmluadebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmlua_debug, -1,
 +      N_("Debug embedded Lua interpreter"), NULL},
 +#endif
{ "rpmmgdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmmg_debug, -1,
        N_("Debug rpmmg magic"), NULL},
  #ifdef WITH_PERLEMBED
{ "rpmperldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmperl_debug, -1,
        N_("Debug embedded Perl interpreter"), NULL},
  #endif
 -#ifdef WITH_PYTHON
 +#ifdef WITH_PYTHONEMBED
{ "rpmpythondebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmpython_debug, -1,
        N_("Debug embedded Python interpreter"), NULL},
  #endif
 @@ .
 patch -p0 <<'@@ .'
 Index: rpm/rpmio/rpmio.c
= = = = = = ======================================================================
 $ cvs diff -u -r1.183 -r1.184 rpmio.c
 --- rpm/rpmio/rpmio.c  7 Apr 2009 23:33:00 -0000       1.183
 +++ rpm/rpmio/rpmio.c  8 Apr 2009 06:09:59 -0000       1.184
 @@ -3127,6 +3127,8 @@
      extern rpmioPool _htPool;
  /*...@=shadow@*/
      extern rpmioPool _rpmmgPool;
 +    extern rpmioPool _rpmluavPool;
 +    extern rpmioPool _rpmluaPool;
      extern rpmioPool _rpmtclPool;
      extern rpmioPool _rpmperlPool;
      extern rpmioPool _rpmpythonPool;
 @@ -3155,6 +3157,10 @@
  #if defined(WITH_TCL)
      _rpmtclPool = rpmioFreePool(_rpmtclPool);
  #endif
 +#if defined(WITH_LUA)
 +    _rpmluavPool = rpmioFreePool(_rpmluavPool);
 +    _rpmluaPool = rpmioFreePool(_rpmluaPool);
 +#endif
      _mirePool = rpmioFreePool(_mirePool);
      _rpmmgPool = rpmioFreePool(_rpmmgPool);
      _htPool = rpmioFreePool(_htPool);
 @@ .
 patch -p0 <<'@@ .'
 Index: rpm/rpmio/rpmlua.c
= = = = = = ======================================================================
 $ cvs diff -u -r2.68 -r2.69 rpmlua.c
 --- rpm/rpmio/rpmlua.c 1 Apr 2009 15:11:35 -0000       2.68
 +++ rpm/rpmio/rpmlua.c 8 Apr 2009 06:09:59 -0000       2.69
 @@ -45,6 +45,9 @@

  /*...@access rpmiob @*/

 +/*...@unchecked@*/
 +int _rpmlua_debug = 0;
 +
  #if !defined(HAVE_VSNPRINTF)
  static inline int vsnprintf(char * buf, /*...@unused@*/ size_t nb,
                            const char * fmt, va_list ap)
 @@ -83,10 +86,46 @@
  /*...@=globstate@*/
  }

 +void rpmluaFini(void * _lua)
 +      /*...@globals globalLuaState @*/
 +      /*...@modifies globalLuaState @*/
 +{
 +    rpmlua lua = _lua;
 +
 +    if (lua->L) lua_close(lua->L);
 +    lua->L = NULL;
 +    lua->printbuf = _free(lua->printbuf);
 +}
 +
 +/*...@unchecked@*/ /*...@only@*/ /*...@null@*/
 +rpmioPool _rpmluaPool;
 +
 +static rpmlua rpmluaGetPool(/*...@null@*/ rpmioPool pool)
 +        /*...@globals _rpmluaPool, fileSystem @*/
 +        /*...@modifies pool, _rpmluaPool, fileSystem @*/
 +{
 +    rpmlua lua;
 +
 +    if (_rpmluaPool == NULL) {
+ _rpmluaPool = rpmioNewPool("lua", sizeof(*lua), -1, _rpmlua_debug,
 +                        NULL, NULL, rpmluaFini);
 +        pool = _rpmluaPool;
 +    }
 +    return (rpmlua) rpmioGetPool(pool, sizeof(*lua));
 +}
 +
 +void *rpmluaFree(rpmlua lua)
 +{
 +    if (lua == NULL) lua = globalLuaState;
+ (void)rpmioFreePoolItem((rpmioItem)lua, __FUNCTION__, __FILE__, __LINE__);
 +    if (lua == globalLuaState) globalLuaState = NULL;
 +    return NULL;
 +}
 +
/*...@-globs -m...@*/ /* XXX hide rpmGlobalMacroContext mods for now. */
 -rpmlua rpmluaNew()
 +rpmlua rpmluaNew(void)
  {
 -    rpmlua lua = (rpmlua) xcalloc(1, sizeof(*lua));
 +    rpmlua lua = rpmluaGetPool(_rpmluaPool);
      lua_State *L = lua_open();
      /*...@-readonlytrans -nullassign @*/
      /*...@observer@*/ /*...@unchecked@*/
 @@ -193,27 +232,10 @@
      }
      path_buf = _free(path_buf);

 -    return lua;
+ return ((rpmlua)rpmioLinkPoolItem((rpmioItem)lua, __FUNCTION__, __FILE__, __LINE__));
  }
  /*...@=globs =m...@*/

 -void *rpmluaFree(rpmlua lua)
 -      /*...@globals globalLuaState @*/
 -      /*...@modifies globalLuaState @*/
 -{
 -    if (lua == NULL)
 -      lua = globalLuaState;
 -    if (lua) {
 -      if (lua->L) lua_close(lua->L);
 -      lua->printbuf = _free(lua->printbuf);
 -      if (lua == globalLuaState) globalLuaState = NULL;
 -      lua = _free(lua);
 -    }
 -/*...@-globstate@*/
 -    return NULL;
 -/*...@=globstate@*/
 -}
 -
  void rpmluaSetData(rpmlua _lua, const char *key, const void *data)
  {
      INITSTATE(_lua, lua);
 @@ -452,16 +474,33 @@
      lua_pop(lua->L, 1);
  }

 -rpmluav rpmluavNew(void)
 +void *rpmluavFree(rpmluav var)
  {
 -    rpmluav var = (rpmluav) xcalloc(1, sizeof(*var));
 -    return var;
+ (void)rpmioFreePoolItem((rpmioItem)var, __FUNCTION__, __FILE__, __LINE__);
 +    return NULL;
  }

 -void *rpmluavFree(rpmluav var)
 +/*...@unchecked@*/ /*...@only@*/ /*...@null@*/
 +rpmioPool _rpmluavPool;
 +
 +static rpmluav rpmluavGetPool(/*...@null@*/ rpmioPool pool)
 +        /*...@globals _rpmluavPool, fileSystem @*/
 +        /*...@modifies pool, _rpmluavPool, fileSystem @*/
  {
 -    var = _free(var);
 -    return NULL;
 +    rpmluav luav;
 +
 +    if (_rpmluavPool == NULL) {
+ _rpmluavPool = rpmioNewPool("luav", sizeof(*luav), -1, _rpmlua_debug,
 +                        NULL, NULL, NULL);
 +        pool = _rpmluavPool;
 +    }
 +    return (rpmluav) rpmioGetPool(pool, sizeof(*luav));
 +}
 +
 +rpmluav rpmluavNew(void)
 +{
 +    rpmluav var = rpmluavGetPool(_rpmluavPool);
+ return ((rpmluav)rpmioLinkPoolItem((rpmioItem)var, __FUNCTION__, __FILE__, __LINE__));
  }

  void rpmluavSetListMode(rpmluav var, int flag)
 @@ .
 patch -p0 <<'@@ .'
 Index: rpm/rpmio/rpmlua.h
= = = = = = ======================================================================
 $ cvs diff -u -r2.15 -r2.16 rpmlua.h
 --- rpm/rpmio/rpmlua.h 11 Dec 2008 21:55:14 -0000      2.15
 +++ rpm/rpmio/rpmlua.h 8 Apr 2009 06:09:59 -0000       2.16
 @@ -13,6 +13,7 @@
  #include <lua.h>

  struct rpmlua_s {
+ struct rpmioItem_s _item; /*!< usage mutex and pool identifier. */
      lua_State *L;
      int pushsize;
      int storeprint;
 @@ -23,6 +24,7 @@
  };

  struct rpmluav_s {
+ struct rpmioItem_s _item; /*!< usage mutex and pool identifier. */
      rpmluavType keyType;
      rpmluavType valueType;
      union {
 @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-...@rpm5.org

______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
Developer Communication List                        rpm-devel@rpm5.org

Reply via email to