diff utils.c @ 95:0701aee1b0cd

JS-wrapped python functions can now return normal strings (not just unicode).
author Atul Varma <varmaa@toolness.com>
date Sat, 15 Aug 2009 00:50:55 -0700
parents 3beb55bedd92
children
line wrap: on
line diff
--- a/utils.c	Sat Aug 15 00:25:48 2009 -0700
+++ b/utils.c	Sat Aug 15 00:50:55 2009 -0700
@@ -59,8 +59,19 @@
                     PyObject *object,
                     jsval *rval)
 {
-  if (PyUnicode_Check(object)) {
-    PyObject *string = PyUnicode_AsUTF16String(object);
+  if (PyString_Check(object) || PyUnicode_Check(object)) {
+    PyObject *unicode;
+    if (PyString_Check(object)) {
+      unicode = PyUnicode_FromObject(object);
+      if (unicode == NULL)
+        return -1;
+    } else {
+      unicode = object;
+      Py_INCREF(unicode);
+    }
+
+    PyObject *string = PyUnicode_AsUTF16String(unicode);
+    Py_DECREF(unicode);
     if (string == NULL)
       return -1;