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.
...Pointer(void* ptr, LONG_LONG len, int readonly void (*dest)(void *ptr, void *user), void* user); In the PyBytes_FromPointer(...) function, if the dest function pointer is passed in as NULL, it will not be called. This should only be used for creating bytes objects from statically allocated space. The user pointer has been called a closure in other places. It is a pointer that the user can use for whatever purposes. It will be passed to the destructor function on cleanup and can be u...
...definitions, a script to convert C source code containing type definitions will be provided [3]. References [1](1, 2) "python3 module definition file": http://svn.python.org/projects/python/branches/pep-0384/PC/python3.def [2]"PEP 384 branch": http://svn.python.org/projects/python/branches/pep-0384/ [3]"ABI type conversion script": http://svn.python.org/projects/python/branches/pep-0384/Tools/scripts/abitype.py Copyright This document has been placed in the public domain. So...
...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)...
...pointer, a setter C function pointer, and a context pointer. The function pointers are optional, so that for example setting the setter function pointer to NULL makes a read-only attribute. The context pointer is intended to pass auxiliary information to generic getter/setter functions, but I haven't found a need for this yet. Note that there is also a similar mechanism to declare built-in methods: these are PyMethodDef structures, which contain a name and a C function pointer (and some flags ...
...pointers to functions to implement various kinds of behaviors. A NULL pointer means that the type does not implement the specific behavior; in that case the system may provide a default behavior or raise an exception when the behavior is invoked for an instance of the type. Some collections of function pointers that are usually defined together are obtained indirectly via a pointer to an additional structure containing more function pointers. While the details of initializing a PyTypeObject st...
...definition 'raw-unicode-escape': See Unicode Constructors for a definition 'native': Dump of the Internal Format used by Python Common aliases should also be provided per default, e.g. 'latin-1' for 'iso-8859-1'. Note: 'utf-16' should be implemented by using and requiring byte order marks (BOM) for file input/output. All other encodings such as the CJK ones to support Asian scripts should be implemented in separate packages which do not get included in the core Python distribution a...
...pointer to the state of the module that the heap type belongs to. On failure, two scenarios may occur. When a non-type object, or a type without a module is passed in, TypeError is set and NULL returned. If the module is found, the pointer to the state, which may be NULL, is returned without setting any exception. Modules Converted in the Initial Implementation To validate the approach, the _elementtree module will be modified during the initial implementation. Summary of API Changes and Ad...
...pointer to void* (a data pointer) or vice versa. Make sure the new API follows reference counting conventions. (Following them makes the API easier to reason about, and easier use in other Python implementations.) Do not return borrowed references from functions. Do not steal references to function arguments. Make sure the ownership rules and lifetimes of all applicable struct fields, arguments and return values are well defined. Think about ease of use for the user. (In C, ease of use its...
...pointer to a PyModuleDef object. The import machinery will be in charge of constructing the module object, calling hooks provided in the PyModuleDef in the relevant phases of initialization (as described below). This multi-phase initialization is an additional possibility. Single-phase initialization, the current practice of returning a fully initialized module object, will still be accepted, so existing code will work unchanged, including binary compatibility. The PyModuleDef structure will be ...
...definition. There are three cooperating parts to the proposed mechanism: the use of the last slot in the type object structure to store a pointer to a rich comparison function the addition of special methods for classes the addition of an optional argument to the builtin cmp() function. Motivation The current comparison protocol for Python objects assumes that any two Python objects can be compared (as of Python 1.5, object comparisons can raise exceptions), and that the return value for any...
...pointers to classes (including exceptions, but excluding static types) and settings (e.g. csv's field_size_limit) which the C code needs to function. Note Another option is to store state in the module's __dict__, but you must avoid crashing when users modify __dict__ from Python code. This means error- and type-checking at the C level, which is easy to get wrong and hard to test sufficiently. If the module state includes PyObject pointers, the module object must hold references to those objec...
...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...
...pointer to the previous (outer) assignment like in a linked list. The local state (also returned by contextvars.get_local_state()) then consists of a reference to the top of the stack and a pointer/weak reference to the bottom of the stack. This allows efficient stack manipulations. An object produced by contextvars.capture() is similar, but refers to only a part of the stack with the bottom reference pointing to the top of the stack as it was in the beginning of the capture block. Now, the stac...
...definition and saved. This proposal introduces a new form of argument default, defined by an expression to be evaluated at function call time. Motivation Optional function arguments, if omitted, often have some sort of logical default value. When this value depends on other arguments, or needs to be reevaluated each function call, there is currently no clean way to state this in the function header. Currently-legal idioms for this include: # Very common: Use None and replace it in the functio...
...definition Implementation: typedef struct { /* function pointer to hash function, e.g. fnv or siphash24 */ Py_hash_t (*const hash)(const void *, Py_ssize_t); const char *name; /* name of the hash algorithm and variant */ const int hash_bits; /* internal size of hash value */ const int seed_bits; /* size of seed input */ } PyHash_FuncDef; PyAPI_FUNC(PyHash_FuncDef*) PyHash_GetFuncDef(void); autoconf A new test is added to the configure script. The test sets HA...
...definitions or the initializer structure changed. What I really wanted was code that would analyze the shape and members of the initializer, query the class definitions themselves about their members, and then adjust itself to impedance-match the two sets. This kind of thing is called metaclass hacking and is generally considered fearsomely esoteric -- deep black magic. Most object-oriented languages don't support it at all; in those that do (Perl being one), it tends to be a complicated and fra...
...pointer to a PyConfigAsObjects struct (which may be a temporary one stored on the C stack). For any already configured value (i.e. any non-NULL pointer), CPython will sanity check the supplied value, but otherwise accept it as correct. A struct is used rather than a Python dictionary as the struct is easier to work with from C, the list of supported fields is fixed for a given CPython version and only a read-only view needs to be exposed to Python code (which is relatively straightforward, thank...
...definitions of PyModule_AddStringConstant and PyModule_AddObject if the Python version is less than 2.0, which provides compatibility with PyXML on Python 1.5.2. If the platform has a bogus definition for LONG_BIT (the number of bits in a long), an error will be reported at compile time. Fix bugs in _PyTuple_Resize() which caused hard-to-interpret garbage collection crashes and possibly other, unreported crashes. Fixed a memory leak in _PyUnicode_Fini(). Build issues ...
...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...
...pointers to process handles, and calls a dict access function during popen.close(). But .close releases threads, which left the internal popen code accessing the dict without a valid thread state. The dict implementation changed so that's no longer accepted. Fixed by creating a temporary thread state in the guts of popen's close routine, and grabbing the global lock with it for the duration] [20-Aug-2000 tim changed the popen2.py _test function to use th...