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:   18-Apr-2009 00:42:14
  Branch: HEAD                             Handle: 2009041722421101

  Modified files:
    rpm                     CHANGES configure.ac devtool.conf
    rpm/rpmio               rpmjs.c

  Log:
    - ficl: permit external ficl too.
    - js: simplify the embedding to the JSAPI examples, not the js shell.

  Summary:
    Revision    Changes     Path
    1.2944      +1  -0      rpm/CHANGES
    2.367       +1  -1      rpm/configure.ac
    2.291       +1  -1      rpm/devtool.conf
    1.3         +34 -286    rpm/rpmio/rpmjs.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.2943 -r1.2944 CHANGES
  --- rpm/CHANGES       17 Apr 2009 18:42:32 -0000      1.2943
  +++ rpm/CHANGES       17 Apr 2009 22:42:11 -0000      1.2944
  @@ -1,5 +1,6 @@
   
   5.2a4 -> 5.2b1:
  +    - jbj: js: simplify the embedding to the JSAPI examples, not the js 
shell.
       - jbj: ficl: capture stdout from ficl vm.
       - jbj: ficl: wire-up %post -p <ficl>.
       - jbj: ficl: wire-up %{ficl:...}. capturing stdout todo++ ...
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/configure.ac
  ============================================================================
  $ cvs diff -u -r2.366 -r2.367 configure.ac
  --- rpm/configure.ac  17 Apr 2009 16:10:22 -0000      2.366
  +++ rpm/configure.ac  17 Apr 2009 22:42:11 -0000      2.367
  @@ -1276,7 +1276,7 @@
   RPM_CHECK_LIB(
       [FICL], [ficl],
       [ficl], [ficlSystemCreate], [ficl.h],
  -    [no,internal:none], [ficl],
  +    [no,external:internal:none], [ficl],
       [ if test ".$RPM_CHECK_LIB_LOCATION" = .internal; then
             AC_DEFINE(HAVE_FICL_H, 1, [Define to 1 if you have <ficl.h>])
          AC_DEFINE(HAVE_LIBFICL, 1, [Define to 1 if you have the 'ficl' 
library (-lficl).])
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/devtool.conf
  ============================================================================
  $ cvs diff -u -r2.290 -r2.291 devtool.conf
  --- rpm/devtool.conf  17 Apr 2009 16:10:22 -0000      2.290
  +++ rpm/devtool.conf  17 Apr 2009 22:42:11 -0000      2.291
  @@ -92,7 +92,7 @@
           --with-pthreads \
           --with-libelf \
           --with-selinux \
  -     --with-ficl=internal \
  +     --with-ficl=/usr/lib:/usr/include/ficl \
        --with-js=internal \
           --with-python \
           --with-pythonembed=/usr/lib:/usr/include/python2.5 \
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmjs.c
  ============================================================================
  $ cvs diff -u -r1.2 -r1.3 rpmjs.c
  --- rpm/rpmio/rpmjs.c 17 Apr 2009 12:41:56 -0000      1.2
  +++ rpm/rpmio/rpmjs.c 17 Apr 2009 22:42:12 -0000      1.3
  @@ -30,270 +30,27 @@
   #include "debug.h"
   
   /*...@unchecked@*/
  -int _rpmjs_debug = 1;
  +int _rpmjs_debug = 0;
   
   /*...@unchecked@*/ /*...@relnull@*/
   rpmjs _rpmjsI = NULL;
   
   #if defined(WITH_JS)
  -
  -typedef enum JSShellExitCode {
  -    EXITCODE_RUNTIME_ERROR      = 3,
  -    EXITCODE_FILE_NOT_FOUND     = 4,
  -    EXITCODE_OUT_OF_MEMORY      = 5
  -} JSShellExitCode;
  -
  -static size_t gStackChunkSize = 8192;
  -static size_t gMaxStackSize = 500000;
  -static jsuword gStackBase;
  -static size_t gScriptStackQuota = JS_DEFAULT_SCRIPT_STACK_QUOTA;
  -static JSBool gEnableBranchCallback = JS_FALSE;
  -static uint32 gBranchCount;
  -static uint32 gBranchLimit;
  -static int gExitCode = 0;
  -
  -static FILE *gErrFile = NULL;
  -static FILE *gOutFile = NULL;
  -
  -static JSBool reportWarnings = JS_TRUE;
  -
  -/* We use a mix of JS_FS and JS_FN to test both kinds of natives. */
  -static JSFunctionSpec shell_functions[] = {
  -    JS_FS_END
  -};
  -
  -static JSBool
  -global_enumerate(JSContext *cx, JSObject *obj)
  -{
  -#ifdef LAZY_STANDARD_CLASSES
  -    return JS_EnumerateStandardClasses(cx, obj);
  -#else
  -    return JS_TRUE;
  -#endif
  -}
  -
  -static JSBool
  -global_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
  -               JSObject **objp)
  -{
  -#ifdef LAZY_STANDARD_CLASSES
  -    if ((flags & JSRESOLVE_ASSIGNING) == 0) {
  -        JSBool resolved;
  -
  -        if (!JS_ResolveStandardClass(cx, obj, id, &resolved))
  -            return JS_FALSE;
  -        if (resolved) {
  -            *objp = obj;
  -            return JS_TRUE;
  -        }
  -    }
  -#endif
  -
  -#if defined(SHELL_HACK) && defined(DEBUG) && defined(XP_UNIX)
  -    if ((flags & (JSRESOLVE_QUALIFIED | JSRESOLVE_ASSIGNING)) == 0) {
  -        /*
  -         * Do this expensive hack only for unoptimized Unix builds, which are
  -         * not used for benchmarking.
  -         */
  -        char *path, *comp, *full;
  -        const char *name;
  -        JSBool ok, found;
  -        JSFunction *fun;
  -
  -        if (!JSVAL_IS_STRING(id))
  -            return JS_TRUE;
  -        path = getenv("PATH");
  -        if (!path)
  -            return JS_TRUE;
  -        path = JS_strdup(cx, path);
  -        if (!path)
  -            return JS_FALSE;
  -        name = JS_GetStringBytes(JSVAL_TO_STRING(id));
  -        ok = JS_TRUE;
  -        for (comp = strtok(path, ":"); comp; comp = strtok(NULL, ":")) {
  -            if (*comp != '\0') {
  -                full = JS_smprintf("%s/%s", comp, name);
  -                if (!full) {
  -                    JS_ReportOutOfMemory(cx);
  -                    ok = JS_FALSE;
  -                    break;
  -                }
  -            } else {
  -                full = (char *)name;
  -            }
  -            found = (access(full, X_OK) == 0);
  -            if (*comp != '\0')
  -                free(full);
  -            if (found) {
  -                fun = JS_DefineFunction(cx, obj, name, Exec, 0,
  -                                        JSPROP_ENUMERATE);
  -                ok = (fun != NULL);
  -                if (ok)
  -                    *objp = obj;
  -                break;
  -            }
  -        }
  -        JS_free(cx, path);
  -        return ok;
  -    }
  -#else
  -    return JS_TRUE;
  -#endif
  -}
  -
  -JSClass global_class = {
  -    "global", JSCLASS_NEW_RESOLVE | JSCLASS_GLOBAL_FLAGS,
  -    JS_PropertyStub,  JS_PropertyStub,
  -    JS_PropertyStub,  JS_PropertyStub,
  -    global_enumerate, (JSResolveOp) global_resolve,
  -    JS_ConvertStub,   JS_FinalizeStub,
  +/*...@unchecked@*/ /*...@observer@*/
  +static JSClass global_class = {
  +    "global", JSCLASS_GLOBAL_FLAGS,
  +    JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
  +    JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
       JSCLASS_NO_OPTIONAL_MEMBERS
   };
   
  -static void
  -my_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
  -{
  -    int i, j, k, n;
  -    char *prefix, *tmp;
  -    const char *ctmp;
  -
  -    if (!report) {
  -        fprintf(gErrFile, "%s\n", message);
  -        return;
  -    }
  -
  -    /* Conditionally ignore reported warnings. */
  -    if (JSREPORT_IS_WARNING(report->flags) && !reportWarnings)
  -        return;
  -
  -    prefix = NULL;
  -    if (report->filename)
  -        prefix = JS_smprintf("%s:", report->filename);
  -    if (report->lineno) {
  -        tmp = prefix;
  -        prefix = JS_smprintf("%s%u: ", tmp ? tmp : "", report->lineno);
  -        JS_free(cx, tmp);
  -    }
  -    if (JSREPORT_IS_WARNING(report->flags)) {
  -        tmp = prefix;
  -        prefix = JS_smprintf("%s%swarning: ",
  -                             tmp ? tmp : "",
  -                             JSREPORT_IS_STRICT(report->flags) ? "strict " : 
"");
  -        JS_free(cx, tmp);
  -    }
  -
  -    /* embedded newlines -- argh! */
  -    while ((ctmp = strchr(message, '\n')) != 0) {
  -        ctmp++;
  -        if (prefix)
  -            fputs(prefix, gErrFile);
  -        fwrite(message, 1, ctmp - message, gErrFile);
  -        message = ctmp;
  -    }
  -
  -    /* If there were no filename or lineno, the prefix might be empty */
  -    if (prefix)
  -        fputs(prefix, gErrFile);
  -    fputs(message, gErrFile);
  -
  -    if (!report->linebuf) {
  -        fputc('\n', gErrFile);
  -        goto out;
  -    }
  -
  -    /* report->linebuf usually ends with a newline. */
  -    n = strlen(report->linebuf);
  -    fprintf(gErrFile, ":\n%s%s%s%s",
  -            prefix,
  -            report->linebuf,
  -            (n > 0 && report->linebuf[n-1] == '\n') ? "" : "\n",
  -            prefix);
  -    n = PTRDIFF(report->tokenptr, report->linebuf, char);
  -    for (i = j = 0; i < n; i++) {
  -        if (report->linebuf[i] == '\t') {
  -            for (k = (j + 8) & ~7; j < k; j++) {
  -                fputc('.', gErrFile);
  -            }
  -            continue;
  -        }
  -        fputc('.', gErrFile);
  -        j++;
  -    }
  -    fputs("^\n", gErrFile);
  - out:
  -    if (!JSREPORT_IS_WARNING(report->flags)) {
  -        if (report->errorNumber == JSMSG_OUT_OF_MEMORY) {
  -            gExitCode = EXITCODE_OUT_OF_MEMORY;
  -        } else {
  -            gExitCode = EXITCODE_RUNTIME_ERROR;
  -        }
  -    }
  -    JS_free(cx, prefix);
  -}
  -
  -static JSBool
  -my_BranchCallback(JSContext *cx, JSScript *script)
  -{
  -    if (++gBranchCount == gBranchLimit) {
  -        if (script) {
  -            if (script->filename)
  -                fprintf(gErrFile, "%s:", script->filename);
  -            fprintf(gErrFile, "%u: script branch callback (%u callbacks)\n",
  -                    script->lineno, gBranchLimit);
  -        } else {
  -            fprintf(gErrFile, "native branch callback (%u callbacks)\n",
  -                    gBranchLimit);
  -        }
  -        gBranchCount = 0;
  -        return JS_FALSE;
  -    }
  -#ifdef JS_THREADSAFE
  -    if ((gBranchCount & 0xff) == 1) {
  -#endif
  -        if ((gBranchCount & 0x3fff) == 1)
  -            JS_MaybeGC(cx);
  -#ifdef JS_THREADSAFE
  -        else
  -            JS_YieldRequest(cx);
  -    }
  -#endif
  -    return JS_TRUE;
  -}
  -
  -static void
  -SetContextOptions(JSContext *cx)
  -{
  -    jsuword stackLimit;
  -
  -    if (gMaxStackSize == 0) {
  -        /*
  -         * Disable checking for stack overflow if limit is zero.
  -         */
  -        stackLimit = 0;
  -    } else {
  -#if JS_STACK_GROWTH_DIRECTION > 0
  -        stackLimit = gStackBase + gMaxStackSize;
  -#else
  -        stackLimit = gStackBase - gMaxStackSize;
  -#endif
  -    }
  -    JS_SetThreadStackLimit(cx, stackLimit);
  -    JS_SetScriptStackQuota(cx, gScriptStackQuota);
  -    if (gEnableBranchCallback) {
  -        JS_SetBranchCallback(cx, my_BranchCallback);
  -        JS_ToggleOptions(cx, JSOPTION_NATIVE_BRANCH_CALLBACK);
  -    }
  -}
  -
  -static JSBool
  -ContextCallback(JSContext *cx, uintN contextOp)
  -{
  -    if (contextOp == JSCONTEXT_NEW) {
  -        JS_SetErrorReporter(cx, my_ErrorReporter);
  -        JS_SetVersion(cx, JSVERSION_LATEST);
  -        SetContextOptions(cx);
  -    }
  -    return JS_TRUE;
  +/* The error reporter callback. */
  +static void reportError(JSContext *cx, const char *msg, JSErrorReport 
*report)
  +     /*...@*/
  +{
  +    fprintf(stderr, "%s:%u:%s\n",
  +     report->filename ? report->filename : "<no filename>",
  +     (unsigned int) report->lineno, msg);
   }
   #endif
   
  @@ -332,45 +89,27 @@
       rpmjs js = rpmjsGetPool(_rpmjsPool);
   
   #if defined(WITH_JS)
  -    int stackDummy;
       static const char * _av[] = { "rpmjs", NULL };
       JSRuntime *rt;
       JSContext *cx;
  -    JSObject *glob, *it, *envobj;
  -    int result;
  +    JSObject *glob;
       int ac;
   
       if (av == NULL) av = _av;
       ac = argvCount(av);
   
  -    gStackBase = (jsuword)&stackDummy;
  -
  -    if (gErrFile == NULL) gErrFile = stderr;
  -    if (gOutFile == NULL) gOutFile = stdout;
  -
  -    rt = JS_NewRuntime(64L * 1024L * 1024L);
  -    JS_SetContextCallback(rt, ContextCallback);
  +    rt = JS_NewRuntime(8L * 1024L * 1024L);
       js->rt = rt;
   
  -    cx = JS_NewContext(rt, gStackChunkSize);
  +    cx = JS_NewContext(rt, 8192);
  +    JS_SetOptions(cx, JSOPTION_VAROBJFIX);
  +    JS_SetVersion(cx, JSVERSION_LATEST);
  +    JS_SetErrorReporter(cx, reportError);
       js->cx = cx;
   
       glob = JS_NewObject(cx, &global_class, NULL, NULL);
  -    JS_SetGlobalObject(cx, glob);
  -    JS_DefineFunctions(cx, glob, shell_functions);
  +    JS_InitStandardClasses(cx, glob);
       js->glob = glob;
  -
  -#ifdef       NOTYET
  -    it = JS_DefineObject(cx, glob, "it", &its_class, NULL, 0);
  -    JS_DefineProperties(cx, it, its_props);
  -    JS_DefineFunctions(cx, it, its_methods);
  - 
  -    envobj = JS_DefineObject(cx, glob, "environment", &env_class, NULL, 0);
  -    JS_SetPrivate(cx, envobj, envp);
  -
  -    result = ProcessArgs(cx, glob, av, ac);
  -#endif       /* NOTYET */
  -
   #endif
   
       return rpmjsLink(js);
  @@ -417,11 +156,20 @@
   
       if (str != NULL) {
   #if defined(WITH_JS)
  -     rc = RPMRC_OK;
  -#ifdef       NOTYET
  -     if (resultp)
  -         *resultp = rpmiobStr(js->iob);
  -#endif
  +     JSContext *cx = js->cx;
  +     JSObject *glob = js->glob;
  +     jsval rval;
  +     JSBool ok;
  +
  +     ok = JS_EvaluateScript(cx, glob, str, strlen(str),
  +                                     __FILE__, __LINE__, &rval);
  +     if (ok) {
  +         rc = RPMRC_OK;
  +         if (resultp) {
  +             JSString *str = JS_ValueToString(cx, rval);
  +             *resultp = JS_GetStringBytes(str);
  +         }
  +     }
   #endif
       }
       return rc;
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to