Commit 43ddf0c
Eliminate the remaining classic DllImport entries and dead DllImport comments
Six entry points still took a delegate directly as a P/Invoke parameter,
which [LibraryImport]'s source generator does not support, so they stayed
on classic [DllImport]. Each is routed through a static
[UnmanagedCallersOnly] trampoline instead, following the pattern already
established for highgui's setMouseCallback/createTrackbar:
- face_FacemarkTrain_setFaceDetector / face_FacemarkKazemi_setFaceDetector
and geometry_SACSegmentation_setCustomModelConstraints support multiple
concurrent instances, each with its own callback, but neither native
entry point threaded a userData pointer back to the raw callback - the
previous per-delegate marshaled thunk was the only thing disambiguating
instances. Native (face_Facemark.h/geometry.h) now carries a void*
userData alongside the callback pointer through to the point of
invocation, mirroring what videoio's ManagedStreamReader already did;
the managed side boxes the real delegate into a GCHandle-rooted context
and passes its IntPtr through as that userData.
- videoio_VideoCapture_new6/open3's ManagedStreamReader::ReadCallback/
SeekCallback already carried userData through to the point of
invocation, so StreamReaderBridge just needed to become a GCHandle-based
context holder instead of an instance whose delegates were marshaled
directly.
- tracking_TrackerKCF_setFeatureExtractor's cv::TrackerKCF::
FeatureExtractorCallbackFN has no per-instance user-data slot at all
(already documented as process-wide-singleton-only), so no GCHandle
context is needed there - only the field the fixed trampoline reads is
swapped.
Also deleted the dead, commented-out //[DllImport(...)] lines left over
from the original Phase 2 bulk conversion to LibraryImport, scattered
across NativeMethods_highgui.cs, NativeMethods_videoio.cs, and the core/
imgproc NativeMethods files - they had no live counterpart to convert and
were pure noise.
Testing:
- dotnet build src/OpenCvSharp/OpenCvSharp.csproj -c Release: 0 warnings, 0 errors.
- cmake --build (OpenCvSharpExtern, Release) for the face_Facemark.h/geometry.h changes.
- dotnet test test/OpenCvSharp.Tests -f net10.0: 1730 passed, 0 failed, 23 skipped
(pre-existing, platform/model-file-gated skips) - including FacemarkKazemiTest.
CustomFaceDetectorIsInvoked, SACSegmentationTest.CustomModelConstraintsRejecting
AllModelsYieldsZeroModels, TrackerKCFTest.SetFeatureExtractor, and
VideoCaptureTest.OpenFromCustomStreamReader, which exercise the new
trampolines end-to-end.
Fixes #2077
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent 4aa709f commit 43ddf0c
19 files changed
Lines changed: 231 additions & 175 deletions
File tree
- src
- OpenCvSharpExtern
- OpenCvSharp
- Internal/PInvoke/NativeMethods
- core
- face
- geometry
- imgproc
- traking
- Modules
- face/Facemark
- geometry
- tracking
- videoio
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | 107 | | |
Lines changed: 12 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
| |||
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
90 | | - | |
91 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
92 | 97 | | |
93 | | - | |
94 | | - | |
| 98 | + | |
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
| |||
116 | 120 | | |
117 | 121 | | |
118 | 122 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| |||
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | 198 | | |
201 | 199 | | |
202 | 200 | | |
| |||
Lines changed: 0 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | 34 | | |
38 | 35 | | |
39 | 36 | | |
| |||
Lines changed: 1 addition & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | 43 | | |
46 | 44 | | |
47 | 45 | | |
48 | | - | |
| 46 | + | |
49 | 47 | | |
50 | 48 | | |
51 | | - | |
52 | | - | |
53 | 49 | | |
54 | 50 | | |
55 | 51 | | |
| |||
Lines changed: 0 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
69 | 67 | | |
70 | 68 | | |
71 | 69 | | |
| |||
259 | 257 | | |
260 | 258 | | |
261 | 259 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | 260 | | |
269 | 261 | | |
270 | 262 | | |
| |||
Lines changed: 0 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
| |||
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | 42 | | |
47 | 43 | | |
48 | 44 | | |
| |||
Lines changed: 12 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
74 | | - | |
75 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
76 | 79 | | |
77 | 80 | | |
78 | 81 | | |
| |||
218 | 221 | | |
219 | 222 | | |
220 | 223 | | |
221 | | - | |
222 | | - | |
223 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
224 | 230 | | |
225 | 231 | | |
226 | 232 | | |
| |||
Lines changed: 6 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
695 | 697 | | |
696 | 698 | | |
697 | 699 | | |
| |||
Lines changed: 0 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | 304 | | |
308 | 305 | | |
309 | 306 | | |
| |||
0 commit comments