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:   24-Apr-2009 15:32:35
  Branch: HEAD                             Handle: 2009042413323500

  Added files:
    rpm/js                  rpmte-js.c rpmte-js.h
  Modified files:
    rpm/js                  Makefile.am rpmds-js.c rpmfi-js.c tjs.c

  Log:
    - js: stub in a Te class for rpmte object.

  Summary:
    Revision    Changes     Path
    1.9         +2  -2      rpm/js/Makefile.am
    1.2         +1  -2      rpm/js/rpmds-js.c
    1.2         +1  -2      rpm/js/rpmfi-js.c
    1.1         +343 -0     rpm/js/rpmte-js.c
    1.1         +26 -0      rpm/js/rpmte-js.h
    1.9         +3  -0      rpm/js/tjs.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/js/Makefile.am
  ============================================================================
  $ cvs diff -u -r1.8 -r1.9 Makefile.am
  --- rpm/js/Makefile.am        24 Apr 2009 12:50:58 -0000      1.8
  +++ rpm/js/Makefile.am        24 Apr 2009 13:32:35 -0000      1.9
  @@ -58,12 +58,12 @@
   
   noinst_HEADERS = \
        rpmjsfile.h \
  -     rpmds-js.h rpmfi-js.h rpmhdr-js.h rpmmi-js.h rpmts-js.h \
  +     rpmds-js.h rpmfi-js.h rpmhdr-js.h rpmmi-js.h rpmte-js.h rpmts-js.h \
        uuid-js.h # syck-js.h
   
   rpmjsm_la_SOURCES = \
        rpmjsfile.c \
  -     rpmds-js.c rpmfi-js.c rpmhdr-js.c rpmmi-js.c rpmts-js.c \
  +     rpmds-js.c rpmfi-js.c rpmhdr-js.c rpmmi-js.c rpmte-js.c rpmts-js.c \
        uuid-js.c # syck-js.c
   
   .PHONY:      lint
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmds-js.c
  ============================================================================
  $ cvs diff -u -r1.1 -r1.2 rpmds-js.c
  --- rpm/js/rpmds-js.c 24 Apr 2009 12:50:58 -0000      1.1
  +++ rpm/js/rpmds-js.c 24 Apr 2009 13:32:35 -0000      1.2
  @@ -12,7 +12,6 @@
   
   #include <rpmdb.h>
   
  -#define      _RPMTS_INTERNAL
   #include <rpmds.h>
   
   #include "debug.h"
  @@ -266,7 +265,7 @@
   if (_debug)
   fprintf(stderr, "==> %s(%p,%p,%p[%u],%p)\n", __FUNCTION__, cx, obj, argv, 
(unsigned)argc, rval);
   
  -    if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/i", &hdro, tagN)))
  +    if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/i", &hdro, &tagN)))
        goto exit;
   
       if (cx->fp->flags & JSFRAME_CONSTRUCTING) {
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmfi-js.c
  ============================================================================
  $ cvs diff -u -r1.1 -r1.2 rpmfi-js.c
  --- rpm/js/rpmfi-js.c 24 Apr 2009 12:50:59 -0000      1.1
  +++ rpm/js/rpmfi-js.c 24 Apr 2009 13:32:35 -0000      1.2
  @@ -12,7 +12,6 @@
   
   #include <rpmdb.h>
   
  -#define      _RPMTS_INTERNAL
   #include <rpmfi.h>
   
   #include "debug.h"
  @@ -267,7 +266,7 @@
   if (_debug)
   fprintf(stderr, "==> %s(%p,%p,%p[%u],%p)\n", __FUNCTION__, cx, obj, argv, 
(unsigned)argc, rval);
   
  -    if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/i", &hdro, tagN)))
  +    if (!(ok = JS_ConvertArguments(cx, argc, argv, "o/i", &hdro, &tagN)))
        goto exit;
   
       if (cx->fp->flags & JSFRAME_CONSTRUCTING) {
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmte-js.c
  ============================================================================
  $ cvs diff -u -r0 -r1.1 rpmte-js.c
  --- /dev/null 2009-04-24 15:32:06 +0200
  +++ rpmte-js.c        2009-04-24 15:32:35 +0200
  @@ -0,0 +1,343 @@
  +/** \ingroup js_c
  + * \file js/rpmte-js.c
  + */
  +
  +#include "system.h"
  +
  +#include "rpmts-js.h"
  +#include "rpmte-js.h"
  +#include "rpmhdr-js.h"
  +
  +#include <argv.h>
  +#include <mire.h>
  +
  +#include <rpmdb.h>
  +
  +#include <rpmal.h>
  +#include <rpmts.h>
  +#define      _RPMTE_INTERNAL         /* XXX for rpmteNew/rpmteFree */
  +#include <rpmte.h>
  +
  +#include "debug.h"
  +
  +/*...@unchecked@*/
  +extern int _rpmjs_debug;
  +
  +/*...@unchecked@*/
  +static int _debug = 1;
  +
  +/* --- Object methods */
  +
  +static JSFunctionSpec rpmte_funcs[] = {
  +    JS_FS_END
  +};
  +
  +/* --- Object properties */
  +enum rpmte_tinyid {
  +    _DEBUG   = -2,
  +};
  +
  +static JSPropertySpec rpmte_props[] = {
  +    {"debug",        _DEBUG,         JSPROP_ENUMERATE,       NULL,   NULL},
  +    {NULL, 0, 0, NULL, NULL}
  +};
  +
  +static JSBool
  +rpmte_addprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmteClass, NULL);
  +
  +if (_debug < 0)
  +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, 
cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, 
JS_GetStringBytes(JS_ValueToString(cx, id)), 
JS_GetStringBytes(JS_ValueToString(cx, *vp)));
  +
  +    return JS_TRUE;
  +}
  +
  +static JSBool
  +rpmte_delprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmteClass, NULL);
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, 
cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, 
JS_GetStringBytes(JS_ValueToString(cx, id)), 
JS_GetStringBytes(JS_ValueToString(cx, *vp)));
  +
  +    return JS_TRUE;
  +}
  +static JSBool
  +rpmte_getprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmteClass, NULL);
  +    rpmte te = ptr;
  +    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) {
  +if (_debug) {
  +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, 
cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, 
JS_GetStringBytes(JS_ValueToString(cx, id)), 
JS_GetStringBytes(JS_ValueToString(cx, *vp)));
  +ok = JS_TRUE;                /* XXX return JS_TRUE iff ... ? */
  +}
  +    }
  +    return ok;
  +}
  +
  +static JSBool
  +rpmte_setprop(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmteClass, NULL);
  +    rpmte te = (rpmte)ptr;
  +    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) {
  +if (_debug) {
  +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],%p) ptr %p %s = %s\n", __FUNCTION__, 
cx, obj, (unsigned long)id, (unsigned)JSVAL_TAG(id), vp, ptr, 
JS_GetStringBytes(JS_ValueToString(cx, id)), 
JS_GetStringBytes(JS_ValueToString(cx, *vp)));
  +ok = JS_TRUE;                /* XXX return JS_TRUE iff ... ? */
  +}
  +    }
  +    return ok;
  +}
  +
  +static JSBool
  +rpmte_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
  +     JSObject **objp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmteClass, NULL);
  +    static char hex[] = "0123456789abcdef";
  +    JSString *idstr;
  +    const char * name;
  +    JSString * valstr;
  +    char value[5];
  +    JSBool ok = JS_FALSE;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,0x%lx[%u],0x%x,%p) ptr %p property %s flags 
0x%x{%s,%s,%s,%s,%s}\n", __FUNCTION__, cx, obj, (unsigned long)id, 
(unsigned)JSVAL_TAG(id), (unsigned)flags, objp, ptr,
  +             JS_GetStringBytes(JS_ValueToString(cx, id)), flags,
  +             (flags & JSRESOLVE_QUALIFIED) ? "qualified" : "",
  +             (flags & JSRESOLVE_ASSIGNING) ? "assigning" : "",
  +             (flags & JSRESOLVE_DETECTING) ? "detecting" : "",
  +             (flags & JSRESOLVE_DETECTING) ? "declaring" : "",
  +             (flags & JSRESOLVE_DETECTING) ? "classname" : "");
  +
  +    if (flags & JSRESOLVE_ASSIGNING) {
  +     ok = JS_TRUE;
  +     goto exit;
  +    }
  +
  +    if ((idstr = JS_ValueToString(cx, id)) == NULL)
  +     goto exit;
  +
  +    name = JS_GetStringBytes(idstr);
  +    if (name[1] == '\0' && xisalpha(name[0])) {
  +     value[0] = '0'; value[1] = 'x';
  +     value[2] = hex[(name[0] >> 4) & 0xf];
  +     value[3] = hex[(name[0]     ) & 0xf];
  +     value[4] = '\0';
  +     if ((valstr = JS_NewStringCopyZ(cx, value)) == NULL
  +      || !JS_DefineProperty(cx, obj, name, STRING_TO_JSVAL(valstr),
  +                             NULL, NULL, JSPROP_ENUMERATE))
  +         goto exit;
  +     *objp = obj;
  +    }
  +    ok = JS_TRUE;
  +exit:
  +    return ok;
  +}
  +
  +static JSBool
  +rpmte_enumerate(JSContext *cx, JSObject *obj, JSIterateOp op,
  +               jsval *statep, jsid *idp)
  +{
  +    JSObject *iterator;
  +    JSBool ok = JS_FALSE;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,%d,%p,%p)\n", __FUNCTION__, cx, obj, op, 
statep, idp);
  +
  +#ifdef       DYING
  +    switch (op) {
  +    case JSENUMERATE_INIT:
  +     if ((iterator = JS_NewPropertyIterator(cx, obj)) == NULL)
  +         goto exit;
  +     *statep = OBJECT_TO_JSVAL(iterator);
  +     if (idp)
  +         *idp = JSVAL_ZERO;
  +     break;
  +    case JSENUMERATE_NEXT:
  +     iterator = (JSObject *) JSVAL_TO_OBJECT(*statep);
  +     if (!JS_NextProperty(cx, iterator, idp))
  +         goto exit;
  +     if (*idp != JSVAL_VOID)
  +         break;
  +     /*...@fallthrough@*/
  +    case JSENUMERATE_DESTROY:
  +     /* Allow our iterator object to be GC'd. */
  +     *statep = JSVAL_NULL;
  +     break;
  +    }
  +#else
  +    {        static const char hex[] = "0123456789abcdef";
  +     const char * s;
  +     char name[2];
  +     JSString * valstr;
  +     char value[5];
  +     for (s = "AaBbCc"; *s != '\0'; s++) {
  +         name[0] = s[0]; name[1] = '\0';
  +         value[0] = '0'; value[1] = 'x';
  +         value[2] = hex[(name[0] >> 4) & 0xf];
  +         value[3] = hex[(name[0]     ) & 0xf];
  +         value[4] = '\0';
  +         if ((valstr = JS_NewStringCopyZ(cx, value)) == NULL
  +          || !JS_DefineProperty(cx, obj, name, STRING_TO_JSVAL(valstr),
  +                             NULL, NULL, JSPROP_ENUMERATE))
  +             goto exit;
  +     }
  +    }
  +#endif
  +    ok = JS_TRUE;
  +exit:
  +    return ok;
  +}
  +
  +static JSBool
  +rpmte_convert(JSContext *cx, JSObject *obj, JSType type, jsval *vp)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmteClass, NULL);
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,%d,%p) ptr %p convert to %s\n", __FUNCTION__, 
cx, obj, type, vp, ptr, JS_GetTypeName(cx, type));
  +    return JS_TRUE;
  +}
  +
  +/* --- Object ctors/dtors */
  +static rpmte
  +rpmte_init(JSContext *cx, JSObject *obj, rpmts ts, Header h)
  +{
  +    rpmte te;
  +    rpmElementType etype = TR_ADDED;
  +    fnpyKey key = NULL;
  +    rpmRelocation relocs = NULL;
  +    int dboffset = 0;
  +    alKey pkgKey = NULL;
  +
  +    if ((te = rpmteNew(ts, h, etype, key, relocs, dboffset, pkgKey)) == NULL)
  +     return NULL;
  +    if (!JS_SetPrivate(cx, obj, (void *)te)) {
  +     /* XXX error msg */
  +     (void) rpmteFree(te);
  +     return NULL;
  +    }
  +    return te;
  +}
  +
  +static void
  +rpmte_dtor(JSContext *cx, JSObject *obj)
  +{
  +    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmteClass, NULL);
  +    rpmte te = ptr;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p) ptr %p\n", __FUNCTION__, cx, obj, ptr);
  +
  +#ifdef       BUGGY
  +    (void) rpmteFree(te);
  +#endif
  +}
  +
  +static JSBool
  +rpmte_ctor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval 
*rval)
  +{
  +    JSBool ok = JS_FALSE;
  +    JSObject *tso = NULL;
  +    JSObject *hdro = NULL;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p,%p[%u],%p)\n", __FUNCTION__, cx, obj, argv, 
(unsigned)argc, rval);
  +
  +    if (!(ok = JS_ConvertArguments(cx, argc, argv, "oo", &tso, &hdro)))
  +     goto exit;
  +
  +    if (cx->fp->flags & JSFRAME_CONSTRUCTING) {
  +     rpmts ts = JS_GetInstancePrivate(cx, tso, &rpmtsClass, NULL);
  +     Header h = JS_GetInstancePrivate(cx, hdro, &rpmhdrClass, NULL);
  +     if (rpmte_init(cx, obj, ts, h) == NULL)
  +         goto exit;
  +    } else {
  +     if ((obj = JS_NewObject(cx, &rpmteClass, NULL, NULL)) == NULL)
  +         goto exit;
  +     *rval = OBJECT_TO_JSVAL(obj);
  +    }
  +    ok = JS_TRUE;
  +
  +exit:
  +    return ok;
  +}
  +
  +/* --- Class initialization */
  +#ifdef       HACKERY
  +JSClass rpmteClass = {
  +    "Te", JSCLASS_NEW_RESOLVE | JSCLASS_NEW_ENUMERATE | JSCLASS_HAS_PRIVATE 
| JSCLASS_HAS_CACHED_PROTO(JSProto_Object),
  +    rpmte_addprop,   rpmte_delprop, rpmte_getprop, rpmte_setprop,
  +    (JSEnumerateOp)rpmte_enumerate, (JSResolveOp)rpmte_resolve,
  +    rpmte_convert,   rpmte_dtor,
  +    JSCLASS_NO_OPTIONAL_MEMBERS
  +};
  +#else
  +JSClass rpmteClass = {
  +    "Te", JSCLASS_NEW_RESOLVE | JSCLASS_HAS_PRIVATE,
  +    JS_PropertyStub,   JS_PropertyStub, rpmte_getprop, JS_PropertyStub,
  +    (JSEnumerateOp)rpmte_enumerate, (JSResolveOp)rpmte_resolve,
  +    JS_ConvertStub,  rpmte_dtor,
  +    JSCLASS_NO_OPTIONAL_MEMBERS
  +};
  +#endif
  +
  +JSObject *
  +rpmjs_InitTeClass(JSContext *cx, JSObject* obj)
  +{
  +    JSObject * o;
  +
  +if (_debug)
  +fprintf(stderr, "==> %s(%p,%p)\n", __FUNCTION__, cx, obj);
  +
  +    o = JS_InitClass(cx, obj, NULL, &rpmteClass, rpmte_ctor, 1,
  +             rpmte_props, rpmte_funcs, NULL, NULL);
  +assert(o != NULL);
  +    return o;
  +}
  +
  +JSObject *
  +rpmjs_NewTeObject(JSContext *cx, void * _ts, void * _h)
  +{
  +    JSObject *obj;
  +    rpmte te;
  +
  +    if ((obj = JS_NewObject(cx, &rpmteClass, NULL, NULL)) == NULL) {
  +     /* XXX error msg */
  +     return NULL;
  +    }
  +    if ((te = rpmte_init(cx, obj, _ts, _h)) == NULL) {
  +     /* XXX error msg */
  +     return NULL;
  +    }
  +    return obj;
  +}
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/rpmte-js.h
  ============================================================================
  $ cvs diff -u -r0 -r1.1 rpmte-js.h
  --- /dev/null 2009-04-24 15:32:06 +0200
  +++ rpmte-js.h        2009-04-24 15:32:35 +0200
  @@ -0,0 +1,26 @@
  +#ifndef H_RPMTE_JS
  +#define H_RPMTE_JS
  +
  +/**
  + * \file js/rpmte-js.h
  + */
  +
  +#include "rpm-js.h"
  +
  +extern JSClass rpmteClass;
  +
  +#ifdef __cplusplus
  +extern "C" {
  +#endif
  +
  +extern JSObject *
  +rpmjs_InitTeClass(JSContext *cx, JSObject* obj);
  +
  +extern JSObject *
  +rpmjs_NewTeObject(JSContext *cx, void * _ts, void * _h);
  +
  +#ifdef __cplusplus      
  +}
  +#endif
  +
  +#endif       /* H_RPMDS_JS */
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/js/tjs.c
  ============================================================================
  $ cvs diff -u -r1.8 -r1.9 tjs.c
  --- rpm/js/tjs.c      24 Apr 2009 12:50:59 -0000      1.8
  +++ rpm/js/tjs.c      24 Apr 2009 13:32:35 -0000      1.9
  @@ -8,6 +8,7 @@
   
   #include "rpmds-js.h"
   #include "rpmfi-js.h"
  +#include "rpmte-js.h"
   #include "rpmts-js.h"
   #include "rpmmi-js.h"
   #include "rpmhdr-js.h"
  @@ -61,6 +62,8 @@
        (void) rpmjsRun(NULL, "print(\"\tMi\");", &result);
        (void) rpmjs_InitTsClass(js->cx, js->glob);
        (void) rpmjsRun(NULL, "print(\"\tTs\");", &result);
  +     (void) rpmjs_InitTeClass(js->cx, js->glob);
  +     (void) rpmjsRun(NULL, "print(\"\tTe\");", &result);
        (void) rpmjs_InitDsClass(js->cx, js->glob);
        (void) rpmjsRun(NULL, "print(\"\tDs\");", &result);
        (void) rpmjs_InitFiClass(js->cx, js->glob);
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org

Reply via email to