Skip to content

Commit

Permalink
gh-85283: Add PySys_Audit() to the limited C API
Browse files Browse the repository at this point in the history
This function was added in Python 3.8 by the PEP 578 "Python Runtime
Audit Hooks". It is needed to convert some stdlib extensions to the
limited C API, like fcntl, resource and syslog.

Move also non-limited "PerfMap" C API from Include/sysmodule.h to
Include/cpython/sysmodule.h.
  • Loading branch information
vstinner committed Aug 28, 2023
1 parent 4116592 commit ee520a1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions Doc/data/stable_abi.dat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,9 @@ New Features
(with an underscore prefix).
(Contributed by Victor Stinner in :gh:`108014`.)

* Add :c:func:`PySys_Audit` function to the limited C API.
(Contributed by Victor Stinner in :gh:`85283`.)

Porting to Python 3.13
----------------------

Expand Down
15 changes: 11 additions & 4 deletions Include/cpython/sysmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@

typedef int(*Py_AuditHookFunction)(const char *, PyObject *, void *);

PyAPI_FUNC(int) PySys_Audit(
const char *event,
const char *argFormat,
...);
PyAPI_FUNC(int) PySys_AddAuditHook(Py_AuditHookFunction, void*);

typedef struct {
FILE* perf_map;
PyThread_type_lock map_lock;
} PerfMapState;

PyAPI_FUNC(int) PyUnstable_PerfMapState_Init(void);

PyAPI_FUNC(int) PyUnstable_WritePerfMapEntry(const void *code_addr, unsigned int code_size, const char *entry_name);

PyAPI_FUNC(void) PyUnstable_PerfMapState_Fini(void);
16 changes: 4 additions & 12 deletions Include/sysmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,10 @@ Py_DEPRECATED(3.13) PyAPI_FUNC(void) PySys_ResetWarnOptions(void);

PyAPI_FUNC(PyObject *) PySys_GetXOptions(void);

#if !defined(Py_LIMITED_API)
typedef struct {
FILE* perf_map;
PyThread_type_lock map_lock;
} PerfMapState;

PyAPI_FUNC(int) PyUnstable_PerfMapState_Init(void);

PyAPI_FUNC(int) PyUnstable_WritePerfMapEntry(const void *code_addr, unsigned int code_size, const char *entry_name);

PyAPI_FUNC(void) PyUnstable_PerfMapState_Fini(void);
#endif
PyAPI_FUNC(int) PySys_Audit(
const char *event,
const char *argFormat,
...);

#ifndef Py_LIMITED_API
# define Py_CPYTHON_SYSMODULE_H
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add the :c:func:`PySys_Audit` function to the limited C API. Patch by Victor
Stinner.
2 changes: 2 additions & 0 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2452,3 +2452,5 @@
added = '3.13'
[function.PyLong_AsInt]
added = '3.13'
[function.PySys_Audit]
added = '3.13'
1 change: 1 addition & 0 deletions PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee520a1

Please sign in to comment.