summaryrefslogtreecommitdiffstats
path: root/Include/cpython
diff options
context:
space:
mode:
Diffstat (limited to 'Include/cpython')
-rw-r--r--Include/cpython/classobject.h57
-rw-r--r--Include/cpython/context.h78
-rw-r--r--Include/cpython/genobject.h100
-rw-r--r--Include/cpython/longintrepr.h99
4 files changed, 334 insertions, 0 deletions
diff --git a/Include/cpython/classobject.h b/Include/cpython/classobject.h
new file mode 100644
index 0000000..80df884
--- /dev/null
+++ b/Include/cpython/classobject.h
@@ -0,0 +1,57 @@
+/* Former class object interface -- now only bound methods are here */
+
+/* Revealing some structures (not for general use) */
+
+#ifndef Py_LIMITED_API
+#ifndef Py_CLASSOBJECT_H
+#define Py_CLASSOBJECT_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ PyObject_HEAD
+ PyObject *im_func; /* The callable object implementing the method */
+ PyObject *im_self; /* The instance it is bound to */
+ PyObject *im_weakreflist; /* List of weak references */
+ vectorcallfunc vectorcall;
+} PyMethodObject;
+
+PyAPI_DATA(PyTypeObject) PyMethod_Type;
+
+#define PyMethod_Check(op) Py_IS_TYPE(op, &PyMethod_Type)
+
+PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *);
+
+PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
+PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
+
+/* Macros for direct access to these values. Type checks are *not*
+ done, so use with care. */
+#define PyMethod_GET_FUNCTION(meth) \
+ (((PyMethodObject *)meth) -> im_func)
+#define PyMethod_GET_SELF(meth) \
+ (((PyMethodObject *)meth) -> im_self)
+
+typedef struct {
+ PyObject_HEAD
+ PyObject *func;
+} PyInstanceMethodObject;
+
+PyAPI_DATA(PyTypeObject) PyInstanceMethod_Type;
+
+#define PyInstanceMethod_Check(op) Py_IS_TYPE(op, &PyInstanceMethod_Type)
+
+PyAPI_FUNC(PyObject *) PyInstanceMethod_New(PyObject *);
+PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
+
+/* Macros for direct access to these values. Type checks are *not*
+ done, so use with care. */
+#define PyInstanceMethod_GET_FUNCTION(meth) \
+ (((PyInstanceMethodObject *)meth) -> func)
+
+#ifdef __cplusplus
+}
+#endif
+#endif // !Py_CLASSOBJECT_H
+#endif // !Py_LIMITED_API
diff --git a/Include/cpython/context.h b/Include/cpython/context.h
new file mode 100644
index 0000000..4db079f
--- /dev/null
+++ b/Include/cpython/context.h
@@ -0,0 +1,78 @@
+#ifndef Py_LIMITED_API
+#ifndef Py_CONTEXT_H
+#define Py_CONTEXT_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+PyAPI_DATA(PyTypeObject) PyContext_Type;
+typedef struct _pycontextobject PyContext;
+
+PyAPI_DATA(PyTypeObject) PyContextVar_Type;
+typedef struct _pycontextvarobject PyContextVar;
+
+PyAPI_DATA(PyTypeObject) PyContextToken_Type;
+typedef struct _pycontexttokenobject PyContextToken;
+
+
+#define PyContext_CheckExact(o) Py_IS_TYPE(o, &PyContext_Type)
+#define PyContextVar_CheckExact(o) Py_IS_TYPE(o, &PyContextVar_Type)
+#define PyContextToken_CheckExact(o) Py_IS_TYPE(o, &PyContextToken_Type)
+
+
+PyAPI_FUNC(PyObject *) PyContext_New(void);
+PyAPI_FUNC(PyObject *) PyContext_Copy(PyObject *);
+PyAPI_FUNC(PyObject *) PyContext_CopyCurrent(void);
+
+PyAPI_FUNC(int) PyContext_Enter(PyObject *);
+PyAPI_FUNC(int) PyContext_Exit(PyObject *);
+
+
+/* Create a new context variable.
+
+ default_value can be NULL.
+*/
+PyAPI_FUNC(PyObject *) PyContextVar_New(
+ const char *name, PyObject *default_value);
+
+
+/* Get a value for the variable.
+
+ Returns -1 if an error occurred during lookup.
+
+ Returns 0 if value either was or was not found.
+
+ If value was found, *value will point to it.
+ If not, it will point to:
+
+ - default_value, if not NULL;
+ - the default value of "var", if not NULL;
+ - NULL.
+
+ '*value' will be a new ref, if not NULL.
+*/
+PyAPI_FUNC(int) PyContextVar_Get(
+ PyObject *var, PyObject *default_value, PyObject **value);
+
+
+/* Set a new value for the variable.
+ Returns NULL if an error occurs.
+*/
+PyAPI_FUNC(PyObject *) PyContextVar_Set(PyObject *var, PyObject *value);
+
+
+/* Reset a variable to its previous value.
+ Returns 0 on success, -1 on error.
+*/
+PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token);
+
+
+/* This method is exposed only for CPython tests. Don not use it. */
+PyAPI_FUNC(PyObject *) _PyContext_NewHamtForTests(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_CONTEXT_H */
+#endif /* !Py_LIMITED_API */
diff --git a/Include/cpython/genobject.h b/Include/cpython/genobject.h
new file mode 100644
index 0000000..8f87cf5
--- /dev/null
+++ b/Include/cpython/genobject.h
@@ -0,0 +1,100 @@
+/* Generator object interface */
+
+#ifndef Py_LIMITED_API
+#ifndef Py_GENOBJECT_H
+#define Py_GENOBJECT_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* --- Generators --------------------------------------------------------- */
+
+/* _PyGenObject_HEAD defines the initial segment of generator
+ and coroutine objects. */
+#define _PyGenObject_HEAD(prefix) \
+ PyObject_HEAD \
+ /* Note: gi_frame can be NULL if the generator is "finished" */ \
+ struct _interpreter_frame *prefix##_xframe; \
+ /* The code object backing the generator */ \
+ PyCodeObject *prefix##_code; \
+ /* List of weak reference. */ \
+ PyObject *prefix##_weakreflist; \
+ /* Name of the generator. */ \
+ PyObject *prefix##_name; \
+ /* Qualified name of the generator. */ \
+ PyObject *prefix##_qualname; \
+ _PyErr_StackItem prefix##_exc_state;
+
+typedef struct {
+ /* The gi_ prefix is intended to remind of generator-iterator. */
+ _PyGenObject_HEAD(gi)
+} PyGenObject;
+
+PyAPI_DATA(PyTypeObject) PyGen_Type;
+
+#define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type)
+#define PyGen_CheckExact(op) Py_IS_TYPE(op, &PyGen_Type)
+
+PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *);
+PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
+ PyObject *name, PyObject *qualname);
+PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
+PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
+PyObject *_PyGen_yf(PyGenObject *);
+PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
+
+
+/* --- PyCoroObject ------------------------------------------------------- */
+
+typedef struct {
+ _PyGenObject_HEAD(cr)
+ PyObject *cr_origin;
+} PyCoroObject;
+
+PyAPI_DATA(PyTypeObject) PyCoro_Type;
+PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
+
+#define PyCoro_CheckExact(op) Py_IS_TYPE(op, &PyCoro_Type)
+PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
+PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
+ PyObject *name, PyObject *qualname);
+
+
+/* --- Asynchronous Generators -------------------------------------------- */
+
+typedef struct {
+ _PyGenObject_HEAD(ag)
+ PyObject *ag_finalizer;
+
+ /* Flag is set to 1 when hooks set up by sys.set_asyncgen_hooks
+ were called on the generator, to avoid calling them more
+ than once. */
+ int ag_hooks_inited;
+
+ /* Flag is set to 1 when aclose() is called for the first time, or
+ when a StopAsyncIteration exception is raised. */
+ int ag_closed;
+
+ int ag_running_async;
+} PyAsyncGenObject;
+
+PyAPI_DATA(PyTypeObject) PyAsyncGen_Type;
+PyAPI_DATA(PyTypeObject) _PyAsyncGenASend_Type;
+PyAPI_DATA(PyTypeObject) _PyAsyncGenWrappedValue_Type;
+PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
+
+PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
+ PyObject *name, PyObject *qualname);
+
+#define PyAsyncGen_CheckExact(op) Py_IS_TYPE(op, &PyAsyncGen_Type)
+
+PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
+
+
+#undef _PyGenObject_HEAD
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_GENOBJECT_H */
+#endif /* Py_LIMITED_API */
diff --git a/Include/cpython/longintrepr.h b/Include/cpython/longintrepr.h
new file mode 100644
index 0000000..ff4155f
--- /dev/null
+++ b/Include/cpython/longintrepr.h
@@ -0,0 +1,99 @@
+#ifndef Py_LIMITED_API
+#ifndef Py_LONGINTREPR_H
+#define Py_LONGINTREPR_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* This is published for the benefit of "friends" marshal.c and _decimal.c. */
+
+/* Parameters of the integer representation. There are two different
+ sets of parameters: one set for 30-bit digits, stored in an unsigned 32-bit
+ integer type, and one set for 15-bit digits with each digit stored in an
+ unsigned short. The value of PYLONG_BITS_IN_DIGIT, defined either at
+ configure time or in pyport.h, is used to decide which digit size to use.
+
+ Type 'digit' should be able to hold 2*PyLong_BASE-1, and type 'twodigits'
+ should be an unsigned integer type able to hold all integers up to
+ PyLong_BASE*PyLong_BASE-1. x_sub assumes that 'digit' is an unsigned type,
+ and that overflow is handled by taking the result modulo 2**N for some N >
+ PyLong_SHIFT. The majority of the code doesn't care about the precise
+ value of PyLong_SHIFT, but there are some notable exceptions:
+
+ - long_pow() requires that PyLong_SHIFT be divisible by 5
+
+ - PyLong_{As,From}ByteArray require that PyLong_SHIFT be at least 8
+
+ - long_hash() requires that PyLong_SHIFT is *strictly* less than the number
+ of bits in an unsigned long, as do the PyLong <-> long (or unsigned long)
+ conversion functions
+
+ - the Python int <-> size_t/Py_ssize_t conversion functions expect that
+ PyLong_SHIFT is strictly less than the number of bits in a size_t
+
+ - the marshal code currently expects that PyLong_SHIFT is a multiple of 15
+
+ - NSMALLNEGINTS and NSMALLPOSINTS should be small enough to fit in a single
+ digit; with the current values this forces PyLong_SHIFT >= 9
+
+ The values 15 and 30 should fit all of the above requirements, on any
+ platform.
+*/
+
+#if PYLONG_BITS_IN_DIGIT == 30
+typedef uint32_t digit;
+typedef int32_t sdigit; /* signed variant of digit */
+typedef uint64_t twodigits;
+typedef int64_t stwodigits; /* signed variant of twodigits */
+#define PyLong_SHIFT 30
+#define _PyLong_DECIMAL_SHIFT 9 /* max(e such that 10**e fits in a digit) */
+#define _PyLong_DECIMAL_BASE ((digit)1000000000) /* 10 ** DECIMAL_SHIFT */
+#elif PYLONG_BITS_IN_DIGIT == 15
+typedef unsigned short digit;
+typedef short sdigit; /* signed variant of digit */
+typedef unsigned long twodigits;
+typedef long stwodigits; /* signed variant of twodigits */
+#define PyLong_SHIFT 15
+#define _PyLong_DECIMAL_SHIFT 4 /* max(e such that 10**e fits in a digit) */
+#define _PyLong_DECIMAL_BASE ((digit)10000) /* 10 ** DECIMAL_SHIFT */
+#else
+#error "PYLONG_BITS_IN_DIGIT should be 15 or 30"
+#endif
+#define PyLong_BASE ((digit)1 << PyLong_SHIFT)
+#define PyLong_MASK ((digit)(PyLong_BASE - 1))
+
+#if PyLong_SHIFT % 5 != 0
+#error "longobject.c requires that PyLong_SHIFT be divisible by 5"
+#endif
+
+/* Long integer representation.
+ The absolute value of a number is equal to
+ SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i)
+ Negative numbers are represented with ob_size < 0;
+ zero is represented by ob_size == 0.
+ In a normalized number, ob_digit[abs(ob_size)-1] (the most significant
+ digit) is never zero. Also, in all cases, for all valid i,
+ 0 <= ob_digit[i] <= MASK.
+ The allocation function takes care of allocating extra memory
+ so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available.
+
+ CAUTION: Generic code manipulating subtypes of PyVarObject has to
+ aware that ints abuse ob_size's sign bit.
+*/
+
+struct _longobject {
+ PyObject_VAR_HEAD
+ digit ob_digit[1];
+};
+
+PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);
+
+/* Return a copy of src. */
+PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_LONGINTREPR_H */
+#endif /* Py_LIMITED_API */