Mercurial > pymonkey
comparison utils.c @ 91:97d1faf02460
Got rid of Py_UNICODE_WIDE ifdefs.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sat, 15 Aug 2009 00:10:29 -0700 |
parents | 4b1149d818e8 |
children | 3beb55bedd92 |
comparison
equal
deleted
inserted
replaced
90:c41f1d2e8f9d | 91:97d1faf02460 |
---|---|
57 int | 57 int |
58 PYM_pyObjectToJsval(PYM_JSContextObject *context, | 58 PYM_pyObjectToJsval(PYM_JSContextObject *context, |
59 PyObject *object, | 59 PyObject *object, |
60 jsval *rval) | 60 jsval *rval) |
61 { | 61 { |
62 #ifndef Py_UNICODE_WIDE | |
63 if (PyUnicode_Check(object)) { | 62 if (PyUnicode_Check(object)) { |
64 Py_UNICODE *string = PyUnicode_AsUnicode(object); | 63 PyObject *string = PyUnicode_AsUTF16String(object); |
65 JSString *jsString = JS_NewUCStringCopyZ(context->cx, | 64 if (string == NULL) |
66 (const jschar *) string); | 65 return -1; |
66 | |
67 char *buffer = PyString_AS_STRING(string); | |
68 Py_ssize_t size = PyString_GET_SIZE(string); | |
69 | |
70 // Note that we're manipulating buffer and size here to get rid of | |
71 // the BOM. | |
72 JSString *jsString = JS_NewUCStringCopyN(context->cx, | |
73 (const jschar *) (buffer + 2), | |
74 (size / 2) - 1); | |
75 Py_DECREF(string); | |
67 if (jsString == NULL) { | 76 if (jsString == NULL) { |
68 PyErr_SetString(PYM_error, "JS_NewUCStringCopyZ() failed"); | 77 PyErr_SetString(PYM_error, "JS_NewUCStringCopyZ() failed"); |
69 return -1; | 78 return -1; |
70 } | 79 } |
71 | 80 |
72 *rval = STRING_TO_JSVAL(jsString); | 81 *rval = STRING_TO_JSVAL(jsString); |
73 return 0; | 82 return 0; |
74 } | 83 } |
75 #endif | |
76 | 84 |
77 if (PyInt_Check(object)) { | 85 if (PyInt_Check(object)) { |
78 long number = PyInt_AS_LONG(object); | 86 long number = PyInt_AS_LONG(object); |
79 if (INT_FITS_IN_JSVAL(number)) { | 87 if (INT_FITS_IN_JSVAL(number)) { |
80 *rval = INT_TO_JSVAL(number); | 88 *rval = INT_TO_JSVAL(number); |