Index: src/PyIVariant.cpp =================================================================== RCS file: /cvsroot/mozilla/extensions/python/xpcom/src/PyIVariant.cpp,v retrieving revision 1.4 diff -u -r1.4 PyIVariant.cpp --- src/PyIVariant.cpp 18 Apr 2004 22:13:54 -0000 1.4 +++ src/PyIVariant.cpp 4 Feb 2005 05:42:38 -0000 @@ -64,10 +64,10 @@ return PyString_FromStringAndSize(&c, 1); } static PyObject *MyUChar( PRUnichar c) { - return PyUnicodeUCS2_FromUnicode(&c, 1); + return PyUnicode_FromPRUnichar(&c, 1); } static PyObject *MyUnicode( PRUnichar *p) { - return PyUnicodeUCS2_FromUnicode(p, nsCRT::strlen(p)); + return PyUnicode_FromPRUnichar(p, nsCRT::strlen(p)); } static PyObject *MyISupports( nsISupports *p) { return Py_nsISupports::PyObjectFromInterface(p, NS_GET_IID(nsISupports), PR_FALSE); @@ -129,7 +129,7 @@ GET_ALLOCATED(char *, GetAsString, PyString_FromString, nsMemory::Free); GET_ALLOCATED(PRUnichar *, GetAsWString, MyUnicode, nsMemory::Free); GET_ALLOCATED_SIZE(char *, GetAsStringWithSize, PyString_FromStringAndSize, nsMemory::Free); -GET_ALLOCATED_SIZE(PRUnichar *, GetAsWStringWithSize, PyUnicodeUCS2_FromUnicode, nsMemory::Free); +GET_ALLOCATED_SIZE(PRUnichar *, GetAsWStringWithSize, PyUnicode_FromPRUnichar, nsMemory::Free); static PyObject *GetAsInterface(PyObject *self, PyObject *args) { nsIVariant *pI = GetI(self); Index: src/PyXPCOM.h =================================================================== RCS file: /cvsroot/mozilla/extensions/python/xpcom/src/PyXPCOM.h,v retrieving revision 1.11 diff -u -r1.11 PyXPCOM.h --- src/PyXPCOM.h 18 Apr 2004 22:13:54 -0000 1.11 +++ src/PyXPCOM.h 4 Feb 2005 05:42:38 -0000 @@ -117,6 +117,10 @@ #define PYXPCOM_LOG_DEBUG() #endif // DEBUG +// Create a Unicode Object from the PRUnichar buffer src of the given size +#define PyUnicode_FromPRUnichar(src, size) \ + PyUnicode_DecodeUTF16((char*)(src),sizeof(PRUnichar)*(size),NULL,NULL) + /************************************************************************* ************************************************************************** Index: src/PyXPCOM_std.h =================================================================== RCS file: /cvsroot/mozilla/extensions/python/xpcom/src/PyXPCOM_std.h,v retrieving revision 1.7 diff -u -r1.7 PyXPCOM_std.h --- src/PyXPCOM_std.h 18 Apr 2004 22:13:54 -0000 1.7 +++ src/PyXPCOM_std.h 4 Feb 2005 05:42:38 -0000 @@ -49,6 +49,14 @@ // // (c) 2000, ActiveState corp. +#include + +#ifdef HAVE_LONG_LONG + // Mozilla also defines this - we undefine it to + // prevent a compiler warning. +# undef HAVE_LONG_LONG +#endif // HAVE_LONG_LONG + #include "nsIAllocator.h" #include "nsIWeakReference.h" #include "nsIInterfaceInfoManager.h" @@ -68,11 +76,4 @@ // we can use it to trigger "exports" #define BUILD_PYXPCOM -#ifdef HAVE_LONG_LONG - // Mozilla also defines this - we undefine it to - // prevent a compiler warning. -# undef HAVE_LONG_LONG -#endif // HAVE_LONG_LONG - -#include "Python.h" #include "PyXPCOM.h" Index: src/Pyxpt_info.cpp =================================================================== RCS file: /cvsroot/mozilla/extensions/python/xpcom/src/Pyxpt_info.cpp,v retrieving revision 1.6 diff -u -r1.6 Pyxpt_info.cpp --- src/Pyxpt_info.cpp 18 Apr 2004 22:13:54 -0000 1.6 +++ src/Pyxpt_info.cpp 4 Feb 2005 05:42:38 -0000 @@ -152,7 +152,7 @@ v = PyString_FromStringAndSize(&c->value.ch, 1); break; case TD_WCHAR: - v = PyUnicode_FromUnicode((PRUnichar *)&c->value.wch, 1); + v = PyUnicode_FromPRUnichar((PRUnichar *)&c->value.wch, 1); break; // TD_VOID = 13, case TD_PNSIID: @@ -163,7 +163,7 @@ v = PyString_FromString(c->value.str); break; case TD_PWSTRING: - v = PyUnicode_FromUnicode((PRUnichar *)c->value.wstr, nsCRT::strlen((PRUnichar *)c->value.wstr)); + v = PyUnicode_FromPRUnichar((PRUnichar *)c->value.wstr, nsCRT::strlen((PRUnichar *)c->value.wstr)); break; // TD_INTERFACE_TYPE = 18, // TD_INTERFACE_IS_TYPE = 19, Index: src/VariantUtils.cpp =================================================================== RCS file: /cvsroot/mozilla/extensions/python/xpcom/src/VariantUtils.cpp,v retrieving revision 1.18 diff -u -r1.18 VariantUtils.cpp --- src/VariantUtils.cpp 21 Jul 2004 11:42:46 -0000 1.18 +++ src/VariantUtils.cpp 4 Feb 2005 05:42:39 -0000 @@ -21,6 +21,9 @@ * Contributor(s): * Mark Hammond (original author) * + * Unicode corrections by Shane Hathaway (http://hathawaymix.org), + * inspired by Mikhail Sobolev + * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), @@ -69,6 +72,38 @@ return PR_FALSE; } +// Create a zero-terminated PRUnichar buffer from a Python unicode. +// On success, returns 0. On failure, returns -1 and sets an exception. +// dest_out must not be null. size_out may be null. +static int +PyUnicode_AsPRUnichar(PyObject *obj, PRUnichar **dest_out, PRUint32 *size_out) +{ + PRUint32 size; + PyObject *s; + PRUnichar *dest; + + s = PyUnicode_AsUTF16String(obj); + if (!s) + return -1; + size = (PyString_GET_SIZE(s) - 2) / sizeof(PRUnichar); + dest = (PRUnichar *)nsMemory::Alloc(sizeof(PRUnichar) * (size + 1)); + if (!dest) { + PyErr_NoMemory(); + Py_DECREF(s); + return -1; + } + // Drop the UTF-16 byte order mark at the beginning of + // the string. (See the docs on PyUnicode_AsUTF16String.) + // Some Mozilla libraries don't like the mark. + memcpy(dest, PyString_AS_STRING(s) + 2, sizeof(PRUnichar) * size); + Py_DECREF(s); + dest[size] = 0; + *dest_out = dest; + if (size_out) + *size_out = size; + return 0; +} + PyObject *PyObject_FromNSString( const nsACString &s, PRBool bAssumeUTF8 = PR_FALSE ) { PyObject *ret; @@ -78,10 +113,16 @@ } else { if (bAssumeUTF8) { char *temp = ToNewCString(s); + if (!temp) { + PyErr_NoMemory(); + return NULL; + } ret = PyUnicode_DecodeUTF8(temp, s.Length(), NULL); nsMemory::Free(temp); } else { ret = PyString_FromStringAndSize(NULL, s.Length()); + if (!ret) + return NULL; // Need "CopyAsciiTo"!? nsACString::const_iterator fromBegin, fromEnd; char* dest = PyString_AS_STRING(ret); @@ -98,8 +139,13 @@ ret = Py_None; Py_INCREF(Py_None); } else { - ret = PyUnicodeUCS2_FromUnicode( NULL, s.Length() ); - CopyUnicodeTo(s, 0, PyUnicodeUCS2_AsUnicode(ret), s.Length()); + PRUnichar *tmp = ToNewUnicode(s); + if (!tmp) { + PyErr_NoMemory(); + return NULL; + } + ret = PyUnicode_FromPRUnichar(tmp, s.Length()); + nsMemory::Free(tmp); } return ret; } @@ -303,9 +349,10 @@ PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); BREAK_FALSE; } - if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL) + if ((val_use = PyUnicode_FromObject(val)) == NULL) BREAK_FALSE; - NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a Unicode object!"); + NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!"); + // Lossy! FILL_SIMPLE_POINTER( PRUnichar, *PyUnicode_AS_UNICODE(val_use) ); break; @@ -369,18 +416,11 @@ PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); BREAK_FALSE; } - if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL) + if ((val_use = PyUnicode_FromObject(val))==NULL) BREAK_FALSE; - NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a Unicode object!"); - const PRUnichar *sz = PyUnicode_AS_UNICODE(val_use); - int nch = PyUnicode_GET_SIZE(val_use); - - *pp = (PRUnichar *)nsMemory::Alloc(sizeof(PRUnichar) * (nch+1)); - if (*pp==NULL) { - PyErr_NoMemory(); + NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!"); + if (PyUnicode_AsPRUnichar(val_use, pp, NULL) < 0) BREAK_FALSE; - } - memcpy(*pp, sz, sizeof(PRUnichar) * (nch + 1)); break; } case nsXPTType::T_INTERFACE_IS: // hmm - ignoring the IID can't be good :( @@ -476,8 +516,9 @@ if (*pp==NULL) { Py_INCREF(Py_None); val = Py_None; - } else - val = PyUnicodeUCS2_FromUnicode( *pp, nsCRT::strlen(*pp) ); + } else { + val = PyUnicode_FromPRUnichar( *pp, nsCRT::strlen(*pp) ); + } break; } case nsXPTType::T_INTERFACE_IS: @@ -532,8 +573,12 @@ return nsIDataType::VTYPE_STRING_SIZE_IS; if (PyUnicode_Check(ob)) return nsIDataType::VTYPE_WSTRING_SIZE_IS; - if (PyTuple_Check(ob) || PyList_Check(ob)) - return PySequence_Length(ob) ? nsIDataType::VTYPE_ARRAY : nsIDataType::VTYPE_EMPTY_ARRAY; + if (PyTuple_Check(ob) || PyList_Check(ob)) { + if (PySequence_Length(ob)) + return nsIDataType::VTYPE_ARRAY; + else + return nsIDataType::VTYPE_EMPTY_ARRAY; + } // Now do expensive or abstract checks. if (Py_nsISupports::InterfaceFromPyObject(ob, NS_GET_IID(nsISupports), &ps, PR_TRUE)) { if (pdata) { @@ -550,8 +595,12 @@ return nsIDataType::VTYPE_ID; } else PyErr_Clear(); - if (PySequence_Check(ob)) - return PySequence_Length(ob) ? nsIDataType::VTYPE_ARRAY : nsIDataType::VTYPE_EMPTY_ARRAY; + if (PySequence_Check(ob)) { + if (PySequence_Length(ob)) + return nsIDataType::VTYPE_ARRAY; + else + return nsIDataType::VTYPE_EMPTY_ARRAY; + } return (PRUint16)-1; } @@ -584,7 +633,19 @@ nr = v->SetAsStringWithSize(PyString_Size(ob), PyString_AsString(ob)); break; case nsIDataType::VTYPE_WSTRING_SIZE_IS: - nr = v->SetAsWStringWithSize(PyUnicodeUCS2_GetSize(ob), PyUnicodeUCS2_AsUnicode(ob)); + if (PyUnicode_GetSize(ob) == 0) { + nr = v->SetAsWStringWithSize(0, (PRUnichar*)NULL); + } + else { + PRUint32 nch; + PRUnichar *p; + if (PyUnicode_AsPRUnichar(ob, &p, &nch) < 0) { + nr = NS_ERROR_UNEXPECTED; + break; + } + nr = v->SetAsWStringWithSize(nch, p); + nsMemory::Free(p); + } break; case nsIDataType::VTYPE_INTERFACE_IS: { @@ -1143,14 +1204,15 @@ PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); BREAK_FALSE; } - if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL) + if ((val_use = PyUnicode_FromObject(val))==NULL) BREAK_FALSE; // Sanity check should PyObject_Str() ever loosen its semantics wrt Unicode! - NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a unicode object!"); - if (PyUnicode_GET_SIZE(val_use) != 1) { + NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a unicode object!"); + if (PyUnicode_GetSize(val_use) != 1) { PyErr_SetString(PyExc_ValueError, "Must specify a one character string for a character"); BREAK_FALSE; } + // Lossy! ns_v.val.wc = *PyUnicode_AS_UNICODE(val_use); break; } @@ -1172,12 +1234,21 @@ PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); BREAK_FALSE; } - if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL) + if ((val_use = PyUnicode_FromObject(val))==NULL) BREAK_FALSE; // Sanity check should PyObject_Str() ever loosen its semantics wrt Unicode! - NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a unicode object!"); - ns_v.val.p = new nsString(PyUnicode_AS_UNICODE(val_use), - PyUnicode_GET_SIZE(val_use)); + NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a unicode object!"); + if (PyUnicode_GET_SIZE(val_use) == 0) { + ns_v.val.p = new nsString(); + } + else { + PRUint32 nch; + PRUnichar *tempo; + if (PyUnicode_AsPRUnichar(val_use, &tempo, &nch) < 0) + BREAK_FALSE; + ns_v.val.p = new nsString(tempo, nch); + nsMemory::Free(tempo); + } } if (!ns_v.val.p) { PyErr_NoMemory(); @@ -1254,22 +1325,19 @@ ns_v.val.p = nsnull; break; } - // If an "in" char *, and we have a PyString, then pass the - // pointer (hoping everyone else plays by the rules too. - if (!XPT_PD_IS_OUT(td.param_flags) && PyUnicode_Check(val)) { - ns_v.val.p = PyUnicode_AS_UNICODE(val); - break; - } if (!PyString_Check(val) && !PyUnicode_Check(val)) { PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); BREAK_FALSE; } - if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL) + if ((val_use = PyUnicode_FromObject(val))==NULL) BREAK_FALSE; - NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a Unicode object!"); - cb_this_buffer_pointer = (PyUnicode_GET_SIZE(val_use)+1) * sizeof(Py_UNICODE); - MAKE_VALUE_BUFFER(cb_this_buffer_pointer); - memcpy(this_buffer_pointer, PyUnicode_AS_UNICODE(val_use), cb_this_buffer_pointer); + NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!"); + PRUnichar *sv; + PRUint32 nch; + if (PyUnicode_AsPRUnichar(val_use, &sv, &nch) < 0) + BREAK_FALSE; + cb_this_buffer_pointer = (nch + 1) * sizeof(PRUnichar); + this_buffer_pointer = sv; ns_v.val.p = this_buffer_pointer; break; } @@ -1346,16 +1414,18 @@ PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); BREAK_FALSE; } - if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL) + if ((val_use = PyUnicode_FromObject(val))==NULL) BREAK_FALSE; // Sanity check should PyObject_Str() ever loosen its semantics wrt Unicode! NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyObject_Unicode didnt return a unicode object!"); - - cb_this_buffer_pointer = PyUnicode_GET_SIZE(val_use) * sizeof(PRUnichar); - MAKE_VALUE_BUFFER(cb_this_buffer_pointer); - memcpy(this_buffer_pointer, PyUnicode_AS_UNICODE(val_use), cb_this_buffer_pointer); + PRUnichar *sv; + PRUint32 nch; + if (PyUnicode_AsPRUnichar(val_use, &sv, &nch) < 0) + BREAK_FALSE; + cb_this_buffer_pointer = (nch + 1) * sizeof(PRUnichar); + this_buffer_pointer = sv; ns_v.val.p = this_buffer_pointer; - rc = SetSizeIs(value_index, PR_TRUE, PyUnicode_GET_SIZE(val_use) ); + rc = SetSizeIs(value_index, PR_TRUE, nch); break; } case nsXPTType::T_ARRAY: { @@ -1556,7 +1626,7 @@ break; case nsXPTType::T_WCHAR: - ret = PyUnicodeUCS2_FromUnicode( ((PRUnichar *)ns_v.ptr), 1 ); + ret = PyUnicode_FromPRUnichar( ((PRUnichar *)ns_v.ptr), 1 ); break; // case nsXPTType::T_VOID: case nsXPTType::T_IID: @@ -1588,8 +1658,9 @@ if (us == NULL) { ret = Py_None; Py_INCREF(Py_None); - } else - ret = PyUnicodeUCS2_FromUnicode( us, nsCRT::strlen(us)); + } else { + ret = PyUnicode_FromPRUnichar( us, nsCRT::strlen(us)); + } break; } case nsXPTType::T_INTERFACE: { @@ -1655,7 +1726,7 @@ Py_INCREF(Py_None); } else { PRUint32 string_size = GetSizeIs(index, PR_TRUE); - ret = PyUnicodeUCS2_FromUnicode( *((PRUnichar **)ns_v.ptr), string_size ); + ret = PyUnicode_FromPRUnichar( *((PRUnichar **)ns_v.ptr), string_size ); } break; default: @@ -1905,7 +1976,7 @@ } case nsXPTType::T_WCHAR: { PRUnichar temp = (PRUnichar)DEREF_IN_OR_OUT(ns_v.val.wc, PRUnichar); - ret = PyUnicodeUCS2_FromUnicode(&temp, 1); + ret = PyUnicode_FromPRUnichar(&temp, 1); break; } // case nsXPTType::T_VOID: @@ -1942,8 +2013,9 @@ if (us==NULL) { ret = Py_None; Py_INCREF(Py_None); - } else - ret = PyUnicodeUCS2_FromUnicode( us, nsCRT::strlen(us)); + } else { + ret = PyUnicode_FromPRUnichar( us, nsCRT::strlen(us)); + } break; } case nsXPTType::T_INTERFACE_IS: // our Python code does it :-) @@ -2000,8 +2072,9 @@ if (t==NULL) { ret = Py_None; Py_INCREF(Py_None); - } else - ret = PyUnicodeUCS2_FromUnicode(t, string_size); + } else { + ret = PyUnicode_FromPRUnichar(t, string_size); + } break; } default: @@ -2160,9 +2233,10 @@ PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); BREAK_FALSE; } - if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL) + if ((val_use = PyUnicode_FromObject(val))==NULL) BREAK_FALSE; - NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a Unicode object!"); + NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!"); + // Lossy! FILL_SIMPLE_POINTER( PRUnichar, *PyUnicode_AS_UNICODE(val_use) ); break; @@ -2195,10 +2269,21 @@ PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); BREAK_FALSE; } - val_use = PyUnicodeUCS2_FromObject(val); - NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a Unicode object!"); - const PRUnichar *sz = PyUnicode_AS_UNICODE(val_use); - ws->Assign(sz, PyUnicode_GET_SIZE(val_use)); + val_use = PyUnicode_FromObject(val); + if (!val_use) + BREAK_FALSE; + NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didn't return a Unicode object!"); + if (PyUnicode_GET_SIZE(val_use) == 0) { + ws->Assign((PRUnichar*)NULL, 0); + } + else { + PRUint32 nch; + PRUnichar *sz; + if (PyUnicode_AsPRUnichar(val_use, &sz, &nch) < 0) + BREAK_FALSE; + ws->Assign(sz, nch); + nsMemory::Free(sz); + } } break; } @@ -2282,17 +2367,10 @@ PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); BREAK_FALSE; } - val_use = PyUnicodeUCS2_FromObject(val); - NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a Unicode object!"); - const PRUnichar *sz = PyUnicode_AS_UNICODE(val_use); - int nch = PyUnicode_GET_SIZE(val_use); - - *pp = (PRUnichar *)nsMemory::Alloc(sizeof(PRUnichar) * (nch+1)); - if (*pp==NULL) { - PyErr_NoMemory(); + val_use = PyUnicode_FromObject(val); + NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!"); + if (PyUnicode_AsPRUnichar(val_use, pp, NULL) < 0) BREAK_FALSE; - } - memcpy(*pp, sz, sizeof(PRUnichar) * (nch + 1)); break; } case nsXPTType::T_INTERFACE: { @@ -2399,7 +2477,7 @@ } case nsXPTType::T_PWSTRING_SIZE_IS: { - const PRUnichar *sz = nsnull; + PRUnichar *sz = nsnull; PRUint32 nch = 0; PRUint32 nbytes = 0; @@ -2408,10 +2486,10 @@ PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); BREAK_FALSE; } - val_use = PyUnicodeUCS2_FromObject(val); - NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a Unicode object!"); - sz = PyUnicode_AS_UNICODE(val_use); - nch = PyUnicode_GET_SIZE(val_use); + val_use = PyUnicode_FromObject(val); + NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!"); + if (PyUnicode_AsPRUnichar(val_use, &sz, &nch) < 0) + BREAK_FALSE; nbytes = sizeof(PRUnichar) * nch; } PRBool bBackFill = PR_FALSE; @@ -2436,22 +2514,16 @@ PRUnichar **pp = (PRUnichar **)ns_v.val.p; if (*pp && pi->IsIn()) nsMemory::Free(*pp); - *pp = nsnull; - - if (val == Py_None) - break; // Remains NULL. - *pp = (PRUnichar *)nsMemory::Alloc(nbytes); - if (*pp==NULL) { - PyErr_NoMemory(); - BREAK_FALSE; - } - memcpy(*pp, sz, nbytes); + *pp = sz; + sz = nsnull; if (bCanSetSizeIs) rc = SetSizeIs(index, PR_TRUE, nch); else { NS_ABORT_IF_FALSE(GetSizeIs(index, PR_TRUE) == nch, "Can't set sizeis, but string isnt correct size"); } } + if (sz) + nsMemory::Free(sz); break; } case nsXPTType::T_ARRAY: { Index: src/loader/pyloader.cpp =================================================================== RCS file: /cvsroot/mozilla/extensions/python/xpcom/src/loader/pyloader.cpp,v retrieving revision 1.19 diff -u -r1.19 pyloader.cpp --- src/loader/pyloader.cpp 18 Apr 2004 22:13:54 -0000 1.19 +++ src/loader/pyloader.cpp 4 Feb 2005 05:42:39 -0000 @@ -43,8 +43,13 @@ // the xpcom "components" directory. Simply locates and loads the standard // _xpcom support module and transfers control to that. +#include + +#ifdef HAVE_LONG_LONG +#undef HAVE_LONG_LONG +#endif + #include "nsIComponentLoader.h" -#include "nsIRegistry.h" #include "nsISupports.h" #include "nsIModule.h" #include "nsDirectoryServiceDefs.h" @@ -57,15 +62,8 @@ #include "nsReadableUtils.h" #include "nsCRT.h" -#include // For console logging. #include "nspr.h" // PR_fprintf -#ifdef HAVE_LONG_LONG -#undef HAVE_LONG_LONG -#endif - -#include "Python.h" - #if (PY_VERSION_HEX >= 0x02030000) #define PYXPCOM_USE_PYGILSTATE #endif @@ -100,14 +98,14 @@ void AddStandardPaths() { // Put {bin}\Python on the path if it exists. + nsresult rv; nsCOMPtr aFile; - nsCOMPtr aLocalFile; - NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(aFile)); - if (!aFile) { + rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(aFile)); + if (NS_FAILED(rv)) { LogError("The Python XPCOM loader could not locate the 'bin' directory\n"); return; } - aFile->Append(NS_LITERAL_STRING("python")); + aFile->AppendNative(NS_LITERAL_CSTRING("python")); nsAutoString pathBuf; aFile->GetPath(pathBuf); PyObject *obPath = PySys_GetObject("path"); Index: test/test_misc.py =================================================================== RCS file: /cvsroot/mozilla/extensions/python/xpcom/test/test_misc.py,v retrieving revision 1.8 diff -u -r1.8 test_misc.py --- test/test_misc.py 25 Aug 2004 23:02:43 -0000 1.8 +++ test/test_misc.py 4 Feb 2005 05:42:39 -0000 @@ -191,7 +191,7 @@ ob = xpcom.components.classes[progid].createInstance() else: ob = progid - self.failUnless(repr(ob).find(progid) >= 0, repr(ob)) + self.failUnless(repr(ob).find(str(progid)) >= 0, repr(ob)) for interface_name in interfaces.split(): self.failUnless(repr(ob).find(interface_name) >= 0, repr(ob))