diff --git a/makefiles/Makefile.java.mk b/makefiles/Makefile.java.mk index 3fdcaf1ca0..7abebc18ed 100755 --- a/makefiles/Makefile.java.mk +++ b/makefiles/Makefile.java.mk @@ -98,6 +98,10 @@ $(GEN_DIR)/ortools/constraint_solver/constraint_solver_java_wrap.cc: \ -module main \ -outdir $(GEN_PATH)$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 \ diff --git a/ortools/algorithms/java/knapsack_solver.i b/ortools/algorithms/java/knapsack_solver.i index a8b5fa1e7b..6102827a2f 100644 --- a/ortools/algorithms/java/knapsack_solver.i +++ b/ortools/algorithms/java/knapsack_solver.i @@ -18,15 +18,19 @@ // // TODO(user): test all lines marked "untested". -%include "ortools/base/base.i" -%include "enums.swg" +%include +%include +%include "ortools/base/base.i" %import "ortools/util/java/vector.i" %{ #include "ortools/algorithms/knapsack_solver.h" %} +typedef int64_t int64; +typedef uint64_t uint64; + %ignoreall %unignore operations_research; %unignore operations_research::KnapsackSolver; diff --git a/ortools/base/base.i b/ortools/base/base.i index ba1218d65b..b27b560d9f 100644 --- a/ortools/base/base.i +++ b/ortools/base/base.i @@ -25,24 +25,11 @@ %include %include - -// Add a char* cast to the SWIG 1.3.21 typemaps to remove a compiler warning. -%typemap(constcode) long long { - PyObject *object = PyLong_FromLongLong($value); - if (object) { - int rc = PyDict_SetItemString(d, (char*) "$symname", object); - Py_DECREF(object); - } -} -%typemap(constcode) unsigned long long { - PyObject *object = PyLong_FromUnsignedLongLong($value); - if (object) { - int rc = PyDict_SetItemString(d, (char*) "$symname", object); - Py_DECREF(object); - } -} +%include +%include %{ +#include #include #include #include @@ -61,7 +48,6 @@ // type names. Google typedefs are placed at the very end along with // the necessary %apply macros. See COPY_TYPEMAPS below for details. -%include "std_string.i" // Support for those popular buffer-pointer/length input pairs %typemap(in) (void *INPUT, unsigned int LENGTH) (Py_ssize_t len) { @@ -144,8 +130,8 @@ LIST_OUTPUT_TYPEMAP(int, PyInt_FromLong); LIST_OUTPUT_TYPEMAP(unsigned int, PyLong_FromUnsignedLong); LIST_OUTPUT_TYPEMAP(long, PyInt_FromLong); LIST_OUTPUT_TYPEMAP(unsigned long, PyLong_FromUnsignedLong); -LIST_OUTPUT_TYPEMAP(long long, PyLong_FromLongLong); -LIST_OUTPUT_TYPEMAP(unsigned long long, PyLong_FromUnsignedLongLong); +LIST_OUTPUT_TYPEMAP(int64, PyLong_FromLongLong); +LIST_OUTPUT_TYPEMAP(uint64, PyLong_FromUnsignedLongLong); LIST_OUTPUT_TYPEMAP(std::string, SwigString_FromString); LIST_OUTPUT_TYPEMAP(char *, PyBytes_FromString); LIST_OUTPUT_TYPEMAP(double, PyFloat_FromDouble); @@ -179,19 +165,12 @@ typedef oldtype newtype; %apply std::vector * OUTPUT { std::vector * OUTPUT }; %enddef -COPY_TYPEMAPS(signed char, schar); -COPY_TYPEMAPS(short, int16); -COPY_TYPEMAPS(unsigned short, uint16); COPY_TYPEMAPS(int, int32); COPY_TYPEMAPS(unsigned int, uint32); -COPY_TYPEMAPS(long long, int64); -COPY_TYPEMAPS(unsigned long long, uint64); +COPY_TYPEMAPS(int64_t, int64); +COPY_TYPEMAPS(uint64_t, uint64); COPY_TYPEMAPS(unsigned int, size_t); -COPY_TYPEMAPS(unsigned int, mode_t); -COPY_TYPEMAPS(long, time_t); -COPY_TYPEMAPS(uint64, Fprint); - #undef COPY_TYPEMAPS %apply (void * INPUT, unsigned int LENGTH) @@ -242,7 +221,9 @@ COPY_TYPEMAPS(uint64, Fprint); #endif // SWIGPYTHON #ifdef SWIGJAVA +// Add a char* cast to the SWIG 1.3.21 typemaps to remove a compiler warning. %{ +#include #include #include #include @@ -252,6 +233,7 @@ COPY_TYPEMAPS(uint64, Fprint); #include "ortools/base/basictypes.h" %} +%include %include %apply const std::string & {std::string &}; @@ -356,11 +338,10 @@ COPY_TYPEMAPS(uint64, Fprint); typedef oldtype newtype; %enddef -COPY_TYPEMAPS(signed char, schar); -COPY_TYPEMAPS(int, int32); -COPY_TYPEMAPS(unsigned int, uint32); -COPY_TYPEMAPS(long long, int64); -COPY_TYPEMAPS(unsigned long long, uint64); +typedef int int32; +typedef unsigned int uint32; +typedef int64_t int64; +typedef uint64_t uint64; #undef COPY_TYPEMAPS #endif // SWIGJAVA @@ -368,6 +349,7 @@ COPY_TYPEMAPS(unsigned long long, uint64); #ifdef SWIGCSHARP %include "enumsimple.swg" %{ +#include #include #include #include @@ -378,19 +360,15 @@ COPY_TYPEMAPS(unsigned long long, uint64); %} %include +%include %apply const std::string & {std::string &}; %apply const std::string & {std::string *}; -%define COPY_TYPEMAPS(oldtype, newtype) -typedef oldtype newtype; -%enddef - -COPY_TYPEMAPS(signed char, schar); -COPY_TYPEMAPS(int, int32); -COPY_TYPEMAPS(unsigned int, uint32); -COPY_TYPEMAPS(long long, int64); -COPY_TYPEMAPS(unsigned long long, uint64); +typedef int int32; +typedef unsigned int uint32; +typedef int64_t int64; +typedef uint64_t uint64; #undef COPY_TYPEMAPS #endif // SWIGCSHARP diff --git a/ortools/constraint_solver/csharp/constraint_solver.i b/ortools/constraint_solver/csharp/constraint_solver.i index ba8040c14a..b47b0d0ce3 100644 --- a/ortools/constraint_solver/csharp/constraint_solver.i +++ b/ortools/constraint_solver/csharp/constraint_solver.i @@ -22,6 +22,7 @@ using System.Collections; %include %include %include + %include "ortools/base/base.i" %include "ortools/util/csharp/tuple_set.i" %include "ortools/util/csharp/functions.i" @@ -143,9 +144,9 @@ PROTECT_FROM_FAILURE(Solver::Fail(), arg1); // files end up being compiled into the same .dll, we must name the // vector template differently. %template(CpIntVector) std::vector; -%template(CpInt64Vector) std::vector; +%template(CpInt64Vector) std::vector; %template(CpIntVectorVector) std::vector >; -%template(CpInt64VectorVector) std::vector >; +%template(CpInt64VectorVector) std::vector >; %define CS_TYPEMAP_STDVECTOR_OBJECT(CTYPE, TYPE) SWIG_STD_VECTOR_ENHANCED(operations_research::CTYPE*); diff --git a/ortools/constraint_solver/java/constraint_solver.i b/ortools/constraint_solver/java/constraint_solver.i index 2d82865511..6b53c06741 100644 --- a/ortools/constraint_solver/java/constraint_solver.i +++ b/ortools/constraint_solver/java/constraint_solver.i @@ -13,14 +13,14 @@ // TODO(user): Refactor this file to adhere to the SWIG style guide. -%include "enumsimple.swg" -%include "exception.i" +%include +%include +%include %include "ortools/base/base.i" %include "ortools/util/java/tuple_set.i" %include "ortools/util/java/vector.i" %include "ortools/util/java/functions.i" - %include "ortools/util/java/proto.i" // Remove swig warnings @@ -52,6 +52,9 @@ struct FailureProtect { }; %} +typedef int64_t int64; +typedef uint64_t uint64; + // ############ BEGIN DUPLICATED CODE BLOCK ############ // IMPORTANT: keep this code block in sync with the .i // files in ../python and ../csharp. diff --git a/ortools/graph/java/graph.i b/ortools/graph/java/graph.i index fdeedc7311..cd3e0c3e10 100644 --- a/ortools/graph/java/graph.i +++ b/ortools/graph/java/graph.i @@ -29,6 +29,8 @@ // // TODO(user): test all the APIs that are currently marked as 'untested'. +%include + %include "ortools/base/base.i" %import "ortools/graph/ebert_graph.h" @@ -39,6 +41,9 @@ #include "ortools/graph/min_cost_flow.h" %} +typedef int64_t int64; +typedef uint64_t uint64; + // ############ max_flow.h ############ %ignoreall diff --git a/ortools/linear_solver/java/linear_solver.i b/ortools/linear_solver/java/linear_solver.i index 395406d7f6..6277387e2c 100644 --- a/ortools/linear_solver/java/linear_solver.i +++ b/ortools/linear_solver/java/linear_solver.i @@ -25,9 +25,10 @@ // // TODO(user): unit test all the APIs that are currently marked with 'no test'. -%include "ortools/base/base.i" +%include // For native Java enum support. +%include -%include "enums.swg" // For native Java enum support. +%include "ortools/base/base.i" // We prefer our in-house vector wrapper to std_vector.i, because it // converts to and from native java arrays. @@ -43,6 +44,9 @@ class MPModelRequest; class MPSolutionResponse; } // namespace operations_research +typedef int64_t int64; +typedef uint64_t uint64; + %{ #include "ortools/linear_solver/linear_solver.h" %} diff --git a/ortools/util/java/vector.i b/ortools/util/java/vector.i index 21e70f72c9..badeb665e4 100644 --- a/ortools/util/java/vector.i +++ b/ortools/util/java/vector.i @@ -20,6 +20,7 @@ // // TODO(user): move to base/swig/java. +%include %include "ortools/base/base.i" %{ @@ -27,6 +28,9 @@ #include "ortools/base/integral_types.h" %} +typedef int64_t int64; +typedef uint64_t uint64; + // Typemaps to represent const std::vector& arguments as arrays of // JavaType. %define VECTOR_AS_JAVA_ARRAY(CType, JavaType, JavaTypeName)