Skip to content
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

gh-116646: Remove _PyLong_FileDescriptor_Converter() #116736

Closed
wants to merge 1 commit into from

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Mar 13, 2024

Argument Clinic now calls directly PyObject_AsFileDescriptor() for the "fildes" format.

Add tests on the "fildes" format in _testclinic_limited.

Argument Clinic now calls directly PyObject_AsFileDescriptor() for
the "fildes" format.

Add tests on the "fildes" format in _testclinic_limited.
@vstinner
Copy link
Member Author

This change makes the "fildes" format compatible with the limited C API.

I don't think that anyone used _PyLong_FileDescriptor_Converter(), since only Argument Clinic generated code using it. See my code search: #116646 (comment)

@vstinner
Copy link
Member Author

@erlend-aasland: Would you mind to review this PR?

@vstinner
Copy link
Member Author

See also PR #116753

@serhiy-storchaka
Copy link
Member

The converter is used if for some reasons the parsing code cannot be inlined and the PyArg_Parse* API is used. It includes the --limited option. So while _PyLong_FileDescriptor_Converter is not in the limited C API, it can be used when Argument Clinic generates the code for the limited C API. Even if it is not the case for current code, it may be necessary with other combinations of function calling options and parameter types.

@vstinner
Copy link
Member Author

cc @serhiy-storchaka

@vstinner
Copy link
Member Author

cc @serhiy-storchaka

Oops, I sent a ping, and just after posting it, I saw that you already replied!

@serhiy-storchaka:

The converter is used if for some reasons the parsing code cannot be inlined and the PyArg_Parse* API is used. It includes the --limited option.

I didn't know that. Do you have examples of cases when AC cannot inline code?

Maybe we should treat these cases as "not implemented" and issue an error, rather than always having to maintain two code paths to parse arguments. It's always possible to workaround these "not supported" cases by declaring all arguments as "object" and parse arguments inside the function.

@vstinner
Copy link
Member Author

Apparently, my PR doesn't work as expected. I wrote a simpler PR: #116769

@vstinner vstinner closed this Mar 13, 2024
@vstinner vstinner deleted the clinic_fd branch March 13, 2024 22:04
@serhiy-storchaka
Copy link
Member

The principle is that inlining the parsing code and using faster calling conventions is an optimization, and that Argument Clinic should work independently from optimization. In worst case it should produce less optimal code, but not fail.

Do you have examples of cases when AC cannot inline code?

  • The converter for which parse_arg() was not implemented. For example HANDLE in _winapi.c or pid_t in posixmodule.c.
  • Optional groups. Many functions in _cursesmodule.c, but not only.
  • If Py_LIMITED_API is defined.

@vstinner
Copy link
Member Author

The converter for which parse_arg() was not implemented. For example HANDLE in _winapi.c or pid_t in posixmodule.c.

Ok, I see. Maybe we can add support for these types directly to AC.

Optional groups. Many functions in _cursesmodule.c, but not only.

That's a corner case. I don't think that we should support any type in optional groups.

If Py_LIMITED_API is defined.

We may try to write a limited C API implementation. But ok, now I understand better the problem.

Thanks a lot for your explanation!


For now, I wrote a way simpler PR which avoids these issues: PR gh-116769.

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.

None yet

2 participants