Skip to content

Commit d4a85f1

Browse files
authored
bpo-35134: Add Include/cpython/descrobject.h (GH-30923)
Move Include/descrobject.h non-limited API to a new Include/cpython/descrobject.h header file.
1 parent 3eb3b4f commit d4a85f1

File tree

5 files changed

+78
-69
lines changed

5 files changed

+78
-69
lines changed

Include/cpython/descrobject.h

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#ifndef Py_CPYTHON_DESCROBJECT_H
2+
# error "this header file must not be included directly"
3+
#endif
4+
5+
typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
6+
void *wrapped);
7+
8+
typedef PyObject *(*wrapperfunc_kwds)(PyObject *self, PyObject *args,
9+
void *wrapped, PyObject *kwds);
10+
11+
struct wrapperbase {
12+
const char *name;
13+
int offset;
14+
void *function;
15+
wrapperfunc wrapper;
16+
const char *doc;
17+
int flags;
18+
PyObject *name_strobj;
19+
};
20+
21+
/* Flags for above struct */
22+
#define PyWrapperFlag_KEYWORDS 1 /* wrapper function takes keyword args */
23+
24+
/* Various kinds of descriptor objects */
25+
26+
typedef struct {
27+
PyObject_HEAD
28+
PyTypeObject *d_type;
29+
PyObject *d_name;
30+
PyObject *d_qualname;
31+
} PyDescrObject;
32+
33+
#define PyDescr_COMMON PyDescrObject d_common
34+
35+
#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
36+
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
37+
38+
typedef struct {
39+
PyDescr_COMMON;
40+
PyMethodDef *d_method;
41+
vectorcallfunc vectorcall;
42+
} PyMethodDescrObject;
43+
44+
typedef struct {
45+
PyDescr_COMMON;
46+
struct PyMemberDef *d_member;
47+
} PyMemberDescrObject;
48+
49+
typedef struct {
50+
PyDescr_COMMON;
51+
PyGetSetDef *d_getset;
52+
} PyGetSetDescrObject;
53+
54+
typedef struct {
55+
PyDescr_COMMON;
56+
struct wrapperbase *d_base;
57+
void *d_wrapped; /* This can be any function pointer */
58+
} PyWrapperDescrObject;
59+
60+
PyAPI_DATA(PyTypeObject) _PyMethodWrapper_Type;
61+
62+
PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
63+
struct wrapperbase *, void *);
64+
PyAPI_FUNC(int) PyDescr_IsData(PyObject *);

Include/descrobject.h

+8-68
Original file line numberDiff line numberDiff line change
@@ -16,93 +16,33 @@ typedef struct PyGetSetDef {
1616
void *closure;
1717
} PyGetSetDef;
1818

19-
#ifndef Py_LIMITED_API
20-
typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args,
21-
void *wrapped);
22-
23-
typedef PyObject *(*wrapperfunc_kwds)(PyObject *self, PyObject *args,
24-
void *wrapped, PyObject *kwds);
25-
26-
struct wrapperbase {
27-
const char *name;
28-
int offset;
29-
void *function;
30-
wrapperfunc wrapper;
31-
const char *doc;
32-
int flags;
33-
PyObject *name_strobj;
34-
};
35-
36-
/* Flags for above struct */
37-
#define PyWrapperFlag_KEYWORDS 1 /* wrapper function takes keyword args */
38-
39-
/* Various kinds of descriptor objects */
40-
41-
typedef struct {
42-
PyObject_HEAD
43-
PyTypeObject *d_type;
44-
PyObject *d_name;
45-
PyObject *d_qualname;
46-
} PyDescrObject;
47-
48-
#define PyDescr_COMMON PyDescrObject d_common
49-
50-
#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
51-
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
52-
53-
typedef struct {
54-
PyDescr_COMMON;
55-
PyMethodDef *d_method;
56-
vectorcallfunc vectorcall;
57-
} PyMethodDescrObject;
58-
59-
typedef struct {
60-
PyDescr_COMMON;
61-
struct PyMemberDef *d_member;
62-
} PyMemberDescrObject;
63-
64-
typedef struct {
65-
PyDescr_COMMON;
66-
PyGetSetDef *d_getset;
67-
} PyGetSetDescrObject;
68-
69-
typedef struct {
70-
PyDescr_COMMON;
71-
struct wrapperbase *d_base;
72-
void *d_wrapped; /* This can be any function pointer */
73-
} PyWrapperDescrObject;
74-
#endif /* Py_LIMITED_API */
75-
7619
PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
7720
PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
7821
PyAPI_DATA(PyTypeObject) PyMemberDescr_Type;
7922
PyAPI_DATA(PyTypeObject) PyMethodDescr_Type;
8023
PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type;
8124
PyAPI_DATA(PyTypeObject) PyDictProxy_Type;
82-
#ifndef Py_LIMITED_API
83-
PyAPI_DATA(PyTypeObject) _PyMethodWrapper_Type;
84-
#endif /* Py_LIMITED_API */
25+
PyAPI_DATA(PyTypeObject) PyProperty_Type;
26+
// Forward declaration for following prototype
27+
struct PyMemberDef;
8528

8629
PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *);
8730
PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *);
88-
struct PyMemberDef; /* forward declaration for following prototype */
8931
PyAPI_FUNC(PyObject *) PyDescr_NewMember(PyTypeObject *,
9032
struct PyMemberDef *);
9133
PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
9234
struct PyGetSetDef *);
93-
#ifndef Py_LIMITED_API
94-
PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
95-
struct wrapperbase *, void *);
96-
PyAPI_FUNC(int) PyDescr_IsData(PyObject *);
97-
#endif
9835

9936
PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
10037
PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *);
10138

39+
#ifndef Py_LIMITED_API
40+
# define Py_CPYTHON_DESCROBJECT_H
41+
# include "cpython/descrobject.h"
42+
# undef Py_CPYTHON_DESCROBJECT_H
43+
#endif
10244

103-
PyAPI_DATA(PyTypeObject) PyProperty_Type;
10445
#ifdef __cplusplus
10546
}
10647
#endif
10748
#endif /* !Py_DESCROBJECT_H */
108-

Makefile.pre.in

+1
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ PYTHON_HEADERS= \
15051505
$(srcdir)/Include/cpython/code.h \
15061506
$(srcdir)/Include/cpython/compile.h \
15071507
$(srcdir)/Include/cpython/context.h \
1508+
$(srcdir)/Include/cpython/descrobject.h \
15081509
$(srcdir)/Include/cpython/dictobject.h \
15091510
$(srcdir)/Include/cpython/fileobject.h \
15101511
$(srcdir)/Include/cpython/fileutils.h \

PCbuild/pythoncore.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
<ClInclude Include="..\Include\cpython\code.h" />
143143
<ClInclude Include="..\Include\cpython\compile.h" />
144144
<ClInclude Include="..\Include\cpython\context.h" />
145+
<ClInclude Include="..\Include\cpython\descrobject.h" />
145146
<ClInclude Include="..\Include\cpython\dictobject.h" />
146147
<ClInclude Include="..\Include\cpython\fileobject.h" />
147148
<ClInclude Include="..\Include\cpython\fileutils.h" />

PCbuild/pythoncore.vcxproj.filters

+4-1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@
366366
<ClInclude Include="..\Include\cpython\context.h">
367367
<Filter>Include\cpython</Filter>
368368
</ClInclude>
369+
<ClInclude Include="..\Include\cpython\descrobject.h">
370+
<Filter>Include\cpython</Filter>
371+
</ClInclude>
369372
<ClInclude Include="..\Include\cpython\dictobject.h">
370373
<Filter>Include\cpython</Filter>
371374
</ClInclude>
@@ -1274,4 +1277,4 @@
12741277
<Filter>Resource Files</Filter>
12751278
</ResourceCompile>
12761279
</ItemGroup>
1277-
</Project>
1280+
</Project>

0 commit comments

Comments
 (0)