File: 0006-ability-to-inhibit-automatic-string-convertion.patch

package info (click to toggle)
camljava 0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 260 kB
  • ctags: 259
  • sloc: ansic: 813; ml: 333; java: 302; makefile: 86
file content (73 lines) | stat: -rw-r--r-- 2,301 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
From: Stefano Zacchiroli <zack@upsilon.cc>
Date: Sat, 28 Nov 2009 10:38:01 +0100
Subject: [PATCH] ability to inhibit automatic string convertion

Rationale: automatic convertion of Java string to OCaml string is not always
desirable (e.g. because Java strings are real Unicode string whereas OCaml's
are not). Using this patch automatic conversion can be globally disabled by
CamlJava users.

This ability is used by O'Jacare.
---
 lib/jni.mli    |    2 ++
 lib/jni.mlp    |    2 ++
 lib/jnistubs.c |   12 +++++++++++-
 3 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/lib/jni.mli b/lib/jni.mli
index ad829b3..db71589 100644
--- a/lib/jni.mli
+++ b/lib/jni.mli
@@ -16,6 +16,8 @@
 
 external set_debug: bool -> unit = "camljava_set_debug"
 
+external set_string_auto_conv: bool -> unit = "camljava_set_strconv"
+
 (* Object operations *)
 
 type obj
diff --git a/lib/jni.mlp b/lib/jni.mlp
index d1febac..108f97d 100644
--- a/lib/jni.mlp
+++ b/lib/jni.mlp
@@ -16,6 +16,8 @@
 
 external set_debug: bool -> unit = "camljava_set_debug"
 
+external set_string_auto_conv: bool -> unit = "camljava_set_strconv"
+
 external init: string -> unit = "camljava_Init"
 external shutdown: unit -> unit = "camljava_Shutdown"
 
diff --git a/lib/jnistubs.c b/lib/jnistubs.c
index 27ff365..bfc6c9d 100644
--- a/lib/jnistubs.c
+++ b/lib/jnistubs.c
@@ -523,6 +523,15 @@ value camljava_MakeJavaString (value vstr)
   return alloc_jobject(jstr);
 }
 
+/* Automatically convert Java string to Caml string?
+   True by default; globally set to false by O'Jacare. */
+static int string_auto_conv = 1;
+
+value camljava_set_strconv(value v) {
+  string_auto_conv = Bool_val(v);
+  return Val_unit;
+}
+
 static value extract_java_string (JNIEnv * env, jstring jstr)
 {
   jsize len;
@@ -852,7 +861,8 @@ static value camljava_callback(JNIEnv * env,
       else if ((*env)->IsInstanceOf(env, arg, caml_double))
         carg = copy_double((*env)->GetDoubleField(env, arg,
                                                 caml_double_contents));
-      else if ((*env)->IsInstanceOf(env, arg, java_lang_string))
+      else if (string_auto_conv
+	       && (*env)->IsInstanceOf(env, arg, java_lang_string))
         carg = extract_java_string(env, (jstring) arg);
       else
         carg = alloc_jobject(arg);
--