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

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  [email protected]
  Module: rpm                              Date:   26-Jun-2009 20:11:25
  Branch: HEAD                             Handle: 2009062618112500

  Added files:
    rpm/js                  rpmbf-js.c rpmbf-js.h
  Modified files:
    rpm/js                  Makefile.am tjs.c

  Log:
    - js: stub-in a rpmbf unit test bit banger.

  Summary:
    Revision    Changes     Path
    1.17        +4  -4      rpm/js/Makefile.am
    1.1         +383 -0     rpm/js/rpmbf-js.c
    1.1         +27 -0      rpm/js/rpmbf-js.h
    1.33        +13 -11     rpm/js/tjs.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/js/Makefile.am
  ============================================================================
  $ cvs diff -u -r1.16 -r1.17 Makefile.am
  --- rpm/js/Makefile.am        12 Jun 2009 19:29:27 -0000      1.16
  +++ rpm/js/Makefile.am        26 Jun 2009 18:11:25 -0000      1.17
  @@ -64,14 +64,14 @@
   
   noinst_HEADERS = \
        rpmjsfile.h \
  -     rpmaug-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 \
  +     rpmaug-js.h rpmbf-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 \
  -     rpmaug-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 \
  +     rpmaug-js.c rpmbf-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
   
   librpmjsm_la_SOURCES = $(rpmjsm_la_SOURCES)
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmbf-js.c
  ============================================================================
  $ cvs diff -u -r0 -r1.1 rpmbf-js.c
  --- /dev/null 2009-06-26 20:11:01 +0200
  +++ rpmbf-js.c        2009-06-26 20:11:25 +0200
  @@ -0,0 +1,383 @@
  +/** \ingroup js_c
  + * \file js/rpmbf-js.c
  + */
  +
  +#include "system.h"
  +
  +#include "rpmbf-js.h"
  +#include "rpmjs-debug.h"
  +
  +#include <rpmmacro.h>
  +#include <rpmbf.h>
  +
  +#include "debug.h"
  +
  +/*...@unchecked@*/
  +static int _debug = 0;
  +
  +#define      rpmbf_addprop   JS_PropertyStub
  +#define      rpmbf_delprop   JS_PropertyStub
  +#define      rpmbf_convert   JS_ConvertStub
  +
  +static JSBool
  +rpmbf_add(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmbfClass, NULL);
  +    rpmbf bf = ptr;
  +    JSBool ok = JS_FALSE;
  +    const char * _s = NULL;
  +
  +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) rpmbfAdd(bf, _s);
  +    *rval = JSVAL_TRUE;              /* XXX return s? */
  +    ok = JS_TRUE;
  +exit:
  +    return ok;
  +}
  +
  +static JSBool
  +rpmbf_chk(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmbfClass, NULL);
  +    rpmbf bf = ptr;
  +    JSBool ok = JS_FALSE;
  +    const char * _s = NULL;
  +
  +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;
  +
  +    *rval = (rpmbfChk(bf, _s) ? JSVAL_TRUE : JSVAL_FALSE);
  +    ok = JS_TRUE;
  +exit:
  +    return ok;
  +}
  +
  +static JSBool
  +rpmbf_clr(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmbfClass, NULL);
  +    rpmbf bf = ptr;
  +    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);
  +
  +    *rval = (rpmbfClr(bf) ? JSVAL_TRUE : JSVAL_FALSE);
  +    ok = JS_TRUE;
  +exit:
  +    return ok;
  +}
  +
  +static JSBool
  +rpmbf_del(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmbfClass, NULL);
  +    rpmbf bf = ptr;
  +    JSBool ok = JS_FALSE;
  +    const char * _s = NULL;
  +
  +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;
  +
  +    *rval = (rpmbfDel(bf, _s) ? JSVAL_TRUE : JSVAL_FALSE);
  +    ok = JS_TRUE;
  +exit:
  +    return ok;
  +}
  +
  +static JSFunctionSpec rpmbf_funcs[] = {
  +    JS_FS("add",     rpmbf_add,              0,0,0),
  +    JS_FS("chk",     rpmbf_chk,              0,0,0),
  +    JS_FS("clr",     rpmbf_clr,              0,0,0),
  +    JS_FS("del",     rpmbf_del,              0,0,0),
  +    JS_FS_END
  +};
  +
  +/* --- Object properties */
  +enum rpmbf_tinyid {
  +    _DEBUG   = -2,
  +    _LENGTH  = -3,
  +};
  +
  +static JSPropertySpec rpmbf_props[] = {
  +    {"debug",        _DEBUG,         JSPROP_ENUMERATE,       NULL,   NULL},
  +    {NULL, 0, 0, NULL, NULL}
  +};
  +
  +static JSBool
  +rpmbf_getprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmbfClass, NULL);
  +    rpmbf bf = ptr;
  +    jsint tiny = JSVAL_TO_INT(id);
  +
  +_PROP_DEBUG_ENTRY(_debug < 0);
  +
  +    /* XXX the class has ptr == NULL, instances have ptr != NULL. */
  +    if (ptr == NULL)
  +     return JS_TRUE;
  +
  +    switch (tiny) {
  +    case _DEBUG:
  +     *vp = INT_TO_JSVAL(_debug);
  +     break;
  +    default:
  +#ifdef       NOTYET
  +        if (JSVAL_IS_STRING(id) && *vp == JSVAL_VOID) {
  +         const char * name = JS_GetStringBytes(JS_ValueToString(cx, id));
  +         const char * _path = rpmGetPath(_defvar, "/", name, NULL);
  +         const char * _value = NULL;
  +         if (rpmbfGet(bf, _path, &_value) >= 0 && _value != NULL)
  +             *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value));
  +         _path = _free(_path);
  +         _value = _free(_value);
  +            break;
  +        }
  +#endif
  +     break;
  +    }
  +
  +    return JS_TRUE;
  +}
  +
  +static JSBool
  +rpmbf_setprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmbfClass, NULL);
  +    rpmbf bf = ptr;
  +    jsint tiny = JSVAL_TO_INT(id);
  +
  +_PROP_DEBUG_ENTRY(_debug < 0);
  +
  +    /* XXX the class has ptr == NULL, instances have ptr != NULL. */
  +    if (ptr == NULL)
  +     return JS_TRUE;
  +
  +    switch (tiny) {
  +    case _DEBUG:
  +     if (!JS_ValueToInt32(cx, *vp, &_debug))
  +         break;
  +     break;
  +    default:
  +#ifdef       NOTYET
  +     /* XXX expr = undefined same as deleting? */
  +        if (JSVAL_IS_STRING(id)) {
  +            const char * name = JS_GetStringBytes(JS_ValueToString(cx, id));
  +            const char * expr = JS_GetStringBytes(JS_ValueToString(cx, *vp));
  +         /* XXX should *setprop be permitted to delete NAME?!? */
  +         /* XXX return is no. nodes in EXPR match. */
  +         (void) rpmbfDefvar(bf, name, expr);
  +            break;
  +        }
  +#endif
  +     break;
  +    }
  +
  +    return JS_TRUE;
  +}
  +
  +static JSBool
  +rpmbf_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
  +     JSObject **objp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmbfClass, NULL);
  +#ifdef       NOTYET
  +    rpmbf bf = ptr;
  +#endif
  +
  +_RESOLVE_DEBUG_ENTRY(_debug);
  +
  +    if (ptr == NULL) {       /* don't resolve to parent prototypes objects. 
*/
  +     *objp = NULL;
  +     goto exit;
  +    }
  +
  +#ifdef       NOTYET
  +    /* Lazily resolve new strings, with duplication to Augeas defvar too. */
  +    if ((flags & JSRESOLVE_ASSIGNING) && JSVAL_IS_STRING(id)) {
  +        const char *name = JS_GetStringBytes(JS_ValueToString(cx, id));
  +     const char * _path;
  +     const char * _value;
  +     int xx;
  +     JSFunctionSpec *fsp;
  +
  +     /* XXX avoid "bf.print" method namess duped into defvar space? */
  +     for (fsp = rpmbf_funcs; fsp->name != NULL; fsp++) {
  +         if (!strcmp(fsp->name, name)) {
  +             *objp = obj;    /* XXX always resolve in this object. */
  +             goto exit;
  +         }
  +     }
  +
  +     /* See if NAME exists in DEFVAR path. */
  +     _path = rpmGetPath(_defvar, "/", name, NULL);
  +     _value = NULL;
  +
  +     switch (rpmbfGet(bf, _path, &_value)) {
  +     /* XXX For now, force all defvar's to be single valued strings. */
  +     case -1:/* multiply defined */
  +     case 0: /* not found */
  +         /* Create an empty Augeas defvar for NAME */
  +         xx = rpmbfDefvar(bf, name, "");
  +         /*...@fallthrough@*/
  +     case 1: /* found */
  +         /* Reflect the Augeas defvar NAME into JS Aug properties. */
  +         if (JS_DefineProperty(cx, obj, name,
  +                     (_value != NULL
  +                         ? STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _value))
  +                         : JSVAL_VOID),
  +                        NULL, NULL, JSPROP_ENUMERATE))
  +             break;
  +         /*...@fallthrough@*/
  +     default:
  +assert(0);
  +         break;
  +     }
  +
  +     _path = _free(_path);
  +     _value = _free(_value);
  +    }
  +#endif
  +    *objp = obj;     /* XXX always resolve in this object. */
  +
  +exit:
  +    return JS_TRUE;
  +}
  +
  +static JSBool
  +rpmbf_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op,
  +               jsval *statep, jsid *idp)
  +{
  +
  +_ENUMERATE_DEBUG_ENTRY(_debug);
  +
  +    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;
  +    }
  +    return JS_TRUE;
  +}
  +
  +/* --- Object ctors/dtors */
  +static rpmbf
  +rpmbf_init(JSContext *cx, JSObject *obj, size_t _n, size_t _m, size_t _k,
  +             unsigned int _flags)
  +{
  +    rpmbf bf;
  +
  +    if ((bf = rpmbfNew(_n, _m, _k, _flags)) == NULL)
  +     return NULL;
  +    if (!JS_SetPrivate(cx, obj, bf)) {
  +     /* XXX error msg */
  +     (void) rpmbfFree(bf);
  +     return NULL;
  +    }
  +    return bf;
  +}
  +
  +static void
  +rpmbf_dtor(JSContext *cx, JSObject *obj)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmbfClass, NULL);
  +    rpmbf bf = ptr;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p) ptr %p\n", __FUNCTION__, cx, obj, ptr);
  +
  +    bf = rpmbfFree(bf);
  +}
  +
  +static JSBool
  +rpmbf_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval 
*rval)
  +{
  +    JSBool ok = JS_FALSE;
  +
  +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" 
: ""));
  +
  +#ifdef       NOTYET
  +    if (!(ok = JS_ConvertArguments(cx, argc, argv, "/ssu", &_root, 
&_loadpath, &_flags)))
  +     goto exit;
  +#endif
  +
  +    if (cx->fp->flags & JSFRAME_CONSTRUCTING) {
  +     size_t _n = 0;
  +     size_t _m = 0;
  +     size_t _k = 0;
  +     unsigned int _flags = 0;
  +     if (rpmbf_init(cx, obj, _n, _m, _k, _flags) == NULL)
  +         goto exit;
  +    } else {
  +     if ((obj = JS_NewObject(cx, &rpmbfClass, NULL, NULL)) == NULL)
  +         goto exit;
  +     *rval = OBJECT_TO_JSVAL(obj);
  +    }
  +    ok = JS_TRUE;
  +
  +exit:
  +    return ok;
  +}
  +
  +/* --- Class initialization */
  +JSClass rpmbfClass = {
  +    /* XXX class should be "Bloom" eventually, avoid name conflicts for now 
*/
  +    "Bf", JSCLASS_NEW_RESOLVE | JSCLASS_NEW_ENUMERATE | JSCLASS_HAS_PRIVATE,
  +    rpmbf_addprop,   rpmbf_delprop, rpmbf_getprop, rpmbf_setprop,
  +    (JSEnumerateOp)rpmbf_enumerate, (JSResolveOp)rpmbf_resolve,
  +    rpmbf_convert,   rpmbf_dtor,
  +    JSCLASS_NO_OPTIONAL_MEMBERS
  +};
  +
  +JSObject *
  +rpmjs_InitBfClass(JSContext *cx, JSObject* obj)
  +{
  +    JSObject * o;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p)\n", __FUNCTION__, cx, obj);
  +
  +    o = JS_InitClass(cx, obj, NULL, &rpmbfClass, rpmbf_ctor, 1,
  +             rpmbf_props, rpmbf_funcs, NULL, NULL);
  +assert(o != NULL);
  +    return o;
  +}
  +
  +JSObject *
  +rpmjs_NewBfObject(JSContext *cx, size_t _n, size_t _m, size_t _k,
  +             unsigned int _flags)
  +{
  +    JSObject *obj;
  +    rpmbf bf;
  +
  +    if ((obj = JS_NewObject(cx, &rpmbfClass, NULL, NULL)) == NULL) {
  +     /* XXX error msg */
  +     return NULL;
  +    }
  +    if ((bf = rpmbf_init(cx, obj, _n, _m, _k, _flags)) == NULL) {
  +     /* XXX error msg */
  +     return NULL;
  +    }
  +    return obj;
  +}
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmbf-js.h
  ============================================================================
  $ cvs diff -u -r0 -r1.1 rpmbf-js.h
  --- /dev/null 2009-06-26 20:11:01 +0200
  +++ rpmbf-js.h        2009-06-26 20:11:25 +0200
  @@ -0,0 +1,27 @@
  +#ifndef H_RPMBF_JS
  +#define H_RPMBF_JS
  +
  +/**
  + * \file js/rpmbf-js.h
  + */
  +
  +#include "rpm-js.h"
  +
  +extern JSClass rpmbfClass;
  +
  +#ifdef __cplusplus
  +extern "C" {
  +#endif
  +
  +extern JSObject *
  +rpmjs_InitBfClass(JSContext *cx, JSObject* obj);
  +
  +extern JSObject *
  +rpmjs_NewBfObject(JSContext *cx, size_t _n, size_t _m, size_t _k,
  +             unsigned int _flags);
  +
  +#ifdef __cplusplus      
  +}
  +#endif
  +
  +#endif       /* H_RPMBF_JS */
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/tjs.c
  ============================================================================
  $ cvs diff -u -r1.32 -r1.33 tjs.c
  --- rpm/js/tjs.c      12 Jun 2009 19:29:27 -0000      1.32
  +++ rpm/js/tjs.c      26 Jun 2009 18:11:25 -0000      1.33
  @@ -9,6 +9,7 @@
   #include <rpmjs.h>
   
   #include "rpmaug-js.h"
  +#include "rpmbf-js.h"
   #include "rpmds-js.h"
   #include "rpmfi-js.h"
   #include "rpmhdr-js.h"
  @@ -44,21 +45,22 @@
   
   /*...@unchecked@*/ /*...@observer@*/
   static struct rpmjsClassTable_s classTable[] = {
  -    { "Aug",         rpmjs_InitAugClass,      25 },
  -    { "Ds",          rpmjs_InitDsClass,       13 },
  -    { "Fi",          rpmjs_InitFiClass,       14 },
  -    { "File",                   js_InitFileClass,      1 },
  -    { "Hdr",         rpmjs_InitHdrClass,      12 },
  -    { "Mc",          rpmjs_InitMcClass,       24 },
  -    { "Mi",          rpmjs_InitMiClass,       11 },
  -    { "Ps",          rpmjs_InitPsClass,       16 },
  +    { "Aug",         rpmjs_InitAugClass,      -25 },
  +    { "Bf",          rpmjs_InitBfClass,       26 },
  +    { "Ds",          rpmjs_InitDsClass,       -13 },
  +    { "Fi",          rpmjs_InitFiClass,       -14 },
  +    { "File",                   js_InitFileClass,      -1 },
  +    { "Hdr",         rpmjs_InitHdrClass,      -12 },
  +    { "Mc",          rpmjs_InitMcClass,       -24 },
  +    { "Mi",          rpmjs_InitMiClass,       -11 },
  +    { "Ps",          rpmjs_InitPsClass,       -16 },
   #ifdef WITH_SYCK
       { "Syck",                rpmjs_InitSyckClass,     -3 },
   #endif
  -    { "Te",          rpmjs_InitTeClass,       15 },
  -    { "Ts",          rpmjs_InitTsClass,       10 },
  +    { "Te",          rpmjs_InitTeClass,       -15 },
  +    { "Ts",          rpmjs_InitTsClass,       -10 },
   #ifdef WITH_UUID
  -    { "Uuid",                rpmjs_InitUuidClass,      2 },
  +    { "Uuid",                rpmjs_InitUuidClass,      -2 },
   #endif
   };
   
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                [email protected]

Reply via email to