Argument Clinic: how to correctly use pid_t_converter?

Modules/posixmodule.c defines a custom pid_t converter:

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

However, when I copy it into another file (let it be 1.c):

/*[clinic input]

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

[clinic start generated code]*/

, clinic throws an exception:

C:\Users\oleg\Documents\dev\notmine\cpython>python Tools\clinic\clinic.py 1.c
Error in file “1.c” on line 7:
DSLParser.directive_class() missing 2 required positional arguments: ‘typedef’ and ‘type_object’

I’ve got three questions:

  1. What do I need to add/fix to make it accepted by the tool?

  2. How to get a full stack trace (because there must be at least main() and parse_file() in a bottom of the stack)?

  3. How this method is used? There’s no literal directive_class inside CPython codebase:

    C:\Users\oleg\Documents\dev\notmine\cpython>git grep directive_class
    Tools/clinic/clinic.py:    def directive_class(self, name, typedef, type_object):
    

“clinic” is the wrong parser. Use the “python” parser. It captures standard output in a StringIO instance and calls exec() to execute the block.

The “clinic” parser is implemented by DSLParser, which dynamically initializes its self.directives dict using the result of dir(self).

2 Likes

Thank you, the mystery is solved.

The only question left is whether the stack trace moment is a bug or not.