#include "pymacro.h"
#include "pymath.h"
#include "pymem.h"
+#include "pytypedefs.h"
#include "pybuffer.h"
#include "object.h"
#include "objimpl.h"
extern "C" {
#endif
-typedef struct PyCodeObject PyCodeObject;
-
#ifndef Py_LIMITED_API
# define Py_CPYTHON_CODE_H
# include "cpython/code.h"
PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *);
PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *);
-struct PyModuleDef;
PyAPI_FUNC(PyObject *) PyType_GetModuleByDef(PyTypeObject *, struct PyModuleDef *);
-struct _Py_Identifier;
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
PyAPI_FUNC(void) _Py_BreakPoint(void);
PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
passed as second argument to Py_TRASHCAN_BEGIN().
*/
-/* Forward declarations for PyThreadState */
-struct _ts;
-
/* Python 3.9 private API, invoked by the macros below. */
PyAPI_FUNC(int) _PyTrash_begin(struct _ts *tstate, PyObject *op);
PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate);
typedef PyObject *(*getter)(PyObject *, void *);
typedef int (*setter)(PyObject *, PyObject *, void *);
-typedef struct PyGetSetDef {
+struct PyGetSetDef {
const char *name;
getter get;
setter set;
const char *doc;
void *closure;
-} PyGetSetDef;
+};
PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type;
PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type;
/* Long (arbitrary precision) integer object interface */
-typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */
-
PyAPI_DATA(PyTypeObject) PyLong_Type;
#define PyLong_Check(op) \
describe the args expected by the C func */
const char *ml_doc; /* The __doc__ attribute, or NULL */
};
-typedef struct PyMethodDef PyMethodDef;
/* PyCFunction_New is declared as a function for stable ABI (declaration is
* needed for e.g. GCC with -fvisibility=hidden), but redefined as a macro
#endif /* New in 3.5 */
-typedef struct PyModuleDef{
+struct PyModuleDef {
PyModuleDef_Base m_base;
const char* m_name;
const char* m_doc;
traverseproc m_traverse;
inquiry m_clear;
freefunc m_free;
-} PyModuleDef;
+};
// Internal C API
#ifndef Py_OBJECT_H
#define Py_OBJECT_H
-
#ifdef __cplusplus
extern "C" {
#endif
# error Py_LIMITED_API is incompatible with Py_TRACE_REFS
#endif
-/* PyTypeObject structure is defined in cpython/object.h.
- In Py_LIMITED_API, PyTypeObject is an opaque structure. */
-typedef struct _typeobject PyTypeObject;
-
#ifdef Py_TRACE_REFS
/* Define pointers to support a doubly-linked list of all live heap objects. */
#define _PyObject_HEAD_EXTRA \
* by hand. Similarly every pointer to a variable-size Python object can,
* in addition, be cast to PyVarObject*.
*/
-typedef struct _object {
+struct _object {
_PyObject_HEAD_EXTRA
Py_ssize_t ob_refcnt;
PyTypeObject *ob_type;
-} PyObject;
+};
/* Cast argument to PyObject* type. */
#define _PyObject_CAST(op) ((PyObject*)(op))
#ifdef __cplusplus
}
#endif
-#endif /* !Py_OBJECT_H */
+#endif // !Py_OBJECT_H
*
*/
-// Forward declaration to be able to include pybuffer.h before object.h:
-// pybuffer.h uses PyObject and object.h uses Py_buffer.
-typedef struct _object PyObject;
-
typedef struct {
void *buf;
PyObject *obj; /* owned reference */
extern "C" {
#endif
-typedef struct _frame PyFrameObject;
-
/* Return the line of code the frame is currently executing. */
PyAPI_FUNC(int) PyFrame_GetLineNumber(PyFrameObject *);
removed (with effort). */
#define MAX_CO_EXTRA_USERS 255
-/* Forward declarations for PyFrameObject, PyThreadState
- and PyInterpreterState */
-struct _ts;
-struct _is;
-
-/* struct _ts is defined in cpython/pystate.h */
-typedef struct _ts PyThreadState;
-/* struct _is is defined in internal/pycore_interp.h */
-typedef struct _is PyInterpreterState;
-
PyAPI_FUNC(PyInterpreterState *) PyInterpreterState_New(void);
PyAPI_FUNC(void) PyInterpreterState_Clear(PyInterpreterState *);
PyAPI_FUNC(void) PyInterpreterState_Delete(PyInterpreterState *);
--- /dev/null
+// Forward declarations of types of the Python C API.
+// Declare them at the same place since redefining typedef is a C11 feature.
+// Only use a forward declaration if there is an interdependency between two
+// header files.
+
+#ifndef Py_PYTYPEDEFS_H
+#define Py_PYTYPEDEFS_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct PyModuleDef PyModuleDef;
+typedef struct PyMethodDef PyMethodDef;
+typedef struct PyGetSetDef PyGetSetDef;
+typedef struct PyMemberDef PyMemberDef;
+
+typedef struct _object PyObject;
+typedef struct _longobject PyLongObject;
+typedef struct _typeobject PyTypeObject;
+typedef struct PyCodeObject PyCodeObject;
+typedef struct _frame PyFrameObject;
+
+typedef struct _ts PyThreadState;
+typedef struct _is PyInterpreterState;
+
+#ifdef __cplusplus
+}
+#endif
+#endif // !Py_PYTYPEDEFS_H
flag is set). The array must be terminated with an entry whose name
pointer is NULL. */
-typedef struct PyMemberDef {
+struct PyMemberDef {
const char *name;
int type;
Py_ssize_t offset;
int flags;
const char *doc;
-} PyMemberDef;
+};
/* Types */
#define T_SHORT 0
$(srcdir)/Include/pystrtod.h \
$(srcdir)/Include/pythonrun.h \
$(srcdir)/Include/pythread.h \
+ $(srcdir)/Include/pytypedefs.h \
$(srcdir)/Include/rangeobject.h \
$(srcdir)/Include/setobject.h \
$(srcdir)/Include/sliceobject.h \
<ClInclude Include="..\Include\pystrtod.h" />
<ClInclude Include="..\Include\pythonrun.h" />
<ClInclude Include="..\Include\pythread.h" />
+ <ClInclude Include="..\Include\pytypedefs.h" />
<ClInclude Include="..\Include\rangeobject.h" />
<ClInclude Include="..\Include\setobject.h" />
<ClInclude Include="..\Include\sliceobject.h" />
<ClInclude Include="..\Include\pythread.h">
<Filter>Include</Filter>
</ClInclude>
+ <ClInclude Include="..\Include\pytypedefs.h">
+ <Filter>Include</Filter>
+ </ClInclude>
<ClInclude Include="..\Include\rangeobject.h">
<Filter>Include</Filter>
</ClInclude>