Skip to content

Fix getter/setter for polymorphic module-level variables - #376

Open
krystophny wants to merge 2 commits into
jameskermode:masterfrom
krystophny:fix-issue-374-polymorphic-global
Open

Fix getter/setter for polymorphic module-level variables#376
krystophny wants to merge 2 commits into
jameskermode:masterfrom
krystophny:fix-issue-374-polymorphic-global

Conversation

@krystophny

Copy link
Copy Markdown
Contributor

Fixes #374.

For module-level variables of class types (derived types with type-bound procedures), the generated getter/setter pointed the *_ptr_type payload directly at the module variable. For class types the payload is a *_wrapper_type holding a class pointer, so the generated wrapper failed to compile. Route module-level access through the wrapper obj pointer, matching the existing code path for class-typed components of derived types. The handle encoding for class-typed values is now ptr_type -> wrapper_type -> obj everywhere, consistent with the method-call convention; the new example verifies this by calling a type-bound method on the retrieved global.

Adds examples/issue374_polymorphic_global with the reproducer from the issue: get/set of both a plain derived-type global and a polymorphic one, plus a method call on the retrieved global.

Verification

Test fails on main

$ cd examples/issue374_polymorphic_global && make test
  195 |     global_testclass_ptr%p => main_global_testclass
      |     1~~~~~~~~~~~~~~~~~~~~~
Error: Different types in pointer assignment at (1); attempted assignment of TYPE(testclass) to TYPE(testclass_wrapper_type)
  214 |     main_global_testclass = global_testclass_ptr%p
Error: Cannot convert TYPE(testclass_wrapper_type) to TYPE(testclass) at (1)
make: *** [Makefile:30: f2py] Error 1

Test passes after fix

$ cd examples/issue374_polymorphic_global && make test
python tests.py
....
----------------------------------------------------------------------
Ran 4 tests in 0.000s

OK

Class-related examples all pass after the change: fortran_oo, issue235_allocatable_classes, issue258_derived_type_attributes, issue254_getter, derivedtypes, mockderivetype, extends, class_names. Unit tests: 38 passed (2 pre-existing test_parse_dnad failures addressed separately).

@jameskermode ready for review.

Module-level variables of class types (derived types with type-bound
procedures) generated getters and setters that pointed the ptr_type
payload directly at the module variable, but for class types the
payload is a wrapper_type holding a class pointer. The generated code
failed to compile with 'Different types in pointer assignment'. Route
module-level access through the wrapper obj pointer, matching the
existing code path for class-typed components of derived types.

Fixes jameskermode#374
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

Copy link
Copy Markdown
Contributor Author

Wheel CI failed for cp312/cp313 on Linux: numpy 2.5 ships only manylinux_2_28 wheels, so the default manylinux2014 container built numpy from source and failed its gcc >= 10.3 check. Included a one-line workflow fix building Linux wheels in the manylinux_2_28 image.

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.

polymorphic derived type cannot be used as global variables

1 participant