• porting old patch

    From Ragnarok@ragnarok@docksud.com.ar to DOVE-Net.Synchronet_Programming_C+ on Sat Oct 26 22:36:27 2013
    Hi all!

    i update sources from cvs today for make a new build of synchronet.

    i have patched to have little support for sqlite database as javascript
    object [1] and need to update the code.

    Compilation fails due to undefined reference to `JS_GetStringBytes'

    i think that need to replace this funcion with according to the new sources

    What should I use?

    [1] http://bbs.docksud.com.ar/~ragnarok/sync/js_sqlite/
  • From Ragnarok@ragnarok@docksud.com.ar to Ragnarok on Sun Oct 27 06:13:49 2013
    El 26/10/13 22:36, Ragnarok escribió:
    Hi all!

    i update sources from cvs today for make a new build of synchronet.

    i have patched to have little support for sqlite database as javascript object [1] and need to update the code.

    Compilation fails due to undefined reference to `JS_GetStringBytes'

    i think that need to replace this funcion with according to the new sources

    What should I use?

    [1] http://bbs.docksud.com.ar/~ragnarok/sync/js_sqlite/


    i try to set a string js property for my object
    i create a struct with the properties

    typedef struct
    {
    sqlite3* db; /* pointer to sqlite db */
    char name[MAX_PATH+1]; /* db filename */
    char* stmt; /* sql query */
    BOOL external; /* externally created, don't close */
    BOOL debug;
    char* errormsg; /* last error message */

    } private_t;


    and the setter part:


    static JSBool
    js_sqlite_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict,
    jsval *vp)
    {
    jsint tiny;
    private_t* p;
    char * str;
    jsval idval;
    jsrefcount rc; // js ref count
    JSString* js_str;

    if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
    JS_ReportError(cx,getprivate_failure,WHERE);
    return(JS_FALSE);
    }

    if(JSVAL_IS_STRING(*vp)) {
    if((js_str = JS_ValueToString(cx, *vp))==NULL)
    return(JS_FALSE);
    JSSTRING_TO_MSTRING(cx, js_str, str, NULL);
    HANDLE_PENDING(cx);
    }

    if(str==NULL)
    return(JS_FALSE);

    JS_IdToValue(cx, id, &idval);
    tiny = JSVAL_TO_INT(idval);

    rc=JS_SUSPENDREQUEST(cx);
    dbprintf(FALSE, p, "setting property %d", tiny);
    JS_RESUMEREQUEST(cx, rc);

    switch(tiny) {
    case SQLITE_PROP_STMT:
    SAFECOPY(p->stmt, str); <==== SEGFAULT
    break;
    case SQLITE_PROP_DEBUG:
    rc=JS_SUSPENDREQUEST(cx);
    JS_ValueToBoolean(cx, *vp, &p->debug);
    JS_RESUMEREQUEST(cx, rc);
    break;
    }
    return(JS_TRUE);
    }

    i have a segfault when try to put the value using SAFECOPY in p->stmt,

    In old sources i was used JS_GetStringBytes(), but is deprecated now.

    pd: sorry my bad english and my bad C code =)
  • From Ragnarok@ragnarok@docksud.com.ar to Ragnarok on Mon Oct 28 20:33:40 2013
    El 27/10/13 06:13, Ragnarok escribió:
    El 26/10/13 22:36, Ragnarok escribió:

    switch(tiny) {
    case SQLITE_PROP_STMT:
    SAFECOPY(p->stmt, str); <==== SEGFAULT

    I solved with this:

    stmt = JS_EncodeString(cx, JS_ValueToString(cx, *vp));
  • From Deuce@VERT to Ragnarok on Mon Oct 28 13:20:25 2013
    Re: porting old patch
    By: Ragnarok to DOVE-Net.Synchronet_Programming_C+ on Sat Oct 26 2013 10:36 pm

    Compilation fails due to undefined reference to `JS_GetStringBytes'
    i think that need to replace this funcion with according to the new sources What should I use?

    In sbbs.h, there are a number of macros defined...

    JS_STRING_TO_RASTRING()
    JSVALUE_TO_RASTRING()
    Uses realloc()... the result must be free()d.

    JSSTRING_TO_MSTRING()
    JSVALUE_TO_MSTRING()
    Uses malloc()... the result must be free()d.

    JSSTRING_TO_STRBUF()
    JSVALUE_TO_STRBUF()
    Copies into the specified buffer.

    JSSTRING_TO_ASTRING()
    JSVALUE_TO_ASTRING()
    Allocates the storage on the stack. Doesn't need to be free()d, but if you use
    "too much" of the stack, Synchronet will crash.

    ---
    http://DuckDuckGo.com/ a better search engine that respects your privacy.
    þ Synchronet þ My Brand-New BBS (All the cool SysOps run STOCK!)
  • From Ragnarok@ragnarok@docksud.com.ar to Deuce on Tue Oct 29 20:42:20 2013
    El 28/10/13 17:20, Deuce escribió:
    Re: porting old patch
    By: Ragnarok to DOVE-Net.Synchronet_Programming_C+ on Sat Oct 26 2013 10:36 pm

    Compilation fails due to undefined reference to `JS_GetStringBytes'
    i think that need to replace this funcion with according to the new sources
    What should I use?

    In sbbs.h, there are a number of macros defined...

    JS_STRING_TO_RASTRING()
    JSVALUE_TO_RASTRING()
    Uses realloc()... the result must be free()d.

    JSSTRING_TO_MSTRING()
    JSVALUE_TO_MSTRING()
    Uses malloc()... the result must be free()d.

    JSSTRING_TO_STRBUF()
    JSVALUE_TO_STRBUF()
    Copies into the specified buffer.

    JSSTRING_TO_ASTRING()
    JSVALUE_TO_ASTRING()
    Allocates the storage on the stack. Doesn't need to be free()d, but if you use
    "too much" of the stack, Synchronet will crash.

    ---
    http://DuckDuckGo.com/ a better search engine that respects your privacy.
    � Synchronet � My Brand-New BBS (All the cool SysOps run STOCK!)

    thanks you, i will test using this macros.