Skip to content

gh-94808: Cover PyFunction_GetCode, PyFunction_GetGlobals, PyFunction_GetModule - #98158

Merged
JelleZijlstra merged 2 commits into
python:mainfrom
sobolevn:cover-pyfunction-getters
Oct 16, 2022
Merged

JelleZijlstra merged 2 commits into
python:mainfrom
sobolevn:cover-pyfunction-getters

Conversation

@sobolevn

@sobolevn sobolevn commented Oct 10, 2022 •

Copy link
Copy Markdown
Member

In the next PRs I will cover PyFunction_* methods with setters.

Comment thread Modules/_testcapimodule.c
{
PyObject *code = PyFunction_GetCode(func);
if (code != NULL) {
Py_INCREF(code);

@sobolevn sobolevn Oct 10, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this Py_INCREF be here? Shouldn't callee do this? 🤔

Without it I have this error:

test_function_get_module (test.test_capi.CAPITest.test_function_get_module) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

== Tests result: SUCCESS ==

1 test OK.

Total duration: 242 ms
Tests result: SUCCESS
./Include/object.h:625: _Py_NegativeRefcount: Assertion failed: object has negative ref count
<object at 0x1082424d0 is freed>
Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: finalizing (tstate=0x000000010759c6d0)

Current thread 0x000000011215d5c0 (most recent call first):
  <no Python frame>
[1]    92538 abort      ./python.exe -m test -v test_capi -m test_function_get_module

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cc: @markshannon as it pertains to code objects.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct, PyFunction_GetCode is documented as returning a borrowed ref: https://docs.python.org/3/c-api/function.html#c.PyFunction_GetCode

@sobolevn sobolevn added skip news 🔨 test-with-buildbots Test PR w/ buildbots; report in status section labels Oct 10, 2022
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @sobolevn for commit f2ddceb 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 10, 2022
@mdboom mdboom added the needs backport to 3.11 only security fixes label Oct 13, 2022
@JelleZijlstra JelleZijlstra self-assigned this Oct 15, 2022
@JelleZijlstra
JelleZijlstra merged commit 7b48d02 into python:main Oct 16, 2022
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @sobolevn for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @sobolevn and @JelleZijlstra, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 7b48d02933639c91ebd957b2326d8c352d8eddec 3.11

@bedevere-bot

Copy link
Copy Markdown

GH-98317 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Oct 16, 2022
JelleZijlstra pushed a commit to JelleZijlstra/cpython that referenced this pull request Oct 16, 2022
…bals`, `PyFunction_GetModule` (pythonGH-98158).

(cherry picked from commit 7b48d02)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
carljm added a commit to carljm/cpython that referenced this pull request Oct 17, 2022
* main: (31 commits)
  pythongh-95913: Move subinterpreter exper removal to 3.11 WhatsNew (pythonGH-98345)
  pythongh-95914: Add What's New item describing PEP 670 changes (python#98315)
  Remove unused arrange_output_buffer function from zlibmodule.c. (pythonGH-98358)
  pythongh-98174: Handle EPROTOTYPE under macOS in test_sendfile_fallback_close_peer_in_the_middle_of_receiving (python#98316)
  pythonGH-98327: Reduce scope of catch_warnings() in _make_subprocess_transport (python#98333)
  pythongh-93691: Compiler's code-gen passes location around instead of holding it on the global compiler state (pythonGH-98001)
  pythongh-97669: Create Tools/build/ directory (python#97963)
  pythongh-95534: Improve gzip reading speed by 10% (python#97664)
  pythongh-95913: Forward-port int/str security change to 3.11 What's New in main (python#98344)
  pythonGH-91415: Mention alphabetical sort ordering in the Sorting HOWTO (pythonGH-98336)
  pythongh-97930: Merge with importlib_resources 5.9 (pythonGH-97929)
  pythongh-85525: Remove extra row in doc (python#98337)
  pythongh-85299: Add note warning about entry point guard for asyncio example (python#93457)
  pythongh-97527: IDLE - fix buggy macosx patch (python#98313)
  pythongh-98307: Add docstring and documentation for SysLogHandler.createSocket (pythonGH-98319)
  pythongh-94808: Cover `PyFunction_GetCode`, `PyFunction_GetGlobals`, `PyFunction_GetModule` (python#98158)
  pythonGH-94597: Deprecate child watcher getters and setters (python#98215)
  pythongh-98254: Include stdlib module names in error messages for NameErrors (python#98255)
  Improve speed. Reduce auxiliary memory to 16.6% of the main array. (pythonGH-98294)
  [doc] Update logging cookbook with an example of custom handling of levels. (pythonGH-98290)
  ...
JelleZijlstra added a commit that referenced this pull request Oct 19, 2022
#98317)

[3.11] gh-94808: Cover `PyFunction_GetCode`, `PyFunction_GetGlobals`, `PyFunction_GetModule` (GH-98158).
(cherry picked from commit 7b48d02)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants