Changeset 36

Show
Ignore:
Timestamp:
03/29/07 03:30:54 (22 months ago)
Author:
scott
Message:

Fixed SIGSEGV 1

  • Turns out that g_source_set_callback takes a different function spec, rather than having a void pointer as an argument it is intended to have a GIOChannel, condition, and then the void pointer. This actually makes a fair amount of sense, and sort of makes the API better. I do however wish that was correctly documented, as it doesn't seem to be mentioned in the glib documentation.

There are still more SIGSEGVs

closes #50

Note: All this code should be refactored, to provide private
objects to represent each of these items - as opposed to simply a wrapper
around each glib type. Reason being that I'm finding myself having to be far
too creative in finding places to store my data. Also the glib queue item(s)
should be refactored to use only a single source for creation, and keep their
own jsval array for argument lists, store the function being called and context
object locally. Factoring out the code that parses the arguments to the JS
wrapper functions wont actually be possible, but atleast we could make it
so the creation/allocation is handled in a uniform way.

This would make the dispatching also have less stuff to do.

    struct queue_item {
        int *esid;
        JSObject *args;
        uintN argc;
        JSContext *cx;
    };

would instead become

    struct queue_item {
        int         *esid;
        JSObject    *args;
        uintN       argc;
        JSContext   *cx;
        JSFunction  *callback;
        JSObject    *this;
    };
Location:
trunk/sagot/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/sagot/src/Makefile.am

    r35 r36  
    33                sagot_glib_iochannel.c sagot_glib_filechannel.c 
    44sagot_LDADD = $(DEPS_LIBS) 
    5 AM_CFLAGS = -std=c99 -pedantic -Wall -W -O2 $(DEPS_CFLAGS) 
     5AM_CFLAGS = -ggdb -std=c99 -pedantic -Wall -W -O2 $(DEPS_CFLAGS) 
  • trunk/sagot/src/sagot_glib_eventloop.c

    r35 r36  
    8080}; 
    8181 
     82gboolean sagot_eventloop_io_dispatch ( GIOChannel *source, GIOCondition 
     83        condition, void *data) { 
     84    return sagot_eventloop_dispatch(data); 
     85} 
     86 
    8287/** 
    8388 * Dispatch an event from glib to javascript 
    8489 */ 
    8590gboolean sagot_eventloop_dispatch (void *data) { 
     91    fprintf(stderr, "got %X\n", data); 
    8692    struct queue_item *qitem = (struct queue_item *) data; 
    8793    JSContext *cx = qitem->cx; 
    8894    uintN argc = qitem->argc; 
    8995    JSObject *arglist = qitem->args; 
    90     jsval argv[qitem->argc]; 
     96    jsval argv[argc]; 
    9197 
    9298    for (int i = 0; i < argc; i++) { 
     
    101107     * interfaces just because you're in spidermonkey unless you hack things up 
    102108     * a bit ;-) */ 
    103     JSObject *parent = NULL; 
     109    JSObject *parent; 
    104110     
    105111    if (JSVAL_IS_OBJECT(argv[0])) { 
     
    175181             * to...funky I know.  Later, we'll even store data using this id, then 
    176182             * fetch it when the event is invoked */ 
     183            fprintf(stderr, "put %X\n", qitem); 
    177184            g_idle_add_full(0, sagot_eventloop_dispatch, qitem, 
    178185                    sagot_eventloop_dispatch_cleanup); 
     
    240247        struct queue_item *qitem = g_malloc(sizeof *qitem); 
    241248 
     249        fprintf(stderr, "qitem alloced as %X\n", qitem); 
     250 
    242251        /* Now that we got what we wanted out of the argv...let's re-arrange it 
    243252         */ 
     
    255264            .cx   = cx, 
    256265        }; 
     266 
     267        fprintf(stderr, "qitem post initialization is %X\n", qitem); 
    257268 
    258269        /* Move the first two items over, creating an empty spot for the 
     
    264275        */ 
    265276         
     277        fprintf(stderr, "watch put %X\n", qitem); 
     278 
    266279        /* Set the callback for this source, storing session data */ 
    267         g_source_set_callback(source, sagot_eventloop_dispatch, qitem, 
    268                 sagot_eventloop_dispatch_cleanup); 
     280        g_source_set_callback(source, sagot_eventloop_io_dispatch, qitem, NULL); 
    269281 
    270282        /* Attach our event source to the context for the loop given to us */