Commit d5c3de3f authored by Stefan Behnel's avatar Stefan Behnel

merge

parents 7b9b3153 37e86755
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
############################################################################ ############################################################################
# 7.2.2 Boolean Objects # 7.2.2 Boolean Objects
......
# Please see the Python header files (object.h) for docs # Please see the Python header files (object.h/abstract.h) for docs
from python_ref cimport PyObject
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef struct bufferinfo:
void *buf
Py_ssize_t len
Py_ssize_t itemsize
int readonly
int ndim
char *format
Py_ssize_t *shape
Py_ssize_t *strides
Py_ssize_t *suboffsets
void *internal
ctypedef bufferinfo Py_buffer
cdef enum: cdef enum:
PyBUF_SIMPLE, PyBUF_SIMPLE,
...@@ -39,14 +25,14 @@ cdef extern from "Python.h": ...@@ -39,14 +25,14 @@ cdef extern from "Python.h":
PyBUF_WRITE, PyBUF_WRITE,
PyBUF_SHADOW PyBUF_SHADOW
int PyObject_CheckBuffer(PyObject* obj) int PyObject_CheckBuffer(object obj)
int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) int PyObject_GetBuffer(object obj, Py_buffer *view, int flags)
void PyObject_ReleaseBuffer(PyObject *obj, Py_buffer *view) void PyObject_ReleaseBuffer(object obj, Py_buffer *view)
void* PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices) void* PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices)
int PyBuffer_SizeFromFormat(char *) # actually const char int PyBuffer_SizeFromFormat(char *) # actually const char
int PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, char fort) int PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, char fort)
int PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort) int PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort)
int PyObject_CopyData(PyObject *dest, PyObject *src) int PyObject_CopyData(object dest, object src)
int PyBuffer_IsContiguous(Py_buffer *view, char fort) int PyBuffer_IsContiguous(Py_buffer *view, char fort)
void PyBuffer_FillContiguousStrides(int ndims, void PyBuffer_FillContiguousStrides(int ndims,
Py_ssize_t *shape, Py_ssize_t *shape,
...@@ -57,5 +43,5 @@ cdef extern from "Python.h": ...@@ -57,5 +43,5 @@ cdef extern from "Python.h":
Py_ssize_t len, int readonly, Py_ssize_t len, int readonly,
int flags) int flags)
PyObject* PyObject_Format(PyObject* obj, object PyObject_Format(object obj,
PyObject *format_spec) object format_spec)
from python_ref cimport PyObject
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
########################################################################### ###########################################################################
# Warning: # Warning:
......
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
ctypedef struct Py_complex ctypedef struct Py_complex
############################################################################ ############################################################################
......
from python_ref cimport PyObject
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
############################################################################ ############################################################################
# 7.4.1 Dictionary Objects # 7.4.1 Dictionary Objects
############################################################################ ############################################################################
# PyDictObject # PyDictObject
# This subtype of PyObject represents a Python dictionary object. #
# This subtype of PyObject represents a Python dictionary object
# (i.e. the 'dict' type).
# PyTypeObject PyDict_Type # PyTypeObject PyDict_Type
# This instance of PyTypeObject represents the Python dictionary type. This is exposed to Python programs as dict and types.DictType. #
# This instance of PyTypeObject represents the Python dictionary
# type. This is exposed to Python programs as dict and
# types.DictType.
bint PyDict_Check(object p) bint PyDict_Check(object p)
# Return true if p is a dict object or an instance of a subtype of # Return true if p is a dict object or an instance of a subtype of
...@@ -29,7 +38,7 @@ cdef extern from "Python.h": ...@@ -29,7 +38,7 @@ cdef extern from "Python.h":
void PyDict_Clear(object p) void PyDict_Clear(object p)
# Empty an existing dictionary of all key-value pairs. # Empty an existing dictionary of all key-value pairs.
int PyDict_Contains(object p, object key) int PyDict_Contains(object p, object key) except -1
# Determine if dictionary p contains key. If an item in p is # Determine if dictionary p contains key. If an item in p is
# matches key, return 1, otherwise return 0. On error, return # matches key, return 1, otherwise return 0. On error, return
# -1. This is equivalent to the Python expression "key in p". # -1. This is equivalent to the Python expression "key in p".
...@@ -38,22 +47,22 @@ cdef extern from "Python.h": ...@@ -38,22 +47,22 @@ cdef extern from "Python.h":
# Return value: New reference. # Return value: New reference.
# Return a new dictionary that contains the same key-value pairs as p. # Return a new dictionary that contains the same key-value pairs as p.
int PyDict_SetItem(object p, object key, object val) int PyDict_SetItem(object p, object key, object val) except -1
# Insert value into the dictionary p with a key of key. key must # Insert value into the dictionary p with a key of key. key must
# be hashable; if it isn't, TypeError will be raised. Return 0 on # be hashable; if it isn't, TypeError will be raised. Return 0 on
# success or -1 on failure. # success or -1 on failure.
int PyDict_SetItemString(object p, char *key, object val) int PyDict_SetItemString(object p, char *key, object val) except -1
# Insert value into the dictionary p using key as a key. key # Insert value into the dictionary p using key as a key. key
# should be a char*. The key object is created using # should be a char*. The key object is created using
# PyString_FromString(key). Return 0 on success or -1 on failure. # PyString_FromString(key). Return 0 on success or -1 on failure.
int PyDict_DelItem(object p, object key) int PyDict_DelItem(object p, object key) except -1
# Remove the entry in dictionary p with key key. key must be # Remove the entry in dictionary p with key key. key must be
# hashable; if it isn't, TypeError is raised. Return 0 on success # hashable; if it isn't, TypeError is raised. Return 0 on success
# or -1 on failure. # or -1 on failure.
int PyDict_DelItemString(object p, char *key) int PyDict_DelItemString(object p, char *key) except -1
# Remove the entry in dictionary p which has a key specified by # Remove the entry in dictionary p which has a key specified by
# the string key. Return 0 on success or -1 on failure. # the string key. Return 0 on success or -1 on failure.
...@@ -87,7 +96,8 @@ cdef extern from "Python.h": ...@@ -87,7 +96,8 @@ cdef extern from "Python.h":
# Python Library Reference). # Python Library Reference).
Py_ssize_t PyDict_Size(object p) Py_ssize_t PyDict_Size(object p)
# Return the number of items in the dictionary. This is equivalent to "len(p)" on a dictionary. # Return the number of items in the dictionary. This is equivalent
# to "len(p)" on a dictionary.
int PyDict_Next(object p, Py_ssize_t *ppos, PyObject* *pkey, PyObject* *pvalue) int PyDict_Next(object p, Py_ssize_t *ppos, PyObject* *pkey, PyObject* *pvalue)
# Iterate over all key-value pairs in the dictionary p. The int # Iterate over all key-value pairs in the dictionary p. The int
...@@ -128,7 +138,7 @@ cdef extern from "Python.h": ...@@ -128,7 +138,7 @@ cdef extern from "Python.h":
# Py_DECREF(o); # Py_DECREF(o);
# } # }
int PyDict_Merge(object a, object b, int override) int PyDict_Merge(object a, object b, int override) except -1
# Iterate over mapping object b adding key-value pairs to # Iterate over mapping object b adding key-value pairs to
# dictionary a. b may be a dictionary, or any object supporting # dictionary a. b may be a dictionary, or any object supporting
# PyMapping_Keys() and PyObject_GetItem(). If override is true, # PyMapping_Keys() and PyObject_GetItem(). If override is true,
...@@ -137,11 +147,11 @@ cdef extern from "Python.h": ...@@ -137,11 +147,11 @@ cdef extern from "Python.h":
# matching key in a. Return 0 on success or -1 if an exception was # matching key in a. Return 0 on success or -1 if an exception was
# raised. # raised.
int PyDict_Update(object a, object b) int PyDict_Update(object a, object b) except -1
# This is the same as PyDict_Merge(a, b, 1) in C, or a.update(b) # This is the same as PyDict_Merge(a, b, 1) in C, or a.update(b)
# in Python. Return 0 on success or -1 if an exception was raised. # in Python. Return 0 on success or -1 if an exception was raised.
int PyDict_MergeFromSeq2(object a, object seq2, int override) int PyDict_MergeFromSeq2(object a, object seq2, int override) except -1
# Update or merge into dictionary a, from the key-value pairs in # Update or merge into dictionary a, from the key-value pairs in
# seq2. seq2 must be an iterable object producing iterable objects # seq2. seq2 must be an iterable object producing iterable objects
# of length 2, viewed as key-value pairs. In case of duplicate # of length 2, viewed as key-value pairs. In case of duplicate
......
from python_ref cimport PyObject
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
##################################################################### #####################################################################
# 3. Exception Handling # 3. Exception Handling
......
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
############################################################################ ############################################################################
# 7.2.3 # 7.2.3
############################################################################ ############################################################################
# PyFloatObject # PyFloatObject
# This subtype of PyObject represents a Python floating point object. #
# This subtype of PyObject represents a Python floating point object.
# PyTypeObject PyFloat_Type # PyTypeObject PyFloat_Type
# This instance of PyTypeObject represents the Python floating point type. This is the same object as float and types.FloatType. #
# This instance of PyTypeObject represents the Python floating
# point type. This is the same object as float and
# types.FloatType.
bint PyFloat_Check(object p) bint PyFloat_Check(object p)
# Return true if its argument is a PyFloatObject or a subtype of # Return true if its argument is a PyFloatObject or a subtype of
...@@ -28,7 +32,8 @@ cdef extern from "Python.h": ...@@ -28,7 +32,8 @@ cdef extern from "Python.h":
# Create a PyFloatObject object from v, or NULL on failure. # Create a PyFloatObject object from v, or NULL on failure.
double PyFloat_AsDouble(object pyfloat) double PyFloat_AsDouble(object pyfloat)
# Return a C double representation of the contents of pyfloat. # Return a C double representation of the contents of pyfloat.
double PyFloat_AS_DOUBLE(object pyfloat) double PyFloat_AS_DOUBLE(object pyfloat)
# Return a C double representation of the contents of pyfloat, but without error checking. # Return a C double representation of the contents of pyfloat, but
# without error checking.
from python_ref cimport PyObject
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
############################################################################ ############################################################################
# 7.5.3 Function Objects # 7.5.3 Function Objects
############################################################################ ############################################################################
# There are a few functions specific to Python functions. # There are a few functions specific to Python functions.
# PyFunctionObject # PyFunctionObject
# The C structure used for functions. #
# The C structure used for functions.
# PyTypeObject PyFunction_Type # PyTypeObject PyFunction_Type
#
# This is an instance of PyTypeObject and represents the Python # This is an instance of PyTypeObject and represents the Python
# function type. It is exposed to Python programmers as # function type. It is exposed to Python programmers as
# types.FunctionType. # types.FunctionType.
...@@ -43,7 +49,7 @@ cdef extern from "Python.h": ...@@ -43,7 +49,7 @@ cdef extern from "Python.h":
# Return the argument default values of the function object # Return the argument default values of the function object
# op. This can be a tuple of arguments or NULL. # op. This can be a tuple of arguments or NULL.
int PyFunction_SetDefaults(object op, object defaults) int PyFunction_SetDefaults(object op, object defaults) except -1
# Set the argument default values for the function object # Set the argument default values for the function object
# op. defaults must be Py_None or a tuple. # op. defaults must be Py_None or a tuple.
# Raises SystemError and returns -1 on failure. # Raises SystemError and returns -1 on failure.
...@@ -53,7 +59,7 @@ cdef extern from "Python.h": ...@@ -53,7 +59,7 @@ cdef extern from "Python.h":
# Return the closure associated with the function object op. This # Return the closure associated with the function object op. This
# can be NULL or a tuple of cell objects. # can be NULL or a tuple of cell objects.
int PyFunction_SetClosure(object op, object closure) int PyFunction_SetClosure(object op, object closure) except -1
# Set the closure associated with the function object op. closure # Set the closure associated with the function object op. closure
# must be Py_None or a tuple of cell objects. # must be Py_None or a tuple of cell objects.
# Raises SystemError and returns -1 on failure. # Raises SystemError and returns -1 on failure.
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
############################################################################ ############################################################################
# 7.5.2 Instance Objects # 7.5.2 Instance Objects
############################################################################ ############################################################################
# PyTypeObject PyInstance_Type # PyTypeObject PyInstance_Type
# Type object for class instances. #
# int PyInstance_Check(PyObject *obj) # Type object for class instances.
int PyInstance_Check(object obj)
# Return true if obj is an instance. # Return true if obj is an instance.
object PyInstance_New(PyObject* cls, object arg, object kw) object PyInstance_New(object cls, object arg, object kw)
# Return value: New reference. # Return value: New reference.
# Create a new instance of a specific class. The parameters arg # Create a new instance of a specific class. The parameters arg
# and kw are used as the positional and keyword parameters to the # and kw are used as the positional and keyword parameters to the
......
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject ctypedef unsigned long long PY_LONG_LONG
############################################################################ ############################################################################
# Integer Objects # Integer Objects
...@@ -48,7 +48,7 @@ cdef extern from "Python.h": ...@@ -48,7 +48,7 @@ cdef extern from "Python.h":
# Create a new integer object with a value of ival. If the value # Create a new integer object with a value of ival. If the value
# exceeds LONG_MAX, a long integer object is returned. # exceeds LONG_MAX, a long integer object is returned.
long PyInt_AsLong(object io) long PyInt_AsLong(object io) except? -1
# Will first attempt to cast the object to a PyIntObject, if it is # Will first attempt to cast the object to a PyIntObject, if it is
# not already one, and then return its value. If there is an # not already one, and then return its value. If there is an
# error, -1 is returned, and the caller should check # error, -1 is returned, and the caller should check
...@@ -64,7 +64,6 @@ cdef extern from "Python.h": ...@@ -64,7 +64,6 @@ cdef extern from "Python.h":
# value as unsigned long. This function does not check for # value as unsigned long. This function does not check for
# overflow. # overflow.
ctypedef unsigned long long PY_LONG_LONG
PY_LONG_LONG PyInt_AsUnsignedLongLongMask(object io) PY_LONG_LONG PyInt_AsUnsignedLongLongMask(object io)
# Will first attempt to cast the object to a PyIntObject or # Will first attempt to cast the object to a PyIntObject or
# PyLongObject, if it is not already one, and then return its # PyLongObject, if it is not already one, and then return its
......
...@@ -3,7 +3,7 @@ cdef extern from "Python.h": ...@@ -3,7 +3,7 @@ cdef extern from "Python.h":
############################################################################ ############################################################################
# 6.5 Iterator Protocol # 6.5 Iterator Protocol
############################################################################ ############################################################################
int PyIter_Check(object o) bint PyIter_Check(object o)
# Return true if the object o supports the iterator protocol. # Return true if the object o supports the iterator protocol.
object PyIter_Next(object o) object PyIter_Next(object o)
......
from python_ref cimport PyObject
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
############################################################################ ############################################################################
# Lists # Lists
############################################################################ ############################################################################
object PyList_New(Py_ssize_t len) object PyList_New(Py_ssize_t len)
# Return a new list of length len on success, or NULL on # Return a new list of length len on success, or NULL on failure.
# failure. Note: If length is greater than zero, the returned list #
# object's items are set to NULL. Thus you cannot use abstract API # Note: If length is greater than zero, the returned list object's
# items are set to NULL. Thus you cannot use abstract API
# functions such as PySequence_SetItem() or expose the object to # functions such as PySequence_SetItem() or expose the object to
# Python code before setting all items to a real object with # Python code before setting all items to a real object with
# PyList_SetItem(). # PyList_SetItem().
bint PyList_Check(object p) bint PyList_Check(object p)
# Return true if p is a list object or an instance of a subtype of the list type. # Return true if p is a list object or an instance of a subtype of
# the list type.
bint PyList_CheckExact(object p) bint PyList_CheckExact(object p)
# Return true if p is a list object, but not an instance of a subtype of the list type. # Return true if p is a list object, but not an instance of a
# subtype of the list type.
Py_ssize_t PyList_Size(object list) Py_ssize_t PyList_Size(object list)
# Return the length of the list object in list; this is equivalent to "len(list)" on a list object. # Return the length of the list object in list; this is equivalent
# to "len(list)" on a list object.
Py_ssize_t PyList_GET_SIZE(object list) Py_ssize_t PyList_GET_SIZE(object list)
# Macro form of PyList_Size() without error checking. # Macro form of PyList_Size() without error checking.
...@@ -35,7 +40,7 @@ cdef extern from "Python.h": ...@@ -35,7 +40,7 @@ cdef extern from "Python.h":
# Return value: Borrowed reference. # Return value: Borrowed reference.
# Macro form of PyList_GetItem() without error checking. # Macro form of PyList_GetItem() without error checking.
int PyList_SetItem(object list, Py_ssize_t index, object item) int PyList_SetItem(object list, Py_ssize_t index, object item) except -1
# Set the item at index index in list to item. Return 0 on success # Set the item at index index in list to item. Return 0 on success
# or -1 on failure. Note: This function ``steals'' a reference to # or -1 on failure. Note: This function ``steals'' a reference to
# item and discards a reference to an item already in the list at # item and discards a reference to an item already in the list at
...@@ -49,12 +54,12 @@ cdef extern from "Python.h": ...@@ -49,12 +54,12 @@ cdef extern from "Python.h":
# to any item that it being replaced; any reference in list at # to any item that it being replaced; any reference in list at
# position i will be *leaked*. # position i will be *leaked*.
int PyList_Insert(object list, Py_ssize_t index, object item) int PyList_Insert(object list, Py_ssize_t index, object item) except -1
# Insert the item item into list list in front of index # Insert the item item into list list in front of index
# index. Return 0 if successful; return -1 and set an exception if # index. Return 0 if successful; return -1 and set an exception if
# unsuccessful. Analogous to list.insert(index, item). # unsuccessful. Analogous to list.insert(index, item).
int PyList_Append(object list, object item) int PyList_Append(object list, object item) except -1
# Append the object item at the end of list list. Return 0 if # Append the object item at the end of list list. Return 0 if
# successful; return -1 and set an exception if # successful; return -1 and set an exception if
# unsuccessful. Analogous to list.append(item). # unsuccessful. Analogous to list.append(item).
...@@ -65,17 +70,17 @@ cdef extern from "Python.h": ...@@ -65,17 +70,17 @@ cdef extern from "Python.h":
# between low and high. Return NULL and set an exception if # between low and high. Return NULL and set an exception if
# unsuccessful. Analogous to list[low:high]. # unsuccessful. Analogous to list[low:high].
int PyList_SetSlice(object list, Py_ssize_t low, Py_ssize_t high, object itemlist) int PyList_SetSlice(object list, Py_ssize_t low, Py_ssize_t high, object itemlist) except -1
# Set the slice of list between low and high to the contents of # Set the slice of list between low and high to the contents of
# itemlist. Analogous to list[low:high] = itemlist. The itemlist # itemlist. Analogous to list[low:high] = itemlist. The itemlist
# may be NULL, indicating the assignment of an empty list (slice # may be NULL, indicating the assignment of an empty list (slice
# deletion). Return 0 on success, -1 on failure. # deletion). Return 0 on success, -1 on failure.
int PyList_Sort(object list) int PyList_Sort(object list) except -1
# Sort the items of list in place. Return 0 on success, -1 on # Sort the items of list in place. Return 0 on success, -1 on
# failure. This is equivalent to "list.sort()". # failure. This is equivalent to "list.sort()".
int PyList_Reverse(object list) int PyList_Reverse(object list) except -1
# Reverse the items of list in place. Return 0 on success, -1 on # Reverse the items of list in place. Return 0 on success, -1 on
# failure. This is the equivalent of "list.reverse()". # failure. This is the equivalent of "list.reverse()".
......
from python_unicode cimport Py_UNICODE
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject ctypedef long long PY_LONG_LONG
ctypedef long PY_LONG_LONG ctypedef unsigned long long uPY_LONG_LONG
############################################################################ ############################################################################
# 7.2.3 Long Integer Objects # 7.2.3 Long Integer Objects
############################################################################ ############################################################################
# PyLongObject # PyLongObject
# This subtype of PyObject represents a Python long integer object. #
# This subtype of PyObject represents a Python long integer object.
# PyTypeObject PyLong_Type # PyTypeObject PyLong_Type
#
# This instance of PyTypeObject represents the Python long integer # This instance of PyTypeObject represents the Python long integer
# type. This is the same object as long and types.LongType. # type. This is the same object as long and types.LongType.
...@@ -29,8 +35,7 @@ cdef extern from "Python.h": ...@@ -29,8 +35,7 @@ cdef extern from "Python.h":
# Return value: New reference. # Return value: New reference.
# Return a new PyLongObject object from a C long long, or NULL on failure. # Return a new PyLongObject object from a C long long, or NULL on failure.
object PyLong_FromUnsignedLongLong(PY_LONG_LONG v) object PyLong_FromUnsignedLongLong(uPY_LONG_LONG v)
#PyObject* PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG v)
# Return value: New reference. # Return value: New reference.
# Return a new PyLongObject object from a C unsigned long long, or NULL on failure. # Return a new PyLongObject object from a C unsigned long long, or NULL on failure.
...@@ -51,8 +56,7 @@ cdef extern from "Python.h": ...@@ -51,8 +56,7 @@ cdef extern from "Python.h":
# inclusive. Leading spaces are ignored. If there are no digits, # inclusive. Leading spaces are ignored. If there are no digits,
# ValueError will be raised. # ValueError will be raised.
object PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
# object PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
# Return value: New reference. # Return value: New reference.
# Convert a sequence of Unicode digits to a Python long integer # Convert a sequence of Unicode digits to a Python long integer
# value. The first parameter, u, points to the first character of # value. The first parameter, u, points to the first character of
...@@ -82,7 +86,7 @@ cdef extern from "Python.h": ...@@ -82,7 +86,7 @@ cdef extern from "Python.h":
# cannot be represented as a long long, an OverflowError will be # cannot be represented as a long long, an OverflowError will be
# raised. # raised.
PY_LONG_LONG PyLong_AsUnsignedLongLong(object pylong) uPY_LONG_LONG PyLong_AsUnsignedLongLong(object pylong)
#unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(object pylong) #unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(object pylong)
# Return a C unsigned long long from a Python long integer. If # Return a C unsigned long long from a Python long integer. If
# pylong cannot be represented as an unsigned long long, an # pylong cannot be represented as an unsigned long long, an
...@@ -93,13 +97,12 @@ cdef extern from "Python.h": ...@@ -93,13 +97,12 @@ cdef extern from "Python.h":
# Return a C unsigned long from a Python long integer, without # Return a C unsigned long from a Python long integer, without
# checking for overflow. # checking for overflow.
PY_LONG_LONG PyLong_AsUnsignedLongLongMask(object io) uPY_LONG_LONG PyLong_AsUnsignedLongLongMask(object io)
#unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(object io) #unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(object io)
# Return a C unsigned long long from a Python long integer, # Return a C unsigned long long from a Python long integer,
# without checking for overflow. # without checking for overflow.
double PyLong_AsDouble(object pylong) except? -1.0
double PyLong_AsDouble(object pylong)
# Return a C double representation of the contents of pylong. If # Return a C double representation of the contents of pylong. If
# pylong cannot be approximately represented as a double, an # pylong cannot be approximately represented as a double, an
# OverflowError exception is raised and -1.0 will be returned. # OverflowError exception is raised and -1.0 will be returned.
......
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
############################################################################ ############################################################################
# 6.4 Mapping Protocol # 6.4 Mapping Protocol
...@@ -9,17 +8,17 @@ cdef extern from "Python.h": ...@@ -9,17 +8,17 @@ cdef extern from "Python.h":
# Return 1 if the object provides mapping protocol, and 0 # Return 1 if the object provides mapping protocol, and 0
# otherwise. This function always succeeds. # otherwise. This function always succeeds.
Py_ssize_t PyMapping_Length(object o) Py_ssize_t PyMapping_Length(object o) except -1
# Returns the number of keys in object o on success, and -1 on # Returns the number of keys in object o on success, and -1 on
# failure. For objects that do not provide mapping protocol, this # failure. For objects that do not provide mapping protocol, this
# is equivalent to the Python expression "len(o)". # is equivalent to the Python expression "len(o)".
int PyMapping_DelItemString(object o, char *key) int PyMapping_DelItemString(object o, char *key) except -1
# Remove the mapping for object key from the object o. Return -1 # Remove the mapping for object key from the object o. Return -1
# on failure. This is equivalent to the Python statement "del # on failure. This is equivalent to the Python statement "del
# o[key]". # o[key]".
int PyMapping_DelItem(object o, object key) int PyMapping_DelItem(object o, object key) except -1
# Remove the mapping for object key from the object o. Return -1 # Remove the mapping for object key from the object o. Return -1
# on failure. This is equivalent to the Python statement "del # on failure. This is equivalent to the Python statement "del
# o[key]". # o[key]".
...@@ -58,7 +57,7 @@ cdef extern from "Python.h": ...@@ -58,7 +57,7 @@ cdef extern from "Python.h":
# failure. This is the equivalent of the Python expression # failure. This is the equivalent of the Python expression
# "o[key]". # "o[key]".
int PyMapping_SetItemString(object o, char *key, object v) int PyMapping_SetItemString(object o, char *key, object v) except -1
# Map the object key to the value v in object o. Returns -1 on # Map the object key to the value v in object o. Returns -1 on
# failure. This is the equivalent of the Python statement "o[key] # failure. This is the equivalent of the Python statement "o[key]
# = v". # = v".
......
from python_ref cimport PyObject
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
ctypedef struct _inittab ctypedef struct _inittab
##################################################################### #####################################################################
...@@ -50,7 +51,7 @@ cdef extern from "Python.h": ...@@ -50,7 +51,7 @@ cdef extern from "Python.h":
# the reloaded module, or NULL with an exception set on failure # the reloaded module, or NULL with an exception set on failure
# (the module still exists in this case). # (the module still exists in this case).
PyObject* PyImport_AddModule(char *name) PyObject* PyImport_AddModule(char *name) except NULL
# Return value: Borrowed reference. # Return value: Borrowed reference.
# Return the module object corresponding to a module name. The # Return the module object corresponding to a module name. The
# name argument may be of the form package.module. First check the # name argument may be of the form package.module. First check the
...@@ -96,7 +97,7 @@ cdef extern from "Python.h": ...@@ -96,7 +97,7 @@ cdef extern from "Python.h":
# variable. # variable.
int PyImport_ImportFrozenModule(char *name) int PyImport_ImportFrozenModule(char *name) except -1
# Load a frozen module named name. Return 1 for success, 0 if the # Load a frozen module named name. Return 1 for success, 0 if the
# module is not found, and -1 with an exception set if the # module is not found, and -1 with an exception set if the
# initialization failed. To access the imported module on a # initialization failed. To access the imported module on a
...@@ -105,7 +106,7 @@ cdef extern from "Python.h": ...@@ -105,7 +106,7 @@ cdef extern from "Python.h":
# imported.) # imported.)
int PyImport_ExtendInittab(_inittab *newtab) int PyImport_ExtendInittab(_inittab *newtab) except -1
# Add a collection of modules to the table of built-in # Add a collection of modules to the table of built-in
# modules. The newtab array must end with a sentinel entry which # modules. The newtab array must end with a sentinel entry which
# contains NULL for the name field; failure to provide the # contains NULL for the name field; failure to provide the
...@@ -118,7 +119,9 @@ cdef extern from "Python.h": ...@@ -118,7 +119,9 @@ cdef extern from "Python.h":
##################################################################### #####################################################################
# 7.5.5 Module Objects # 7.5.5 Module Objects
##################################################################### #####################################################################
# PyTypeObject PyModule_Type # PyTypeObject PyModule_Type
#
# This instance of PyTypeObject represents the Python module # This instance of PyTypeObject represents the Python module
# type. This is exposed to Python programs as types.ModuleType. # type. This is exposed to Python programs as types.ModuleType.
...@@ -129,7 +132,7 @@ cdef extern from "Python.h": ...@@ -129,7 +132,7 @@ cdef extern from "Python.h":
bint PyModule_CheckExact(object p) bint PyModule_CheckExact(object p)
# Return true if p is a module object, but not a subtype of PyModule_Type. # Return true if p is a module object, but not a subtype of PyModule_Type.
object PyModule_New( char *name) object PyModule_New(char *name)
# Return value: New reference. # Return value: New reference.
# Return a new module object with the __name__ attribute set to # Return a new module object with the __name__ attribute set to
# name. Only the module's __doc__ and __name__ attributes are # name. Only the module's __doc__ and __name__ attributes are
...@@ -144,28 +147,28 @@ cdef extern from "Python.h": ...@@ -144,28 +147,28 @@ cdef extern from "Python.h":
# use other PyModule_*() and PyObject_*() functions rather than # use other PyModule_*() and PyObject_*() functions rather than
# directly manipulate a module's __dict__. # directly manipulate a module's __dict__.
char* PyModule_GetName(object module) char* PyModule_GetName(object module) except NULL
# Return module's __name__ value. If the module does not provide # 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 # one, or if it is not a string, SystemError is raised and NULL is
# returned. # returned.
char* PyModule_GetFilename(object module) char* PyModule_GetFilename(object module) except NULL
# Return the name of the file from which module was loaded using # 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 # module's __file__ attribute. If this is not defined, or if it is
# not a string, raise SystemError and return NULL. # not a string, raise SystemError and return NULL.
int PyModule_AddObject(object module, char *name, object value) int PyModule_AddObject(object module, char *name, object value) except -1
# Add an object to module as name. This is a convenience function # Add an object to module as name. This is a convenience function
# which can be used from the module's initialization # which can be used from the module's initialization
# function. This steals a reference to value. Return -1 on error, # function. This steals a reference to value. Return -1 on error,
# 0 on success. # 0 on success.
int PyModule_AddIntant(object module, char *name, long value) int PyModule_AddIntant(object module, char *name, long value) except -1
# Add an integer ant to module as name. This convenience # Add an integer ant to module as name. This convenience
# function can be used from the module's initialization # function can be used from the module's initialization
# function. Return -1 on error, 0 on success. # function. Return -1 on error, 0 on success.
int PyModule_AddStringant(object module, char *name, char *value) int PyModule_AddStringant(object module, char *name, char *value) except -1
# Add a string constant to module as name. This convenience # Add a string constant to module as name. This convenience
# function can be used from the module's initialization # function can be used from the module's initialization
# function. The string value must be null-terminated. Return -1 on # function. The string value must be null-terminated. Return -1 on
......
from python_ref cimport PyObject
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
ctypedef void PyTypeObject
ctypedef struct FILE
##################################################################### #####################################################################
# 6.2 Number Protocol # 6.2 Number Protocol
...@@ -203,7 +201,7 @@ cdef extern from "Python.h": ...@@ -203,7 +201,7 @@ cdef extern from "Python.h":
# failure. The operation is done in-place when o1 supports # failure. The operation is done in-place when o1 supports
# it. This is the equivalent of the Python statement "o1 |= o2". # it. This is the equivalent of the Python statement "o1 |= o2".
int PyNumber_Coerce(PyObject **p1, PyObject **p2) int PyNumber_Coerce(PyObject **p1, PyObject **p2) except -1
# This function takes the addresses of two variables of type # This function takes the addresses of two variables of type
# PyObject*. If the objects pointed to by *p1 and *p2 have the # PyObject*. If the objects pointed to by *p1 and *p2 have the
# same type, increment their reference count and return 0 # same type, increment their reference count and return 0
...@@ -249,4 +247,5 @@ cdef extern from "Python.h": ...@@ -249,4 +247,5 @@ cdef extern from "Python.h":
# integer or PY_SSIZE_T_MAX for a positive integer. # integer or PY_SSIZE_T_MAX for a positive integer.
bint PyIndex_Check(object o) bint PyIndex_Check(object o)
# Returns True if o is an index integer (has the nb_index slot of the tp_as_number structure filled in). # Returns True if o is an index integer (has the nb_index slot of
# the tp_as_number structure filled in).
from python_ref cimport PyObject from python_ref cimport PyObject, PyTypeObject
from stdio cimport FILE
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyTypeObject
ctypedef struct FILE
##################################################################### #####################################################################
# 6.1 Object Protocol # 6.1 Object Protocol
##################################################################### #####################################################################
int PyObject_Print(object o, FILE *fp, int flags) int PyObject_Print(object o, FILE *fp, int flags) except -1
# Print an object o, on file fp. Returns -1 on error. The flags # Print an object o, on file fp. Returns -1 on error. The flags
# argument is used to enable certain printing options. The only # argument is used to enable certain printing options. The only
# option currently supported is Py_PRINT_RAW; if given, the str() # option currently supported is Py_PRINT_RAW; if given, the str()
...@@ -35,22 +34,22 @@ cdef extern from "Python.h": ...@@ -35,22 +34,22 @@ cdef extern from "Python.h":
# or NULL on failure. This is the equivalent of the Python # or NULL on failure. This is the equivalent of the Python
# expression "o.attr_name". # expression "o.attr_name".
int PyObject_SetAttrString(object o, char *attr_name, object v) int PyObject_SetAttrString(object o, char *attr_name, object v) except -1
# Set the value of the attribute named attr_name, for object o, to # Set the value of the attribute named attr_name, for object o, to
# the value v. Returns -1 on failure. This is the equivalent of # the value v. Returns -1 on failure. This is the equivalent of
# the Python statement "o.attr_name = v". # the Python statement "o.attr_name = v".
int PyObject_SetAttr(object o, object attr_name, object v) int PyObject_SetAttr(object o, object attr_name, object v) except -1
# Set the value of the attribute named attr_name, for object o, to # Set the value of the attribute named attr_name, for object o, to
# the value v. Returns -1 on failure. This is the equivalent of # the value v. Returns -1 on failure. This is the equivalent of
# the Python statement "o.attr_name = v". # the Python statement "o.attr_name = v".
int PyObject_DelAttrString(object o, char *attr_name) int PyObject_DelAttrString(object o, char *attr_name) except -1
# Delete attribute named attr_name, for object o. Returns -1 on # Delete attribute named attr_name, for object o. Returns -1 on
# failure. This is the equivalent of the Python statement: "del # failure. This is the equivalent of the Python statement: "del
# o.attr_name". # o.attr_name".
int PyObject_DelAttr(object o, object attr_name) int PyObject_DelAttr(object o, object attr_name) except -1
# Delete attribute named attr_name, for object o. Returns -1 on # Delete attribute named attr_name, for object o. Returns -1 on
# failure. This is the equivalent of the Python statement "del # failure. This is the equivalent of the Python statement "del
# o.attr_name". # o.attr_name".
...@@ -65,7 +64,7 @@ cdef extern from "Python.h": ...@@ -65,7 +64,7 @@ cdef extern from "Python.h":
# opid. Returns the value of the comparison on success, or NULL on # opid. Returns the value of the comparison on success, or NULL on
# failure. # failure.
int PyObject_RichCompareBool(object o1, object o2, int opid) bint PyObject_RichCompareBool(object o1, object o2, int opid) except -1
# Compare the values of o1 and o2 using the operation specified by # Compare the values of o1 and o2 using the operation specified by
# opid, which must be one of Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, or # opid, which must be one of Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, or
# Py_GE, corresponding to <, <=, ==, !=, >, or >= # Py_GE, corresponding to <, <=, ==, !=, >, or >=
...@@ -73,14 +72,14 @@ cdef extern from "Python.h": ...@@ -73,14 +72,14 @@ cdef extern from "Python.h":
# otherwise. This is the equivalent of the Python expression "o1 # otherwise. This is the equivalent of the Python expression "o1
# op o2", where op is the operator corresponding to opid. # op o2", where op is the operator corresponding to opid.
int PyObject_Cmp(object o1, object o2, int *result) int PyObject_Cmp(object o1, object o2, int *result) except -1
# Compare the values of o1 and o2 using a routine provided by o1, # Compare the values of o1 and o2 using a routine provided by o1,
# if one exists, otherwise with a routine provided by o2. The # if one exists, otherwise with a routine provided by o2. The
# result of the comparison is returned in result. Returns -1 on # result of the comparison is returned in result. Returns -1 on
# failure. This is the equivalent of the Python statement "result # failure. This is the equivalent of the Python statement "result
# = cmp(o1, o2)". # = cmp(o1, o2)".
int PyObject_Compare(object o1, object o2) int PyObject_Compare(object o1, object o2) except *
# Compare the values of o1 and o2 using a routine provided by o1, # Compare the values of o1 and o2 using a routine provided by o1,
# if one exists, otherwise with a routine provided by o2. Returns # if one exists, otherwise with a routine provided by o2. Returns
# the result of the comparison on success. On error, the value # the result of the comparison on success. On error, the value
...@@ -109,7 +108,7 @@ cdef extern from "Python.h": ...@@ -109,7 +108,7 @@ cdef extern from "Python.h":
# is the equivalent of the Python expression "unicode(o)". Called # is the equivalent of the Python expression "unicode(o)". Called
# by the unicode() built-in function. # by the unicode() built-in function.
bint PyObject_IsInstance(object inst, object cls) bint PyObject_IsInstance(object inst, object cls) except -1
# Returns 1 if inst is an instance of the class cls or a subclass # Returns 1 if inst is an instance of the class cls or a subclass
# of cls, or 0 if not. On error, returns -1 and sets an # of cls, or 0 if not. On error, returns -1 and sets an
# exception. If cls is a type object rather than a class object, # exception. If cls is a type object rather than a class object,
...@@ -134,7 +133,7 @@ cdef extern from "Python.h": ...@@ -134,7 +133,7 @@ cdef extern from "Python.h":
# fashion for A -- the presence of the __bases__ attribute is # fashion for A -- the presence of the __bases__ attribute is
# considered sufficient for this determination. # considered sufficient for this determination.
bint PyObject_IsSubclass(object derived, object cls) bint PyObject_IsSubclass(object derived, object cls) except -1
# Returns 1 if the class derived is identical to or derived from # Returns 1 if the class derived is identical to or derived from
# the class cls, otherwise returns 0. In case of an error, returns # the class cls, otherwise returns 0. In case of an error, returns
# -1. If cls is a tuple, the check will be done against every # -1. If cls is a tuple, the check will be done against every
...@@ -208,17 +207,17 @@ cdef extern from "Python.h": ...@@ -208,17 +207,17 @@ cdef extern from "Python.h":
# NULL. Returns the result of the call on success, or NULL on # NULL. Returns the result of the call on success, or NULL on
# failure. # failure.
long PyObject_Hash(object o) long PyObject_Hash(object o) except? -1
# Compute and return the hash value of an object o. On failure, # Compute and return the hash value of an object o. On failure,
# return -1. This is the equivalent of the Python expression # return -1. This is the equivalent of the Python expression
# "hash(o)". # "hash(o)".
bint PyObject_IsTrue(object o) bint PyObject_IsTrue(object o) except -1
# Returns 1 if the object o is considered to be true, and 0 # Returns 1 if the object o is considered to be true, and 0
# otherwise. This is equivalent to the Python expression "not not # otherwise. This is equivalent to the Python expression "not not
# o". On failure, return -1. # o". On failure, return -1.
bint PyObject_Not(object o) bint PyObject_Not(object o) except -1
# Returns 0 if the object o is considered to be true, and 1 # Returns 0 if the object o is considered to be true, and 1
# otherwise. This is equivalent to the Python expression "not # otherwise. This is equivalent to the Python expression "not
# o". On failure, return -1. # o". On failure, return -1.
...@@ -238,8 +237,8 @@ cdef extern from "Python.h": ...@@ -238,8 +237,8 @@ cdef extern from "Python.h":
# Return true if the object o is of type type or a subtype of # Return true if the object o is of type type or a subtype of
# type. Both parameters must be non-NULL. # type. Both parameters must be non-NULL.
Py_ssize_t PyObject_Length(object o) Py_ssize_t PyObject_Length(object o) except -1
Py_ssize_t PyObject_Size(object o) Py_ssize_t PyObject_Size(object o) except -1
# Return the length of object o. If the object o provides either # Return the length of object o. If the object o provides either
# the sequence and mapping protocols, the sequence length is # the sequence and mapping protocols, the sequence length is
# returned. On error, -1 is returned. This is the equivalent to # returned. On error, -1 is returned. This is the equivalent to
...@@ -251,15 +250,15 @@ cdef extern from "Python.h": ...@@ -251,15 +250,15 @@ cdef extern from "Python.h":
# failure. This is the equivalent of the Python expression # failure. This is the equivalent of the Python expression
# "o[key]". # "o[key]".
int PyObject_SetItem(object o, object key, object v) int PyObject_SetItem(object o, object key, object v) except -1
# Map the object key to the value v. Returns -1 on failure. This # Map the object key to the value v. Returns -1 on failure. This
# is the equivalent of the Python statement "o[key] = v". # is the equivalent of the Python statement "o[key] = v".
int PyObject_DelItem(object o, object key) int PyObject_DelItem(object o, object key) except -1
# Delete the mapping for key from o. Returns -1 on failure. This # Delete the mapping for key from o. Returns -1 on failure. This
# is the equivalent of the Python statement "del o[key]". # is the equivalent of the Python statement "del o[key]".
int PyObject_AsFileDescriptor(object o) int PyObject_AsFileDescriptor(object o) except -1
# Derives a file-descriptor from a Python object. If the object is # Derives a file-descriptor from a Python object. If the object is
# an integer or long integer, its value is returned. If not, the # an integer or long integer, its value is returned. If not, the
# object's fileno() method is called if it exists; the method must # object's fileno() method is called if it exists; the method must
......
from python_ref cimport PyObject
# available since Python 3.1!
# note all char* in the below functions are actually const char*
cdef extern from "Python.h":
ctypedef struct PyCapsule_Type
# This subtype of PyObject represents an opaque value, useful for
# C extension modules who need to pass an opaque value (as a void*
# pointer) through Python code to other C code. It is often used
# to make a C function pointer defined in one module available to
# other modules, so the regular import mechanism can be used to
# access C APIs defined in dynamically loaded modules.
ctypedef void (*PyCapsule_Destructor)(object o)
# The type of a destructor callback for a capsule.
#
# See PyCapsule_New() for the semantics of PyCapsule_Destructor
# callbacks.
bint PyCapsule_CheckExact(object o)
# Return true if its argument is a PyCapsule.
object PyCapsule_New(void *pointer, char *name,
PyCapsule_Destructor destructor)
# Return value: New reference.
#
# Create a PyCapsule encapsulating the pointer. The pointer
# argument may not be NULL.
#
# On failure, set an exception and return NULL.
#
# The name string may either be NULL or a pointer to a valid C
# string. If non-NULL, this string must outlive the
# capsule. (Though it is permitted to free it inside the
# destructor.)
#
# If the destructor argument is not NULL, it will be called with
# the capsule as its argument when it is destroyed.
#
# If this capsule will be stored as an attribute of a module, the
# name should be specified as modulename.attributename. This will
# enable other modules to import the capsule using
# PyCapsule_Import().
void* PyCapsule_GetPointer(object capsule, char *name)
# Retrieve the pointer stored in the capsule. On failure, set an
# exception and return NULL.
#
# The name parameter must compare exactly to the name stored in
# the capsule. If the name stored in the capsule is NULL, the name
# passed in must also be NULL. Python uses the C function strcmp()
# to compare capsule names.
PyCapsule_Destructor PyCapsule_GetDestructor(object capsule)
# Return the current destructor stored in the capsule. On failure,
# set an exception and return NULL.
#
# It is legal for a capsule to have a NULL destructor. This makes
# a NULL return code somewhat ambiguous; use PyCapsule_IsValid()
# or PyErr_Occurred() to disambiguate.
char* PyCapsule_GetName(object capsule)
# Return the current name stored in the capsule. On failure, set
# an exception and return NULL.
#
# It is legal for a capsule to have a NULL name. This makes a NULL
# return code somewhat ambiguous; use PyCapsule_IsValid() or
# PyErr_Occurred() to disambiguate.
void* PyCapsule_GetContext(object capsule)
# Return the current context stored in the capsule. On failure,
# set an exception and return NULL.
#
# It is legal for a capsule to have a NULL context. This makes a
# NULL return code somewhat ambiguous; use PyCapsule_IsValid() or
# PyErr_Occurred() to disambiguate.
int PyCapsule_IsValid(object capsule, char *name)
# Determines whether or not capsule is a valid capsule. A valid
# capsule is non-NULL, passes PyCapsule_CheckExact(), has a
# non-NULL pointer stored in it, and its internal name matches the
# name parameter. (See PyCapsule_GetPointer() for information on
# how capsule names are compared.)
#
# In other words, if PyCapsule_IsValid() returns a true value,
# calls to any of the accessors (any function starting with
# PyCapsule_Get()) are guaranteed to succeed.
#
# Return a nonzero value if the object is valid and matches the
# name passed in. Return 0 otherwise. This function will not fail.
int PyCapsule_SetPointer(object capsule, void *pointer)
# Set the void pointer inside capsule to pointer. The pointer may
# not be NULL.
#
# Return 0 on success. Return nonzero and set an exception on
# failure.
int PyCapsule_SetDestructor(object capsule, PyCapsule_Destructor destructor)
# Set the destructor inside capsule to destructor.
#
# Return 0 on success. Return nonzero and set an exception on
# failure.
int PyCapsule_SetName(object capsule, char *name)
# Set the name inside capsule to name. If non-NULL, the name must
# outlive the capsule. If the previous name stored in the capsule
# was not NULL, no attempt is made to free it.
#
# Return 0 on success. Return nonzero and set an exception on
# failure.
int PyCapsule_SetContext(object capsule, void *context)
# Set the context pointer inside capsule to context. Return 0 on
# success. Return nonzero and set an exception on failure.
void* PyCapsule_Import(char *name, int no_block)
# Import a pointer to a C object from a capsule attribute in a
# module. The name parameter should specify the full name to the
# attribute, as in module.attribute. The name stored in the
# capsule must match this string exactly. If no_block is true,
# import the module without blocking (using
# PyImport_ImportModuleNoBlock()). If no_block is false, import
# the module conventionally (using PyImport_ImportModule()).
#
# Return the capsule’s internal pointer on success. On failure,
# set an exception and return NULL. However, if PyCapsule_Import()
# failed to import the module, and no_block was true, no exception
# is set.
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyTypeObject ctypedef struct PyTypeObject
ctypedef struct PyObject: ctypedef struct PyObject:
Py_ssize_t ob_refcnt Py_ssize_t ob_refcnt
PyTypeObject *ob_type PyTypeObject *ob_type
......
############################################################################ from python_ref cimport PyObject
# 6.3 Sequence Protocol
############################################################################
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
############################################################################
# 6.3 Sequence Protocol
############################################################################
bint PySequence_Check(object o) bint PySequence_Check(object o)
# Return 1 if the object provides sequence protocol, and 0 # Return 1 if the object provides sequence protocol, and 0
# otherwise. This function always succeeds. # otherwise. This function always succeeds.
Py_ssize_t PySequence_Size(object o) Py_ssize_t PySequence_Size(object o) except -1
# Returns the number of objects in sequence o on success, and -1 # Returns the number of objects in sequence o on success, and -1
# on failure. For objects that do not provide sequence protocol, # on failure. For objects that do not provide sequence protocol,
# this is equivalent to the Python expression "len(o)". # this is equivalent to the Python expression "len(o)".
Py_ssize_t PySequence_Length(object o) Py_ssize_t PySequence_Length(object o) except -1
# Alternate name for PySequence_Size(). # Alternate name for PySequence_Size().
object PySequence_Concat(object o1, object o2) object PySequence_Concat(object o1, object o2)
...@@ -54,37 +54,37 @@ cdef extern from "Python.h": ...@@ -54,37 +54,37 @@ cdef extern from "Python.h":
# on failure. This is the equivalent of the Python expression # on failure. This is the equivalent of the Python expression
# "o[i1:i2]". # "o[i1:i2]".
int PySequence_SetItem(object o, Py_ssize_t i, object v) int PySequence_SetItem(object o, Py_ssize_t i, object v) except -1
# Assign object v to the ith element of o. Returns -1 on # Assign object v to the ith element of o. Returns -1 on
# failure. This is the equivalent of the Python statement "o[i] = # failure. This is the equivalent of the Python statement "o[i] =
# v". This function does not steal a reference to v. # v". This function does not steal a reference to v.
int PySequence_DelItem(object o, Py_ssize_t i) int PySequence_DelItem(object o, Py_ssize_t i) except -1
# Delete the ith element of object o. Returns -1 on failure. This # Delete the ith element of object o. Returns -1 on failure. This
# is the equivalent of the Python statement "del o[i]". # is the equivalent of the Python statement "del o[i]".
int PySequence_SetSlice(object o, Py_ssize_t i1, Py_ssize_t i2, object v) int PySequence_SetSlice(object o, Py_ssize_t i1, Py_ssize_t i2, object v) except -1
# Assign the sequence object v to the slice in sequence object o # Assign the sequence object v to the slice in sequence object o
# from i1 to i2. This is the equivalent of the Python statement # from i1 to i2. This is the equivalent of the Python statement
# "o[i1:i2] = v". # "o[i1:i2] = v".
int PySequence_DelSlice(object o, Py_ssize_t i1, Py_ssize_t i2) int PySequence_DelSlice(object o, Py_ssize_t i1, Py_ssize_t i2) except -1
# Delete the slice in sequence object o from i1 to i2. Returns -1 # Delete the slice in sequence object o from i1 to i2. Returns -1
# on failure. This is the equivalent of the Python statement "del # on failure. This is the equivalent of the Python statement "del
# o[i1:i2]". # o[i1:i2]".
int PySequence_Count(object o, object value) int PySequence_Count(object o, object value) except -1
# Return the number of occurrences of value in o, that is, return # Return the number of occurrences of value in o, that is, return
# the number of keys for which o[key] == value. On failure, return # the number of keys for which o[key] == value. On failure, return
# -1. This is equivalent to the Python expression # -1. This is equivalent to the Python expression
# "o.count(value)". # "o.count(value)".
int PySequence_Contains(object o, object value) int PySequence_Contains(object o, object value) except -1
# Determine if o contains value. If an item in o is equal to # Determine if o contains value. If an item in o is equal to
# value, return 1, otherwise return 0. On error, return -1. This # value, return 1, otherwise return 0. On error, return -1. This
# is equivalent to the Python expression "value in o". # is equivalent to the Python expression "value in o".
int PySequence_Index(object o, object value) int PySequence_Index(object o, object value) except -1
# Return the first index i for which o[i] == value. On error, # Return the first index i for which o[i] == value. On error,
# return -1. This is equivalent to the Python expression # return -1. This is equivalent to the Python expression
# "o.index(value)". # "o.index(value)".
......
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
############################################################################ ############################################################################
# 7.5.14 Set Objects # 7.5.14 Set Objects
...@@ -63,9 +62,11 @@ cdef extern from "Python.h": ...@@ -63,9 +62,11 @@ cdef extern from "Python.h":
# frozenset. Return the new set on success or NULL on # frozenset. Return the new set on success or NULL on
# failure. Raise TypeError if iterable is not actually iterable. # failure. Raise TypeError if iterable is not actually iterable.
# The following functions and macros are available for instances of set or frozenset or instances of their subtypes.
int PySet_Size(object anyset) # The following functions and macros are available for instances
# of set or frozenset or instances of their subtypes.
int PySet_Size(object anyset) except -1
# Return the length of a set or frozenset object. Equivalent to # Return the length of a set or frozenset object. Equivalent to
# "len(anyset)". Raises a PyExc_SystemError if anyset is not a # "len(anyset)". Raises a PyExc_SystemError if anyset is not a
# set, frozenset, or an instance of a subtype. # set, frozenset, or an instance of a subtype.
...@@ -73,7 +74,7 @@ cdef extern from "Python.h": ...@@ -73,7 +74,7 @@ cdef extern from "Python.h":
int PySet_GET_SIZE(object anyset) int PySet_GET_SIZE(object anyset)
# Macro form of PySet_Size() without error checking. # Macro form of PySet_Size() without error checking.
int PySet_Contains(object anyset, object key) bint PySet_Contains(object anyset, object key) except -1
# Return 1 if found, 0 if not found, and -1 if an error is # Return 1 if found, 0 if not found, and -1 if an error is
# encountered. Unlike the Python __contains__() method, this # encountered. Unlike the Python __contains__() method, this
# function does not automatically convert unhashable sets into # function does not automatically convert unhashable sets into
...@@ -81,17 +82,18 @@ cdef extern from "Python.h": ...@@ -81,17 +82,18 @@ cdef extern from "Python.h":
# unhashable. Raise PyExc_SystemError if anyset is not a set, # unhashable. Raise PyExc_SystemError if anyset is not a set,
# frozenset, or an instance of a subtype. # frozenset, or an instance of a subtype.
# The following functions are available for instances of set or # The following functions are available for instances of set or
# its subtypes but not for instances of frozenset or its subtypes. # its subtypes but not for instances of frozenset or its subtypes.
int PySet_Add(object set, object key) int PySet_Add(object set, object key) except -1
# Add key to a set instance. Does not apply to frozenset # Add key to a set instance. Does not apply to frozenset
# instances. Return 0 on success or -1 on failure. Raise a # instances. Return 0 on success or -1 on failure. Raise a
# TypeError if the key is unhashable. Raise a MemoryError if there # TypeError if the key is unhashable. Raise a MemoryError if there
# is no room to grow. Raise a SystemError if set is an not an # is no room to grow. Raise a SystemError if set is an not an
# instance of set or its subtype. # instance of set or its subtype.
int PySet_Discard(object set, object key) bint PySet_Discard(object set, object key) except -1
# Return 1 if found and removed, 0 if not found (no action taken), # Return 1 if found and removed, 0 if not found (no action taken),
# and -1 if an error is encountered. Does not raise KeyError for # and -1 if an error is encountered. Does not raise KeyError for
# missing keys. Raise a TypeError if the key is unhashable. Unlike # missing keys. Raise a TypeError if the key is unhashable. Unlike
...@@ -100,7 +102,7 @@ cdef extern from "Python.h": ...@@ -100,7 +102,7 @@ cdef extern from "Python.h":
# frozensets. Raise PyExc_SystemError if set is an not an instance # frozensets. Raise PyExc_SystemError if set is an not an instance
# of set or its subtype. # of set or its subtype.
PySet_Pop(object set) object PySet_Pop(object set)
# Return value: New reference. # Return value: New reference.
# Return a new reference to an arbitrary object in the set, and # Return a new reference to an arbitrary object in the set, and
# removes the object from the set. Return NULL on failure. Raise # removes the object from the set. Return NULL on failure. Raise
...@@ -109,4 +111,3 @@ cdef extern from "Python.h": ...@@ -109,4 +111,3 @@ cdef extern from "Python.h":
int PySet_Clear(object set) int PySet_Clear(object set)
# Empty an existing set of all elements. # Empty an existing set of all elements.
from python_ref cimport PyObject
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
ctypedef struct va_list ctypedef struct va_list
############################################################################ ############################################################################
# 7.3.1 String Objects # 7.3.1 String Objects
############################################################################ ############################################################################
# These functions raise TypeError when expecting a string # These functions raise TypeError when expecting a string
# parameter and are called with a non-string parameter. # parameter and are called with a non-string parameter.
# PyStringObject # PyStringObject
...@@ -72,7 +74,7 @@ cdef extern from "Python.h": ...@@ -72,7 +74,7 @@ cdef extern from "Python.h":
Py_ssize_t PyString_GET_SIZE(object string) Py_ssize_t PyString_GET_SIZE(object string)
# Macro form of PyString_Size() but without error checking. # Macro form of PyString_Size() but without error checking.
char* PyString_AsString(object string) char* PyString_AsString(object string) except NULL
# Return a NUL-terminated representation of the contents of # Return a NUL-terminated representation of the contents of
# string. The pointer refers to the internal buffer of string, not # string. The pointer refers to the internal buffer of string, not
# a copy. The data must not be modified in any way, unless the # a copy. The data must not be modified in any way, unless the
...@@ -87,7 +89,7 @@ cdef extern from "Python.h": ...@@ -87,7 +89,7 @@ cdef extern from "Python.h":
# checking. Only string objects are supported; no Unicode objects # checking. Only string objects are supported; no Unicode objects
# should be passed. # should be passed.
int PyString_AsStringAndSize(object obj, char **buffer, Py_ssize_t *length) int PyString_AsStringAndSize(object obj, char **buffer, Py_ssize_t *length) except -1
# Return a NULL-terminated representation of the contents of the # Return a NULL-terminated representation of the contents of the
# object obj through the output variables buffer and length. # object obj through the output variables buffer and length.
# #
...@@ -118,7 +120,7 @@ cdef extern from "Python.h": ...@@ -118,7 +120,7 @@ cdef extern from "Python.h":
# newpart appended to string. This version decrements the # newpart appended to string. This version decrements the
# reference count of newpart. # reference count of newpart.
int _PyString_Resize(PyObject **string, Py_ssize_t newsize) int _PyString_Resize(PyObject **string, Py_ssize_t newsize) except -1
# A way to resize a string object even though it is # A way to resize a string object even though it is
# ``immutable''. Only use this to build up a brand new string # ``immutable''. Only use this to build up a brand new string
# object; don't use this if the string may already be known in # object; don't use this if the string may already be known in
......
from python_ref cimport PyObject
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
############################################################################ ############################################################################
# Tuples # Tuples
...@@ -30,7 +31,7 @@ cdef extern from "Python.h": ...@@ -30,7 +31,7 @@ cdef extern from "Python.h":
# Return the size of the tuple p, which must be non-NULL and point # Return the size of the tuple p, which must be non-NULL and point
# to a tuple; no error checking is performed. # to a tuple; no error checking is performed.
PyObject* PyTuple_GetItem(object p, Py_ssize_t pos) PyObject* PyTuple_GetItem(object p, Py_ssize_t pos) except NULL
# Return value: Borrowed reference. # Return value: Borrowed reference.
# Return the object at position pos in the tuple pointed to by # Return the object at position pos in the tuple pointed to by
# p. If pos is out of bounds, return NULL and sets an IndexError # p. If pos is out of bounds, return NULL and sets an IndexError
...@@ -54,7 +55,7 @@ cdef extern from "Python.h": ...@@ -54,7 +55,7 @@ cdef extern from "Python.h":
# only be used to fill in brand new tuples. Note: This function # only be used to fill in brand new tuples. Note: This function
# ``steals'' a reference to o. # ``steals'' a reference to o.
int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize) int _PyTuple_Resize(PyObject **p, Py_ssize_t newsize) except -1
# Can be used to resize a tuple. newsize will be the new length of # Can be used to resize a tuple. newsize will be the new length of
# the tuple. Because tuples are supposed to be immutable, this # the tuple. Because tuples are supposed to be immutable, this
# should only be used if there is only one reference to the # should only be used if there is only one reference to the
......
cdef extern from "Python.h": cdef extern from "Python.h":
ctypedef void PyObject
ctypedef void PyTypeObject
# The C structure of the objects used to describe built-in types. # The C structure of the objects used to describe built-in types.
############################################################################ ############################################################################
...@@ -38,7 +37,7 @@ cdef extern from "Python.h": ...@@ -38,7 +37,7 @@ cdef extern from "Python.h":
object PyType_GenericNew(object type, object args, object kwds) object PyType_GenericNew(object type, object args, object kwds)
# Return value: New reference. # Return value: New reference.
bint PyType_Ready(object type) bint PyType_Ready(object type) except -1
# Finalize a type object. This should be called on all type # Finalize a type object. This should be called on all type
# objects to finish their initialization. This function is # objects to finish their initialization. This function is
# responsible for adding inherited slots from a type's base # responsible for adding inherited slots from a type's base
......
cdef extern from *: cdef extern from *:
ctypedef int Py_UNICODE ctypedef unsigned int Py_UNICODE
# Return true if the object o is a Unicode object or an instance # Return true if the object o is a Unicode object or an instance
# of a Unicode subtype. Changed in version 2.2: Allowed subtypes # of a Unicode subtype. Changed in version 2.2: Allowed subtypes
......
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