Explicitly use Python UCS2 functions, for platforms where
sizeof(wchar) != sizeof(PRUnichar).

Incorporate Linux build changes for dynamic linking.
This commit is contained in:
mhammond%skippinet.com.au 2003-07-30 01:08:13 +00:00
Родитель 4fd8cf233b
Коммит a326402327
3 изменённых файлов: 37 добавлений и 41 удалений

Просмотреть файл

@ -45,11 +45,11 @@ static PyObject *MyBool( PRBool v) {
static PyObject *MyChar( char c) {
return PyString_FromStringAndSize(&c, 1);
}
static PyObject *MyWChar( wchar_t c) {
return PyUnicode_FromWideChar(&c, 1);
static PyObject *MyUChar( PRUnichar c) {
return PyUnicodeUCS2_FromUnicode(&c, 1);
}
static PyObject *MyUnicode( PRUnichar *p) {
return PyUnicode_FromUnicode(p, nsCRT::strlen(p));
return PyUnicodeUCS2_FromUnicode(p, nsCRT::strlen(p));
}
static PyObject *MyISupports( nsISupports *p) {
return Py_nsISupports::PyObjectFromInterface(p, NS_GET_IID(nsISupports), PR_FALSE);
@ -104,14 +104,14 @@ GET_SIMPLE(float, GetAsFloat, PyFloat_FromDouble);
GET_SIMPLE(double, GetAsDouble, PyFloat_FromDouble);
GET_SIMPLE(PRBool, GetAsBool, MyBool);
GET_SIMPLE(char, GetAsChar, MyChar);
GET_SIMPLE(PRUnichar, GetAsWChar, MyWChar);
GET_SIMPLE(PRUnichar, GetAsWChar, MyUChar);
GET_SIMPLE(nsISupports *, GetAsISupports, MyISupports);
GET_SIMPLE(nsIID, GetAsID, Py_nsIID::PyObjectFromIID);
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, PyUnicode_FromUnicode, nsMemory::Free);
GET_ALLOCATED_SIZE(PRUnichar *, GetAsWStringWithSize, PyUnicodeUCS2_FromUnicode, nsMemory::Free);
static PyObject *GetAsInterface(PyObject *self, PyObject *args) {
nsIVariant *pI = GetI(self);

Просмотреть файл

@ -80,8 +80,8 @@ PyObject *PyObject_FromNSString( const nsAString &s )
ret = Py_None;
Py_INCREF(Py_None);
} else {
ret = PyUnicode_FromUnicode( NULL, s.Length() );
CopyUnicodeTo(s, 0, PyUnicode_AsUnicode(ret), s.Length());
ret = PyUnicodeUCS2_FromUnicode( NULL, s.Length() );
CopyUnicodeTo(s, 0, PyUnicodeUCS2_AsUnicode(ret), s.Length());
}
return ret;
}
@ -285,9 +285,9 @@ PRBool FillSingleArray(void *array_ptr, PyObject *sequence_ob, PRUint32 sequence
PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
BREAK_FALSE;
}
if ((val_use = PyUnicode_FromObject(val))==NULL)
if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL)
BREAK_FALSE;
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a Unicode object!");
FILL_SIMPLE_POINTER( PRUnichar, *PyUnicode_AS_UNICODE(val_use) );
break;
@ -351,9 +351,9 @@ PRBool FillSingleArray(void *array_ptr, PyObject *sequence_ob, PRUint32 sequence
PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
BREAK_FALSE;
}
if ((val_use = PyUnicode_FromObject(val))==NULL)
if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL)
BREAK_FALSE;
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
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);
@ -459,7 +459,7 @@ PyObject *UnpackSingleArray(void *array_ptr, PRUint32 sequence_size, PRUint8 arr
Py_INCREF(Py_None);
val = Py_None;
} else
val = PyUnicode_FromUnicode( *pp, nsCRT::strlen(*pp) );
val = PyUnicodeUCS2_FromUnicode( *pp, nsCRT::strlen(*pp) );
break;
}
case nsXPTType::T_INTERFACE_IS:
@ -566,7 +566,7 @@ nsIVariant *PyObject_AsVariant( PyObject *ob)
nr = v->SetAsStringWithSize(PyString_Size(ob), PyString_AsString(ob));
break;
case nsIDataType::VTYPE_WSTRING_SIZE_IS:
nr = v->SetAsWStringWithSize(PyUnicode_GetSize(ob), PyUnicode_AsUnicode(ob));
nr = v->SetAsWStringWithSize(PyUnicodeUCS2_GetSize(ob), PyUnicodeUCS2_AsUnicode(ob));
break;
case nsIDataType::VTYPE_INTERFACE_IS:
{
@ -1125,10 +1125,10 @@ PRBool PyXPCOM_InterfaceVariantHelper::FillInVariant(const PythonTypeDescriptor
PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
BREAK_FALSE;
}
if ((val_use = PyUnicode_FromObject(val))==NULL)
if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL)
BREAK_FALSE;
// Sanity check should PyObject_Str() ever loosen its semantics wrt Unicode!
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromUnicode didnt return a unicode object!");
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a unicode object!");
if (PyUnicode_GET_SIZE(val_use) != 1) {
PyErr_SetString(PyExc_ValueError, "Must specify a one character string for a character");
BREAK_FALSE;
@ -1154,10 +1154,10 @@ PRBool PyXPCOM_InterfaceVariantHelper::FillInVariant(const PythonTypeDescriptor
PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
BREAK_FALSE;
}
if ((val_use = PyUnicode_FromObject(val))==NULL)
if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL)
BREAK_FALSE;
// Sanity check should PyObject_Str() ever loosen its semantics wrt Unicode!
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromUnicode didnt return a unicode object!");
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));
}
@ -1246,9 +1246,9 @@ PRBool PyXPCOM_InterfaceVariantHelper::FillInVariant(const PythonTypeDescriptor
PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
BREAK_FALSE;
}
if ((val_use = PyUnicode_FromObject(val))==NULL)
if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL)
BREAK_FALSE;
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
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);
@ -1328,7 +1328,7 @@ PRBool PyXPCOM_InterfaceVariantHelper::FillInVariant(const PythonTypeDescriptor
PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
BREAK_FALSE;
}
if ((val_use = PyUnicode_FromObject(val))==NULL)
if ((val_use = PyUnicodeUCS2_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!");
@ -1538,7 +1538,7 @@ PyObject *PyXPCOM_InterfaceVariantHelper::MakeSinglePythonResult(int index)
break;
case nsXPTType::T_WCHAR:
ret = PyUnicode_FromUnicode( ((PRUnichar *)ns_v.ptr), 1 );
ret = PyUnicodeUCS2_FromUnicode( ((PRUnichar *)ns_v.ptr), 1 );
break;
// case nsXPTType::T_VOID:
case nsXPTType::T_IID:
@ -1571,7 +1571,7 @@ PyObject *PyXPCOM_InterfaceVariantHelper::MakeSinglePythonResult(int index)
ret = Py_None;
Py_INCREF(Py_None);
} else
ret = PyUnicode_FromUnicode( us, nsCRT::strlen(us));
ret = PyUnicodeUCS2_FromUnicode( us, nsCRT::strlen(us));
break;
}
case nsXPTType::T_INTERFACE: {
@ -1637,7 +1637,7 @@ PyObject *PyXPCOM_InterfaceVariantHelper::MakeSinglePythonResult(int index)
Py_INCREF(Py_None);
} else {
PRUint32 string_size = GetSizeIs(index, PR_TRUE);
ret = PyUnicode_FromUnicode( *((PRUnichar **)ns_v.ptr), string_size );
ret = PyUnicodeUCS2_FromUnicode( *((PRUnichar **)ns_v.ptr), string_size );
}
break;
default:
@ -1888,7 +1888,7 @@ PyObject *PyXPCOM_GatewayVariantHelper::MakeSingleParam(int index, PythonTypeDes
}
case nsXPTType::T_WCHAR: {
wchar_t temp = (wchar_t)DEREF_IN_OR_OUT(ns_v.val.wc, PRUint16);
ret = PyUnicode_FromWideChar(&temp, 1);
ret = PyUnicodeUCS2_FromUnicode(&temp, 1);
break;
}
// case nsXPTType::T_VOID:
@ -1926,7 +1926,7 @@ PyObject *PyXPCOM_GatewayVariantHelper::MakeSingleParam(int index, PythonTypeDes
ret = Py_None;
Py_INCREF(Py_None);
} else
ret = PyUnicode_FromUnicode( us, nsCRT::strlen(us));
ret = PyUnicodeUCS2_FromUnicode( us, nsCRT::strlen(us));
break;
}
case nsXPTType::T_INTERFACE_IS: // our Python code does it :-)
@ -1985,7 +1985,7 @@ PyObject *PyXPCOM_GatewayVariantHelper::MakeSingleParam(int index, PythonTypeDes
ret = Py_None;
Py_INCREF(Py_None);
} else
ret = PyUnicode_FromUnicode(t, string_size);
ret = PyUnicodeUCS2_FromUnicode(t, string_size);
break;
}
default:
@ -2145,9 +2145,9 @@ nsresult PyXPCOM_GatewayVariantHelper::BackFillVariant( PyObject *val, int index
PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
BREAK_FALSE;
}
if ((val_use = PyUnicode_FromObject(val))==NULL)
if ((val_use = PyUnicodeUCS2_FromObject(val))==NULL)
BREAK_FALSE;
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicodeUCS2_FromObject didnt return a Unicode object!");
FILL_SIMPLE_POINTER( PRUnichar, *PyUnicode_AS_UNICODE(val_use) );
break;
@ -2180,8 +2180,8 @@ nsresult PyXPCOM_GatewayVariantHelper::BackFillVariant( PyObject *val, int index
PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
BREAK_FALSE;
}
val_use = PyUnicode_FromObject(val);
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
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));
}
@ -2267,8 +2267,8 @@ nsresult PyXPCOM_GatewayVariantHelper::BackFillVariant( PyObject *val, int index
PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
BREAK_FALSE;
}
val_use = PyUnicode_FromObject(val);
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
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);
@ -2393,8 +2393,8 @@ nsresult PyXPCOM_GatewayVariantHelper::BackFillVariant( PyObject *val, int index
PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
BREAK_FALSE;
}
val_use = PyUnicode_FromObject(val);
NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!");
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);
nbytes = sizeof(PRUnichar) * nch;

Просмотреть файл

@ -51,11 +51,11 @@ extern PRInt32 _PyXPCOM_GetInterfaceCount(void);
extern void AddDefaultGateway(PyObject *instance, nsISupports *gateway);
#ifdef XP_WIN
// Can only assume dynamic loading on Windows.
#define LOADER_LINKS_WITH_PYTHON
#endif // XP_WIN
#ifndef LOADER_LINKS_WITH_PYTHON
extern void PyXPCOM_InterpreterState_Ensure();
#endif
PyXPCOM_INTERFACE_DEFINE(Py_nsIComponentManager, nsIComponentManagerObsolete, PyMethods_IComponentManager)
PyXPCOM_INTERFACE_DEFINE(Py_nsIInterfaceInfoManager, nsIInterfaceInfoManager, PyMethods_IInterfaceInfoManager)
@ -442,10 +442,6 @@ static struct PyMethodDef xpcom_methods[]=
////////////////////////////////////////////////////////////
// Other helpers/global functions.
//
#ifndef PYXPCOM_USE_PYGILSTATE
extern void PyXPCOM_InterpreterState_Ensure();
#endif
PRBool PyXPCOM_Globals_Ensure()
{
PRBool rc = PR_TRUE;