VirtualBox

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


Ignore:
Timestamp:
Sep 28, 2020 10:44:15 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
140595
Message:

xpcom/python: Use PyUnicode_GetLength instead of deprecated PyUnicode_GetSize for empty string test. Indentation and other minor py3 cleanups. bugref:9840

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/python/src/VariantUtils.cpp

    r86297 r86309  
    8484        PRUint32 size;
    8585        PyObject *s;
    86         void *src;
     86        const void *src;
    8787        PRUnichar *dest;
    8888
     
    9797        src = PyString_AS_STRING(s) + 2;
    9898#else
    99     if (!PyBytes_Check(s))
    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(s) - 2) / sizeof(PRUnichar);
    105     src = PyBytes_AS_STRING(s) + 2;
     99        if (!PyBytes_Check(s)) {
     100                PyErr_SetString(PyExc_TypeError, "internal error in PyXPCOM, parameter must be a bytes object");
     101                return -1;
     102        }
     103        size = (PyBytes_GET_SIZE(s) - 2) / sizeof(PRUnichar);
     104        src = PyBytes_AS_STRING(s) + 2;
    106105#endif
    107106        dest = (PRUnichar *)nsMemory::Alloc(sizeof(PRUnichar) * (size + 1));
     
    187186                ok = PR_FALSE;
    188187#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);
     188        if (!PyUnicode_Check(val)) {
     189                PyErr_SetString(PyExc_TypeError, "This parameter must be a unicode object");
     190                ok = PR_FALSE;
     191        }
     192        val_use = val;
     193        Py_INCREF(val_use);
    195194#endif
    196195        if (ok) {
     
    817816                        break;
    818817                case nsIDataType::VTYPE_STRING_SIZE_IS:
     818                {
    819819#if PY_MAJOR_VERSION <= 2
    820820                        nr = v->SetAsStringWithSize(PyString_Size(ob), PyString_AsString(ob));
    821821#else
    822             Py_ssize_t cb;
    823             const char *psz;
    824             psz = PyUnicode_AsUTF8AndSize(ob, &cb);
     822                        Py_ssize_t cb = 0;
     823                        const char *psz = PyUnicode_AsUTF8AndSize(ob, &cb);
    825824                        nr = v->SetAsStringWithSize(cb, psz);
    826825#endif
    827826                        break;
     827                }
    828828                case nsIDataType::VTYPE_WSTRING_SIZE_IS:
     829#if PY_VERSION_HEX >= 0x03030000
     830                        if (PyUnicode_GetLength(ob) == 0) {
     831#else
    829832                        if (PyUnicode_GetSize(ob) == 0) {
     833#endif
    830834                                nr = v->SetAsWStringWithSize(0, (PRUnichar*)NULL);
    831                         }
    832                         else {
     835                        } else {
    833836                                PRUint32 nch;
    834837                                PRUnichar *p;
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