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 15:24:03 Branch: HEAD Handle: 2009041613240201 Modified files: rpm CHANGES rpm/lib psm.c rpm/rpmio rpmpython.c rpmruby.c rpmruby.h Log: - ruby: load and use ARGV. Note that shell $1 ends up in ruby ARGV[0]. Summary: Revision Changes Path 1.2937 +1 -0 rpm/CHANGES 2.361 +3 -9 rpm/lib/psm.c 2.11 +27 -2 rpm/rpmio/rpmpython.c 2.9 +5 -3 rpm/rpmio/rpmruby.c 2.4 +0 -1 rpm/rpmio/rpmruby.h ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.2936 -r1.2937 CHANGES --- rpm/CHANGES 16 Apr 2009 04:04:44 -0000 1.2936 +++ rpm/CHANGES 16 Apr 2009 13:24:02 -0000 1.2937 @@ -1,5 +1,6 @@ 5.2a4 -> 5.2b1: + - jbj: ruby: load and use ARGV. Note that shell $1 ends up in ruby ARGV[0]. - jbj: python: load and use sys.argv. - jbj: ruby: finish converting to WITH_RUBYEMBED. - jbj: use poptParseArgvString, not argvSplit, for shell arg escaping. @@ . patch -p0 <<'@@ .' Index: rpm/lib/psm.c ============================================================================ $ cvs diff -u -r2.360 -r2.361 psm.c --- rpm/lib/psm.c 16 Apr 2009 04:04:45 -0000 2.360 +++ rpm/lib/psm.c 16 Apr 2009 13:24:03 -0000 2.361 @@ -677,15 +677,9 @@ #endif #if defined(WITH_RUBY) if (!strcmp(Phe->p.argv[0], "<ruby>")) { - rpmruby ruby = rpmrubyNew(NULL, 0); - char args[128]; - (void)snprintf(args, sizeof(args), "arg = [%d,%d]", arg1, arg2); - args[sizeof(args)-1] = '\0'; - if (rpmrubyRun(ruby, args, NULL) == RPMRC_OK - && rpmrubyRun(ruby, script, NULL) == RPMRC_OK) - rc = RPMRC_OK; - else - rc = RPMRC_FAIL; + rpmruby ruby = rpmrubyNew(av, 0); + rc = rpmrubyRun(ruby, script, NULL) == RPMRC_OK + ? RPMRC_OK : RPMRC_FAIL; ruby = rpmrubyFree(ruby); } else #endif @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmpython.c ============================================================================ $ cvs diff -u -r2.10 -r2.11 rpmpython.c --- rpm/rpmio/rpmpython.c 16 Apr 2009 04:04:46 -0000 2.10 +++ rpm/rpmio/rpmpython.c 16 Apr 2009 13:24:03 -0000 2.11 @@ -121,6 +121,30 @@ return rc; } +static const char * rpmpythonSlurp(const char * arg) + /*...@*/ +{ + rpmiob iob = NULL; + const char * val = NULL; + struct stat sb; + int xx; + + if (!strcmp(arg, "-")) { /* Macros from stdin arg. */ + xx = rpmiobSlurp(arg, &iob); + } else + if ((arg[0] == '/' || strchr(arg, ' ') == NULL) + && !Stat(arg, &sb) + && S_ISREG(sb.st_mode)) { /* Macros from a file arg. */ + xx = rpmiobSlurp(arg, &iob); + } else { /* Macros from string arg. */ + iob = rpmiobAppend(rpmiobNew(strlen(arg)+1), arg, 0); + } + + val = xstrdup(rpmiobStr(iob)); + iob = rpmiobFree(iob); + return val; +} + rpmRC rpmpythonRun(rpmpython python, const char * str, const char ** resultp) { rpmRC rc = RPMRC_FAIL; @@ -131,11 +155,12 @@ if (python == NULL) python = rpmpythonI(); if (str != NULL) { + const char * val = rpmpythonSlurp(str); #if defined(WITH_PYTHONEMBED) PyCompilerFlags cf = { .cf_flags = 0 }; PyObject * m = PyImport_AddModule("__main__"); PyObject * d = (m ? PyModule_GetDict(m) : NULL); - PyObject * v = (m ? PyRun_StringFlags(str, Py_file_input, d, d, &cf) : NULL); + PyObject * v = (m ? PyRun_StringFlags(val, Py_file_input, d, d, &cf) : NULL); if (v == NULL) { PyErr_Print(); @@ -148,13 +173,13 @@ } else *resultp = ""; } - Py_DECREF(v); if (Py_FlushLine()) PyErr_Clear(); rc = RPMRC_OK; } #endif + val = _free(val); } return rc; } @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmruby.c ============================================================================ $ cvs diff -u -r2.8 -r2.9 rpmruby.c --- rpm/rpmio/rpmruby.c 15 Apr 2009 23:01:40 -0000 2.8 +++ rpm/rpmio/rpmruby.c 16 Apr 2009 13:24:03 -0000 2.9 @@ -1,4 +1,5 @@ #include "system.h" +#include <argv.h> /* XXX grrr, ruby.h includes its own config.h too. */ #ifdef HAVE_CONFIG_H @@ -31,7 +32,6 @@ { rpmruby ruby = _ruby; - ruby->flags = 0; #if defined(WITH_RUBYEMBED) ruby_finalize(); ruby_cleanup(0); @@ -66,14 +66,16 @@ rpmruby rpmrubyNew(const char ** av, int flags) { + static const char * _av[] = { "rpmpython", NULL }; rpmruby ruby = rpmrubyGetPool(_rpmrubyPool); - ruby->flags = flags; + if (av == NULL) av = _av; #if defined(WITH_RUBYEMBED) ruby_init(); ruby_init_loadpath(); - ruby_script("rpmruby"); + ruby_script((char *)av[0]); + ruby_set_argv(argvCount(av)-1, (char **)av+1); rb_gv_set("$result", rb_str_new2("")); (void) rpmrubyRun(ruby, rpmrubyInitStringIO, NULL); #endif @@ . patch -p0 <<'@@ .' Index: rpm/rpmio/rpmruby.h ============================================================================ $ cvs diff -u -r2.3 -r2.4 rpmruby.h --- rpm/rpmio/rpmruby.h 15 Apr 2009 23:01:40 -0000 2.3 +++ rpm/rpmio/rpmruby.h 16 Apr 2009 13:24:03 -0000 2.4 @@ -19,7 +19,6 @@ #if defined(_RPMRUBY_INTERNAL) struct rpmruby_s { struct rpmioItem_s _item; /*!< usage mutex and pool identifier. */ - int flags; void * I; unsigned long state; }; @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org