[prev in list] [next in list] [prev in thread] [next in thread]
List: rpm-devel
Subject: Re: [CVS] RPM: rpm/js/ rpm-js.h rpmds-js.c rpmds-js.h tjs.c
From: Jeff Johnson <n3npq () mac ! com>
Date: 2009-04-24 20:36:11
Message-ID: B949A89E-FFAA-4A2A-82D8-C93E03F68C80 () mac ! com
[Download RAW message or body]
Here's what is implemented:
[jbj@fedora10 js]$ cat ds.js
var RPMTAG_NAME = 1000;
var RPMTAG_REQUIRENAME = 1049;
var RPMSENSE_ANY = 0;
var RPMSENSE_LESS = (1 << 1);
var RPMSENSE_GREATER = (1 << 2);
var RPMSENSE_EQUAL = (1 << 3);
var RPMSENSE_LE = (RPMSENSE_EQUAL|RPMSENSE_LESS);
var RPMSENSE_GE = (RPMSENSE_EQUAL|RPMSENSE_GREATER);
var ts = new Ts();
var mi = new Mi(ts);
var h = mi.next();
var ofH = new Ds(h, RPMTAG_NAME);
var fromH = new Ds(h, RPMTAG_REQUIRENAME);
var cpuinfo = new Ds('cpuinfo');
var rpmlib = new Ds('rpmlib');
var getconf = new Ds('getconf');
var uname = new Ds('uname');
var single = new Ds(["N", "EVR", RPMSENSE_LE]);
var fubar = new Ds('fubar');
var fubar = new Ds(ts);
On Apr 24, 2009, at 4:34 PM, Jeff Johnson wrote:
> 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: 24-Apr-2009 22:34:20
> Branch: HEAD Handle: 2009042420342000
>
> Modified files:
> rpm/js rpm-js.h rpmds-js.c rpmds-js.h tjs.c
>
> Log:
> - rpmds-js: ornament various rpmds constructors.
>
> Summary:
> Revision Changes Path
> 1.2 +1 -0 rpm/js/rpm-js.h
> 1.4 +96 -11 rpm/js/rpmds-js.c
> 1.2 +1 -1 rpm/js/rpmds-js.h
> 1.11 +1 -1 rpm/js/tjs.c
>
> ____________________________________________________________________________
>
> patch -p0 <<'@@ .'
> Index: rpm/js/rpm-js.h
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.1 -r1.2 rpm-js.h
> --- rpm/js/rpm-js.h 20 Apr 2009 15:45:43 -0000 1.1
> +++ rpm/js/rpm-js.h 24 Apr 2009 20:34:20 -0000 1.2
> @@ -14,6 +14,7 @@
> #define XP_UNIX 1
> #include "jsapi.h"
> #include "jscntxt.h" /* XXX JSFRAME_CONSTRUCTING */
> +#include "jsarray.h" /* XXX js_ArrayClass */
>
> #ifdef NOTYET
> #include "jsapi.h"
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/js/rpmds-js.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.3 -r1.4 rpmds-js.c
> --- rpm/js/rpmds-js.c 24 Apr 2009 17:39:08 -0000 1.3
> +++ rpm/js/rpmds-js.c 24 Apr 2009 20:34:20 -0000 1.4
> @@ -225,14 +225,100 @@
> }
>
> /* --- Object ctors/dtors */
> +#define OBJ_IS_STRING(_cx, _o) (OBJ_GET_CLASS(_cx, _o) ==
> &js_StringClass)
> +#define OBJ_IS_HEADER(_cx, _o) (OBJ_GET_CLASS(_cx, _o) ==
> &rpmhdrClass)
> +
> static rpmds
> -rpmds_init(JSContext *cx, JSObject *obj, Header h, int _tagN)
> +rpmds_init(JSContext *cx, JSObject *obj, JSObject *o, int _tagN)
> {
> - rpmds ds;
> - int flags = 0;
> + rpmds ds = NULL;
> + int xx;
>
> - if ((ds = rpmdsNew(h, _tagN, flags)) == NULL)
> + if (OBJ_IS_HEADER(cx, o)) {
> + Header h = JS_GetPrivate(cx, o);
> + int flags = 0;
> + if (_tagN == RPMTAG_NAME) {
> + flags = RPMSENSE_EQUAL;
> + _tagN = RPMTAG_PROVIDENAME;
> + ds = rpmdsThis(h, _tagN, flags);
> +if (_debug)
> +fprintf(stderr, "\trpmdsThis(%p, %s(%d), 0x%x) ds %p\n", h,
> tagName(_tagN), _tagN, flags, ds);
> + } else {
> + ds = rpmdsNew(h, _tagN, flags);
> +if (_debug)
> +fprintf(stderr, "\trpmdsNew(%p, %s(%d), 0x%x) ds %p\n", h,
> tagName(_tagN), _tagN, flags, ds);
> + }
> + if (ds == NULL)
> + return NULL;
> + } else
> + if (OBJ_IS_STRING(cx, o)) {
> + const char * s =
> + JS_GetStringBytes(JS_ValueToString(cx, OBJECT_TO_JSVAL(o)));
> + if (!strcmp(s, "cpuinfo")) {
> + xx = rpmdsCpuinfo(&ds, NULL);
> +if (_debug)
> +fprintf(stderr, "\trpmdsCpuinfo() ret %d ds %p\n", xx, ds);
> + } else
> + if (!strcmp(s, "rpmlib")) {
> + xx = rpmdsRpmlib(&ds, NULL);
> +if (_debug)
> +fprintf(stderr, "\trpmdsRpmlib() ret %d ds %p\n", xx, ds);
> + } else
> + if (!strcmp(s, "getconf")) {
> + xx = rpmdsGetconf(&ds, NULL);
> +if (_debug)
> +fprintf(stderr, "\trpmdsGetconf() ret %d ds %p\n", xx, ds);
> + } else
> + if (!strcmp(s, "uname")) {
> + xx = rpmdsUname(&ds, NULL);
> +if (_debug)
> +fprintf(stderr, "\trpmdsUname() ret %d ds %p\n", xx, ds);
> + } else {
> +if (_debug)
> +fprintf(stderr, "\tstring \"%s\" is unknown. ds %p\n", s, ds);
> + return NULL;
> + }
> + } else
> + if (OBJ_IS_ARRAY(cx, o)) {
> + jsuint length = 0;
> + jsuint i;
> + JSBool ok = JS_GetArrayLength(cx, o, &length);
> + const char * N = NULL;
> + const char * EVR = NULL;
> + uint32_t F = 0;
> +
> + if (!ok)
> + return NULL;
> + if (length != 3)
> + return NULL;
> + for (i = 0; i < length; i++) {
> + jsval v;
> + if (!(ok = JS_GetElement(cx, o, (jsint)i, &v)))
> + return NULL;
> + switch (i) {
> + default:
> + return NULL;
> + /*@notreached@*/ break;
> + case 0:
> + N = JS_GetStringBytes(JSVAL_TO_STRING(v));
> + break;
> + case 1:
> + EVR = JS_GetStringBytes(JSVAL_TO_STRING(v));
> + break;
> + case 2:
> + F = JSVAL_TO_INT(v);
> + break;
> + }
> + }
> + ds = rpmdsSingle(_tagN, N, EVR, F);
> +if (_debug)
> +fprintf(stderr, "\trpmdsSingle(%s(%d), %s, %s, 0x%x) ds %p\n",
> tagName(_tagN), _tagN, N, EVR, F, ds);
> return NULL;
> + } else {
> +if (_debug)
> +fprintf(stderr, "\tobject class %p is unknown. ds %p\n",
> OBJ_GET_CLASS(cx, o), ds);
> + return NULL;
> + }
> if (!JS_SetPrivate(cx, obj, (void *)ds)) {
> /* XXX error msg */
> (void) rpmdsFree(ds);
> @@ -257,18 +343,17 @@
> rpmds_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
> jsval *rval)
> {
> JSBool ok = JS_FALSE;
> - JSObject *hdro = NULL;
> + JSObject *o = NULL;
> int tagN = RPMTAG_REQUIRENAME;
>
> if (_debug)
> -fprintf(stderr, "==> %s(%p,%p,%p[%u],%p)\n", __FUNCTION__, cx,
> obj, argv, (unsigned)argc, rval);
> +fprintf(stderr, "==> %s(%p,%p,%p[%u],%p)%s\n", __FUNCTION__, cx,
> obj, argv, (unsigned)argc, rval, ((cx->fp->flags &
> JSFRAME_CONSTRUCTING) ? " constructing" : ""));
>
> - if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/i", &hdro,
> &tagN)))
> + if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/i", &o,
> &tagN)))
> goto exit;
>
> if (cx->fp->flags & JSFRAME_CONSTRUCTING) {
> - Header h = JS_GetInstancePrivate(cx, hdro, &rpmhdrClass, NULL);
> - if (rpmds_init(cx, obj, h, tagN) == NULL)
> + if (rpmds_init(cx, obj, o, tagN) == NULL)
> goto exit;
> } else {
> if ((obj = JS_NewObject(cx, &rpmdsClass, NULL, NULL)) == NULL)
> @@ -315,7 +400,7 @@
> }
>
> JSObject *
> -rpmjs_NewDsObject(JSContext *cx, void * _h, int _tagN)
> +rpmjs_NewDsObject(JSContext *cx, JSObject *o, int _tagN)
> {
> JSObject *obj;
> rpmds ds;
> @@ -324,7 +409,7 @@
> /* XXX error msg */
> return NULL;
> }
> - if ((ds = rpmds_init(cx, obj, _h, _tagN)) == NULL) {
> + if ((ds = rpmds_init(cx, obj, o, _tagN)) == NULL) {
> /* XXX error msg */
> return NULL;
> }
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/js/rpmds-js.h
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.1 -r1.2 rpmds-js.h
> --- rpm/js/rpmds-js.h 24 Apr 2009 12:50:58 -0000 1.1
> +++ rpm/js/rpmds-js.h 24 Apr 2009 20:34:20 -0000 1.2
> @@ -17,7 +17,7 @@
> rpmjs_InitDsClass(JSContext *cx, JSObject* obj);
>
> extern JSObject *
> -rpmjs_NewDsObject(JSContext *cx, void * _h, int _tagN);
> +rpmjs_NewDsObject(JSContext *cx, JSObject *o, int _tagN);
>
> #ifdef __cplusplus
> }
> @@ .
> patch -p0 <<'@@ .'
> Index: rpm/js/tjs.c
>
> =
> =
> =
> =
> =
> =
> ======================================================================
> $ cvs diff -u -r1.10 -r1.11 tjs.c
> --- rpm/js/tjs.c 24 Apr 2009 13:51:48 -0000 1.10
> +++ rpm/js/tjs.c 24 Apr 2009 20:34:20 -0000 1.11
> @@ -46,7 +46,7 @@
> goto exit;
> }
>
> -_rpmts_debug = -1;
> +_rpmts_debug = 0;
>
> /* XXX FIXME: resultp != NULL to actually execute?!? */
> (void) rpmjsRun(NULL, "print(\"loading RPM classes:\");",
> &result);
> @@ .
> ______________________________________________________________________
> RPM Package Manager http://rpm5.org
> CVS Sources Repository rpm-cvs@rpm5.org
______________________________________________________________________
RPM Package Manager http://rpm5.org
Developer Communication List rpm-devel@rpm5.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic