[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rpm-cvs
Subject:    [CVS] RPM: rpm/js/ Makefile.am rpmmacro-js.c rpmmacro-js.h rpmmc-js.c ...
From:       "Jeff Johnson" <jbj () rpm5 ! org>
Date:       2009-04-28 17:31:19
Message-ID: 20090428173119.8D3A13FB6D () rpm5 ! org
[Download RAW message or body]

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

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
  Module: rpm                              Date:   28-Apr-2009 19:31:19
  Branch: HEAD                             Handle: 2009042817311801

  Added files:
    rpm/js                  rpmmc-js.c rpmmc-js.h
    rpm/js/tscripts         Mc.js
  Modified files:
    rpm/js                  Makefile.am tjs.c
  Removed files:
    rpm/js                  rpmmacro-js.c rpmmacro-js.h
    rpm/js/tscripts         Macro.js

  Log:
    - js: rename the Macro -> Mc class, add mc.add/mc.del methods.

  Summary:
    Revision    Changes     Path
    1.13        +2  -2      rpm/js/Makefile.am
    1.2         +0  -277    rpm/js/rpmmacro-js.c
    1.2         +0  -26     rpm/js/rpmmacro-js.h
    1.1         +322 -0     rpm/js/rpmmc-js.c
    1.1         +26 -0      rpm/js/rpmmc-js.h
    1.21        +2  -2      rpm/js/tjs.c
    1.2         +0  -21     rpm/js/tscripts/Macro.js
    1.1         +24 -0      rpm/js/tscripts/Mc.js
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/js/Makefile.am
  ============================================================================
  $ cvs diff -u -r1.12 -r1.13 Makefile.am
  --- rpm/js/Makefile.am	28 Apr 2009 05:29:54 -0000	1.12
  +++ rpm/js/Makefile.am	28 Apr 2009 17:31:18 -0000	1.13
  @@ -58,13 +58,13 @@
   
   noinst_HEADERS = \
   	rpmjsfile.h \
  -	rpmds-js.h rpmfi-js.h rpmhdr-js.h rpmmacro-js.h rpmmi-js.h rpmps-js.h \
  +	rpmds-js.h rpmfi-js.h rpmhdr-js.h rpmmc-js.h rpmmi-js.h rpmps-js.h \
   	rpmte-js.h rpmts-js.h \
   	syck-js.h uuid-js.h
   
   rpmjsm_la_SOURCES = \
   	rpmjsfile.c \
  -	rpmds-js.c rpmfi-js.c rpmhdr-js.c rpmmacro-js.c rpmmi-js.c rpmps-js.c \
  +	rpmds-js.c rpmfi-js.c rpmhdr-js.c rpmmc-js.c rpmmi-js.c rpmps-js.c \
   	rpmte-js.c rpmts-js.c \
   	syck-js.c uuid-js.c
   
  @@ .
  rm -f rpm/js/rpmmacro-js.c <<'@@ .'
  Index: rpm/js/rpmmacro-js.c
  ============================================================================
  [NO CHANGE SUMMARY BECAUSE FILE AS A WHOLE IS JUST REMOVED]
  @@ .
  rm -f rpm/js/rpmmacro-js.h <<'@@ .'
  Index: rpm/js/rpmmacro-js.h
  ============================================================================
  [NO CHANGE SUMMARY BECAUSE FILE AS A WHOLE IS JUST REMOVED]
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmmc-js.c
  ============================================================================
  $ cvs diff -u -r0 -r1.1 rpmmc-js.c
  --- /dev/null	2009-04-28 19:31:00 +0200
  +++ rpmmc-js.c	2009-04-28 19:31:19 +0200
  @@ -0,0 +1,322 @@
  +/** \ingroup js_c
  + * \file js/rpmmc-js.c
  + */
  +
  +#include "system.h"
  +
  +#include "rpmmc-js.h"
  +#include "rpmjs-debug.h"
  +
  +#include <rpmmacro.h>
  +
  +#include "debug.h"
  +
  +/*@unchecked@*/
  +static int _debug = -1;
  +
  +typedef	MacroContext rpmmc;
  +
  +/* --- helpers */
  +
  +/* --- Object methods */
  +static JSBool
  +rpmmc_add(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +    rpmmc mc = ptr;
  +    char * s = NULL;
  +    int lvl = 0;
  +    JSBool ok = JS_FALSE;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,%p[%u],%p) ptr %p\n", __FUNCTION__, cx, obj, argv, \
(unsigned)argc, rval, ptr);  +
  +    if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &s)))
  +        goto exit;
  +
  +    (void) rpmDefineMacro(mc, s, lvl);
  +    ok = JS_TRUE;
  +exit:
  +    *rval = BOOLEAN_TO_JSVAL(ok);
  +    return ok;
  +}
  +
  +static JSBool
  +rpmmc_del(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +    rpmmc mc = ptr;
  +    char * s = NULL;
  +    JSBool ok = JS_FALSE;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,%p[%u],%p) ptr %p\n", __FUNCTION__, cx, obj, argv, \
(unsigned)argc, rval, ptr);  +
  +    if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &s)))
  +        goto exit;
  +
  +    (void) rpmUndefineMacro(mc, s);
  +    ok = JS_TRUE;
  +exit:
  +    *rval = BOOLEAN_TO_JSVAL(ok);
  +    return ok;
  +}
  +
  +static JSBool
  +rpmmc_expand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +    rpmmc mc = ptr;
  +    char * s;
  +    char * t;
  +    JSString *valstr;
  +    JSBool ok = JS_FALSE;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,%p[%u],%p) ptr %p\n", __FUNCTION__, cx, obj, argv, \
(unsigned)argc, rval, ptr);  +
  +    if (!(ok = JS_ConvertArguments(cx, argc, argv, "s", &s)))
  +        goto exit;
  +
  +    /* XXX FIXME: expand in given context, don't assume global. */
  +    t = rpmExpand(s, NULL);
  +
  +    if ((valstr = JS_NewStringCopyZ(cx, t)) == NULL)
  +	goto exit;
  +    t = _free(t);
  +    *rval = STRING_TO_JSVAL(valstr);
  +
  +    ok = JS_TRUE;
  +exit:
  +    return ok;
  +}
  +
  +static JSFunctionSpec rpmmc_funcs[] = {
  +    {"add",	rpmmc_add,		0,0,0},
  +    {"del",	rpmmc_del,		0,0,0},
  +    {"expand",	rpmmc_expand,		0,0,0},
  +    JS_FS_END
  +};
  +
  +/* --- Object properties */
  +enum rpmmc_tinyid {
  +    _DEBUG	= -2,
  +};
  +
  +static JSPropertySpec rpmmc_props[] = {
  +    {"debug",	_DEBUG,		JSPROP_ENUMERATE,	NULL,	NULL},
  +    {NULL, 0, 0, NULL, NULL}
  +};
  +
  +static JSBool
  +rpmmc_addprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +_PROP_DEBUG_ENTRY(_debug < 0);
  +    return JS_TRUE;
  +}
  +
  +static JSBool
  +rpmmc_delprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +_PROP_DEBUG_ENTRY(_debug < 0);
  +    return JS_TRUE;
  +}
  +
  +static JSBool
  +rpmmc_getprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +    jsint tiny = JSVAL_TO_INT(id);
  +    /* XXX the class has ptr == NULL, instances have ptr != NULL. */
  +    JSBool ok = (ptr ? JS_FALSE : JS_TRUE);
  +
  +    switch (tiny) {
  +    case _DEBUG:
  +	*vp = INT_TO_JSVAL(_debug);
  +	ok = JS_TRUE;
  +	break;
  +    default:
  +	break;
  +    }
  +
  +    if (!ok) {
  +_PROP_DEBUG_EXIT(_debug);
  +    }
  +
  +ok = JS_TRUE;   /* XXX avoid immediate interp exit by always succeeding. */
  +
  +    return ok;
  +}
  +
  +static JSBool
  +rpmmc_setprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +    jsint tiny = JSVAL_TO_INT(id);
  +    /* XXX the class has ptr == NULL, instances have ptr != NULL. */
  +    JSBool ok = (ptr ? JS_FALSE : JS_TRUE);
  +    int myint;
  +
  +    switch (tiny) {
  +    case _DEBUG:
  +	if (JS_ValueToInt32(cx, *vp, &_debug))
  +	    ok = JS_TRUE;
  +	break;
  +    default:
  +	break;
  +    }
  +
  +    if (!ok) {
  +_PROP_DEBUG_EXIT(_debug);
  +    }
  +    return ok;
  +}
  +
  +static JSBool
  +rpmmc_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
  +	JSObject **objp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +    JSBool ok = JS_FALSE;
  +
  +_RESOLVE_DEBUG_ENTRY(_debug < 0);
  +
  +    if ((flags & JSRESOLVE_ASSIGNING)
  +     || (ptr == NULL)) { /* don't resolve to parent prototypes objects. */
  +	*objp = NULL;
  +	ok = JS_TRUE;
  +	goto exit;
  +    }
  +
  +    *objp = obj;	/* XXX always resolve in this object. */
  +
  +    ok = JS_TRUE;
  +exit:
  +    return ok;
  +}
  +
  +static JSBool
  +rpmmc_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op,
  +		  jsval *statep, jsid *idp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +    JSBool ok = JS_FALSE;
  +
  +_ENUMERATE_DEBUG_ENTRY(_debug < 0);
  +
  +    switch (op) {
  +    case JSENUMERATE_INIT:
  +	*statep = JSVAL_VOID;
  +        if (idp)
  +            *idp = JSVAL_ZERO;
  +        break;
  +    case JSENUMERATE_NEXT:
  +	*statep = JSVAL_VOID;
  +        if (*idp != JSVAL_VOID)
  +            break;
  +        /*@fallthrough@*/
  +    case JSENUMERATE_DESTROY:
  +	*statep = JSVAL_NULL;
  +        break;
  +    }
  +    ok = JS_TRUE;
  +exit:
  +    return ok;
  +}
  +
  +static JSBool
  +rpmmc_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +
  +_CONVERT_DEBUG_ENTRY(_debug);
  +
  +    return JS_TRUE;
  +}
  +
  +/* --- Object ctors/dtors */
  +static rpmmc
  +rpmmc_init(JSContext *cx, JSObject *obj, JSObject *o)
  +{
  +    rpmmc mc = NULL;	/* XXX FIXME: only global context for now. */
  +
  +    if (!JS_SetPrivate(cx, obj, (void *)mc)) {
  +	/* XXX error msg */
  +	return NULL;
  +    }
  +    return mc;
  +}
  +
  +static void
  +rpmmc_dtor(JSContext *cx, JSObject *obj)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmmcClass, NULL);
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p) ptr %p\n", __FUNCTION__, cx, obj, ptr);
  +
  +}
  +
  +static JSBool
  +rpmmc_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
  +{
  +    JSBool ok = JS_FALSE;
  +    JSObject *o = NULL;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,%p[%u],%p)%s\n", __FUNCTION__, cx, obj, argv, \
(unsigned)argc, rval, ((cx->fp->flags & JSFRAME_CONSTRUCTING) ? " constructing" : \
""));  +
  +    if (cx->fp->flags & JSFRAME_CONSTRUCTING) {
  +	(void) rpmmc_init(cx, obj, NULL);
  +    } else {
  +	if ((obj = JS_NewObject(cx, &rpmmcClass, NULL, NULL)) == NULL)
  +	    goto exit;
  +	*rval = OBJECT_TO_JSVAL(obj);
  +    }
  +    ok = JS_TRUE;
  +
  +exit:
  +    return ok;
  +}
  +
  +/* --- Class initialization */
  +JSClass rpmmcClass = {
  +    "Mc", JSCLASS_NEW_RESOLVE | JSCLASS_NEW_ENUMERATE | JSCLASS_HAS_PRIVATE,
  +    rpmmc_addprop,   rpmmc_delprop, rpmmc_getprop, rpmmc_setprop,
  +    (JSEnumerateOp)rpmmc_enumerate, (JSResolveOp)rpmmc_resolve,
  +    rpmmc_convert,	rpmmc_dtor,
  +    JSCLASS_NO_OPTIONAL_MEMBERS
  +};
  +
  +JSObject *
  +rpmjs_InitMcClass(JSContext *cx, JSObject* obj)
  +{
  +    JSObject *proto;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p)\n", __FUNCTION__, cx, obj);
  +
  +    proto = JS_InitClass(cx, obj, NULL, &rpmmcClass, rpmmc_ctor, 1,
  +		rpmmc_props, rpmmc_funcs, NULL, NULL);
  +assert(proto != NULL);
  +    return proto;
  +}
  +
  +JSObject *
  +rpmjs_NewMcObject(JSContext *cx, JSObject *o)
  +{
  +    JSObject *obj;
  +    rpmmc mc;
  +
  +    if ((obj = JS_NewObject(cx, &rpmmcClass, NULL, NULL)) == NULL) {
  +	/* XXX error msg */
  +	return NULL;
  +    }
  +    if ((mc = rpmmc_init(cx, obj, o)) == NULL) {
  +	/* XXX error msg */
  +	return NULL;
  +    }
  +    return obj;
  +}
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmmc-js.h
  ============================================================================
  $ cvs diff -u -r0 -r1.1 rpmmc-js.h
  --- /dev/null	2009-04-28 19:31:00 +0200
  +++ rpmmc-js.h	2009-04-28 19:31:19 +0200
  @@ -0,0 +1,26 @@
  +#ifndef H_RPMMC_JS
  +#define H_RPMMC_JS
  +
  +/**
  + * \file js/rpmmc-js.h
  + */
  +
  +#include "rpm-js.h"
  +
  +extern JSClass rpmmcClass;
  +
  +#ifdef __cplusplus
  +extern "C" {
  +#endif
  +
  +extern JSObject *
  +rpmjs_InitMcClass(JSContext *cx, JSObject* obj);
  +
  +extern JSObject *
  +rpmjs_NewMcObject(JSContext *cx, JSObject *o);
  +
  +#ifdef __cplusplus      
  +}
  +#endif
  +
  +#endif	/* H_RPMMC_JS */
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/tjs.c
  ============================================================================
  $ cvs diff -u -r1.20 -r1.21 tjs.c
  --- rpm/js/tjs.c	28 Apr 2009 15:13:36 -0000	1.20
  +++ rpm/js/tjs.c	28 Apr 2009 17:31:18 -0000	1.21
  @@ -8,8 +8,8 @@
   
   #include "rpmds-js.h"
   #include "rpmfi-js.h"
  -#include "rpmmacro-js.h"
   #include "rpmhdr-js.h"
  +#include "rpmmc-js.h"
   #include "rpmmi-js.h"
   #include "rpmps-js.h"
   #include "rpmte-js.h"
  @@ -45,7 +45,7 @@
       { "Fi",		rpmjs_InitFiClass,	 14 },
       { "File",		   js_InitFileClass,	  1 },
       { "Hdr",		rpmjs_InitHdrClass,	 12 },
  -    { "Macro",		rpmjs_InitMacroClass,	 24 },
  +    { "Mc",		rpmjs_InitMcClass,	 24 },
       { "Mi",		rpmjs_InitMiClass,	 11 },
       { "Ps",		rpmjs_InitPsClass,	 16 },
       { "Syck",		rpmjs_InitSyckClass,	  3 },
  @@ .
  rm -f rpm/js/tscripts/Macro.js <<'@@ .'
  Index: rpm/js/tscripts/Macro.js
  ============================================================================
  [NO CHANGE SUMMARY BECAUSE FILE AS A WHOLE IS JUST REMOVED]
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/tscripts/Mc.js
  ============================================================================
  $ cvs diff -u -r0 -r1.1 Mc.js
  --- /dev/null	2009-04-28 19:31:00 +0200
  +++ Mc.js	2009-04-28 19:31:19 +0200
  @@ -0,0 +1,24 @@
  +if (loglvl) print("--> Mc.js");
  +
  +var mc = new Mc();
  +ack("typeof mc;", "object");
  +ack("mc instanceof Mc;", true);
  +ack("mc.debug = 1;", 1);
  +ack("mc.debug = 0;", 0);
  +
  +ack('mc.expand("%{_bindir}")', "/usr/bin");
  +
  +ack('mc.add("foo bar")', true);
  +ack('mc.expand("%{foo}")', "bar");
  +ack('mc.del("foo")', true);
  +
  +ack('mc.expand("%{lua:print(\\"lua\\")}")',	"lua");
  +
  +// FIXME: reloading rpm modules within embedded interpreter segfaults
  +// ack('mc.expand("%{perl:print \\"perl\\"}")',	"perl");
  +// ack('mc.expand("%{python:print \\"python\\"}")', "python");
  +
  +ack('mc.expand("%{ruby:puts \\"ruby\\"}")',	"ruby");
  +ack('mc.expand("%{tcl:puts \\"tcl\\"}")',	"tcl");
  +
  +if (loglvl) print("<-- Mc.js");
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic