COMP: Resolve Python ST/IT/OT from the wrapped C types - #6772
Conversation
|
|
||
| # Mangled names of the C types the wrapping instantiated for itk::SizeValueType, | ||
| # itk::IdentifierType and itk::OffsetValueType, from Wrapping/WrapBasicTypes.cmake. | ||
| ITK_GLOBAL_WRAPPING_TYPE_ALIASES: dict[str, str] = { |
There was a problem hiding this comment.
Shouldn't this identifier start with an underscore (as in _ITK_GLOBAL_WRAPPING_TYPE_ALIASES), to indicate that it is only for internal use?
There was a problem hiding this comment.
I'd lean toward keeping it un-prefixed, for consistency with its two immediate siblings in this same file — ITK_GLOBAL_VERSION_STRING (line 182) and ITK_GLOBAL_WRAPPING_BUILD_OPTIONS (line 185) — both of which are equally internal and neither of which is underscore-prefixed.
The established convention here looks like it puts the privacy marker on the consumer side rather than the definition side, e.g. itk/support/build_options.py:
from itkConfig import ITK_GLOBAL_WRAPPING_BUILD_OPTIONS as _itkwrapbo
That is what the as _wrapping_type_aliases in this PR was imitating — but since you and Dzenan both preferred a single name for the dict, I have dropped the rename and instead del the imported name after use, so nothing leaks into itk.support.types either way.
Happy to go the other direction if you'd rather: either underscore-prefix this one alone (accepting the inconsistency), or rename all three ITK_GLOBAL_* names in a separate STYLE: commit so the file stays uniform. Your call — just say which and I'll make the change.
dzenanz
left a comment
There was a problem hiding this comment.
Generally looks good. Niels' suggestions make sense.
Wrapping/WrapBasicTypes.cmake selects unsigned long long for itk::IdentifierType only when both WIN32 and ITK_USE_64BITS_IDS hold, while itk.support.types derived the alias independently. On Windows with ITK_USE_64BITS_IDS=OFF the wrapping instantiates unsigned long while itk.IT reported a 64-bit type, so itk.VectorContainer[itk.IT, ...] named an instantiation that does not exist. Export the mangled names ITKM_ST, ITKM_IT and ITKM_OT through itkConfig and look the aliases up from there, so the Python aliases and the instantiated templates come from one definition.
2fa8836 to
cd67e98
Compare
|
Thanks for addressing my comments so far, Hans! For my understanding, the current For the record, Back in 2019, we had some discussion at discourse.itk.org about |
correct. |
|
Split your One correction worth stating here: |
|
N-Dekker
left a comment
There was a problem hiding this comment.
Thank you so far, Hans. Can we please take a little bit more time for this PR? Specifically, does this solves a real problem for end-users nowadays? (As you reported by issue #6774). If it does solve a significant problem, I still have some more detailed questions.
| ST = _c_type_by_mangled_name[ITK_GLOBAL_WRAPPING_TYPE_ALIASES["ST"]] | ||
| IT = _c_type_by_mangled_name[ITK_GLOBAL_WRAPPING_TYPE_ALIASES["IT"]] | ||
| OT = _c_type_by_mangled_name[ITK_GLOBAL_WRAPPING_TYPE_ALIASES["OT"]] |
There was a problem hiding this comment.
I find the use of two dictionaries here a bit complicated. It may make the code harder to understand for human readers. Would it be possible to simplify these three lines to just:
ST = uint64_t if ITK_USE_64BITS_IDS else uint32_t
IT = ST
OT = int64_t if ITK_USE_64BITS_IDS else int32_tThen we would only need to make ITK_USE_64BITS_IDS accessible in Python, right? (Assuming ITK_USE_64BITS_IDS is still needed, of course, as discussed at issue #6774.)
itk.ITdid not agree with the identifier type the wrapping actually instantiated:Wrapping/WrapBasicTypes.cmakeselectsunsigned long longonly when bothWIN32andITK_USE_64BITS_IDShold, whileitk/support/types.pyderived the alias independently. On Windows withITK_USE_64BITS_IDS=OFFthe two disagreed, soitk.VectorContainer[itk.IT, ...]named an instantiation that does not exist.Export
ITKM_ST/ITKM_IT/ITKM_OTthroughitkConfigand resolve the Python aliases from there, so both sides come from one definition.Surfaced while answering #6769 (comment) — that PR wants to use
itk.ITasIdentifierType, which needs this first.The disagreement
Wrapping/WrapBasicTypes.cmake:221:Wrapping/Generators/Python/itk/support/types.py, after #6767:On Windows with
ITK_USE_64BITS_IDS=OFF, CMake instantiatesunsigned long(32-bit there) while Python reports a 64-bit type. Elsewhere the two happen to coincide, which is why this has gone unnoticed.ITKM_ITexpands to the literal"UL"/"ULL", which is exactly theitkCTypeshort name, so the CMake value maps to the Python object by direct lookup with no translation table to drift.Local verification
macOS,
ITK_WRAP_PYTHON=ON,Module_ITKVtkGlue=OFF(incompatible withITK_USE_PYTHON_LIMITED_API). Build exit 0, 4610/4610 targets, zero errors.ctest -R "[Pp]ython"-> 176/176 passed, includingPythonTypeTest,PythonVerifyTTypeAPIConsistencyandPythonTemplateTest.Not verifiable locally: the defect case is
WIN32 + ITK_USE_64BITS_IDS=OFF. Every build available to me resolvesITKM_IT=UL, so what is shown above is that the new path reproduces the correct answer where the old path was also right. Windows CI is the first real executor for the case this targets.