diff utils.c @ 33:3f8a2db496f5

Changed PYM_pyObjectToJsval() to simply return an int status/error code; this way callers don't have to worry about decreasing the reference count of a Py_NONE.
author Atul Varma <varmaa@toolness.com>
date Tue, 30 Jun 2009 22:42:48 -0700
parents abf14cba9ef5
children 5d3d3b25f23f
line wrap: on
line diff
--- a/utils.c	Tue Jun 30 22:37:00 2009 -0700
+++ b/utils.c	Tue Jun 30 22:42:48 2009 -0700
@@ -4,7 +4,7 @@
 
 PyObject *PYM_error;
 
-static PyObject *
+static int
 PYM_doubleToJsval(JSContext *cx,
                   double number,
                   jsval *rval)
@@ -12,13 +12,13 @@
   jsdouble *numberAsJsdouble = JS_NewDouble(cx, number);
   if (numberAsJsdouble == NULL) {
     PyErr_SetString(PYM_error, "JS_NewDouble() failed");
-    return NULL;
+    return -1;
   }
   *rval = DOUBLE_TO_JSVAL(numberAsJsdouble);
-  Py_RETURN_NONE;
+  return 0;
 }
 
-PyObject *
+int
 PYM_pyObjectToJsval(JSContext *cx,
                     PyObject *object,
                     jsval *rval)
@@ -30,11 +30,11 @@
                                              (const jschar *) string);
     if (jsString == NULL) {
       PyErr_SetString(PYM_error, "JS_NewUCStringCopyZ() failed");
-      return NULL;
+      return -1;
     }
 
     *rval = STRING_TO_JSVAL(jsString);
-    Py_RETURN_NONE;
+    return 0;
   }
 #endif
 
@@ -42,7 +42,7 @@
     long number = PyInt_AS_LONG(object);
     if (INT_FITS_IN_JSVAL(number)) {
       *rval = INT_TO_JSVAL(number);
-      Py_RETURN_NONE;
+      return 0;
     } else
       return PYM_doubleToJsval(cx, number, rval);
   }
@@ -53,7 +53,7 @@
   // TODO: Support more types.
   PyErr_SetString(PyExc_NotImplementedError,
                   "Data type conversion not implemented.");
-  return NULL;
+  return -1;
 }
 
 PyObject *