Skip to content

clinic: add option to pass module object to converter function #86570

Description

@tiran
BPO 42404
Nosy @vstinner, @larryhastings, @tiran, @corona10

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-11-19.11:40:44.395>
labels = ['type-feature', 'expert-argument-clinic', '3.10']
title = 'clinic: add option to pass module object to converter function'
updated_at = <Date 2020-11-19.11:40:44.395>
user = 'https://github.com/tiran'

bugs.python.org fields:

activity = <Date 2020-11-19.11:40:44.395>
actor = 'christian.heimes'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Argument Clinic']
creation = <Date 2020-11-19.11:40:44.395>
creator = 'christian.heimes'
dependencies = []
files = []
hgrepos = []
issue_num = 42404
keywords = []
message_count = 1.0
messages = ['381406']
nosy_count = 4.0
nosy_names = ['vstinner', 'larry', 'christian.heimes', 'corona10']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue42404'
versions = ['Python 3.10']

Activity

  1. tiran commented on Nov 19, 2020

    @tiran
    MemberAuthor

    Sometimes the converter function for CConverter must access the current module object in order to access the current module state. Currently CConverter subclasses have no easy way to pass the module to the converter function. It would be fantastic if easier CConverter would get an option to pass the module.

    Example:

    #23398 converts the struct module to multiphase initialization. The struct module has a converter for cached struct definitions. The cache used to be a module level object. It is now an interpreter scoped object. I used a custom parse_arg() function to pass the module object:

    class cache_struct_converter(CConverter):
        type = 'PyStructObject *'
        converter = 'cache_struct_converter'
        c_default = "NULL"
        def parse_arg(self, argname, displayname):
            return """
                if (!{converter}(module, {argname}, &{paramname})) {{{{
                    goto exit;
                }}}}
                """.format(argname=argname, paramname=self.name,
                           converter=self.converter)
        def cleanup(self):
            return "Py_XDECREF(%s);\n" % self.name
  2. transferred this issue fromon Apr 10, 2022
  3. added
    3.13only security fixes
    and removed on Jan 4, 2024
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