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 cd4e215
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
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
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.

0 comments on commit cd4e215

Please sign in to comment.