Notice: While JavaScript is not essential for this website, your interaction with the content will be limited. Please turn JavaScript on for the full experience.
...definitions of it on the same platform (depending on whether it uses narrow or wide code units). Applications that need to access the contents of a Unicode string can convert it to wchar_t. Functions and function-like Macros By default, all functions are available, unless they are excluded below. Whether a function is documented or not does not matter. Function-like macros (in particular, field access macros) remain available to applications, but get replaced by function calls (unless their de...
...macros.STMT_MACRO A statement macro where the body of the macro is indented. This is the only form allowed to have additional names. macros.SIBLING_MACRO A statement macro where the body of the macro is the next statement is the same block. The following statement is moved into the macro as its body. macros.EXPR_MACRO An expression macro. version is used to track versions of macros, so that generated bytecodes can be correctly cached. It must be an integer. additional_names are the names of th...
...macro), will be annotated as such. For items that are only available on some systems, the manifest will record the feature macro that determines their presence (such as MS_WINDOWS or HAVE_FORK). To make the implementation (and usage from non-C languages) easier, all such macros will be simple names. If a future item needs a “negative” macro or complex expression (such as a hypothetical #ifndef MACOSX or #if defined(POSIX) && !defined(LINUX)), a new feature macro will be derived. The form...
...definitions, and major sections inside functions. Comments go before the code they describe. All functions and global variables should be declared static unless they are to be part of a published interface For external functions and variables, we always have a declaration in an appropriate header file in the "Include" directory, which uses the PyAPI_FUNC() macro and PyAPI_DATA() macro, like this: PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *); PyAPI_DATA(PyTypeObject) PySuper_Type; N...
...definitions of PyObject_HEAD are normative, so extension authors MAY either use the macro, or put the ob_base field explicitly into their structs. As a convention, the base field SHOULD be called ob_base. However, all accesses to ob_refcnt and ob_type MUST cast the object pointer to PyObject* (unless the pointer is already known to have that type), and SHOULD use the respective accessor macros. To simplify access to ob_type, ob_refcnt, and ob_size, macros: #define Py_TYPE(o) (((PyObject*)(o)...
...Definition Language (ASDL) [Wang97]. The definition of the AST nodes for Python is found in the file Parser/Python.asdl . Each AST node (representing statements, expressions, and several specialized types, like list comprehensions and exception handlers) is defined by the ASDL. Most definitions in the AST correspond to a particular source construct, such as an 'if' statement or an attribute lookup. The definition is independent of its realization in any particular programming language. The fol...
...macros), so you write, effectively try(computation(), catch(MyException, explanation, default(explanation))) try(computation(), catch(MyException, explanation, default(explanation)), catch(MyOtherException, explanation, other_default(explanation))) In Common Lisp, this is done with a slightly clunkier "handler-case" macro, but the basic idea is the same. The Lisp style is, surprisingly, used by some languages that don't have macros, like Lua, where xpcall takes functions. Writing lamb...
...macro: if (PyType_HasFeature(x->ob_type, Py_TPFLAGS_HAVE_INPLACE_OPS) && x->ob_type->tp_as_number && x->ob_type->tp_as_number->nb_inplace_add) { /* ... */ This check must be made even before testing the method slots for NULL values! The macro only tests whether the slots are available, not whether they are filled with methods or not. Implementation The current implementation of augmented assignment [2] adds, in addition to the methods and slots ...
...definition of NULL in C source code; all definitions were removed and add #error to Python.h if NULL isn't defined after #include of stdio.h. Py_PROTO() macros that were removed in 2.0b1 have been restored for backwards compatibility (at the source level) with old extensions. A wrapper API was added for signal() and sigaction(). Instead of either function, always use PyOS_getsig() to get a signal handler and PyOS_setsig() to set one. A new convenience typedef PyOS_sigha...
...macro (like PyDict_Check()), this macro should be made to recognize subtypes. This can be done by using the new PyObject_TypeCheck(object, type) macro, which calls a function that follows the base class links. The PyObject_TypeCheck() macro contains a slight optimization: it first compares object->ob_type directly to the type argument, and if this is a match, bypasses the function call. This should make it fast enough for most situations. Note that this change in the type-checking macro mea...
...macro. It works as-is when the platform C computes true for x != x if and only if X is a NaN. Other platforms can override the default definition with a platform- specific spelling in that platform's pyconfig.h. You can also override pyport.h's default Py_IS_INFINITY definition now. C API SF patch 1044089: New function PyEval_ThreadsInitialized() returns non-zero if PyEval_InitThreads() has been called. The undocumented and unused extern int _PyThread_Started was removed. The C API calls ...
...macro implementing the module creation phase will be added. These are similar to PyModule_Create and PyModule_Create2, except they take an additional ModuleSpec argument, and handle module definitions with non-NULL slots: PyObject * PyModule_FromDefAndSpec(PyModuleDef *def, PyObject *spec) PyObject * PyModule_FromDefAndSpec2(PyModuleDef *def, PyObject *spec, int module_api_version) A new function implementing the module execution phase will be added. This al...
...MacroPy: MacroPy is an implementation of Syntactic Macros in the Python Programming Language. MacroPy provides a mechanism for user-defined functions (macros) to perform transformations on the abstract syntax tree (AST) of a Python program at import time. pypreprocessor: C-style preprocessor directives in Python, like #define and #ifdef Bytecode transformers codetransformer: Bytecode transformers for CPython inspired by the ast module’s NodeTransformer. byteplay: Byteplay lets you convert Py...
...definition autoconf hash function selection Python API addition sys module Necessary modifications to C code _Py_HashBytes() (Objects/object.c) bytes_hash() (Objects/bytesobject.c) memory_hash() (Objects/memoryobject.c) unicode_hash() (Objects/unicodeobject.c) generic_hash() (Modules/_datetimemodule.c) Performance Hash value distribution Typical length Grand Unified Python Benchmark Suite Backwards Compatibility Alternative counter measures against hash collision DoS Discussion Pluggable...
...definition is executed, and even if the namespace has been manipulated to return a different object, at worst an exception will be raised. The __class__ closure, (2), is a safer way to get the defining class, but it still relies on __closure__ being set appropriately. By contrast, extension methods are typically implemented as normal C functions. This means that they only have access to their arguments and C level thread-local and process-global states. Traditionally, many extension modules have...
...definition in the nearest enclosing function scope will be used. One consequence of this change is that lambda statements could reference variables in the namespaces where the lambda is defined. In some unusual cases, this change will break code. In all previous version of Python, names were resolved in exactly three namespaces -- the local namespace, the global namespace, and the builtin namespace. According to this old definition, if a function A is defined within a function B, the names bo...
...macros or some other kind of preprocessor or whatever, and imported from a module, rather than requiring major hacking in the parser, the bytecode compiler, and the virtual machine. PEP 275 - Switching on Multiple Values - Lemburg I'm still not convinced that we need a switch statement, and the proposed syntax has problems: e.g. why only constants? why not allow ranges? In addition, it proposes many different alternatives without picking one. The first alternative proposed by th...
...definition of which may depend on the underlying TLS implementation. It is defined: typedef struct { int _is_initialized; NATIVE_TSS_KEY_T _key; } Py_tss_t; where NATIVE_TSS_KEY_T is a macro whose value depends on the underlying native TLS implementation (e.g. pthread_key_t). An initializer for Py_tss_t variables, Py_tss_NEEDS_INIT. Three new functions: PyAPI_FUNC(Py_tss_t *) PyThread_tss_alloc(void) PyAPI_FUNC(void) PyThread_tss_free(Py_tss_t *key) PyAPI_FUNC(int) PyThread_tss_is_...
...definitions are called 'statement templates'. The above is the main point of the PEP. However, if that was all it said, then PEP 310 would be sufficient and this PEP would be essentially redundant. Instead, this PEP recommends additional enhancements that make it natural to write these statement templates using appropriately decorated generators. A side effect of those enhancements is that it becomes important to appropriately deal with the management of resources inside generators. This is qu...