Skip to content

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

Description

@arhadthedev

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions