Changeset 59809 in vbox for trunk/src/libs/xpcom18a4/python
- Timestamp:
- Feb 24, 2016 10:12:21 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105691
- Location:
- trunk/src/libs/xpcom18a4/python
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/python/Makefile.kmk
r59800 r59809 5 5 6 6 # 7 # Copyright (C) 2009-201 5Oracle Corporation7 # Copyright (C) 2009-2016 Oracle Corporation 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 27 27 # 28 28 # List of supported Python versions, defining a number of 29 # VBOX_PYTHON[25|26|27|DEF]_[INC|LIB] variables which get picked up below. 29 # VBOX_PYTHON[26|27|31|32|33|34|35|DEF]_[INC|LIB] variables 30 # which get picked up below. 30 31 # 31 32 ifeq ($(KBUILD_TARGET),darwin) # Relatively predictable, don't script. 32 ifeq ($(KBUILD_TARGET_ARCH),x86)33 VBOX_PYTHON25_INC = $(VBOX_PATH_MACOSX_SDK)/usr/include/python2.534 VBOX_PYTHON25_LIB = $(VBOX_PATH_MACOSX_SDK)/usr/lib/libpython2.5.dylib35 VBOX_PYTHON25_LIB_X86 = $(VBOX_PYTHON25_LIB)36 endif37 33 if !defined(VBOX_WITHOUT_VBOXPYTHON_FOR_OSX_10_6) \ 38 34 && ( !defined(VBOX_OSE) \ … … 49 45 VBOX_PYTHON27_LIB_X86 = $(VBOX_PYTHON27_LIB) 50 46 endif 47 # No Python 3.x yet as part of OSX versions including El Capitan, 10.11. 51 48 52 49 else … … 115 112 116 113 117 ifdef VBOX_PYTHON23_INC118 #119 # Python 2.3 version120 #121 DLLS += VBoxPython2_3122 VBoxPython2_3_EXTENDS = VBoxPythonBase123 VBoxPython2_3_EXTENDS_BY = appending124 VBoxPython2_3_TEMPLATE = XPCOM$(if-expr "$(KBUILD_TARGET)" == "darwin",OSX104,)125 VBoxPython2_3_INCS = $(VBOX_PYTHON23_INC)126 VBoxPython2_3_LIBS = $(VBOX_PYTHON23_LIB)127 128 ifdef VBOX_WITH_32_ON_64_MAIN_API129 DLLS += VBoxPython2_3_x86130 VBoxPython2_3_x86_EXTENDS = VBoxPythonBase_x86131 VBoxPython2_3_x86_EXTENDS_BY = appending132 VBoxPython2_3_x86_TEMPLATE = XPCOM$(if-expr "$(KBUILD_TARGET)" == "darwin",OSX104,-x86)133 VBoxPython2_3_x86_INCS = $(VBOX_PYTHON23_INC)134 VBoxPython2_3_x86_LIBS = $(VBOX_PYTHON23_LIB_X86)135 endif136 endif137 138 ifdef VBOX_PYTHON24_INC139 #140 # Python 2.4 version141 #142 DLLS += VBoxPython2_4143 VBoxPython2_4_EXTENDS = VBoxPythonBase144 VBoxPython2_4_EXTENDS_BY = appending145 VBoxPython2_4_INCS = $(VBOX_PYTHON24_INC)146 VBoxPython2_4_LIBS = $(VBOX_PYTHON24_LIB)147 148 ifdef VBOX_WITH_32_ON_64_MAIN_API149 DLLS += VBoxPython2_4_x86150 VBoxPython2_4_x86_EXTENDS = VBoxPythonBase_x86151 VBoxPython2_4_x86_EXTENDS_BY = appending152 VBoxPython2_4_x86_INCS = $(VBOX_PYTHON24_INC)153 VBoxPython2_4_x86_LIBS = $(VBOX_PYTHON24_LIB_X86)154 endif155 endif156 157 ifdef VBOX_PYTHON25_INC158 #159 # Python 2.5 version160 #161 DLLS += VBoxPython2_5162 VBoxPython2_5_EXTENDS = VBoxPythonBase163 VBoxPython2_5_EXTENDS_BY = appending164 VBoxPython2_5_INCS = $(VBOX_PYTHON25_INC)165 VBoxPython2_5_LIBS = $(VBOX_PYTHON25_LIB)166 167 ifdef VBOX_WITH_32_ON_64_MAIN_API168 DLLS += VBoxPython2_5_x86169 VBoxPython2_5_x86_EXTENDS = VBoxPythonBase_x86170 VBoxPython2_5_x86_EXTENDS_BY = appending171 VBoxPython2_5_x86_INCS = $(VBOX_PYTHON25_INC)172 VBoxPython2_5_x86_LIBS = $(VBOX_PYTHON25_LIB_X86)173 endif174 endif175 176 114 ifdef VBOX_PYTHON26_INC 177 115 # … … 213 151 VBoxPython2_7_x86_INCS = $(VBOX_PYTHON27_INC) 214 152 VBoxPython2_7_x86_LIBS = $(VBOX_PYTHON27_LIB_X86) 153 endif 154 endif 155 156 ifdef VBOX_PYTHON31_INC 157 # 158 # Python 3.1 version 159 # 160 DLLS += VBoxPython3_1 161 VBoxPython3_1_EXTENDS = VBoxPythonBase 162 VBoxPython3_1_EXTENDS_BY = appending 163 VBoxPython3_1_TEMPLATE = XPCOM 164 VBoxPython3_1_INCS = $(VBOX_PYTHON31_INC) 165 VBoxPython3_1_LIBS = $(VBOX_PYTHON31_LIB) 166 167 ifdef VBOX_WITH_32_ON_64_MAIN_API 168 DLLS += VBoxPython3_1_x86 169 VBoxPython3_1_x86_EXTENDS = VBoxPythonBase_x86 170 VBoxPython3_1_x86_EXTENDS_BY = appending 171 VBoxPython3_1_x86_TEMPLATE = XPCOM 172 VBoxPython3_1_x86_INCS = $(VBOX_PYTHON31_INC) 173 VBoxPython3_1_x86_LIBS = $(VBOX_PYTHON31_LIB_X86) 174 endif 175 endif 176 177 ifdef VBOX_PYTHON32_INC 178 # 179 # Python 3.2 version 180 # 181 DLLS += VBoxPython3_2 182 VBoxPython3_2_EXTENDS = VBoxPythonBase 183 VBoxPython3_2_EXTENDS_BY = appending 184 VBoxPython3_2_TEMPLATE = XPCOM 185 VBoxPython3_2_INCS = $(VBOX_PYTHON32_INC) 186 VBoxPython3_2_LIBS = $(VBOX_PYTHON32_LIB) 187 188 ifdef VBOX_WITH_32_ON_64_MAIN_API 189 DLLS += VBoxPython3_2_x86 190 VBoxPython3_2_x86_EXTENDS = VBoxPythonBase_x86 191 VBoxPython3_2_x86_EXTENDS_BY = appending 192 VBoxPython3_2_x86_TEMPLATE = XPCOM 193 VBoxPython3_2_x86_INCS = $(VBOX_PYTHON32_INC) 194 VBoxPython3_2_x86_LIBS = $(VBOX_PYTHON32_LIB_X86) 195 endif 196 endif 197 198 ifdef VBOX_PYTHON33_INC 199 # 200 # Python 3.3 version 201 # 202 DLLS += VBoxPython3_3 203 VBoxPython3_3_EXTENDS = VBoxPythonBase 204 VBoxPython3_3_EXTENDS_BY = appending 205 VBoxPython3_3_TEMPLATE = XPCOM 206 VBoxPython3_3_INCS = $(VBOX_PYTHON33_INC) 207 VBoxPython3_3_LIBS = $(VBOX_PYTHON33_LIB) 208 209 ifdef VBOX_WITH_32_ON_64_MAIN_API 210 DLLS += VBoxPython3_3_x86 211 VBoxPython3_3_x86_EXTENDS = VBoxPythonBase_x86 212 VBoxPython3_3_x86_EXTENDS_BY = appending 213 VBoxPython3_3_x86_TEMPLATE = XPCOM 214 VBoxPython3_3_x86_INCS = $(VBOX_PYTHON33_INC) 215 VBoxPython3_3_x86_LIBS = $(VBOX_PYTHON33_LIB_X86) 216 endif 217 endif 218 219 ifdef VBOX_PYTHON34_INC 220 # 221 # Python 3.4 version 222 # 223 DLLS += VBoxPython3_4 224 VBoxPython3_4_EXTENDS = VBoxPythonBase 225 VBoxPython3_4_EXTENDS_BY = appending 226 VBoxPython3_4_TEMPLATE = XPCOM 227 VBoxPython3_4_INCS = $(VBOX_PYTHON34_INC) 228 VBoxPython3_4_LIBS = $(VBOX_PYTHON34_LIB) 229 230 ifdef VBOX_WITH_32_ON_64_MAIN_API 231 DLLS += VBoxPython3_4_x86 232 VBoxPython3_4_x86_EXTENDS = VBoxPythonBase_x86 233 VBoxPython3_4_x86_EXTENDS_BY = appending 234 VBoxPython3_4_x86_TEMPLATE = XPCOM 235 VBoxPython3_4_x86_INCS = $(VBOX_PYTHON34_INC) 236 VBoxPython3_4_x86_LIBS = $(VBOX_PYTHON34_LIB_X86) 237 endif 238 endif 239 240 ifdef VBOX_PYTHON35_INC 241 # 242 # Python 3.5 version 243 # 244 DLLS += VBoxPython3_5 245 VBoxPython3_5_EXTENDS = VBoxPythonBase 246 VBoxPython3_5_EXTENDS_BY = appending 247 VBoxPython3_5_TEMPLATE = XPCOM 248 VBoxPython3_5_INCS = $(VBOX_PYTHON35_INC) 249 VBoxPython3_5_LIBS = $(VBOX_PYTHON35_LIB) 250 251 ifdef VBOX_WITH_32_ON_64_MAIN_API 252 DLLS += VBoxPython3_5_x86 253 VBoxPython3_5_x86_EXTENDS = VBoxPythonBase_x86 254 VBoxPython3_5_x86_EXTENDS_BY = appending 255 VBoxPython3_5_x86_TEMPLATE = XPCOM 256 VBoxPython3_5_x86_INCS = $(VBOX_PYTHON35_INC) 257 VBoxPython3_5_x86_LIBS = $(VBOX_PYTHON35_LIB_X86) 215 258 endif 216 259 endif -
trunk/src/libs/xpcom18a4/python/gen_python_deps.py
r59800 r59809 2 2 3 3 """ 4 Copyright (C) 2009-201 3Oracle Corporation4 Copyright (C) 2009-2016 Oracle Corporation 5 5 6 6 This file is part of VirtualBox Open Source Edition (OSE), as … … 14 14 15 15 import os,sys 16 from distutils.version import StrictVersion 16 17 17 versions = ["2. 3", "2.4", "2.5", "2.6", "2.7",]18 versions = ["2.6", "2.7", "3.1", "3.2", "3.3", "3.4", "3.5"] 18 19 prefixes = ["/usr", "/usr/local", "/opt", "/opt/local"] 19 20 known = {} … … 41 42 42 43 def print_vars(vers, known, sep, bitness_magic): 43 print "VBOX_PYTHON%s_INC=%s%s" %(vers, known[0], sep)44 print("VBOX_PYTHON%s_INC=%s%s" %(vers, known[0], sep)) 44 45 if bitness_magic > 0: 45 print "VBOX_PYTHON%s_LIB=%s%s" %(vers, known[2], sep)46 print "VBOX_PYTHON%s_LIB_X86=%s%s" %(vers, known[1], sep)46 print("VBOX_PYTHON%s_LIB=%s%s" %(vers, known[2], sep)) 47 print("VBOX_PYTHON%s_LIB_X86=%s%s" %(vers, known[1], sep)) 47 48 else: 48 print "VBOX_PYTHON%s_LIB=%s%s" %(vers, known[1], sep)49 print("VBOX_PYTHON%s_LIB=%s%s" %(vers, known[1], sep)) 49 50 50 51 … … 91 92 92 93 for v in versions: 94 if StrictVersion(v) < StrictVersion('2.6'): 95 continue 93 96 for p in prefixes: 94 97 c = checkPair(p, v, dllpre, dllsuff, bitness_magic) … … 96 99 known[v] = c 97 100 break 98 keys = known.keys()101 keys = list(known.keys()) 99 102 # we want default to be the lowest versioned Python 100 103 keys.sort() -
trunk/src/libs/xpcom18a4/python/src/ErrorUtils.cpp
r59795 r59809 111 111 c += "('%s', "; 112 112 // Pull a trick to ensure a valid string - use Python repr! 113 #if PY_MAJOR_VERSION <= 2 113 114 PyObject *obMessage = PyString_FromString(pszMessageText); 115 #else 116 PyObject *obMessage = PyUnicode_FromString(pszMessageText); 117 #endif 114 118 if (obMessage) { 115 119 PyObject *repr = PyObject_Repr(obMessage); 116 120 if (repr) { 121 #if PY_MAJOR_VERSION <= 2 117 122 c += PyString_AsString(repr); 123 #else 124 c += PyUnicode_AsUTF8(repr); 125 #endif 118 126 Py_DECREF(repr); 119 127 } … … 193 201 PyObject *temp = PyObject_Str(exc_typ); 194 202 if (temp) { 203 #if PY_MAJOR_VERSION <= 2 195 204 streamout += PyString_AsString(temp); 205 #else 206 streamout += PyUnicode_AsUTF8(temp); 207 #endif 196 208 Py_DECREF(temp); 197 209 } else … … 201 213 temp = PyObject_Str(exc_val); 202 214 if (temp) { 215 #if PY_MAJOR_VERSION <= 2 203 216 streamout += PyString_AsString(temp); 217 #else 218 streamout += PyUnicode_AsUTF8(temp); 219 #endif 204 220 Py_DECREF(temp); 205 221 } else … … 355 371 PyObject *obResult = NULL; 356 372 373 #if PY_MAJOR_VERSION <= 2 357 374 /* Import the modules we need - cStringIO and traceback */ 358 375 modStringIO = PyImport_ImportModule("cStringIO"); … … 370 387 if (obStringIO==NULL) 371 388 TRACEBACK_FETCH_ERROR("cStringIO.StringIO() failed\n"); 389 #else 390 /* Import the modules we need - io and traceback */ 391 modStringIO = PyImport_ImportModule("io"); 392 if (modStringIO==NULL) 393 TRACEBACK_FETCH_ERROR("cant import io\n"); 394 395 modTB = PyImport_ImportModule("traceback"); 396 if (modTB==NULL) 397 TRACEBACK_FETCH_ERROR("cant import traceback\n"); 398 /* Construct a StringIO object */ 399 obFuncStringIO = PyObject_GetAttrString(modStringIO, "StringIO"); 400 if (obFuncStringIO==NULL) 401 TRACEBACK_FETCH_ERROR("cant find io.StringIO\n"); 402 obStringIO = PyObject_CallObject(obFuncStringIO, NULL); 403 if (obStringIO==NULL) 404 TRACEBACK_FETCH_ERROR("io.StringIO() failed\n"); 405 #endif 372 406 /* Get the traceback.print_exception function, and call it. */ 373 407 obFuncTB = PyObject_GetAttrString(modTB, "print_tb"); … … 396 430 397 431 /* And it should be a string all ready to go - duplicate it. */ 432 #if PY_MAJOR_VERSION <= 2 398 433 if (!PyString_Check(obResult)) 434 #else 435 if (!PyUnicode_Check(obResult)) 436 #endif 399 437 TRACEBACK_FETCH_ERROR("getvalue() did not return a string\n"); 400 438 401 439 { // a temp scope so I can use temp locals. 440 #if PY_MAJOR_VERSION <= 2 402 441 char *tempResult = PyString_AsString(obResult); 442 #else 443 char *tempResult = PyUnicode_AsUTF8(obResult); 444 #endif 403 445 result = (char *)PyMem_Malloc(strlen(tempResult)+1); 404 446 if (result==NULL) -
trunk/src/libs/xpcom18a4/python/src/PyGBase.cpp
r59795 r59809 67 67 PRBool CheckDefaultGateway(PyObject *real_inst, REFNSIID iid, nsISupports **ret_gateway); 68 68 69 /*static*/ nsresult 69 /*static*/ nsresult 70 70 PyG_Base::CreateNew(PyObject *pPyInstance, const nsIID &iid, void **ppResult) 71 71 { … … 115 115 } 116 116 else 117 #if PY_MAJOR_VERSION <= 2 117 118 szRepr = PyString_AsString(r); 119 #else 120 szRepr = PyUnicode_AsUTF8(r); 121 #endif 118 122 if (szRepr==NULL) szRepr = ""; 119 123 int reprOffset = *szRepr=='<' ? 1 : 0; … … 185 189 if (iid.Equals(NS_GET_IID(nsISupportsWeakReference))) 186 190 return (nsISupportsWeakReference *)this; 187 if (iid.Equals(NS_GET_IID(nsIInternalPython))) 191 if (iid.Equals(NS_GET_IID(nsIInternalPython))) 188 192 return (nsISupports *)(nsIInternalPython *)this; 189 193 return NULL; … … 192 196 // Call back into Python, passing a Python instance, and get back 193 197 // an interface object that wraps the instance. 194 /*static*/ PRBool 198 /*static*/ PRBool 195 199 PyG_Base::AutoWrapPythonInstance(PyObject *ob, const nsIID &iid, nsISupports **ppret) 196 200 { … … 245 249 // the object to actually use as the gateway parameter for this interface. 246 250 // For example, it is expected that the policy will wrap the interface 247 // object in one of the xpcom.client.Interface objects, allowing 251 // object in one of the xpcom.client.Interface objects, allowing 248 252 // natural usage of the interface from Python clients. 249 253 // Note that piid will usually be NULL - this is because the runtime … … 256 260 // so at least the user can simply QI the object. 257 261 PyObject * 258 PyG_Base::MakeInterfaceParam(nsISupports *pis, 259 const nsIID *piid, 262 PyG_Base::MakeInterfaceParam(nsISupports *pis, 263 const nsIID *piid, 260 264 int methodIndex /* = -1 */, 261 const XPTParamDescriptor *d /* = NULL */, 265 const XPTParamDescriptor *d /* = NULL */, 262 266 int paramIndex /* = -1 */) 263 267 { … … 302 306 goto done; 303 307 304 result = PyObject_CallMethod(m_pPyObject, 308 result = PyObject_CallMethod(m_pPyObject, 305 309 (char*)"_MakeInterfaceParam_", 306 310 (char*)"OOiOi", … … 351 355 return NS_OK; 352 356 } 353 // If we have a "base object", then we need to delegate _every_ remaining 357 // If we have a "base object", then we need to delegate _every_ remaining 354 358 // QI to it. 355 359 if (m_pBaseObject != NULL) … … 374 378 375 379 PyObject *result = PyObject_CallMethod(m_pPyObject, (char*)"_QueryInterface_", 376 (char*)"OO", 380 (char*)"OO", 377 381 this_interface_ob, ob); 378 382 Py_DECREF(ob); … … 462 466 if (PyErr_Occurred()) { 463 467 // The error handling - fairly involved, but worth it as 464 // good error reporting is critical for users to know WTF 468 // good error reporting is critical for users to know WTF 465 469 // is going on - especially with TypeErrors etc in their 466 470 // return values (ie, after the Python code has successfully 467 471 // exited, but we encountered errors unpacking their 468 // result values for the COM caller - there is literally no 472 // result values for the COM caller - there is literally no 469 473 // way to catch these exceptions from Python code, as their 470 474 // is no Python function directly on the call-stack) … … 481 485 PyErr_Fetch(&exc_typ, &exc_val, &exc_tb); 482 486 483 PyObject *err_result = PyObject_CallMethod(m_pPyObject, 487 PyObject *err_result = PyObject_CallMethod(m_pPyObject, 484 488 (char*)"_GatewayException_", 485 489 (char*)"z(OOO)", … … 641 645 ob_ret = PyObject_GetAttrString(real_ob, (char *)szPropertyName); 642 646 if (ob_ret==NULL) { 643 PyErr_Format(PyExc_AttributeError, 644 "The object does not have a 'get_%s' function, or a '%s attribute.", 647 PyErr_Format(PyExc_AttributeError, 648 "The object does not have a 'get_%s' function, or a '%s attribute.", 645 649 szPropertyName, szPropertyName); 646 650 } else { … … 695 699 ret = NS_OK; 696 700 else { 697 PyErr_Format(PyExc_AttributeError, 698 "The object does not have a 'set_%s' function, or a '%s attribute.", 701 PyErr_Format(PyExc_AttributeError, 702 "The object does not have a 'set_%s' function, or a '%s attribute.", 699 703 szPropertyName, szPropertyName); 700 704 } … … 737 741 first thing we do is see if it has been auto-wrapped before. 738 742 739 If not, we create a new wrapper, then make a COM weak reference 743 If not, we create a new wrapper, then make a COM weak reference 740 744 to that wrapper, and store it directly back into the instance 741 745 we are auto-wrapping! The use of a weak-reference prevents … … 761 765 PRBool ok = PR_TRUE; 762 766 nsCOMPtr<nsIWeakReference> pWeakRef; 763 ok = NS_SUCCEEDED(Py_nsISupports::InterfaceFromPyObject(ob_existing_weak, 764 NS_GET_IID(nsIWeakReference), 767 ok = NS_SUCCEEDED(Py_nsISupports::InterfaceFromPyObject(ob_existing_weak, 768 NS_GET_IID(nsIWeakReference), 765 769 getter_AddRefs(pWeakRef), 766 770 PR_FALSE)); … … 791 795 PRBool ok = PR_TRUE; 792 796 nsCOMPtr<nsIWeakReference> pWeakRef; 793 ok = NS_SUCCEEDED(Py_nsISupports::InterfaceFromPyObject(ob_existing_weak, 794 NS_GET_IID(nsIWeakReference), 795 getter_AddRefs(pWeakRef), 797 ok = NS_SUCCEEDED(Py_nsISupports::InterfaceFromPyObject(ob_existing_weak, 798 NS_GET_IID(nsIWeakReference), 799 getter_AddRefs(pWeakRef), 796 800 PR_FALSE)); 797 801 Py_DECREF(ob_existing_weak); … … 827 831 swr->GetWeakReference( getter_AddRefs(pWeakReference) ); 828 832 if (pWeakReference) { 829 PyObject *ob_new_weak = Py_nsISupports::PyObjectFromInterface(pWeakReference, 833 PyObject *ob_new_weak = Py_nsISupports::PyObjectFromInterface(pWeakReference, 830 834 NS_GET_IID(nsIWeakReference), 831 835 PR_FALSE ); /* bMakeNicePyObject */ -
trunk/src/libs/xpcom18a4/python/src/PyIClassInfo.cpp
r59795 r59809 107 107 { 108 108 if (v) 109 #if PY_MAJOR_VERSION <= 2 109 110 return PyString_FromString(v); 111 #else 112 return PyUnicode_FromString(v); 113 #endif 110 114 Py_INCREF(Py_None); 111 115 return Py_None; … … 167 171 } 168 172 169 struct PyMethodDef 173 struct PyMethodDef 170 174 PyMethods_IClassInfo[] = 171 175 { -
trunk/src/libs/xpcom18a4/python/src/PyIComponentManagerObsolete.cpp
r59795 r59809 133 133 return PyXPCOM_BuildPyException(r); 134 134 135 #if PY_MAJOR_VERSION <= 2 135 136 PyObject *ob_pid = PyString_FromString(ret_pid); 136 137 PyObject *ob_class = PyString_FromString(ret_class); 138 #else 139 PyObject *ob_pid = PyUnicode_FromString(ret_pid); 140 PyObject *ob_class = PyUnicode_FromString(ret_class); 141 #endif 137 142 PyObject *ret = Py_BuildValue("OO", ob_pid, ob_class); 138 143 nsMemory::Free(ret_pid); … … 183 188 } 184 189 185 struct PyMethodDef 190 struct PyMethodDef 186 191 PyMethods_IComponentManagerObsolete[] = 187 192 { -
trunk/src/libs/xpcom18a4/python/src/PyIID.cpp
r59795 r59809 60 60 PyObject *obBuf; 61 61 if ( PyArg_ParseTuple(args, "O", &obBuf)) { 62 #if PY_MAJOR_VERSION <= 2 62 63 if (PyBuffer_Check(obBuf)) { 63 64 PyBufferProcs *pb = NULL; … … 65 66 void *buf = NULL; 66 67 int size = (*pb->bf_getreadbuffer)(obBuf, 0, &buf); 68 #else 69 if (PyObject_CheckBuffer(obBuf)) { 70 void *buf = NULL; 71 Py_buffer view; 72 if (PyObject_GetBuffer(obBuf, &view, PyBUF_CONTIG_RO) != 0) 73 { 74 PyErr_Format(PyExc_ValueError, "Could not get contiguous buffer from object"); 75 return NULL; 76 } 77 Py_ssize_t size = view.len; 78 buf = view.buf; 79 #endif 67 80 if (size != sizeof(nsIID) || buf==NULL) { 81 #if PY_MAJOR_VERSION >= 3 82 PyBuffer_Release(&view); 83 #endif 68 84 #ifdef VBOX 69 85 PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", (int)sizeof(nsIID)); 70 86 #else 71 87 PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", sizeof(nsIID)); … … 85 101 ptr += sizeof(PRUint8); 86 102 } 103 #if PY_MAJOR_VERSION >= 3 104 PyBuffer_Release(&view); 105 #endif 87 106 return new Py_nsIID(iid); 88 107 } … … 107 126 return PR_FALSE; 108 127 } 128 #if PY_MAJOR_VERSION <= 2 109 129 if (PyString_Check(ob)) { 110 130 ok = iid.Parse(PyString_AsString(ob)); 131 #else 132 if (PyUnicode_Check(ob)) { 133 ok = iid.Parse(PyUnicode_AsUTF8(ob)); 134 #endif 111 135 if (!ok) { 112 136 PyXPCOM_BuildPyException(NS_ERROR_ILLEGAL_VALUE); … … 144 168 PyTypeObject Py_nsIID::type = 145 169 { 146 PyObject_HEAD_INIT(&PyType_Type) 147 0, 170 PyVarObject_HEAD_INIT(&PyType_Type, 0) 148 171 "IID", 149 172 sizeof(Py_nsIID), … … 153 176 PyTypeMethod_getattr, /* tp_getattr */ 154 177 0, /* tp_setattr */ 178 #if PY_MAJOR_VERSION <= 2 155 179 PyTypeMethod_compare, /* tp_compare */ 180 #else 181 0, /* reserved */ 182 #endif 156 183 PyTypeMethod_repr, /* tp_repr */ 157 184 0, /* tp_as_number */ … … 161 188 0, /* tp_call */ 162 189 PyTypeMethod_str, /* tp_str */ 190 0, /* tp_getattro */ 191 0, /* tp_setattro */ 192 0, /* tp_as_buffer */ 193 0, /* tp_flags */ 194 0, /* tp_doc */ 195 0, /* tp_traverse */ 196 0, /* tp_clear */ 197 PyTypeMethod_richcompare, /* tp_richcompare */ 198 0, /* tp_weaklistoffset */ 199 0, /* tp_iter */ 200 0, /* tp_iternext */ 201 0, /* tp_methods */ 202 0, /* tp_members */ 203 0, /* tp_getset */ 204 0, /* tp_base */ 163 205 }; 164 206 … … 184 226 PyObject *ret; 185 227 if (iid_repr != nsnull) { 228 #if PY_MAJOR_VERSION <= 2 186 229 ret = PyString_FromString(iid_repr); 230 #else 231 ret = PyUnicode_FromString(iid_repr); 232 #endif 187 233 nsMemory::Free(iid_repr); 188 234 } else 235 #if PY_MAJOR_VERSION <= 2 189 236 ret = PyString_FromString("<cant get IID info!>"); 237 #else 238 ret = PyUnicode_FromString("<cant get IID info!>"); 239 #endif 190 240 return ret; 191 241 } … … 193 243 } 194 244 245 #if PY_MAJOR_VERSION <= 2 195 246 /* static */ int 196 247 Py_nsIID::PyTypeMethod_compare(PyObject *self, PyObject *other) … … 201 252 return rc == 0 ? 0 : (rc < 0 ? -1 : 1); 202 253 } 254 #endif 255 256 /* static */ PyObject * 257 Py_nsIID::PyTypeMethod_richcompare(PyObject *self, PyObject *other, int op) 258 { 259 PyObject *result = NULL; 260 Py_nsIID *s_iid = (Py_nsIID *)self; 261 Py_nsIID *o_iid = (Py_nsIID *)other; 262 int rc = memcmp(&s_iid->m_iid, &o_iid->m_iid, sizeof(s_iid->m_iid)); 263 switch (op) 264 { 265 case Py_LT: 266 result = rc < 0 ? Py_True : Py_False; 267 break; 268 case Py_LE: 269 result = rc <= 0 ? Py_True : Py_False; 270 break; 271 case Py_EQ: 272 result = rc == 0 ? Py_True : Py_False; 273 break; 274 case Py_NE: 275 result = rc != 0 ? Py_True : Py_False; 276 break; 277 case Py_GT: 278 result = rc > 0 ? Py_True : Py_False; 279 break; 280 case Py_GE: 281 result = rc >= 0 ? Py_True : Py_False; 282 break; 283 } 284 Py_XINCREF(result); 285 return result; 286 } 203 287 204 288 /* static */ PyObject * … … 209 293 char *sziid = s_iid->m_iid.ToString(); 210 294 #ifdef VBOX 211 snprintf(buf, sizeof(buf), "_xpcom.I ID('%s')", sziid);295 snprintf(buf, sizeof(buf), "_xpcom.ID('%s')", sziid); 212 296 #else 213 297 sprintf(buf, "_xpcom.IID('%s')", sziid); 214 298 #endif 215 299 nsMemory::Free(sziid); 300 #if PY_MAJOR_VERSION <= 2 216 301 return PyString_FromString(buf); 302 #else 303 return PyUnicode_FromString(buf); 304 #endif 217 305 } 218 306 … … 222 310 Py_nsIID *s_iid = (Py_nsIID *)self; 223 311 char *sziid = s_iid->m_iid.ToString(); 312 #if PY_MAJOR_VERSION <= 2 224 313 PyObject *ret = PyString_FromString(sziid); 314 #else 315 PyObject *ret = PyUnicode_FromString(sziid); 316 #endif 225 317 nsMemory::Free(sziid); 226 318 return ret; -
trunk/src/libs/xpcom18a4/python/src/PyIInputStream.cpp
r59795 r59809 109 109 } 110 110 if (n==0) { // mozilla will assert if we alloc zero bytes. 111 #if PY_MAJOR_VERSION <= 2 111 112 return PyBuffer_New(0); 113 #else 114 return PyBytes_FromString(""); 115 #endif 112 116 } 113 117 char *buf = (char *)nsMemory::Alloc(n); … … 123 127 PyObject *rc = NULL; 124 128 if ( NS_SUCCEEDED(r) ) { 129 #if PY_MAJOR_VERSION <= 2 125 130 rc = PyBuffer_New(nread); 126 131 if (rc != NULL) { … … 146 151 memcpy(ob_buf, buf, nread); 147 152 } 153 #else 154 rc = PyBytes_FromStringAndSize(buf, nread); 155 #endif 148 156 } else 149 157 PyXPCOM_BuildPyException(r); -
trunk/src/libs/xpcom18a4/python/src/PyIInterfaceInfo.cpp
r59795 r59809 75 75 if ( NS_FAILED(r) ) 76 76 return PyXPCOM_BuildPyException(r); 77 #if PY_MAJOR_VERSION <= 2 77 78 PyObject *ret = PyString_FromString(name); 79 #else 80 PyObject *ret = PyUnicode_FromString(name); 81 #endif 78 82 nsMemory::Free(name); 79 83 return ret; … … 393 397 } 394 398 395 struct PyMethodDef 399 struct PyMethodDef 396 400 PyMethods_IInterfaceInfo[] = 397 401 { -
trunk/src/libs/xpcom18a4/python/src/PyIInterfaceInfoManager.cpp
r59795 r59809 135 135 return PyXPCOM_BuildPyException(r); 136 136 137 #if PY_MAJOR_VERSION <= 2 137 138 PyObject *ret = PyString_FromString(ret_name); 139 #else 140 PyObject *ret = PyUnicode_FromString(ret_name); 141 #endif 138 142 nsMemory::Free(ret_name); 139 143 return ret; … … 186 190 // void autoRegisterInterfaces(); 187 191 188 PyMethodDef 192 PyMethodDef 189 193 PyMethods_IInterfaceInfoManager[] = 190 194 { -
trunk/src/libs/xpcom18a4/python/src/PyISupports.cpp
r59795 r59809 218 218 } 219 219 PyXPCOM_TypeObject *this_type = (PyXPCOM_TypeObject *)ob_type; 220 #if PY_MAJOR_VERSION <= 2 220 221 return Py_FindMethodInChain(&this_type->chain, this, (char *)name); 222 #else 223 PyMethodChain *chain = &this_type->chain; 224 if (name[0] == '_' && name[1] == '_') 225 { 226 if (!strcmp(name, "__doc__")) 227 { 228 const char *doc = ob_type->tp_doc; 229 if (doc) 230 #if PY_MAJOR_VERSION <= 2 231 return PyString_FromString(doc); 232 #else 233 return PyUnicode_FromString(doc); 234 #endif 235 } 236 } 237 while (chain) 238 { 239 PyMethodDef *ml = chain->methods; 240 for (; ml->ml_name; ml++) 241 { 242 if (!strcmp(name, ml->ml_name)) 243 return PyCFunction_New(ml, this); 244 } 245 chain = chain->link; 246 } 247 PyErr_SetString(PyExc_AttributeError, name); 248 return NULL; 249 #endif 221 250 } 222 251 -
trunk/src/libs/xpcom18a4/python/src/PyIVariant.cpp
r59795 r59809 62 62 } 63 63 static PyObject *MyChar( char c) { 64 #if PY_MAJOR_VERSION <= 2 64 65 return PyString_FromStringAndSize(&c, 1); 66 #else 67 return PyUnicode_FromStringAndSize(&c, 1); 68 #endif 65 69 } 66 70 static PyObject *MyUChar( PRUnichar c) { … … 123 127 GET_SIMPLE(nsIID, GetAsID, Py_nsIID::PyObjectFromIID) 124 128 129 #if PY_MAJOR_VERSION <= 2 125 130 GET_ALLOCATED(char *, GetAsString, PyString_FromString, nsMemory::Free) 131 #else 132 GET_ALLOCATED(char *, GetAsString, PyUnicode_FromString, nsMemory::Free) 133 #endif 126 134 GET_ALLOCATED(PRUnichar *, GetAsWString, MyUnicode, nsMemory::Free) 135 #if PY_MAJOR_VERSION <= 2 127 136 GET_ALLOCATED_SIZE(char *, GetAsStringWithSize, PyString_FromStringAndSize, nsMemory::Free) 137 #else 138 GET_ALLOCATED_SIZE(char *, GetAsStringWithSize, PyUnicode_FromStringAndSize, nsMemory::Free) 139 #endif 128 140 GET_ALLOCATED_SIZE(PRUnichar *, GetAsWStringWithSize, PyObject_FromNSString, nsMemory::Free) 129 141 … … 166 178 } 167 179 168 struct PyMethodDef 180 struct PyMethodDef 169 181 PyMethods_IVariant[] = 170 182 { -
trunk/src/libs/xpcom18a4/python/src/Pyxpt_info.cpp
r59795 r59809 55 55 } 56 56 // build an object using the same format as a TypeDescriptor. 57 return Py_BuildValue("bzzz", 57 return Py_BuildValue("bzzz", 58 58 d->flags, 59 59 NULL, NULL, NULL); … … 66 66 return Py_None; 67 67 } 68 return Py_BuildValue("bbbh", 68 return Py_BuildValue("bbbh", 69 69 d->prefix.flags, 70 70 d->argnum, … … 150 150 break; 151 151 case TD_CHAR: 152 #if PY_MAJOR_VERSION <= 2 152 153 v = PyString_FromStringAndSize(&c->value.ch, 1); 154 #else 155 v = PyUnicode_FromStringAndSize(&c->value.ch, 1); 156 #endif 153 157 break; 154 158 case TD_WCHAR: 155 159 v = PyObject_FromNSString((PRUnichar *)&c->value.wch, 1); 156 160 break; 157 // TD_VOID = 13, 161 // TD_VOID = 13, 158 162 case TD_PNSIID: 159 163 v = Py_nsIID::PyObjectFromIID(*c->value.iid); … … 161 165 // TD_DOMSTRING = 15, 162 166 case TD_PSTRING: 167 #if PY_MAJOR_VERSION <= 2 163 168 v = PyString_FromString(c->value.str); 169 #else 170 v = PyUnicode_FromString(c->value.str); 171 #endif 164 172 break; 165 173 case TD_PWSTRING: … … 175 183 // TD_ASTRING = 25 176 184 default: 185 #if PY_MAJOR_VERSION <= 2 177 186 v = PyString_FromString("Unknown type code!!"); 187 #else 188 v = PyUnicode_FromString("Unknown type code!!"); 189 #endif 178 190 break; 179 191 -
trunk/src/libs/xpcom18a4/python/src/TypeObject.cpp
r59795 r59809 53 53 54 54 static PyTypeObject PyInterfaceType_Type = { 55 PyObject_HEAD_INIT(&PyType_Type) 56 0, /* Number of items for varobject */ 55 PyVarObject_HEAD_INIT(&PyType_Type, 0) 57 56 "interface-type", /* Name of this type */ 58 57 sizeof(PyTypeObject), /* Basic object size */ … … 80 79 PyXPCOM_TypeObject::IsType(PyTypeObject *t) 81 80 { 81 #if PY_MAJOR_VERSION <= 2 82 82 return t->ob_type == &PyInterfaceType_Type; 83 #else 84 return Py_TYPE(t) == &PyInterfaceType_Type; 85 #endif 83 86 } 84 87 … … 122 125 } 123 126 127 /*static*/PyObject * 128 PyXPCOM_TypeObject::Py_richcmp(PyObject *self, PyObject *other, int op) 129 { 130 PyObject *result = NULL; 131 int rc = Py_cmp(self, other); 132 switch (op) 133 { 134 case Py_LT: 135 result = rc < 0 ? Py_True : Py_False; 136 break; 137 case Py_LE: 138 result = rc <= 0 ? Py_True : Py_False; 139 break; 140 case Py_EQ: 141 result = rc == 0 ? Py_True : Py_False; 142 break; 143 case Py_NE: 144 result = rc != 0 ? Py_True : Py_False; 145 break; 146 case Py_GT: 147 result = rc > 0 ? Py_True : Py_False; 148 break; 149 case Py_GE: 150 result = rc >= 0 ? Py_True : Py_False; 151 break; 152 } 153 Py_XINCREF(result); 154 return result; 155 } 156 124 157 // @pymethod int|Py_nsISupports|__hash__|Implement a hash-code for the XPCOM object using XPCOM identity rules. 125 158 /*static*/long PyXPCOM_TypeObject::Py_hash(PyObject *self) … … 152 185 char buf[512]; 153 186 #ifdef VBOX 154 snprintf(buf, sizeof(buf), "<XPCOM object (%s) at 0x%p/0x%p>",187 snprintf(buf, sizeof(buf), "<XPCOM object (%s) at %p/%p>", 155 188 iid_repr, (void *)self, (void *)pis->m_obj.get()); 156 189 #else … … 159 192 #endif 160 193 nsMemory::Free(iid_repr); 194 #if PY_MAJOR_VERSION <= 2 161 195 return PyString_FromString(buf); 196 #else 197 return PyUnicode_FromString(buf); 198 #endif 162 199 } 163 200 … … 173 210 if (NS_SUCCEEDED(rv)) 174 211 rv = ss->ToString(&val); 175 } // end-scope 212 } // end-scope 176 213 Py_END_ALLOW_THREADS; 177 214 PyObject *ret; … … 179 216 ret = Py_repr(self); 180 217 else 218 #if PY_MAJOR_VERSION <= 2 181 219 ret = PyString_FromString(val); 220 #else 221 ret = PyUnicode_FromString(val); 222 #endif 182 223 if (val) nsMemory::Free(val); 183 224 return ret; … … 193 234 { 194 235 static const PyTypeObject type_template = { 195 PyObject_HEAD_INIT(&PyInterfaceType_Type) 196 0, /*ob_size*/ 236 PyVarObject_HEAD_INIT(&PyInterfaceType_Type, 0) 197 237 "XPCOMTypeTemplate", /*tp_name*/ 198 sizeof(Py_nsISupports), /*tp_basicsize*/238 sizeof(Py_nsISupports), /*tp_basicsize*/ 199 239 0, /*tp_itemsize*/ 200 240 Py_dealloc, /* tp_dealloc */ … … 202 242 Py_getattr, /* tp_getattr */ 203 243 Py_setattr, /* tp_setattr */ 244 #if PY_MAJOR_VERSION <= 2 204 245 Py_cmp, /* tp_compare */ 246 #else 247 0, /* reserved */ 248 #endif 205 249 Py_repr, /* tp_repr */ 206 250 0, /* tp_as_number*/ 207 251 0, /* tp_as_sequence */ 208 252 0, /* tp_as_mapping */ … … 211 255 Py_str, /* tp_str */ 212 256 0, /* tp_getattro */ 213 0, /* tp_setattro */257 0, /* tp_setattro */ 214 258 0, /* tp_as_buffer */ 215 259 0, /* tp_flags */ … … 217 261 0, /* tp_traverse */ 218 262 0, /* tp_clear */ 219 0,/* tp_richcompare */263 Py_richcmp, /* tp_richcompare */ 220 264 0, /* tp_weaklistoffset */ 221 265 0, /* tp_iter */ -
trunk/src/libs/xpcom18a4/python/src/VariantUtils.cpp
r59795 r59809 84 84 PRUint32 size; 85 85 PyObject *s; 86 void *src; 86 87 PRUnichar *dest; 87 88 … … 89 90 if (!s) 90 91 return -1; 92 // Drop the UTF-16 byte order mark at the beginning of 93 // the string. (See the docs on PyUnicode_AsUTF16String.) 94 // Some Mozilla libraries don't like the mark. 95 #if PY_MAJOR_VERSION <= 2 91 96 size = (PyString_GET_SIZE(s) - 2) / sizeof(PRUnichar); 97 src = PyString_AS_STRING(s) + 2; 98 #else 99 if (!PyBytes_Check(obj)) 100 { 101 PyErr_SetString(PyExc_TypeError, "internal error in PyXPCOM, parameter must be a bytes object"); 102 return -1; 103 } 104 size = (PyBytes_GET_SIZE(obj) - 2) / sizeof(PRUnichar); 105 src = PyBytes_AS_STRING(obj) + 2; 106 #endif 92 107 dest = (PRUnichar *)nsMemory::Alloc(sizeof(PRUnichar) * (size + 1)); 93 108 if (!dest) { … … 96 111 return -1; 97 112 } 98 // Drop the UTF-16 byte order mark at the beginning of 99 // the string. (See the docs on PyUnicode_AsUTF16String.) 100 // Some Mozilla libraries don't like the mark. 101 memcpy(dest, PyString_AS_STRING(s) + 2, sizeof(PRUnichar) * size); 113 memcpy(dest, src, sizeof(PRUnichar) * size); 102 114 Py_DECREF(s); 103 115 dest[size] = 0; … … 116 128 } else { 117 129 if (bAssumeUTF8) { 118 119 130 const nsPromiseFlatCString& temp = PromiseFlatCString(s); 131 ret = PyUnicode_DecodeUTF8(temp.get(), temp.Length(), NULL); 120 132 } else { 133 #if PY_MAJOR_VERSION <= 2 121 134 ret = PyString_FromStringAndSize(NULL, s.Length()); 135 #else 136 ret = PyUnicode_FromStringAndSize(NULL, s.Length()); 137 #endif 122 138 if (!ret) 123 139 return NULL; 124 140 // Need "CopyAsciiTo"!? 125 141 nsACString::const_iterator fromBegin, fromEnd; 126 char* dest = PyString_AS_STRING(ret); 142 #if PY_MAJOR_VERSION <= 2 143 char* dest = (char *)PyString_AS_STRING(ret); 144 #else 145 char* dest = (char *)PyUnicode_AsUTF8(ret); 146 #endif 127 147 copy_string(s.BeginReading(fromBegin), s.EndReading(fromEnd), dest); 128 148 } … … 159 179 PyObject *val_use = NULL; 160 180 PRBool ok = PR_TRUE; 181 #if PY_MAJOR_VERSION <= 2 161 182 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 162 183 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 165 186 if (ok && (val_use = PyUnicode_FromObject(val))==NULL) 166 187 ok = PR_FALSE; 188 #else 189 if (!PyUnicode_Check(val)) { 190 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 191 ok = PR_FALSE; 192 } 193 val_use = val; 194 Py_INCREF(val_use); 195 #endif 167 196 if (ok) { 168 197 if (PyUnicode_GET_SIZE(val_use) == 0) { … … 353 382 // If it is NOT a string, we just fall through and allow the standard 354 383 // sequence unpack code process it (just slower!) 384 #if PY_MAJOR_VERSION <= 2 355 385 if ( array_type == nsXPTType::T_U8 && 356 386 (PyString_Check(sequence_ob) || PyUnicode_Check(sequence_ob))) { 387 #else 388 if ( array_type == nsXPTType::T_U8 && PyUnicode_Check(sequence_ob)) { 389 #endif 357 390 358 391 PRBool release_seq; 359 392 if (PyUnicode_Check(sequence_ob)) { 360 393 release_seq = PR_TRUE; 394 #if PY_MAJOR_VERSION <= 2 361 395 sequence_ob = PyObject_Str(sequence_ob); 396 #else 397 sequence_ob = PyUnicode_AsUTF8String(sequence_ob); 398 #endif 362 399 } else 363 400 release_seq = PR_FALSE; 364 401 if (!sequence_ob) // presumably a memory error, or Unicode encoding error. 365 402 return PR_FALSE; 403 #if PY_MAJOR_VERSION <= 2 366 404 memcpy(pthis, PyString_AS_STRING(sequence_ob), sequence_size); 405 #else 406 memcpy(pthis, PyUnicode_AsUTF8(sequence_ob), sequence_size); 407 #endif 367 408 if (release_seq) 368 409 { … … 423 464 break; 424 465 case nsXPTType::T_CHAR: 466 #if PY_MAJOR_VERSION <= 2 425 467 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 426 468 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 432 474 NS_ABORT_IF_FALSE(PyString_Check(val_use), "PyObject_Str didnt return a string object!"); 433 475 FILL_SIMPLE_POINTER( char, *PyString_AS_STRING(val_use) ); 476 #else 477 if (!PyUnicode_Check(val)) { 478 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 479 BREAK_FALSE; 480 } 481 FILL_SIMPLE_POINTER( char, *PyUnicode_AsUTF8(val) ); 482 #endif 434 483 break; 435 484 436 485 case nsXPTType::T_WCHAR: 486 #if PY_MAJOR_VERSION <= 2 437 487 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 438 488 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); 439 489 BREAK_FALSE; 440 490 } 491 #else 492 if (!PyUnicode_Check(val)) { 493 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 494 BREAK_FALSE; 495 } 496 #endif 441 497 if ((val_use = PyUnicode_FromObject(val)) == NULL) 442 498 BREAK_FALSE; … … 474 530 if (val == Py_None) 475 531 break; // Remains NULL. 532 #if PY_MAJOR_VERSION <= 2 476 533 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 477 534 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 485 542 const char *sz = PyString_AS_STRING(val_use); 486 543 int nch = PyString_GET_SIZE(val_use); 544 #else 545 if (!PyUnicode_Check(val)) { 546 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 547 BREAK_FALSE; 548 } 549 if ((val_use = PyUnicode_AsUTF8String(val))==NULL) 550 BREAK_FALSE; 551 552 const char *sz = PyBytes_AS_STRING(val_use); 553 int nch = PyBytes_GET_SIZE(val_use); 554 #endif 487 555 488 556 *pp = (char *)nsMemory::Alloc(nch+1); … … 502 570 if (val == Py_None) 503 571 break; // Remains NULL. 572 #if PY_MAJOR_VERSION <= 2 504 573 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 505 574 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 509 578 BREAK_FALSE; 510 579 NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!"); 580 #else 581 if (!PyUnicode_Check(val)) { 582 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 583 BREAK_FALSE; 584 } 585 val_use = val; 586 Py_INCREF(val_use); 587 #endif 511 588 if (PyUnicode_AsPRUnichar(val_use, pp, NULL) < 0) 512 589 BREAK_FALSE; … … 549 626 } 550 627 if (array_type == nsXPTType::T_U8) 628 #if PY_MAJOR_VERSION <= 2 551 629 return PyString_FromStringAndSize( (char *)array_ptr, sequence_size ); 630 #else 631 return PyUnicode_FromStringAndSize( (char *)array_ptr, sequence_size ); 632 #endif 552 633 553 634 PRUint32 array_element_size = GetArrayElementSize(array_type); … … 599 680 val = Py_None; 600 681 } else 682 #if PY_MAJOR_VERSION <= 2 601 683 val = PyString_FromString(*pp); 684 #else 685 val = PyUnicode_FromString(*pp); 686 #endif 602 687 break; 603 688 } … … 632 717 sprintf(buf, "Unknown XPCOM array type flags (0x%x)", array_type); 633 718 PyXPCOM_LogWarning("%s - returning a string object with this message!\n", buf); 719 #if PY_MAJOR_VERSION <= 2 634 720 val = PyString_FromString(buf); 721 #else 722 val = PyUnicode_FromString(buf); 723 #endif 635 724 break; 636 725 } … … 670 759 if (PyFloat_Check(ob)) 671 760 return nsIDataType::VTYPE_DOUBLE; 761 #if PY_MAJOR_VERSION <= 2 672 762 if (PyString_Check(ob)) 673 763 return nsIDataType::VTYPE_STRING_SIZE_IS; 764 #endif 674 765 if (PyUnicode_Check(ob)) 675 766 return nsIDataType::VTYPE_WSTRING_SIZE_IS; … … 726 817 break; 727 818 case nsIDataType::VTYPE_STRING_SIZE_IS: 819 #if PY_MAJOR_VERSION <= 2 728 820 nr = v->SetAsStringWithSize(PyString_Size(ob), PyString_AsString(ob)); 821 #else 822 Py_ssize_t cb; 823 const char *psz; 824 psz = PyUnicode_AsUTF8AndSize(ob, &cb); 825 nr = v->SetAsStringWithSize(cb, psz); 826 #endif 729 827 break; 730 828 case nsIDataType::VTYPE_WSTRING_SIZE_IS: … … 1296 1394 break; 1297 1395 case nsXPTType::T_CHAR:{ 1396 #if PY_MAJOR_VERSION <= 2 1298 1397 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 1299 1398 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 1310 1409 1311 1410 ns_v.val.c = *PyString_AS_STRING(val_use); 1411 #else 1412 if (!PyUnicode_Check(val)) { 1413 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 1414 BREAK_FALSE; 1415 } 1416 if (PyUnicode_GET_SIZE(val) != 1) { 1417 PyErr_SetString(PyExc_ValueError, "Must specify a one character string for a character"); 1418 BREAK_FALSE; 1419 } 1420 1421 ns_v.val.c = *PyUnicode_AS_UNICODE(val_use); 1422 #endif 1312 1423 break; 1313 1424 } 1314 1425 1315 1426 case nsXPTType::T_WCHAR: { 1427 #if PY_MAJOR_VERSION <= 2 1316 1428 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 1317 1429 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); 1318 1430 BREAK_FALSE; 1319 1431 } 1432 #else 1433 if (!PyUnicode_Check(val)) { 1434 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 1435 BREAK_FALSE; 1436 } 1437 #endif 1320 1438 if ((val_use = PyUnicode_FromObject(val))==NULL) 1321 1439 BREAK_FALSE; 1322 // Sanity check should Py Object_Str() ever loosen its semantics wrt Unicode!1440 // Sanity check should PyUnicode_FromObject() ever loosen its semantics wrt Unicode! 1323 1441 NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a unicode object!"); 1324 if (PyUnicode_G etSize(val_use) != 1) {1442 if (PyUnicode_GET_SIZE(val_use) != 1) { 1325 1443 PyErr_SetString(PyExc_ValueError, "Must specify a one character string for a character"); 1326 1444 BREAK_FALSE; … … 1360 1478 ns_v.val.p = new nsCString(); 1361 1479 } else { 1362 // strings are assumed to already be UTF8 encoded. 1480 #if PY_MAJOR_VERSION <= 2 1363 1481 if (PyString_Check(val)) { 1482 // strings are assumed to already be UTF8 encoded. 1364 1483 val_use = val; 1365 1484 Py_INCREF(val); 1366 // Unicode objects are encoded by us. 1367 } else if (PyUnicode_Check(val)) { 1485 } 1486 else 1487 #endif 1488 if (PyUnicode_Check(val)) { 1489 // Unicode objects are encoded by us. 1368 1490 if (bIsUTF8) 1369 1491 val_use = PyUnicode_AsUTF8String(val); 1370 1492 else 1493 #if PY_MAJOR_VERSION <= 2 1371 1494 val_use = PyObject_Str(val); 1495 #else 1496 val_use = PyUnicode_AsUTF8String(val); 1497 #endif 1372 1498 } else { 1499 #if PY_MAJOR_VERSION <= 2 1373 1500 PyErr_SetString(PyExc_TypeError, "UTF8 parameters must be string or Unicode objects"); 1501 #else 1502 PyErr_SetString(PyExc_TypeError, "UTF8 parameters must be unicode objects"); 1503 #endif 1374 1504 BREAK_FALSE; 1375 1505 } 1376 1506 if (!val_use) 1377 1507 BREAK_FALSE; 1508 #if PY_MAJOR_VERSION <= 2 1378 1509 ns_v.val.p = new nsCString(PyString_AS_STRING(val_use), 1379 1510 PyString_GET_SIZE(val_use)); 1511 #else 1512 ns_v.val.p = new nsCString(PyBytes_AS_STRING(val_use), 1513 PyBytes_GET_SIZE(val_use)); 1514 #endif 1380 1515 } 1381 1516 … … 1393 1528 break; 1394 1529 } 1530 #if PY_MAJOR_VERSION <= 2 1395 1531 // If an "in" char *, and we have a PyString, then pass the 1396 1532 // pointer (hoping everyone else plays by the rules too. 1397 1533 if (!XPT_PD_IS_OUT(td.param_flags) && PyString_Check(val)) { 1398 ns_v.val.p = PyString_AS_STRING(val);1534 ns_v.val.p = (void *)PyString_AS_STRING(val); 1399 1535 break; 1400 1536 } … … 1412 1548 MAKE_VALUE_BUFFER(cb_this_buffer_pointer); 1413 1549 memcpy(this_buffer_pointer, PyString_AS_STRING(val_use), cb_this_buffer_pointer); 1550 #else 1551 1552 if (!PyUnicode_Check(val)) { 1553 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 1554 BREAK_FALSE; 1555 } 1556 if ((val_use = PyUnicode_AsUTF8String(val))==NULL) 1557 BREAK_FALSE; 1558 1559 cb_this_buffer_pointer = PyBytes_GET_SIZE(val_use)+1; 1560 MAKE_VALUE_BUFFER(cb_this_buffer_pointer); 1561 memcpy(this_buffer_pointer, PyBytes_AS_STRING(val_use), cb_this_buffer_pointer); 1562 #endif 1414 1563 ns_v.val.p = this_buffer_pointer; 1415 1564 break; … … 1421 1570 break; 1422 1571 } 1572 #if PY_MAJOR_VERSION <= 2 1423 1573 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 1424 1574 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 1428 1578 BREAK_FALSE; 1429 1579 NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!"); 1580 #else 1581 if (!PyUnicode_Check(val)) { 1582 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 1583 BREAK_FALSE; 1584 } 1585 val_use = val; 1586 Py_INCREF(val_use); 1587 #endif 1430 1588 PRUnichar *sv; 1431 1589 PRUint32 nch; … … 1484 1642 break; 1485 1643 } 1644 #if PY_MAJOR_VERSION <= 2 1486 1645 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 1487 1646 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 1496 1655 MAKE_VALUE_BUFFER(cb_this_buffer_pointer); 1497 1656 memcpy(this_buffer_pointer, PyString_AS_STRING(val_use), cb_this_buffer_pointer); 1657 #else 1658 if (!PyUnicode_Check(val)) { 1659 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 1660 BREAK_FALSE; 1661 } 1662 if ((val_use = PyUnicode_AsUTF8String(val))==NULL) 1663 BREAK_FALSE; 1664 1665 cb_this_buffer_pointer = PyBytes_GET_SIZE(val_use); 1666 MAKE_VALUE_BUFFER(cb_this_buffer_pointer); 1667 memcpy(this_buffer_pointer, PyBytes_AS_STRING(val_use), cb_this_buffer_pointer); 1668 #endif 1498 1669 ns_v.val.p = this_buffer_pointer; 1499 1670 rc = SetSizeIs(value_index, PR_TRUE, cb_this_buffer_pointer); … … 1506 1677 break; 1507 1678 } 1679 #if PY_MAJOR_VERSION <= 2 1508 1680 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 1509 1681 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 1514 1686 // Sanity check should PyObject_Str() ever loosen its semantics wrt Unicode! 1515 1687 NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyObject_Unicode didnt return a unicode object!"); 1688 #else 1689 if (!PyUnicode_Check(val)) { 1690 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 1691 BREAK_FALSE; 1692 } 1693 val_use = val; 1694 Py_INCREF(val_use); 1695 #endif 1516 1696 PRUnichar *sv; 1517 1697 PRUint32 nch; … … 1719 1899 break; 1720 1900 case nsXPTType::T_CHAR: 1901 #if PY_MAJOR_VERSION <= 2 1721 1902 ret = PyString_FromStringAndSize( ((char *)ns_v.ptr), 1 ); 1903 #else 1904 ret = PyUnicode_FromStringAndSize( ((char *)ns_v.ptr), 1 ); 1905 #endif 1722 1906 break; 1723 1907 … … 1747 1931 Py_INCREF(Py_None); 1748 1932 } else 1933 #if PY_MAJOR_VERSION <= 2 1749 1934 ret = PyString_FromString( *((char **)ns_v.ptr) ); 1935 #else 1936 ret = PyUnicode_FromString( *((char **)ns_v.ptr) ); 1937 #endif 1750 1938 break; 1751 1939 … … 1828 2016 } else { 1829 2017 PRUint32 string_size = GetSizeIs(index, PR_TRUE); 2018 #if PY_MAJOR_VERSION <= 2 1830 2019 ret = PyString_FromStringAndSize( *((char **)ns_v.ptr), string_size ); 2020 #else 2021 ret = PyUnicode_FromStringAndSize( *((char **)ns_v.ptr), string_size ); 2022 #endif 1831 2023 } 1832 2024 break; … … 2083 2275 case nsXPTType::T_CHAR: { 2084 2276 char temp = DEREF_IN_OR_OUT(ns_v.val.c, char); 2277 #if PY_MAJOR_VERSION <= 2 2085 2278 ret = PyString_FromStringAndSize(&temp, 1); 2279 #else 2280 ret = PyUnicode_FromStringAndSize(&temp, 1); 2281 #endif 2086 2282 break; 2087 2283 } … … 2116 2312 Py_INCREF(Py_None); 2117 2313 } else 2314 #if PY_MAJOR_VERSION <= 2 2118 2315 ret = PyString_FromString(t); 2316 #else 2317 ret = PyUnicode_FromString(t); 2318 #endif 2119 2319 break; 2120 2320 } … … 2178 2378 Py_INCREF(Py_None); 2179 2379 } else 2380 #if PY_MAJOR_VERSION <= 2 2180 2381 ret = PyString_FromStringAndSize(t, string_size); 2382 #else 2383 ret = PyUnicode_FromStringAndSize(t, string_size); 2384 #endif 2181 2385 break; 2182 2386 } … … 2199 2403 sprintf(buf, "Unknown XPCOM type flags (0x%x)", td.type_flags); 2200 2404 PyXPCOM_LogWarning("%s - returning a string object with this message!\n", buf); 2405 #if PY_MAJOR_VERSION <= 2 2201 2406 ret = PyString_FromString(buf); 2407 #else 2408 ret = PyUnicode_FromString(buf); 2409 #endif 2202 2410 break; 2203 2411 } … … 2340 2548 break; 2341 2549 case nsXPTType::T_CHAR: 2550 #if PY_MAJOR_VERSION <= 2 2342 2551 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 2343 2552 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 2349 2558 NS_ABORT_IF_FALSE(PyString_Check(val_use), "PyObject_Str didnt return a string object!"); 2350 2559 FILL_SIMPLE_POINTER( char, *PyString_AS_STRING(val_use) ); 2560 #else 2561 if (!PyUnicode_Check(val)) { 2562 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 2563 BREAK_FALSE; 2564 } 2565 FILL_SIMPLE_POINTER( char, *PyUnicode_AS_UNICODE(val) ); 2566 #endif 2351 2567 break; 2352 2568 2353 2569 case nsXPTType::T_WCHAR: 2570 #if PY_MAJOR_VERSION <= 2 2354 2571 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 2355 2572 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); 2356 2573 BREAK_FALSE; 2357 2574 } 2575 #else 2576 if (!PyUnicode_Check(val)) { 2577 PyErr_SetString(PyExc_TypeError, "This parameter must be a Unicode object"); 2578 BREAK_FALSE; 2579 } 2580 #endif 2358 2581 if ((val_use = PyUnicode_FromObject(val))==NULL) 2359 2582 BREAK_FALSE; … … 2395 2618 NS_ABORT_IF_FALSE(0, "dont handle None here yet"); 2396 2619 } else { 2620 #if PY_MAJOR_VERSION <= 2 2397 2621 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 2398 2622 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 2402 2626 NS_ABORT_IF_FALSE(PyString_Check(val_use), "PyObject_Str didnt return a string object!"); 2403 2627 const char *sz = PyString_AS_STRING(val_use); 2404 ws->Assign(sz, PyString_Size(val_use)); 2628 ws->Assign(sz, PyString_GET_SIZE(val_use)); 2629 #else 2630 if (!PyUnicode_Check(val)) { 2631 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 2632 BREAK_FALSE; 2633 } 2634 val_use = PyUnicode_AsUTF8String(val); 2635 const char *sz = PyBytes_AS_STRING(val_use); 2636 ws->Assign(sz, PyBytes_GET_SIZE(val_use)); 2637 #endif 2405 2638 } 2406 2639 break; … … 2412 2645 NS_ABORT_IF_FALSE(0, "dont handle None here yet"); 2413 2646 } else { 2647 #if PY_MAJOR_VERSION <= 2 2414 2648 if (PyString_Check(val)) { 2415 2649 val_use = val; 2416 2650 Py_INCREF(val); 2417 } else if (PyUnicode_Check(val)) { 2651 } 2652 else 2653 #endif 2654 if (PyUnicode_Check(val)) { 2418 2655 val_use = PyUnicode_AsUTF8String(val); 2419 2656 } else { 2657 #if PY_MAJOR_VERSION <= 2 2420 2658 PyErr_SetString(PyExc_TypeError, "UTF8 parameters must be string or Unicode objects"); 2421 BREAK_FALSE; 2422 } 2659 #else 2660 PyErr_SetString(PyExc_TypeError, "UTF8 parameters must be unicode objects"); 2661 #endif 2662 BREAK_FALSE; 2663 } 2664 #if PY_MAJOR_VERSION <= 2 2423 2665 NS_ABORT_IF_FALSE(PyString_Check(val_use), "must have a string object!"); 2424 2666 const char *sz = PyString_AS_STRING(val_use); 2425 ws->Assign(sz, PyString_Size(val_use)); 2667 ws->Assign(sz, PyString_GET_SIZE(val_use)); 2668 #else 2669 NS_ABORT_IF_FALSE(PyBytes_Check(val_use), "must have a bytes object!"); 2670 const char *sz = PyBytes_AS_STRING(val_use); 2671 ws->Assign(sz, PyBytes_GET_SIZE(val_use)); 2672 #endif 2426 2673 } 2427 2674 break; … … 2437 2684 if (val == Py_None) 2438 2685 break; // Remains NULL. 2686 #if PY_MAJOR_VERSION <= 2 2439 2687 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 2440 2688 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 2448 2696 const char *sz = PyString_AS_STRING(val_use); 2449 2697 int nch = PyString_GET_SIZE(val_use); 2698 #else 2699 if (!PyUnicode_Check(val)) { 2700 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 2701 BREAK_FALSE; 2702 } 2703 if ((val_use = PyUnicode_AsUTF8String(val))==NULL) 2704 BREAK_FALSE; 2705 2706 const char *sz = PyBytes_AS_STRING(val_use); 2707 int nch = PyBytes_GET_SIZE(val_use); 2708 #endif 2450 2709 2451 2710 *pp = (char *)nsMemory::Alloc(nch+1); … … 2465 2724 if (val == Py_None) 2466 2725 break; // Remains NULL. 2726 #if PY_MAJOR_VERSION <= 2 2467 2727 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 2468 2728 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 2471 2731 val_use = PyUnicode_FromObject(val); 2472 2732 NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!"); 2733 #else 2734 if (!PyUnicode_Check(val)) { 2735 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 2736 BREAK_FALSE; 2737 } 2738 val_use = val; 2739 Py_INCREF(val_use); 2740 #endif 2473 2741 if (PyUnicode_AsPRUnichar(val_use, pp, NULL) < 0) 2474 2742 BREAK_FALSE; … … 2525 2793 PRUint32 nch = 0; 2526 2794 if (val != Py_None) { 2795 #if PY_MAJOR_VERSION <= 2 2527 2796 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 2528 2797 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 2536 2805 sz = PyString_AS_STRING(val_use); 2537 2806 nch = PyString_GET_SIZE(val_use); 2807 #else 2808 if (!PyUnicode_Check(val)) { 2809 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 2810 BREAK_FALSE; 2811 } 2812 if ((val_use = PyUnicode_AsUTF8String(val))==NULL) 2813 BREAK_FALSE; 2814 2815 sz = PyBytes_AS_STRING(val_use); 2816 nch = PyBytes_GET_SIZE(val_use); 2817 #endif 2538 2818 } 2539 2819 PRBool bBackFill = PR_FALSE; … … 2582 2862 2583 2863 if (val != Py_None) { 2864 #if PY_MAJOR_VERSION <= 2 2584 2865 if (!PyString_Check(val) && !PyUnicode_Check(val)) { 2585 2866 PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object"); … … 2588 2869 val_use = PyUnicode_FromObject(val); 2589 2870 NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a Unicode object!"); 2871 #else 2872 if (!PyUnicode_Check(val)) { 2873 PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object"); 2874 BREAK_FALSE; 2875 } 2876 val_use = val; 2877 Py_INCREF(val_use); 2878 #endif 2590 2879 if (PyUnicode_AsPRUnichar(val_use, &sz, &nch) < 0) 2591 2880 BREAK_FALSE; … … 2750 3039 // But the retval is often the last param described in the info. 2751 3040 if (!PySequence_Check(user_result) || 3041 #if PY_MAJOR_VERSION <= 2 2752 3042 PyString_Check(user_result) || 3043 #else 3044 PyBytes_Check(user_result) || 3045 #endif 2753 3046 PyUnicode_Check(user_result)) { 2754 3047 PyErr_SetString(PyExc_TypeError, "This function has multiple results, but a sequence was not given to fill them"); -
trunk/src/libs/xpcom18a4/python/src/dllmain.cpp
r59795 r59809 196 196 CEnterLeaveXPCOMFramework _celf; 197 197 PRInt32 cnt = PR_AtomicIncrement(&g_cLockCount); 198 if (cnt==1) { // First call 198 if (cnt==1) { // First call 199 199 if (!Py_IsInitialized()) { 200 200 Py_Initialize(); … … 204 204 if (PySys_GetObject((char*)"argv")==NULL) { 205 205 PyObject *path = PyList_New(0); 206 #if PY_MAJOR_VERSION <= 2 206 207 PyObject *str = PyString_FromString(""); 208 #else 209 PyObject *str = PyUnicode_FromString(""); 210 #endif 207 211 PyList_Append(path, str); 208 212 PySys_SetObject((char*)"argv", path); … … 246 250 PR_DestroyLock(g_lockMain); 247 251 #ifndef PYXPCOM_USE_PYGILSTATE 248 // I can't locate a way to kill this - 252 // I can't locate a way to kill this - 249 253 // should I pass a dtor to PR_NewThreadPrivateIndex?? 250 254 // TlsFree(tlsIndex); … … 330 334 bHaveInitXPCOM = PR_TRUE; 331 335 // Register our custom interfaces. 332 336 333 337 Py_nsISupports::InitType(); 334 338 Py_nsIComponentManager::InitType(); … … 342 346 // for backward compatibility: 343 347 Py_nsIComponentManagerObsolete::InitType(); 344 348 345 349 } 346 350 return rc; -
trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp
r59795 r59809 84 84 # endif 85 85 # ifdef VBOX_PYXPCOM_VERSIONED 86 # if PY_VERSION_HEX >= 0x02080000 86 # if PY_VERSION_HEX >= 0x03080000 && PY_VERSION_HEX < 0x03090000 87 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython3_8") 88 # define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_8) 89 90 # elif PY_VERSION_HEX >= 0x03070000 && PY_VERSION_HEX < 0x03080000 91 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython3_7") 92 # define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_7) 93 94 # elif PY_VERSION_HEX >= 0x03060000 && PY_VERSION_HEX < 0x03070000 95 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython3_6") 96 # define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_6) 97 98 # elif PY_VERSION_HEX >= 0x03050000 && PY_VERSION_HEX < 0x03060000 99 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython3_5") 100 # define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_5) 101 102 # elif PY_VERSION_HEX >= 0x03040000 && PY_VERSION_HEX < 0x03050000 103 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython3_4") 104 # define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_4) 105 106 # elif PY_VERSION_HEX >= 0x03030000 && PY_VERSION_HEX < 0x03040000 107 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython3_3") 108 # define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_3) 109 110 # elif PY_VERSION_HEX >= 0x03020000 && PY_VERSION_HEX < 0x03030000 111 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython3_2") 112 # define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_2) 113 114 # elif PY_VERSION_HEX >= 0x03010000 && PY_VERSION_HEX < 0x03020000 115 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython3_1") 116 # define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython3_1) 117 118 # elif PY_VERSION_HEX >= 0x02080000 && PY_VERSION_HEX < 0x02090000 87 119 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython2_8") 88 120 # define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_8) 89 121 90 # elif PY_VERSION_HEX >= 0x02070000 122 # elif PY_VERSION_HEX >= 0x02070000 && PY_VERSION_HEX < 0x02080000 91 123 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython2_7") 92 124 # define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_7) 93 125 94 # elif PY_VERSION_HEX >= 0x02060000 126 # elif PY_VERSION_HEX >= 0x02060000 && PY_VERSION_HEX < 0x02070000 95 127 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython2_6") 96 128 # define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_6) 97 98 # elif PY_VERSION_HEX >= 0x0205000099 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython2_5")100 # define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_5)101 102 # elif PY_VERSION_HEX >= 0x02040000103 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython2_4")104 # define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_4)105 106 # elif PY_VERSION_HEX >= 0x02030000107 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython2_3")108 # define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_3)109 129 # else 110 # error "Fix module versioning. "130 # error "Fix module versioning. This Python version is not recognized." 111 131 # endif 112 132 # else 113 133 # define MODULE_NAME MANGLE_MODULE_NAME("VBoxPython") 114 # define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython) 134 # if PY_MAJOR_VERSION <= 2 135 # define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython) 136 # else 137 # define initVBoxPython MANGLE_MODULE_INIT(PyInit_VBoxPython) 138 # endif 115 139 # endif 116 140 #else … … 121 145 // interface support! 122 146 147 #ifndef VBOX 123 148 /* deprecated, included for backward compatibility */ 124 149 static PyObject * … … 143 168 return Py_nsISupports::PyObjectFromInterface(ocm, NS_GET_IID(nsIComponentManagerObsolete), PR_FALSE); 144 169 } 170 #endif 145 171 146 172 static PyObject * … … 195 221 } 196 222 223 #ifndef VBOX 197 224 /* deprecated, included for backward compatibility */ 198 225 static PyObject * … … 204 231 return PyXPCOMMethod_GetComponentManager(self, args); 205 232 } 233 #endif 206 234 207 235 static PyObject * … … 500 528 if (!PyArg_ParseTuple(args, "i", &bufSize)) 501 529 return NULL; 530 #if PY_MAJOR_VERSION <= 2 502 531 return PyBuffer_New(bufSize); 532 #else 533 return PyBytes_FromStringAndSize(NULL, bufSize); 534 #endif 503 535 } 504 536 … … 671 703 {"GetComponentManager", PyXPCOMMethod_GetComponentManager, 1}, 672 704 {"GetComponentRegistrar", PyXPCOMMethod_GetComponentRegistrar, 1}, 705 #ifndef VBOX 673 706 {"NS_GetGlobalComponentManager", PyXPCOMMethod_NS_GetGlobalComponentManager, 1}, // deprecated 707 #endif 674 708 {"XPTI_GetInterfaceInfoManager", PyXPCOMMethod_XPTI_GetInterfaceInfoManager, 1}, 675 709 {"XPTC_InvokeByIndex", PyXPCOMMethod_XPTC_InvokeByIndex, 1}, 676 710 {"GetServiceManager", PyXPCOMMethod_GetServiceManager, 1}, 711 #ifndef VBOX 677 712 {"GetGlobalServiceManager", PyXPCOMMethod_GetGlobalServiceManager, 1}, // deprecated 678 713 {"IID", PyXPCOMMethod_IID, 1}, // IID is wrong - deprecated - not just IID, but CID, etc. 714 #endif 679 715 {"ID", PyXPCOMMethod_IID, 1}, // This is the official name. 680 716 {"NS_ShutdownXPCOM", PyXPCOMMethod_NS_ShutdownXPCOM, 1}, … … 691 727 {"GetVariantValue", PyXPCOMMethod_GetVariantValue, 1}, 692 728 #ifdef VBOX 693 694 695 696 697 729 {"WaitForEvents", PyXPCOMMethod_WaitForEvents, 1}, 730 {"InterruptWait", PyXPCOMMethod_InterruptWait, 1}, 731 {"DeinitCOM", PyXPCOMMethod_DeinitCOM, 1}, 732 {"AttachThread", PyXPCOMMethod_AttachThread, 1}, 733 {"DetachThread", PyXPCOMMethod_DetachThread, 1}, 698 734 #endif 699 735 #ifdef VBOX_DEBUG_LIFETIMES … … 705 741 }; 706 742 743 #if PY_MAJOR_VERSION >= 3 744 static struct PyModuleDef xpcom_module = 745 { 746 PyModuleDef_HEAD_INIT, 747 MODULE_NAME, /* name of module */ 748 NULL, /* module documentation */ 749 -1, /* size of per-interpreter state or -1 if using globals */ 750 xpcom_methods 751 }; 752 #endif 753 754 707 755 #define REGISTER_IID(t) { \ 708 756 PyObject *iid_ob = Py_nsIID::PyObjectFromIID(NS_GET_IID(t)); \ … … 721 769 // The module init code. 722 770 // 771 #if PY_MAJOR_VERSION <= 2 723 772 extern "C" NS_EXPORT 724 773 void 774 #else 775 PyObject * 776 #endif 725 777 init_xpcom() { 726 778 PyObject *oModule; … … 728 780 // ensure the framework has valid state to work with. 729 781 if (!PyXPCOM_Globals_Ensure()) 782 #if PY_MAJOR_VERSION <= 2 730 783 return; 784 #else 785 return NULL; 786 #endif 731 787 732 788 // Must force Python to start using thread locks … … 734 790 735 791 // Create the module and add the functions 792 #if PY_MAJOR_VERSION <= 2 736 793 oModule = Py_InitModule(MODULE_NAME, xpcom_methods); 794 #else 795 oModule = PyModule_Create(&xpcom_module); 796 #endif 737 797 738 798 PyObject *dict = PyModule_GetDict(oModule); … … 741 801 { 742 802 PyErr_SetString(PyExc_MemoryError, "can't define error"); 803 #if PY_MAJOR_VERSION <= 2 743 804 return; 805 #else 806 return NULL; 807 #endif 744 808 } 745 809 PyDict_SetItemString(dict, "IIDType", (PyObject *)&Py_nsIID::type); … … 784 848 PyDict_SetItemString(dict, "NS_DEBUG", ob); 785 849 Py_DECREF(ob); 850 #if PY_MAJOR_VERSION >= 3 851 return oModule; 852 #endif 786 853 } 787 854 … … 795 862 #include <iprt/stream.h> 796 863 864 #if PY_MAJOR_VERSION <= 2 797 865 extern "C" NS_EXPORT 798 866 void 867 #else 868 /** @todo r=klaus this is hacky, but as Python3 doesn't deal with ELF 869 * visibility, assuming that all globals are visible (which is ugly and not 870 * true in our case). */ 871 #undef PyMODINIT_FUNC 872 #define PyMODINIT_FUNC extern "C" NS_EXPORT PyObject* 873 PyMODINIT_FUNC 874 #endif 799 875 initVBoxPython() { /* NOTE! This name is redefined at the top of the file! */ 800 876 static bool s_vboxInited = false; … … 819 895 rc = com::Initialize(); 820 896 897 #if PY_MAJOR_VERSION <= 2 821 898 init_xpcom(); 899 #else 900 return init_xpcom(); 901 #endif 822 902 } 903 #if PY_MAJOR_VERSION >= 3 904 return NULL; 905 #endif 823 906 } 824 907
Note:
See TracChangeset
for help on using the changeset viewer.