diff --git a/makefiles/Makefile.java.mk b/makefiles/Makefile.java.mk index ba04b96397..a1a0932304 100755 --- a/makefiles/Makefile.java.mk +++ b/makefiles/Makefile.java.mk @@ -98,10 +98,6 @@ $(GEN_DIR)/ortools/constraint_solver/constraint_solver_java_wrap.cc: \ -module main \ -outdir $(GEN_PATH)$Sjava$Scom$Sgoogle$Sortools$Sconstraintsolver \ $(SRC_DIR)$Sortools$Sconstraint_solver$Sjava$Srouting.i - $(SED) -i -e 's/< long long >/< int64 >/g' \ - $(GEN_PATH)$Sortools$Sconstraint_solver$Sconstraint_solver_java_wrap.cc - $(SED) -i -e 's/< long long,long long >/< int64, int64 >/g' \ - $(GEN_PATH)$Sortools$Sconstraint_solver$Sconstraint_solver_java_wrap.cc $(OBJ_DIR)/swig/constraint_solver_java_wrap.$O: \ $(GEN_DIR)/ortools/constraint_solver/constraint_solver_java_wrap.cc \ @@ -184,8 +180,6 @@ $(GEN_DIR)/ortools/sat/sat_java_wrap.cc: \ -module main \ -outdir $(GEN_PATH)$Sjava$Scom$Sgoogle$Sortools$Ssat \ $(SRC_DIR)$Sortools$Ssat$Sjava$Ssat.i - $(SED) -i -e 's/< long long >/< int64 >/g' \ - $(GEN_PATH)$Sortools$Ssat$Ssat_java_wrap.cc $(OBJ_DIR)/swig/sat_java_wrap.$O: \ $(GEN_DIR)/ortools/sat/sat_java_wrap.cc \ @@ -206,8 +200,6 @@ $(GEN_DIR)/ortools/util/util_java_wrap.cc: \ -module main \ -outdir $(GEN_PATH)$Sjava$Scom$Sgoogle$Sortools$Sutil \ $(SRC_DIR)$Sortools$Sutil$Sjava$Ssorted_interval_list.i - $(SED) -i -e 's/< long long >/< int64 >/g' \ - $(GEN_PATH)$Sortools$Sutil$Sutil_java_wrap.cc $(OBJ_DIR)/swig/util_java_wrap.$O: \ $(GEN_DIR)/ortools/util/util_java_wrap.cc \ diff --git a/ortools/algorithms/java/knapsack_solver.i b/ortools/algorithms/java/knapsack_solver.i index 14950eddcc..3314d16b20 100644 --- a/ortools/algorithms/java/knapsack_solver.i +++ b/ortools/algorithms/java/knapsack_solver.i @@ -19,7 +19,6 @@ // TODO(user): test all lines marked "untested". %include "enums.swg" -%include "stdint.i" %include "ortools/base/base.i" %import "ortools/util/java/vector.i" diff --git a/ortools/base/base.i b/ortools/base/base.i index 41fe0a9725..2c76df7a7e 100644 --- a/ortools/base/base.i +++ b/ortools/base/base.i @@ -72,9 +72,31 @@ COPY_TYPEMAPS(uint64_t, uint64); #endif // SWIGPYTHON -#if defined(SWIGJAVA) || defined(SWIGCSHARP) -#endif // defined(SWIGJAVA) || defined(SWIGCSHARP) +#if defined(SWIGJAVA) +// swig/java/typenames.i and swig/java/java.swg typemap C++ 'long int' as Java 'int' +// but in C++ 'int64' aka 'int64_t' is defined as "long int" and we have +// overload functions int/int64 in routing... +// So we need to force C++ 'long int' to map to Java 'long' instead of 'int' reusing the +// typemap for C++ `long long` +// note: there is no `ulong` in java so we map both on Java `long` type. +#if defined(SWIGWORDSIZE64) +%define PRIMITIVE_TYPEMAP(NEW_TYPE, TYPE) +%clear NEW_TYPE; +%clear NEW_TYPE *; +%clear NEW_TYPE &; +%clear const NEW_TYPE &; +%apply TYPE { NEW_TYPE }; +%apply TYPE * { NEW_TYPE * }; +%apply TYPE & { NEW_TYPE & }; +%apply const TYPE & { const NEW_TYPE & }; +%enddef // PRIMITIVE_TYPEMAP +PRIMITIVE_TYPEMAP(long int, long long); +PRIMITIVE_TYPEMAP(unsigned long int, long long); +#undef PRIMITIVE_TYPEMAP +#endif // defined(SWIGWORDSIZE64) + +#endif // defined(SWIGJAVA) // SWIG macros for explicit API declaration. // Usage: diff --git a/ortools/constraint_solver/java/constraint_solver.i b/ortools/constraint_solver/java/constraint_solver.i index 39fa968354..63949097d5 100644 --- a/ortools/constraint_solver/java/constraint_solver.i +++ b/ortools/constraint_solver/java/constraint_solver.i @@ -13,9 +13,9 @@ // TODO(user): Refactor this file to adhere to the SWIG style guide. + %include "enumsimple.swg" %include "exception.i" -%include "stdint.i" %include "ortools/base/base.i" %include "ortools/util/java/tuple_set.i" diff --git a/ortools/sat/java/sat.i b/ortools/sat/java/sat.i index 94000190e1..c795c5a6ed 100644 --- a/ortools/sat/java/sat.i +++ b/ortools/sat/java/sat.i @@ -11,8 +11,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -%include "stdint.i" - %include "ortools/base/base.i" %include "ortools/util/java/proto.i" diff --git a/ortools/util/java/vector.i b/ortools/util/java/vector.i index af79859fcd..a96ad6838c 100644 --- a/ortools/util/java/vector.i +++ b/ortools/util/java/vector.i @@ -20,8 +20,6 @@ // // TODO(user): move to base/swig/java. -%include "stdint.i" - %include "ortools/base/base.i" %{