Commit 007ac7ba authored by Jeroen Demeyer's avatar Jeroen Demeyer

Add various declarations for the CPython C API

parent 1a1087bd
from .object cimport PyObject, PyTypeObject
cdef extern from "Python.h":
ctypedef object (*wrapperfunc)(self, args, void* wrapped)
ctypedef object (*wrapperfunc_kwds)(self, args, void* wrapped, kwds)
struct wrapperbase:
char* name
int offset
void* function
wrapperfunc wrapper
char* doc
int flags
PyObject* name_strobj
int PyWrapperFlag_KEYWORDS
ctypedef class __builtin__.wrapper_descriptor [object PyWrapperDescrObject]:
cdef type d_type
cdef d_name
cdef wrapperbase* d_base
cdef void* d_wrapped
PyDescr_NewWrapper(PyTypeObject* cls, wrapperbase* wrapper, void* wrapped)
int PyDescr_IsData(descr)
from .object cimport PyObject
from .pyport cimport uint64_t
cdef extern from "Python.h":
# On Python 2, PyDict_GetItemWithError is called _PyDict_GetItemWithError
"""
#if PY_MAJOR_VERSION <= 2
#define PyDict_GetItemWithError _PyDict_GetItemWithError
#endif
"""
############################################################################
# 7.4.1 Dictionary Objects
......@@ -72,11 +79,25 @@ cdef extern from "Python.h":
# NULL if the key key is not present, but without setting an
# exception.
PyObject* PyDict_GetItemWithError(object p, object key) except? NULL
# Return value: Borrowed reference.
# Variant of PyDict_GetItem() that does not suppress exceptions. Return
# NULL with an exception set if an exception occurred. Return NULL
# without an exception set if the key wasn’t present.
PyObject* PyDict_GetItemString(object p, const char *key)
# Return value: Borrowed reference.
# This is the same as PyDict_GetItem(), but key is specified as a
# char*, rather than a PyObject*.
PyObject* PyDict_SetDefault(object p, object key, object default) except NULL
# Return value: Borrowed reference.
# This is the same as the Python-level dict.setdefault(). If present, it
# returns the value corresponding to key from the dictionary p. If the key
# is not in the dict, it is inserted with value defaultobj and defaultobj
# is returned. This function evaluates the hash function of key only once,
# instead of evaluating it independently for the lookup and the insertion.
list PyDict_Items(object p)
# Return value: New reference.
# Return a PyListObject containing all the items from the
......
......@@ -145,6 +145,12 @@ cdef extern from "Python.h":
bint PyModule_CheckExact(object p)
# Return true if p is a module object, but not a subtype of PyModule_Type.
object PyModule_NewObject(object name)
# Return a new module object with the __name__ attribute set to name.
# The module’s __name__, __doc__, __package__, and __loader__
# attributes are filled in (all but __name__ are set to None); the caller
# is responsible for providing a __file__ attribute.
object PyModule_New(const char *name)
# Return value: New reference.
# Return a new module object with the __name__ attribute set to
......@@ -160,15 +166,28 @@ cdef extern from "Python.h":
# use other PyModule_*() and PyObject_*() functions rather than
# directly manipulate a module's __dict__.
object PyModule_GetNameObject(object module)
# Return module’s __name__ value. If the module does not provide one, or if
# it is not a string, SystemError is raised and NULL is returned.
char* PyModule_GetName(object module) except NULL
# Return module's __name__ value. If the module does not provide
# one, or if it is not a string, SystemError is raised and NULL is
# returned.
# Similar to PyModule_GetNameObject() but return the name encoded
# to 'utf-8'.
void* PyModule_GetState(object module)
# Return the “state” of the module, that is, a pointer to the block of
# memory allocated at module creation time, or NULL.
# See PyModuleDef.m_size.
object PyModule_GetFilenameObject(object module)
# Return the name of the file from which module was loaded using module’s
# __file__ attribute. If this is not defined, or if it is not a unicode
# string, raise SystemError and return NULL; otherwise return a reference
# to a Unicode object.
char* PyModule_GetFilename(object module) except NULL
# Return the name of the file from which module was loaded using
# module's __file__ attribute. If this is not defined, or if it is
# not a string, raise SystemError and return NULL.
# Similar to PyModule_GetFilenameObject() but return the filename encoded
# to ‘utf-8’.
int PyModule_AddObject(object module, const char *name, object value) except -1
# Add an object to module as name. This is a convenience function
......
......@@ -45,6 +45,8 @@ cdef extern from "Python.h":
newfunc tp_new
destructor tp_dealloc
destructor tp_del
destructor tp_finalize
traverseproc tp_traverse
inquiry tp_clear
freefunc tp_free
......@@ -63,6 +65,8 @@ cdef extern from "Python.h":
descrgetfunc tp_descr_get
descrsetfunc tp_descr_set
unsigned int tp_version_tag
ctypedef struct PyObject:
Py_ssize_t ob_refcnt
PyTypeObject *ob_type
......@@ -397,3 +401,4 @@ cdef extern from "Python.h":
long Py_TPFLAGS_DEFAULT_EXTERNAL
long Py_TPFLAGS_DEFAULT_CORE
long Py_TPFLAGS_DEFAULT
long Py_TPFLAGS_HAVE_FINALIZE
cdef extern from "Python.h":
ctypedef int int32_t
ctypedef int int64_t
ctypedef unsigned int uint32_t
ctypedef unsigned int uint64_t
const Py_ssize_t PY_SSIZE_T_MIN
const Py_ssize_t PY_SSIZE_T_MAX
......@@ -23,6 +23,11 @@ cdef extern from "Python.h":
# of the standard type object. Return false in all other
# cases.
void PyType_Modified(type type)
# Invalidate the internal lookup cache for the type and all of its
# subtypes. This function must be called after any manual modification
# of the attributes or base classes of the type.
bint PyType_HasFeature(object o, int feature)
# Return true if the type object o sets the feature feature. Type
# features are denoted by single bit flags.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment