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

BUG: Handle iso_c_type mappings more consistently #25480

Merged
merged 9 commits into from Dec 23, 2023

Conversation

charris
Copy link
Member

@charris charris commented Dec 23, 2023

Backport of #25226.

Closes #25207. This one could use a backport. Needs:

  • Scoping TODOs (can't rewrite the entire cfuncs here)
  • Tests
  • Check that SciPy builds

As discussed below, there were basically two deficiencies:

  • Type maps were not propagated
  • Fortran types (iso_c_binding) were mapped to ignored C types
    • This is the default behavior, but is silent and the maps are done to basic (lowest precision) corresponding types

This PR fixes (pragmatically) both these deficiences, for the first problem, the fix is a simple refactor and cleanup.

The second issue is a little trickier. For now, the pragmatic solution (as done by users anyway) is to map the iso_c_binding kinds to supported f2py types, i.e. to one of:

c2py_map = {'double': 'float',
            'float': 'float',                          # forced casting
            'long_double': 'float',                    # forced casting
            'char': 'int',                             # forced casting
            'signed_char': 'int',                      # forced casting
            'unsigned_char': 'int',                    # forced casting
            'short': 'int',                            # forced casting
            'unsigned_short': 'int',                   # forced casting
            'int': 'int',                              # forced casting
            'long': 'int',
            'long_long': 'long',
            'unsigned': 'int',                         # forced casting
            'complex_float': 'complex',                # forced casting
            'complex_double': 'complex',
            'complex_long_double': 'complex',          # forced casting
            'string': 'string',
            'character': 'bytes',
            }

Pending a more complete overhaul of the generated bindings (tracked in #25229, which @Pranavchiku is also looking into) this is the optimal bugfix for #25207.

@charris charris added this to the 1.26.3 release milestone Dec 23, 2023
@charris charris merged commit 0a39198 into numpy:maintenance/1.26.x Dec 23, 2023
65 of 69 checks passed
@charris charris deleted the backport-25226 branch December 23, 2023 23:05
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