-
Notifications
You must be signed in to change notification settings - Fork 128
MMCoreJ: Switch to SWIG 4 with compatibility tweak #699
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
base: main
Are you sure you want to change the base?
Conversation
SWIG 4 replaced the `std::vector` and `std::map` wrappers with versions
that fit better into Java by extending `java.util.List` and
`java.util.Map`.
This results in the generated Java API from being incompatible with that
generated by SWIG 2-3, in the following ways (based on japicmp output):
- `*Vector`, with `*` = `Boolean`, `Char`, `Double`, `Long`, `Str`,
`Unsigned`
- The constructor taking Java `long` (and producing that many
empty/zero elements) was removed
- Parameter type for `add()` and `set()` was changed from primitive to
boxed (for all but `StrVector`); these methods also newly have a
return value
- `get()` now returns boxed, rather than primitive, type
- `size()` and `capacity()` now return `int` rather than `long`
- `reserve()` now takes `int` rather than `long`
- `StrMap`
- `get()` takes `Object` instead of `String` (source-compatible but
not binary-compatible)
- `set()` is replaced by `put()`
- `del()` is removed (in favor of `remove()`)
- `has_key()` is replaced by `containsKey()`
- `empty()` is replaced by `isEmpty()`
- `size()` now returns `int` rather than `long`
(I'm ignoring backward-compatible changes, and incompatible changes to
generated classes that should not be considered part of the API, such as
`MMCoreJJNI`.)
This PR explicitly adds back the `*Vector` constructors taking `long`.
This was enough to get all of our Java modules in `micro-manager` to
compile (as of this writing).
For the remaining incompatibilities, I suggest that we leave them alone:
- The changes from unboxed to boxed types and from `long` to `int` may
cause compile errors under certain usage, but they do not cause any
silent change in semantics. And they are hopefully even less likely to
cause errors in BeanShell scripts.
- I'm inclined leave `StrMap` alone, since `StrMap` is not actually used
as a parameter or return value to any API methods (currently, at
least). Even if there is code that uses it, it will at most get a
compile error that should be easy to fix.
Java 8 added a default implementation for Iterator#remove().
Did not seem to be generating any Java code. No use spotted either.
Like its already-hidden subclasses, it is not thrown by MMCoreJ.
Not used anywhere in MMCore API; we don't need it, so remove while we're already making minor breaking changes.
Not used in MMCore API.
Copy-paste...
3e77360 to
9f9d7c8
Compare
|
The changes to The classes removed above are not used by any of the jars currently shipped with Micro-Manager (according to However, the
So we need to release new versions of PycroManagerJava and AcqEngJ and ship those together with the new MMCoreJ. |
|
It would be easier to manage the releases if MMCoreJ were already releasing to Maven Central, but that is stalled on (among other things) javadoc generation, which (under the current plan) requires SWIG 4 (#696). So one way to break the cycle is probably to manually deploy a (Java-only) preliminary MMCoreJ to Maven (built from this PR but before merging), so that we can update the dependencies for pycro-manager and AcqEngJ. The other way would be to work on #696 first without SWIG 4, which is also doable. |
MMCoreJ is currently built with SWIG 2-3 (2 on Windows, 3 on macOS, but it makes little difference).
SWIG 4 replaced the
std::vectorandstd::mapwrappers with versions that fit better into Java by extendingjava.util.Listandjava.util.Map.This results in the generated Java API from being incompatible with that generated by SWIG 2-3, in the following ways (based on japicmp output; see #37 for full details):
*Vector, with*=Boolean,Char,Double,Long,Str,Unsignedlong(and producing that many empty/zero elements) was removedadd()andset()was changed from primitive to boxed (for all butStrVector); these methods also newly have a return valueget()now returns boxed, rather than primitive, typesize()andcapacity()now returnintrather thanlongreserve()now takesintrather thanlongStrMapget()takesObjectinstead ofString(source-compatible but not binary-compatible)set()is replaced byput()del()is removed (in favor ofremove())has_key()is replaced bycontainsKey()empty()is replaced byisEmpty()size()now returnsintrather thanlong(I'm ignoring backward-compatible changes, and incompatible changes to generated classes that should not be considered part of the API, such as
MMCoreJJNI.)This PR explicitly adds back the
*Vectorconstructors takinglong. This was enough to get all of our Java modules inmicro-managerto compile (as of this writing).For the remaining incompatibilities, I suggest that we leave them alone:
The changes from unboxed to boxed types and from
longtointmay cause compile errors under certain usage, but they do not cause any silent change in semantics. And they are hopefully even less likely to cause errors in BeanShell scripts.I'm inclined leave
StrMapalone, sinceStrMapis not actually used as a parameter or return value to any API methods (currently, at least). Even if there is code that uses it, it will at most get a compile error that should be easy to fix.Before merging (let's do some minor "breaking" cleanup while we're at it):
BooleanVectorbe removed? (Not used in MMCore API)StrMapandpair_ss? (Also not used in MMCore API)istringstreamwrappers (%ignoretheMetadataTagmethods that takeistringstream); these were never usable in Java%rename(eql) operator=(doesn't generate any Java code; not sure how you'd use it -- was it meant to beoperator==?)%ignore)MetadataError(exceptions are converted so not used)remove()(Java 8 default implementation suffices)swig-doc-converter(used by apidoc CI) work with SWIG 4 output?micro-managerrepo needs SWIG 4Closes #37.