gen: skip enum typedefs in mod.add_type<T> (fixes ORB ScoreType factory error)#87
Merged
Conversation
`parse_tree.py` pushes every unknown return/arg type into `register_types`,
including enum typedefs like `cv::ORB::ScoreType`. `gen3_cpp.py` then emitted
`mod.add_type<cv::ORB::ScoreType>("ORB_ScoreType")` in the generated C++ — but
the Julia side declares these as `const ORB_ScoreType = Int64` (a constant,
not a wrapped type). Loading `libopencv_julia.so` tripped CxxWrap's
"No appropriate factory for type N2cv3ORB9ScoreTypeE" at @wrapmodule time.
The bug was latent until `OpenCV_jll v4.13.0+1` enabled `features2d` in
`BUILD_LIST` (Yggdrasil JuliaPackaging/Yggdrasil#13882), exposing
`cv::ORB::ScoreType` (and the other features2d enum typedefs in
`gen/cpp_files/jlcv.hpp` lines 45-51).
Fix: pre-populate the `enums` list across all namespaces before emitting
`register_types`, then filter out enum typedefs. Verified: regenerated
`autogen_cpp/cv_core.cpp` has zero `mod.add_type<...EnumType>` lines.
Also regenerate `src/generated/` — `cv_cxx_wrap.jl` (+927) and `cv_wrap.jl`
(+54) now contain the features2d/ORB Julia bindings that pair with the
features2d glue compiled into the JLL.
Pairs with the matching `OpenCV_jll v4.13.0+2` rebuild on Yggdrasil.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
ViralBShah
added a commit
that referenced
this pull request
Jun 5, 2026
…ror) Follow-up to #87. That PR stopped the generator from emitting `mod.add_type<EnumT>("...")` for enum typedefs in register_types — but the C++ glue still failed at @wrapmodule time with: C++ exception while wrapping module OpenCV: No appropriate factory for type N2cv3ORB9ScoreTypeE Because `getScoreType` (and the other features2d enum getters) were generated as `return retval;` instead of `return (int64_t)retval;`, so jlcxx instantiated `stored_type<cv::ORB::ScoreType>` from the return type's deduced jl-type, registering it as a wrapped type with no Julia counterpart. Root cause: hdr_parser normalizes argument types via `::` -> `_` and strips `cv::` (parse_arg, line 385), so setScoreType sees its arg as `ORB_ScoreType`. But parse_tree.py reads `decl[4]` (the *original* return type) into self.rettype, so getScoreType's return reaches us as `ORB::ScoreType` — cv:: stripped, `::` preserved. The previously populated `enums` set had only `cv::ORB::ScoreType` and `ORB_ScoreType`, so the `tp in enums` check at gen3_cpp.py:151 missed, and the int64_t cast wasn't emitted. Fix: when populating the `enums` set in gen3_cpp.py, also push the cv::-stripped-but-`::`-preserving form (e.g. `ORB::ScoreType`) so all three shapes a type can appear in are covered. Verified locally: regenerated autogen_cpp/cv_core.cpp now emits `return (int64_t)retval;` for getScoreType, getDescriptorType, etc. src/generated/ is unchanged (the fix is C++-side only). Pairs with a matching OpenCV_jll v4.13.0+4 rebuild on Yggdrasil. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ViralBShah
added a commit
to JuliaPackaging/Yggdrasil
that referenced
this pull request
Jun 5, 2026
#13907) * [OpenCV] Rebuild as 4.13.0+4 (cast enum return types to int64_t) OpenCV_jll v4.13.0+3 (#13901) shipped with JuliaImages/OpenCV.jl#87's generator fix for `mod.add_type<EnumT>`, but `using OpenCV` still fails at @wrapmodule with: C++ exception while wrapping module OpenCV: No appropriate factory for type N2cv3ORB9ScoreTypeE The factory error fires not only on `mod.add_type`, but also on any unregistered type used as a return type. `getScoreType()` was generated as `return retval;` (raw cv::ORB::ScoreType), making jlcxx instantiate `stored_type<cv::ORB::ScoreType>` from the return-type deduction path — same effect, same error. Confirmed by symbol inspection of the +3 dylib: __ZGVZN5jlcxx11stored_typeIN2cv3ORB9ScoreTypeE...m_dt OpenCV.jl#89 fixes the generator's enum set to also include the cv::-stripped-but-`::`-preserving form (`ORB::ScoreType`), so the `(int64_t)retval` cast is emitted for enum returners across features2d. Re-pin the GitSource to that commit and rebuild as 4.13.0+4. No other recipe changes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Update OpenCV.jl GitSource commit hash * [OpenCV] Bump OpenCV.jl GitSource to master (7d86cca) incl. merged #89 Picks up the merged PR #89: enum return-type int64_t cast (fixes the ORB::ScoreType factory error at load) plus the features2d wrapper fixes (ORB/SimpleBlobDetector default ctors, KeyPoint detect->compute round-trip). Only src/ and test/ changed vs the previously pinned a8e1995, so the compiled libopencv_julia is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a latent generator bug exposed by
OpenCV_jll v4.13.0+1, which fails atusing OpenCVwith:Root cause
gen/parse_tree.pypushes every unknown return/arg type intons.register_types, including enum typedefs (e.g.cv::ORB::ScoreType).gen/gen3_cpp.pythen emittedmod.add_type<cv::ORB::ScoreType>("ORB_ScoreType")in the generated C++.const ORB_ScoreType = Int64— a constant alias, not a wrapped type — so CxxWrap finds no factory at load time.OpenCV_jll v4.13.0+0excludedfeatures2dfromBUILD_LIST. [OpenCV] Generate Julia wrappers from OpenCV.jl, ship only libopencv_julia JuliaPackaging/Yggdrasil#13882 addedfeatures2dto the build for+1(paving the way for Wrap features2d (2/2): generated wrappers + tests (closes #51) #82), and that's when the bug fired.Fix
enumslist across all namespaces before emittingregister_types(the old loop populatedenumsper-namespace in the same pass, so later-namespace enums were never available for filtering).mod.add_type<T>.Wrappers
Regenerate
src/generated/against the patched generator.cv_cxx_wrap.jl(+927) andcv_wrap.jl(+54) now contain the features2d/ORB Julia bindings that pair with the features2d C++ glue already compiled into the JLL.Pairs with
OpenCV_jll v4.13.0+2rebuild on Yggdrasil (PR linked once open).v4.13.0+1(PR linked once open).Test plan
autogen_cpp/cv_core.cpplocally — zeromod.add_type<...EnumType>lines (verified forScoreType,DescriptorType,DiffusivityType,DetectorType,MatcherType,HistogramNormType,DescriptorStorageFormat).julia gen/regenerate.jlis deterministic and produces the committedsrc/generated/diff.OpenCV_jll v4.13.0+2lands:using OpenCVloads cleanly;OpenCV.getVersionString() == "4.13.0"; full test suite passes; features2d/ORB calls work.🤖 Generated with Claude Code