◐ Shell
reader mode source ↗
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
3 changes: 3 additions & 0 deletions Doc/c-api/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ The following functions and structs are used to create

This function calls :c:func:`PyType_Ready` on the new type.

.. versionadded:: 3.3

.. c:function:: PyObject* PyType_FromSpec(PyType_Spec *spec)
Expand Down
4 changes: 4 additions & 0 deletions Include/bltinmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ PyAPI_DATA(PyTypeObject) PyFilter_Type;
PyAPI_DATA(PyTypeObject) PyMap_Type;
PyAPI_DATA(PyTypeObject) PyZip_Type;

#ifdef __cplusplus
}
#endif
Expand Down
16 changes: 12 additions & 4 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,20 @@ typedef struct _heaptypeobject {
PyBufferProcs as_buffer;
PyObject *ht_name, *ht_slots, *ht_qualname;
struct _dictkeysobject *ht_cached_keys;
/* here are optional user slots, followed by the members. */
} PyHeapTypeObject;

/* access macro to the members which are floating "behind" the object */
#define PyHeapType_GET_MEMBERS(etype) \
((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))

PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *);
PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
Expand Down
12 changes: 9 additions & 3 deletions Include/descrobject.h
Original file line number Diff line number Diff line change
@@ -52,18 +52,24 @@ typedef struct {

typedef struct {
PyDescr_COMMON;
PyMethodDef *d_method;
vectorcallfunc vectorcall;
} PyMethodDescrObject;

typedef struct {
PyDescr_COMMON;
struct PyMemberDef *d_member;
} PyMemberDescrObject;

typedef struct {
PyDescr_COMMON;
PyGetSetDef *d_getset;
} PyGetSetDescrObject;

typedef struct {
Expand Down
5 changes: 5 additions & 0 deletions Include/structmember.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ typedef struct PyMemberDef {
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);


#ifdef __cplusplus
}
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ def test_objecttypes(self):
# buffer
# XXX
# builtin_function_or_method
check(len, size('5P'))
# bytearray
samples = [b'', b'u'*100000]
for sample in samples:
Expand Up @@ -1111,15 +1111,15 @@ def inner():
# complex
check(complex(0,1), size('2d'))
# method_descriptor (descriptor object)
check(str.lower, size('3PPP'))
# classmethod_descriptor (descriptor object)
# XXX
# member_descriptor (descriptor object)
import datetime
check(datetime.timedelta.days, size('3PP'))
# getset_descriptor (descriptor object)
import collections
check(collections.defaultdict.default_factory, size('3PP'))
# wrapper_descriptor (descriptor object)
check(int.__add__, size('3P2P'))
# method-wrapper (descriptor object)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
38 changes: 18 additions & 20 deletions Modules/_lsprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,42 +132,40 @@ normalizeUserObj(PyObject *obj)
if (modname != NULL) {
if (!_PyUnicode_EqualToASCIIString(modname, "builtins")) {
PyObject *result;
result = PyUnicode_FromFormat("<%U.%s>", modname,
fn->m_ml->ml_name);
Py_DECREF(modname);
return result;
}
Py_DECREF(modname);
}
return PyUnicode_FromFormat("<%s>", fn->m_ml->ml_name);
}
else {
/* built-in method: try to return
repr(getattr(type(__self__), __name__))
*/
PyObject *self = fn->m_self;
PyObject *name = PyUnicode_FromString(fn->m_ml->ml_name);
PyObject *modname = fn->m_module;

if (name != NULL) {
PyObject *mo = _PyType_Lookup(Py_TYPE(self), name);
Py_XINCREF(mo);
Py_DECREF(name);
if (mo != NULL) {
PyObject *res = PyObject_Repr(mo);
Py_DECREF(mo);
if (res != NULL)
return res;
}
}
/* Otherwise, use __module__ */
PyErr_Clear();
if (modname != NULL && PyUnicode_Check(modname))
return PyUnicode_FromFormat("<built-in method %S.%s>",
modname, fn->m_ml->ml_name);
else
return PyUnicode_FromFormat("<built-in method %s>",
fn->m_ml->ml_name);
}
}

Expand Down Expand Up @@ -409,7 +407,7 @@ profiler_callback(PyObject *self, PyFrameObject *frame, int what,
if ((((ProfilerObject *)self)->flags & POF_BUILTINS)
&& PyCFunction_Check(arg)) {
ptrace_enter_call(self,
((PyCFunctionObject *)arg)->m_ml,
arg);
}
break;
Expand All @@ -421,7 +419,7 @@ profiler_callback(PyObject *self, PyFrameObject *frame, int what,
if ((((ProfilerObject *)self)->flags & POF_BUILTINS)
&& PyCFunction_Check(arg)) {
ptrace_leave_call(self,
((PyCFunctionObject *)arg)->m_ml);
}
break;

Expand Down
3 changes: 2 additions & 1 deletion Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ctype.h>
#include "structmember.h" /* we need the offsetof() macro from there */
#include "longintrepr.h"



Expand Up @@ -840,7 +841,7 @@ binary_op(PyObject *v, PyObject *w, const int op_slot, const char *op_name)

if (op_slot == NB_SLOT(nb_rshift) &&
PyCFunction_Check(v) &&
strcmp(((PyCFunctionObject *)v)->m_ml->ml_name, "print") == 0)
{
PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for %.100s: "
Expand Down
Loading
Toggle all file notes Toggle all file annotations