VirtualBox

Changeset 59809 in vbox for trunk/src/libs/xpcom18a4/python


Ignore:
Timestamp:
Feb 24, 2016 10:12:21 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105691
Message:

re-applied the remaining changes which were backed out in r105674

Location:
trunk/src/libs/xpcom18a4/python
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/python/Makefile.kmk

    r59800 r59809  
    55
    66#
    7 # Copyright (C) 2009-2015 Oracle Corporation
     7# Copyright (C) 2009-2016 Oracle Corporation
    88#
    99# This file is part of VirtualBox Open Source Edition (OSE), as
     
    2727#
    2828# 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.
    3031#
    3132ifeq ($(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.5
    34   VBOX_PYTHON25_LIB = $(VBOX_PATH_MACOSX_SDK)/usr/lib/libpython2.5.dylib
    35   VBOX_PYTHON25_LIB_X86 = $(VBOX_PYTHON25_LIB)
    36  endif
    3733 if  !defined(VBOX_WITHOUT_VBOXPYTHON_FOR_OSX_10_6) \
    3834  && (   !defined(VBOX_OSE) \
     
    4945  VBOX_PYTHON27_LIB_X86 = $(VBOX_PYTHON27_LIB)
    5046 endif
     47 # No Python 3.x yet as part of OSX versions including El Capitan, 10.11.
    5148
    5249else
     
    115112
    116113
    117 ifdef VBOX_PYTHON23_INC
    118 #
    119 # Python 2.3 version
    120 #
    121 DLLS += VBoxPython2_3
    122 VBoxPython2_3_EXTENDS    = VBoxPythonBase
    123 VBoxPython2_3_EXTENDS_BY = appending
    124 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_API
    129 DLLS += VBoxPython2_3_x86
    130 VBoxPython2_3_x86_EXTENDS    = VBoxPythonBase_x86
    131 VBoxPython2_3_x86_EXTENDS_BY = appending
    132 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  endif
    136 endif
    137 
    138 ifdef VBOX_PYTHON24_INC
    139 #
    140 # Python 2.4 version
    141 #
    142 DLLS += VBoxPython2_4
    143 VBoxPython2_4_EXTENDS    = VBoxPythonBase
    144 VBoxPython2_4_EXTENDS_BY = appending
    145 VBoxPython2_4_INCS       = $(VBOX_PYTHON24_INC)
    146 VBoxPython2_4_LIBS       = $(VBOX_PYTHON24_LIB)
    147 
    148  ifdef VBOX_WITH_32_ON_64_MAIN_API
    149 DLLS += VBoxPython2_4_x86
    150 VBoxPython2_4_x86_EXTENDS    = VBoxPythonBase_x86
    151 VBoxPython2_4_x86_EXTENDS_BY = appending
    152 VBoxPython2_4_x86_INCS       = $(VBOX_PYTHON24_INC)
    153 VBoxPython2_4_x86_LIBS       = $(VBOX_PYTHON24_LIB_X86)
    154  endif
    155 endif
    156 
    157 ifdef VBOX_PYTHON25_INC
    158 #
    159 # Python 2.5 version
    160 #
    161 DLLS += VBoxPython2_5
    162 VBoxPython2_5_EXTENDS    = VBoxPythonBase
    163 VBoxPython2_5_EXTENDS_BY = appending
    164 VBoxPython2_5_INCS       = $(VBOX_PYTHON25_INC)
    165 VBoxPython2_5_LIBS       = $(VBOX_PYTHON25_LIB)
    166 
    167  ifdef VBOX_WITH_32_ON_64_MAIN_API
    168 DLLS += VBoxPython2_5_x86
    169 VBoxPython2_5_x86_EXTENDS    = VBoxPythonBase_x86
    170 VBoxPython2_5_x86_EXTENDS_BY = appending
    171 VBoxPython2_5_x86_INCS       = $(VBOX_PYTHON25_INC)
    172 VBoxPython2_5_x86_LIBS       = $(VBOX_PYTHON25_LIB_X86)
    173  endif
    174 endif
    175 
    176114ifdef VBOX_PYTHON26_INC
    177115#
     
    213151VBoxPython2_7_x86_INCS       = $(VBOX_PYTHON27_INC)
    214152VBoxPython2_7_x86_LIBS       = $(VBOX_PYTHON27_LIB_X86)
     153 endif
     154endif
     155
     156ifdef VBOX_PYTHON31_INC
     157#
     158# Python 3.1 version
     159#
     160DLLS += VBoxPython3_1
     161VBoxPython3_1_EXTENDS    = VBoxPythonBase
     162VBoxPython3_1_EXTENDS_BY = appending
     163VBoxPython3_1_TEMPLATE   = XPCOM
     164VBoxPython3_1_INCS       = $(VBOX_PYTHON31_INC)
     165VBoxPython3_1_LIBS       = $(VBOX_PYTHON31_LIB)
     166
     167 ifdef VBOX_WITH_32_ON_64_MAIN_API
     168DLLS += VBoxPython3_1_x86
     169VBoxPython3_1_x86_EXTENDS    = VBoxPythonBase_x86
     170VBoxPython3_1_x86_EXTENDS_BY = appending
     171VBoxPython3_1_x86_TEMPLATE   = XPCOM
     172VBoxPython3_1_x86_INCS       = $(VBOX_PYTHON31_INC)
     173VBoxPython3_1_x86_LIBS       = $(VBOX_PYTHON31_LIB_X86)
     174 endif
     175endif
     176
     177ifdef VBOX_PYTHON32_INC
     178#
     179# Python 3.2 version
     180#
     181DLLS += VBoxPython3_2
     182VBoxPython3_2_EXTENDS    = VBoxPythonBase
     183VBoxPython3_2_EXTENDS_BY = appending
     184VBoxPython3_2_TEMPLATE   = XPCOM
     185VBoxPython3_2_INCS       = $(VBOX_PYTHON32_INC)
     186VBoxPython3_2_LIBS       = $(VBOX_PYTHON32_LIB)
     187
     188 ifdef VBOX_WITH_32_ON_64_MAIN_API
     189DLLS += VBoxPython3_2_x86
     190VBoxPython3_2_x86_EXTENDS    = VBoxPythonBase_x86
     191VBoxPython3_2_x86_EXTENDS_BY = appending
     192VBoxPython3_2_x86_TEMPLATE   = XPCOM
     193VBoxPython3_2_x86_INCS       = $(VBOX_PYTHON32_INC)
     194VBoxPython3_2_x86_LIBS       = $(VBOX_PYTHON32_LIB_X86)
     195 endif
     196endif
     197
     198ifdef VBOX_PYTHON33_INC
     199#
     200# Python 3.3 version
     201#
     202DLLS += VBoxPython3_3
     203VBoxPython3_3_EXTENDS    = VBoxPythonBase
     204VBoxPython3_3_EXTENDS_BY = appending
     205VBoxPython3_3_TEMPLATE   = XPCOM
     206VBoxPython3_3_INCS       = $(VBOX_PYTHON33_INC)
     207VBoxPython3_3_LIBS       = $(VBOX_PYTHON33_LIB)
     208
     209 ifdef VBOX_WITH_32_ON_64_MAIN_API
     210DLLS += VBoxPython3_3_x86
     211VBoxPython3_3_x86_EXTENDS    = VBoxPythonBase_x86
     212VBoxPython3_3_x86_EXTENDS_BY = appending
     213VBoxPython3_3_x86_TEMPLATE   = XPCOM
     214VBoxPython3_3_x86_INCS       = $(VBOX_PYTHON33_INC)
     215VBoxPython3_3_x86_LIBS       = $(VBOX_PYTHON33_LIB_X86)
     216 endif
     217endif
     218
     219ifdef VBOX_PYTHON34_INC
     220#
     221# Python 3.4 version
     222#
     223DLLS += VBoxPython3_4
     224VBoxPython3_4_EXTENDS    = VBoxPythonBase
     225VBoxPython3_4_EXTENDS_BY = appending
     226VBoxPython3_4_TEMPLATE   = XPCOM
     227VBoxPython3_4_INCS       = $(VBOX_PYTHON34_INC)
     228VBoxPython3_4_LIBS       = $(VBOX_PYTHON34_LIB)
     229
     230 ifdef VBOX_WITH_32_ON_64_MAIN_API
     231DLLS += VBoxPython3_4_x86
     232VBoxPython3_4_x86_EXTENDS    = VBoxPythonBase_x86
     233VBoxPython3_4_x86_EXTENDS_BY = appending
     234VBoxPython3_4_x86_TEMPLATE   = XPCOM
     235VBoxPython3_4_x86_INCS       = $(VBOX_PYTHON34_INC)
     236VBoxPython3_4_x86_LIBS       = $(VBOX_PYTHON34_LIB_X86)
     237 endif
     238endif
     239
     240ifdef VBOX_PYTHON35_INC
     241#
     242# Python 3.5 version
     243#
     244DLLS += VBoxPython3_5
     245VBoxPython3_5_EXTENDS    = VBoxPythonBase
     246VBoxPython3_5_EXTENDS_BY = appending
     247VBoxPython3_5_TEMPLATE   = XPCOM
     248VBoxPython3_5_INCS       = $(VBOX_PYTHON35_INC)
     249VBoxPython3_5_LIBS       = $(VBOX_PYTHON35_LIB)
     250
     251 ifdef VBOX_WITH_32_ON_64_MAIN_API
     252DLLS += VBoxPython3_5_x86
     253VBoxPython3_5_x86_EXTENDS    = VBoxPythonBase_x86
     254VBoxPython3_5_x86_EXTENDS_BY = appending
     255VBoxPython3_5_x86_TEMPLATE   = XPCOM
     256VBoxPython3_5_x86_INCS       = $(VBOX_PYTHON35_INC)
     257VBoxPython3_5_x86_LIBS       = $(VBOX_PYTHON35_LIB_X86)
    215258 endif
    216259endif
  • trunk/src/libs/xpcom18a4/python/gen_python_deps.py

    r59800 r59809  
    22
    33"""
    4 Copyright (C) 2009-2013 Oracle Corporation
     4Copyright (C) 2009-2016 Oracle Corporation
    55
    66This file is part of VirtualBox Open Source Edition (OSE), as
     
    1414
    1515import os,sys
     16from distutils.version import StrictVersion
    1617
    17 versions = ["2.3", "2.4", "2.5", "2.6", "2.7",]
     18versions = ["2.6", "2.7", "3.1", "3.2", "3.3", "3.4", "3.5"]
    1819prefixes = ["/usr", "/usr/local", "/opt", "/opt/local"]
    1920known = {}
     
    4142
    4243def 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))
    4445    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))
    4748    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))
    4950
    5051
     
    9192
    9293    for v in versions:
     94        if StrictVersion(v) < StrictVersion('2.6'):
     95            continue
    9396        for p in prefixes:
    9497            c = checkPair(p, v, dllpre, dllsuff, bitness_magic)
     
    9699                known[v] = c
    97100                break
    98     keys = known.keys()
     101    keys = list(known.keys())
    99102    # we want default to be the lowest versioned Python
    100103    keys.sort()
  • trunk/src/libs/xpcom18a4/python/src/ErrorUtils.cpp

    r59795 r59809  
    111111        c += "('%s', ";
    112112        // Pull a trick to ensure a valid string - use Python repr!
     113#if PY_MAJOR_VERSION <= 2
    113114        PyObject *obMessage = PyString_FromString(pszMessageText);
     115#else
     116        PyObject *obMessage = PyUnicode_FromString(pszMessageText);
     117#endif
    114118        if (obMessage) {
    115119                PyObject *repr = PyObject_Repr(obMessage);
    116120                if (repr) {
     121#if PY_MAJOR_VERSION <= 2
    117122                        c += PyString_AsString(repr);
     123#else
     124                        c += PyUnicode_AsUTF8(repr);
     125#endif
    118126                        Py_DECREF(repr);
    119127                }
     
    193201        PyObject *temp = PyObject_Str(exc_typ);
    194202        if (temp) {
     203#if PY_MAJOR_VERSION <= 2
    195204                streamout += PyString_AsString(temp);
     205#else
     206                streamout += PyUnicode_AsUTF8(temp);
     207#endif
    196208                Py_DECREF(temp);
    197209        } else
     
    201213                temp = PyObject_Str(exc_val);
    202214                if (temp) {
     215#if PY_MAJOR_VERSION <= 2
    203216                        streamout += PyString_AsString(temp);
     217#else
     218                        streamout += PyUnicode_AsUTF8(temp);
     219#endif
    204220                        Py_DECREF(temp);
    205221                } else
     
    355371        PyObject *obResult = NULL;
    356372
     373#if PY_MAJOR_VERSION <= 2
    357374        /* Import the modules we need - cStringIO and traceback */
    358375        modStringIO = PyImport_ImportModule("cStringIO");
     
    370387        if (obStringIO==NULL)
    371388                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
    372406        /* Get the traceback.print_exception function, and call it. */
    373407        obFuncTB = PyObject_GetAttrString(modTB, "print_tb");
     
    396430
    397431        /* And it should be a string all ready to go - duplicate it. */
     432#if PY_MAJOR_VERSION <= 2
    398433        if (!PyString_Check(obResult))
     434#else
     435        if (!PyUnicode_Check(obResult))
     436#endif
    399437                        TRACEBACK_FETCH_ERROR("getvalue() did not return a string\n");
    400438
    401439        { // a temp scope so I can use temp locals.
     440#if PY_MAJOR_VERSION <= 2
    402441        char *tempResult = PyString_AsString(obResult);
     442#else
     443        char *tempResult = PyUnicode_AsUTF8(obResult);
     444#endif
    403445        result = (char *)PyMem_Malloc(strlen(tempResult)+1);
    404446        if (result==NULL)
  • trunk/src/libs/xpcom18a4/python/src/PyGBase.cpp

    r59795 r59809  
    6767PRBool CheckDefaultGateway(PyObject *real_inst, REFNSIID iid, nsISupports **ret_gateway);
    6868
    69 /*static*/ nsresult 
     69/*static*/ nsresult
    7070PyG_Base::CreateNew(PyObject *pPyInstance, const nsIID &iid, void **ppResult)
    7171{
     
    115115        }
    116116        else
     117#if PY_MAJOR_VERSION <= 2
    117118                szRepr = PyString_AsString(r);
     119#else
     120                szRepr = PyUnicode_AsUTF8(r);
     121#endif
    118122        if (szRepr==NULL) szRepr = "";
    119123        int reprOffset = *szRepr=='<' ? 1 : 0;
     
    185189        if (iid.Equals(NS_GET_IID(nsISupportsWeakReference)))
    186190                return (nsISupportsWeakReference *)this;
    187         if (iid.Equals(NS_GET_IID(nsIInternalPython))) 
     191        if (iid.Equals(NS_GET_IID(nsIInternalPython)))
    188192                return (nsISupports *)(nsIInternalPython *)this;
    189193        return NULL;
     
    192196// Call back into Python, passing a Python instance, and get back
    193197// an interface object that wraps the instance.
    194 /*static*/ PRBool 
     198/*static*/ PRBool
    195199PyG_Base::AutoWrapPythonInstance(PyObject *ob, const nsIID &iid, nsISupports **ppret)
    196200{
     
    245249// the object to actually use as the gateway parameter for this interface.
    246250// 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
    248252// natural usage of the interface from Python clients.
    249253// Note that piid will usually be NULL - this is because the runtime
     
    256260// so at least the user can simply QI the object.
    257261PyObject *
    258 PyG_Base::MakeInterfaceParam(nsISupports *pis, 
    259                              const nsIID *piid, 
     262PyG_Base::MakeInterfaceParam(nsISupports *pis,
     263                             const nsIID *piid,
    260264                             int methodIndex /* = -1 */,
    261                              const XPTParamDescriptor *d /* = NULL */, 
     265                             const XPTParamDescriptor *d /* = NULL */,
    262266                             int paramIndex /* = -1 */)
    263267{
     
    302306                goto done;
    303307
    304         result = PyObject_CallMethod(m_pPyObject, 
     308        result = PyObject_CallMethod(m_pPyObject,
    305309                                       (char*)"_MakeInterfaceParam_",
    306310                                       (char*)"OOiOi",
     
    351355                return NS_OK;
    352356        }
    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
    354358        // QI to it.
    355359        if (m_pBaseObject != NULL)
     
    374378
    375379                PyObject *result = PyObject_CallMethod(m_pPyObject, (char*)"_QueryInterface_",
    376                                                                     (char*)"OO", 
     380                                                                    (char*)"OO",
    377381                                                                    this_interface_ob, ob);
    378382                Py_DECREF(ob);
     
    462466        if (PyErr_Occurred()) {
    463467                // 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
    465469                // is going on - especially with TypeErrors etc in their
    466470                // return values (ie, after the Python code has successfully
    467471                // 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
    469473                // way to catch these exceptions from Python code, as their
    470474                // is no Python function directly on the call-stack)
     
    481485                PyErr_Fetch(&exc_typ, &exc_val, &exc_tb);
    482486
    483                 PyObject *err_result = PyObject_CallMethod(m_pPyObject, 
     487                PyObject *err_result = PyObject_CallMethod(m_pPyObject,
    484488                                               (char*)"_GatewayException_",
    485489                                               (char*)"z(OOO)",
     
    641645                ob_ret = PyObject_GetAttrString(real_ob, (char *)szPropertyName);
    642646                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.",
    645649                                     szPropertyName, szPropertyName);
    646650                } else {
     
    695699                        ret = NS_OK;
    696700                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.",
    699703                                     szPropertyName, szPropertyName);
    700704                }
     
    737741  first thing we do is see if it has been auto-wrapped before.
    738742
    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
    740744  to that wrapper, and store it directly back into the instance
    741745  we are auto-wrapping!  The use of a weak-reference prevents
     
    761765                PRBool ok = PR_TRUE;
    762766                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),
    765769                                                       getter_AddRefs(pWeakRef),
    766770                                                       PR_FALSE));
     
    791795                PRBool ok = PR_TRUE;
    792796                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),
    796800                                                       PR_FALSE));
    797801                Py_DECREF(ob_existing_weak);
     
    827831                        swr->GetWeakReference( getter_AddRefs(pWeakReference) );
    828832                        if (pWeakReference) {
    829                                 PyObject *ob_new_weak = Py_nsISupports::PyObjectFromInterface(pWeakReference, 
     833                                PyObject *ob_new_weak = Py_nsISupports::PyObjectFromInterface(pWeakReference,
    830834                                                                                   NS_GET_IID(nsIWeakReference),
    831835                                                                                   PR_FALSE ); /* bMakeNicePyObject */
  • trunk/src/libs/xpcom18a4/python/src/PyIClassInfo.cpp

    r59795 r59809  
    107107{
    108108        if (v)
     109#if PY_MAJOR_VERSION <= 2
    109110                return PyString_FromString(v);
     111#else
     112                return PyUnicode_FromString(v);
     113#endif
    110114        Py_INCREF(Py_None);
    111115        return Py_None;
     
    167171}
    168172
    169 struct PyMethodDef 
     173struct PyMethodDef
    170174PyMethods_IClassInfo[] =
    171175{
  • trunk/src/libs/xpcom18a4/python/src/PyIComponentManagerObsolete.cpp

    r59795 r59809  
    133133                return PyXPCOM_BuildPyException(r);
    134134
     135#if PY_MAJOR_VERSION <= 2
    135136        PyObject *ob_pid = PyString_FromString(ret_pid);
    136137        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
    137142        PyObject *ret = Py_BuildValue("OO", ob_pid, ob_class);
    138143        nsMemory::Free(ret_pid);
     
    183188}
    184189
    185 struct PyMethodDef 
     190struct PyMethodDef
    186191PyMethods_IComponentManagerObsolete[] =
    187192{
  • trunk/src/libs/xpcom18a4/python/src/PyIID.cpp

    r59795 r59809  
    6060        PyObject *obBuf;
    6161        if ( PyArg_ParseTuple(args, "O", &obBuf)) {
     62#if PY_MAJOR_VERSION <= 2
    6263                if (PyBuffer_Check(obBuf)) {
    6364                        PyBufferProcs *pb = NULL;
     
    6566                        void *buf = NULL;
    6667                        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
    6780                        if (size != sizeof(nsIID) || buf==NULL) {
     81#if PY_MAJOR_VERSION >= 3
     82                PyBuffer_Release(&view);
     83#endif
    6884#ifdef VBOX
    69                                 PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", (int)sizeof(nsIID));
     85                PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", (int)sizeof(nsIID));
    7086#else
    7187                                PyErr_Format(PyExc_ValueError, "A buffer object to be converted to an IID must be exactly %d bytes long", sizeof(nsIID));
     
    85101                                ptr += sizeof(PRUint8);
    86102                        }
     103#if PY_MAJOR_VERSION >= 3
     104            PyBuffer_Release(&view);
     105#endif
    87106                        return new Py_nsIID(iid);
    88107                }
     
    107126                return PR_FALSE;
    108127        }
     128#if PY_MAJOR_VERSION <= 2
    109129        if (PyString_Check(ob)) {
    110130                ok = iid.Parse(PyString_AsString(ob));
     131#else
     132        if (PyUnicode_Check(ob)) {
     133                ok = iid.Parse(PyUnicode_AsUTF8(ob));
     134#endif
    111135                if (!ok) {
    112136                        PyXPCOM_BuildPyException(NS_ERROR_ILLEGAL_VALUE);
     
    144168PyTypeObject Py_nsIID::type =
    145169{
    146         PyObject_HEAD_INIT(&PyType_Type)
    147         0,
     170        PyVarObject_HEAD_INIT(&PyType_Type, 0)
    148171        "IID",
    149172        sizeof(Py_nsIID),
     
    153176        PyTypeMethod_getattr,                           /* tp_getattr */
    154177        0,                                              /* tp_setattr */
     178#if PY_MAJOR_VERSION <= 2
    155179        PyTypeMethod_compare,                           /* tp_compare */
     180#else
     181        0,                                              /* reserved */
     182#endif
    156183        PyTypeMethod_repr,                              /* tp_repr */
    157184        0,                                              /* tp_as_number */
     
    161188        0,                                              /* tp_call */
    162189        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 */
    163205};
    164206
     
    184226                PyObject *ret;
    185227                if (iid_repr != nsnull) {
     228#if PY_MAJOR_VERSION <= 2
    186229                        ret = PyString_FromString(iid_repr);
     230#else
     231                        ret = PyUnicode_FromString(iid_repr);
     232#endif
    187233                        nsMemory::Free(iid_repr);
    188234                } else
     235#if PY_MAJOR_VERSION <= 2
    189236                        ret = PyString_FromString("<cant get IID info!>");
     237#else
     238                        ret = PyUnicode_FromString("<cant get IID info!>");
     239#endif
    190240                return ret;
    191241        }
     
    193243}
    194244
     245#if PY_MAJOR_VERSION <= 2
    195246/* static */ int
    196247Py_nsIID::PyTypeMethod_compare(PyObject *self, PyObject *other)
     
    201252        return rc == 0 ? 0 : (rc < 0 ? -1 : 1);
    202253}
     254#endif
     255
     256/* static */ PyObject *
     257Py_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}
    203287
    204288/* static */ PyObject *
     
    209293        char *sziid = s_iid->m_iid.ToString();
    210294#ifdef VBOX
    211         snprintf(buf, sizeof(buf), "_xpcom.IID('%s')", sziid);
     295        snprintf(buf, sizeof(buf), "_xpcom.ID('%s')", sziid);
    212296#else
    213297        sprintf(buf, "_xpcom.IID('%s')", sziid);
    214298#endif
    215299        nsMemory::Free(sziid);
     300#if PY_MAJOR_VERSION <= 2
    216301        return PyString_FromString(buf);
     302#else
     303        return PyUnicode_FromString(buf);
     304#endif
    217305}
    218306
     
    222310        Py_nsIID *s_iid = (Py_nsIID *)self;
    223311        char *sziid = s_iid->m_iid.ToString();
     312#if PY_MAJOR_VERSION <= 2
    224313        PyObject *ret = PyString_FromString(sziid);
     314#else
     315        PyObject *ret = PyUnicode_FromString(sziid);
     316#endif
    225317        nsMemory::Free(sziid);
    226318        return ret;
  • trunk/src/libs/xpcom18a4/python/src/PyIInputStream.cpp

    r59795 r59809  
    109109        }
    110110        if (n==0) { // mozilla will assert if we alloc zero bytes.
     111#if PY_MAJOR_VERSION <= 2
    111112                return PyBuffer_New(0);
     113#else
     114                return PyBytes_FromString("");
     115#endif
    112116        }
    113117        char *buf = (char *)nsMemory::Alloc(n);
     
    123127        PyObject *rc = NULL;
    124128        if ( NS_SUCCEEDED(r) ) {
     129#if PY_MAJOR_VERSION <= 2
    125130                rc = PyBuffer_New(nread);
    126131                if (rc != NULL) {
     
    146151                        memcpy(ob_buf, buf, nread);
    147152                }
     153#else
     154        rc = PyBytes_FromStringAndSize(buf, nread);
     155#endif
    148156        } else
    149157                PyXPCOM_BuildPyException(r);
  • trunk/src/libs/xpcom18a4/python/src/PyIInterfaceInfo.cpp

    r59795 r59809  
    7575        if ( NS_FAILED(r) )
    7676                return PyXPCOM_BuildPyException(r);
     77#if PY_MAJOR_VERSION <= 2
    7778        PyObject *ret = PyString_FromString(name);
     79#else
     80        PyObject *ret = PyUnicode_FromString(name);
     81#endif
    7882        nsMemory::Free(name);
    7983        return ret;
     
    393397}
    394398
    395 struct PyMethodDef 
     399struct PyMethodDef
    396400PyMethods_IInterfaceInfo[] =
    397401{
  • trunk/src/libs/xpcom18a4/python/src/PyIInterfaceInfoManager.cpp

    r59795 r59809  
    135135                return PyXPCOM_BuildPyException(r);
    136136
     137#if PY_MAJOR_VERSION <= 2
    137138        PyObject *ret = PyString_FromString(ret_name);
     139#else
     140        PyObject *ret = PyUnicode_FromString(ret_name);
     141#endif
    138142        nsMemory::Free(ret_name);
    139143        return ret;
     
    186190// void autoRegisterInterfaces();
    187191
    188 PyMethodDef 
     192PyMethodDef
    189193PyMethods_IInterfaceInfoManager[] =
    190194{
  • trunk/src/libs/xpcom18a4/python/src/PyISupports.cpp

    r59795 r59809  
    218218        }
    219219        PyXPCOM_TypeObject *this_type = (PyXPCOM_TypeObject *)ob_type;
     220#if PY_MAJOR_VERSION <= 2
    220221        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
    221250}
    222251
  • trunk/src/libs/xpcom18a4/python/src/PyIVariant.cpp

    r59795 r59809  
    6262}
    6363static PyObject *MyChar( char c) {
     64#if PY_MAJOR_VERSION <= 2
    6465        return PyString_FromStringAndSize(&c, 1);
     66#else
     67        return PyUnicode_FromStringAndSize(&c, 1);
     68#endif
    6569}
    6670static PyObject *MyUChar( PRUnichar c) {
     
    123127GET_SIMPLE(nsIID, GetAsID, Py_nsIID::PyObjectFromIID)
    124128
     129#if PY_MAJOR_VERSION <= 2
    125130GET_ALLOCATED(char *, GetAsString, PyString_FromString, nsMemory::Free)
     131#else
     132GET_ALLOCATED(char *, GetAsString, PyUnicode_FromString, nsMemory::Free)
     133#endif
    126134GET_ALLOCATED(PRUnichar *, GetAsWString, MyUnicode, nsMemory::Free)
     135#if PY_MAJOR_VERSION <= 2
    127136GET_ALLOCATED_SIZE(char *, GetAsStringWithSize, PyString_FromStringAndSize, nsMemory::Free)
     137#else
     138GET_ALLOCATED_SIZE(char *, GetAsStringWithSize, PyUnicode_FromStringAndSize, nsMemory::Free)
     139#endif
    128140GET_ALLOCATED_SIZE(PRUnichar *, GetAsWStringWithSize, PyObject_FromNSString, nsMemory::Free)
    129141
     
    166178}
    167179
    168 struct PyMethodDef 
     180struct PyMethodDef
    169181PyMethods_IVariant[] =
    170182{
  • trunk/src/libs/xpcom18a4/python/src/Pyxpt_info.cpp

    r59795 r59809  
    5555        }
    5656    // build an object using the same format as a TypeDescriptor.
    57         return Py_BuildValue("bzzz", 
     57        return Py_BuildValue("bzzz",
    5858                d->flags,
    5959                NULL, NULL, NULL);
     
    6666                return Py_None;
    6767        }
    68         return Py_BuildValue("bbbh", 
     68        return Py_BuildValue("bbbh",
    6969                d->prefix.flags,
    7070                d->argnum,
     
    150150                        break;
    151151                case TD_CHAR:
     152#if PY_MAJOR_VERSION <= 2
    152153                        v = PyString_FromStringAndSize(&c->value.ch, 1);
     154#else
     155                        v = PyUnicode_FromStringAndSize(&c->value.ch, 1);
     156#endif
    153157                        break;
    154158                case TD_WCHAR:
    155159                        v = PyObject_FromNSString((PRUnichar *)&c->value.wch, 1);
    156160                        break;
    157         //    TD_VOID              = 13, 
     161        //    TD_VOID              = 13,
    158162                case TD_PNSIID:
    159163                        v = Py_nsIID::PyObjectFromIID(*c->value.iid);
     
    161165        //    TD_DOMSTRING         = 15,
    162166                case TD_PSTRING:
     167#if PY_MAJOR_VERSION <= 2
    163168                        v = PyString_FromString(c->value.str);
     169#else
     170                        v = PyUnicode_FromString(c->value.str);
     171#endif
    164172                        break;
    165173                case TD_PWSTRING:
     
    175183        //    TD_ASTRING           = 25
    176184                default:
     185#if PY_MAJOR_VERSION <= 2
    177186                        v = PyString_FromString("Unknown type code!!");
     187#else
     188                        v = PyUnicode_FromString("Unknown type code!!");
     189#endif
    178190                        break;
    179191
  • trunk/src/libs/xpcom18a4/python/src/TypeObject.cpp

    r59795 r59809  
    5353
    5454static PyTypeObject PyInterfaceType_Type = {
    55         PyObject_HEAD_INIT(&PyType_Type)
    56         0,                      /* Number of items for varobject */
     55        PyVarObject_HEAD_INIT(&PyType_Type, 0)
    5756        "interface-type",                       /* Name of this type */
    5857        sizeof(PyTypeObject),   /* Basic object size */
     
    8079PyXPCOM_TypeObject::IsType(PyTypeObject *t)
    8180{
     81#if PY_MAJOR_VERSION <= 2
    8282        return t->ob_type == &PyInterfaceType_Type;
     83#else
     84        return Py_TYPE(t) == &PyInterfaceType_Type;
     85#endif
    8386}
    8487
     
    122125}
    123126
     127/*static*/PyObject *
     128PyXPCOM_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
    124157// @pymethod int|Py_nsISupports|__hash__|Implement a hash-code for the XPCOM object using XPCOM identity rules.
    125158/*static*/long PyXPCOM_TypeObject::Py_hash(PyObject *self)
     
    152185        char buf[512];
    153186#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>",
    155188                iid_repr, (void *)self, (void *)pis->m_obj.get());
    156189#else
     
    159192#endif
    160193        nsMemory::Free(iid_repr);
     194#if PY_MAJOR_VERSION <= 2
    161195        return PyString_FromString(buf);
     196#else
     197        return PyUnicode_FromString(buf);
     198#endif
    162199}
    163200
     
    173210        if (NS_SUCCEEDED(rv))
    174211                rv = ss->ToString(&val);
    175         } // end-scope 
     212        } // end-scope
    176213        Py_END_ALLOW_THREADS;
    177214        PyObject *ret;
     
    179216                ret = Py_repr(self);
    180217        else
     218#if PY_MAJOR_VERSION <= 2
    181219                ret = PyString_FromString(val);
     220#else
     221                ret = PyUnicode_FromString(val);
     222#endif
    182223        if (val) nsMemory::Free(val);
    183224        return ret;
     
    193234{
    194235        static const PyTypeObject type_template = {
    195                 PyObject_HEAD_INIT(&PyInterfaceType_Type)
    196                 0,                                           /*ob_size*/
     236                PyVarObject_HEAD_INIT(&PyInterfaceType_Type, 0)
    197237                "XPCOMTypeTemplate",                         /*tp_name*/
    198                 sizeof(Py_nsISupports),                 /*tp_basicsize*/
     238                sizeof(Py_nsISupports),                      /*tp_basicsize*/
    199239                0,                                           /*tp_itemsize*/
    200240                Py_dealloc,                                  /* tp_dealloc */
     
    202242                Py_getattr,                                  /* tp_getattr */
    203243                Py_setattr,                                  /* tp_setattr */
     244#if PY_MAJOR_VERSION <= 2
    204245                Py_cmp,                                      /* tp_compare */
     246#else
     247                0,                                           /* reserved */
     248#endif
    205249                Py_repr,                                     /* tp_repr */
    206                 0,                                           /* tp_as_number*/
     250                0,                                           /* tp_as_number*/
    207251                0,                                           /* tp_as_sequence */
    208252                0,                                           /* tp_as_mapping */
     
    211255                Py_str,                                      /* tp_str */
    212256                0,                                           /* tp_getattro */
    213                 0,                                           /*tp_setattro */
     257                0,                                           /* tp_setattro */
    214258                0,                                           /* tp_as_buffer */
    215259                0,                                           /* tp_flags */
     
    217261                0,                                           /* tp_traverse */
    218262                0,                                           /* tp_clear */
    219                 0,                                           /* tp_richcompare */
     263                Py_richcmp,                                  /* tp_richcompare */
    220264                0,                                           /* tp_weaklistoffset */
    221265                0,                                           /* tp_iter */
  • trunk/src/libs/xpcom18a4/python/src/VariantUtils.cpp

    r59795 r59809  
    8484        PRUint32 size;
    8585        PyObject *s;
     86        void *src;
    8687        PRUnichar *dest;
    8788
     
    8990        if (!s)
    9091                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
    9196        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
    92107        dest = (PRUnichar *)nsMemory::Alloc(sizeof(PRUnichar) * (size + 1));
    93108        if (!dest) {
     
    96111                return -1;
    97112        }
    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);
    102114        Py_DECREF(s);
    103115        dest[size] = 0;
     
    116128        } else {
    117129                if (bAssumeUTF8) {
    118                         const nsPromiseFlatCString& temp = PromiseFlatCString(s);
    119                         ret = PyUnicode_DecodeUTF8(temp.get(), temp.Length(), NULL);
     130                        const nsPromiseFlatCString& temp = PromiseFlatCString(s);
     131                        ret = PyUnicode_DecodeUTF8(temp.get(), temp.Length(), NULL);
    120132                } else {
     133#if PY_MAJOR_VERSION <= 2
    121134                        ret = PyString_FromStringAndSize(NULL, s.Length());
     135#else
     136                        ret = PyUnicode_FromStringAndSize(NULL, s.Length());
     137#endif
    122138                        if (!ret)
    123139                                return NULL;
    124140                        // Need "CopyAsciiTo"!?
    125141                        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
    127147                        copy_string(s.BeginReading(fromBegin), s.EndReading(fromEnd), dest);
    128148                }
     
    159179        PyObject *val_use = NULL;
    160180        PRBool ok = PR_TRUE;
     181#if PY_MAJOR_VERSION <= 2
    161182        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    162183                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    165186        if (ok && (val_use = PyUnicode_FromObject(val))==NULL)
    166187                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
    167196        if (ok) {
    168197                if (PyUnicode_GET_SIZE(val_use) == 0) {
     
    353382        // If it is NOT a string, we just fall through and allow the standard
    354383        // sequence unpack code process it (just slower!)
     384#if PY_MAJOR_VERSION <= 2
    355385        if ( array_type == nsXPTType::T_U8 &&
    356386                (PyString_Check(sequence_ob) || PyUnicode_Check(sequence_ob))) {
     387#else
     388        if ( array_type == nsXPTType::T_U8 && PyUnicode_Check(sequence_ob)) {
     389#endif
    357390
    358391                PRBool release_seq;
    359392                if (PyUnicode_Check(sequence_ob)) {
    360393                        release_seq = PR_TRUE;
     394#if PY_MAJOR_VERSION <= 2
    361395                        sequence_ob = PyObject_Str(sequence_ob);
     396#else
     397                        sequence_ob = PyUnicode_AsUTF8String(sequence_ob);
     398#endif
    362399                } else
    363400                        release_seq = PR_FALSE;
    364401                if (!sequence_ob) // presumably a memory error, or Unicode encoding error.
    365402                        return PR_FALSE;
     403#if PY_MAJOR_VERSION <= 2
    366404                memcpy(pthis, PyString_AS_STRING(sequence_ob), sequence_size);
     405#else
     406                memcpy(pthis, PyUnicode_AsUTF8(sequence_ob), sequence_size);
     407#endif
    367408                if (release_seq)
    368409                {
     
    423464                                break;
    424465                          case nsXPTType::T_CHAR:
     466#if PY_MAJOR_VERSION <= 2
    425467                                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    426468                                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    432474                                NS_ABORT_IF_FALSE(PyString_Check(val_use), "PyObject_Str didnt return a string object!");
    433475                                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
    434483                                break;
    435484
    436485                          case nsXPTType::T_WCHAR:
     486#if PY_MAJOR_VERSION <= 2
    437487                                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    438488                                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
    439489                                        BREAK_FALSE;
    440490                                }
     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
    441497                                if ((val_use = PyUnicode_FromObject(val)) == NULL)
    442498                                        BREAK_FALSE;
     
    474530                                if (val == Py_None)
    475531                                        break; // Remains NULL.
     532#if PY_MAJOR_VERSION <= 2
    476533                                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    477534                                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    485542                                const char *sz = PyString_AS_STRING(val_use);
    486543                                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
    487555
    488556                                *pp = (char *)nsMemory::Alloc(nch+1);
     
    502570                                if (val == Py_None)
    503571                                        break; // Remains NULL.
     572#if PY_MAJOR_VERSION <= 2
    504573                                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    505574                                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    509578                                        BREAK_FALSE;
    510579                                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
    511588                                if (PyUnicode_AsPRUnichar(val_use, pp, NULL) < 0)
    512589                                        BREAK_FALSE;
     
    549626        }
    550627        if (array_type == nsXPTType::T_U8)
     628#if PY_MAJOR_VERSION <= 2
    551629                return PyString_FromStringAndSize( (char *)array_ptr, sequence_size );
     630#else
     631                return PyUnicode_FromStringAndSize( (char *)array_ptr, sequence_size );
     632#endif
    552633
    553634        PRUint32 array_element_size = GetArrayElementSize(array_type);
     
    599680                                        val = Py_None;
    600681                                } else
     682#if PY_MAJOR_VERSION <= 2
    601683                                        val = PyString_FromString(*pp);
     684#else
     685                                        val = PyUnicode_FromString(*pp);
     686#endif
    602687                                break;
    603688                                }
     
    632717                                sprintf(buf, "Unknown XPCOM array type flags (0x%x)", array_type);
    633718                                PyXPCOM_LogWarning("%s - returning a string object with this message!\n", buf);
     719#if PY_MAJOR_VERSION <= 2
    634720                                val = PyString_FromString(buf);
     721#else
     722                                val = PyUnicode_FromString(buf);
     723#endif
    635724                                break;
    636725                                }
     
    670759        if (PyFloat_Check(ob))
    671760                return nsIDataType::VTYPE_DOUBLE;
     761#if PY_MAJOR_VERSION <= 2
    672762        if (PyString_Check(ob))
    673763                return nsIDataType::VTYPE_STRING_SIZE_IS;
     764#endif
    674765        if (PyUnicode_Check(ob))
    675766                return nsIDataType::VTYPE_WSTRING_SIZE_IS;
     
    726817                        break;
    727818                case nsIDataType::VTYPE_STRING_SIZE_IS:
     819#if PY_MAJOR_VERSION <= 2
    728820                        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
    729827                        break;
    730828                case nsIDataType::VTYPE_WSTRING_SIZE_IS:
     
    12961394                        break;
    12971395                  case nsXPTType::T_CHAR:{
     1396#if PY_MAJOR_VERSION <= 2
    12981397                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    12991398                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    13101409
    13111410                        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
    13121423                        break;
    13131424                        }
    13141425
    13151426                  case nsXPTType::T_WCHAR: {
     1427#if PY_MAJOR_VERSION <= 2
    13161428                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    13171429                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
    13181430                                BREAK_FALSE;
    13191431                        }
     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
    13201438                        if ((val_use = PyUnicode_FromObject(val))==NULL)
    13211439                                BREAK_FALSE;
    1322                         // Sanity check should PyObject_Str() ever loosen its semantics wrt Unicode!
     1440                        // Sanity check should PyUnicode_FromObject() ever loosen its semantics wrt Unicode!
    13231441                        NS_ABORT_IF_FALSE(PyUnicode_Check(val_use), "PyUnicode_FromObject didnt return a unicode object!");
    1324                         if (PyUnicode_GetSize(val_use) != 1) {
     1442                        if (PyUnicode_GET_SIZE(val_use) != 1) {
    13251443                                PyErr_SetString(PyExc_ValueError, "Must specify a one character string for a character");
    13261444                                BREAK_FALSE;
     
    13601478                                ns_v.val.p = new nsCString();
    13611479                        } else {
    1362                                 // strings are assumed to already be UTF8 encoded.
     1480#if PY_MAJOR_VERSION <= 2
    13631481                                if (PyString_Check(val)) {
     1482                    // strings are assumed to already be UTF8 encoded.
    13641483                                        val_use = val;
    13651484                                        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.
    13681490                                        if (bIsUTF8)
    13691491                                                val_use = PyUnicode_AsUTF8String(val);
    13701492                                        else
     1493#if PY_MAJOR_VERSION <= 2
    13711494                                                val_use = PyObject_Str(val);
     1495#else
     1496                                                val_use = PyUnicode_AsUTF8String(val);
     1497#endif
    13721498                                } else {
     1499#if PY_MAJOR_VERSION <= 2
    13731500                                        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
    13741504                                        BREAK_FALSE;
    13751505                                }
    13761506                                if (!val_use)
    13771507                                        BREAK_FALSE;
     1508#if PY_MAJOR_VERSION <= 2
    13781509                                ns_v.val.p = new nsCString(PyString_AS_STRING(val_use),
    13791510                                                           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
    13801515                        }
    13811516
     
    13931528                                break;
    13941529                        }
     1530#if PY_MAJOR_VERSION <= 2
    13951531                        // If an "in" char *, and we have a PyString, then pass the
    13961532                        // pointer (hoping everyone else plays by the rules too.
    13971533                        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);
    13991535                                break;
    14001536                        }
     
    14121548                        MAKE_VALUE_BUFFER(cb_this_buffer_pointer);
    14131549                        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
    14141563                        ns_v.val.p = this_buffer_pointer;
    14151564                        break;
     
    14211570                                break;
    14221571                        }
     1572#if PY_MAJOR_VERSION <= 2
    14231573                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    14241574                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    14281578                                BREAK_FALSE;
    14291579                        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
    14301588                        PRUnichar *sv;
    14311589                        PRUint32 nch;
     
    14841642                                break;
    14851643                        }
     1644#if PY_MAJOR_VERSION <= 2
    14861645                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    14871646                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    14961655                        MAKE_VALUE_BUFFER(cb_this_buffer_pointer);
    14971656                        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
    14981669                        ns_v.val.p = this_buffer_pointer;
    14991670                        rc = SetSizeIs(value_index, PR_TRUE, cb_this_buffer_pointer);
     
    15061677                                break;
    15071678                        }
     1679#if PY_MAJOR_VERSION <= 2
    15081680                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    15091681                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    15141686                        // Sanity check should PyObject_Str() ever loosen its semantics wrt Unicode!
    15151687                        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
    15161696                        PRUnichar *sv;
    15171697                        PRUint32 nch;
     
    17191899                break;
    17201900          case nsXPTType::T_CHAR:
     1901#if PY_MAJOR_VERSION <= 2
    17211902                ret = PyString_FromStringAndSize( ((char *)ns_v.ptr), 1 );
     1903#else
     1904                ret = PyUnicode_FromStringAndSize( ((char *)ns_v.ptr), 1 );
     1905#endif
    17221906                break;
    17231907
     
    17471931                        Py_INCREF(Py_None);
    17481932                } else
     1933#if PY_MAJOR_VERSION <= 2
    17491934                        ret = PyString_FromString( *((char **)ns_v.ptr) );
     1935#else
     1936                        ret = PyUnicode_FromString( *((char **)ns_v.ptr) );
     1937#endif
    17501938                break;
    17511939
     
    18282016                } else {
    18292017                        PRUint32 string_size = GetSizeIs(index, PR_TRUE);
     2018#if PY_MAJOR_VERSION <= 2
    18302019                        ret = PyString_FromStringAndSize( *((char **)ns_v.ptr), string_size );
     2020#else
     2021                        ret = PyUnicode_FromStringAndSize( *((char **)ns_v.ptr), string_size );
     2022#endif
    18312023                }
    18322024                break;
     
    20832275          case nsXPTType::T_CHAR: {
    20842276                char temp = DEREF_IN_OR_OUT(ns_v.val.c, char);
     2277#if PY_MAJOR_VERSION <= 2
    20852278                ret = PyString_FromStringAndSize(&temp, 1);
     2279#else
     2280                ret = PyUnicode_FromStringAndSize(&temp, 1);
     2281#endif
    20862282                break;
    20872283                }
     
    21162312                        Py_INCREF(Py_None);
    21172313                } else
     2314#if PY_MAJOR_VERSION <= 2
    21182315                        ret = PyString_FromString(t);
     2316#else
     2317                        ret = PyUnicode_FromString(t);
     2318#endif
    21192319                break;
    21202320                }
     
    21782378                        Py_INCREF(Py_None);
    21792379                } else
     2380#if PY_MAJOR_VERSION <= 2
    21802381                        ret = PyString_FromStringAndSize(t, string_size);
     2382#else
     2383                        ret = PyUnicode_FromStringAndSize(t, string_size);
     2384#endif
    21812385                break;
    21822386                }
     
    21992403                sprintf(buf, "Unknown XPCOM type flags (0x%x)", td.type_flags);
    22002404                PyXPCOM_LogWarning("%s - returning a string object with this message!\n", buf);
     2405#if PY_MAJOR_VERSION <= 2
    22012406                ret = PyString_FromString(buf);
     2407#else
     2408                ret = PyUnicode_FromString(buf);
     2409#endif
    22022410                break;
    22032411                }
     
    23402548                break;
    23412549          case nsXPTType::T_CHAR:
     2550#if PY_MAJOR_VERSION <= 2
    23422551                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    23432552                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    23492558                NS_ABORT_IF_FALSE(PyString_Check(val_use), "PyObject_Str didnt return a string object!");
    23502559                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
    23512567                break;
    23522568
    23532569          case nsXPTType::T_WCHAR:
     2570#if PY_MAJOR_VERSION <= 2
    23542571                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    23552572                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
    23562573                        BREAK_FALSE;
    23572574                }
     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
    23582581                if ((val_use = PyUnicode_FromObject(val))==NULL)
    23592582                        BREAK_FALSE;
     
    23952618                        NS_ABORT_IF_FALSE(0, "dont handle None here yet");
    23962619                } else {
     2620#if PY_MAJOR_VERSION <= 2
    23972621                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    23982622                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    24022626                        NS_ABORT_IF_FALSE(PyString_Check(val_use), "PyObject_Str didnt return a string object!");
    24032627                        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
    24052638                }
    24062639                break;
     
    24122645                        NS_ABORT_IF_FALSE(0, "dont handle None here yet");
    24132646                } else {
     2647#if PY_MAJOR_VERSION <= 2
    24142648                        if (PyString_Check(val)) {
    24152649                                val_use = val;
    24162650                                Py_INCREF(val);
    2417                         } else if (PyUnicode_Check(val)) {
     2651                        }
     2652            else
     2653#endif
     2654            if (PyUnicode_Check(val)) {
    24182655                                val_use = PyUnicode_AsUTF8String(val);
    24192656                        } else {
     2657#if PY_MAJOR_VERSION <= 2
    24202658                                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
    24232665                        NS_ABORT_IF_FALSE(PyString_Check(val_use), "must have a string object!");
    24242666                        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
    24262673                }
    24272674                break;
     
    24372684                if (val == Py_None)
    24382685                        break; // Remains NULL.
     2686#if PY_MAJOR_VERSION <= 2
    24392687                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    24402688                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    24482696                const char *sz = PyString_AS_STRING(val_use);
    24492697                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
    24502709
    24512710                *pp = (char *)nsMemory::Alloc(nch+1);
     
    24652724                if (val == Py_None)
    24662725                        break; // Remains NULL.
     2726#if PY_MAJOR_VERSION <= 2
    24672727                if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    24682728                        PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    24712731                val_use = PyUnicode_FromObject(val);
    24722732                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
    24732741                if (PyUnicode_AsPRUnichar(val_use, pp, NULL) < 0)
    24742742                        BREAK_FALSE;
     
    25252793                PRUint32 nch = 0;
    25262794                if (val != Py_None) {
     2795#if PY_MAJOR_VERSION <= 2
    25272796                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    25282797                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    25362805                        sz = PyString_AS_STRING(val_use);
    25372806                        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
    25382818                }
    25392819                PRBool bBackFill = PR_FALSE;
     
    25822862
    25832863                if (val != Py_None) {
     2864#if PY_MAJOR_VERSION <= 2
    25842865                        if (!PyString_Check(val) && !PyUnicode_Check(val)) {
    25852866                                PyErr_SetString(PyExc_TypeError, "This parameter must be a string or Unicode object");
     
    25882869                        val_use = PyUnicode_FromObject(val);
    25892870                        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
    25902879                        if (PyUnicode_AsPRUnichar(val_use, &sz, &nch) < 0)
    25912880                                BREAK_FALSE;
     
    27503039                // But the retval is often the last param described in the info.
    27513040                if (!PySequence_Check(user_result) ||
     3041#if PY_MAJOR_VERSION <= 2
    27523042                     PyString_Check(user_result) ||
     3043#else
     3044                     PyBytes_Check(user_result) ||
     3045#endif
    27533046                     PyUnicode_Check(user_result)) {
    27543047                        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  
    196196        CEnterLeaveXPCOMFramework _celf;
    197197        PRInt32 cnt = PR_AtomicIncrement(&g_cLockCount);
    198         if (cnt==1) { // First call 
     198        if (cnt==1) { // First call
    199199                if (!Py_IsInitialized()) {
    200200                        Py_Initialize();
     
    204204                        if (PySys_GetObject((char*)"argv")==NULL) {
    205205                                PyObject *path = PyList_New(0);
     206#if PY_MAJOR_VERSION <= 2
    206207                                PyObject *str = PyString_FromString("");
     208#else
     209                                PyObject *str = PyUnicode_FromString("");
     210#endif
    207211                                PyList_Append(path, str);
    208212                                PySys_SetObject((char*)"argv", path);
     
    246250        PR_DestroyLock(g_lockMain);
    247251#ifndef PYXPCOM_USE_PYGILSTATE
    248         // I can't locate a way to kill this - 
     252        // I can't locate a way to kill this -
    249253        // should I pass a dtor to PR_NewThreadPrivateIndex??
    250254        // TlsFree(tlsIndex);
     
    330334                bHaveInitXPCOM = PR_TRUE;
    331335                // Register our custom interfaces.
    332        
     336
    333337                Py_nsISupports::InitType();
    334338                Py_nsIComponentManager::InitType();
     
    342346                // for backward compatibility:
    343347                Py_nsIComponentManagerObsolete::InitType();
    344                
     348
    345349        }
    346350        return rc;
  • trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp

    r59795 r59809  
    8484# endif
    8585# 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
    87119#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_8")
    88120#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_8)
    89121
    90 #  elif PY_VERSION_HEX >= 0x02070000
     122#  elif PY_VERSION_HEX >= 0x02070000 && PY_VERSION_HEX < 0x02080000
    91123#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_7")
    92124#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_7)
    93125
    94 #  elif PY_VERSION_HEX >= 0x02060000
     126#  elif PY_VERSION_HEX >= 0x02060000 && PY_VERSION_HEX < 0x02070000
    95127#   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_6")
    96128#   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_6)
    97 
    98 #  elif PY_VERSION_HEX >= 0x02050000
    99 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_5")
    100 #   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_5)
    101 
    102 #  elif PY_VERSION_HEX >= 0x02040000
    103 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_4")
    104 #   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_4)
    105 
    106 #  elif PY_VERSION_HEX >= 0x02030000
    107 #   define MODULE_NAME    MANGLE_MODULE_NAME("VBoxPython2_3")
    108 #   define initVBoxPython MANGLE_MODULE_INIT(initVBoxPython2_3)
    109129#  else
    110 #   error "Fix module versioning."
     130#   error "Fix module versioning. This Python version is not recognized."
    111131#  endif
    112132# else
    113133#  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
    115139# endif
    116140#else
     
    121145// interface support!
    122146
     147#ifndef VBOX
    123148/* deprecated, included for backward compatibility */
    124149static PyObject *
     
    143168        return Py_nsISupports::PyObjectFromInterface(ocm, NS_GET_IID(nsIComponentManagerObsolete), PR_FALSE);
    144169}
     170#endif
    145171
    146172static PyObject *
     
    195221}
    196222
     223#ifndef VBOX
    197224/* deprecated, included for backward compatibility */
    198225static PyObject *
     
    204231        return PyXPCOMMethod_GetComponentManager(self, args);
    205232}
     233#endif
    206234
    207235static PyObject *
     
    500528        if (!PyArg_ParseTuple(args, "i", &bufSize))
    501529                return NULL;
     530#if PY_MAJOR_VERSION <= 2
    502531        return PyBuffer_New(bufSize);
     532#else
     533    return PyBytes_FromStringAndSize(NULL, bufSize);
     534#endif
    503535}
    504536
     
    671703        {"GetComponentManager", PyXPCOMMethod_GetComponentManager, 1},
    672704        {"GetComponentRegistrar", PyXPCOMMethod_GetComponentRegistrar, 1},
     705#ifndef VBOX
    673706        {"NS_GetGlobalComponentManager", PyXPCOMMethod_NS_GetGlobalComponentManager, 1}, // deprecated
     707#endif
    674708        {"XPTI_GetInterfaceInfoManager", PyXPCOMMethod_XPTI_GetInterfaceInfoManager, 1},
    675709        {"XPTC_InvokeByIndex", PyXPCOMMethod_XPTC_InvokeByIndex, 1},
    676710        {"GetServiceManager", PyXPCOMMethod_GetServiceManager, 1},
     711#ifndef VBOX
    677712        {"GetGlobalServiceManager", PyXPCOMMethod_GetGlobalServiceManager, 1}, // deprecated
    678713        {"IID", PyXPCOMMethod_IID, 1}, // IID is wrong - deprecated - not just IID, but CID, etc.
     714#endif
    679715        {"ID", PyXPCOMMethod_IID, 1}, // This is the official name.
    680716        {"NS_ShutdownXPCOM", PyXPCOMMethod_NS_ShutdownXPCOM, 1},
     
    691727        {"GetVariantValue", PyXPCOMMethod_GetVariantValue, 1},
    692728#ifdef VBOX
    693         {"WaitForEvents", PyXPCOMMethod_WaitForEvents, 1},
    694         {"InterruptWait", PyXPCOMMethod_InterruptWait, 1},
    695         {"DeinitCOM",     PyXPCOMMethod_DeinitCOM, 1},
    696         {"AttachThread",  PyXPCOMMethod_AttachThread, 1},
    697         {"DetachThread",  PyXPCOMMethod_DetachThread, 1},
     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},
    698734#endif
    699735#ifdef VBOX_DEBUG_LIFETIMES
     
    705741};
    706742
     743#if PY_MAJOR_VERSION >= 3
     744static 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
    707755#define REGISTER_IID(t) { \
    708756        PyObject *iid_ob = Py_nsIID::PyObjectFromIID(NS_GET_IID(t)); \
     
    721769// The module init code.
    722770//
     771#if PY_MAJOR_VERSION <= 2
    723772extern "C" NS_EXPORT
    724773void
     774#else
     775PyObject *
     776#endif
    725777init_xpcom() {
    726778        PyObject *oModule;
     
    728780        // ensure the framework has valid state to work with.
    729781        if (!PyXPCOM_Globals_Ensure())
     782#if PY_MAJOR_VERSION <= 2
    730783                return;
     784#else
     785                return NULL;
     786#endif
    731787
    732788        // Must force Python to start using thread locks
     
    734790
    735791        // Create the module and add the functions
     792#if PY_MAJOR_VERSION <= 2
    736793        oModule = Py_InitModule(MODULE_NAME, xpcom_methods);
     794#else
     795        oModule = PyModule_Create(&xpcom_module);
     796#endif
    737797
    738798        PyObject *dict = PyModule_GetDict(oModule);
     
    741801        {
    742802                PyErr_SetString(PyExc_MemoryError, "can't define error");
     803#if PY_MAJOR_VERSION <= 2
    743804                return;
     805#else
     806                return NULL;
     807#endif
    744808        }
    745809        PyDict_SetItemString(dict, "IIDType", (PyObject *)&Py_nsIID::type);
     
    784848    PyDict_SetItemString(dict, "NS_DEBUG", ob);
    785849    Py_DECREF(ob);
     850#if PY_MAJOR_VERSION >= 3
     851    return oModule;
     852#endif
    786853}
    787854
     
    795862#include <iprt/stream.h>
    796863
     864#if PY_MAJOR_VERSION <= 2
    797865extern "C" NS_EXPORT
    798866void
     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*
     873PyMODINIT_FUNC
     874#endif
    799875initVBoxPython() { /* NOTE! This name is redefined at the top of the file! */
    800876  static bool s_vboxInited = false;
     
    819895    rc = com::Initialize();
    820896
     897#if PY_MAJOR_VERSION <= 2
    821898    init_xpcom();
     899#else
     900    return init_xpcom();
     901#endif
    822902  }
     903#if PY_MAJOR_VERSION >= 3
     904  return NULL;
     905#endif
    823906}
    824907
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette