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 00:57:48 Branch: HEAD Handle: 2009040722574701 Added files: rpm/rpmio rpmpython.c rpmpython.h tpython.c Modified files: rpm CHANGES configure.ac devtool.conf rpm/rpmio .cvsignore Makefile.am librpmio.vers poptIO.c rpmio.c ttcl.c Log: - python: add --with-pythonembed for embedding python. Summary: Revision Changes Path 1.2906 +1 -0 rpm/CHANGES 2.357 +8 -1 rpm/configure.ac 2.277 +1 -0 rpm/devtool.conf 1.36 +1 -0 rpm/rpmio/.cvsignore 1.221 +6 -3 rpm/rpmio/Makefile.am 2.106 +4 -0 rpm/rpmio/librpmio.vers 1.39 +13 -1 rpm/rpmio/poptIO.c 1.182 +4 -0 rpm/rpmio/rpmio.c 2.1 +99 -0 rpm/rpmio/rpmpython.c 2.1 +104 -0 rpm/rpmio/rpmpython.h 2.1 +54 -0 rpm/rpmio/tpython.c 2.3 +0 -1 rpm/rpmio/ttcl.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.2905 -r1.2906 CHANGES --- rpm/CHANGES 7 Apr 2009 17:57:04 -0000 1.2905 +++ rpm/CHANGES 7 Apr 2009 22:57:47 -0000 1.2906 @@ -1,5 +1,6 @@ 5.2a3 -> 5.2a4: + - jbj: python: add --with-pythonembed for embedding python. - jbj: perl: wire-up %post -p <perl>. arg1/arg2, persistent interp, todo++. - jbj: perl: wire-up %{perl:...} with a string result. - jbj: perl: add --with-perlembed for embedding perl. @@ . patch -p0 <<'@@ .' Index: rpm/configure.ac ============================================================================ $ cvs diff -u -r2.356 -r2.357 configure.ac --- rpm/configure.ac 7 Apr 2009 17:17:21 -0000 2.356 +++ rpm/configure.ac 7 Apr 2009 22:57:47 -0000 2.357 @@ -1248,6 +1248,14 @@ [ ], []) +dnl # Python embedding +RPM_CHECK_LIB( + [Python embedding], [pythonembed], + [python], [Py_Initialize], [Python.h], + [no,external:none], [], + [ + ], []) + dnl # Tcl RPM_CHECK_LIB( [Tcl], [tcl], @@ -1794,7 +1802,6 @@ dnl # determine whether to build using a specific vendor's changes or not AC_MSG_CHECKING([if building for a specfic vendor]) - AC_ARG_WITH( [vendor], AS_HELP_STRING([--with-vendor=VENDOR], [build with a supported vendor's specific set of changes: mandriva, ark, fedora]), @@ . patch -p0 <<'@@ .' Index: rpm/devtool.conf ============================================================================ $ cvs diff -u -r2.276 -r2.277 devtool.conf --- rpm/devtool.conf 7 Apr 2009 17:17:21 -0000 2.276 +++ rpm/devtool.conf 7 Apr 2009 22:57:47 -0000 2.277 @@ -93,6 +93,7 @@ --with-libelf \ --with-selinux \ --with-python \ + --with-pythonembed=/usr/lib:/usr/include/python \ --with-perl \ --with-perlembed=/usr/lib/perl5/5.10.0/i386-linux-thread-multi/CORE \ --with-build-extlibdep \ @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/.cvsignore ============================================================================ $ cvs diff -u -r1.35 -r1.36 .cvsignore --- rpm/rpmio/.cvsignore 7 Apr 2009 17:17:21 -0000 1.35 +++ rpm/rpmio/.cvsignore 7 Apr 2009 22:57:48 -0000 1.36 @@ -45,6 +45,7 @@ tperl tput tpw +tpython tring trpmio tsw @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/Makefile.am ============================================================================ $ cvs diff -u -r1.220 -r1.221 Makefile.am --- rpm/rpmio/Makefile.am 7 Apr 2009 17:17:21 -0000 1.220 +++ rpm/rpmio/Makefile.am 7 Apr 2009 22:57:48 -0000 1.221 @@ -18,7 +18,7 @@ rpmgenbasedir rpmgenpkglist rpmgensrclist rpmgpg \ rpmpbzip2 rpmpigz rpmtar rpmz \ tdir tfts tget tglob thkp thtml tinv tkey tmacro tmagic tmire \ - tperl tput tpw trpmio tsw ttcl dumpasn1 lookup3 + tperl tpython tput tpw trpmio tsw ttcl dumpasn1 lookup3 bin_PROGRAMS = man_MANS = @@ -66,7 +66,7 @@ salsa10.h salsa20.h tiger.h \ poptIO.h rpmbc.h rpmbz.h rpmdav.h \ rpmgc.h rpmhash.h rpmhook.h rpmio_internal.h rpmkeyring.h rpmku.h \ - rpmlua.h rpmmg.h rpmnss.h rpmperl.h rpmsq.h rpmssl.h \ + rpmlua.h rpmmg.h rpmnss.h rpmperl.h rpmpython.h rpmsq.h rpmssl.h \ rpmio-stub.h rpmtcl.h rpmurl.h rpmuuid.h rpmxar.h rpmz.h rpmzq.h \ tar.h ugid.h @@ -80,7 +80,7 @@ salsa10.c salsa20.c tiger.c \ rpmbc.c rpmdav.c rpmgc.c rpmhash.c rpmhook.c rpmio.c rpmiob.c rpmio-stub.c \ rpmkeyring.c rpmku.c rpmlog.c rpmlua.c rpmmalloc.c rpmmg.c rpmnss.c \ - rpmperl.c rpmpgp.c rpmrpc.c rpmsq.c rpmssl.c rpmsw.c rpmtcl.c \ + rpmperl.c rpmpgp.c rpmpython.c rpmrpc.c rpmsq.c rpmssl.c rpmsw.c rpmtcl.c \ rpmuuid.c rpmxar.c rpmzlog.c rpmzq.c \ strcasecmp.c strtolocale.c tar.c url.c ugid.c xzdio.c yarn.c librpmio_la_LDFLAGS = -release $(LT_CURRENT).$(LT_REVISION) @@ -322,6 +322,9 @@ tperl_SOURCES = tperl.c tperl_LDADD = $(RPMIO_LDADD_COMMON) +tpython = tpython.c +tpython_LDADD = $(RPMIO_LDADD_COMMON) + tput_SOURCES = tput.c tput_LDADD = $(RPMIO_LDADD_COMMON) @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/librpmio.vers ============================================================================ $ cvs diff -u -r2.105 -r2.106 librpmio.vers --- rpm/rpmio/librpmio.vers 7 Apr 2009 17:17:21 -0000 2.105 +++ rpm/rpmio/librpmio.vers 7 Apr 2009 22:57:48 -0000 2.106 @@ -394,6 +394,10 @@ _rpmperl_debug; rpmperlNew; rpmperlRun; + _rpmpython_debug; + rpmpythonNew; + rpmpythonRun; + rpmpythonRunFile; _rpmsq_debug; rpmsqAction; rpmsqCaught; @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/poptIO.c ============================================================================ $ cvs diff -u -r1.38 -r1.39 poptIO.c --- rpm/rpmio/poptIO.c 7 Apr 2009 10:02:49 -0000 1.38 +++ rpm/rpmio/poptIO.c 7 Apr 2009 22:57:48 -0000 1.39 @@ -66,6 +66,10 @@ /*...@unchecked@*/ extern int _rpmiob_debug; /*...@unchecked@*/ +extern int _rpmperl_debug; +/*...@unchecked@*/ +extern int _rpmpython_debug; +/*...@unchecked@*/ extern int _rpmsq_debug; /*...@unchecked@*/ extern int _rpmtcl_debug; @@ -409,11 +413,19 @@ N_("Debug rpmio I/O buffers"), NULL}, { "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 + { "rpmpythondebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmpython_debug, -1, + N_("Debug embedded Python interpreter"), NULL}, +#endif { "rpmsqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmsq_debug, -1, N_("Debug rpmsq Signal Queue"), NULL}, #ifdef WITH_TCL { "rpmtcldebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmtcl_debug, -1, - N_("Debug rpmtcl TCL interpreter"), NULL}, + N_("Debug embedded TCL interpreter"), NULL}, #endif { "rpmzqdebug", '\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &_rpmzq_debug, -1, N_("Debug rpmzq Job Queuing"), NULL}, @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmio.c ============================================================================ $ cvs diff -u -r1.181 -r1.182 rpmio.c --- rpm/rpmio/rpmio.c 7 Apr 2009 17:17:21 -0000 1.181 +++ rpm/rpmio/rpmio.c 7 Apr 2009 22:57:48 -0000 1.182 @@ -3129,6 +3129,7 @@ extern rpmioPool _rpmmgPool; extern rpmioPool _rpmtclPool; extern rpmioPool _rpmperlPool; + extern rpmioPool _rpmpythonPool; /*...@=nestedextern@*/ #if defined(WITH_LUA) @@ -3145,6 +3146,9 @@ #endif urlFreeCache(); +#if defined(WITH_PYTHON) + _rpmpythonPool = rpmioFreePool(_rpmpythonPool); +#endif #if defined(WITH_PERLEMBED) _rpmperlPool = rpmioFreePool(_rpmperlPool); #endif @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmpython.c ============================================================================ $ cvs diff -u -r0 -r2.1 rpmpython.c --- /dev/null 2009-04-08 00:55:01 +0200 +++ rpmpython.c 2009-04-08 00:57:48 +0200 @@ -0,0 +1,99 @@ +#include "system.h" + +#define _RPMPYTHON_INTERNAL +#include "rpmpython.h" + +#include "debug.h" + +/*...@unchecked@*/ +int _rpmpython_debug = 0; + +static void rpmpythonFini(void * _python) + /*...@globals fileSystem @*/ + /*...@modifies *_python, fileSystem @*/ +{ + rpmpython python = _python; + + python->fn = _free(python->fn); + python->flags = 0; +#if defined(WITH_PYTHONEMBED) + Py_Finalize(); +#endif + python->I = NULL; +} + +/*...@unchecked@*/ /*...@only@*/ /*...@null@*/ +rpmioPool _rpmpythonPool; + +static rpmpython rpmpythonGetPool(/*...@null@*/ rpmioPool pool) + /*...@globals _rpmpythonPool, fileSystem @*/ + /*...@modifies pool, _rpmpythonPool, fileSystem @*/ +{ + rpmpython python; + + if (_rpmpythonPool == NULL) { + _rpmpythonPool = rpmioNewPool("python", sizeof(*python), -1, _rpmpython_debug, + NULL, NULL, rpmpythonFini); + pool = _rpmpythonPool; + } + return (rpmpython) rpmioGetPool(pool, sizeof(*python)); +} + +rpmpython rpmpythonNew(const char * fn, int flags) +{ + rpmpython python = rpmpythonGetPool(_rpmpythonPool); + + if (fn) + python->fn = xstrdup(fn); + python->flags = flags; + +#if defined(WITH_PYTHONEMBED) + Py_Initialize(); +#endif + + return rpmpythonLink(python); +} + +rpmRC rpmpythonRunFile(rpmpython python, const char * fn, const char ** resultp) +{ + rpmRC rc = RPMRC_FAIL; + +if (_rpmpython_debug) +fprintf(stderr, "==> %s(%p,%s)\n", __FUNCTION__, python, fn); + + if (fn != NULL) { +#if defined(WITH_PYTHONEMBED) + FILE * fp = fopen(fn, "rb"); + if (fp != NULL) { + PyRun_SimpleFileExFlags(fp, fn, 1, NULL); + rc = RPMRC_OK; + } +#endif +#ifdef NOTYET + if (resultp) + *resultp = Tcl_GetStringResult(python->I); +#endif + } +exit: + return rc; +} + +rpmRC rpmpythonRun(rpmpython python, const char * str, const char ** resultp) +{ + rpmRC rc = RPMRC_FAIL; + +if (_rpmpython_debug) +fprintf(stderr, "==> %s(%p,%s)\n", __FUNCTION__, python, str); + + if (str != NULL) { +#if defined(WITH_PYTHONEMBED) + PyRun_SimpleStringFlags(str, NULL); + rc = RPMRC_OK; +#ifdef NOTYET + if (resultp) + *resultp = Tcl_GetStringResult(python->I); +#endif +#endif + } + return rc; +} @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmpython.h ============================================================================ $ cvs diff -u -r0 -r2.1 rpmpython.h --- /dev/null 2009-04-08 00:55:01 +0200 +++ rpmpython.h 2009-04-08 00:57:48 +0200 @@ -0,0 +1,104 @@ +#ifndef RPMPYTHON_H +#define RPMPYTHON_H + +/** \ingroup rpmio + * \file rpmio/rpmpython.h + */ + +#include <rpmiotypes.h> +#include <rpmio.h> + +typedef /*...@abstract@*/ struct rpmpython_s * rpmpython; + +/*...@unchecked@*/ +extern int _rpmpython_debug; + +#if defined(_RPMPYTHON_INTERNAL) +#include <Python.h> + +struct rpmpython_s { + struct rpmioItem_s _item; /*!< usage mutex and pool identifier. */ + const char * fn; + int flags; + void * I; +}; +#endif /* _RPMPYTHON_INTERNAL */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Unreference a python interpreter instance. + * @param python python interpreter + * @return NULL on last dereference + */ +/*...@unused@*/ /*...@null@*/ +rpmpython rpmpythonUnlink (/*...@killref@*/ /*...@only@*/ /*...@null@*/ rpmpython python) + /*...@modifies python @*/; +#define rpmpythonUnlink(_ds) \ + ((rpmpython)rpmioUnlinkPoolItem((rpmioItem)(_python), __FUNCTION__, __FILE__, __LINE__)) + +/** + * Reference a python interpreter instance. + * @param python python interpreter + * @return new python interpreter reference + */ +/*...@unused@*/ /*...@newref@*/ /*...@null@*/ +rpmpython rpmpythonLink (/*...@null@*/ rpmpython python) + /*...@modifies python @*/; +#define rpmpythonLink(_python) \ + ((rpmpython)rpmioLinkPoolItem((rpmioItem)(_python), __FUNCTION__, __FILE__, __LINE__)) + +/** + * Destroy a python interpreter. + * @param python python interpreter + * @return NULL on last dereference + */ +/*...@null@*/ +rpmpython rpmpythonFree(/*...@killref@*/ /*...@null@*/rpmpython python) + /*...@globals fileSystem @*/ + /*...@modifies python, fileSystem @*/; +#define rpmpythonFree(_python) \ + ((rpmpython)rpmioFreePoolItem((rpmioItem)(_python), __FUNCTION__, __FILE__, __LINE__)) + +/** + * Create and load a python interpreter. + * @param fn (unimplemented) python file to load (or NULL) + * @param flags (unimplemented) python interpreter flags + * @return new python interpreter + */ +/*...@newref@*/ /*...@null@*/ +rpmpython rpmpythonNew(/*...@null@*/ const char * fn, 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 *resultp python exec result + * @return RPMRC_OK on success + */ +rpmRC rpmpythonRunFile(rpmpython python, /*...@null@*/ const char * fn, + /*...@null@*/ const char ** resultp) + /*...@globals fileSystem, internalState @*/ + /*...@modifies python, fileSystem, internalState @*/; + +/** + * Execute python string. + * @param python python interpreter + * @param str python string to execute (or NULL) + * @param *resultp python exec result + * @return RPMRC_OK on success + */ +rpmRC rpmpythonRun(rpmpython python, /*...@null@*/ const char * str, + /*...@null@*/ const char ** resultp) + /*...@globals fileSystem, internalState @*/ + /*...@modifies python, *resultp, fileSystem, internalState @*/; + +#ifdef __cplusplus +} +#endif + +#endif /* RPMPYTHON_H */ @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/tpython.c ============================================================================ $ cvs diff -u -r0 -r2.1 tpython.c --- /dev/null 2009-04-08 00:55:01 +0200 +++ tpython.c 2009-04-08 00:57:48 +0200 @@ -0,0 +1,54 @@ +#include "system.h" + +#include <rpmio_internal.h> +#include <poptIO.h> + +#define _RPMPYTHON_INTERNAL +#include <rpmpython.h> + +#include "debug.h" + +static struct poptOption optionsTable[] = { + + { NULL, '\0', POPT_ARG_INCLUDE_TABLE, rpmioAllPoptTable, 0, + N_("Common options for all rpmio executables:"), + NULL }, + + POPT_AUTOHELP + POPT_TABLEEND +}; + +int +main(int argc, char *argv[]) +{ + poptContext optCon = rpmioInit(argc, argv, optionsTable); + const char * pythonFN = NULL; + int pythonFlags = 0; + rpmpython python = rpmpythonNew(pythonFN, pythonFlags); + ARGV_t av = poptGetArgs(optCon); + int ac = argvCount(av); + const char * fn; + int rc = 1; /* assume failure */ + + if (ac < 1) { + poptPrintUsage(optCon, stderr, 0); + goto exit; + } + + while ((fn = *av++) != NULL) { + const char * result; + rpmRC ret; + result = NULL; + if ((ret = rpmpythonRunFile(python, fn, &result)) != RPMRC_OK) + goto exit; + if (result != NULL && *result != '\0') + fprintf(stdout, "%s\n", result); + } + rc = 0; + +exit: + python = rpmpythonFree(python); + optCon = rpmioFini(optCon); + + return rc; +} @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/ttcl.c ============================================================================ $ cvs diff -u -r2.2 -r2.3 ttcl.c --- rpm/rpmio/ttcl.c 6 Apr 2009 21:41:16 -0000 2.2 +++ rpm/rpmio/ttcl.c 7 Apr 2009 22:57:48 -0000 2.3 @@ -1,4 +1,3 @@ - #include "system.h" #include <rpmio_internal.h> @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org