Changed strategy to root the File object set for PGConn.trace()
authorMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 4 Oct 2006 01:54:33 +0000 (01:54 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 4 Oct 2006 01:54:33 +0000 (01:54 +0000)
mmsoftware/js/classes/js_pgsql.c

index efd09fb..cab014e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: js_pgsql.c,v 1.5 2006/10/04 00:56:25 mmondor Exp $ */
+/* $Id: js_pgsql.c,v 1.6 2006/10/04 01:54:33 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -283,13 +283,6 @@ static int *param_lengths = NULL;
 static int     *param_formats = NULL;
 static int     param_entries = 0;
 
-/*
- * This object is crated by js_InitPGClass() and rooted, so that we may easily
- * root objects by adding them as properties into it.  To be thread-safe, a
- * critical section or mutex would be needed when accessing this object.
- */
-static JSObject        *root_object = NULL;
-
 
 /* PG class */
 static JSClass pg_class = {
@@ -604,16 +597,6 @@ js_InitPGClass(JSContext *cx, JSObject *obj)
        }
        param_entries = 16;
 
-       /* Create our rooted object */
-       if ((root_object = JS_NewObject(cx, NULL, NULL, NULL)) == NULL) {
-               (void) fprintf(stderr, "PG: JS_NewObject(root_object)\n");
-               goto err;
-       }
-       if (!JS_AddRoot(cx, &root_object)) { /* Pointer to pointer */
-               (void) fprintf(stderr, "PG: JS_AddRoot(root_object)\n");
-               goto err;
-       }
-
        return proto;
 
 err:
@@ -642,13 +625,12 @@ pg_constructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
        return JS_FALSE;
 }
 
+/* ARGSUSED */
 static void
 pg_finalize(JSContext *cx, JSObject *obj)
 {
 
-       /* XXX This never gets called since PG is uninstanciable. */
-       if (root_object != NULL)
-               (void) JS_RemoveRoot(cx, &root_object); /* Ptr to ptr */
+       /* NOOP */
 }
 
 
@@ -2625,6 +2607,7 @@ pgconn_m_PQtrace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
 {
        PGconn          *pgc;
        FILE            *fh;
+       JSObject        *ro;
 
        *rval = OBJECT_TO_JSVAL(NULL);
 
@@ -2644,8 +2627,9 @@ pgconn_m_PQtrace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
         * Unroot previously rooted File object, if any, then root newly
         * provided File object.
         */
-       (void) JS_DeleteProperty(cx, root_object, "trace");
-       if (!JS_DefineProperty(cx, root_object, "trace", argv[0],
+       ro = JSVAL_TO_OBJECT(argv[-1]);
+       (void) JS_DeleteProperty(cx, ro, "trace_file_root");
+       if (!JS_DefineProperty(cx, ro, "trace_file_root", argv[0],
            NULL, NULL, 0)) {
                QUEUE_EXCEPTION("Internal error!");
                return JS_FALSE;
@@ -2664,6 +2648,7 @@ pgconn_m_PQuntrace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
     jsval *rval)
 {
        PGconn          *pgc;
+       JSObject        *ro;
 
        *rval = OBJECT_TO_JSVAL(NULL);
 
@@ -2678,7 +2663,8 @@ pgconn_m_PQuntrace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
        /*
         * Unroot previously rooted File object
         */
-       (void) JS_DeleteProperty(cx, root_object, "trace");
+       ro = JSVAL_TO_OBJECT(argv[-1]);
+       (void) JS_DeleteProperty(cx, ro, "trace_file_root");
 
        PQuntrace(pgc);