VirtualBox

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


Ignore:
Timestamp:
Jan 15, 2025 4:28:07 PM (5 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
166933
Message:

libs/xpcom/python: Python 3.12 flags a size discrepancy when calling
PyType_FromSpec() for 'Py_nsIID' where the base class '&PyType_Type' is
larger than the derived class of 'Py_nsIID'. Thus the size required for
the 'Py_nsIID' heap object created by PyType_FromSpec() needs to be
increased to accommodate both of the objects in question. bugref:10832

File:
1 edited

Legend:

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

    r103125 r107794  
    240240                { 0, NULL } /* terminator */
    241241        };
     242
     243    /* The parent/base class specified in Py_tp_base (&PyType_Type) here is larger
     244     * than the Py_nsIID derived class so we need to ensure enough space is allocated
     245     * for both when calling PyType_FromSpec(), i.e.: PyType_Type.tp_basicsize +
     246     * sizeof(Py_nsIID).  Starting with Python 3.12 when 'basicsize' is negative "the
     247     * absolute value specifies how much space instances of the class need in addition
     248     * to the superclass".  Earlier Python releases require calculating the total size
     249     * by hand. */
     250#if PY_VERSION_HEX >= 0x030C0000
     251    int basicsize = -(int)sizeof(Py_nsIID);
     252#else
     253    /* PyObjects are opaque in the Py_LIMITED_API so we must use PyObject_GetAttrString() here. */
     254    PyObject *sizeObj = PyObject_GetAttrString((PyObject*)&PyType_Type, "__basicsize__");
     255    int basicsize = (int)PyLong_AsLong(sizeObj) + (int)sizeof(Py_nsIID);
     256#endif
    242257        PyType_Spec TypeSpec = {
    243258                /* .name: */            "IID",
    244                 /* .basicsize: */       sizeof(Py_nsIID),
     259                /* .basicsize: */       basicsize,
    245260                /* .itemsize: */        0,
    246261                /* .flags: */           Py_TPFLAGS_DEFAULT,
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