From e803574173bdac8a7f33085a648c29eaf248a394 Mon Sep 17 00:00:00 2001
From: Uwe Hermann <uwe@hermann-uwe.de>
Date: Sat, 4 Apr 2020 21:54:13 +0200
Subject: [PATCH 1/1] bindings/java: Fix build issue with SWIG 4.x.

Tested with SWIG 3.x and SWIG 4.x.

This fixes bug #1527.
---
 bindings/java/org/sigrok/core/classes/classes.i | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/bindings/java/org/sigrok/core/classes/classes.i b/bindings/java/org/sigrok/core/classes/classes.i
index 75793b25..e953fe5d 100644
--- a/bindings/java/org/sigrok/core/classes/classes.i
+++ b/bindings/java/org/sigrok/core/classes/classes.i
@@ -94,10 +94,18 @@ VECTOR(std::shared_ptr<sigrok::HardwareDevice>, HardwareDevice)
   "java.util.Map<JKey, JValue>"
 
 %typemap(javain,
+/* SWIG 4.0.0 changed the std::map wrappers in an incompatible way. */
+#if SWIG_VERSION >= 0x040000
+    pre="  $javaclassname temp$javainput = new $javaclassname();
+    for (java.util.Map.Entry<JKey, JValue> entry : $javainput.entrySet())
+      temp$javainput.put(entry.getKey(), entry.getValue());",
+    pgcppname="temp$javainput")
+#else
     pre="  $javaclassname temp$javainput = new $javaclassname();
     for (java.util.Map.Entry<JKey, JValue> entry : $javainput.entrySet())
       temp$javainput.set(entry.getKey(), entry.getValue());",
     pgcppname="temp$javainput")
+#endif
   std::map< CKey, CValue > "$javaclassname.getCPtr(temp$javainput)"
 
 %typemap(javaout) std::map< CKey, CValue > {
-- 
2.24.0.rc2
