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

Fix forced arg format in AC-processed modules with custom converters #94512

Open
5 of 7 tasks
arhadthedev opened this issue Jul 2, 2022 · 0 comments
Open
5 of 7 tasks
Labels
topic-argument-clinic type-feature A feature request or enhancement

Comments

@arhadthedev
Copy link
Member

arhadthedev commented Jul 2, 2022

There are custom Argument Clinic converters that define format_unit but omit parse_arg. As a result, generation of positional argument parsers is forced to back up from the fastest possible _PyArg_CheckPositional to slower _PyArg_ParseStack-based format strings.

Here is a list of such classes (and fixing PRs except complex cases):

An example of such a converter:

class BOOL_converter(CConverter):
    type = 'BOOL'
    format_unit = 'i'

class pid_t_converter(CConverter):
    type = 'pid_t'
    format_unit = '" _Py_PARSE_PID "'

I'm going to teach all of them about low-level generation by replacing manual format_unit definitions with:

  • inheritance from a corresponding builtin converter where possible
  • and custom parse_args in other places.

For the example it gives:

class BOOL_converter(int_converter):
    type = 'BOOL'

class pid_t_converter(CConverter):
    type = 'pid_t'
    # Left as a backup for potential complex cases
    format_unit = '" _Py_PARSE_PID "'

    def parse_arg(self, argname, displayname):
        return """
            {paramname} = PyLong_AsPid({argname});
            if ({paramname} == -1 && PyErr_Occurred()) {{{{
                goto exit;
            }}}}
            """.format(argname=argname, paramname=self.parser_name)

Linked PRs

@arhadthedev arhadthedev added the type-feature A feature request or enhancement label Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-argument-clinic type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants