cpy3

package module
v0.0.0-...-bde1bc7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2024 License: MIT Imports: 3 Imported by: 1

README

Go bindings for the CPython-3 C-API

[!IMPORTANT] Currently supports python-3.11 only.

This package provides a go package named "python" under which most of the PyXYZ functions and macros of the public C-API of CPython have been exposed. Theoretically, you should be able use https://docs.python.org/3/c-api and know what to type in your go program.

Prerequisites

  • go >= 1.21
  • python = 3.11.x
MacOS
  • brew install python@3.11
  • brew install pkg-config
Linux

We will need pkg-config and a working python3.11 environment to build these bindings. Make sure you have Python libraries and header files installed as well (python3.11-dev on Debian, brew install python@3.11 on macOS, or python3-devel on Centos for example).

By default pkg-config will look at the python3 library so if you want to choose a specific version just symlink python-X.Y.pc to python3.pc or use the PKG_CONFIG_PATH environment variable.

Install

go get go.nhat.io/cpy3

API

Some functions mix go code and call to Python function. Those functions will return and int and error type. The int represent the Python result code and the error represent any issue from the Go layer.

Example:

func PyRun_AnyFile(filename string) open filename and then call CPython API function int PyRun_AnyFile(FILE *fp, const char *filename).

Therefore, its signature is func PyRun_AnyFile(filename string) (int, error), the int represent the error code from the CPython PyRun_AnyFile function and error will be set if we failed to open filename.

If an error is raise before calling th CPython function int default to -1.

Take a look at some examples and this tutorial blogpost.

Versioning

We follow the versioning of the CPython API. The version of this package is 3.11.x which means it supports the CPython API version 3.11. However, the patch version x is used to indicate the version of this package, not the CPython API. If you see a version 3.11.7, it doesn't mean the module only supports CPython API version 3.11.7, it's just the 7th time we patch to support the CPython API version 3.11.

Contributing

Contributions are welcome! See details.

Relations

Relation to DataDog/go-python3

This project is a community maintained successor to DataDog/go-python3, which will get archived in December 2021.

If you use the Go package github.com/DataDog/go-python3 in your code, you can use go.nhat.io/cpy3 as a drop-in replacement. We intend to not introduce breaking changes.

Relation to sbinet/go-python

This project was inspired by sbinet/go-python (Go bindings for the CPython-2 C-API).

Relation to sublime-security/cpy3

This project was a fork of sublime-security (Go bindings for the CPython-3 C-API) which only supports python 3.10.

Documentation

Overview

Package cpy3 provides a Go binding for Python 3 C-API.

Index

Constants

View Source
const MaxVariadicLength = 20

MaxVariadicLength is the maximum number of arguments that can be passed to a variadic C function due to a cgo limitation

Variables

View Source
var (
	Py_False = togo(C.Py_False)
	Py_True  = togo(C.Py_True)
)

Python boolean constants.

View Source
var (
	PyExc_BaseException          = togo(C.PyExc_BaseException)
	PyExc_Exception              = togo(C.PyExc_Exception)
	PyExc_ArithmeticError        = togo(C.PyExc_ArithmeticError)
	PyExc_AssertionError         = togo(C.PyExc_AssertionError)
	PyExc_AttributeError         = togo(C.PyExc_AttributeError)
	PyExc_BlockingIOError        = togo(C.PyExc_BlockingIOError)
	PyExc_BrokenPipeError        = togo(C.PyExc_BrokenPipeError)
	PyExc_BufferError            = togo(C.PyExc_BufferError)
	PyExc_ChildProcessError      = togo(C.PyExc_ChildProcessError)
	PyExc_ConnectionAbortedError = togo(C.PyExc_ConnectionAbortedError)
	PyExc_ConnectionError        = togo(C.PyExc_ConnectionError)
	PyExc_ConnectionRefusedError = togo(C.PyExc_ConnectionRefusedError)
	PyExc_ConnectcionResetError  = togo(C.PyExc_ConnectionResetError)
	PyExc_EOFError               = togo(C.PyExc_EOFError)
	PyExc_FileExistsError        = togo(C.PyExc_FileExistsError)
	PyExc_FileNotFoundError      = togo(C.PyExc_FileNotFoundError)
	PyExc_FloatingPointError     = togo(C.PyExc_FloatingPointError)
	PyExc_GeneratorExit          = togo(C.PyExc_GeneratorExit)
	PyExc_ImportError            = togo(C.PyExc_ImportError)
	PyExc_IndentationError       = togo(C.PyExc_IndentationError)
	PyExc_IndexError             = togo(C.PyExc_IndexError)
	PyExc_InterruptedError       = togo(C.PyExc_InterruptedError)
	PyExc_IsADirectoryError      = togo(C.PyExc_IsADirectoryError)
	PyExc_KeyError               = togo(C.PyExc_KeyError)
	PyExc_KeyboardInterrupt      = togo(C.PyExc_KeyboardInterrupt)
	PyExc_LookupError            = togo(C.PyExc_LookupError)
	PyExc_MemoryError            = togo(C.PyExc_MemoryError)
	PyExc_ModuleNotFoundError    = togo(C.PyExc_ModuleNotFoundError)
	PyExc_NameError              = togo(C.PyExc_NameError)
	PyExc_NotADirectoryError     = togo(C.PyExc_NotADirectoryError)
	PyExc_NotImplementedError    = togo(C.PyExc_NotImplementedError)
	PyExc_OSError                = togo(C.PyExc_OSError)
	PyExc_OverflowError          = togo(C.PyExc_OverflowError)
	PyExc_PermissionError        = togo(C.PyExc_PermissionError)
	PyExc_ProcessLookupError     = togo(C.PyExc_ProcessLookupError)
	PyExc_RecursionError         = togo(C.PyExc_RecursionError)
	PyExc_ReferenceError         = togo(C.PyExc_ReferenceError)
	PyExc_RuntimeError           = togo(C.PyExc_RuntimeError)
	PyExc_StopAsyncIteration     = togo(C.PyExc_StopAsyncIteration)
	PyExc_StopIteration          = togo(C.PyExc_StopIteration)
	PyExc_SyntaxError            = togo(C.PyExc_SyntaxError)
	PyExc_SystemError            = togo(C.PyExc_SystemError)
	PyExc_SystemExit             = togo(C.PyExc_SystemExit)
	PyExc_TabError               = togo(C.PyExc_TabError)
	PyExc_TimeoutError           = togo(C.PyExc_TimeoutError)
	PyExc_TypeError              = togo(C.PyExc_TypeError)
	PyExc_UnboundLocalError      = togo(C.PyExc_UnboundLocalError)
	PyExc_UnicodeDecodeError     = togo(C.PyExc_UnicodeDecodeError)
	PyExc_UnicodeEncodeError     = togo(C.PyExc_UnicodeEncodeError)
	PyExc_UnicodeError           = togo(C.PyExc_UnicodeError)
	PyExc_UnicodeTranslateError  = togo(C.PyExc_UnicodeTranslateError)
	PyExc_ValueError             = togo(C.PyExc_ValueError)
	PyExc_ZeroDivisionError      = togo(C.PyExc_ZeroDivisionError)
)

All standard Python exceptions are available as global variables whose names are PyExc_ followed by the Python exception name. These have the type PyObject*; they are all class objects.

View Source
var (
	Py_LT = int(C.Py_LT)
	Py_LE = int(C.Py_LE)
	Py_EQ = int(C.Py_EQ)
	Py_NE = int(C.Py_NE)
	Py_GT = int(C.Py_GT)
	Py_GE = int(C.Py_GE)
)

Constants used for comparison in PyObject_RichCompareBool.

View Source
var (
	PyExc_Warning                   = togo(C.PyExc_Warning)
	PyExc_BytesWarning              = togo(C.PyExc_BytesWarning)
	PyExc_DeprecationWarning        = togo(C.PyExc_DeprecationWarning)
	PyExc_FutureWarning             = togo(C.PyExc_FutureWarning)
	PyExc_ImportWarning             = togo(C.PyExc_ImportWarning)
	PyExc_PendingDeprecationWarning = togo(C.PyExc_PendingDeprecationWarning)
	PyExc_ResourceWarning           = togo(C.PyExc_ResourceWarning)
	PyExc_RuntimeWarning            = togo(C.PyExc_RuntimeWarning)
	PyExc_SyntaxWarning             = togo(C.PyExc_SyntaxWarning)
	PyExc_UnicodeWarning            = togo(C.PyExc_UnicodeWarning)
	PyExc_UserWarning               = togo(C.PyExc_UserWarning)
)

All standard Python warning categories are available as global variables whose names are PyExc_ followed by the Python exception name. These have the type PyObject*; they are all class objects.

View Source
var Bool = togo((*C.PyObject)(unsafe.Pointer(&C.PyBool_Type)))

Bool is an instance of PyTypeObject represents the Python boolean type; it is the same object as `bool` in the Python layer.

Reference: https://docs.python.org/3/c-api/bool.html#c.PyBool_Type

View Source
var ByteArray = togo((*C.PyObject)(unsafe.Pointer(&C.PyByteArray_Type)))

ByteArray is an instance of PyTypeObject represents the Python bytearray type; it is the same object as `bytearray` in the Python layer.

Reference: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Type

View Source
var Bytes = togo((*C.PyObject)(unsafe.Pointer(&C.PyBytes_Type)))

Bytes is an instance of PyTypeObject represents the Python `bytes` type; it is the same object as `bytes` in the Python layer.

Reference: https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Type

View Source
var Complex = togo((*C.PyObject)(unsafe.Pointer(&C.PyComplex_Type)))

Complex is an instance of PyTypeObject represents the Python `complex` number type. It is the same object as `complex` in the Python layer.

Reference: https://docs.python.org/3/c-api/complex.html#c.PyComplex_Type

View Source
var Dict = togo((*C.PyObject)(unsafe.Pointer(&C.PyDict_Type)))

Dict is an instance of PyTypeObject represents the Python dictionary type. This is the same object as `dict` in the Python layer.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_Type

View Source
var ErrEncodeLocaleFailed = fmt.Errorf("fail to call Py_EncodeLocale")

ErrEncodeLocaleFailed is returned when we fail to call Py_EncodeLocale.

View Source
var Float = togo((*C.PyObject)(unsafe.Pointer(&C.PyFloat_Type)))

Float is an instance of PyTypeObject represents the Python floating point type. This is the same object as float in the Python layer.

Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_Type

View Source
var List = togo((*C.PyObject)(unsafe.Pointer(&C.PyList_Type)))

List is an instance of PyTypeObject represents the Python list type. This is the same object as list in the Python layer.

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_Type

View Source
var Long = togo((*C.PyObject)(unsafe.Pointer(&C.PyLong_Type)))

Long is an instance of PyTypeObject represents the Python integer type. This is the same object as int in the Python layer.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_Type

View Source
var Module = togo((*C.PyObject)(unsafe.Pointer(&C.PyModule_Type)))

Module is an instance of PyTypeObject represents the Python module type. This is exposed to Python programs as types.ModuleType.

Reference: https://docs.python.org/3/c-api/module.html#c.PyModule_Type

View Source
var Py_None = togo(C.Py_None)

Py_None is the Python None object, denoting lack of value. This object has no methods and is immortal.

Reference: https://docs.python.org/3/c-api/none.html#c.Py_None

View Source
var Tuple = togo((*C.PyObject)(unsafe.Pointer(&C.PyTuple_Type)))

Tuple is an instance of PyTypeObject represents the Python tuple type; it is the same object as tuple in the Python layer.

Reference: https://docs.python.org/3/c-api/tuple.html#c.PyTuple_Type

View Source
var Type = togo((*C.PyObject)(unsafe.Pointer(&C.PyType_Type)))

Type is the type object for type objects; it is the same object as type in the Python layer.

Reference: https://docs.python.org/3/c-api/type.html#c.PyType_Type

View Source
var Unicode = togo((*C.PyObject)(unsafe.Pointer(&C.PyUnicode_Type)))

Unicode is an instance of PyTypeObject represents the Python Unicode type. It is exposed to Python code as str.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_Type

Functions

func PyBool_Check

func PyBool_Check(o *PyObject) bool

PyBool_Check returns true if o is of type PyBool_Type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/bool.html#c.PyBool_Check

func PyByteArray_AsString

func PyByteArray_AsString(o *PyObject) string

PyByteArray_AsString returns the contents of `bytearray` as a char array after checking for a `NULL` pointer. The returned array always has an extra null byte appended.

Reference: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_AsString

func PyByteArray_Check

func PyByteArray_Check(o *PyObject) bool

PyByteArray_Check returns true if the object o is a bytearray object or an instance of a subtype of the `bytearray` type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Check

func PyByteArray_CheckExact

func PyByteArray_CheckExact(o *PyObject) bool

PyByteArray_CheckExact returns true if the object o is a bytearray object, but not an instance of a subtype of the `bytearray` type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_CheckExact

func PyByteArray_Resize

func PyByteArray_Resize(bytearray *PyObject, length int)

PyByteArray_Resize resizes the internal buffer of bytearray to len.

Reference: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Resize

func PyByteArray_Size

func PyByteArray_Size(o *PyObject) int

PyByteArray_Size returns the size of bytearray after checking for a NULL pointer.

Reference: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Size

func PyBytes_AsByteSlice

func PyBytes_AsByteSlice(o *PyObject) []byte

PyBytes_AsByteSlice is equivalent to PyBytes_AsString but returns byte slices.

func PyBytes_AsString

func PyBytes_AsString(o *PyObject) string

PyBytes_AsString returns a pointer to the contents of o. The pointer refers to the internal buffer of o, which consists of len(o) + 1 bytes. The last byte in the buffer is always null, regardless of whether there are any other null bytes. The data must not be modified in any way, unless the object was just created using PyBytes_FromStringAndSize(NULL, size). It must not be deallocated.

If o is not a bytes object at all, PyBytes_AsString() returns NULL and raises TypeError.

Reference: https://docs.python.org/3/c-api/bytes.html#c.PyBytes_AsString

func PyBytes_Check

func PyBytes_Check(o *PyObject) bool

PyBytes_Check returns true if the object o is a `bytes` object or an instance of a subtype of the `bytes` type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Check

func PyBytes_CheckExact

func PyBytes_CheckExact(o *PyObject) bool

PyBytes_CheckExact returns true if the object o is a `bytes` object, but not an instance of a subtype of the `bytes` type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/bytes.html#c.PyBytes_CheckExact

func PyBytes_Size

func PyBytes_Size(o *PyObject) int

PyBytes_Size returns the length of the bytes in bytes object o.

Reference: https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Size

func PyCallable_Check

func PyCallable_Check(o *PyObject) bool

PyCallable_Check 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 exception.

If cls is a tuple, the check will be done against every entry in cls. The result will be 1 when at least one of the checks returns 1, otherwise it will be 0.

If cls has a __instancecheck__() method, it will be called to determine the subclass status as described in PEP 3119. Otherwise, inst is an instance of cls if its class is a subclass of cls.

An instance inst can override what is considered its class by having a __class__ attribute.

An object cls can override if it is considered a class, and what its base classes are, by having a __bases__ attribute (which must be a tuple of base classes).

Reference: https://docs.python.org/3/c-api/object.html#c.PyCallable_Check

func PyComplex_Check

func PyComplex_Check(p *PyObject) bool

PyComplex_Check returns true if its argument is a PyComplexObject or a subtype of PyComplexObject. This function always succeeds.

Reference: https://docs.python.org/3/c-api/complex.html#c.PyComplex_Check

func PyComplex_CheckExact

func PyComplex_CheckExact(p *PyObject) bool

PyComplex_CheckExact returns true if its argument is a PyComplexObject or a subtype of PyComplexObject. This function always succeeds.

Reference: https://docs.python.org/3/c-api/complex.html#c.PyComplex_CheckExact

func PyComplex_ImagAsDouble

func PyComplex_ImagAsDouble(op *PyObject) float64

PyComplex_ImagAsDouble returns the imaginary part of op as a C double.

Reference: https://docs.python.org/3/c-api/complex.html#c.PyComplex_ImagAsDouble

func PyComplex_RealAsDouble

func PyComplex_RealAsDouble(op *PyObject) float64

PyComplex_RealAsDouble returns the real part of op as a C double.

Reference: https://docs.python.org/3/c-api/complex.html#c.PyComplex_RealAsDouble

func PyDict_Check

func PyDict_Check(p *PyObject) bool

PyDict_Check returns true if p is a dict object or an instance of a subtype of the dict type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_Check

func PyDict_CheckExact

func PyDict_CheckExact(p *PyObject) bool

PyDict_CheckExact returns true if p is a dict object, but not an instance of a subtype of the dict type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_CheckExact

func PyDict_Clear

func PyDict_Clear(p *PyObject)

PyDict_Clear empties an existing dictionary of all key-value pairs.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_Clear

func PyDict_Contains

func PyDict_Contains(p, key *PyObject) int

PyDict_Contains determines if dictionary p contains key. If an item in p is matches key, return 1, otherwise return 0. On error, return -1. This is equivalent to the Python expression key in p.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_Contains

func PyDict_DelItem

func PyDict_DelItem(p, key *PyObject) int

PyDict_DelItem removes the entry in dictionary p with the key. key must be hashable; if it isn't, TypeError is raised. If key is not in the dictionary, KeyError is raised. Return 0 on success or -1 on failure.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_DelItem

func PyDict_DelItemString

func PyDict_DelItemString(p *PyObject, key string) int

PyDict_DelItemString is the same as PyDict_DelItem(), but key is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_DelItemString

func PyDict_Next

func PyDict_Next(p *PyObject, ppos *int, pkey, pvalue **PyObject) bool

PyDict_Next iterates over all key-value pairs in the dictionary p. The Py_ssize_t referred to by ppos must be initialized to 0 prior to the first call to this function to start the iteration; the function returns true for each pair in the dictionary, and false once all pairs have been reported. The parameters pkey and pvalue should either point to PyObject* variables that will be filled in with each key and value, respectively, or may be NULL. Any references returned through them are borrowed. ppos should not be altered during iteration. Its value represents offsets within the internal dictionary structure, and since the structure is sparse, the offsets are not consecutive.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_Next

func PyDict_SetItem

func PyDict_SetItem(p, key, val *PyObject) int

PyDict_SetItem : https://docs.python.org/3/c-api/dict.html#c.PyDict_SetItem

func PyDict_SetItemString

func PyDict_SetItemString(p *PyObject, key string, val *PyObject) int

PyDict_SetItemString inserts val into the dictionary p with a key of key. key must be hashable; if it isn't, TypeError will be raised. Return 0 on success or -1 on failure. This function does not steal a reference to val.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_SetItemString

func PyDict_Size

func PyDict_Size(p *PyObject) int

PyDict_Size returns the number of items in the dictionary. This is equivalent to len(p) on a dictionary.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_Size

func PyErr_BadArgument

func PyErr_BadArgument()

PyErr_BadArgument is a shorthand for PyErr_SetString(PyExc_TypeError, message), where message indicates that a built-in operation was invoked with an illegal argument. It is mostly for internal use.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_BadArgument

func PyErr_BadInternalCall

func PyErr_BadInternalCall()

PyErr_BadInternalCall is a shorthand for PyErr_SetString(PyExc_SystemError, message), where message indicates that an internal operation (e.g. a Python/C API function) was invoked with an illegal argument. It is mostly for internal use.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_BadInternalCall

func PyErr_CheckSignals

func PyErr_CheckSignals() int

PyErr_CheckSignals interacts with Python's signal handling.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_CheckSignals

func PyErr_Clear

func PyErr_Clear()

PyErr_Clear clears the error indicator. If the error indicator is not set, there is no effect.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Clear

func PyErr_ExceptionMatches

func PyErr_ExceptionMatches(exc *PyObject) bool

PyErr_ExceptionMatches is equivalent to PyErr_GivenExceptionMatches(PyErr_Occurred(), exc). This should only be called when an exception is actually set; a memory access violation will occur if no exception has been raised.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_ExceptionMatches

func PyErr_Fetch

func PyErr_Fetch() (*PyObject, *PyObject, *PyObject)

PyErr_Fetch retrieves the error indicator into three variables whose addresses are passed. If the error indicator is not set, set all three variables to NULL. If it is set, it will be cleared and you own a reference to each object retrieved. The value and traceback object may be NULL even when the type object is not.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Fetch

func PyErr_GetExcInfo

func PyErr_GetExcInfo() (*PyObject, *PyObject, *PyObject)

PyErr_GetExcInfo retrieves the old-style representation of the exception info, as known from sys.exc_info(). This refers to an exception that was already caught, not to an exception that was freshly raised. Returns new references for the three objects, any of which may be NULL. Does not modify the exception info state. This function is kept for backwards compatibility.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_GetExcInfo

func PyErr_GivenExceptionMatches

func PyErr_GivenExceptionMatches(given, exc *PyObject) bool

PyErr_GivenExceptionMatches returns true if the given exception matches the exception type in exc. If exc is a class object, this also returns true when given is an instance of a subclass. If exc is a tuple, all exception types in the tuple (and recursively in subtuples) are searched for a match.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_GivenExceptionMatches

func PyErr_NormalizeException

func PyErr_NormalizeException(exc, val, tb *PyObject) (*PyObject, *PyObject, *PyObject)

PyErr_NormalizeException is used to instantiate the class in that the values returned by PyErr_Fetch() below can be "unnormalized", meaning that *exc is a class object but *val is not an instance of the same class. If the values are already normalized, nothing happens. The delayed normalization is implemented to improve performance.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NormalizeException

func PyErr_Print

func PyErr_Print()

PyErr_Print is an alias for PyErr_PrintEx(1).

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Print

func PyErr_PrintEx

func PyErr_PrintEx(setSysLastVars bool)

PyErr_PrintEx prints a standard traceback to sys.stderr and clear the error indicator. Unless the error is a SystemExit, in that case no traceback is printed and the Python process will exit with the error code specified by the SystemExit instance.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_PrintEx

func PyErr_Restore

func PyErr_Restore(pyType *PyObject, value *PyObject, traceback *PyObject)

PyErr_Restore sets the error indicator from the three objects, type, value, and traceback, clearing the existing exception if one is set. If the objects are NULL, the error indicator is cleared. Do not pass a NULL type and non-NULL value or traceback. The exception type should be a class. Do not pass an invalid exception type or value. (Violating these rules will cause subtle problems later.) This call takes away a reference to each object: you must own a reference to each object before the call and after the call you no longer own these references. (If you don't understand this, don't use this function. I warned you.)

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Restore

func PyErr_SetExcInfo

func PyErr_SetExcInfo(pyType *PyObject, value *PyObject, traceback *PyObject)

PyErr_SetExcInfo sets the exception info, as known from sys.exc_info(). This refers to an exception that was already caught, not to an exception that was freshly raised. This function steals the references of the arguments. To clear the exception state, pass NULL for all three arguments. This function is kept for backwards compatibility. Prefer using PyErr_SetHandledException().

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetExcInfo

func PyErr_SetInterrupt

func PyErr_SetInterrupt()

PyErr_SetInterrupt simulates the effect of a SIGINT signal arriving. This is equivalent to PyErr_SetInterruptEx(SIGINT).

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetInterrupt

func PyErr_SetNone

func PyErr_SetNone(pyType *PyObject)

PyErr_SetNone this function is similar to PyErr_SetString() but lets you specify an arbitrary Python object for the "value" of the exception.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetNone

func PyErr_SetObject

func PyErr_SetObject(pyType, value *PyObject)

PyErr_SetObject is similar to PyErr_SetString() but lets you specify an arbitrary Python object for the "value" of the exception.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetObject

func PyErr_SetString

func PyErr_SetString(pyType *PyObject, message string)

PyErr_SetString this is the most common way to set the error indicator. The first argument specifies the exception type; it is normally one of the standard exceptions, e.g. PyExc_RuntimeError. You need not create a new strong reference to it (e.g. with Py_INCREF()). The second argument is an error message; it is decoded from 'utf-8'.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetString

func PyErr_SyntaxLocation

func PyErr_SyntaxLocation(filename string, lineno int)

PyErr_SyntaxLocation is like PyErr_SyntaxLocationEx(), but the col_offset parameter is omitted.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SyntaxLocation

func PyErr_SyntaxLocationEx

func PyErr_SyntaxLocationEx(filename string, lineno, col_offset int)

PyErr_SyntaxLocationEx is like PyErr_SyntaxLocationObject(), but filename is a byte string decoded from the filesystem encoding and error handler.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SyntaxLocationEx

func PyErr_SyntaxLocationObject

func PyErr_SyntaxLocationObject(filename *PyObject, lineno, col_offset int)

PyErr_SyntaxLocationObject sets file, line, and offset information for the current exception. If the current exception is not a SyntaxError, then it sets additional attributes, which make the exception printing subsystem think the exception is a SyntaxError.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SyntaxLocationObject

func PyErr_WarnEx

func PyErr_WarnEx(category *PyObject, message string, stack_level int) int

PyErr_WarnEx issues a warning message. The category argument is a warning category (see below) or NULL; the message argument is a UTF-8 encoded string. stack_level is a positive number giving a number of stack frames; the warning will be issued from the currently executing line of code in that stack frame. A stack_level of 1 is the function calling PyErr_WarnEx(), 2 is the function above that, and so forth.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_WarnEx

func PyErr_WarnExplicit

func PyErr_WarnExplicit(category *PyObject, message string, filename string, lineno int, module string, registry *PyObject) int

PyErr_WarnExplicit is similar to PyErr_WarnExplicitObject() except that message and module are UTF-8 encoded strings, and filename is decoded from the filesystem encoding and error handler.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_WarnExplicit

func PyErr_WarnExplicitObject

func PyErr_WarnExplicitObject(category *PyObject, message *PyObject, filename *PyObject, lineno int, module *PyObject, registry *PyObject) int

PyErr_WarnExplicitObject issues a warning message with explicit control over all warning attributes. This is a straightforward wrapper around the Python function warnings.warn_explicit(); see there for more information. The module and registry arguments may be set to NULL to get the default effect described there.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_WarnExplicitObject

func PyErr_WriteUnraisable

func PyErr_WriteUnraisable(obj *PyObject)

PyErr_WriteUnraisable calls sys.unraisablehook() using the current exception and obj argument.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_WriteUnraisable

func PyEval_GetFuncDesc

func PyEval_GetFuncDesc(pyFunc *PyObject) string

PyEval_GetFuncDesc returns a description string, depending on the type of func. Return values include "()" for functions and methods, " constructor", " instance", and " object". Concatenated with the result of PyEval_GetFuncName(), the result will be a description of func.

Reference: https://docs.python.org/3/c-api/reflection.html?highlight=reflection#c.PyEval_GetFuncDesc

func PyEval_GetFuncName

func PyEval_GetFuncName(pyFunc *PyObject) string

PyEval_GetFuncName returns the name of func if it is a function, class or instance object, else the name of funcs type.

Reference: https://docs.python.org/3/c-api/reflection.html?highlight=reflection#c.PyEval_GetFuncName

func PyEval_RestoreThread

func PyEval_RestoreThread(tstate *PyThreadState)

PyEval_RestoreThread acquires the global interpreter lock (if it has been created) and set the thread state to tstate, which must not be NULL. If the lock has been created, the current thread must not have acquired it, otherwise deadlock ensues.

Reference: https://docs.python.org/3/c-api/init.html#c.PyEval_RestoreThread

func PyException_SetCause

func PyException_SetCause(ex, cause *PyObject)

PyException_SetCause sets the cause associated with the exception to cause. Use NULL to clear it. There is no type check to make sure that cause is either an exception instance or None. This steals a reference to cause.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyException_SetCause

func PyException_SetContext

func PyException_SetContext(ex, ctx *PyObject)

PyException_SetContext sets the context associated with the exception to ctx. Use NULL to clear it. There is no type check to make sure that ctx is an exception instance. This steals a reference to ctx.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyException_SetContext

func PyException_SetTraceback

func PyException_SetTraceback(ex, tb *PyObject) int

PyException_SetTraceback sets the traceback associated with the exception to tb. Use Py_None to clear it.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyException_SetTraceback

func PyFloat_AsDouble

func PyFloat_AsDouble(obj *PyObject) float64

PyFloat_AsDouble creates a PyFloatObject object based on the string value in str, or NULL on failure.

Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_AsDouble

func PyFloat_Check

func PyFloat_Check(p *PyObject) bool

PyFloat_Check returns true if its argument is a PyFloatObject or a subtype of PyFloatObject. This function always succeeds.

Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_Check

func PyFloat_CheckExact

func PyFloat_CheckExact(p *PyObject) bool

PyFloat_CheckExact returns true if its argument is a PyFloatObject, but not a subtype of PyFloatObject. This function always succeeds.

Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_CheckExact

func PyFloat_GetMax

func PyFloat_GetMax() float64

PyFloat_GetMax returns the maximum representable finite float DBL_MAX as C double.

Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_GetMax

func PyFloat_GetMin

func PyFloat_GetMin() float64

PyFloat_GetMin returns the minimum normalized positive float DBL_MIN as C double.

Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_GetMin

func PyGILState_Check

func PyGILState_Check() bool

PyGILState_Check returns 1 if the current thread is holding the GIL and 0 otherwise. This function can be called from any thread at any time. Only if it has had its Python thread state initialized and currently is holding the GIL will it return 1. This is mainly a helper/diagnostic function. It can be useful for example in callback contexts or memory allocation functions when knowing that the GIL is locked can allow the caller to perform sensitive actions or otherwise behave differently.

Reference: https://docs.python.org/3/c-api/init.html#c.PyGILState_Check

func PyGILState_Release

func PyGILState_Release(state PyGILState)

PyGILState_Release releases any resources previously acquired. After this call, Python’s state will be the same as it was prior to the corresponding PyGILState_Ensure() call (but generally this state will be unknown to the caller, hence the use of the GILState API).

Every call to PyGILState_Ensure() must be matched by a call to PyGILState_Release() on the same thread.

Reference: https://docs.python.org/3/c-api/init.html#c.PyGILState_Release

func PyImport_GetMagicNumber

func PyImport_GetMagicNumber() int

PyImport_GetMagicNumber returns the magic number for Python bytecode files (a.k.a. .pyc file). The magic number should be present in the first four bytes of the bytecode file, in little-endian byte order. Returns -1 on error.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_GetMagicNumber

func PyImport_ImportFrozenModule

func PyImport_ImportFrozenModule(name string) int

PyImport_ImportFrozenModule is similar to PyImport_ImportFrozenModuleObject(), but the name is a UTF-8 encoded string instead of a Unicode object.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ImportFrozenModule

func PyImport_ImportFrozenModuleObject

func PyImport_ImportFrozenModuleObject(name *PyObject) int

PyImport_ImportFrozenModuleObject loads a frozen module named name. Return 1 for success, 0 if the module is not found, and -1 with an exception set if the initialization failed. To access the imported module on a successful load, use PyImport_ImportModule(). (Note the misnomer — this function would reload the module if it was already imported.)

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ImportFrozenModuleObject

func PyList_Append

func PyList_Append(p, item *PyObject) int

PyList_Append appends the object item at the end of the list. Return 0 if successful; return -1 and set an exception if unsuccessful. Analogous to list.append(item).

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_Append

func PyList_Check

func PyList_Check(p *PyObject) bool

PyList_Check returns true if p is a list object or an instance of a subtype of the list type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_Check

func PyList_CheckExact

func PyList_CheckExact(p *PyObject) bool

PyList_CheckExact returns true if p is a list object or an instance of a subtype of the list type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_CheckExact

func PyList_Insert

func PyList_Insert(p *PyObject, index int, item *PyObject) int

PyList_Insert inserts the item into the list in front of the index. Return 0 if successful; return -1 and set an exception if unsuccessful. Analogous to list.insert(index, item).

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_Insert

func PyList_Reverse

func PyList_Reverse(list *PyObject) int

PyList_Reverse sorts the items of list in place. Return 0 on success, -1 on failure. This is equivalent to list.sort().

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_Reverse

func PyList_SetItem

func PyList_SetItem(p *PyObject, pos int, o *PyObject) int

PyList_SetItem sets the item at an index in list to item. Return 0 on success. If index is out of bounds, return -1 and set an IndexError exception.

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_SetItem

func PyList_SetSlice

func PyList_SetSlice(p *PyObject, low, high int, itemlist *PyObject) int

PyList_SetSlice sets the slice of list between low and high to the contents of itemlist. Analogous to list[low:high] = itemlist. The itemlist may be NULL, indicating the assignment of an empty list (slice deletion). Return 0 on success, -1 on failure. Indexing from the end of the list is not supported.

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_SetSlice

func PyList_Size

func PyList_Size(p *PyObject) int

PyList_Size returns the length of the list object in list; this is equivalent to len(list) on a list object.

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_Size

func PyList_Sort

func PyList_Sort(list *PyObject) int

PyList_Sort sorts the items of list in place. Return 0 on success, -1 on failure. This is equivalent to list.sort().

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_Sort

func PyLong_AsDouble

func PyLong_AsDouble(obj *PyObject) float64

PyLong_AsDouble returns a C double representation of pylong. pylong must be an instance of PyLongObject.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_AsDouble

func PyLong_AsLong

func PyLong_AsLong(obj *PyObject) int

PyLong_AsLong returns a C long representation of obj. If obj is not an instance of PyLongObject, first call its __index__() method (if present) to convert it to a PyLongObject.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_AsLong

func PyLong_AsLongAndOverflow

func PyLong_AsLongAndOverflow(obj *PyObject) (int, int)

PyLong_AsLongAndOverflow returns a C long representation of obj. If obj is not an instance of PyLongObject, first call its __index__() method (if present) to convert it to a PyLongObject.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_AsLongAndOverflow

func PyLong_AsLongLong

func PyLong_AsLongLong(obj *PyObject) int64

PyLong_AsLongLong returns a C long long representation of obj. If obj is not an instance of PyLongObject, first call its __index__() method (if present) to convert it to a PyLongObject.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_AsLongLong nolint: dupword

func PyLong_AsLongLongAndOverflow

func PyLong_AsLongLongAndOverflow(obj *PyObject) (int64, int)

PyLong_AsLongLongAndOverflow returns a C long long representation of obj. If obj is not an instance of PyLongObject, first call its __index__() method (if present) to convert it to a PyLongObject.

If the value of obj is greater than LLONG_MAX or less than LLONG_MIN, set *overflow to 1 or -1, respectively, and return -1; otherwise, set *overflow to 0. If any other exception occurs set *overflow to 0 and return -1 as usual.

Returns -1 on error. Use PyErr_Occurred() to disambiguate.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_AsLongLongAndOverflow nolint: dupword

func PyLong_AsUnsignedLong

func PyLong_AsUnsignedLong(obj *PyObject) uint

PyLong_AsUnsignedLong returns a C long long representation of obj. If obj is not an instance of PyLongObject, first call its __index__() method (if present) to convert it to a PyLongObject.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_AsUnsignedLong nolint: dupword

func PyLong_AsUnsignedLongLong

func PyLong_AsUnsignedLongLong(obj *PyObject) uint64

PyLong_AsUnsignedLongLong returns a C unsigned long long representation of pylong. pylong must be an instance of PyLongObject.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_AsUnsignedLongLong nolint: dupword

func PyLong_AsUnsignedLongLongMask

func PyLong_AsUnsignedLongLongMask(obj *PyObject) uint64

PyLong_AsUnsignedLongLongMask returns a C unsigned long long representation of obj. If obj is not an instance of PyLongObject, first call its __index__() method (if present) to convert it to a PyLongObject.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_AsUnsignedLongLongMask nolint: dupword

func PyLong_AsUnsignedLongMask

func PyLong_AsUnsignedLongMask(obj *PyObject) uint

PyLong_AsUnsignedLongMask returns a C unsigned long representation of obj. If obj is not an instance of PyLongObject, first call its __index__() method (if present) to convert it to a PyLongObject.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_AsUnsignedLongMask

func PyLong_Check

func PyLong_Check(p *PyObject) bool

PyLong_Check returns true if its argument is a PyLongObject or a subtype of PyLongObject. This function always succeeds.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_Check

func PyLong_CheckExact

func PyLong_CheckExact(p *PyObject) bool

PyLong_CheckExact returns true if its argument is a PyLongObject, but not a subtype of PyLongObject. This function always succeeds.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_CheckExact

func PyModule_Check

func PyModule_Check(p *PyObject) bool

PyModule_Check returns true if p is a module object, or a subtype of a module object. This function always succeeds.

Reference: https://docs.python.org/3/c-api/module.html#c.PyModule_Check

func PyModule_CheckExact

func PyModule_CheckExact(p *PyObject) bool

PyModule_CheckExact returns true if p is a module object, but not a subtype of PyModule_Type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/module.html#c.PyModule_CheckExact

func PyModule_GetName

func PyModule_GetName(module *PyObject) string

PyModule_GetName is similar to PyModule_GetNameObject() but return the name encoded to 'utf-8'.

Reference: https://docs.python.org/3/c-api/module.html#c.PyModule_GetName

func PyModule_GetState

func PyModule_GetState(module *PyObject) unsafe.Pointer

PyModule_GetState returns 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.

Reference: https://docs.python.org/3/c-api/module.html#c.PyModule_GetState

func PyOS_AfterFork_Child

func PyOS_AfterFork_Child()

PyOS_AfterFork_Child updates internal interpreter state after a process fork. This must be called from the child process after calling fork(), or any similar function that clones the current process, if there is any chance the process will call back into the Python interpreter. Only available on systems where fork() is defined.

Reference: https://docs.python.org/3/c-api/sys.html#c.PyOS_AfterFork_Child

func PyRun_AnyFile

func PyRun_AnyFile(filename string) (int, error)

PyRun_AnyFile is a simplified interface to PyRun_AnyFileExFlags() below, leaving closeit set to 0 and flags set to NULL.

"error" will be set if we fail to open "filename".

Reference: https://docs.python.org/3/c-api/veryhigh.html?highlight=pycompilerflags#c.PyRun_AnyFile

func PySequence_Contains

func PySequence_Contains(o *PyObject, value *PyObject) int

PySequence_Contains determines if o contains value. If an item in o is equal to value, return 1, otherwise return 0. On error, return -1. This is equivalent to the Python expression value in o.

Reference: https://docs.python.org/3/c-api/sequence.html#c.PySequence_Contains

func PySys_ResetWarnOptions

func PySys_ResetWarnOptions()

PySys_ResetWarnOptions resets sys.warnoptions to an empty list. This function may be called prior to Py_Initialize().

Reference: https://docs.python.org/3/c-api/sys.html#c.PySys_ResetWarnOptions

func PySys_SetObject

func PySys_SetObject(name string, v *PyObject) int

PySys_SetObject sets name in the sys module to v unless v is NULL, in which case name is deleted from the sys module. Returns 0 on success, -1 on error.

Reference: https://docs.python.org/3/c-api/sys.html#c.PySys_SetObject

func PyTuple_Check

func PyTuple_Check(p *PyObject) bool

PyTuple_Check returns true if p is a tuple object or an instance of a subtype of the tuple type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/tuple.html#c.PyTuple_Check

func PyTuple_CheckExact

func PyTuple_CheckExact(p *PyObject) bool

PyTuple_CheckExact return true if p is a tuple object, but not an instance of a subtype of the tuple type. This function always succeeds.

Reference: https://docs.python.org/3/c-api/tuple.html#c.PyTuple_CheckExact

func PyTuple_SetItem

func PyTuple_SetItem(p *PyObject, pos int, o *PyObject) int

PyTuple_SetItem inserts a reference to object o at position pos of the tuple pointed to by p. Return 0 on success. If pos is out of bounds, return -1 and set an IndexError exception.

Reference: https://docs.python.org/3/c-api/tuple.html#c.PyTuple_SetItem

func PyTuple_Size

func PyTuple_Size(p *PyObject) int

PyTuple_Size returns the size of the tuple.

Reference: https://docs.python.org/3/c-api/tuple.html#c.PyTuple_Size

func PyType_Check

func PyType_Check(o *PyObject) bool

PyType_Check returns non-zero if the object o is a type object, including instances of types derived from the standard type object. Return 0 in all other cases. This function always succeeds.

Reference: https://docs.python.org/3/c-api/type.html#c.PyType_Check

func PyType_CheckExact

func PyType_CheckExact(o *PyObject) bool

PyType_CheckExact returns non-zero if the object o is a type object, but not a subtype of the standard type object. Return 0 in all other cases. This function always succeeds.

Reference: https://docs.python.org/3/c-api/type.html#c.PyType_CheckExact

func PyUnicode_AsUTF8

func PyUnicode_AsUTF8(unicode *PyObject) string

PyUnicode_AsUTF8 is the same as PyUnicode_AsUTF8AndSize(), but does not store the size.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_AsUTF8

func PyUnicode_Check

func PyUnicode_Check(o *PyObject) bool

PyUnicode_Check returns true if the object obj is a Unicode object or an instance of a Unicode subtype. This function always succeeds.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_Check

func PyUnicode_CheckExact

func PyUnicode_CheckExact(o *PyObject) bool

PyUnicode_CheckExact returns true if the object obj is a Unicode object, but not an instance of a subtype. This function always succeeds.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_CheckExact

func PyUnicode_CopyCharacters

func PyUnicode_CopyCharacters(to, from *PyObject, to_start, from_start, how_many int) int

PyUnicode_CopyCharacters copy characters from one Unicode object into another. This function performs character conversion when necessary and falls back to memcpy() if possible. Returns -1 and sets an exception on error, otherwise returns the number of copied characters.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_CopyCharacters

func PyUnicode_Fill

func PyUnicode_Fill(unicode *PyObject, start, length int, fill_char rune) int

PyUnicode_Fill fills a string with a character: write fill_char into unicode[start:start+length].

Fail if fill_char is bigger than the string maximum character, or if the string has more than 1 reference.

The function returns the number of written character, or return -1 and raise an exception on error.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_Fill

func PyUnicode_GetLength

func PyUnicode_GetLength(unicode *PyObject) int

PyUnicode_GetLength returns the length of the Unicode object, in code points.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_GetLength

func PyUnicode_ReadChar

func PyUnicode_ReadChar(unicode *PyObject, index int) rune

PyUnicode_ReadChar reads a character from a string. This function checks that unicode is a Unicode object and the index is not out of bounds, in contrast to PyUnicode_READ_CHAR(), which performs no error checking.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_ReadChar

func PyUnicode_WriteChar

func PyUnicode_WriteChar(unicode *PyObject, index int, character rune) int

PyUnicode_WriteChar writes a character to a string. The string must have been created through PyUnicode_New(). Since Unicode strings are supposed to be immutable, the string must not be shared, or have been hashed yet.

This function checks that unicode is a Unicode object, that the index is not out of bounds, and that the object can be modified safely (i.e. that it its reference count is one).

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_WriteChar

func Py_EnterRecursiveCall

func Py_EnterRecursiveCall(where string) int

Py_EnterRecursiveCall marks a point where a recursive C-level call is about to be performed.

If USE_STACKCHECK is defined, this function checks if the OS stack overflowed using PyOS_CheckStack(). In this is the case, it sets a MemoryError and returns a nonzero value.

The function then checks if the recursion limit is reached. If this is the case, a RecursionError is set and a nonzero value is returned. Otherwise, zero is returned.

where should be a UTF-8 encoded string such as "in instance check" to be concatenated to the RecursionError message caused by the recursion depth limit.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.Py_EnterRecursiveCall

func Py_Finalize

func Py_Finalize()

Py_Finalize is a backwards-compatible version of Py_FinalizeEx() that disregards the return value.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_Finalize

func Py_FinalizeEx

func Py_FinalizeEx() int

Py_FinalizeEx undoes all initializations made by Py_Initialize() and subsequent use of Python/C API functions, and destroy all sub-interpreters (see Py_NewInterpreter() below) that were created and not yet destroyed since the last call to Py_Initialize(). Ideally, this frees all memory allocated by the Python interpreter. This is a no-op when called for a second time (without calling Py_Initialize() again first). Normally the return value is 0. If there were errors during finalization (flushing buffered data), -1 is returned.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_FinalizeEx

func Py_GetBuildInfo

func Py_GetBuildInfo() string

Py_GetBuildInfo returns information about the sequence number and build date and time of the current Python interpreter instance, for example:

"#67, Aug 1 1997, 22:34:28"

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetBuildInfo

func Py_GetCompiler

func Py_GetCompiler() string

Py_GetCompiler returns an indication of the compiler used to build the current Python version, in square brackets, for example:

"[GCC 2.7.2.2]"

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetCompiler

func Py_GetCopyright

func Py_GetCopyright() string

Py_GetCopyright returns the official copyright string for the current Python version, for example:

"Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam"

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetCopyright nolint: misspell

func Py_GetExecPrefix

func Py_GetExecPrefix() (string, error)

Py_GetExecPrefix returns the exec-prefix for installed platform-dependent files. This is derived through a number of complicated rules from the program name set with Py_SetProgramName() and some environment variables; for example, if the program name is '/usr/local/bin/python', the exec-prefix is '/usr/local'. The returned string points into static storage; the caller should not modify its value. This corresponds to the exec_prefix variable in the top-level Makefile and the --exec-prefix argument to the configure script at build time. The value is available to Python code as sys.exec_prefix. It is only useful on Unix.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetExecPrefix

func Py_GetPath

func Py_GetPath() (string, error)

Py_GetPath returns the default module search path; this is computed from the program name (set by Py_SetProgramName() above) and some environment variables. The returned string consists of a series of directory names separated by a platform dependent delimiter character. The delimiter character is ':' on Unix and macOS, ';' on Windows. The returned string points into static storage; the caller should not modify its value. The list `sys.path` is initialized with this value on interpreter startup; it can be (and usually is) modified later to change the search path for loading modules.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetPath

func Py_GetPlatform

func Py_GetPlatform() string

Py_GetPlatform returns the platform identifier for the current platform. On Unix, this is formed from the "official" name of the operating system, converted to lower case, followed by the major revision number; e.g., for Solaris 2.x, which is also known as SunOS 5.x, the value is 'sunos5'. On macOS, it is 'darwin'. On Windows, it is 'win'. The returned string points into static storage; the caller should not modify its value. The value is available to Python code as `sys.platform`.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetPlatform

func Py_GetPrefix

func Py_GetPrefix() (string, error)

Py_GetPrefix returns the prefix for installed platform-independent files. This is derived through a number of complicated rules from the program name set with Py_SetProgramName() and some environment variables; for example, if the program name is '/usr/local/bin/python', the prefix is '/usr/local'. The returned string points into static storage; the caller should not modify its value. This corresponds to the prefix variable in the top-level Makefile and the --prefix argument to the configure script at build time. The value is available to Python code as sys.prefix. It is only useful on Unix. See also the next function.

This function should not be called before Py_Initialize(), otherwise it returns NULL.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetPrefix

func Py_GetProgramFullPath

func Py_GetProgramFullPath() (string, error)

Py_GetProgramFullPath returns the full program name of the Python executable; this is computed as a side effect of deriving the default module search path from the program name (set by Py_SetProgramName() above). The returned string points into static storage; the caller should not modify its value. The value is available to Python code as `sys.executable`.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetProgramFullPath

func Py_GetProgramName

func Py_GetProgramName() (string, error)

Py_GetProgramName returns the program name set with Py_SetProgramName(), or the default. The returned string points into static storage; the caller should not modify its value.

This function should not be called before Py_Initialize(), otherwise it returns NULL.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetProgramName

func Py_GetPythonHome

func Py_GetPythonHome() (string, error)

Py_GetPythonHome returns the default "home", that is, the value set by a previous call to Py_SetPythonHome(), or the value of the `PYTHONHOME` environment variable if it is set.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetPythonHome

func Py_GetVersion

func Py_GetVersion() string

Py_GetVersion returns the version of this Python interpreter. This is a string that looks something like:

"3.0a5+ (py3k:63103M, May 12 2008, 00:53:55) \n[GCC 4.2.3]"

Reference: https://docs.python.org/3/c-api/init.html#c.Py_GetVersion

func Py_Initialize

func Py_Initialize()

Py_Initialize initializes the Python interpreter. In an application embedding Python, this should be called before using any other Python/C API functions; see Before Python Initialization for the few exceptions.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_Initialize

func Py_InitializeEx

func Py_InitializeEx(initsigs bool)

Py_InitializeEx works like Py_Initialize() if initsigs is 1. If initsigs is 0, it skips initialization registration of signal handlers, which might be useful when Python is embedded.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_InitializeEx

func Py_IsInitialized

func Py_IsInitialized() bool

Py_IsInitialized return true (nonzero) when the Python interpreter has been initialized, false (zero) if not. After Py_FinalizeEx() is called, this returns false until Py_Initialize() is called again.

Reference: https://docs.python.org/3/c-api/init.html#c.Py_IsInitialized

func Py_LeaveRecursiveCall

func Py_LeaveRecursiveCall()

Py_LeaveRecursiveCall implements tp_repr for container types requires special recursion handling. In addition to protecting the stack, tp_repr also needs to track objects to prevent cycles. The following two functions facilitate this functionality. Effectively, these are the C equivalent to reprlib.recursive_repr().

Reference: https://docs.python.org/3/c-api/exceptions.html#c.Py_LeaveRecursiveCall

func Py_Main

func Py_Main(args []string) (int, error)

Py_Main is the main program for the standard interpreter. This is made available for programs which embed Python. The argc and argv parameters should be prepared exactly as those which are passed to a C program's main() function (converted to wchar_t according to the user's locale). It is important to note that the argument list may be modified (but the contents of the strings pointed to by the argument list are not). The return value will be 0 if the interpreter exits normally (i.e., without an exception), 1 if the interpreter exits due to an exception, or 2 if the parameter list does not represent a valid Python command line.

"error" will be set if we fail to call "Py_DecodeLocale" on every "args".

Reference: https://docs.python.org/3/c-api/veryhigh.html?highlight=pycompilerflags#c.Py_Main

Types

type PyGILState

type PyGILState C.PyGILState_STATE

PyGILState is an opaque "handle" to the thread state when PyGILState_Ensure() was called, and must be passed to PyGILState_Release() to ensure Python is left in the same state

func PyGILState_Ensure

func PyGILState_Ensure() PyGILState

PyGILState_Ensure ensures that the current thread is ready to call the Python C API regardless of the current state of Python, or of the global interpreter lock. This may be called as many times as desired by a thread as long as each call is matched with a call to PyGILState_Release(). In general, other thread-related APIs may be used between PyGILState_Ensure() and PyGILState_Release() calls as long as the thread state is restored to its previous state before the Release(). For example, normal usage of the Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS macros is acceptable.

The return value is an opaque "handle" to the thread state when PyGILState_Ensure() was called, and must be passed to PyGILState_Release() to ensure Python is left in the same state. Even though recursive calls are allowed, these handles cannot be shared - each unique call to PyGILState_Ensure() must save the handle for its call to PyGILState_Release().

When the function returns, the current thread will hold the GIL and be able to call arbitrary Python code. Failure is a fatal error.

Reference: https://docs.python.org/3/c-api/init.html#c.PyGILState_Ensure

type PyObject

type PyObject C.PyObject

PyObject is the base of all object types. This is a type which contains the information Python needs to treat a pointer to an object as an object. In a normal "release" build, it contains only the object's reference count and a pointer to the corresponding type object. Nothing is actually declared to be a PyObject, but every pointer to a Python object can be cast to a PyObject*. Access to the members must be done by using the macros Py_REFCNT and Py_TYPE.

Reference: https://docs.python.org/3/c-api/structures.html?highlight=pyobject#c.PyObject

func PyBool_FromLong

func PyBool_FromLong(v int) *PyObject

PyBool_FromLong returns Py_True or Py_False, depending on the truth value of v.

Reference: https://docs.python.org/3/c-api/bool.html#c.PyBool_FromLong

func PyByteArray_Concat

func PyByteArray_Concat(a, b *PyObject) *PyObject

PyByteArray_Concat concatenates `bytearray`s a and b and return a new `bytearray` with the result.

Reference: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_Concat

func PyByteArray_FromObject

func PyByteArray_FromObject(o *PyObject) *PyObject

PyByteArray_FromObject returns a new `bytearray` object from any object, o, that implements the buffer protocol.

Reference: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_FromObject

func PyByteArray_FromStringAndSize

func PyByteArray_FromStringAndSize(str string) *PyObject

PyByteArray_FromStringAndSize creates a new `bytearray` object from `string` and its length, `len`. On failure, `NULL` is returned.

Reference: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_FromStringAndSize

func PyBytes_Concat

func PyBytes_Concat(bytes, newpart *PyObject) *PyObject

PyBytes_Concat creates a new bytes object in *bytes containing the contents of newpart appended to bytes; the caller will own the new reference. The reference to the old value of bytes will be stolen. If the new object cannot be created, the old reference to bytes will still be discarded and the value of *bytes will be set to NULL; the appropriate exception will be set.

Reference: https://docs.python.org/3/c-api/bytes.html#c.PyBytes_Concat

func PyBytes_ConcatAndDel

func PyBytes_ConcatAndDel(bytes, newpart *PyObject) *PyObject

PyBytes_ConcatAndDel creates a new bytes object in *bytes containing the contents of newpart appended to bytes. This version releases the strong reference to newpart (i.e. decrements its reference count).

Reference: https://docs.python.org/3/c-api/bytes.html#c.PyBytes_ConcatAndDel

func PyBytes_FromByteSlice

func PyBytes_FromByteSlice(bytes []byte) *PyObject

PyBytes_FromByteSlice uses https://docs.python.org/3/c-api/bytes.html#c.PyBytes_FromStringAndSize but with []byte

func PyBytes_FromObject

func PyBytes_FromObject(o *PyObject) *PyObject

PyBytes_FromObject returns the `bytes` representation of object o that implements the buffer protocol.

Reference: https://docs.python.org/3/c-api/bytes.html#c.PyBytes_FromObject

func PyBytes_FromString

func PyBytes_FromString(str string) *PyObject

PyBytes_FromString returns a new bytes object with a copy of the string v as value on success, and NULL on failure. The parameter v must not be NULL; it will not be checked.

Reference: https://docs.python.org/3/c-api/bytes.html#c.PyBytes_FromString

func PyBytes_FromStringAndSize

func PyBytes_FromStringAndSize(str string) *PyObject

PyBytes_FromStringAndSize returns a new `bytes` object with a copy of the string v as value and length len on success, and `NULL` on failure. If v is `NULL`, the contents of the bytes object are uninitialized.

Reference: https://docs.python.org/3/c-api/bytes.html#c.PyBytes_FromStringAndSize

func PyComplex_FromDoubles

func PyComplex_FromDoubles(realNumber, imaginaryUnit float64) *PyObject

PyComplex_FromDoubles returns a new PyComplexObject object from real and imag.

Reference: https://docs.python.org/3/c-api/complex.html#c.PyComplex_FromDoubles

func PyDictProxy_New

func PyDictProxy_New(mapping *PyObject) *PyObject

PyDictProxy_New returns a types.MappingProxyType object for a mapping which enforces read-only behavior. This is normally used to create a view to prevent modification of the dictionary for non-dynamic class types.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDictProxy_New

func PyDict_Copy

func PyDict_Copy(p *PyObject) *PyObject

PyDict_Copy returns a new dictionary that contains the same key-value pairs as p.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_Copy

func PyDict_GetItem

func PyDict_GetItem(p, key *PyObject) *PyObject

PyDict_GetItem returns the object from dictionary p which has the key. Return NULL if the key is not present, but without setting an exception.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_GetItem

func PyDict_GetItemString

func PyDict_GetItemString(p *PyObject, key string) *PyObject

PyDict_GetItemString is the same as PyDict_GetItem(), but key is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_GetItemString

func PyDict_GetItemWithError

func PyDict_GetItemWithError(p, key *PyObject) *PyObject

PyDict_GetItemWithError is a 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.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_GetItemWithError

func PyDict_Items

func PyDict_Items(p *PyObject) *PyObject

PyDict_Items returns a PyListObject containing all the items from the dictionary.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_Items

func PyDict_Keys

func PyDict_Keys(p *PyObject) *PyObject

PyDict_Keys returns a PyListObject containing all the items from the dictionary.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_Keys

func PyDict_New

func PyDict_New() *PyObject

PyDict_New returns a new empty dictionary, or NULL on failure.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_New

func PyDict_SetDefault

func PyDict_SetDefault(p, key, pyDefault *PyObject) *PyObject

PyDict_SetDefault 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.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_SetDefault

func PyDict_Values

func PyDict_Values(p *PyObject) *PyObject

PyDict_Values returns a PyListObject containing all the values from the dictionary p.

Reference: https://docs.python.org/3/c-api/dict.html#c.PyDict_Values

func PyErr_NewException

func PyErr_NewException(name string, base, dict *PyObject) *PyObject

PyErr_NewException creates and returns a new exception class. The name argument must be the name of the new exception, a C string of the form module.classname. The base and dict arguments are normally NULL. This creates a class object derived from Exception (accessible in C as PyExc_Exception).

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NewException

func PyErr_NewExceptionWithDoc

func PyErr_NewExceptionWithDoc(name, doc string, base, dict *PyObject) *PyObject

PyErr_NewExceptionWithDoc is the same as PyErr_NewException(), except that the new exception class can easily be given a docstring: If doc is non-NULL, it will be used as the docstring for the exception class.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NewExceptionWithDoc

func PyErr_NoMemory

func PyErr_NoMemory() *PyObject

PyErr_NoMemory is a shorthand for PyErr_SetNone(PyExc_MemoryError); it returns NULL so an object allocation function can write return PyErr_NoMemory(); when it runs out of memory.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_NoMemory

func PyErr_Occurred

func PyErr_Occurred() *PyObject

PyErr_Occurred tests whether the error indicator is set. If set, return the exception type (the first argument to the last call to one of the PyErr_Set* functions or to PyErr_Restore()). If not set, return NULL. You do not own a reference to the return value, so you do not need to Py_DECREF() it.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_Occurred

func PyErr_SetImportError

func PyErr_SetImportError(msg, name, path *PyObject) *PyObject

PyErr_SetImportError is a convenience function to raise ImportError. msg will be set as the exception's message string. name and path, both of which can be NULL, will be set as the ImportError's respective name and path attributes.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetImportError

func PyErr_SetImportErrorSubclass

func PyErr_SetImportErrorSubclass(msg, name, path, subclass *PyObject) *PyObject

PyErr_SetImportErrorSubclass is like PyErr_SetImportError() but this function allows for specifying a subclass of ImportError to raise.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyErr_SetImportErrorSubclass

func PyEval_GetBuiltins

func PyEval_GetBuiltins() *PyObject

PyEval_GetBuiltins returns a dictionary of the builtins in the current execution frame, or the interpreter of the thread state if no frame is currently executing.

Reference: https://docs.python.org/3/c-api/reflection.html?highlight=reflection#c.PyEval_GetBuiltins

func PyEval_GetGlobals

func PyEval_GetGlobals() *PyObject

PyEval_GetGlobals returns a dictionary of the global variables in the current execution frame, or NULL if no frame is currently executing.

Reference: https://docs.python.org/3/c-api/reflection.html?highlight=reflection#c.PyEval_GetGlobals

func PyEval_GetLocals

func PyEval_GetLocals() *PyObject

PyEval_GetLocals returns a dictionary of the local variables in the current execution frame, or NULL if no frame is currently executing.

Reference: https://docs.python.org/3/c-api/reflection.html?highlight=reflection#c.PyEval_GetLocals

func PyException_GetCause

func PyException_GetCause(ex *PyObject) *PyObject

PyException_GetCause returns the cause (either an exception instance, or None, set by raise ... from ...) associated with the exception as a new reference, as accessible from Python through the __cause__ attribute.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyException_GetCause

func PyException_GetContext

func PyException_GetContext(ex *PyObject) *PyObject

PyException_GetContext returns the context (another exception instance during whose handling ex was raised) associated with the exception as a new reference, as accessible from Python through the __context__ attribute. If there is no context associated, this returns NULL.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyException_GetContext

func PyException_GetTraceback

func PyException_GetTraceback(ex *PyObject) *PyObject

PyException_GetTraceback returns the traceback associated with the exception as a new reference, as accessible from Python through the __traceback__ attribute. If there is no traceback associated, this returns NULL.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.PyException_GetTraceback

func PyFloat_FromDouble

func PyFloat_FromDouble(v float64) *PyObject

PyFloat_FromDouble creates a PyFloatObject object from v, or NULL on failure.

Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_FromDouble

func PyFloat_FromString

func PyFloat_FromString(str *PyObject) *PyObject

PyFloat_FromString creates a PyFloatObject object based on the string value in str, or NULL on failure.

Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_FromString

func PyFloat_GetInfo

func PyFloat_GetInfo() *PyObject

PyFloat_GetInfo returns a structseq instance which contains information about the precision, minimum and maximum values of a float. It's a thin wrapper around the header file float.h.

Reference: https://docs.python.org/3/c-api/float.html#c.PyFloat_GetInfo

func PyImport_AddModule

func PyImport_AddModule(name string) *PyObject

PyImport_AddModule is similar to PyImport_AddModuleObject(), but the name is a UTF-8 encoded string instead of a Unicode object.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_AddModule

func PyImport_AddModuleObject

func PyImport_AddModuleObject(name *PyObject) *PyObject

PyImport_AddModuleObject returns the module object corresponding to a module name. The name argument may be of the form package.module. First check the modules dictionary if there's one there, and if not, create a new one and insert it in the modules dictionary. Return NULL with an exception set on failure.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_AddModuleObject

func PyImport_ExecCodeModule

func PyImport_ExecCodeModule(name string, co *PyObject) *PyObject

PyImport_ExecCodeModule loads a module given a module name (possibly of the form package.module) and a code object read from a Python bytecode file or obtained from the built-in function compile(). Return a new reference to the module object, or NULL with an exception set if an error occurred. name is removed from sys.modules in error cases, even if name was already in sys.modules on entry to PyImport_ExecCodeModule(). Leaving incompletely initialized modules in sys.modules is dangerous, as imports of such modules have no way to know that the module object is an unknown (and probably damaged with respect to the module author's intents) state.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ExecCodeModule

func PyImport_ExecCodeModuleEx

func PyImport_ExecCodeModuleEx(name string, co *PyObject, pathname string) *PyObject

PyImport_ExecCodeModuleEx is like PyImport_ExecCodeModule(), but the __file__ attribute of the module object is set to pathname if it is non-NULL.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ExecCodeModuleEx

func PyImport_ExecCodeModuleObject

func PyImport_ExecCodeModuleObject(name, co, pathname, cpathname *PyObject) *PyObject

PyImport_ExecCodeModuleObject is like PyImport_ExecCodeModuleEx(), but the __cached__ attribute of the module object is set to cpathname if it is non-NULL. Of the three functions, this is the preferred one to use.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ExecCodeModuleObject

func PyImport_ExecCodeModuleWithPathnames

func PyImport_ExecCodeModuleWithPathnames(name string, co *PyObject, pathname string, cpathname string) *PyObject

PyImport_ExecCodeModuleWithPathnames is like PyImport_ExecCodeModuleObject(), but name, pathname and cpathname are UTF-8 encoded strings. Attempts are also made to figure out what the value for pathname should be from cpathname if the former is set to NULL.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ExecCodeModuleWithPathnames

func PyImport_GetImporter

func PyImport_GetImporter(path *PyObject) *PyObject

PyImport_GetImporter returns a finder object for a sys.path/pkg.__path__ item path, possibly by fetching it from the sys.path_importer_cache dict. If it wasn't yet cached, traverse sys.path_hooks until a hook is found that can handle the path item. Return None if no hook could; this tells our caller that the path based finder could not find a finder for this path item. Cache the result in sys.path_importer_cache. Return a new reference to the finder object.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_GetImporter

func PyImport_GetModule

func PyImport_GetModule(name *PyObject) *PyObject

PyImport_GetModule returns the already imported module with the given name. If the module has not been imported yet then returns NULL but does not set an error. Returns NULL and sets an error if the lookup failed.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_GetModule

func PyImport_GetModuleDict

func PyImport_GetModuleDict() *PyObject

PyImport_GetModuleDict returns the magic tag string for PEP 3147 format Python bytecode file names. Keep in mind that the value at sys.implementation.cache_tag is authoritative and should be used instead of this function.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_GetModuleDict

func PyImport_Import

func PyImport_Import(name *PyObject) *PyObject

PyImport_Import is a higher-level interface that calls the current "import hook function" (with an explicit level of 0, meaning absolute import). It invokes the __import__() function from the __builtins__ of the current globals. This means that the import is done using whatever import hooks are installed in the current environment.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_Import

func PyImport_ImportModule

func PyImport_ImportModule(name string) *PyObject

PyImport_ImportModule is a wrapper around PyImport_Import() which takes a const char* as an argument instead of a PyObject*.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ImportModule

func PyImport_ImportModuleEx

func PyImport_ImportModuleEx(name string, globals, locals, fromlist *PyObject) *PyObject

PyImport_ImportModuleEx imports a module. This is best described by referring to the built-in Python function __import__().

The return value is a new reference to the imported module or top-level package, or NULL with an exception set on failure. Like for __import__(), the return value when a submodule of a package was requested is normally the top-level package, unless a non-empty fromlist was given.

Failing imports remove incomplete module objects, like with PyImport_ImportModule().

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ImportModuleEx

func PyImport_ImportModuleLevel

func PyImport_ImportModuleLevel(name string, globals, locals, fromlist *PyObject, level int) *PyObject

PyImport_ImportModuleLevel is similar to PyImport_ImportModuleLevelObject(), but the name is a UTF-8 encoded string instead of a Unicode object.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ImportModuleLevel

func PyImport_ImportModuleLevelObject

func PyImport_ImportModuleLevelObject(name, globals, locals, fromlist *PyObject, level int) *PyObject

PyImport_ImportModuleLevelObject imports a module. This is best described by referring to the built-in Python function __import__(), as the standard __import__() function calls this function directly.

The return value is a new reference to the imported module or top-level package, or NULL with an exception set on failure. Like for __import__(), the return value when a submodule of a package was requested is normally the top-level package, unless a non-empty fromlist was given.

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ImportModuleLevelObject

func PyImport_ReloadModule

func PyImport_ReloadModule(name *PyObject) *PyObject

PyImport_ReloadModule reloads a module. Return a new reference to the reloaded module, or NULL with an exception set on failure (the module still exists in this case).

Reference: https://docs.python.org/3/c-api/import.html#c.PyImport_ReloadModule

func PyList_AsTuple

func PyList_AsTuple(list *PyObject) *PyObject

PyList_AsTuple returns a new tuple object containing the contents of list; equivalent to tuple(list).

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_AsTuple

func PyList_GetItem

func PyList_GetItem(p *PyObject, pos int) *PyObject

PyList_GetItem returns the object at position index in the list pointed to by list. The position must be non-negative; indexing from the end of the list is not supported. If index is out of bounds (<0 or >=len(list)), return NULL and set an IndexError exception.

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_GetItem

func PyList_GetSlice

func PyList_GetSlice(p *PyObject, low, high int) *PyObject

PyList_GetSlice appends the object item at the end of the list. Return 0 if successful; return -1 and set an exception if unsuccessful. Analogous to list.append(item).

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_GetSlice

func PyList_New

func PyList_New(length int) *PyObject

PyList_New returns a new list of length len on success, or NULL on failure.

Reference: https://docs.python.org/3/c-api/list.html#c.PyList_New

func PyLong_FromDouble

func PyLong_FromDouble(v float64) *PyObject

PyLong_FromDouble returns a new PyLongObject object from the integer part of v, or NULL on failure.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_FromDouble

func PyLong_FromGoFloat64

func PyLong_FromGoFloat64(v float64) *PyObject

PyLong_FromGoFloat64 ensures the go integer type does not overflow.

func PyLong_FromGoInt

func PyLong_FromGoInt(v int) *PyObject

PyLong_FromGoInt ensures the go integer type does not overflow.

func PyLong_FromGoInt64

func PyLong_FromGoInt64(v int64) *PyObject

PyLong_FromGoInt64 ensures the go integer type does not overflow.

func PyLong_FromGoUint

func PyLong_FromGoUint(v uint) *PyObject

PyLong_FromGoUint ensures the go integer type does not overflow.

func PyLong_FromGoUint64

func PyLong_FromGoUint64(v uint64) *PyObject

PyLong_FromGoUint64 ensures the go integer type does not overflow.

func PyLong_FromLong

func PyLong_FromLong(v int) *PyObject

PyLong_FromLong returns a new PyLongObject object from v, or NULL on failure.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_FromLong

func PyLong_FromLongLong

func PyLong_FromLongLong(v int64) *PyObject

PyLong_FromLongLong returns a new PyLongObject object from a C unsigned long, or NULL on failure.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_FromLongLong

func PyLong_FromString

func PyLong_FromString(str string, base int) *PyObject

PyLong_FromString returns a new PyLongObject based on the string value in str, which is interpreted according to the radix in base, or NULL on failure. If pend is non-NULL, *pend will point to the end of str on success or to the first character that could not be processed on error. If base is 0, str is interpreted using the Integer literals definition; in this case, leading zeros in a non-zero decimal number raises a ValueError. If base is not 0, it must be between 2 and 36, inclusive. Leading and trailing whitespace and single underscores after a base specifier and between digits are ignored. If there are no digits or str is not NULL-terminated following the digits and trailing whitespace, ValueError will be raised.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_FromString

func PyLong_FromUnicodeObject

func PyLong_FromUnicodeObject(u *PyObject, base int) *PyObject

PyLong_FromUnicodeObject converts a sequence of Unicode digits in the string u to a Python integer value.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_FromUnicodeObject

func PyLong_FromUnsignedLong

func PyLong_FromUnsignedLong(v uint) *PyObject

PyLong_FromUnsignedLong returns a new PyLongObject object from a C unsigned long, or NULL on failure.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_FromUnsignedLong

func PyLong_FromUnsignedLongLong

func PyLong_FromUnsignedLongLong(v uint64) *PyObject

PyLong_FromUnsignedLongLong returns a new PyLongObject object from a C unsigned long long, or NULL on failure.

Reference: https://docs.python.org/3/c-api/long.html#c.PyLong_FromUnsignedLongLong

func PyModule_GetDict

func PyModule_GetDict(module *PyObject) *PyObject

PyModule_GetDict returns the dictionary object that implements module's namespace; this object is the same as the __dict__ attribute of the module object. If module is not a module object (or a subtype of a module object), SystemError is raised and NULL is returned.

Reference: https://docs.python.org/3/c-api/module.html#c.PyModule_GetDict

func PyModule_GetFilenameObject

func PyModule_GetFilenameObject(module *PyObject) *PyObject

PyModule_GetFilenameObject returns 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.

Reference: https://docs.python.org/3/c-api/module.html#c.PyModule_GetFilenameObject

func PyModule_GetNameObject

func PyModule_GetNameObject(module *PyObject) *PyObject

PyModule_GetNameObject 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.

Reference: https://docs.python.org/3/c-api/module.html#c.PyModule_GetNameObject

func PyModule_New

func PyModule_New(name string) *PyObject

PyModule_New is similar to PyModule_NewObject(), but the name is a UTF-8 encoded string instead of a Unicode object.

Reference: https://docs.python.org/3/c-api/module.html#c.PyModule_New

func PyModule_NewObject

func PyModule_NewObject(name *PyObject) *PyObject

PyModule_NewObject returns 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.

Reference: https://docs.python.org/3/c-api/module.html#c.PyModule_NewObject

func PySys_GetObject

func PySys_GetObject(name string) *PyObject

PySys_GetObject returns the object name from the sys module or NULL if it does not exist, without setting an exception.

Reference: https://docs.python.org/3/c-api/sys.html#c.PySys_GetObject

func PySys_GetXOptions

func PySys_GetXOptions() *PyObject

PySys_GetXOptions returns the current dictionary of -X options, similarly to sys._xoptions. On error, NULL is returned and an exception is set.

Reference: https://docs.python.org/3/c-api/sys.html#c.PySys_GetXOptions

func PyTuple_GetItem

func PyTuple_GetItem(p *PyObject, pos int) *PyObject

PyTuple_GetItem returns the object at position pos in the tuple pointed to by p. If pos is negative or out of bounds, return NULL and set an IndexError exception.

Reference: https://docs.python.org/3/c-api/tuple.html#c.PyTuple_GetItem

func PyTuple_GetSlice

func PyTuple_GetSlice(p *PyObject, low, high int) *PyObject

PyTuple_GetSlice returns the slice of the tuple pointed to by p between low and high, or NULL on failure. This is the equivalent of the Python expression p[low:high]. Indexing from the end of the tuple is not supported.

Reference: https://docs.python.org/3/c-api/tuple.html#c.PyTuple_GetSlice

func PyTuple_New

func PyTuple_New(length int) *PyObject

PyTuple_New returns a new tuple object of size len, or NULL on failure.

Reference: https://docs.python.org/3/c-api/tuple.html#c.PyTuple_New

func PyUnicode_FromEncodedObject

func PyUnicode_FromEncodedObject(obj *PyObject, encoding, errors string) *PyObject

PyUnicode_FromEncodedObject decodes an encoded object obj to a Unicode object.

bytes, bytearray and other bytes-like objects are decoded according to the given encoding and using the error handling defined by errors. Both can be NULL to have the interface use the default values (see Built-in Codecs for details).

All other objects, including Unicode objects, cause a TypeError to be set.

The API returns NULL if there was an error. The caller is responsible for decref’ing the returned objects.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_FromEncodedObject

func PyUnicode_FromString

func PyUnicode_FromString(u string) *PyObject

PyUnicode_FromString creates a Unicode object from a UTF-8 encoded null-terminated char buffer str.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_FromString

func PyUnicode_New

func PyUnicode_New(size int, maxchar rune) *PyObject

PyUnicode_New creates a new Unicode object. maxchar should be the true maximum code point to be placed in the string. As an approximation, it can be rounded up to the nearest value in the sequence 127, 255, 65535, 1114111.

This is the recommended way to allocate a new Unicode object. Objects created using this function are not resizable.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_New

func PyUnicode_Substring

func PyUnicode_Substring(unicode *PyObject, start, end int) *PyObject

PyUnicode_Substring returns a substring of unicode, from character index start (included) to character index end (excluded). Negative indices are not supported.

Reference: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_Substring

func (*PyObject) ASCII

func (pyObject *PyObject) ASCII() *PyObject

ASCII is similar to PyObject.Repr(), computes a string representation of object o, but escapes the non-ASCII characters in the string returned by PyObject_Repr() with \x, \u or \U escapes. This generates a string similar to that returned by PyObject.Repr() in Python 2. Called by the ascii() built-in function.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_ASCII

func (*PyObject) Bytes

func (pyObject *PyObject) Bytes() *PyObject

Bytes computes a bytes representation of object o. NULL is returned on failure and a bytes object on success. This is equivalent to the Python expression bytes(o), when o is not an integer. Unlike bytes(o), a TypeError is raised when o is an integer instead of a zero-initialized bytes object.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_Bytes

func (*PyObject) Call

func (pyObject *PyObject) Call(args *PyObject, kwargs *PyObject) *PyObject

Call calls a callable Python object callable, with arguments given by the tuple args, and named arguments given by the dictionary kwargs. The function returns the result of the call on success, or raise an exception and return NULL on failure.

args must not be NULL; use an empty tuple if no arguments are needed. If no named arguments are needed, kwargs can be NULL.

This is the equivalent of the Python expression: callable(*args).

Reference: https://docs.python.org/3/c-api/call.html#c.PyObject_Call

func (*PyObject) CallFunctionObjArgs

func (pyObject *PyObject) CallFunctionObjArgs(args ...*PyObject) *PyObject

CallFunctionObjArgs calls a callable Python object callable, with a variable number of PyObject* arguments. The arguments are provided as a variable number of parameters followed by NULL. The function returns the result of the call on success, or raise an exception and return NULL on failure.

This is the equivalent of the Python expression: callable(arg1, arg2, ...).

Reference: https://docs.python.org/3/c-api/call.html#c.PyObject_CallFunctionObjArgs

func (*PyObject) CallMethodArgs

func (pyObject *PyObject) CallMethodArgs(name string, args ...*PyObject) *PyObject

CallMethodArgs is the same as PyObject.CallMethodObjArgs but with name as go string

func (*PyObject) CallMethodObjArgs

func (pyObject *PyObject) CallMethodObjArgs(name *PyObject, args ...*PyObject) *PyObject

CallMethodObjArgs calls a method of the Python object obj, where the name of the method is given as a Python string object in name. It is called with a variable number of PyObject* arguments. The arguments are provided as a variable number of parameters followed by NULL. The function returns the result of the call on success, or raise an exception and return NULL on failure.

Reference: https://docs.python.org/3/c-api/call.html#c.PyObject_CallMethodObjArgs

func (*PyObject) CallObject

func (pyObject *PyObject) CallObject(args *PyObject) *PyObject

CallObject calls a callable Python object callable, with a variable number of C arguments. The C arguments are described using a Py_BuildValue() style format string. The format can be NULL, indicating that no arguments are provided. The function returns the result of the call on success, or raise an exception and return NULL on failure.

This is the equivalent of the Python expression: callable(*args).

Note that if you only pass PyObject* args, PyObject_CallFunctionObjArgs() is a faster alternative.

Reference: https://docs.python.org/3/c-api/call.html#c.PyObject_CallObject

func (*PyObject) DecRef

func (pyObject *PyObject) DecRef()

DecRef releases a strong reference to object o, indicating the reference is no longer used.

Reference: https://docs.python.org/3/c-api/refcounting.html#c.Py_DECREF

func (*PyObject) DelAttr

func (pyObject *PyObject) DelAttr(attr_name *PyObject) int

DelAttr deletes attribute named attr_name, for object o. Returns -1 on failure. This is the equivalent of the Python statement del o.attr_name.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_DelAttr

func (*PyObject) DelAttrString

func (pyObject *PyObject) DelAttrString(attr_name string) int

DelAttrString is the same as PyObject.DelAttr(), but attr_name is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_DelAttrString

func (*PyObject) DelItem

func (pyObject *PyObject) DelItem(key *PyObject) int

DelItem removes the mapping for the object key from the object o. Return -1 on failure. This is equivalent to the Python statement del o[key].

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_DelItem

func (*PyObject) Dir

func (pyObject *PyObject) Dir() *PyObject

Dir is equivalent to the Python expression dir(o), returning a (possibly empty) list of strings appropriate for the object argument, or NULL if there was an error. If the argument is NULL, this is like the Python dir(), returning the names of the current locals; in this case, if no execution frame is active then NULL is returned but PyErr_Occurred() will return false.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_Dir

func (*PyObject) GetAttr

func (pyObject *PyObject) GetAttr(attr_name *PyObject) *PyObject

GetAttr retrieves an attribute named attr_name from object o. Returns the attribute value on success, or NULL on failure. This is the equivalent of the Python expression o.attr_name.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_GetAttr

func (*PyObject) GetAttrString

func (pyObject *PyObject) GetAttrString(attr_name string) *PyObject

GetAttrString is the same as PyObject.GetAttr(), but attr_name is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_GetAttrString

func (*PyObject) GetItem

func (pyObject *PyObject) GetItem(key *PyObject) *PyObject

GetItem returns element of o corresponding to the object key or NULL on failure. This is the equivalent of the Python expression o[key].

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_GetItem

func (*PyObject) GetIter

func (pyObject *PyObject) GetIter() *PyObject

GetIter is equivalent to the Python expression iter(o). It returns a new iterator for the object argument, or the object itself if the object is already an iterator. Raises TypeError and returns NULL if the object cannot be iterated.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_GetIter

func (*PyObject) HasAttr

func (pyObject *PyObject) HasAttr(attr_name *PyObject) bool

HasAttr returns 1 if o has the attribute attr_name, and 0 otherwise. This is equivalent to the Python expression hasattr(o, attr_name). This function always succeeds.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_HasAttr

func (*PyObject) HasAttrString

func (pyObject *PyObject) HasAttrString(attr_name string) bool

HasAttrString is the same as PyObject.HasAttr(), but attr_name is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_HasAttrString

func (*PyObject) Hash

func (pyObject *PyObject) Hash() int

Hash computes and returns the hash value of an object o. On failure, return -1. This is the equivalent of the Python expression hash(o).

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_Hash

func (*PyObject) HashNotImplemented

func (pyObject *PyObject) HashNotImplemented() int

HashNotImplemented sets a TypeError indicating that type(o) is not hashable and return -1. This function receives special treatment when stored in a tp_hash slot, allowing a type to explicitly indicate to the interpreter that it is not hashable.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_HashNotImplemented

func (*PyObject) IncRef

func (pyObject *PyObject) IncRef()

IncRef indicates taking a new strong reference to object o, indicating it is in use and should not be destroyed.

Reference: https://docs.python.org/3/c-api/refcounting.html#c.Py_INCREF

func (*PyObject) IsInstance

func (pyObject *PyObject) IsInstance(cls *PyObject) int

IsInstance 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 exception.

If cls is a tuple, the check will be done against every entry in cls. The result will be 1 when at least one of the checks returns 1, otherwise it will be 0.

If cls has a __instancecheck__() method, it will be called to determine the subclass status as described in PEP 3119. Otherwise, inst is an instance of cls if its class is a subclass of cls.

An instance inst can override what is considered its class by having a __class__ attribute.

An object cls can override if it is considered a class, and what its base classes are, by having a __bases__ attribute (which must be a tuple of base classes).

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_IsInstance

func (*PyObject) IsSubclass

func (pyObject *PyObject) IsSubclass(cls *PyObject) int

IsSubclass returns 1 if the class derived is identical to or derived from the class cls, otherwise return 0. In case of an error, return -1.

If cls is a tuple, the check will be done against every entry in cls. The result will be 1 when at least one of the checks returns 1, otherwise it will be 0.

If cls has a __subclasscheck__() method, it will be called to determine the subclass status as described in PEP 3119. Otherwise, derived is a subclass of cls if it is a direct or indirect subclass, i.e. contained in cls.__mro__.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_IsSubclass

func (*PyObject) IsTrue

func (pyObject *PyObject) IsTrue() int

IsTrue returns 1 if the object o is considered to be true, and 0 otherwise. This is equivalent to the Python expression `not not o`. On failure, return -1.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_IsTrue nolint: dupword

func (*PyObject) Length

func (pyObject *PyObject) Length() int

Length returns the length of object o. If the object o provides either the sequence and mapping protocols, the sequence length is returned. On error, -1 is returned. This is the equivalent to the Python expression len(o).

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_Length

func (*PyObject) LengthHint

func (pyObject *PyObject) LengthHint(pyDefault int) int

LengthHint return an estimated length for the object o. First try to return its actual length, then an estimate using __length_hint__(), and finally return the default value. On error return -1. This is the equivalent to the Python expression operator.length_hint(o, defaultvalue).

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_LengthHint

func (*PyObject) Not

func (pyObject *PyObject) Not() int

Not returns 0 if the object o is considered to be true, and 1 otherwise. This is equivalent to the Python expression not o. On failure, return -1.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_Not

func (*PyObject) Repr

func (pyObject *PyObject) Repr() *PyObject

Repr compute a string representation of object o. Returns the string representation on success, NULL on failure. This is the equivalent of the Python expression repr(o). Called by the repr() built-in function.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_Repr

func (*PyObject) ReprEnter

func (pyObject *PyObject) ReprEnter() int

ReprEnter is called at the beginning of the tp_repr implementation to detect cycles.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.Py_ReprEnter

func (*PyObject) ReprLeave

func (pyObject *PyObject) ReprLeave()

ReprLeave ends a PyObject.ReprEnter(). Must be called once for each invocation of Py_ReprEnter() that returns zero.

Reference: https://docs.python.org/3/c-api/exceptions.html#c.Py_ReprLeave

func (*PyObject) RichCompare

func (pyObject *PyObject) RichCompare(o *PyObject, opid int) *PyObject

RichCompare compares 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 Py_GE, corresponding to <, <=, ==, !=, >, or >= respectively. This is the equivalent of the Python expression o1 op o2, where op is the operator corresponding to opid. Returns the value of the comparison on success, or NULL on failure.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_RichCompare

func (*PyObject) RichCompareBool

func (pyObject *PyObject) RichCompareBool(o *PyObject, opid int) int

RichCompareBool compares the values of o1 and o2 using the operation specified by opid, like PyObject_RichCompare(), but returns -1 on error, 0 if the result is false, 1 otherwise.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_RichCompareBool

func (*PyObject) SetAttr

func (pyObject *PyObject) SetAttr(attr_name *PyObject, v *PyObject) int

SetAttr sets the value of the attribute named attr_name, for object o, to the value v. Raise an exception and return -1 on failure; return 0 on success. This is the equivalent of the Python statement o.attr_name = v.

If v is NULL, the attribute is deleted. This behavior is deprecated in favor of using PyObject_DelAttr(), but there are currently no plans to remove it.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_SetAttr

func (*PyObject) SetAttrString

func (pyObject *PyObject) SetAttrString(attr_name string, v *PyObject) int

SetAttrString is the same as PyObject.SetAttr(), but attr_name is specified as a const char* UTF-8 encoded bytes string, rather than a PyObject*.

If v is NULL, the attribute is deleted, but this feature is deprecated in favor of using PyObject.DelAttrString().

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_SetAttrString

func (*PyObject) SetItem

func (pyObject *PyObject) SetItem(key, v *PyObject) int

SetItem maps the object key to the value v. Raise an exception and return -1 on failure; return 0 on success. This is the equivalent of the Python statement o[key] = v. This function does not steal a reference to v.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_SetItem

func (*PyObject) Str

func (pyObject *PyObject) Str() *PyObject

Str computes a string representation of object o. Returns the string representation on success, NULL on failure. This is the equivalent of the Python expression str(o). Called by the str() built-in function and, therefore, by the print() function.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_Str

func (*PyObject) Type

func (pyObject *PyObject) Type() *PyObject

Type returns a type object corresponding to the object type of object o when o is non-NULL. On failure, raises SystemError and returns NULL. This is equivalent to the Python expression type(o). This function creates a new strong reference to the return value. There's really no reason to use this function instead of the Py_TYPE() function, which returns a pointer of type PyTypeObject*, except when a new strong reference is needed.

Reference: https://docs.python.org/3/c-api/object.html#c.PyObject_Type

type PyThreadState

type PyThreadState C.PyThreadState

PyThreadState represents the state of a single thread.

Reference: https://docs.python.org/3/c-api/init.html#c.PyThreadState

func PyEval_SaveThread

func PyEval_SaveThread() *PyThreadState

PyEval_SaveThread releases the global interpreter lock (if it has been created) and reset the thread state to NULL, returning the previous thread state (which is not NULL). If the lock has been created, the current thread must have acquired it.

Reference: https://docs.python.org/3/c-api/init.html#c.PyEval_SaveThread

func PyGILState_GetThisThreadState

func PyGILState_GetThisThreadState() *PyThreadState

PyGILState_GetThisThreadState gets the current thread state for this thread. May return NULL if no GILState API has been used on the current thread. Note that the main thread always has such a thread-state, even if no auto-thread-state call has been made on the main thread. This is mainly a helper/diagnostic function.

Reference: https://docs.python.org/3/c-api/init.html#c.PyGILState_GetThisThreadState

func PyThreadState_Get

func PyThreadState_Get() *PyThreadState

PyThreadState_Get returns the current thread state. The global interpreter lock must be held. When the current thread state is NULL, this issues a fatal error (so that the caller needn't check for NULL).

Reference: https://docs.python.org/3/c-api/init.html#c.PyThreadState_Get

func PyThreadState_Swap

func PyThreadState_Swap(tstate *PyThreadState) *PyThreadState

PyThreadState_Swap swaps the current thread state with the thread state given by the argument tstate, which may be NULL. The global interpreter lock must be held and is not released.

Reference: https://docs.python.org/3/c-api/init.html#c.PyThreadState_Swap

Directories

Path Synopsis
examples
resources

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL