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:   16-Apr-2009 01:01:41
  Branch: HEAD                             Handle: 2009041523014000

  Modified files:
    rpm                     CHANGES
    rpm/rpmio               macro.c rpmperl.c rpmperl.h rpmpython.c
                            rpmpython.h rpmruby.c rpmruby.h rpmtcl.c rpmtcl.h

  Log:
    - rework the embedded interpreter API's preparing to handle args.
    - permit args in PHP like %{python a b c:...} syntax.

  Summary:
    Revision    Changes     Path
    1.2935      +2  -0      rpm/CHANGES
    2.224       +63 -31     rpm/rpmio/macro.c
    2.8         +1  -4      rpm/rpmio/rpmperl.c
    2.4         +5  -6      rpm/rpmio/rpmperl.h
    2.9         +1  -4      rpm/rpmio/rpmpython.c
    2.5         +7  -8      rpm/rpmio/rpmpython.h
    2.8         +1  -4      rpm/rpmio/rpmruby.c
    2.3         +7  -8      rpm/rpmio/rpmruby.h
    2.8         +1  -4      rpm/rpmio/rpmtcl.c
    2.6         +7  -8      rpm/rpmio/rpmtcl.h
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.2934 -r1.2935 CHANGES
  --- rpm/CHANGES       15 Apr 2009 18:41:29 -0000      1.2934
  +++ rpm/CHANGES       15 Apr 2009 23:01:40 -0000      1.2935
  @@ -1,5 +1,7 @@
   
   5.2a4 -> 5.2b1:
  +    - jbj: rework the embedded interpreter API's preparing to handle args.
  +    - jbj: permit args in PHP like %{python a b c:...} syntax.
       - jbj: map NULL interp to lazily instantiated globally persistent 
instance.
       - rse: RPM_CHECK_LIB: correctly handle library names like "libpython2.6" 
and "libdb-4.7"
       - rse: place XZ code under WITH_XZ (RPM_CHECK_LIB based) instead of 
HAVE_LZMA_H (standard Autoconf header check)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/macro.c
  ============================================================================
  $ cvs diff -u -r2.223 -r2.224 macro.c
  --- rpm/rpmio/macro.c 15 Apr 2009 18:41:30 -0000      2.223
  +++ rpm/rpmio/macro.c 15 Apr 2009 23:01:40 -0000      2.224
  @@ -63,6 +63,7 @@
   
   #include <rpmio_internal.h>
   #include <rpmlog.h>
  +#include <argv.h>
   #include <mire.h>
   
   #ifdef       WITH_LUA
  @@ -1442,6 +1443,45 @@
       return rc;
   }
   
  +
  +/**
  + * Parse args and string for PHP like %{foo <args> : <string> } syntax.
  + * @param s          "{ ... }" construct to parse
  + * @param nb         no. of bytes
  + * @retval *avp              invocation args
  + * @return           script string
  + */
  +static char * parseEmbedded(const char * s, size_t nb, const char *** avp)
  +     /*...@*/
  +{
  +    char * args = NULL;
  +    char * script = NULL;
  +    const char * se;
  +
  +    /* XXX FIXME: args might have embedded : too. */
  +    for (se = s + 1; se < (s+nb); se++)
  +    switch (*se) {
  +    default: continue;       /*...@notreached@*/ break;
  +    case ':':        goto bingo;     /*...@notreached@*/ break;
  +    }
  +
  +bingo:
  +    {        size_t na = (size_t)(se-s-1);
  +     int xx;
  +
  +     args = memcpy(xmalloc(na+1), s+1, na);
  +     args[na] = '\0';
  +     xx = argvSplit(avp, args, NULL);
  +     args = _free(args);
  +     nb -= na;
  +    }
  +
  +    nb -= 3;
  +    script = memcpy(xmalloc(nb+1), se+1, nb+1);
  +    script[nb] = '\0';
  +    return script;
  +}
  +
   /**
    * The main macro recursion loop.
    * @todo Dynamically reallocate target buffer.
  @@ -1721,15 +1761,12 @@
   
   #ifdef       WITH_PERLEMBED
        if (STREQ("perl", f, fn)) {
  -             rpmperl perl = (!_globalI ? rpmperlNew(NULL, 0) : NULL);
  -             const char *ls = s+sizeof("{perl:")-1;
  -             const char *lse = se-sizeof("}")+1;
  -             char *scriptbuf = (char *)xmalloc((lse-ls)+1);
  +             const char ** av = NULL;
  +             char * script = parseEmbedded(s, (size_t)(se-s), &av);
  +             rpmperl perl = rpmperlNew(av, _globalI);
                const char * result = NULL;
   
  -             memcpy(scriptbuf, ls, lse-ls);
  -             scriptbuf[lse-ls] = '\0';
  -             if (rpmperlRun(perl, scriptbuf, &result) != RPMRC_OK)
  +             if (rpmperlRun(perl, script, &result) != RPMRC_OK)
                    rc = 1;
                else {
                  if (result == NULL) result = "FIXME";
  @@ -1742,8 +1779,9 @@
                    mb->nb -= len;
                 }
                }
  -             scriptbuf = _free(scriptbuf);
                perl = rpmperlFree(perl);
  +             av = argvFree(av);
  +             script = _free(script);
                s = se;
                continue;
        }
  @@ -1751,14 +1789,11 @@
   
   #ifdef       WITH_PYTHONEMBED
        if (STREQ("python", f, fn)) {
  -             rpmpython python = (!_globalI ? rpmpythonNew(NULL, 0) : NULL);
  -             const char *ls = s+sizeof("{python:")-1;
  -             const char *lse = se-sizeof("}")+1;
  -             char *script = (char *)xmalloc((lse-ls)+1);
  +             const char ** av = NULL;
  +             char * script = parseEmbedded(s, (size_t)(se-s), &av);
  +             rpmpython python = rpmpythonNew(av, _globalI);
                const char * result = NULL;
   
  -             memcpy(script, ls, lse-ls);
  -             script[lse-ls] = '\0';
                if (rpmpythonRun(python, script, &result) != RPMRC_OK)
                    rc = 1;
                else {
  @@ -1772,8 +1807,9 @@
                    mb->nb -= len;
                  }
                }
  -             script = _free(script);
                python = rpmpythonFree(python);
  +             av = argvFree(av);
  +             script = _free(script);
                s = se;
                continue;
        }
  @@ -1781,15 +1817,12 @@
   
   #ifdef       WITH_RUBYEMBED
        if (STREQ("ruby", f, fn)) {
  -             rpmruby ruby = (!_globalI ? rpmrubyNew(NULL, 0) : NULL);
  -             const char *ls = s+sizeof("{ruby:")-1;
  -             const char *lse = se-sizeof("}")+1;
  -             char *scriptbuf = (char *)xmalloc((lse-ls)+1);
  +             const char ** av = NULL;
  +             char * script = parseEmbedded(s, (size_t)(se-s), &av);
  +             rpmruby ruby = rpmrubyNew(av, _globalI);
                const char * result = NULL;
   
  -             memcpy(scriptbuf, ls, lse-ls);
  -             scriptbuf[lse-ls] = '\0';
  -             if (rpmrubyRun(ruby, scriptbuf, &result) != RPMRC_OK)
  +             if (rpmrubyRun(ruby, script, &result) != RPMRC_OK)
                    rc = 1;
                else {
                  if (result == NULL) result = "FIXME";
  @@ -1802,8 +1835,9 @@
                    mb->nb -= len;
                  }
                }
  -             scriptbuf = _free(scriptbuf);
                ruby = rpmrubyFree(ruby);
  +             av = argvFree(av);
  +             script = _free(script);
                s = se;
                continue;
        }
  @@ -1811,15 +1845,12 @@
   
   #ifdef       WITH_TCL
        if (STREQ("tcl", f, fn)) {
  -             rpmtcl tcl = (!_globalI ? rpmtclNew(NULL, 0) : NULL);
  -             const char *ls = s+sizeof("{tcl:")-1;
  -             const char *lse = se-sizeof("}")+1;
  -             char *scriptbuf = (char *)xmalloc((lse-ls)+1);
  +             const char ** av = NULL;
  +             char * script = parseEmbedded(s, (size_t)(se-s), &av);
  +             rpmtcl tcl = rpmtclNew(av, _globalI);
                const char * result = NULL;
   
  -             memcpy(scriptbuf, ls, lse-ls);
  -             scriptbuf[lse-ls] = '\0';
  -             if (rpmtclRun(tcl, scriptbuf, &result) != RPMRC_OK)
  +             if (rpmtclRun(tcl, script, &result) != RPMRC_OK)
                    rc = 1;
                else if (result != NULL && *result != '\0') {
                    size_t len = strlen(result);
  @@ -1829,8 +1860,9 @@
                    mb->t += len;
                    mb->nb -= len;
                }
  -             scriptbuf = _free(scriptbuf);
                tcl = rpmtclFree(tcl);
  +             av = argvFree(av);
  +             script = _free(script);
                s = se;
                continue;
        }
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmperl.c
  ============================================================================
  $ cvs diff -u -r2.7 -r2.8 rpmperl.c
  --- rpm/rpmio/rpmperl.c       15 Apr 2009 18:41:30 -0000      2.7
  +++ rpm/rpmio/rpmperl.c       15 Apr 2009 23:01:40 -0000      2.8
  @@ -26,7 +26,6 @@
   {
       rpmperl perl = _perl;
   
  -    perl->fn = _free(perl->fn);
       perl->flags = 0;
   #if defined(WITH_PERLEMBED)
       PERL_SET_CONTEXT(my_perl);
  @@ -78,7 +77,7 @@
   ";
   #endif
   
  -rpmperl rpmperlNew(const char * fn, int flags)
  +rpmperl rpmperlNew(const char ** av, int flags)
   {
   #if defined(WITH_PERLEMBED)
       static char *embedding[] = { "", "-e", "0" };
  @@ -86,8 +85,6 @@
   #endif
       rpmperl perl = rpmperlGetPool(_rpmperlPool);
   
  -    if (fn)
  -     perl->fn = xstrdup(fn);
       perl->flags = flags;
   
   #if defined(WITH_PERLEMBED)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmperl.h
  ============================================================================
  $ cvs diff -u -r2.3 -r2.4 rpmperl.h
  --- rpm/rpmio/rpmperl.h       15 Apr 2009 18:41:30 -0000      2.3
  +++ rpm/rpmio/rpmperl.h       15 Apr 2009 23:01:40 -0000      2.4
  @@ -19,7 +19,6 @@
   #if defined(_RPMPERL_INTERNAL)
   struct rpmperl_s {
       struct rpmioItem_s _item;        /*!< usage mutex and pool identifier. */
  -    const char * fn;
       int flags;
       void * I;
   };
  @@ -65,19 +64,19 @@
   
   /**
    * Create and load a perl interpreter.
  - * @param fn         (unimplemented) perl file to load (or NULL)
  - * @param flags              (unimplemented) perl interpreter flags
  + * @param av         perl interpreter args (or NULL)
  + * @param flags              perl interpreter flags (1 == use global 
interpreter)
    * @return           new perl interpreter
    */
   /*...@newref@*/ /*...@null@*/
  -rpmperl rpmperlNew(/*...@null@*/ const char * fn, int flags)
  +rpmperl rpmperlNew(/*...@null@*/ const char ** av, int flags)
        /*...@globals fileSystem, internalState @*/
        /*...@modifies fileSystem, internalState @*/;
   
   /**
    * Execute perl string.
  - * @param perl               perl interpreter
  - * @param str                perl string to execute (or NULL)
  + * @param perl               perl interpreter (NULL uses global interpreter)
  + * @param str                perl string to execute (NULL returns RPMRC_FAIL)
    * @param *resultp   perl exec result
    * @return           RPMRC_OK on success
    */
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmpython.c
  ============================================================================
  $ cvs diff -u -r2.8 -r2.9 rpmpython.c
  --- rpm/rpmio/rpmpython.c     15 Apr 2009 18:41:30 -0000      2.8
  +++ rpm/rpmio/rpmpython.c     15 Apr 2009 23:01:40 -0000      2.9
  @@ -22,7 +22,6 @@
   {
       rpmpython python = _python;
   
  -    python->fn = _free(python->fn);
       python->flags = 0;
   #if defined(WITH_PYTHONEMBED)
       Py_Finalize();
  @@ -58,12 +57,10 @@
   ";
   #endif
   
  -rpmpython rpmpythonNew(const char * fn, int flags)
  +rpmpython rpmpythonNew(const char ** av, int flags)
   {
       rpmpython python = rpmpythonGetPool(_rpmpythonPool);
   
  -    if (fn)
  -     python->fn = xstrdup(fn);
       python->flags = flags;
   
   #if defined(WITH_PYTHONEMBED)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmpython.h
  ============================================================================
  $ cvs diff -u -r2.4 -r2.5 rpmpython.h
  --- rpm/rpmio/rpmpython.h     15 Apr 2009 18:41:30 -0000      2.4
  +++ rpm/rpmio/rpmpython.h     15 Apr 2009 23:01:40 -0000      2.5
  @@ -19,7 +19,6 @@
   #if defined(_RPMPYTHON_INTERNAL)
   struct rpmpython_s {
       struct rpmioItem_s _item;        /*!< usage mutex and pool identifier. */
  -    const char * fn;
       int flags;
       void * I;                        /* (unused) */
   };
  @@ -65,19 +64,19 @@
   
   /**
    * Create and load a python interpreter.
  - * @param fn         (unimplemented) python file to load (or NULL)
  - * @param flags              (unimplemented) python interpreter flags
  + * @param fn         python interpreter args (or NULL)
  + * @param flags              python interpreter flags (1 == use global 
interpreter)
    * @return           new python interpreter
    */
   /*...@newref@*/ /*...@null@*/
  -rpmpython rpmpythonNew(/*...@null@*/ const char * fn, int flags)
  +rpmpython rpmpythonNew(/*...@null@*/ const char ** av, int flags)
        /*...@globals fileSystem, internalState @*/
        /*...@modifies fileSystem, internalState @*/;
   
   /**
    * Execute python from a file.
  - * @param python     python interpreter
  - * @param fn         python file to run (or NULL)
  + * @param python     python interpreter (NULL uses global interpreter)
  + * @param fn         python file to run (NULL returns RPMRC_FAIL)
    * @param *resultp   python exec result
    * @return           RPMRC_OK on success
    */
  @@ -88,8 +87,8 @@
   
   /**
    * Execute python string.
  - * @param python     python interpreter
  - * @param str                python string to execute (or NULL)
  + * @param python     python interpreter (NULL uses global interpreter)
  + * @param str                python string to execute (NULL returns 
RPMRC_FAIL)
    * @param *resultp   python exec result
    * @return           RPMRC_OK on success
    */
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmruby.c
  ============================================================================
  $ cvs diff -u -r2.7 -r2.8 rpmruby.c
  --- rpm/rpmio/rpmruby.c       15 Apr 2009 18:41:30 -0000      2.7
  +++ rpm/rpmio/rpmruby.c       15 Apr 2009 23:01:40 -0000      2.8
  @@ -31,7 +31,6 @@
   {
       rpmruby ruby = _ruby;
   
  -    ruby->fn = _free(ruby->fn);
       ruby->flags = 0;
   #if defined(WITH_RUBYEMBED)
       ruby_finalize();
  @@ -65,12 +64,10 @@
   ";
   #endif
   
  -rpmruby rpmrubyNew(const char * fn, int flags)
  +rpmruby rpmrubyNew(const char ** av, int flags)
   {
       rpmruby ruby = rpmrubyGetPool(_rpmrubyPool);
   
  -    if (fn)
  -     ruby->fn = strdup(fn);
       ruby->flags = flags;
   
   #if defined(WITH_RUBYEMBED)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmruby.h
  ============================================================================
  $ cvs diff -u -r2.2 -r2.3 rpmruby.h
  --- rpm/rpmio/rpmruby.h       15 Apr 2009 18:41:30 -0000      2.2
  +++ rpm/rpmio/rpmruby.h       15 Apr 2009 23:01:40 -0000      2.3
  @@ -19,7 +19,6 @@
   #if defined(_RPMRUBY_INTERNAL)
   struct rpmruby_s {
       struct rpmioItem_s _item;        /*!< usage mutex and pool identifier. */
  -    const char * fn;
       int flags;
       void * I;
       unsigned long state;
  @@ -66,19 +65,19 @@
   
   /**
    * Create and load a ruby interpreter.
  - * @param fn         (unimplemented) ruby file to load (or NULL)
  - * @param flags              (unimplemented) ruby interpreter flags
  + * @param av         ruby interpreter args (or NULL)
  + * @param flags              ruby interpreter flags (1 == use global 
interpreter)
    * @return           new ruby interpreter
    */
   /*...@newref@*/ /*...@null@*/
  -rpmruby rpmrubyNew(/*...@null@*/ const char * fn, int flags)
  +rpmruby rpmrubyNew(/*...@null@*/ const char ** av, int flags)
        /*...@globals fileSystem, internalState @*/
        /*...@modifies fileSystem, internalState @*/;
   
   /**
    * Execute ruby from a file.
  - * @param ruby               ruby interpreter
  - * @param fn         ruby file to run (or NULL)
  + * @param ruby               ruby interpreter (NULL uses global interpreter)
  + * @param fn         ruby file to run (NULL returns RPMRC_FAIL)
    * @param *resultp   ruby exec result
    * @return           RPMRC_OK on success
    */
  @@ -89,8 +88,8 @@
   
   /**
    * Execute ruby string.
  - * @param ruby               ruby interpreter
  - * @param str                ruby string to execute (or NULL)
  + * @param ruby               ruby interpreter (NULL uses global interpreter)
  + * @param str                ruby string to execute (NULL returns RPMRC_FAIL)
    * @param *resultp   ruby exec result
    * @return           RPMRC_OK on success
    */
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmtcl.c
  ============================================================================
  $ cvs diff -u -r2.7 -r2.8 rpmtcl.c
  --- rpm/rpmio/rpmtcl.c        15 Apr 2009 19:34:01 -0000      2.7
  +++ rpm/rpmio/rpmtcl.c        15 Apr 2009 23:01:40 -0000      2.8
  @@ -20,7 +20,6 @@
   {
       rpmtcl tcl = _tcl;
   
  -    tcl->fn = _free(tcl->fn);
       tcl->flags = 0;
   #if defined(WITH_TCL)
       Tcl_DeleteInterp((Tcl_Interp *)tcl->I);
  @@ -105,12 +104,10 @@
   };
   #endif
   
  -rpmtcl rpmtclNew(const char * fn, int flags)
  +rpmtcl rpmtclNew(const char ** av, int flags)
   {
       rpmtcl tcl = rpmtclGetPool(_rpmtclPool);
   
  -    if (fn)
  -     tcl->fn = xstrdup(fn);
       tcl->flags = flags;
   
   #if defined(WITH_TCL)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmtcl.h
  ============================================================================
  $ cvs diff -u -r2.5 -r2.6 rpmtcl.h
  --- rpm/rpmio/rpmtcl.h        15 Apr 2009 18:41:30 -0000      2.5
  +++ rpm/rpmio/rpmtcl.h        15 Apr 2009 23:01:40 -0000      2.6
  @@ -21,7 +21,6 @@
   
   struct rpmtcl_s {
       struct rpmioItem_s _item;        /*!< usage mutex and pool identifier. */
  -    const char * fn;
       int flags;
       void * I;                        /* Tcl_Interp */
       void * tclout;           /* Tcl_Channel */
  @@ -69,19 +68,19 @@
   
   /**
    * Create and load a tcl interpreter.
  - * @param fn         (unimplemented) tcl file to load (or NULL)
  - * @param flags              (unimplemented) tcl interpreter flags
  + * @param av         tcl interpreter args (or NULL)
  + * @param flags              tcl interpreter flags (1 == use global 
interpreter)
    * @return           new tcl interpreter
    */
   /*...@newref@*/ /*...@null@*/
  -rpmtcl rpmtclNew(/*...@null@*/ const char * fn, int flags)
  +rpmtcl rpmtclNew(/*...@null@*/ const char ** av, int flags)
        /*...@globals fileSystem, internalState @*/
        /*...@modifies fileSystem, internalState @*/;
   
   /**
    * Execute tcl from a file.
  - * @param tcl                tcl interpreter
  - * @param fn         tcl file to run (or NULL)
  + * @param tcl                tcl interpreter (NULL uses global interpreter)
  + * @param fn         tcl file to run (NULL returns RPMRC_FAIL)
    * @param *resultp   tcl exec result
    * @return           RPMRC_OK on success
    */
  @@ -92,8 +91,8 @@
   
   /**
    * Execute tcl string.
  - * @param tcl                tcl interpreter
  - * @param str                tcl string to execute (or NULL)
  + * @param tcl                tcl interpreter (NULL uses global interpreter)
  + * @param str                tcl string to execute (NULL returns RPMRC_FAIL)
    * @param *resultp   tcl exec result
    * @return           RPMRC_OK on success
    */
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to