Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca7b046

Browse files
committed
Issue #17162: Add PyType_GetSlot.
1 parent 83bdfa0 commit ca7b046

6 files changed

Lines changed: 30 additions & 2 deletions

File tree

Doc/c-api/type.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,13 @@ Type Objects
9797
types. This allows the caller to reference other heap types as base types.
9898
9999
.. versionadded:: 3.3
100+
101+
.. c:function:: void* PyType_GetSlot(PyTypeObject *type, int slot)
102+
103+
Return the function pointer stored int the given slot. If the
104+
result is *NULL*, this indicates that either the slot is *NULL*,
105+
or that the function was called with invalid parameters.
106+
Callers will typically cast the result pointer into the appropriate
107+
function type.
108+
109+
.. versionadded:: 3.4

Include/object.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*);
439439
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
440440
PyAPI_FUNC(PyObject*) PyType_FromSpecWithBases(PyType_Spec*, PyObject*);
441441
#endif
442+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
443+
PyAPI_FUNC(void*) PyType_GetSlot(PyTypeObject*, int);
444+
#endif
442445

443446
#ifndef Py_LIMITED_API
444447
/* The *real* layout of a type object when allocated on the heap */

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Release date: 2014-02-09
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #17162: Add PyType_GetSlot.
14+
1315
- Issue #20162: Fix an alignment issue in the siphash24() hash function which
1416
caused a crash on PowerPC 64-bit (ppc64).
1517

Modules/xxlimited.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void
4444
Xxo_dealloc(XxoObject *self)
4545
{
4646
Py_XDECREF(self->x_attr);
47-
PyObject_Del(self);
47+
((freefunc)PyType_GetSlot(Py_TYPE(self), Py_tp_free))(self);
4848
}
4949

5050
static PyObject *

Objects/typeobject.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,6 +2641,19 @@ PyType_FromSpec(PyType_Spec *spec)
26412641
return PyType_FromSpecWithBases(spec, NULL);
26422642
}
26432643

2644+
void *
2645+
PyType_GetSlot(PyTypeObject *type, int slot)
2646+
{
2647+
if (!PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
2648+
PyErr_BadInternalCall();
2649+
return NULL;
2650+
}
2651+
if (slot >= Py_ARRAY_LENGTH(slotoffsets)) {
2652+
/* Extension module requesting slot from a future version */
2653+
return NULL;
2654+
}
2655+
return *(void**)(((char*)type) + slotoffsets[slot]);
2656+
}
26442657

26452658
/* Internal API to look for a name through the MRO.
26462659
This returns a borrowed reference, and doesn't set an exception! */

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ class db_found(Exception): pass
15391539

15401540
if 'd' not in sys.abiflags:
15411541
ext = Extension('xxlimited', ['xxlimited.c'],
1542-
define_macros=[('Py_LIMITED_API', 1)])
1542+
define_macros=[('Py_LIMITED_API', '0x03040000')])
15431543
self.extensions.append(ext)
15441544

15451545
return missing

0 commit comments

Comments
 (0)