Skip to content

gen: skip enum typedefs in mod.add_type<T> (fixes ORB ScoreType factory error)#87

Merged
ViralBShah merged 1 commit into
masterfrom
vs/fix-enum-add-type
Jun 4, 2026
Merged

gen: skip enum typedefs in mod.add_type<T> (fixes ORB ScoreType factory error)#87
ViralBShah merged 1 commit into
masterfrom
vs/fix-enum-add-type

Conversation

@ViralBShah

Copy link
Copy Markdown
Member

Summary

Fix a latent generator bug exposed by OpenCV_jll v4.13.0+1, which fails at using OpenCV with:

C++ exception while wrapping module OpenCV: No appropriate factory for type N2cv3ORB9ScoreTypeE
ERROR: LoadError: No appropriate factory for type N2cv3ORB9ScoreTypeE

Root cause

Fix

  • Pre-populate the enums list across all namespaces before emitting register_types (the old loop populated enums per-namespace in the same pass, so later-namespace enums were never available for filtering).
  • Skip enum typedefs when emitting mod.add_type<T>.

Wrappers

Regenerate src/generated/ against the patched generator. cv_cxx_wrap.jl (+927) and cv_wrap.jl (+54) now contain the features2d/ORB Julia bindings that pair with the features2d C++ glue already compiled into the JLL.

Pairs with

  • A matching OpenCV_jll v4.13.0+2 rebuild on Yggdrasil (PR linked once open).
  • General-registry yank of the broken v4.13.0+1 (PR linked once open).

Test plan

  • Regenerated autogen_cpp/cv_core.cpp locally — zero mod.add_type<...EnumType> lines (verified for ScoreType, DescriptorType, DiffusivityType, DetectorType, MatcherType, HistogramNormType, DescriptorStorageFormat).
  • julia gen/regenerate.jl is deterministic and produces the committed src/generated/ diff.
  • After OpenCV_jll v4.13.0+2 lands: using OpenCV loads cleanly; OpenCV.getVersionString() == "4.13.0"; full test suite passes; features2d/ORB calls work.

🤖 Generated with Claude Code

`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>
@ViralBShah ViralBShah merged commit 52c3c7f into master Jun 4, 2026
1 of 21 checks passed
@ViralBShah ViralBShah deleted the vs/fix-enum-add-type branch June 4, 2026 19:48
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>
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.

1 participant