-
-
Notifications
You must be signed in to change notification settings - Fork 743
COMP: Resolve Python ST/IT/OT from the wrapped C types #6772
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,6 +194,14 @@ def _normalized_path(relative_posix_path: str, message) -> str: | |
| "ITK_WRAP_PYTHON_COMPLEX_REAL": "@ITK_WRAP_PYTHON_COMPLEX_REAL@".split(";"), | ||
| } | ||
|
|
||
| # 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] = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this identifier start with an underscore (as in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd lean toward keeping it un-prefixed, for consistency with its two immediate siblings in this same file — The established convention here looks like it puts the privacy marker on the consumer side rather than the definition side, e.g. That is what the Happy to go the other direction if you'd rather: either underscore-prefix this one alone (accepting the inconsistency), or rename all three |
||
| "ST": "@ITKM_ST@", | ||
| "IT": "@ITKM_IT@", | ||
| "OT": "@ITKM_OT@", | ||
| } | ||
|
|
||
| (swig_lib, swig_py, config_py, doxygen_root, path) = _initialize() | ||
| del _initialize | ||
| del warnings | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
Then we would only need to make
ITK_USE_64BITS_IDSaccessible in Python, right? (AssumingITK_USE_64BITS_IDSis still needed, of course, as discussed at issue #6774.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TLDR: I'm not willing to hold up the fix based on a nit like this, and since either method works, I'll do you preference in a forced push in a few minutes.
====
I have a minor preference disagreement with the proposed change request. The double dictionary lookup is a common way to map between types, and I think it more clearly defines what we are trying to accomplish. I think that this paradigm will be more maintainable in the future.
The conditional based on a compile-time option that we are considering removing seems like a move in the wrong direction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reversing what I said earlier — after checking it against a real build, I'm keeping the dictionary lookup as written. Your suggestion misses that the wrapped types do not follow
ITK_USE_64BITS_IDSalone; the selection is gated onWIN32as well, so the proposed form is only correct on Windows.Wrapping/WrapBasicTypes.cmake:220-235is the authority:On macOS and Linux the
WIN32term is false, so theelsebranch is always taken andST/ITare alwaysUL— 64-bit there — regardless of howITK_USE_64BITS_IDSis set. This matches the platform table in #6774: on LP64 the option is a no-op in both positions, because the guard atitkIntTypes.h:65additionally requiresULLONG_MAX != ULONG_MAX. It changes types only on Windows LLP64 and on 32-bit targets such as WebAssembly.Checked against my macOS build, which has
ITK_USE_64BITS_IDS:BOOL=OFF(/* #undef ITK_USE_64BITS_IDS */in the generateditkConfigure.h):uint64_t if ITK_USE_64BITS_IDS else uint32_tUL— 64-bituint32_t→UI, 32-bit ❌ULuint64_t→UL✓ULLuint64_t→ULL✓ULuint32_t→UI❌So it would break the default macOS/Linux configuration — where nearly all wheels are built — and on Windows/OFF it would still not produce the right answer, just a different wrong one.
There is a second, subtler problem:
uint32_tisUI(unsigned int), notUL. Even where the widths coincide these are distinctitkCTypes with distinct mangled names, soitk.STwould name an instantiation the wrapping never created — which is the class of bug this PR exists to fix.Worth noting for the record that this would be the third independent re-derivation of a value CMake already computes, each wrong in its own way: the original
if os.name == "nt": ST = ULLignored the option entirely; #6767 (b5eb3ae3ffb) replaced it with an unconditionaluint64_t; and this proposal drops theWIN32term. Making your version correct would mean restoring theos.name == "nt"check you removed in #6767. That history is the argument for readingITKM_*rather than reconstructing it — the dictionary is doing real work, not ceremony.I take your point that two dictionaries read as indirection. I'd rather keep the mapping explicit than trade correctness for brevity here, so I'm leaving the three lines as they are. Happy to revisit the spelling if you see a form that keeps the CMake value as the single source of truth.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that the following should work?
Then for now I think that would be OK.
Oh, I see now, it wants UL for Windows + OFF 🤔 So then:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the type of logic that we want to avoid. It's replicating the logic that is already hard-coded in the dictionaries and can not deviate from what occurs in the C++ layer. The current solution I have will track what the C++ layer demands without the need for manual synchronization. Your solution requires manual modification of this logic for every change in the CMake or C++ logic.