Skip to content

Probe target compiler for opaque handle size - #379

Open
krystophny wants to merge 3 commits into
jameskermode:masterfrom
krystophny:fix-issue-378-flang-handle-size
Open

Probe target compiler for opaque handle size#379
krystophny wants to merge 3 commits into
jameskermode:masterfrom
krystophny:fix-issue-378-flang-handle-size

Conversation

@krystophny

@krystophny krystophny commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • probe opaque derived-type handle size with --fortran-compiler, F90WRAP_FC, F90, or FC
  • allow --sizeof-fortran-t for cross-compilers whose probe executable cannot run locally
  • use one integer(c_int) element count in generated Fortran, Direct-C arrays, and generated Python array access
  • add a Flang MRE and compiler-probe regression tests

The handle remains an opaque, byte-preserving container. The change does not interpret descriptor data or alter object ownership and lifetime.

This PR is stacked on #377 so its test fixture and manylinux_2_28 wheel fix are present. Once #377 merges, the remaining functional change is the issue #378 fix.

Fixes #378.

Verification

Test fails on main

$ f90wrap --direct-c -m example example.f90
$ flang-new -c example.f90 -o example.o
$ flang-new -c f90wrap_example.f90 -o f90wrap_example.o
error: Semantic errors in f90wrap_example.f90
./f90wrap_example.f90:44:5: error: Dimension 1 of left-hand side has extent 4, but right-hand side has extent 10
      this = transfer(this_ptr, this)
      ^^^^

Test passes after fix

$ make -C examples/issue378_flang_handle_size clean test F90=flang-new
flang-new -fPIC -c example.f90 -o example.o
flang-new -fPIC -c f90wrap_example.f90 -o f90wrap_example.o

The gfortran MRE also passes.

Regression suite

$ python -m pytest -q test/test_directc.py test/test_pywrapgen.py test/test_sizeof_fortran.py
36 passed in 0.26s

Wheel build, isolated installation, compiled-extension import, and both Meson example entries pass. --build --fortran-compiler flang-new produces objects identified as LLVM Flang 22.1.6.

RABE with Flang

Validated against RABE PR #76 with f90wrap built by gfortran and wrappers built by Flang:

[230/230] Linking Fortran shared module python/_rabe...so
100% tests passed, 0 tests failed out of 32
handle_len 10
b_mod 1.01
covariant (0.0, 8.0)

test_parser.py and test_transform.py reference test/samples/DNAD.fpp,
which was never committed because .gitignore excludes *.fpp globally,
so both test_parse_dnad cases fail with FileNotFoundError on a clean
checkout. Un-ignore .fpp files under test/samples and add the sample
from the DNAD project (github.com/joddlehod/dnad, dnad.F90), whose
structure matches the assertions in both tests.
numpy 2.5 ships only manylinux_2_28 wheels, so the cp312 and cp313
Linux wheel builds fall back to compiling numpy from source inside the
default manylinux2014 container, where gcc 10.2.1 fails numpy's
'requires GCC >= 10.3' check. Build in the manylinux_2_28 image, whose
toolchain is new enough and where numpy wheels install directly.
@krystophny
krystophny force-pushed the fix-issue-378-flang-handle-size branch from 6f396c0 to 321a206 Compare July 10, 2026 14:17
@GeorgGrassler

Copy link
Copy Markdown

@krystophny out of interest: this is a targeted fix of the --direct-c functionality, right? Or does it also affect the classic mode?

@krystophny

Copy link
Copy Markdown
Contributor Author

It affects both modes. The handle size is resolved before the --direct-c branch and is passed into the classic Fortran-wrapper transformation/generator and the generated Python array-access code. In Direct-C mode, the same value additionally sizes the generated C handle buffers. So issue #378 exposed it with flang/Direct-C, but the fix also prevents classic wrappers from using a handle size derived from a different compiler. (If no target compiler or explicit size is supplied, it still falls back to the installed f90wrap value.)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--direct-c: hardcoded handle_size = 4 breaks under LLVM flang (TRANSFER size mismatch)

2 participants