FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-108494: Fix AC limited C API for kwargs by vstinner · Pull Request #108516 · python/cpython · GitHub

Repository navigation

gh-108494: Fix AC limited C API for kwargs - #108516

Closed
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:clinic_limited_kwds
Closed

vstinner wants to merge 1 commit into
python:mainfrom
vstinner:clinic_limited_kwds

Conversation

vstinner commented Aug 26, 2023 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

Fix the limited C API code path in Argument Clinic to parse "positional or keywords" arguments.

Add an unit test in _testclinic_limited.

Fix the limited C API code path in Argument Clinic to parse
"positional or keywords" arguments.

Add an unit test in _testclinic_limited.

Copy link
Copy Markdown
Member Author

@erlend-aasland @AlexWaygood @serhiy-storchaka: Here is a fix for PyArg_ParseTupleAndKeywords(). It removes the unused argname_fmt in the PyArg_ParseTuple() code path.

Comment thread Tools/clinic/clinic.py
""", indent=4)]
declarations = ""

else:

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Does it work if requires_defining_class is true?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No, it doesn't. This change is incomplete, it can be completed later. Or do you mean that an exception should be raised instead of an compilation error?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Currently it can produce invalid code which is compiled. There are two opposite approaches:

  1. Raise an exception or ensure that the compiling the generated code will get a compilation error.
  2. Try to use the limited API if possible, but fallback to private API otherwise.

I am currently trying the second approach. It allows to re-generate all clinic code using the limited API and test that at least it works (I found many cases in which the current code does not generate working code). Please hold this PR, the current code is more suitable for this experiment. After testing it will be easy to switch to the first approach.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

A module targeting the limited C API cannot use the private API. It fails at build.

Comment thread Tools/clinic/clinic.py
# positional-only for the limited C API
flags = "METH_VARARGS"
elif clinic.limited_capi:
if not requires_defining_class and pos_only == len(parameters) - pseudo_args:

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Does it work if pseudo_args is not zero?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I have no idea. I don't know what are pseudo args.

Comment thread Tools/clinic/clinic.py
{parse_arguments}))
goto exit;
""", indent=4)]
declarations = "char* _keywords[] = {{{keywords_c} NULL}};"

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
declarations = "char* _keywords[] = {{{keywords_c} NULL}};"
declarations = "static char *_keywords[] = {{{keywords_c} NULL}};"

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't reallly understand the difference between the two. The value is constant so the variable should not really exist on the stack, no?

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There is a difference. It is an array of pointers. If it is a local variable, it should fill with initial values every time the function is called. If it is a static variable, it is only filled with initial values at the program's start (or when the function is called first time).

Copy link
Copy Markdown
Member

See #108536.

Copy link
Copy Markdown
Member Author

Does your PR make this one useless, or should it be merged first?

Copy link
Copy Markdown
Member

I think that it makes it useless, maybe except the test. But for testing I want to reuse existing tests, so the current Modules/_testclinic_limited.c will become obsolete too.

Copy link
Copy Markdown
Member Author

Serhiy's PR got merged and it's way more complete, I close this PR: #108536

vstinner closed this Aug 28, 2023
vstinner deleted the clinic_limited_kwds branch August 28, 2023 14:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL