Skip to content

bpo-38644: Add _PySys_Audit() which takes tstate #19180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 26, 2020
Merged

bpo-38644: Add _PySys_Audit() which takes tstate #19180

merged 2 commits into from
Mar 26, 2020

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Mar 26, 2020

Add _PySys_Audit() function to the internal C API: similar to
PySys_Audit(), but requires a mandatory tstate parameter.

Cleanup sys_audit_tstate() code: remove code path for NULL tstate,
since the function exits at entry if tstate is NULL. Remove also code
path for NULL tstate->interp: should_audit() now ensures that it is
not NULL (even if tstate->interp cannot be NULL in practice).

PySys_AddAuditHook() now checks if tstate is not NULL to decide if
tstate can be used or not, and tstate is set to NULL if the runtime
is not initialized yet.

Use _PySys_Audit() in sysmodule.c.

https://bugs.python.org/issue38644

Add _PySys_Audit() function to the internal C API: similar to
PySys_Audit(), but requires a mandatory tstate parameter.

Cleanup sys_audit_tstate() code: remove code path for NULL tstate,
since the function exits at entry if tstate is NULL. Remove also code
path for NULL tstate->interp: should_audit() now ensures that it is
not NULL (even if tstate->interp cannot be NULL in practice).

PySys_AddAuditHook() now checks if tstate is not NULL to decide if
tstate can be used or not, and tstate is set to NULL if the runtime
is not initialized yet.

Use _PySys_Audit() in sysmodule.c.
@vstinner
Copy link
Member Author

Adding extern void _PySys_ClearAuditHooks(PyThreadState *tstate); to Include/internal/pycore_sysmodule.h doesn't export the symbol. Python is now built using -fvisibility=hidden compiler flag which is supported by GCC and clang. Symbols which are not exported explicitly are hidden by default. If the compiler doesn't support -fvisibility=hidden, _PySys_ClearAuditHooks() should not be exported neither. At least, I don't expect my change to change anything.

I prefer to add the function definition in a header file to ensure that tstate parameter is passed properly (as a pointer, not as an int).

@vstinner
Copy link
Member Author

cc @zooba

@vstinner vstinner merged commit 08faf00 into python:master Mar 26, 2020
@vstinner vstinner deleted the sys_audit_tstate branch March 26, 2020 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants