mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 11:37:35 +00:00
b420ed8248
This change gets the Python codebase into a state where it conforms to the conventions of this codebase. It's now possible to include headers from Python, without worrying about ordering. Python has traditionally solved that problem by "diamonding" everything in Python.h, but that's problematic since it means any change to any Python header invalidates all the build artifacts. Lastly it makes tooling not work. Since it is hard to explain to Emacs when I press C-c C-h to add an import line it shouldn't add the header that actually defines the symbol, and instead do follow the nonstandard Python convention. Progress has been made on letting Python load source code from the zip executable structure via the standard C library APIs. System calss now recognizes zip!FILENAME alternative URIs as equivalent to zip:FILENAME since Python uses colon as its delimiter. Some progress has been made on embedding the notice license terms into the Python object code. This is easier said than done since Python has an extremely complicated ownership story. - Some termios APIs have been added - Implement rewinddir() dirstream API - GetCpuCount() API added to Cosmopolitan Libc - More bugs in Cosmopolitan Libc have been fixed - zipobj.com now has flags for mangling the path - Fixed bug a priori with sendfile() on certain BSDs - Polyfill F_DUPFD and F_DUPFD_CLOEXEC across platforms - FIOCLEX / FIONCLEX now polyfilled for fast O_CLOEXEC changes - APE now supports a hybrid solution to no-self-modify for builds - Many BSD-only magnums added, e.g. O_SEARCH, O_SHLOCK, SF_NODISKIO
57 lines
2.5 KiB
C
57 lines
2.5 KiB
C
#ifndef Py_LIMITED_API
|
|
#ifndef Py_PYARENA_H
|
|
#define Py_PYARENA_H
|
|
#include "third_party/python/Include/object.h"
|
|
COSMOPOLITAN_C_START_
|
|
/* clang-format off */
|
|
|
|
typedef struct _arena PyArena;
|
|
|
|
/* PyArena_New() and PyArena_Free() create a new arena and free it,
|
|
respectively. Once an arena has been created, it can be used
|
|
to allocate memory via PyArena_Malloc(). Pointers to PyObject can
|
|
also be registered with the arena via PyArena_AddPyObject(), and the
|
|
arena will ensure that the PyObjects stay alive at least until
|
|
PyArena_Free() is called. When an arena is freed, all the memory it
|
|
allocated is freed, the arena releases internal references to registered
|
|
PyObject*, and none of its pointers are valid.
|
|
XXX (tim) What does "none of its pointers are valid" mean? Does it
|
|
XXX mean that pointers previously obtained via PyArena_Malloc() are
|
|
XXX no longer valid? (That's clearly true, but not sure that's what
|
|
XXX the text is trying to say.)
|
|
|
|
PyArena_New() returns an arena pointer. On error, it
|
|
returns a negative number and sets an exception.
|
|
XXX (tim): Not true. On error, PyArena_New() actually returns NULL,
|
|
XXX and looks like it may or may not set an exception (e.g., if the
|
|
XXX internal PyList_New(0) returns NULL, PyArena_New() passes that on
|
|
XXX and an exception is set; OTOH, if the internal
|
|
XXX block_new(DEFAULT_BLOCK_SIZE) returns NULL, that's passed on but
|
|
XXX an exception is not set in that case).
|
|
*/
|
|
PyArena * PyArena_New(void);
|
|
void PyArena_Free(PyArena *);
|
|
|
|
/* Mostly like malloc(), return the address of a block of memory spanning
|
|
* `size` bytes, or return NULL (without setting an exception) if enough
|
|
* new memory can't be obtained. Unlike malloc(0), PyArena_Malloc() with
|
|
* size=0 does not guarantee to return a unique pointer (the pointer
|
|
* returned may equal one or more other pointers obtained from
|
|
* PyArena_Malloc()).
|
|
* Note that pointers obtained via PyArena_Malloc() must never be passed to
|
|
* the system free() or realloc(), or to any of Python's similar memory-
|
|
* management functions. PyArena_Malloc()-obtained pointers remain valid
|
|
* until PyArena_Free(ar) is called, at which point all pointers obtained
|
|
* from the arena `ar` become invalid simultaneously.
|
|
*/
|
|
void * PyArena_Malloc(PyArena *, size_t size);
|
|
|
|
/* This routine isn't a proper arena allocation routine. It takes
|
|
* a PyObject* and records it so that it can be DECREFed when the
|
|
* arena is freed.
|
|
*/
|
|
int PyArena_AddPyObject(PyArena *, PyObject *);
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* !Py_PYARENA_H */
|
|
#endif /* Py_LIMITED_API */
|