annotate libinterp/octave-value/ov-java.cc @ 33634:4a70f390c85e default tip @

maint: Merge stable to default.
author Markus Mützel <markus.muetzel@gmx.de>
date Tue, 28 May 2024 15:25:54 +0200
parents a5217e6ed309
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31845
diff changeset
3 // Copyright (C) 2007-2024 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
26
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
27 //! @file ov-java.cc
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
28 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
29 //! Provides Octave's Java interface.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
30
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
31 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21211
diff changeset
32 # include "config.h"
15736
6faa01ff2967 build: Add --disable-java option to configure (bug #37838).
Rik <rik@octave.org>
parents: 15625
diff changeset
33 #endif
6faa01ff2967 build: Add --disable-java option to configure (bug #37838).
Rik <rik@octave.org>
parents: 15625
diff changeset
34
15755
3216dafbbd48 ov-java.cc: Correcty typo HAVE_WINDWOS_H to HAVE_WINDOWS_H
Rik <rik@octave.org>
parents: 15754
diff changeset
35 #if defined (HAVE_WINDOWS_H)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21042
diff changeset
36 # include <windows.h>
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #endif
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include <algorithm>
28492
ae4cdbe75992 Use C++11 container for array of strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28491
diff changeset
40 #include <array>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
41 #include <fstream>
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25337
diff changeset
42 #include <map>
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
43 #include <string>
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
44 #include <vector>
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 #include <clocale>
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
48 #include "Cell.h"
23129
35e3d199527c Replace feval calls with direct call to C++ function (bug #50116).
Rik <rik@octave.org>
parents: 23084
diff changeset
49 #include "builtin-defun-decls.h"
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
50 #include "cmd-edit.h"
25460
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
51 #include "defaults.h"
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
52 #include "defun.h"
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
53 #include "error.h"
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
54 #include "errwarn.h"
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
55 #include "file-ops.h"
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
56 #include "file-stat.h"
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
57 #include "fpucw-wrappers.h"
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26009
diff changeset
58 #include "interpreter.h"
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26009
diff changeset
59 #include "interpreter-private.h"
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
60 #include "load-path.h"
25548
d6050ba12c0c Call get_ASCII_filename for std::ifstream (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25460
diff changeset
61 #include "lo-sysdep.h"
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
62 #include "oct-env.h"
27003
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
63 #include "oct-process.h"
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
64 #include "oct-shlib.h"
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
65 #include "ov-java.h"
15747
4be890c5527c * __java__.cc, __java__.h: Clean up lists of include files.
John W. Eaton <jwe@octave.org>
parents: 15746
diff changeset
66 #include "variables.h"
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
67
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
68 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
69 #include <jni.h>
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
70 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
71
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
72 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
73
27003
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
74 // FIXME: Should these values be configurable at run time?
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
75
25770
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
76 #if defined (OCTAVE_USE_WINDOWS_API)
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
77 # define LIBJVM_FILE_NAME "jvm.dll"
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
78 #elif defined (__APPLE__)
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
79 # define LIBJVM_FILE_NAME "libjvm.dylib"
27003
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
80 # define JAVA_HOME_CMD "/usr/libexec/java_home"
25770
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
81 #else
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
82 # define LIBJVM_FILE_NAME "libjvm.so"
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
83 #endif
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
84
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
85 #define TO_JOBJECT(obj) reinterpret_cast<jobject> (obj)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
86 #define TO_JCLASS(obj) reinterpret_cast<jclass> (obj)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
87
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
88 #define TO_JNIENV(env) reinterpret_cast<JNIEnv *> (env)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
89
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
90 typedef jint (JNICALL *JNI_CreateJavaVM_t) (JavaVM **pvm, JNIEnv **penv,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
91 void *args);
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
92
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
93 typedef jint (JNICALL *JNI_GetCreatedJavaVMs_t) (JavaVM **pvm, jsize bufLen,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
94 jsize *nVMs);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
96 template <typename T>
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
97 class java_local_ref
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
98 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
99 public:
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
100
30137
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
101 java_local_ref (JNIEnv *env)
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
102 : m_jobj (nullptr), m_detached (false), m_env (env) { }
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
103
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
104 java_local_ref (JNIEnv *env, T obj)
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
105 : m_jobj (obj), m_detached (false), m_env (env) { }
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
106
32832
f3c1a77bcc6b maint: Replace (void) in function declarations with () where possible
Arun Giridhar <arungiridhar@gmail.com>
parents: 32660
diff changeset
107 ~java_local_ref () { release (); }
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
108
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
109 T& operator = (T obj)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
110 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
111 release ();
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
112
30137
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
113 m_jobj = obj;
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
114 m_detached = false;
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
115
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
116 return m_jobj;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
117 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
118
30137
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
119 operator bool () const { return (m_jobj != 0); }
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
120 operator T () { return m_jobj; }
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
121
32832
f3c1a77bcc6b maint: Replace (void) in function declarations with () where possible
Arun Giridhar <arungiridhar@gmail.com>
parents: 32660
diff changeset
122 void detach () { m_detached = true; }
30137
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
123
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
124 protected:
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
125
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
126 T m_jobj;
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
127 bool m_detached;
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
128 JNIEnv *m_env;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
129
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
130 private:
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
131
32832
f3c1a77bcc6b maint: Replace (void) in function declarations with () where possible
Arun Giridhar <arungiridhar@gmail.com>
parents: 32660
diff changeset
132 java_local_ref ()
30137
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
133 : m_jobj (0), m_detached (false), m_env (0)
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
134 { }
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
135
32832
f3c1a77bcc6b maint: Replace (void) in function declarations with () where possible
Arun Giridhar <arungiridhar@gmail.com>
parents: 32660
diff changeset
136 void release ()
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
137 {
30137
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
138 if (m_env && m_jobj && ! m_detached)
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
139 m_env->DeleteLocalRef (m_jobj);
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
140
14214fbfa258 maint: use "m_" prefix for member variables in class java_local_ref.
Rik <rik@octave.org>
parents: 30133
diff changeset
141 m_jobj = nullptr;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
142 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
143
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
144 };
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
145
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
146 typedef java_local_ref<jobject> jobject_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
147 typedef java_local_ref<jclass> jclass_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
148 typedef java_local_ref<jstring> jstring_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
149 typedef java_local_ref<jobjectArray> jobjectArray_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
150 typedef java_local_ref<jintArray> jintArray_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
151 typedef java_local_ref<jbyteArray> jbyteArray_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
152 typedef java_local_ref<jdoubleArray> jdoubleArray_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
153 typedef java_local_ref<jthrowable> jthrowable_ref;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
154
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
155 static std::string
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
156 jstring_to_string (JNIEnv *jni_env, jstring s);
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
157
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
158 static std::string
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
159 jstring_to_string (JNIEnv *jni_env, jobject obj);
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
160
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
161 static octave_value
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23449
diff changeset
162 box (JNIEnv *jni_env, void *jobj, void *jcls_arg = nullptr);
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
163
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
164 static octave_value
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23449
diff changeset
165 box_more (JNIEnv *jni_env, void *jobj_arg, void *jcls_arg = nullptr);
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
166
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
167 static bool
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
168 unbox (JNIEnv *jni_env, const octave_value& val, jobject_ref& jobj,
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
169 jclass_ref& jcls);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
170
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
171 static bool
23449
c763214a8260 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23447
diff changeset
172 unbox (JNIEnv *jni_env, const octave_value_list& args,
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
173 jobjectArray_ref& jobjs, jobjectArray_ref& jclss);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
174
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
175 extern "C"
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
176 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
177 JNIEXPORT jboolean JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
178 Java_org_octave_Octave_call (JNIEnv *, jclass, jstring, jobjectArray,
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
179 jobjectArray);
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
180
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
181 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
182 Java_org_octave_OctaveReference_doFinalize (JNIEnv *, jclass, jint);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
183
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
184 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
185 Java_org_octave_Octave_doInvoke (JNIEnv *, jclass, jint, jobjectArray);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
187 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
188 Java_org_octave_Octave_doEvalString (JNIEnv *, jclass, jstring);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
189
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
190 JNIEXPORT jboolean JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
191 Java_org_octave_Octave_needThreadedInvokation (JNIEnv *, jclass);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
192 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
193
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
194 //! The pointer to a java virtual machine either created in the current thread
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
195 //! or attached this thread to it.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
196
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23449
diff changeset
197 static JavaVM *jvm = nullptr;
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
198
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
199 //! Whether the current thread is attached to the jvm given by #jvm.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
200 //! This is @c false also if no jvm exists, i.e. if #jvm is @c nullptr.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
201 //! @see #initialize_jvm()
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
202 //! @see #terminate_jvm()
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
203
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 static bool jvm_attached = false;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
206 //! Need to keep hold of the shared library handle until exit.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
207 //! @see #initialize_jvm()
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
208 //! @see #terminate_jvm()
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
209
21750
6720e5a220ba use namespace for octave_shlib class
John W. Eaton <jwe@octave.org>
parents: 21748
diff changeset
210 static octave::dynamic_library jvm_lib;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
212 static std::map<int, octave_value> listener_map;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
213 static std::map<int, octave_value> octave_ref_map;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 static int octave_java_refcount = 0;
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
215
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
216 //! The thread id of the currently executing thread or @c -1 if this is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
217 //! unknown.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
218 //! @see #initialize_java()
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
219
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220 static long octave_thread_ID = -1;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
222 bool Vjava_matrix_autoconversion = false;
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
223 bool Vjava_unsigned_autoconversion = true;
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
224 bool Vdebug_java = false;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31105
diff changeset
226 OCTAVE_BEGIN_NAMESPACE(octave)
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
227
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
228 class JVMArgs
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
229 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
230 public:
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
231
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
232 JVMArgs ()
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
233 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
234 m_vm_args.version = JNI_VERSION_1_6;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
235 m_vm_args.nOptions = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
236 m_vm_args.options = nullptr;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
237 m_vm_args.ignoreUnrecognized = false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
238 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
239
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
240 ~JVMArgs ()
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
241 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
242 clean ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
243 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
244
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
245 JavaVMInitArgs * to_args ()
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
246 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
247 update ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
248 return &m_vm_args;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
249 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
250
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
251 void add (const std::string& opt)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
252 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
253 m_java_opts.push_back (opt);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
254 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
255
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
256 void read_java_opts (const std::string& filename)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
257 {
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
258 std::ifstream js = sys::ifstream (filename.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
259
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
260 if (! js.bad () && ! js.fail ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
261 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
262 std::string line;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
263
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
264 while (! js.eof () && ! js.fail ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
265 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
266 std::getline (js, line);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
267
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
268 if (line.find ('-') == 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
269 m_java_opts.push_back (line);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
270 else if (line.length () > 0 && Vdebug_java)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
271 warning ("invalid JVM option, skipping: %s", line.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
272 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
273 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
274 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
275
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
276 private:
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
277
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
278 void clean ()
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
279 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
280 if (m_vm_args.options != nullptr)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
281 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
282 for (int i = 0; i < m_vm_args.nOptions; i++)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
283 delete [] m_vm_args.options[i].optionString;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
284
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
285 delete [] m_vm_args.options;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
286
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
287 m_vm_args.options = nullptr;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
288 m_vm_args.nOptions = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
289 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
290 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
291
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
292 void update ()
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
293 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
294 clean ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
295
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
296 if (m_java_opts.size () > 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
297 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
298 int index = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
299
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
300 m_vm_args.nOptions = m_java_opts.size ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
301 m_vm_args.options = new JavaVMOption [m_vm_args.nOptions];
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
302
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
303 for (const auto& opt : m_java_opts)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
304 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
305 if (Vdebug_java)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
306 octave_stdout << opt << std::endl;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
307 m_vm_args.options[index++].optionString = strsave (opt.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
308 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
309
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
310 m_java_opts.clear ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
311 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
312 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
313
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
314 private:
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
315
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
316 JavaVMInitArgs m_vm_args;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
317
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
318 std::list<std::string> m_java_opts;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
319 };
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
320
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31105
diff changeset
321 OCTAVE_END_NAMESPACE(octave)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
323 //! The java initialization directory is given by the environment variable
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
324 //! @c OCTAVE_JAVA_DIR if defined; otherwise it is the directory of Octave's
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
325 //! m-files defining Java functions.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
326 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
327 //! The Java initialization directory is the directory where resides:
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
328 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
329 //! - @c octave.jar, defining the java classes implementing octave's java
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
330 //! interface,
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
331 //! - @c javaclasspath.txt, defining the installation defined portion of the
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
332 //! (static) classpath,
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
333 //! - @c java.opts, defining the configurable options of the java virtual
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
334 //! machine.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
335 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
336 //! Note that the (static) java classpath of the java virtual machine starts
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
337 //! with @c octave.jar, and that the static java classpath ends with what
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
338 //! is read from @c javaclasspath.txt located in the initial java directory.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
339 //! Moreover, the java virtual machine is created essentially with
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
340 //! the options given by @c java.opts.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
341
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
342 static std::string
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
343 initial_java_dir ()
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
344 {
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
345 static std::string java_dir;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
346
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
347 if (java_dir.empty ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
348 {
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
349 java_dir = octave::sys::env::getenv ("OCTAVE_JAVA_DIR");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
350
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
351 if (java_dir.empty ())
25460
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
352 java_dir = (octave::config::fcn_file_dir ()
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
353 + octave::sys::file_ops::dir_sep_str () + "java");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
354 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
355
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
356 return java_dir;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
357 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
359 //! Return the classpath in the given file @c filepath as a string.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
360 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
361 //! In the classpath file, each line which is neither empty nor a comment, is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
362 //! interpreted as a segment of a path. Comment lines are those starting with
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
363 //! a @c # or with a @c % in the very first column.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
364 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
365 //! @param filepath The path to the file (usually @c classpath.txt) containing
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
366 //! a portion of the classpath.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
367 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
368 //! @returns A string consisting of the lines of @c filepath which are neither
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
369 //! comments nor empty without trailing whitespace separated by
27216
823b4bcf79fc unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents: 27126
diff changeset
370 //! 'octave::directory_path::path_sep_str()'. The returned string also
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
371 //! starts with that path separator.
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
372
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
373 static std::string
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
374 read_classpath_txt (const std::string& filepath)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
375 {
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
376 std::string classpath;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
377
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28996
diff changeset
378 std::ifstream fs = octave::sys::ifstream (filepath.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
379
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
380 if (! fs.bad () && ! fs.fail ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
381 {
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
382 std::string line;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
383
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
384 while (! fs.eof () && ! fs.fail ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
385 {
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
386 std::getline (fs, line);
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
387 if (line.length () > 0 && line[0] != '#' && line[0] != '%')
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
388 {
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
389 // prepend separator character
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
390 classpath.append (octave::directory_path::path_sep_str ());
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
391
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
392 // append content of line without whitespace
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
393 int last = line.find_last_not_of (" \t\f\v\r\n");
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
394
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
395 classpath.append (octave::sys::file_ops::tilde_expand (line.substr (0, last+1)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
396 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
397 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
398 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
399
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
400 return (classpath);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
401 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
403 //! Return the initial classpath.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
404 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
405 //! The initial classpath starts with a pointer to @c octave.jar which is
33080
d911fafcf27a * ov-java.cc: Fix some Doxygen comments.
John W. Eaton <jwe@octave.org>
parents: 32632
diff changeset
406 //! located in the initial java directory given by #initial_java_dir().
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
407 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
408 //! @attention This is nowhere documented and also the script
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
409 //! @c javaclasspath.m drops this. On the other hand, this is vital because
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
410 //! @c octave.jar contains the java core classes of octave's java interface.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
411 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
412 //! The rest of the classpath is read sequentially from files
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
413 //! @c javaclasspath.txt located in either:
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
414 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
415 //! - the current directory,
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
416 //! - the user's home directory,
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
417 //! - the initial java directory returned by #initial_java_dir()
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
418 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
419 //! @returns The initial classpath.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
420
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
421 static std::string
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
422 initial_class_path ()
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423 {
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
424 std::string java_dir = initial_java_dir ();
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
425
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
426 std::string retval = java_dir;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
427
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
428 // Find octave.jar file.
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
429 if (! retval.empty ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430 {
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
431 std::string sep = octave::sys::file_ops::dir_sep_str ();
15752
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
432
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
433 std::string jar_file = java_dir + sep + "octave.jar";
f96faf028d90 make java functions part of core octave_value classes
John W. Eaton <jwe@octave.org>
parents: 15747
diff changeset
434
21736
0504351a45e6 use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
435 octave::sys::file_stat jar_exists (jar_file);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
436
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
437 if (jar_exists)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
438 {
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
439 // Initialize static classpath to octave.jar.
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
440 retval = jar_file;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
441
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
442 // The base classpath has been set.
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
443 // Try to find an optional file specifying classpaths in 3 places.
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
444 // 1) Current directory
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
445 // 2) User's home directory
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
446 // 3) Octave installation directory where octave.jar resides
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
447
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
448 std::string cwd = octave::sys::env::get_current_directory ();
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
449 std::string home_dir = octave::sys::env::get_home_directory ();
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
450
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
451 // The filename is "javaclasspath.txt", but historically has been
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
452 // "classpath.txt" so both are supported.
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
453 std::vector<std::string> cp_list = {"javaclasspath.txt",
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
454 "classpath.txt"
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
455 };
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
456
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
457 for (std::string filename : cp_list)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
458 {
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
459 std::string cp_file = filename;
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23804
diff changeset
460 octave::sys::file_stat cp_exists;
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
461
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
462 // Try to find classpath file in the current directory.
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
463
21736
0504351a45e6 use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
464 cp_exists = octave::sys::file_stat (cp_file);
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
465 if (cp_exists)
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
466 {
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
467 // File found. Add its contents to the static classpath.
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
468 std::string classpath = read_classpath_txt (cp_file);
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
469 retval.append (classpath);
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
470 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
471
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
472 // Try to find classpath file in the user's home directory.
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
473
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
474 if (cwd != home_dir)
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
475 {
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23804
diff changeset
476 cp_file = '~' + sep + filename;
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
477 cp_file = octave::sys::file_ops::tilde_expand (cp_file);
21736
0504351a45e6 use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
478 cp_exists = octave::sys::file_stat (cp_file);
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
479 if (cp_exists)
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
480 {
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
481 // File found. Add its contents to the static classpath.
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
482 std::string classpath = read_classpath_txt (cp_file);
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
483 retval.append (classpath);
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
484 }
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
485 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
486
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
487 // Try to find classpath file in the Octave install directory.
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
488
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
489 if (cwd != java_dir)
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
490 {
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
491 cp_file = java_dir + sep + filename;
21736
0504351a45e6 use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
492 cp_exists = octave::sys::file_stat (cp_file);
20422
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
493 if (cp_exists)
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
494 {
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
495 // File found. Add its contents to the static classpath.
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
496 std::string classpath = read_classpath_txt (cp_file);
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
497 retval.append (classpath);
4262598620ae Don't add duplicates to javaclasspath when run in home directory (bug #45683).
Rik <rik@octave.org>
parents: 20274
diff changeset
498 }
15797
492893b98eef Search for "javaclasspath.txt" as well as "classpath.txt" to set static class path.
Rik <rik@octave.org>
parents: 15792
diff changeset
499 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
500 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
501 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
502 else
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
503 error ("octave.jar does not exist: %s", jar_file.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
504 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
505 else
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
506 error ("initial java dir is empty");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
507
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
508 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
509 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
510
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
511 static std::string
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
512 get_jvm_lib_path_in_subdir (std::string java_home_path)
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
513 {
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
514 // This assumes that whatever architectures are installed are appropriate for
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
515 // this machine
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
516 #if defined (OCTAVE_USE_WINDOWS_API)
28492
ae4cdbe75992 Use C++11 container for array of strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28491
diff changeset
517 const std::array<const std::string, 2> subdirs = {"bin/client", "bin/server"};
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
518 #else
28492
ae4cdbe75992 Use C++11 container for array of strings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28491
diff changeset
519 const std::array<const std::string, 8> subdirs =
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
520 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
521 "jre/lib/server", "jre/lib", "lib/client", "lib/server",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
522 "jre/lib/amd64/client", "jre/lib/amd64/server",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
523 "jre/lib/i386/client", "jre/lib/i386/server"
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
524 };
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
525 #endif
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
526
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29569
diff changeset
527 for (std::size_t i = 0; i < subdirs.size (); i++)
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
528 {
25770
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
529 std::string candidate = java_home_path + "/" + subdirs[i]
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
530 + "/" LIBJVM_FILE_NAME;
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
531 if (octave::sys::file_stat (candidate))
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
532 return candidate;
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
533 }
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
534 return "";
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
535 }
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
536
24684
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
537 #if defined (OCTAVE_USE_WINDOWS_API)
27126
3d9e72cac668 allow Windows build to work again
John W. Eaton <jwe@octave.org>
parents: 27108
diff changeset
538
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31105
diff changeset
539 OCTAVE_BEGIN_NAMESPACE(octave)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
540 // Declare function defined in sysdep.cc
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
541 extern LONG
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
542 get_regkey_value (HKEY h_rootkey, const std::string subkey,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
543 const std::string name, octave_value& value);
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31105
diff changeset
544 OCTAVE_END_NAMESPACE(octave)
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
545
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
546 static std::string
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
547 get_jvm_lib_path_from_registry ()
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
548 {
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
549 // In Windows, find the location of the JRE from the registry
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
550 std::string key, jversion, value;
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
551
28996
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
552 // First search for JRE >= 15
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
553 key = R"(software\javasoft\jdk)";
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
554
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
555 jversion = octave::sys::env::getenv ("JAVA_VERSION");
28996
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
556 bool maybe_version_15_or_newer = true;
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
557 octave_value regval;
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
558 LONG retval;
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
559 if (jversion.empty ())
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
560 {
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
561 value = "CurrentVersion";
28996
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
562 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
563 regval);
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
564
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
565 if (retval != ERROR_SUCCESS)
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
566 {
28996
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
567 // Search for JRE < 15
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
568 maybe_version_15_or_newer = false;
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
569 key = R"(software\javasoft\jre)";
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
570 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
571 regval);
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
572
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
573 if (retval != ERROR_SUCCESS)
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
574 {
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
575 // Search for JRE < 9
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
576 key = R"(software\javasoft\java runtime environment)";
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
577 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key,
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
578 value, regval);
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
579 }
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
580 }
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
581
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
582 if (retval != ERROR_SUCCESS)
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
583 error ("unable to find Java Runtime Environment: %s::%s",
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
584 key.c_str (), value.c_str ());
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
585
28996
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
586 jversion = regval.xstring_value ("initialize_jvm: registry value "
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
587 R"("%s" at "%s" must be a string)",
27276
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27216
diff changeset
588 value.c_str (), key.c_str ());
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
589 }
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
590
28996
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
591 std::string jvm_lib_path;
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
592 if (maybe_version_15_or_newer)
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
593 {
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
594 // Look for value used by JRE >= 15
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
595 key = key + '\\' + jversion;
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
596 value = "JavaHome";
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
597 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
598 regval);
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
599
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
600 if (retval != ERROR_SUCCESS)
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
601 error ("unable to find Java Runtime Environment: %s::%s",
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
602 key.c_str (), value.c_str ());
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
603
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
604 jvm_lib_path
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
605 = regval.xstring_value (R"(initialize_jvm: registry value "%s" at )"
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
606 R"("%s" must be a string)",
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
607 value.c_str (), key.c_str ())
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
608 + R"(\bin\server\jvm.dll)";
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
609
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
610 if (! jvm_lib_path.empty ())
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
611 return jvm_lib_path;
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
612
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
613 }
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
614
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
615 // Search for JRE < 15
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
616 key = R"(software\javasoft\jre\)" + jversion;
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
617 value = "RuntimeLib";
28996
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
618 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
619 regval);
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
620
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
621 if (retval != ERROR_SUCCESS)
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
622 {
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
623 // Search for JRE < 9
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
624 key = R"(software\javasoft\java runtime environment\)" + jversion;
28996
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
625 retval = octave::get_regkey_value (HKEY_LOCAL_MACHINE, key, value,
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
626 regval);
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
627 }
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
628
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
629 if (retval != ERROR_SUCCESS)
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
630 error ("unable to find Java Runtime Environment: %s::%s",
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
631 key.c_str (), value.c_str ());
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
632
28996
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
633 jvm_lib_path
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
634 = regval.xstring_value (R"(initialize_jvm: registry value "%s" at )"
55bdcab3d85b Detect Java versions >= 15 on Windows (bug #59215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28889
diff changeset
635 R"("%s" must be a string)",
27276
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27216
diff changeset
636 value.c_str (), key.c_str ());
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
637
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
638 if (jvm_lib_path.empty ())
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
639 error ("unable to find Java Runtime Environment: %s::%s",
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
640 key.c_str (), value.c_str ());
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
641
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
642 return jvm_lib_path;
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
643 }
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
644
24684
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
645 #endif
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
646
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
647 //! Initialize the java virtual machine (jvm) and field #jvm if necessary.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
648 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
649 //! If the jvm exists and is initialized, #jvm points to it, i.e. is not 0
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
650 //! and there is nothing to do.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
651 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
652 //! If #jvm is 0 and if at least one jvm exists, attach the current thread to
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
653 //! it by setting #jvm_attached. Otherwise, create a #jvm with some hard-
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
654 //! coded options:
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
655 //!
27216
823b4bcf79fc unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents: 27126
diff changeset
656 //! - '-Djava.class.path=classpath', where @c classpath is given by
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
657 //! #initial_class_path().
27216
823b4bcf79fc unless necessary for formatting or code, use ' instead of `
John W. Eaton <jwe@octave.org>
parents: 27126
diff changeset
658 //! - '-Xrs'
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
659 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
660 //! Further options are read from the file @c java.opts in the directory given
33080
d911fafcf27a * ov-java.cc: Fix some Doxygen comments.
John W. Eaton <jwe@octave.org>
parents: 32632
diff changeset
661 //! by #initial_java_dir().
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
662 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
663 //! Note that #initial_class_path() determines the initial classpath. This
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
664 //! is the static classpath which cannot be changed. Elements of the dynamic
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
665 //! classpath can be added and removed using the m-file scripts
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
666 //! @c javaaddpath.m and @c javarmpath.m.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
667 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
668 //! @see #terminate_jvm()
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
669
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
670 static void
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
671 initialize_jvm ()
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
672 {
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
673 // Most of the time JVM already exists and has been initialized.
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
674 // Also it seems, as if jvm is set, the jvm is already attached.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
675 // This does not fit terminate_jvm.
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
676 if (jvm)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
677 return;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
678
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
679 JNIEnv *current_env;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
680 const char *static_locale = setlocale (LC_ALL, nullptr);
26532
4dae224112a1 ov-java.cc: Fix static analyzer detected issue (bug #55464).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
681 std::string locale;
4dae224112a1 ov-java.cc: Fix static analyzer detected issue (bug #55464).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
682 if (static_locale)
4dae224112a1 ov-java.cc: Fix static analyzer detected issue (bug #55464).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
683 locale = std::string (static_locale);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
684
24684
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
685 octave::dynamic_library lib ("");
27003
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
686 std::string jvm_lib_path;
24684
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
687
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
688 // Check whether the Java VM library is already loaded or linked in.
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
689 JNI_CreateJavaVM_t create_vm = reinterpret_cast<JNI_CreateJavaVM_t>
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
690 (lib.search ("JNI_CreateJavaVM"));
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
691 JNI_GetCreatedJavaVMs_t get_vm = reinterpret_cast<JNI_GetCreatedJavaVMs_t>
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
692 (lib.search ("JNI_GetCreatedJavaVMs"));
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
693
27003
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
694 if (create_vm && get_vm)
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
695 jvm_lib_path = "linked in or loaded libraries";
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
696 else
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
697 {
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
698 // JAVA_HOME environment variable takes precedence
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
699 std::string java_home_env = octave::sys::env::getenv ("JAVA_HOME");
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
700 if (! java_home_env.empty ())
25770
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
701 {
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
702 jvm_lib_path = get_jvm_lib_path_in_subdir (java_home_env);
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
703
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
704 // If JAVA_HOME does not look like a Java directory, use it anyway
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
705 // to fail with a useful error message indicating the directory
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
706 if (jvm_lib_path.empty ())
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
707 jvm_lib_path = java_home_env + "/" LIBJVM_FILE_NAME;
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
708 }
27003
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
709
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
710 # if defined (__APPLE__)
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
711 // Use standard /usr/libexec/java_home if available.
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
712 if (jvm_lib_path.empty ())
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
713 {
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
714 octave::sys::file_stat libexec_java_home_exists (JAVA_HOME_CMD);
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
715 if (libexec_java_home_exists)
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
716 {
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
717 // FIXME: Should this command be fully configurable at run
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
718 // time? Or is it OK for the options to be fixed here?
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
719
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
720 std::string java_home_cmd = std::string (JAVA_HOME_CMD)
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
721 + " --failfast --version 1.6+ 2>/dev/null";
27003
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
722
27006
cdc67ea473d1 Fix build failure on macOS due to missing namespace qualification.
Andrew Janke <andrew@apjanke.net>
parents: 27003
diff changeset
723 octave::process_execution_result rslt
27003
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
724 = octave::run_command_and_return_output (java_home_cmd);
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
725
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
726 if (rslt.exit_status () == 0)
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
727 {
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
728 std::string output = rslt.stdout_output ();
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
729 std::string found_path = output.substr (0, output.length() - 1);
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
730 std::string jvm_lib_found = get_jvm_lib_path_in_subdir (found_path);
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
731 if (!jvm_lib_found.empty ())
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
732 jvm_lib_path = jvm_lib_found;
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
733 }
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
734 }
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
735 }
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
736 # endif
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
737
2a57165f892c detect JVM at run time on macOS (bug #54219)
Andrew Janke <andrew@apjanke.net>
parents: 26568
diff changeset
738 if (jvm_lib_path.empty ())
25770
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
739 {
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
740 #if defined (OCTAVE_USE_WINDOWS_API)
25770
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
741 jvm_lib_path = get_jvm_lib_path_from_registry ();
20945
9d9270e2f98f eliminate comments after preprocessor conditionals
John W. Eaton <jwe@octave.org>
parents: 20939
diff changeset
742 #else
25770
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
743 // Fall back to JAVA_LDPATH, determined by the build system
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
744 jvm_lib_path = std::string (JAVA_LDPATH) + "/" LIBJVM_FILE_NAME;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
745 #endif
25770
374edade7b1b fix use of JAVA_HOME to fail if not found and fall back correctly (bug #40111)
Mike Miller <mtmiller@octave.org>
parents: 25744
diff changeset
746 }
25744
3ddd74bd7b11 Use JAVA_HOME for JVM detection at run-time (bug #40111).
Andrew Janke <andrew@apjanke.net>
parents: 25604
diff changeset
747
24684
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
748 lib = octave::dynamic_library (jvm_lib_path);
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
749
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
750 if (! lib)
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
751 error ("unable to load Java Runtime Environment from %s",
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
752 jvm_lib_path.c_str ());
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
753
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
754 create_vm = reinterpret_cast<JNI_CreateJavaVM_t>
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
755 (lib.search ("JNI_CreateJavaVM"));
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
756 get_vm = reinterpret_cast<JNI_GetCreatedJavaVMs_t>
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
757 (lib.search ("JNI_GetCreatedJavaVMs"));
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
758
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
759 if (! create_vm)
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
760 error ("unable to find JNI_CreateJavaVM in %s", jvm_lib_path.c_str ());
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
761
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
762 if (! get_vm)
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
763 error ("unable to find JNI_GetCreatedJavaVMs in %s",
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
764 jvm_lib_path.c_str ());
037ace76257d ov-java.cc: Use new functions in initialization of JVM.
Markus Mützel <markus.muetzel@gmx.de>
parents: 24671
diff changeset
765 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
766
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
767 //! The number of created jvm's.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
768 jsize nVMs = 0;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
769
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
770 if (get_vm (&jvm, 1, &nVMs) == 0 && nVMs > 0)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
771 {
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
772 // At least one JVM exists, try to attach the current thread to it.
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
773
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
774 switch (jvm->GetEnv (reinterpret_cast<void **> (&current_env),
23929
20c83f619102 bump Java compatibility level to 1.6, minimum supported by Java 9 (bug #51803)
Mike Miller <mtmiller@octave.org>
parents: 23807
diff changeset
775 JNI_VERSION_1_6))
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
776 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
777 case JNI_EDETACHED:
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
778 // Attach the current thread
30064
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
779 JavaVMAttachArgs m_vm_args;
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
780 m_vm_args.version = JNI_VERSION_1_6;
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
781 m_vm_args.name = const_cast<char *> ("octave");
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
782 m_vm_args.group = nullptr;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
783 if (jvm->AttachCurrentThread (reinterpret_cast<void **> (&current_env),
30064
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
784 &m_vm_args) < 0)
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
785 error ("JVM internal error, unable to attach octave to existing JVM");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
786 break;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
787
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
788 case JNI_EVERSION:
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
789 error ("JVM internal error, the required JNI version is not supported");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
790
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
791 case JNI_OK:
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
792 // Don't do anything, the current thread is already attached to JVM
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
793 break;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
794 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
795
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
796 jvm_attached = true;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
797 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
798 else
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
799 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
800 // No JVM exists, create one
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
801
30064
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
802 octave::JVMArgs m_vm_args;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
803
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
804 // Hard-coded options for the jvm.
30064
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
805 m_vm_args.add ("-Djava.class.path=" + initial_class_path ());
28527
9e7b2625e574 ov-java.cc: Set reaper thread to use default stack size (bug #58641).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28490
diff changeset
806 #if defined (HAVE_BROKEN_PTHREAD_STACKSIZE)
30064
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
807 m_vm_args.add ("-Djdk.lang.processReaperUseDefaultStackSize=true");
28527
9e7b2625e574 ov-java.cc: Set reaper thread to use default stack size (bug #58641).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28490
diff changeset
808 #endif
30064
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
809 m_vm_args.add ("-Xrs");
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
810
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
811 // Additional options given by file java.opts.
30064
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
812 m_vm_args.read_java_opts (initial_java_dir () +
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
813 octave::sys::file_ops::dir_sep_str () +
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
814 "java.opts");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
815
30064
0d32dcc699cd maint: use "m_" prefix for member variables in class JVMArgs.
Rik <rik@octave.org>
parents: 30045
diff changeset
816 if (create_vm (&jvm, &current_env, m_vm_args.to_args ()) != JNI_OK)
21380
460943554233 * ov-java.cc: Call error instead of throwing std::string objects.
John W. Eaton <jwe@octave.org>
parents: 21379
diff changeset
817 error ("unable to start Java VM in %s", jvm_lib_path.c_str ());
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
818 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
819
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
820 jvm_lib = lib;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
821
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
822 setlocale (LC_ALL, locale.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
823 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
824
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
825 //! Terminate the current jvm, if there is any.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
826 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
827 //! Otherwise, detach the jvm if this thread is attached to it and unload it
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
828 //! if this thread created it itself.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
829 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
830 //! @see #initialize_jvm()
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
831
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
832 static void
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
833 terminate_jvm ()
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
834 {
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
835 // There is nothing to do if jvm is not set (= nullptr).
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
836 if (jvm)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
837 {
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
838 // FIXME: Seems that if jvm_attached is always true if jvm is not null.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
839 if (jvm_attached)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
840 jvm->DetachCurrentThread ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
841 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
842 jvm->DestroyJavaVM ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
843
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
844 jvm = nullptr;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
845 jvm_attached = false;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
846
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
847 if (jvm_lib)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
848 jvm_lib.close ();
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
849
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
850 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
851 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
852 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
853
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
854 //! Converts a Java string object to std::string.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
855 //!{
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
856 static std::string
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
857 jstring_to_string (JNIEnv *jni_env, jstring s)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
858 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
859 std::string retval;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
860
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
861 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
862 {
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
863 const char *cstr = jni_env->GetStringUTFChars (s, nullptr);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
864 retval = cstr;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
865 jni_env->ReleaseStringUTFChars (s, cstr);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
866 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
867
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
868 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
869 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
870
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
871 static std::string
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
872 jstring_to_string (JNIEnv *jni_env, jobject obj)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
873 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
874 std::string retval;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
875
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
876 if (jni_env && obj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
877 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
878 jclass_ref cls (jni_env, jni_env->FindClass ("java/lang/String"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
879 if (cls)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
880 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
881 if (jni_env->IsInstanceOf (obj, cls))
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
882 retval = jstring_to_string (jni_env,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
883 reinterpret_cast<jstring> (obj));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
884 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
885 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
886
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
887 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
888 }
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
889 //!}
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
890
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
891 //! Returns a reference to the jni (java native interface) environment of the
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
892 //! Java virtual machine #jvm.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
893 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
894 //! @returns A reference to jni, if #jvm is present, otherwise @c nullptr.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
895
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
896 static inline JNIEnv *
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
897 thread_jni_env ()
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
898 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23449
diff changeset
899 JNIEnv *env = nullptr;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
900
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
901 if (jvm)
23929
20c83f619102 bump Java compatibility level to 1.6, minimum supported by Java 9 (bug #51803)
Mike Miller <mtmiller@octave.org>
parents: 23807
diff changeset
902 jvm->GetEnv (reinterpret_cast<void **> (&env), JNI_VERSION_1_6);
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
903
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
904 return env;
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
905 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
906
33361
a5217e6ed309 * ov-java.cc (error_unexpected): Only define if HAVE_JAVA is not undefined.
John W. Eaton <jwe@octave.org>
parents: 33353
diff changeset
907 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
908
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
909 OCTAVE_NORETURN static void
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
910 error_unexpected (const char *name)
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
911 {
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
912 error ("unexpected call to %s when HAVE_JAVA is not defined - please report this bug", name);
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
913 }
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
914
33361
a5217e6ed309 * ov-java.cc (error_unexpected): Only define if HAVE_JAVA is not undefined.
John W. Eaton <jwe@octave.org>
parents: 33353
diff changeset
915 #endif
a5217e6ed309 * ov-java.cc (error_unexpected): Only define if HAVE_JAVA is not undefined.
John W. Eaton <jwe@octave.org>
parents: 33353
diff changeset
916
15824
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
917 bool
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
918 octave_java::is_java_string () const
15824
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
919 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
920 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
921
15824
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
922 JNIEnv *current_env = thread_jni_env ();
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
923
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
924 if (current_env && m_java_object)
15824
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
925 {
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
926 jclass_ref cls (current_env, current_env->FindClass ("java/lang/String"));
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
927 return current_env->IsInstanceOf (TO_JOBJECT (m_java_object), cls);
15824
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
928 }
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
929
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
930 return false;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
931
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
932 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
933
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
934 // This shouldn't happen because construction of octave_java objects is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
935 // supposed to be impossible if Java is not available.
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
936
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
937 error_unexpected ("octave_java::is_java_string");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
938
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
939 #endif
15824
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
940 }
abc9e5f3c661 Return correct value for ischar() predicate test on octave_java objects.
Rik <rik@octave.org>
parents: 15822
diff changeset
941
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
942 bool
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
943 octave_java::is_instance_of (const std::string& cls_name) const
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
944 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
945 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
946
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
947 JNIEnv *current_env = thread_jni_env ();
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
948
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
949 std::string cls_cpp = cls_name;
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
950 std::replace (cls_cpp.begin (), cls_cpp.end (), '.', '/');
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
951
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
952 if (current_env && m_java_object)
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
953 {
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
954 jclass_ref cls (current_env, current_env->FindClass (cls_cpp.c_str ()));
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
955 if (current_env->ExceptionCheck ())
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
956 current_env->ExceptionClear ();
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
957 else
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
958 return current_env->IsInstanceOf (TO_JOBJECT (m_java_object), cls);
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
959 }
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
960 return false;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
961
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
962 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
963
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
964 octave_unused_parameter (cls_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
965
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
966 // This shouldn't happen because construction of octave_java objects is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
967 // supposed to be impossible if Java is not available.
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
968
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
969 error_unexpected ("octave_java::is_instance_of");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
970
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
971 #endif
20028
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
972 }
107130a0490c isa: check parent class of java objects (bug #42702)
Carnë Draug <carandraug@octave.org>
parents: 19861
diff changeset
973
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
974 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
975
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
976 static octave_value
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
977 check_exception (JNIEnv *jni_env)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
978 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
979 octave_value retval;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
980
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
981 jthrowable_ref ex (jni_env, jni_env->ExceptionOccurred ());
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
982
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
983 if (ex)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
984 {
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
985 if (Vdebug_java)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
986 jni_env->ExceptionDescribe ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
987
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
988 jni_env->ExceptionClear ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
989
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
990 jclass_ref jcls (jni_env, jni_env->GetObjectClass (ex));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
991 jmethodID mID = jni_env->GetMethodID (jcls, "toString",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
992 "()Ljava/lang/String;");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
993 jstring_ref js (jni_env,
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
994 reinterpret_cast<jstring> (jni_env->CallObjectMethod (ex,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
995 mID)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
996 std::string msg = jstring_to_string (jni_env, js);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
997
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
998 error ("[java] %s", msg.c_str ());
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
999 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1000 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1001 retval = Matrix ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1002
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1003 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1004 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1005
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1006 static jclass
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1007 find_octave_class (JNIEnv *jni_env, const char *name)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1008 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1009 static std::string class_loader;
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
1010 static jclass uiClass = nullptr;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1011
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1012 jclass jcls = jni_env->FindClass (name);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1013
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
1014 if (jcls == nullptr)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1015 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1016 jni_env->ExceptionClear ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1017
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1018 if (! uiClass)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1019 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1020 if (class_loader.empty ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1021 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1022 jclass_ref syscls (jni_env,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1023 jni_env->FindClass ("java/lang/System"));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1024 jmethodID mID = jni_env->GetStaticMethodID
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1025 (syscls,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1026 "getProperty",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1027 "(Ljava/lang/String;)Ljava/lang/String;");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1028 jstring_ref js (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1029 jni_env->NewStringUTF ("octave.class.loader"));
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1030 js = reinterpret_cast<jstring> (jni_env->CallStaticObjectMethod
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1031 (syscls, mID, jstring (js)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1032 class_loader = jstring_to_string (jni_env, jstring (js));
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
1033 std::replace (class_loader.begin (), class_loader.end (),
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
1034 '.', '/');
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1035 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1036
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1037 jclass_ref uicls (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1038 jni_env->FindClass (class_loader.c_str ()));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1039
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1040 if (! uicls)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1041 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1042 jni_env->ExceptionClear ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1043
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20945
diff changeset
1044 // Try the netbeans way
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
1045 std::replace (class_loader.begin (), class_loader.end (),
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
1046 '/', '.');
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1047 jclass_ref jcls2 (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1048 jni_env->FindClass ("org/openide/util/Lookup"));
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1049 jmethodID mID = jni_env->GetStaticMethodID
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1050 (jcls2, "getDefault", "()Lorg/openide/util/Lookup;");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1051 jobject_ref lObj (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1052 jni_env->CallStaticObjectMethod (jcls2, mID));
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
1053 mID = jni_env->GetMethodID (jcls2, "lookup",
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19598
diff changeset
1054 "(Ljava/lang/Class;)Ljava/lang/Object;");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1055 jclass_ref cLoaderCls (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1056 jni_env->FindClass ("java/lang/ClassLoader"));
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1057 jobject_ref cLoader (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1058 jni_env->CallObjectMethod
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1059 (lObj, mID, jclass (cLoaderCls)));
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1060 mID = jni_env->GetMethodID (cLoaderCls, "loadClass",
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1061 "(Ljava/lang/String;)Ljava/lang/Class;");
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1062 jstring_ref js (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1063 jni_env->NewStringUTF (class_loader.c_str ()));
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1064 uicls = reinterpret_cast<jclass>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1065 (jni_env->CallObjectMethod (cLoader, mID, jstring (js)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1066 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1067
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1068 if (uicls)
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1069 uiClass = reinterpret_cast<jclass>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1070 (jni_env->NewGlobalRef (jclass (uicls)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1071 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1072
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1073 if (uiClass)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1074 {
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1075 jmethodID mID = jni_env->GetStaticMethodID
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1076 (uiClass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1077 jstring_ref js (jni_env, jni_env->NewStringUTF (name));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1078 jcls = reinterpret_cast<jclass>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1079 (jni_env->CallStaticObjectMethod (uiClass, mID, jstring (js)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1080 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1081 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1082
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1083 return jcls;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1084 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1085
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1086 static dim_vector
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1087 compute_array_dimensions (JNIEnv *jni_env, jobject obj)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1088 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1089 jobjectArray_ref jobj (jni_env, reinterpret_cast<jobjectArray> (obj));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1090 jclass_ref jcls (jni_env, jni_env->GetObjectClass (obj));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1091 jclass_ref ccls (jni_env, jni_env->GetObjectClass (jcls));
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1092 jmethodID isArray_ID = jni_env->GetMethodID (ccls, "isArray", "()Z");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1093 jmethodID getComponentType_ID = jni_env->GetMethodID (ccls,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1094 "getComponentType",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1095 "()Ljava/lang/Class;");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1096
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1097 dim_vector dv (1, 1);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1098 int idx = 0;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1099
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1100 jobj.detach ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1101 while (jcls && jni_env->CallBooleanMethod (jcls, isArray_ID))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1102 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1103 int len = (jobj ? jni_env->GetArrayLength (jobj) : 0);
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21580
diff changeset
1104 if (idx >= dv.ndims ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1105 dv.resize (idx+1);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1106 dv(idx) = len;
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1107 jcls = reinterpret_cast<jclass>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1108 (jni_env->CallObjectMethod (jcls, getComponentType_ID));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1109 jobj = len > 0
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1110 ? reinterpret_cast<jobjectArray> (jni_env->GetObjectArrayElement (jobj,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1111 0))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1112 : nullptr;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1113 idx++;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1114 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1115
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
1116 octave_set_default_fpucw ();
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1117
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1118 return dv;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1119 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1120
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1121 static jobject
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1122 make_java_index (JNIEnv *jni_env, const octave_value_list& idx)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1123 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1124 jclass_ref ocls (jni_env, jni_env->FindClass ("[I"));
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
1125 jobjectArray retval = jni_env->NewObjectArray (idx.length (), ocls, nullptr);
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1126 // Here retval has the same length as idx
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1127
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1128 // Fill in entries of idx into retval
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1129 for (int i = 0; i < idx.length (); i++)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
1130 try
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
1131 {
29569
29a1f8fd8ee6 move idx_vector classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
1132 octave::idx_vector v = idx(i).index_vector ();
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
1133
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1134 jintArray_ref i_array (jni_env, jni_env->NewIntArray (v.length ()));
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
1135 jint *buf = jni_env->GetIntArrayElements (i_array, nullptr);
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1136 // Here, buf points to the beginning of i_array
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1137
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1138 // Copy v to buf.
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1139 for (int k = 0; k < v.length (); k++)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1140 buf[k] = v(k);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1141
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1142 // Set retval[i] = i_array
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1143 jni_env->ReleaseIntArrayElements (i_array, buf, 0);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1144 jni_env->SetObjectArrayElement (retval, i, i_array);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1145
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1146 check_exception (jni_env);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
1147 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29007
diff changeset
1148 catch (octave::index_exception& ie)
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
1149 {
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
1150 // Rethrow to allow more info to be reported later.
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29007
diff changeset
1151 ie.set_pos_if_unset (idx.length (), i + 1);
20542
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
1152 throw;
dd6345fd8a97 use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20531
diff changeset
1153 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1154
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1155 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1156 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1157
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1158 static octave_value
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1159 get_array_elements (JNIEnv *jni_env, jobject jobj,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1160 const octave_value_list& idx)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1161 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1162 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1163 jobject_ref resObj (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1164 jobject_ref java_idx (jni_env, make_java_index (jni_env, idx));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1165
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1166 jclass_ref helperClass (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1167 find_octave_class (jni_env,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1168 "org/octave/ClassHelper"));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1169 jmethodID mID = jni_env
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1170 ->GetStaticMethodID (helperClass, "arraySubsref",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1171 "(Ljava/lang/Object;[[I)Ljava/lang/Object;");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1172 resObj = jni_env->CallStaticObjectMethod
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1173 (helperClass, mID, jobj, jobject (java_idx));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1174
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1175 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1176 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1177 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1178 retval = check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1179
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
1180 octave_set_default_fpucw ();
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1181
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1182 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1183 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1184
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1185 static octave_value
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1186 set_array_elements (JNIEnv *jni_env, jobject jobj,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1187 const octave_value_list& idx, const octave_value& rhs)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1188 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1189 octave_value retval;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1190
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1191 jclass_ref rhsCls (jni_env);
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1192 jobject_ref resObj (jni_env);
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1193 jobject_ref rhsObj (jni_env);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1194 jobject_ref java_idx (jni_env, make_java_index (jni_env, idx));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1195
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1196 if (unbox (jni_env, rhs, rhsObj, rhsCls))
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1197 {
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1198 jclass_ref helperClass (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1199 find_octave_class (jni_env,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1200 "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1201 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "arraySubsasgn",
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1202 "(Ljava/lang/Object;[[ILjava/lang/Object;)" "Ljava/lang/Object;");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1203 resObj = jni_env->CallStaticObjectMethod
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1204 (helperClass, mID, jobj, jobject (java_idx), jobject (rhsObj));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1205 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1206
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1207 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1208 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1209 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1210 retval = check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1211
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
1212 octave_set_default_fpucw ();
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1213
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1214 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1215 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1216
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1217 static string_vector
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1218 get_invoke_list (JNIEnv *jni_env, void *jobj_arg)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1219 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1220 jobject jobj = TO_JOBJECT (jobj_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1221
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1222 std::list<std::string> name_list;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1223
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1224 if (jni_env)
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1225 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1226 jclass_ref cls (jni_env, jni_env->GetObjectClass (jobj));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1227 jclass_ref ccls (jni_env, jni_env->GetObjectClass (cls));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1228 jmethodID getMethods_ID = jni_env->GetMethodID
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1229 (ccls, "getMethods", "()[Ljava/lang/reflect/Method;");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1230 jmethodID getFields_ID = jni_env->GetMethodID
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1231 (ccls, "getFields", "()[Ljava/lang/reflect/Field;");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1232 jobjectArray_ref mList (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1233 reinterpret_cast<jobjectArray>
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1234 (jni_env->CallObjectMethod (cls, getMethods_ID)));
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1235 jobjectArray_ref fList (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1236 reinterpret_cast<jobjectArray>
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1237 (jni_env->CallObjectMethod (cls, getFields_ID)));
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1238 int mLen = jni_env->GetArrayLength (mList);
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
1239 int fLen = jni_env->GetArrayLength (fList);
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1240 jclass_ref mCls (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1241 jni_env->FindClass ("java/lang/reflect/Method"));
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1242 jclass_ref fCls (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1243 jni_env->FindClass ("java/lang/reflect/Field"));
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1244 jmethodID m_getName_ID = jni_env->GetMethodID (mCls, "getName",
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1245 "()Ljava/lang/String;");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1246 jmethodID f_getName_ID = jni_env->GetMethodID (fCls, "getName",
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1247 "()Ljava/lang/String;");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1248
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1249 for (int i = 0; i < mLen; i++)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1250 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1251 jobject_ref meth (jni_env, jni_env->GetObjectArrayElement (mList, i));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1252 jstring_ref methName (jni_env, reinterpret_cast<jstring>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1253 (jni_env->CallObjectMethod (meth,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1254 m_getName_ID)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1255 name_list.push_back (jstring_to_string (jni_env, methName));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1256 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1257
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1258 for (int i = 0; i < fLen; i++)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1259 {
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1260 jobject_ref field (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1261 jni_env->GetObjectArrayElement (fList, i));
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1262 jstring_ref fieldName (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1263 reinterpret_cast<jstring>
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1264 (jni_env->CallObjectMethod
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1265 (field, f_getName_ID)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1266 name_list.push_back (jstring_to_string (jni_env, fieldName));
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1267 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1268
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
1269 octave_set_default_fpucw ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1270 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1271
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1272 string_vector v (name_list);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1273
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1274 return v.sort (true);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1275 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1276
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1277 static octave_value
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
1278 convert_to_string (JNIEnv *jni_env, jobject m_java_object, bool force,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
1279 char type)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1280 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1281 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1282
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
1283 if (jni_env && m_java_object)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1284 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1285 jclass_ref cls (jni_env, jni_env->FindClass ("java/lang/String"));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1286
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
1287 if (jni_env->IsInstanceOf (m_java_object, cls))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
1288 retval = octave_value (jstring_to_string (jni_env, m_java_object),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
1289 type);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1290 else if (force)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1291 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1292 cls = jni_env->FindClass ("[Ljava/lang/String;");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1293
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
1294 if (jni_env->IsInstanceOf (m_java_object, cls))
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1295 {
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
1296 jobjectArray array = reinterpret_cast<jobjectArray> (m_java_object);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1297 int len = jni_env->GetArrayLength (array);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1298 Cell c (len, 1);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1299
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1300 for (int i = 0; i < len; i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1301 {
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1302 jstring_ref js (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1303 reinterpret_cast<jstring>
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1304 (jni_env->GetObjectArrayElement (array, i)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1305
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1306 if (js)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1307 c(i) = octave_value (jstring_to_string (jni_env, js), type);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1308 else
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1309 c(i) = check_exception (jni_env);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1310 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1311
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1312 retval = octave_value (c);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1313 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1314 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1315 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1316 cls = jni_env->FindClass ("java/lang/Object");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1317 jmethodID mID = jni_env->GetMethodID (cls, "toString",
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1318 "()Ljava/lang/String;");
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1319 jstring_ref js (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1320 reinterpret_cast<jstring>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1321 (jni_env->CallObjectMethod (m_java_object,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1322 mID)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1323
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1324 if (js)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1325 retval = octave_value (jstring_to_string (jni_env, js), type);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1326 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1327 retval = check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1328 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1329 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1330 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1331 error ("unable to convert Java object to string");
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1332
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
1333 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1334 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1335
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1336 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1337 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1338
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
1339 #define TO_JAVA(obj) dynamic_cast<octave_java *> ((obj).internal_rep ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1340
22202
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1341 //! Return whether @c jobj shall be automatically converted to an Octave
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1342 //! numeric value.
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1343 //!
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1344 //! If @c jobj is an instance of any of the numeric wrapper classes @c Byte,
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1345 //! @c Integer, @c Long, @c Short, @c Float, or @c Double, then it will be
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1346 //! converted using the @c java.lang.Number.doubleValue() method.
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1347 //!
33080
d911fafcf27a * ov-java.cc: Fix some Doxygen comments.
John W. Eaton <jwe@octave.org>
parents: 32632
diff changeset
1348 //! @param jni_env JNI environment pointer.
22202
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1349 //! @param jobj Java object being returned to Octave
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1350 //! @return @c true if @c jobj shall be converted into a numeric value
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1351 //! automatically, @c false otherwise
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1352 static bool
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1353 is_auto_convertible_number (JNIEnv *jni_env, jobject jobj)
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1354 {
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1355 jclass_ref cls (jni_env);
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1356 cls = jni_env->FindClass ("java/lang/Double");
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1357 if (jni_env->IsInstanceOf (jobj, cls))
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1358 return true;
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1359 cls = jni_env->FindClass ("java/lang/Float");
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1360 if (jni_env->IsInstanceOf (jobj, cls))
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1361 return true;
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1362 cls = jni_env->FindClass ("java/lang/Byte");
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1363 if (jni_env->IsInstanceOf (jobj, cls))
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1364 return true;
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1365 cls = jni_env->FindClass ("java/lang/Short");
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1366 if (jni_env->IsInstanceOf (jobj, cls))
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1367 return true;
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1368 cls = jni_env->FindClass ("java/lang/Integer");
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1369 if (jni_env->IsInstanceOf (jobj, cls))
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1370 return true;
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1371 cls = jni_env->FindClass ("java/lang/Long");
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1372 if (jni_env->IsInstanceOf (jobj, cls))
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1373 return true;
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1374
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1375 return false;
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1376 }
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1377
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1378 //! Convert the Java object pointed to by @c jobj_arg with class @c jcls_arg
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1379 //! to an Octave value.
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1380 //!
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1381 //! @param jni_env JNI environment pointer.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1382 //! @param jobj_arg Pointer to a Java object.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1383 //! @param jcls_arg Optional pointer to the Java class of @c jobj_arg.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1384 //!
22202
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1385 //! @return
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1386 //! @arg numeric value as a @c double if @c jobj_arg is of type @c Byte,
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1387 //! @c Short, @c Integer, @c Long, @c Float or @c Double
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1388 //! @arg logical value if @c jobj_arg is of type @c Boolean
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1389 //! @arg string value if @c jobj_arg is of type @c Character or @c String
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1390 //! @arg Octave array of numeric, logical, or char type if @c jobj_arg is
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1391 //! a Java array of primitive types
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1392 //! @arg Octave matrix if @c jobj_arg is of type @c org.octave.Matrix and
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1393 //! #Vjava_matrix_autoconversion is enabled
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1394 //! @arg Octave object if @c jobj_arg is of type
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1395 //! @c org.octave.OctaveReference
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1396 //! @arg @c octave_java object wrapping the Java object otherwise.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1397
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1398 static octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1399 box (JNIEnv *jni_env, void *jobj_arg, void *jcls_arg)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1400 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1401 octave_value retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1402
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1403 jobject jobj = TO_JOBJECT (jobj_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1404 jclass jcls = TO_JCLASS (jcls_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1405
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1406 jclass_ref cls (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1407
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1408 if (! jobj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1409 retval = Matrix ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1410
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1411 while (retval.is_undefined ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1412 {
22202
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1413 // Convert a scalar of any numeric class wrapping a primitive class
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1414 // (byte, short, integer, long, float, double) to a double value.
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1415 // Test whether java.lang.Number before testing for each type.
15820
00172e5c2302 Add autoconversion of Java numeric types (byte, short, integer, long, float) to Octave double.
Rik <rik@octave.org>
parents: 15816
diff changeset
1416 cls = jni_env->FindClass ("java/lang/Number");
22202
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1417 if (jni_env->IsInstanceOf (jobj, cls)
f094186125d3 Only convert specific Java numeric objects to double for Matlab compatibility (bug #48013)
Ernst Reissner <rei3ner@arcor.de>
parents: 22146
diff changeset
1418 && is_auto_convertible_number (jni_env, jobj))
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1419 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1420 jmethodID m = jni_env->GetMethodID (cls, "doubleValue", "()D");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1421 retval = jni_env->CallDoubleMethod (jobj, m);
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1422 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1423 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1424
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1425 cls = jni_env->FindClass ("java/lang/Boolean");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1426 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1427 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1428 jmethodID m = jni_env->GetMethodID (cls, "booleanValue", "()Z");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1429 retval = (jni_env->CallBooleanMethod (jobj, m) ? true : false);
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1430 break;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1431 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1432
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1433 cls = jni_env->FindClass ("java/lang/String");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1434 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1435 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1436 retval = jstring_to_string (jni_env, jobj);
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1437 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1438 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1439
15815
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1440 cls = jni_env->FindClass ("java/lang/Character");
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1441 if (jni_env->IsInstanceOf (jobj, cls))
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1442 {
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1443 jmethodID m = jni_env->GetMethodID (cls, "charValue", "()C");
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1444 retval = jni_env->CallCharMethod (jobj, m);
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17898
diff changeset
1445 retval = retval.convert_to_str (false, true);
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1446 break;
15815
f28b3dcbaa9a Add autoconversion between java.lang.Character class and Octave string class.
Rik <rik@octave.org>
parents: 15813
diff changeset
1447 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1448
20120
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1449 #define BOX_PRIMITIVE_ARRAY(JAVA_TYPE, JAVA_ID, JAVA_TYPE_CAP, OCTAVE_ID) \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1450 cls = jni_env->FindClass (JAVA_ID); \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1451 if (jni_env->IsInstanceOf (jobj, cls)) \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1452 { \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1453 const JAVA_TYPE ## Array jarr = reinterpret_cast<JAVA_TYPE ## Array> (jobj); \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1454 const jsize len = jni_env->GetArrayLength (jarr); \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1455 OCTAVE_ID ## NDArray d (dim_vector (len, 1)); \
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1456 JAVA_TYPE *buffer = reinterpret_cast<JAVA_TYPE *> (d.rwdata ()); \
20120
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1457 jni_env->Get ## JAVA_TYPE_CAP ## ArrayRegion (jarr, 0, len, buffer); \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1458 retval = d; \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1459 break; \
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1460 }
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1461
20254
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1462 BOX_PRIMITIVE_ARRAY (jdouble, "[D", Double, )
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1463 BOX_PRIMITIVE_ARRAY (jboolean, "[Z", Boolean, bool)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1464 BOX_PRIMITIVE_ARRAY (jfloat, "[F", Float, Float)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1465 BOX_PRIMITIVE_ARRAY (jchar, "[C", Char, char)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1466 BOX_PRIMITIVE_ARRAY (jbyte, "[B", Byte, int8)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1467 BOX_PRIMITIVE_ARRAY (jshort, "[S", Short, int16)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1468 BOX_PRIMITIVE_ARRAY (jint, "[I", Int, int32)
a51fe1b60e3f Put most used conversions first in Java box/unbox routines.
Rik <rik@octave.org>
parents: 20253
diff changeset
1469 BOX_PRIMITIVE_ARRAY (jlong, "[J", Long, int64)
20120
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1470
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1471 #undef BOX_PRIMITIVE_ARRAY
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
1472
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1473 if (Vjava_matrix_autoconversion)
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1474 {
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1475 cls = find_octave_class (jni_env, "org/octave/Matrix");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1476
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1477 if (jni_env->IsInstanceOf (jobj, cls))
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1478 {
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1479 jmethodID mID = jni_env->GetMethodID (cls, "getDims", "()[I");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1480 jintArray_ref iv (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1481 reinterpret_cast<jintArray>
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1482 (jni_env->CallObjectMethod (jobj, mID)));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
1483 jint *iv_data = jni_env->GetIntArrayElements (jintArray (iv),
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1484 nullptr);
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1485 dim_vector dims;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1486 dims.resize (jni_env->GetArrayLength (jintArray (iv)));
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1487
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21580
diff changeset
1488 for (int i = 0; i < dims.ndims (); i++)
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1489 dims(i) = iv_data[i];
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1490
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1491 jni_env->ReleaseIntArrayElements (jintArray (iv), iv_data, 0);
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1492 mID = jni_env->GetMethodID (cls, "getClassName",
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1493 "()Ljava/lang/String;");
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1494 jstring_ref js (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1495 reinterpret_cast<jstring>
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1496 (jni_env->CallObjectMethod (jobj, mID)));
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1497
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1498 std::string s = jstring_to_string (jni_env, js);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1499
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1500 if (s == "double")
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1501 {
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1502 NDArray m (dims);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1503 mID = jni_env->GetMethodID (cls, "toDouble", "()[D");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1504 jdoubleArray_ref dv (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1505 reinterpret_cast<jdoubleArray>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1506 (jni_env->CallObjectMethod (jobj,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1507 mID)));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
1508 jni_env->GetDoubleArrayRegion (dv, 0, m.numel (),
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1509 m.rwdata ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1510 retval = m;
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1511 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1512 }
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1513 else if (s == "byte")
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1514 {
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1515 if (Vjava_unsigned_autoconversion)
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1516 {
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1517 uint8NDArray m (dims);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1518 mID = jni_env->GetMethodID (cls, "toByte", "()[B");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1519 jbyteArray_ref dv (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1520 reinterpret_cast<jbyteArray>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1521 (jni_env->CallObjectMethod (jobj,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1522 mID)));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1523 jni_env->GetByteArrayRegion (dv, 0, m.numel (),
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1524 reinterpret_cast<jbyte *>
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1525 (m.rwdata ()));
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1526 retval = m;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1527 break;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1528 }
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1529 else
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1530 {
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1531 int8NDArray m (dims);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1532 mID = jni_env->GetMethodID (cls, "toByte", "()[B");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1533 jbyteArray_ref dv (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1534 reinterpret_cast<jbyteArray>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1535 (jni_env->CallObjectMethod (jobj,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1536 mID)));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1537 jni_env->GetByteArrayRegion (dv, 0, m.numel (),
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1538 reinterpret_cast<jbyte *>
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1539 (m.rwdata ()));
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1540 retval = m;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1541 break;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1542 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1543 }
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1544 else if (s == "integer")
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1545 {
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1546 if (Vjava_unsigned_autoconversion)
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1547 {
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1548 uint32NDArray m (dims);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1549 mID = jni_env->GetMethodID (cls, "toInt", "()[I");
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
1550 jintArray_ref dv (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
1551 reinterpret_cast<jintArray>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1552 (jni_env->CallObjectMethod (jobj,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1553 mID)));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
1554 jni_env->GetIntArrayRegion (dv, 0, m.numel (),
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
1555 reinterpret_cast<jint *>
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1556 (m.rwdata ()));
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1557 retval = m;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1558 break;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1559 }
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1560 else
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1561 {
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1562 int32NDArray m (dims);
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1563 mID = jni_env->GetMethodID (cls, "toInt", "()[I");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1564 jintArray_ref dv (jni_env,
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1565 reinterpret_cast<jintArray>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1566 (jni_env->CallObjectMethod (jobj,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1567 mID)));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1568 jni_env->GetIntArrayRegion (dv, 0, m.numel (),
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1569 reinterpret_cast<jint *>
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1570 (m.rwdata ()));
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1571 retval = m;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1572 break;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1573 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1574 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1575 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1576 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1577
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
1578 cls = find_octave_class (jni_env, "org/octave/OctaveReference");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1579 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1580 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1581 jmethodID mID = jni_env->GetMethodID (cls, "getID", "()I");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1582 int ID = jni_env->CallIntMethod (jobj, mID);
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25305
diff changeset
1583 auto it = octave_ref_map.find (ID);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1584
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1585 if (it != octave_ref_map.end ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1586 retval = it->second;
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1587 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1588 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1589
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1590 // No suitable class found. Return a generic octave_java object.
15821
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1591 retval = octave_value (new octave_java (jobj, jcls));
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1592 break;
72661fe4b9e5 Short-circuit out of Java box code as soon as valid class has been found.
Rik <rik@octave.org>
parents: 15820
diff changeset
1593 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1594
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1595 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1596 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1597
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1598 static octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1599 box_more (JNIEnv *jni_env, void *jobj_arg, void *jcls_arg)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1600 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1601 jobject jobj = TO_JOBJECT (jobj_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1602 jclass jcls = TO_JCLASS (jcls_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1603
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1604 octave_value retval = box (jni_env, jobj, jcls);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1605
23578
7b47b7c2d6c7 maint: Deprecate is_java and replace with isjava.
Rik <rik@octave.org>
parents: 23577
diff changeset
1606 if (retval.isjava ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1607 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1608 retval = octave_value ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1609
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1610 jclass_ref cls (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1611
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1612 if (retval.is_undefined ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1613 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1614 cls = jni_env->FindClass ("[D");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1615
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1616 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1617 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1618 jdoubleArray jarr = reinterpret_cast<jdoubleArray> (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1619 int len = jni_env->GetArrayLength (jarr);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1620
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1621 if (len > 0)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1622 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1623 Matrix m (1, len);
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
1624 jni_env->GetDoubleArrayRegion (jarr, 0, len,
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1625 m.rwdata ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1626 retval = m;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1627 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1628 else
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1629 retval = Matrix ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1630 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1631 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1632
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1633 if (retval.is_undefined ())
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1634 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1635 cls = jni_env->FindClass ("[[D");
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1636
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1637 if (jni_env->IsInstanceOf (jobj, cls))
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1638 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1639 jobjectArray jarr = reinterpret_cast<jobjectArray> (jobj);
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17898
diff changeset
1640 int rows = jni_env->GetArrayLength (jarr);
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17898
diff changeset
1641 int cols = 0;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1642
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1643 if (rows > 0)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1644 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1645 Matrix m;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1646
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1647 for (int r = 0; r < rows; r++)
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1648 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1649 jdoubleArray_ref row (jni_env,
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1650 reinterpret_cast<jdoubleArray>
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1651 (jni_env->GetObjectArrayElement
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1652 (jarr, r)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1653
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
1654 if (m.isempty ())
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1655 {
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1656 cols = jni_env->GetArrayLength (row);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1657 m.resize (cols, rows);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1658 }
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1659 jni_env->GetDoubleArrayRegion
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1660 (row, 0, cols, m.rwdata () + r * cols);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1661 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1662 retval = m.transpose ();
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1663 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1664 else
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1665 retval = Matrix ();
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1666 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1667 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1668
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1669 if (retval.is_undefined ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1670 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1671 cls = jni_env->FindClass ("[Ljava/lang/String;");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1672
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1673 if (jni_env->IsInstanceOf (jobj, cls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1674 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1675 jobjectArray jarr = reinterpret_cast<jobjectArray> (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1676 int len = jni_env->GetArrayLength (jarr);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1677 Cell m (len, 1);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1678
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1679 for (int i = 0; i < len; i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1680 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1681 jstring_ref js (jni_env,
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1682 reinterpret_cast<jstring>
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1683 (jni_env->GetObjectArrayElement (jarr, i)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1684 m(i) = jstring_to_string (jni_env, js);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1685 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1686
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1687 retval = m;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1688 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1689 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1690 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1691
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1692 if (retval.is_undefined ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1693 retval = octave_value (new octave_java (jobj, jcls));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1694
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
1695 octave_set_default_fpucw ();
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
1696
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1697 return retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1698 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1699
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1700 static bool
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1701 unbox (JNIEnv *jni_env, const octave_value& val, jobject_ref& jobj,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1702 jclass_ref& jcls)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1703 {
20121
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1704 bool found = true;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1705
23578
7b47b7c2d6c7 maint: Deprecate is_java and replace with isjava.
Rik <rik@octave.org>
parents: 23577
diff changeset
1706 if (val.isjava ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1707 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1708 octave_java *ovj = TO_JAVA (val);
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1709 jobj = TO_JOBJECT (ovj->to_java ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1710 jobj.detach ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1711 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1712 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1713 else if (val.is_string ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1714 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1715 std::string s = val.string_value ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1716
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1717 jobj = jni_env->NewStringUTF (s.c_str ());
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1718 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1719 }
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23573
diff changeset
1720 else if (val.iscellstr ())
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1721 {
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1722 const Array<std::string> str_arr = val.cellstr_value ();
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1723 const octave_idx_type n = str_arr.numel ();
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1724
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1725 jclass_ref scls (jni_env, jni_env->FindClass ("java/lang/String"));
23459
ddcbf10c8c39 maint: Use C++11 nullptr rather than 0 or NULL for remaining instances in code.
Rik <rik@octave.org>
parents: 23457
diff changeset
1726 jobjectArray array = jni_env->NewObjectArray (n, scls, nullptr);
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1727
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1728 for (octave_idx_type i = 0; i < n; i++)
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1729 {
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1730 jstring_ref jstr (jni_env, jni_env->NewStringUTF
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1731 (str_arr(i).c_str ()));
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1732 jni_env->SetObjectArrayElement (array, i, jstr);
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1733 }
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1734
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1735 jobj = array;
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1736 jcls = jni_env->GetObjectClass (jobj);
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
1737 }
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23585
diff changeset
1738 else if (val.numel () > 1 && val.dims ().isvector ())
20122
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1739 {
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1740 // FIXME: Is there any way to avoid code duplication here without
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1741 // using a macro?
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1742
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1743 #define UNBOX_PRIMITIVE_ARRAY(METHOD_T, OCTAVE_T, JAVA_T, JAVA_T_CAP) \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1744 do \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1745 { \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1746 const OCTAVE_T ## NDArray v = val.METHOD_T ## array_value (); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1747 JAVA_T ## Array jarr = jni_env->New ## JAVA_T_CAP ## Array (v.numel ()); \
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23446
diff changeset
1748 const JAVA_T *jv = reinterpret_cast<const JAVA_T *> (v.data ()); \
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1749 jni_env->Set ## JAVA_T_CAP ## ArrayRegion (jarr, 0, v.numel (), jv); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1750 jobj = reinterpret_cast<jobject> (jarr); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1751 jcls = jni_env->GetObjectClass (jobj); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1752 } \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1753 while (0)
20122
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1754
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1755 // Note that we do NOT handle char here because they are unboxed
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1756 // into a String[], not into a char array
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1757
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1758 if (val.is_double_type ())
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1759 UNBOX_PRIMITIVE_ARRAY (,, jdouble, Double);
23579
c20a0fa91c0c maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents: 23578
diff changeset
1760 else if (val.islogical ())
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1761 UNBOX_PRIMITIVE_ARRAY (bool_, bool, jboolean, Boolean);
23585
570170b6eb09 maint: Deprecate is_float_type and replace with isfloat.
Rik <rik@octave.org>
parents: 23582
diff changeset
1762 else if (val.isfloat ())
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1763 UNBOX_PRIMITIVE_ARRAY (float_, Float, jfloat, Float);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1764 else if (val.is_int8_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1765 UNBOX_PRIMITIVE_ARRAY (int8_, int8, jbyte, Byte);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1766 else if (val.is_uint8_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1767 UNBOX_PRIMITIVE_ARRAY (uint8_, uint8, jbyte, Byte);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1768 else if (val.is_int16_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1769 UNBOX_PRIMITIVE_ARRAY (int16_, int16, jshort, Short);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1770 else if (val.is_uint16_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1771 UNBOX_PRIMITIVE_ARRAY (uint16_, uint16, jshort, Short);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1772 else if (val.is_int32_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1773 UNBOX_PRIMITIVE_ARRAY (int32_, int32, jint, Int);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1774 else if (val.is_uint32_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1775 UNBOX_PRIMITIVE_ARRAY (uint32_, uint32, jint, Int);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1776 else if (val.is_int64_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1777 UNBOX_PRIMITIVE_ARRAY (int64_, int64, jlong, Long);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1778 else if (val.is_uint64_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1779 UNBOX_PRIMITIVE_ARRAY (uint64_, uint64, jlong, Long);
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1780
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1781 #undef UNBOX_PRIMITIVE_ARRAY
20122
81fcf4aa9e03 Automatically convert octave vectors into java primitive arrays (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20121
diff changeset
1782 }
20123
8261c4a11250 Convert octave integer scalars into closest java type (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20122
diff changeset
1783 else if (val.is_real_scalar () || val.is_bool_scalar ())
15822
e7d9db9531d1 Add conversion for Octave integer and single classes to Java int and float classes.
Rik <rik@octave.org>
parents: 15821
diff changeset
1784 {
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1785 // FIXME: Is there any way to avoid code duplication here without
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1786 // using a macro?
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1787
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1788 #define UNBOX_PRIMITIVE_SCALAR(OCTAVE_T, METHOD_T, JAVA_T, JAVA_CON) \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1789 do \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1790 { \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1791 const OCTAVE_T ov = val.METHOD_T ## _value (); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1792 jclass_ref dcls (jni_env, jni_env->FindClass (JAVA_T)); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1793 const jfieldID fid = jni_env->GetStaticFieldID (dcls, "TYPE", "Ljava/lang/Class;"); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1794 const jmethodID mid = jni_env->GetMethodID (dcls, "<init>", JAVA_CON); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1795 jcls = reinterpret_cast<jclass> (jni_env->GetStaticObjectField (dcls, fid)); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1796 jobj = jni_env->NewObject (dcls, mid, ov); \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1797 } \
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1798 while (0)
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1799
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1800 if (val.is_double_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1801 UNBOX_PRIMITIVE_SCALAR (double, double, "java/lang/Double", "(D)V");
23579
c20a0fa91c0c maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents: 23578
diff changeset
1802 else if (val.islogical ())
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1803 UNBOX_PRIMITIVE_SCALAR (bool, bool, "java/lang/Boolean", "(Z)V");
23585
570170b6eb09 maint: Deprecate is_float_type and replace with isfloat.
Rik <rik@octave.org>
parents: 23582
diff changeset
1804 else if (val.isfloat ())
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1805 UNBOX_PRIMITIVE_SCALAR (float, float, "java/lang/Float", "(F)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1806 else if (val.is_int8_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1807 UNBOX_PRIMITIVE_SCALAR (int8_t, int8_scalar, "java/lang/Byte", "(B)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1808 else if (val.is_uint8_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1809 UNBOX_PRIMITIVE_SCALAR (uint8_t, uint8_scalar, "java/lang/Byte", "(B)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1810 else if (val.is_int16_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1811 UNBOX_PRIMITIVE_SCALAR (int16_t, int16_scalar, "java/lang/Short", "(S)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1812 else if (val.is_uint16_type ())
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1813 UNBOX_PRIMITIVE_SCALAR (uint16_t, uint16_scalar, "java/lang/Short", "(S)V");
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1814 else if (val.is_int32_type ())
21823
49d999dc443f maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
parents: 21781 21822
diff changeset
1815 UNBOX_PRIMITIVE_SCALAR (int32_t, int32_scalar, "java/lang/Integer", "(I)V");
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1816 else if (val.is_uint32_type ())
21823
49d999dc443f maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
parents: 21781 21822
diff changeset
1817 UNBOX_PRIMITIVE_SCALAR (uint32_t, uint32_scalar, "java/lang/Integer", "(I)V");
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1818 else if (val.is_int64_type ())
21823
49d999dc443f maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
parents: 21781 21822
diff changeset
1819 UNBOX_PRIMITIVE_SCALAR (int64_t, int64_scalar, "java/lang/Long", "(J)V");
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1820 else if (val.is_uint64_type ())
21823
49d999dc443f maint: Periodic merge of stable to default.
Mike Miller <mtmiller@octave.org>
parents: 21781 21822
diff changeset
1821 UNBOX_PRIMITIVE_SCALAR (uint64_t, uint64_scalar, "java/lang/Long", "(J)V");
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1822
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1823 #undef UNBOX_PRIMITIVE_SCALAR
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
1824 }
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
1825 else if (val.isempty ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1826 {
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
1827 jobj = nullptr;
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
1828 jcls = nullptr;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1829 //jcls = jni_env->FindClass ("java/lang/Object");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1830 }
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20946
diff changeset
1831 else if (! Vjava_matrix_autoconversion
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1832 && ((val.is_real_matrix ()
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1833 && (val.rows () == 1 || val.columns () == 1))
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1834 || val.is_range ()))
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1835 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1836 Matrix m = val.matrix_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1837 jdoubleArray dv = jni_env->NewDoubleArray (m.numel ());
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1838 jni_env->SetDoubleArrayRegion (dv, 0, m.numel (), m.rwdata ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1839 jobj = dv;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1840 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1841 }
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
1842 else if (Vjava_matrix_autoconversion
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1843 && (val.is_matrix_type () || val.is_range ())
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23579
diff changeset
1844 && val.isreal ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1845 {
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1846 jclass_ref mcls (jni_env, find_octave_class (jni_env,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1847 "org/octave/Matrix"));
32598
2f3b54f81947 avoid dim_vector copies in more places where possible (bug #64962)
John W. Eaton <jwe@octave.org>
parents: 31845
diff changeset
1848 const dim_vector& dims = val.dims ();
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21580
diff changeset
1849 jintArray_ref iv (jni_env, jni_env->NewIntArray (dims.ndims ()));
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
1850 jint *iv_data = jni_env->GetIntArrayElements (jintArray (iv), nullptr);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1851
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21580
diff changeset
1852 for (int i = 0; i < dims.ndims (); i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1853 iv_data[i] = dims(i);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1854
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1855 jni_env->ReleaseIntArrayElements (jintArray (iv), iv_data, 0);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1856
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1857 if (val.is_double_type ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1858 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1859 NDArray m = val.array_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1860 jdoubleArray_ref dv (jni_env, jni_env->NewDoubleArray (m.numel ()));
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1861 jni_env->SetDoubleArrayRegion (jdoubleArray (dv), 0, m.numel (),
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1862 m.rwdata ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1863 jmethodID mID = jni_env->GetMethodID (mcls, "<init>", "([D[I)V");
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1864 jobj = jni_env->NewObject (jclass (mcls), mID, jdoubleArray (dv),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1865 jintArray (iv));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1866 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1867 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1868 else if (val.is_int8_type ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1869 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1870 int8NDArray m = val.int8_array_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1871 jbyteArray_ref bv (jni_env, jni_env->NewByteArray (m.numel ()));
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1872 jni_env->SetByteArrayRegion (jbyteArray (bv), 0, m.numel (),
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1873 reinterpret_cast<jbyte *>
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1874 (m.rwdata ()));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1875 jmethodID mID = jni_env->GetMethodID (mcls, "<init>", "([B[I)V");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1876 jobj = jni_env->NewObject
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1877 (jclass (mcls), mID, jbyteArray (bv), jintArray (iv));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1878 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1879 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1880 else if (val.is_uint8_type ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1881 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1882 uint8NDArray m = val.uint8_array_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1883 jbyteArray_ref bv (jni_env, jni_env->NewByteArray (m.numel ()));
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1884 jni_env->SetByteArrayRegion (jbyteArray (bv), 0, m.numel (),
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1885 reinterpret_cast<jbyte *>
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1886 (m.rwdata ()));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1887 jmethodID mID = jni_env->GetMethodID (mcls, "<init>", "([B[I)V");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1888 jobj = jni_env->NewObject
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1889 (jclass (mcls), mID, jbyteArray (bv), jintArray (iv));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1890 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1891 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1892 else if (val.is_int32_type ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1893 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1894 int32NDArray m = val.int32_array_value ();
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1895 jintArray_ref v (jni_env, jni_env->NewIntArray (m.numel ()));
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20163
diff changeset
1896 jni_env->SetIntArrayRegion (jintArray (v), 0, m.numel (),
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1897 reinterpret_cast<jint *>
32660
f53ac65ffba6 maint: New method rwdata() as clearer alternative to fortran_vec().
Rik <rik@octave.org>
parents: 32633
diff changeset
1898 (m.rwdata ()));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1899 jmethodID mID = jni_env->GetMethodID (mcls, "<init>", "([I[I)V");
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1900 jobj = jni_env->NewObject
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1901 (jclass (mcls), mID, jintArray (v), jintArray (iv));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1902 jcls = jni_env->GetObjectClass (jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1903 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1904 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1905 {
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1906 error ("cannot convert matrix of type '%s'",
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1907 val.class_name ().c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1908 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1909 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1910 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1911 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
1912 jclass rcls = find_octave_class (jni_env, "org/octave/OctaveReference");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1913 jmethodID mID = jni_env->GetMethodID (rcls, "<init>", "(I)V");
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1914 int ID = octave_java_refcount++;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1915
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1916 jobj = jni_env->NewObject (rcls, mID, ID);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1917 jcls = rcls;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1918 octave_ref_map[ID] = val;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1919 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1920
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1921 return found;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1922 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1923
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1924 static bool
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
1925 unbox (JNIEnv *jni_env, const octave_value_list& args,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1926 jobjectArray_ref& jobjs, jobjectArray_ref& jclss)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1927 {
20121
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1928 bool found = true;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1929
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1930 jclass_ref ocls (jni_env, jni_env->FindClass ("java/lang/Object"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1931 jclass_ref ccls (jni_env, jni_env->FindClass ("java/lang/Class"));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1932
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1933 if (! jobjs)
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
1934 jobjs = jni_env->NewObjectArray (args.length (), ocls, nullptr);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1935
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1936 if (! jclss)
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
1937 jclss = jni_env->NewObjectArray (args.length (), ccls, nullptr);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1938
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1939 for (int i = 0; i < args.length (); i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1940 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1941 jobject_ref jobj (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1942 jclass_ref jcls (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1943
20121
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1944 found = unbox (jni_env, args(i), jobj, jcls);
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1945 if (! found)
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
1946 break;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1947
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1948 jni_env->SetObjectArrayElement (jobjs, i, jobj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1949 jni_env->SetObjectArrayElement (jclss, i, jcls);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1950 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1951
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1952 return found;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1953 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1954
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1955 //! Returns the id of the current thread.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1956 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1957 //! @param jni_env The current environment or @c nullptr.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1958 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1959 //! @returns The id of the current thread or -1 otherwise. The latter happens
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1960 //! if @c jni_env is @c nullptr, for example.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1961
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1962 static long
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1963 get_current_thread_ID (JNIEnv *jni_env)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1964 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1965 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1966 {
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1967 // Call Java method static Thread java.lang.Thread.currentThread().
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1968 jclass_ref cls (jni_env, jni_env->FindClass ("java/lang/Thread"));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1969 jmethodID mID = jni_env->GetStaticMethodID (cls, "currentThread",
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1970 "()Ljava/lang/Thread;");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1971 jobject_ref jthread (jni_env, jni_env->CallStaticObjectMethod (cls, mID));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1972
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1973 if (jthread)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1974 {
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1975 // Call Java method long java.lang.Thread.getId().
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1976 jclass_ref jth_cls (jni_env, jni_env->GetObjectClass (jthread));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1977 mID = jni_env->GetMethodID (jth_cls, "getId", "()J");
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1978 long result = jni_env->CallLongMethod (jthread, mID);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1979 return result;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1980 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1981 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1982
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1983 return -1;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1984 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1985
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1986 //! Run the java method @c org.octave.Octave.checkPendingAction().
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1987 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1988 //! @returns 0 in any case for good reason.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1989
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
1990 static int
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
1991 java_event_hook ()
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1992 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1993 JNIEnv *current_env = thread_jni_env ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1994
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1995 if (current_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1996 {
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
1997 // Invoke static void org.octave.Octave.checkPendingAction().
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
1998 jclass_ref cls (current_env, find_octave_class (current_env,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
1999 "org/octave/Octave"));
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
2000 jmethodID mID = current_env->GetStaticMethodID
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2001 (cls, "checkPendingAction", "()V");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2002 current_env->CallStaticVoidMethod (cls, mID);
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2003
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
2004 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2005 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2006
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2007 return 0;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2008 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2009
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2010 //! Initialize java including the virtual machine (jvm) if necessary.
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2011 //!
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2012 //! Initializes the fields #jvm, #jvm_attached, #jvm_lib, and
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2013 //! #octave_thread_ID. To ensure that java is initialized, this method is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2014 //! used as part of octave functions @c javaObject, @c javaMethod,
25041
d5d61f1b6de0 Deprecate java2mat function.
Rik <rik@octave.org>
parents: 24853
diff changeset
2015 //! @c __java_get__, @c __java_set__, and @c __java2mat__.
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2016
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2017 static void
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2018 initialize_java ()
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2019 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2020 if (! jvm)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2021 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2022 try
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2023 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2024 initialize_jvm ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2025
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2026 JNIEnv *current_env = thread_jni_env ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2027
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
2028 octave::command_editor::add_event_hook (java_event_hook);
15754
bf77f7f66bdf register octave_java type at Octave startup
John W. Eaton <jwe@octave.org>
parents: 15752
diff changeset
2029
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2030 octave_thread_ID = get_current_thread_ID (current_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2031 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29007
diff changeset
2032 catch (const std::string msg)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2033 {
26149
242aa7b2c783 Silence unnecessary warnings about security-format (bug #55046).
Rik <rik@octave.org>
parents: 26113
diff changeset
2034 error ("%s", msg.c_str ());
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2035 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2036
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
2037 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2038 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2039 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2040
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2041 JNIEXPORT jboolean JNICALL
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2042 Java_org_octave_Octave_call (JNIEnv *env, jclass, jstring fcnName,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2043 jobjectArray argin, jobjectArray argout)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2044 {
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2045 std::string fname = jstring_to_string (env, fcnName);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2046
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2047 int nargout = env->GetArrayLength (argout);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2048 int nargin = env->GetArrayLength (argin);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2049
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
2050 octave_value_list varargin;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2051
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2052 for (int i = 0; i < nargin; i++)
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
2053 varargin(i) = box (env, env->GetObjectArrayElement (argin, i), nullptr);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2054
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
2055 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
2056
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
2057 octave_value_list varargout = interp.feval (fname, varargin, nargout);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2058
20121
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
2059 jobjectArray_ref out_objs (env, argout), out_clss (env);
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
2060 out_objs.detach ();
41064c150724 Return bools instead of ints in oc-java box and unbox internal functions.
Carnë Draug <carandraug@octave.org>
parents: 20120
diff changeset
2061 return unbox (env, varargout, out_objs, out_clss);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2062 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2063
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2064 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2065 Java_org_octave_OctaveReference_doFinalize (JNIEnv *, jclass, jint ID)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2066 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2067 octave_ref_map.erase (ID);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2068 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2069
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2070 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2071 Java_org_octave_Octave_doInvoke (JNIEnv *env, jclass, jint ID,
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2072 jobjectArray args)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2073 {
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25305
diff changeset
2074 auto it = octave_ref_map.find (ID);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2075
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2076 if (it != octave_ref_map.end ())
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2077 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2078 octave_value val = it->second;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2079 int len = env->GetArrayLength (args);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2080 octave_value_list oct_args;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2081
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2082 for (int i = 0; i < len; i++)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2083 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2084 jobject_ref jobj (env, env->GetObjectArrayElement (args, i));
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
2085 oct_args(i) = box (env, jobj, nullptr);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2086 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2087
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
2088 octave::interpreter& interp = octave::__get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
2089
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2090 if (val.is_function_handle ())
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2091 {
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2092 octave_function *fcn = val.function_value ();
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
2093 interp.feval (fcn, oct_args);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2094 }
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
2095 else if (val.iscell () && val.length () > 0
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2096 && (val.rows () == 1 || val.columns () == 1)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2097 && val.cell_value()(0).is_function_handle ())
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2098 {
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2099 Cell c = val.cell_value ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2100 octave_function *fcn = c(0).function_value ();
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2101
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2102 for (int i=1; i<c.numel (); i++)
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2103 oct_args(len+i-1) = c(i);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2104
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
2105 interp.feval (fcn, oct_args);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2106 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2107 else
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2108 error ("trying to invoke non-invocable object");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2109 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2110 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2111
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2112 JNIEXPORT void JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2113 Java_org_octave_Octave_doEvalString (JNIEnv *env, jclass, jstring cmd)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2114 {
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 30896
diff changeset
2115 octave::interpreter& interp = octave::__get_interpreter__ ();
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26009
diff changeset
2116
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2117 std::string s = jstring_to_string (env, cmd);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2118 int pstatus;
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 26009
diff changeset
2119 interp.eval_string (s, false, pstatus, 0);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2120 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2121
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2122 JNIEXPORT jboolean JNICALL
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2123 Java_org_octave_Octave_needThreadedInvokation (JNIEnv *env, jclass)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2124 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2125 return (get_current_thread_ID (env) != octave_thread_ID);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2126 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2127
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2128 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2129
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2130 //! Ctor.
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2131
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2132 octave_java::octave_java ()
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2133 : octave_base_value (), m_java_object (nullptr), m_java_class (nullptr)
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2134 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2135 #if ! defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2136
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2137 err_disabled_feature ("Java Objects", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2138
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2139 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2140 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2141
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2142 octave_java::octave_java (const voidptr& jobj, void *jcls)
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2143 : octave_base_value (), m_java_object (nullptr), m_java_class (nullptr)
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2144 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2145 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2146
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2147 init (jobj, jcls);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2148
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2149 #else
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2150
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2151 octave_unused_parameter (jobj);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2152 octave_unused_parameter (jcls);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2153
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2154 err_disabled_feature ("Java Objects", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2155
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2156 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2157 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2158
31845
2da025d5e98d maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents: 31814
diff changeset
2159 int octave_java::s_t_id (-1);
2da025d5e98d maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents: 31814
diff changeset
2160
2da025d5e98d maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents: 31814
diff changeset
2161 const std::string octave_java::s_t_name ("octave_java");
15813
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
2162
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
2163 void
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2164 octave_java::register_type (octave::type_info& ti)
15813
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
2165 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2166 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2167
31845
2da025d5e98d maint: Use 's_' prefix for static private class variables.
Rik <rik@octave.org>
parents: 31814
diff changeset
2168 s_t_id = ti.register_type (octave_java::s_t_name, "<unknown>",
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
2169 octave_value (new octave_java ()));
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2170
24571
7b6a5336ddb3 * ov-java.cc (octave_java::register_type): Eliminate unused variable warning.
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
2171 #else
7b6a5336ddb3 * ov-java.cc (octave_java::register_type): Eliminate unused variable warning.
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
2172
7b6a5336ddb3 * ov-java.cc (octave_java::register_type): Eliminate unused variable warning.
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
2173 octave_unused_parameter (ti);
7b6a5336ddb3 * ov-java.cc (octave_java::register_type): Eliminate unused variable warning.
John W. Eaton <jwe@octave.org>
parents: 24540
diff changeset
2174
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2175 #endif
15813
10d6ab9b1b4f Implement octave_value function class_name() for class "octave_java"
Rik <rik@octave.org>
parents: 15806
diff changeset
2176 }
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2177
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2178 dim_vector
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2179 octave_java::dims () const
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2180 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2181 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2182
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2183 JNIEnv *current_env = thread_jni_env ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2184
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2185 if (current_env && m_java_object)
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2186 return compute_array_dimensions (current_env, TO_JOBJECT (m_java_object));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2187 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2188 return dim_vector (1, 1);
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2189
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2190 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2191
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2192 // This shouldn't happen because construction of octave_java objects is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2193 // supposed to be impossible if Java is not available.
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2194
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2195 error_unexpected ("octave_java::dims");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2196
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2197 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2198 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2199
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2200 octave_value_list
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2201 octave_java::subsref (const std::string& type,
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2202 const std::list<octave_value_list>& idx, int nargout)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2203 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2204 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2205
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2206 octave_value_list retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2207 int skip = 1;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2208
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2209 JNIEnv *current_env = thread_jni_env ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2210
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2211 switch (type[0])
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2212 {
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2213 case '.':
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2214 if (type.length () > 1 && type[1] == '(')
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2215 {
31813
73fdf7f8381b maint: Use consistent coding style when calling Ffunction().
Rik <rik@octave.org>
parents: 31771
diff changeset
2216 octave_value_list ovl (2);
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31813
diff changeset
2217 m_count++;
31813
73fdf7f8381b maint: Use consistent coding style when calling Ffunction().
Rik <rik@octave.org>
parents: 31771
diff changeset
2218 ovl(0) = (idx.front ())(0);
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
2219 ovl(1) = octave_value (this);
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25305
diff changeset
2220 auto it = idx.begin ();
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2221 ovl.append (*++it);
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
2222 retval = octave::FjavaMethod (ovl, 1);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2223 skip++;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2224 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2225 else
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2226 {
31813
73fdf7f8381b maint: Use consistent coding style when calling Ffunction().
Rik <rik@octave.org>
parents: 31771
diff changeset
2227 octave_value_list ovl (2);
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31813
diff changeset
2228 m_count++;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2229 ovl(0) = octave_value (this);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2230 ovl(1) = (idx.front ())(0);
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
2231 retval = octave::F__java_get__ (ovl, 1);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2232 }
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2233 break;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2234
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2235 case '(':
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2236 if (current_env)
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
2237 retval = get_array_elements
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2238 (current_env, TO_JOBJECT (to_java ()), idx.front ());
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2239 break;
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2240
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2241 default:
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2242 error ("subsref: Java object cannot be indexed with %c", type[0]);
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2243 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2244 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2245
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2246 if (idx.size () > 1 && type.length () > 1)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2247 retval = retval(0).next_subsref (nargout, type, idx, skip);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2248
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2249 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2250
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2251 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2252
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2253 octave_unused_parameter (type);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2254 octave_unused_parameter (idx);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2255 octave_unused_parameter (nargout);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2256
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2257 // This shouldn't happen because construction of octave_java objects is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2258 // supposed to be impossible if Java is not available.
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2259
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2260 error_unexpected ("octave_java::subsref");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2261
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2262 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2263 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2264
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2265 octave_value
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2266 octave_java::subsasgn (const std::string& type,
21661
1b9a36a66b01 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21660
diff changeset
2267 const std::list<octave_value_list>& idx,
1b9a36a66b01 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21660
diff changeset
2268 const octave_value& rhs)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2269 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2270 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2271
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2272 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2273
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2274 JNIEnv *current_env = thread_jni_env ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2275
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2276 switch (type[0])
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2277 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2278 case '.':
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2279 if (type.length () == 1)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2280 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2281 // field assignment
31813
73fdf7f8381b maint: Use consistent coding style when calling Ffunction().
Rik <rik@octave.org>
parents: 31771
diff changeset
2282 octave_value_list ovl (3);
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31813
diff changeset
2283 m_count++;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2284 ovl(0) = octave_value (this);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2285 ovl(1) = (idx.front ())(0);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2286 ovl(2) = rhs;
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
2287 octave::F__java_set__ (ovl);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2288
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31813
diff changeset
2289 m_count++;
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2290 retval = octave_value (this);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2291 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2292 else if (type.length () > 2 && type[1] == '(')
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2293 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2294 std::list<octave_value_list> new_idx;
25337
3ff9192b676e use auto keyword to declare iterator variables where possible
John W. Eaton <jwe@octave.org>
parents: 25305
diff changeset
2295 auto it = idx.begin ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2296 new_idx.push_back (*it++);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2297 new_idx.push_back (*it++);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2298 octave_value_list u = subsref (type.substr (0, 2), new_idx, 1);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2299
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2300 std::list<octave_value_list> next_idx (idx);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2301 next_idx.erase (next_idx.begin ());
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2302 next_idx.erase (next_idx.begin ());
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2303 u(0).subsasgn (type.substr (2), next_idx, rhs);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2304
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31813
diff changeset
2305 m_count++;
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2306 retval = octave_value (this);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2307 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2308 else if (type[1] == '.')
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2309 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2310 octave_value_list u = subsref (type.substr (0, 1), idx, 1);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2311
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2312 std::list<octave_value_list> next_idx (idx);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2313 next_idx.erase (next_idx.begin ());
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2314 u(0).subsasgn (type.substr (1), next_idx, rhs);
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2315
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31813
diff changeset
2316 m_count++;
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2317 retval = octave_value (this);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2318 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2319 else
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2320 error ("invalid indexing/assignment on Java object");
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2321 break;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2322
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2323 case '(':
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2324 if (current_env)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2325 {
22303
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
2326 set_array_elements (current_env, TO_JOBJECT (to_java ()),
0448bf26fe98 style fixes (patch #9059)
Ernst Reissner <rei3ner@arcor.de>
parents: 22203
diff changeset
2327 idx.front (), rhs);
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2328
31814
53c10d69a9be maint: use "m_" prefix for member variables in class octave_value.
Rik <rik@octave.org>
parents: 31813
diff changeset
2329 m_count++;
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
2330 retval = octave_value (this);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2331 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2332 break;
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2333
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2334 default:
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2335 error ("Java object cannot be indexed with %c", type[0]);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2336 break;
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2337 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2338
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2339 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2340
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2341 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2342
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2343 octave_unused_parameter (type);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2344 octave_unused_parameter (idx);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2345 octave_unused_parameter (rhs);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2346
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2347 // This shouldn't happen because construction of octave_java objects is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2348 // supposed to be impossible if Java is not available.
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2349
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2350 error_unexpected ("octave_java::subsasgn");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2351
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2352 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2353 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2354
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2355 string_vector
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
2356 octave_java::map_keys () const
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2357 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2358 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2359
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2360 JNIEnv *current_env = thread_jni_env ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2361
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2362 if (current_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2363 return get_invoke_list (current_env, to_java ());
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2364 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2365 return string_vector ();
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2366
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2367 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2368
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2369 // This shouldn't happen because construction of octave_java objects is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2370 // supposed to be impossible if Java is not available.
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2371
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2372 error_unexpected ("octave_java::map_keys");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2373
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2374 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2375 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2376
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2377 octave_value
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2378 octave_java::convert_to_str_internal (bool, bool force, char type) const
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2379 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2380 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2381
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2382 JNIEnv *current_env = thread_jni_env ();
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2383
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2384 if (current_env)
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
2385 return convert_to_string (current_env, TO_JOBJECT (to_java ()), force,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
2386 type);
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2387 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2388 return octave_value ("");
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2389
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2390 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2391
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2392 octave_unused_parameter (force);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2393 octave_unused_parameter (type);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2394
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2395 // This shouldn't happen because construction of octave_java objects is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2396 // supposed to be impossible if Java is not available.
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2397
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2398 error_unexpected ("octave_java::convert_to_str_internal");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2399
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2400 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2401 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2402
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2403 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18100
diff changeset
2404 octave_java::print (std::ostream& os, bool)
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2405 {
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2406 print_raw (os);
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2407 newline (os);
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2408 }
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2409
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2410 void
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2411 octave_java::print_raw (std::ostream& os, bool) const
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2412 {
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2413 os << "<Java object: " << m_java_classname << '>';
15859
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2414 }
0e393e744e5e ov-java.cc: Replace instances of comma operator for code clarity.
Rik <rik@octave.org>
parents: 15858
diff changeset
2415
20441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2416 // FIXME: Need routines to actually save/load java objects through Serialize.
20531
dcfbf4c1c3c8 eliminate trailing whitespace and tabs from sources
John W. Eaton <jwe@octave.org>
parents: 20468
diff changeset
2417 // See bug #42112.
20441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2418
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2419 bool
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2420 octave_java::save_ascii (std::ostream& /* os */)
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2421 {
20531
dcfbf4c1c3c8 eliminate trailing whitespace and tabs from sources
John W. Eaton <jwe@octave.org>
parents: 20468
diff changeset
2422 warning ("save: unable to save java objects, skipping");
20441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2423
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2424 return true;
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2425 }
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2426
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2427 bool
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2428 octave_java::load_ascii (std::istream& /* is */)
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2429 {
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2430 // Silently skip over java object that was not saved
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2431 return true;
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2432 }
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2433
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2434 bool
26399
586413770c7f pass save_as_floats by value in octave_value save_binary functions
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
2435 octave_java::save_binary (std::ostream& /* os */, bool /* save_as_floats */)
20441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2436 {
20531
dcfbf4c1c3c8 eliminate trailing whitespace and tabs from sources
John W. Eaton <jwe@octave.org>
parents: 20468
diff changeset
2437 warning ("save: unable to save java objects, skipping");
20441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2438
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2439 return true;
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2440 }
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2442 bool
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2443 octave_java::load_binary (std::istream& /* is */, bool /* swap*/,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
2444 octave::mach_info::float_format /* fmt */)
20441
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2445 {
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2446 // Silently skip over java object that was not saved
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2447 return true;
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2448 }
b22528fd3deb Add placeholder functions for save_ascii, save_binary for octave_java (bug #45694).
Rik <rik@octave.org>
parents: 20422
diff changeset
2449
20468
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2450 bool
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2451 octave_java::save_hdf5 (octave_hdf5_id /* loc_id */, const char * /* name */,
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2452 bool /* save_as_floats */)
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2453 {
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2454 warning ("save: unable to save java objects, skipping");
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2455
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2456 return true;
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2457 }
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2458
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2459 bool
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2460 octave_java::load_hdf5 (octave_hdf5_id /* loc_id */, const char * /* name */)
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2461 {
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2462 // Silently skip object that was not saved
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2463 return true;
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2464 }
2f94652de9ff Add placeholder functions for save_hdf5, load_hdf5 for octave_java functions.
Rik <rik@octave.org>
parents: 20441
diff changeset
2465
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2466 octave_value
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2467 octave_java::do_javaMethod (void *jni_env_arg, const std::string& name,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2468 const octave_value_list& args)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2469 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2470 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2471
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2472 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2473
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2474 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2475
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2476 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2477 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2478 jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2479 if (unbox (jni_env, args, arg_objs, arg_types))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2480 {
15744
686580b1a934 eliminate most compilation warnings for __java__.cc
John W. Eaton <jwe@octave.org>
parents: 15743
diff changeset
2481 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2482 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "invokeMethod",
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2483 "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2484 jstring_ref methName (jni_env, jni_env->NewStringUTF (name.c_str ()));
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2485 jobjectArray_ref resObj (jni_env,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2486 reinterpret_cast<jobjectArray> (jni_env->CallStaticObjectMethod (helperClass, mID,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2487 to_java (), jstring (methName), jobjectArray (arg_objs), jobjectArray (arg_types))));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2488 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2489 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2490 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2491 retval = check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2492 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2493
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
2494 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2495 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2496
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2497 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2498
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2499 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2500
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2501 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2502 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2503 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2504
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2505 // This shouldn't happen because construction of octave_java objects is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
2506 // supposed to be impossible if Java is not available.
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2507
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2508 error_unexpected ("octave_java::do_javaMethod");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2509
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2510 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2511 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2512
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2513 octave_value
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
2514 octave_java::do_javaMethod (const std::string& name,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
2515 const octave_value_list& args)
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2516 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2517 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2518
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2519 return do_javaMethod (thread_jni_env (), name, args);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2520
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2521 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2522
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2523 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2524 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2525
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2526 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2527 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2528
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2529 error_unexpected ("octave_java::do_javaMethod");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2530
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2531 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2532 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2533
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2534 octave_value
24199
2ac103974d00 Remove extra space between scope operator '::' and function.
Rik <rik@octave.org>
parents: 24141
diff changeset
2535 octave_java::do_javaMethod (void *jni_env_arg,
2ac103974d00 Remove extra space between scope operator '::' and function.
Rik <rik@octave.org>
parents: 24141
diff changeset
2536 const std::string& class_name,
2ac103974d00 Remove extra space between scope operator '::' and function.
Rik <rik@octave.org>
parents: 24141
diff changeset
2537 const std::string& name,
2ac103974d00 Remove extra space between scope operator '::' and function.
Rik <rik@octave.org>
parents: 24141
diff changeset
2538 const octave_value_list& args)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2539 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2540 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2541
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2542 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2543
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2544 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2545
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2546 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2547 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2548 jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2549 if (unbox (jni_env, args, arg_objs, arg_types))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2550 {
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2551 jclass_ref helperClass (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2552 find_octave_class (jni_env,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2553 "org/octave/ClassHelper"));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2554 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2555 "invokeStaticMethod",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2556 "(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2557 jstring_ref methName (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2558 jni_env->NewStringUTF (name.c_str ()));
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2559 jstring_ref clsName (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2560 jni_env->NewStringUTF (class_name.c_str ()));
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2561 jobject_ref resObj (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2562 jni_env->CallStaticObjectMethod (helperClass,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2563 mID,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2564 jstring (clsName),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2565 jstring (methName),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2566 jobjectArray (arg_objs),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2567 jobjectArray (arg_types)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2568 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2569 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2570 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2571 retval = check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2572 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2573
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
2574 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2575 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2576
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2577 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2578
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2579 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2580
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2581 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2582 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2583 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2584 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2585
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2586 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2587 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2588
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2589 error_unexpected ("octave_java::do_javaMethod");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2590
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2591 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2592 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2593
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2594 octave_value
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2595 octave_java::do_javaMethod (const std::string& class_name,
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2596 const std::string& name,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2597 const octave_value_list& args)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2598 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2599 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2600
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2601 return do_javaMethod (thread_jni_env (), class_name, name, args);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2602
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2603 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2604
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2605 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2606 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2607 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2608
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2609 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2610 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2611
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2612 error_unexpected ("octave_java::do_javaMethod");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2613
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2614 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2615 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2616
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2617 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2618 octave_java::do_javaObject (void *jni_env_arg, const std::string& name,
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2619 const octave_value_list& args)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2620 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2621 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2622
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2623 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2624
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2625 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2626
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2627 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2628 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2629 jobjectArray_ref arg_objs (jni_env), arg_types (jni_env);
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2630
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2631 if (unbox (jni_env, args, arg_objs, arg_types))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2632 {
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2633 jclass_ref helperClass (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2634 find_octave_class (jni_env,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2635 "org/octave/ClassHelper"));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2636 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2637 "invokeConstructor",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2638 "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/Class;)Ljava/lang/Object;");
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2639 jstring_ref clsName (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2640 jni_env->NewStringUTF (name.c_str ()));
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2641 jobject_ref resObj (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2642 jni_env->CallStaticObjectMethod (helperClass,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2643 mID,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2644 jstring (clsName),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2645 jobjectArray (arg_objs),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2646 jobjectArray (arg_types)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2647
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2648 if (resObj)
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
2649 retval = octave_value (new octave_java (resObj, nullptr));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2650 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2651 check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2652 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2653
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
2654 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2655 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2656
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2657 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2658
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2659 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2660
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2661 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2662 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2663 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2664
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2665 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2666 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2667
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2668 error_unexpected ("octave_java::do_javaObject");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2669
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2670 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2671 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2672
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2673 octave_value
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
2674 octave_java::do_javaObject (const std::string& name,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
2675 const octave_value_list& args)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2676 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2677 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2678
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2679 return do_javaObject (thread_jni_env (), name, args);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2680
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2681 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2682
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2683 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2684 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2685
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2686 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2687 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2688
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2689 error_unexpected ("octave_java::do_javaObject");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2690
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2691 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2692 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2693
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2694 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2695 octave_java::do_java_get (void *jni_env_arg, const std::string& name)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2696 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2697 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2698
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2699 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2700
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2701 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2702
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2703 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2704 {
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2705 jclass_ref helperClass (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2706 find_octave_class (jni_env,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2707 "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2708 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "getField",
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2709 "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2710 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2711 jobject_ref resObj (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2712 jni_env->CallStaticObjectMethod (helperClass,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2713 mID,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2714 to_java (),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2715 jstring (fName)));
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2716
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2717 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2718 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2719 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2720 retval = check_exception (jni_env);
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2721
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
2722 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2723 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2724
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2725 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2726
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2727 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2728
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2729 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2730 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2731
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2732 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2733 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2734
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2735 error_unexpected ("octave_java::do_java_get");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2736
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2737 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2738 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2739
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2740 octave_value
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2741 octave_java::do_java_get (const std::string& name)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2742 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2743 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2744
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2745 return do_java_get (thread_jni_env (), name);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2746
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2747 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2748
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2749 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2750
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2751 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2752 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2753
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2754 error_unexpected ("octave_java::do_java_get");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2755
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2756 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2757 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2758
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2759 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2760 octave_java::do_java_get (void *jni_env_arg, const std::string& class_name,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2761 const std::string& name)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2762 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2763 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2764
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2765 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2766
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2767 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2768
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2769 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2770 {
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2771 jclass_ref helperClass (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2772 find_octave_class (jni_env,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2773 "org/octave/ClassHelper"));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2774 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2775 "getStaticField",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2776 "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2777 jstring_ref cName (jni_env, jni_env->NewStringUTF (class_name.c_str ()));
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2778 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2779 jobject_ref resObj (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2780 jni_env->CallStaticObjectMethod (helperClass, mID,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2781 jstring (cName),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2782 jstring (fName)));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2783 if (resObj)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2784 retval = box (jni_env, resObj);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2785 else
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2786 retval = check_exception (jni_env);
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2787
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
2788 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2789 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2790
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2791 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2792
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2793 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2794
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2795 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2796 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2797 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2798
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2799 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2800 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2801
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2802 error_unexpected ("octave_java::do_java_get");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2803
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2804 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2805 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2806
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2807 octave_value
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
2808 octave_java::do_java_get (const std::string& class_name,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
2809 const std::string& name)
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2810 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2811 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2812
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2813 return do_java_get (thread_jni_env (), class_name, name);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2814
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2815 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2816
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2817 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2818 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2819
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2820 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2821 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2822
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2823 error_unexpected ("octave_java::do_java_get");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2824
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2825 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2826 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2827
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2828 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2829 octave_java::do_java_set (void *jni_env_arg, const std::string& name,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2830 const octave_value& val)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2831 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2832 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2833
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2834 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2835
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2836 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2837
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2838 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2839 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2840 jobject_ref jobj (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2841 jclass_ref jcls (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2842
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2843 if (unbox (jni_env, val, jobj, jcls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2844 {
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2845 jclass_ref helperClass (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2846 find_octave_class (jni_env,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2847 "org/octave/ClassHelper"));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2848 jmethodID mID = jni_env->GetStaticMethodID (helperClass, "setField",
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2849 "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2850 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2851 jni_env->CallStaticObjectMethod (helperClass, mID, to_java (),
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2852 jstring (fName), jobject (jobj));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2853 check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2854 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2855
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
2856 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2857 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2858
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2859 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2860
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2861 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2862
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2863 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2864 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2865 octave_unused_parameter (val);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2866
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2867 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2868 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2869
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2870 error_unexpected ("octave_java::do_java_set");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2871
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2872 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2873 }
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2874
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2875 octave_value
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2876 octave_java::do_java_set (const std::string& name, const octave_value& val)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2877 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2878 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2879
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2880 return do_java_set (thread_jni_env (), name, val);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2881
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2882 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2883
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2884 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2885 octave_unused_parameter (val);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2886
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2887 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2888 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2889
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2890 error_unexpected ("octave_java::do_java_set");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2891
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2892 #endif
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2893 }
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2894
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2895 octave_value
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2896 octave_java::do_java_set (void *jni_env_arg, const std::string& class_name,
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2897 const std::string& name, const octave_value& val)
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2898 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2899 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2900
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2901 octave_value retval;
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2902
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2903 JNIEnv *jni_env = TO_JNIENV (jni_env_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2904
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2905 if (jni_env)
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2906 {
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2907 jobject_ref jobj (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2908 jclass_ref jcls (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2909
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2910 if (unbox (jni_env, val, jobj, jcls))
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2911 {
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2912 jclass_ref helperClass (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2913 find_octave_class (jni_env,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2914 "org/octave/ClassHelper"));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2915 jmethodID mID = jni_env->GetStaticMethodID (helperClass,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2916 "setStaticField",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2917 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V");
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2918 jstring_ref cName (jni_env,
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2919 jni_env->NewStringUTF (class_name.c_str ()));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2920 jstring_ref fName (jni_env, jni_env->NewStringUTF (name.c_str ()));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2921 jni_env->CallStaticObjectMethod (helperClass, mID, jstring (cName),
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2922 jstring (fName), jobject (jobj));
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2923 check_exception (jni_env);
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2924 }
16078
9439f3b5c5fa Restore default floating point state after calling Java
Mike Miller <mtmiller@ieee.org>
parents: 15879
diff changeset
2925
21894
67a5cb9cd941 hide gnulib fpucw header
John W. Eaton <jwe@octave.org>
parents: 21823
diff changeset
2926 octave_set_default_fpucw ();
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2927 }
15745
19850dfc2f88 * __java__.h, __java__.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 15744
diff changeset
2928
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2929 return retval;
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2930
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2931 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2932
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2933 octave_unused_parameter (jni_env_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2934 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2935 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2936 octave_unused_parameter (val);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2937
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2938 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2939 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2940
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2941 error_unexpected ("octave_java::do_java_set");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2942
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2943 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2944 }
15736
6faa01ff2967 build: Add --disable-java option to configure (bug #37838).
Rik <rik@octave.org>
parents: 15625
diff changeset
2945
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2946 octave_value
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
2947 octave_java::do_java_set (const std::string& class_name,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22331
diff changeset
2948 const std::string& name,
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2949 const octave_value& val)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2950 {
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2951 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2952
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2953 return do_java_set (thread_jni_env (), class_name, name, val);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2954
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2955 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2956
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2957 octave_unused_parameter (class_name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2958 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2959 octave_unused_parameter (val);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2960
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2961 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2962 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2963
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
2964 error_unexpected ("octave_java::do_java_set");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
2965
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2966 #endif
15625
acf0addfc610 include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2967 }
15736
6faa01ff2967 build: Add --disable-java option to configure (bug #37838).
Rik <rik@octave.org>
parents: 15625
diff changeset
2968
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2969 void
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2970 octave_java::init (void *jobj_arg, void *jcls_arg)
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2971 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2972 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2973
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2974 jobject jobj = TO_JOBJECT (jobj_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2975 jclass jcls = TO_JCLASS (jcls_arg);
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
2976
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2977 JNIEnv *current_env = thread_jni_env ();
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2978
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2979 if (current_env)
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2980 {
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2981 if (jobj)
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2982 m_java_object = current_env->NewGlobalRef (jobj);
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2983
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2984 if (jcls)
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2985 m_java_class = current_env->NewGlobalRef (jcls);
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2986 else if (m_java_object)
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2987 {
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2988 jclass_ref ocls (current_env,
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2989 current_env->GetObjectClass(TO_JOBJECT (m_java_object)));
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2990 m_java_class = current_env->NewGlobalRef (jclass (ocls));
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2991 }
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2992
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2993 if (m_java_class)
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
2994 {
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2995 jclass_ref clsCls (current_env,
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
2996 current_env->GetObjectClass (TO_JCLASS (m_java_class)));
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
2997 jmethodID mID = current_env->GetMethodID (clsCls,
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2998 "getCanonicalName",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2999 "()Ljava/lang/String;");
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
3000 jobject_ref resObj (current_env,
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
3001 current_env->CallObjectMethod (TO_JCLASS (m_java_class), mID));
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
3002 m_java_classname = jstring_to_string (current_env, resObj);
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3003 }
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3004 }
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3005
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3006 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3007
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3008 octave_unused_parameter (jobj_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3009 octave_unused_parameter (jcls_arg);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3010
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3011 // This shouldn't happen because construction of octave_java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3012 // objects is supposed to be impossible if Java is not available.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3013
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
3014 error_unexpected ("octave_java::init");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3015
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3016 #endif
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3017 }
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3018
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3019 void
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31730
diff changeset
3020 octave_java::release ()
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3021 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3022 #if defined (HAVE_JAVA)
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3023
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3024 JNIEnv *current_env = thread_jni_env ();
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3025
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3026 if (current_env)
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3027 {
30045
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
3028 if (m_java_object)
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
3029 current_env->DeleteGlobalRef (TO_JOBJECT (m_java_object));
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
3030
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
3031 if (m_java_class)
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
3032 current_env->DeleteGlobalRef (TO_JCLASS (m_java_class));
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
3033
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
3034 m_java_object = nullptr;
849bd0f1129c maint: use "m_" prefix for member variables of octave_value classes for Java.
Rik <rik@octave.org>
parents: 30001
diff changeset
3035 m_java_class = nullptr;
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3036 }
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3037
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3038 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3039
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
3040 // This shouldn't happen because construction of octave_java objects is
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
3041 // supposed to be impossible if Java is not available.
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3042
33353
b4683c8bf531 eliminate uses of panic_impossible in ov-java.cc
John W. Eaton <jwe@octave.org>
parents: 33086
diff changeset
3043 error_unexpected ("octave_java::release");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3044
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3045 #endif
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3046 }
15806
01d4f742d75d doc: Re-organize and improve Java Interface documentation.
Rik <rik@octave.org>
parents: 15800
diff changeset
3047
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31105
diff changeset
3048 OCTAVE_BEGIN_NAMESPACE(octave)
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
3049
24140
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
3050 // DEFUN blocks below must be outside of HAVE_JAVA block so that documentation
0b7662d8bd02 doc: libinterp/octave-value/ov-java.cc: Improve (Doxygen) comments.
Ernst Reissner <rei3ner@arcor.de>
parents: 23929
diff changeset
3051 // strings are always available, even when functions are not.
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3052
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3053 DEFUN (__java_init__, , ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3054 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30588
diff changeset
3055 @deftypefn {} {@var{status} =} __java_init__ ()
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30588
diff changeset
3056 Internal function used @strong{only} when debugging the Java interface.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30588
diff changeset
3057
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30588
diff changeset
3058 This function will directly call @code{initialize_java} to create an instance
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30588
diff changeset
3059 of a JVM.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30588
diff changeset
3060
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30588
diff changeset
3061 The return variable @var{status} is 1 if the Java interface has been created,
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30588
diff changeset
3062 and 0 otherwise.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3063 @end deftypefn */)
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3064 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3065 #if defined (HAVE_JAVA)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3066
24141
af577de75e68 maint: libinterp/octave-value/ov-java.cc: Clean up code. No function changes.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 24140
diff changeset
3067 octave_value retval = 0;
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3068
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3069 initialize_java ();
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3070
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3071 retval = 1;
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3072
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3073 return retval;
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3074
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3075 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3076
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3077 err_disabled_feature ("__java_init__", "Java");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3078
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3079 #endif
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3080 }
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3081
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3082 DEFUN (__java_exit__, , ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3083 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3084 @deftypefn {} {} __java_exit__ ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3085 Internal function used @strong{only} when debugging Java interface.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3086
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30588
diff changeset
3087 Function will directly call terminate_jvm to destroy the current JVM instance.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3088 @end deftypefn */)
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3089 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3090 #if defined (HAVE_JAVA)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3091
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3092 terminate_jvm ();
20957
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20955
diff changeset
3093
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20955
diff changeset
3094 return ovl ();
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20955
diff changeset
3095
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3096 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3097
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3098 err_disabled_feature ("__java_exit__", "Java");
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3099
15879
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3100 #endif
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3101 }
f69530e3600d make docstrings for __java_init__ and __java_exit__ available unconditionally
John W. Eaton <jwe@octave.org>
parents: 15859
diff changeset
3102
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3103 DEFUN (javaObject, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3104 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3105 @deftypefn {} {@var{jobj} =} javaObject (@var{classname})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3106 @deftypefnx {} {@var{jobj} =} javaObject (@var{classname}, @var{arg1}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3107 Create a Java object of class @var{classsname}, by calling the class
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3108 constructor with the arguments @var{arg1}, @dots{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3109
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3110 The first example below creates an uninitialized object, while the second
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3111 example supplies an initial argument to the constructor.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3112
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3113 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3114 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3115 x = javaObject ("java.lang.StringBuffer")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3116 x = javaObject ("java.lang.StringBuffer", "Initial string")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3117 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3118 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3119
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3120 @seealso{javaMethod, javaArray}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3121 @end deftypefn */)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3122 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3123 #if defined (HAVE_JAVA)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3124
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3125 if (args.length () == 0)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3126 print_usage ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3127
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3128 std::string classname = args(0).xstring_value ("javaObject: CLASSNAME must be a string");
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3129
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3130 initialize_java ();
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
3131
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3132 JNIEnv *current_env = thread_jni_env ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3133
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3134 octave_value_list tmp;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3135 for (int i=1; i<args.length (); i++)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3136 tmp(i-1) = args(i);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3137
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3138 return ovl (octave_java::do_javaObject (current_env, classname, tmp));
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
3139
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3140 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3141
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3142 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3143
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3144 err_disabled_feature ("javaObject", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3145
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3146 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3147 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3148
15825
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
3149 /*
21042
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3150 ## The tests below merely check if javaObject works at all. Whether
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3151 ## it works properly, i.e., creates the right values, is a matter of
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3152 ## Java itself. Create a Short and check if it really is a short, i.e.,
0967e2393386 * ov-java.h, ov-java.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 20974
diff changeset
3153 ## whether it overflows.
23405
32ec90068be5 use %!testif runtime tests to properly skip java tests
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3154 %!testif HAVE_JAVA; usejava ("jvm")
15825
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
3155 %! assert (javaObject ("java.lang.Short", 40000).doubleValue < 0);
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
3156 */
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
3157
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3158 DEFUN (javaMethod, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3159 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3160 @deftypefn {} {@var{ret} =} javaMethod (@var{methodname}, @var{obj})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3161 @deftypefnx {} {@var{ret} =} javaMethod (@var{methodname}, @var{obj}, @var{arg1}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3162 Invoke the method @var{methodname} on the Java object @var{obj} with the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3163 arguments @var{arg1}, @dots{}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3164
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3165 For static methods, @var{obj} can be a string representing the fully
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3166 qualified name of the corresponding class.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3167
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3168 When @var{obj} is a regular Java object, structure-like indexing can be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3169 used as a shortcut syntax. For instance, the two following statements are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3170 equivalent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3171
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3172 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3173 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3174 ret = javaMethod ("method1", x, 1.0, "a string")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3175 ret = x.method1 (1.0, "a string")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3176 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3177 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3178
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3179 @code{javaMethod} returns the result of the method invocation.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3180
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3181 @seealso{methods, javaObject}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3182 @end deftypefn */)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3183 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3184 #if defined (HAVE_JAVA)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3185
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3186 if (args.length () < 2)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3187 print_usage ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3188
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3189 std::string methodname = args(0).xstring_value ("javaMethod: METHODNAME must be a string");
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3190
15790
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
3191 initialize_java ();
921912c92102 Deprecate java_invoke, replace with javaMethod.
Rik <rik@octave.org>
parents: 15771
diff changeset
3192
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3193 JNIEnv *current_env = thread_jni_env ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3194
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3195 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3196
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3197 octave_value_list tmp;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3198 for (int i=2; i<args.length (); i++)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3199 tmp(i-2) = args(i);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3200
23578
7b47b7c2d6c7 maint: Deprecate is_java and replace with isjava.
Rik <rik@octave.org>
parents: 23577
diff changeset
3201 if (args(1).isjava ())
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3202 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3203 octave_java *jobj = TO_JAVA (args(1));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3204 retval = jobj->do_javaMethod (current_env, methodname, tmp);
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3205 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3206 else if (args(1).is_string ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3207 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3208 std::string cls = args(1).string_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3209 retval = octave_java::do_javaMethod (current_env, cls, methodname, tmp);
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3210 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3211 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3212 error ("javaMethod: OBJ must be a Java object or a string");
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3213
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3214 return retval;
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
3215
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3216 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3217
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3218 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3219
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3220 err_disabled_feature ("javaMethod", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3221
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3222 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3223 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3224
15825
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
3225 /*
23405
32ec90068be5 use %!testif runtime tests to properly skip java tests
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3226 %!testif HAVE_JAVA; usejava ("jvm")
24671
5aa9c885ea18 Rewrite certain Java BIST tests to pass with Java 9 (bug #52627).
Rik <rik@octave.org>
parents: 24592
diff changeset
3227 %! jver = javaMethod ("getProperty", "java.lang.System", "java.version");
5aa9c885ea18 Rewrite certain Java BIST tests to pass with Java 9 (bug #52627).
Rik <rik@octave.org>
parents: 24592
diff changeset
3228 %! jver = strsplit (jver, ".");
5aa9c885ea18 Rewrite certain Java BIST tests to pass with Java 9 (bug #52627).
Rik <rik@octave.org>
parents: 24592
diff changeset
3229 %! if (numel (jver) > 1)
5aa9c885ea18 Rewrite certain Java BIST tests to pass with Java 9 (bug #52627).
Rik <rik@octave.org>
parents: 24592
diff changeset
3230 %! assert (isfinite (str2double (jver{1})));
5aa9c885ea18 Rewrite certain Java BIST tests to pass with Java 9 (bug #52627).
Rik <rik@octave.org>
parents: 24592
diff changeset
3231 %! assert (isfinite (str2double (jver{2})));
5aa9c885ea18 Rewrite certain Java BIST tests to pass with Java 9 (bug #52627).
Rik <rik@octave.org>
parents: 24592
diff changeset
3232 %! else
5aa9c885ea18 Rewrite certain Java BIST tests to pass with Java 9 (bug #52627).
Rik <rik@octave.org>
parents: 24592
diff changeset
3233 %! assert (isfinite (str2double (jver{1})));
5aa9c885ea18 Rewrite certain Java BIST tests to pass with Java 9 (bug #52627).
Rik <rik@octave.org>
parents: 24592
diff changeset
3234 %! endif
15825
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
3235 */
9854666df787 ov-java.cc: tests added for javaObject and javaMethod
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 15824
diff changeset
3236
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3237 DEFUN (__java_get__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3238 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3239 @deftypefn {} {@var{val} =} __java_get__ (@var{obj}, @var{name})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3240 Get the value of the field @var{name} of the Java object @var{obj}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3241
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3242 For static fields, @var{obj} can be a string representing the fully
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3243 qualified name of the corresponding class.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3244
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3245 When @var{obj} is a regular Java object, structure-like indexing can be used
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3246 as a shortcut syntax. For instance, the two following statements are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3247 equivalent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3248
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3249 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3250 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3251 __java_get__ (x, "field1")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3252 x.field1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3253 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3254 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3255
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3256 @seealso{__java_set__, javaMethod, javaObject}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3257 @end deftypefn */)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3258 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3259 #if defined (HAVE_JAVA)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3260
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3261 if (args.length () != 2)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3262 print_usage ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3263
26365
45d5a4ae636b ov-java.cc: Bugfix use xstring_value for extraction
Andreas Weber <octave@josoansi.de>
parents: 26149
diff changeset
3264 std::string name = args(1).xstring_value ("__java_get__: NAME must be a string");
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3265
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3266 initialize_java ();
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3267
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3268 JNIEnv *current_env = thread_jni_env ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3269
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3270 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3271
23578
7b47b7c2d6c7 maint: Deprecate is_java and replace with isjava.
Rik <rik@octave.org>
parents: 23577
diff changeset
3272 if (args(0).isjava ())
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3273 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3274 octave_java *jobj = TO_JAVA (args(0));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3275 retval = jobj->do_java_get (current_env, name);
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3276 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3277 else if (args(0).is_string ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3278 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3279 std::string cls = args(0).string_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3280 retval = octave_java::do_java_get (current_env, cls, name);
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3281 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3282 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3283 error ("__java_get__: OBJ must be a Java object or a string");
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3284
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3285 return retval;
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
3286
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3287 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3288
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3289 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3290
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3291 err_disabled_feature ("__java_get__", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3292
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3293 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3294 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3295
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3296 DEFUN (__java_set__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3297 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3298 @deftypefn {} {@var{obj} =} __java_set__ (@var{obj}, @var{name}, @var{val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3299 Set the value of the field @var{name} of the Java object @var{obj} to
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3300 @var{val}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3301
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3302 For static fields, @var{obj} can be a string representing the fully
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3303 qualified named of the corresponding Java class.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3304
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3305 When @var{obj} is a regular Java object, structure-like indexing can be
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3306 used as a shortcut syntax. For instance, the two following statements are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3307 equivalent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3308
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3309 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3310 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3311 __java_set__ (x, "field1", val)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3312 x.field1 = val
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3313 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3314 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3315
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3316 @seealso{__java_get__, javaMethod, javaObject}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3317 @end deftypefn */)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3318 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3319 #if defined (HAVE_JAVA)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3320
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3321 if (args.length () != 3)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3322 print_usage ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3323
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3324 std::string name = args(1).xstring_value ("__java_set__: NAME must be a string");
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3325
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3326 initialize_java ();
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3327
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3328 JNIEnv *current_env = thread_jni_env ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3329
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3330 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3331
23578
7b47b7c2d6c7 maint: Deprecate is_java and replace with isjava.
Rik <rik@octave.org>
parents: 23577
diff changeset
3332 if (args(0).isjava ())
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3333 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3334 octave_java *jobj = TO_JAVA (args(0));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3335 retval = jobj->do_java_set (current_env, name, args(2));
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3336 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3337 else if (args(0).is_string ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3338 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3339 std::string cls = args(0).string_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3340 retval = octave_java::do_java_set (current_env, cls, name, args(2));
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3341 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3342 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3343 error ("__java_set__: OBJ must be a Java object or a string");
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3344
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3345 return retval;
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
3346
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3347 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3348
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3349 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3350
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3351 err_disabled_feature ("__java_set__", "Java");
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3352
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3353 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3354 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3355
25041
d5d61f1b6de0 Deprecate java2mat function.
Rik <rik@octave.org>
parents: 24853
diff changeset
3356 DEFUN (__java2mat__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3357 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30588
diff changeset
3358 @deftypefn {} {@var{mat} =} __java2mat__ (@var{javaobj})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3359 Undocumented internal function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3360 @end deftypefn */)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3361 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3362 #if defined (HAVE_JAVA)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3363
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3364 if (args.length () != 1)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3365 print_usage ();
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3366
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3367 initialize_java ();
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3368
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3369 JNIEnv *current_env = thread_jni_env ();
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3370
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3371 octave_value_list retval;
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
3372
23578
7b47b7c2d6c7 maint: Deprecate is_java and replace with isjava.
Rik <rik@octave.org>
parents: 23577
diff changeset
3373 if (args(0).isjava ())
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3374 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
3375 octave_java *jobj = TO_JAVA (args(0));
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23717
diff changeset
3376 retval = ovl (box_more (current_env, jobj->to_java (), nullptr));
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3377 }
20559
0650b8431037 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3378 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3379 retval = ovl (args(0));
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3380
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3381 return retval;
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
3382
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3383 #else
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3384
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3385 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3386
25041
d5d61f1b6de0 Deprecate java2mat function.
Rik <rik@octave.org>
parents: 24853
diff changeset
3387 err_disabled_feature ("__java2mat__", "Java");
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3388
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3389 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3390 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3391
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3392 DEFUN (java_matrix_autoconversion, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3393 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3394 @deftypefn {} {@var{val} =} java_matrix_autoconversion ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3395 @deftypefnx {} {@var{old_val} =} java_matrix_autoconversion (@var{new_val})
30588
ed17822e7662 doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents: 30565
diff changeset
3396 @deftypefnx {} {@var{old_val} =} java_matrix_autoconversion (@var{new_val}, "local")
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3397 Query or set the internal variable that controls whether Java arrays are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3398 automatically converted to Octave matrices.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3399
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3400 The default value is false.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3401
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3402 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3403 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3404 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3405 @seealso{java_unsigned_autoconversion, debug_java}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3406 @end deftypefn */)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3407 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3408 #if defined (HAVE_JAVA)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3409
30001
428cccc75cc9 move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29974
diff changeset
3410 return set_internal_variable (Vjava_matrix_autoconversion, args, nargout,
428cccc75cc9 move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29974
diff changeset
3411 "java_matrix_autoconversion");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3412
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3413 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3414
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3415 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3416 octave_unused_parameter (nargout);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3417
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3418 err_disabled_feature ("java_matrix_autoconversion", "Java");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3419
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3420 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3421 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3422
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3423 DEFUN (java_unsigned_autoconversion, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3424 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3425 @deftypefn {} {@var{val} =} java_unsigned_autoconversion ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3426 @deftypefnx {} {@var{old_val} =} java_unsigned_autoconversion (@var{new_val})
30588
ed17822e7662 doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents: 30565
diff changeset
3427 @deftypefnx {} {@var{old_val} =} java_unsigned_autoconversion (@var{new_val}, "local")
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3428 Query or set the internal variable that controls how integer classes are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3429 converted when @code{java_matrix_autoconversion} is enabled.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3430
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3431 When enabled, Java arrays of class Byte or Integer are converted to matrices
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3432 of class uint8 or uint32 respectively. The default value is true.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3433
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3434 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3435 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3436 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3437 @seealso{java_matrix_autoconversion, debug_java}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3438 @end deftypefn */)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3439 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3440 #if defined (HAVE_JAVA)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3441
30001
428cccc75cc9 move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29974
diff changeset
3442 return set_internal_variable (Vjava_unsigned_autoconversion, args, nargout,
428cccc75cc9 move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29974
diff changeset
3443 "java_unsigned_autoconversion");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3444
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3445 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3446
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3447 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3448 octave_unused_parameter (nargout);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3449
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3450 err_disabled_feature ("java_unsigned_autoconversion", "Java");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3451
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3452 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3453 }
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3454
15800
d9b8333df5e4 Deprecate java_debug, java_convert_matrix, java_unsigned_conversion.
Rik <rik@octave.org>
parents: 15798
diff changeset
3455 DEFUN (debug_java, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3456 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3457 @deftypefn {} {@var{val} =} debug_java ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3458 @deftypefnx {} {@var{old_val} =} debug_java (@var{new_val})
30588
ed17822e7662 doc: Always have a return value for functions which set internal variables (bug #61681)
Rik <rik@octave.org>
parents: 30565
diff changeset
3459 @deftypefnx {} {@var{old_val} =} debug_java (@var{new_val}, "local")
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3460 Query or set the internal variable that determines whether extra debugging
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3461 information regarding the initialization of the JVM and any Java exceptions
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3462 is printed.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3463
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3464 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3465 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3466 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3467 @seealso{java_matrix_autoconversion, java_unsigned_autoconversion}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3468 @end deftypefn */)
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3469 {
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3470 #if defined (HAVE_JAVA)
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3471
30001
428cccc75cc9 move most functions in variables.cc to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29974
diff changeset
3472 return set_internal_variable (Vdebug_java, args, nargout, "debug_java");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3473
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3474 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3475
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3476 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3477 octave_unused_parameter (nargout);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3478
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3479 err_disabled_feature ("debug_java", "Java");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21661
diff changeset
3480
15771
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3481 #endif
4698ea77aa75 Hide java_init, java_exit functions. Deprecate java_new, java_set, java_get.
Rik <rik@octave.org>
parents: 15770
diff changeset
3482 }
15736
6faa01ff2967 build: Add --disable-java option to configure (bug #37838).
Rik <rik@octave.org>
parents: 15625
diff changeset
3483
21379
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3484 // Outside of #if defined (HAVE_JAVA) because it is desirable to be able
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3485 // to test for the presence of a Java object without having Java
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3486 // installed.
93c489ca8a6b elimnate HAVE_JAVA from ov-java.h
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3487
15770
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3488 DEFUN (isjava, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3489 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
3490 @deftypefn {} {@var{tf} =} isjava (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3491 Return true if @var{x} is a Java object.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3492 @seealso{class, typeinfo, isa, javaObject}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21894
diff changeset
3493 @end deftypefn */)
15770
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3494 {
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3495 if (args.length () != 1)
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3496 print_usage ();
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20765
diff changeset
3497
23578
7b47b7c2d6c7 maint: Deprecate is_java and replace with isjava.
Rik <rik@octave.org>
parents: 23577
diff changeset
3498 return ovl (args(0).isjava ());
15770
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3499 }
e61405133a76 Add new isjava function.
Rik <rik@octave.org>
parents: 15763
diff changeset
3500
20120
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
3501 /*
20152
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3502 ## Check automatic conversion of java primitive arrays into octave types.
23405
32ec90068be5 use %!testif runtime tests to properly skip java tests
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3503 %!testif HAVE_JAVA; usejava ("jvm")
20152
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3504 %! assert (javaObject ("java.lang.String", "hello").getBytes (),
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3505 %! int8 ([104 101 108 108 111]'));
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3506
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3507 ## Check automatic conversion of octave types into java primitive arrays.
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3508 ## Note that uint8 is casted to int8.
23405
32ec90068be5 use %!testif runtime tests to properly skip java tests
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3509 %!testif HAVE_JAVA; usejava ("jvm")
20152
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3510 %! assert (javaMethod ("binarySearch", "java.util.Arrays", [90 100 255], 255), 2);
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3511 %! assert (javaMethod ("binarySearch", "java.util.Arrays", uint8 ([90 100 255]), uint8 (255)) < 0);
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3512 %! assert (javaMethod ("binarySearch", "java.util.Arrays", uint8 ([90 100 128]), uint8 (128)) < 0);
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3513 %! assert (javaMethod ("binarySearch", "java.util.Arrays", uint8 ([90 100 127]), uint8 (127)), 2);
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3514 %! assert (javaMethod ("binarySearch", "java.util.Arrays", uint16 ([90 100 128]), uint16 (128)), 2);
8187a66039e4 Don't run Java BIST tests if HAVA_JAVA is false.
Rik <rik@octave.org>
parents: 20124
diff changeset
3515
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22407
diff changeset
3516 ## Check we can create objects that wrap java literals
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
3517 %!testif HAVE_JAVA; usejava ("jvm") <*38821>
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3518 %! assert (class (javaObject ("java.lang.Byte", uint8 (1))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3519 %! "java.lang.Byte");
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3520 %! assert (class (javaObject ("java.lang.Byte", int8 (1))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3521 %! "java.lang.Byte");
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3522 %! assert (class (javaObject ("java.lang.Short", uint16 (1))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3523 %! "java.lang.Short");
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3524 %! assert (class (javaObject ("java.lang.Short", int16 (1))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3525 %! "java.lang.Short");
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3526 %! assert (class (javaObject ("java.lang.Integer", uint32 (1))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3527 %! "java.lang.Integer");
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3528 %! assert (class (javaObject ("java.lang.Integer", int32 (1))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3529 %! "java.lang.Integer");
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3530 %! assert (class (javaObject ("java.lang.Long", uint64 (1))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3531 %! "java.lang.Long");
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3532 %! assert (class (javaObject ("java.lang.Long", int64 (1))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3533 %! "java.lang.Long");
20260
137f183b7dee Fix conversion from string cell array into java's String[] (bug #45290)
Carnë Draug <carandraug@octave.org>
parents: 20250
diff changeset
3534
23681
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3535 ## More checks of java numeric and boolean class instances
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3536 %!testif HAVE_JAVA; usejava ("jvm")
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3537 %! n = javaObject ("java.lang.Double", 1.35);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3538 %! assert (n.compareTo (1.0), 1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3539 %! assert (n.compareTo (1.35), 0);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3540 %! assert (n.compareTo (10), -1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3541 %! assert (n.isInfinite (), false);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3542
28889
a2fbb2074436 ov-java.cc: Add bug number to BIST (bug #51804).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28527
diff changeset
3543 %!testif HAVE_JAVA; usejava ("jvm") <51804>
23681
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3544 %! n = javaObject ("java.lang.Float", 1.35);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3545 %! assert (n.compareTo (1.0), 1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3546 %! assert (n.compareTo (1.35), 0);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3547 %! assert (n.compareTo (10), -1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3548 %! assert (n.doubleValue (), 1.35, 1e7);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3549
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3550 %!testif HAVE_JAVA; usejava ("jvm")
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3551 %! n = javaObject ("java.lang.Long", (int64 (1)));
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3552 %! assert (n.compareTo (int64 (0)), 1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3553 %! assert (n.compareTo (int64 (1)), 0);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3554 %! assert (n.compareTo (int64 (2)), -1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3555 %! assert (n.toString (), "1");
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3556
24671
5aa9c885ea18 Rewrite certain Java BIST tests to pass with Java 9 (bug #52627).
Rik <rik@octave.org>
parents: 24592
diff changeset
3557 %!testif HAVE_JAVA; usejava ("jvm") <51804>
23681
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3558 %! n = javaObject ("java.lang.Integer", 1.35);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3559 %! assert (n.compareTo (0), 1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3560 %! assert (n.compareTo (1), 0);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3561 %! assert (n.compareTo (2), -1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3562
25305
47c803b4b8ae test: tag possible test failure with known bug #51804
Mike Miller <mtmiller@octave.org>
parents: 25139
diff changeset
3563 %!testif HAVE_JAVA; usejava ("jvm") <51804>
23681
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3564 %! n = javaObject ("java.lang.Short", 1.35);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3565 %! assert (n.compareTo (0), 1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3566 %! assert (n.compareTo (1), 0);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3567 %! assert (n.compareTo (2), -1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3568
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3569 %!testif HAVE_JAVA; usejava ("jvm")
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3570 %! n = javaObject ("java.lang.Byte", int8 (17));
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3571 %! assert (n.compareTo (int8 (20)), -3);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3572 %! assert (n.compareTo (int8 (10)), 7);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3573 %! assert (n.compareTo (int8 (17)), 0);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3574
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3575 %!testif HAVE_JAVA; usejava ("jvm")
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3576 %! b = javaObject ("java.lang.Boolean", true);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3577 %! assert (b.compareTo (true), 0);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3578 %! assert (b.compareTo (false), 1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3579 %! b = javaObject ("java.lang.Boolean", false);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3580 %! assert (b.compareTo (true), -1);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3581 %! assert (b.compareTo (false), 0);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3582
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22407
diff changeset
3583 ## Test for automatic conversion of specific numeric classes
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
3584 %!testif HAVE_JAVA; usejava ("jvm") <*48013>
22203
2f301a30aeed Add tests for Java numeric type conversion (bug #48013)
Mike Miller <mtmiller@octave.org>
parents: 22202
diff changeset
3585 %! assert (javaMethod ("valueOf", "java.lang.Byte", int8 (1)), 1)
2f301a30aeed Add tests for Java numeric type conversion (bug #48013)
Mike Miller <mtmiller@octave.org>
parents: 22202
diff changeset
3586 %! assert (javaMethod ("valueOf", "java.lang.Short", int16 (1)), 1)
2f301a30aeed Add tests for Java numeric type conversion (bug #48013)
Mike Miller <mtmiller@octave.org>
parents: 22202
diff changeset
3587 %! assert (javaMethod ("valueOf", "java.lang.Integer", int32 (1)), 1)
2f301a30aeed Add tests for Java numeric type conversion (bug #48013)
Mike Miller <mtmiller@octave.org>
parents: 22202
diff changeset
3588 %! assert (javaMethod ("valueOf", "java.lang.Long", int64 (1)), 1)
2f301a30aeed Add tests for Java numeric type conversion (bug #48013)
Mike Miller <mtmiller@octave.org>
parents: 22202
diff changeset
3589 %! assert (javaMethod ("valueOf", "java.lang.Float", single (1)), 1)
2f301a30aeed Add tests for Java numeric type conversion (bug #48013)
Mike Miller <mtmiller@octave.org>
parents: 22202
diff changeset
3590 %! assert (javaMethod ("valueOf", "java.lang.Double", double (1)), 1)
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3591 %! assert (class (javaMethod ("valueOf", "java.math.BigDecimal", double (1))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3592 %! "java.math.BigDecimal")
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3593 %! assert (class (javaMethod ("valueOf", "java.math.BigInteger", int64 (1))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30139
diff changeset
3594 %! "java.math.BigInteger")
22203
2f301a30aeed Add tests for Java numeric type conversion (bug #48013)
Mike Miller <mtmiller@octave.org>
parents: 22202
diff changeset
3595
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22407
diff changeset
3596 ## Automatic conversion from string cell array into String[]
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
3597 %!testif HAVE_JAVA; usejava ("jvm") <*45290>
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
3598 %! assert (javaMethod ("binarySearch", "java.util.Arrays", {"aaa", "bbb", "ccc", "zzz"}, "aaa"), 0);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
3599 %! assert (javaMethod ("binarySearch", "java.util.Arrays", {"aaa", "bbb", "ccc", "zzz"}, "zzz"), 3);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21547
diff changeset
3600 %! assert (javaMethod ("binarySearch", "java.util.Arrays", {"aaa", "bbb", "ccc", "zzz"}, "hhh") < 0);
23671
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3601
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3602 ## Test that Octave index syntax allows Java object method calls with args
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3603 %!testif HAVE_JAVA; usejava ("jvm") <*51152>
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3604 %! s = javaObject ("java.lang.String", "Octave");
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3605 %! assert (s.length (), 6)
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3606 %! assert (s.charAt (0), "O")
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3607 %! assert (s.charAt (5), "e")
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3608 %! assert (s.matches ("^Octave$"))
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3609 %! assert (s.startsWith ("Oct"))
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3610 %! ## same tests with Java object as part of another indexing expression
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3611 %! a(1).s = s;
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3612 %! assert (! a(1).s.isEmpty ())
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3613 %! assert (a(1).s.length (), 6)
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3614 %! assert (a(1).s.charAt (0), "O")
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3615 %! assert (a(1).s.charAt (5), "e")
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3616 %! assert (a(1).s.matches ("^Octave$"))
d197f62cde8a restore Java method calls by delegating indexing properly (bug #51152)
Mike Miller <mtmiller@octave.org>
parents: 23592
diff changeset
3617 %! assert (a(1).s.startsWith ("Oct"))
23681
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3618
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3619 ## Check for basic usability of the java awt library
24853
1e207bd05b5d avoid AWT test on OS X (bug #53305)
John W. Eaton <jwe@octave.org>
parents: 24684
diff changeset
3620 ## Skip the test on OS X where we currently have Java 9 and attempting
1e207bd05b5d avoid AWT test on OS X (bug #53305)
John W. Eaton <jwe@octave.org>
parents: 24684
diff changeset
3621 ## to use awt causes Octave to exit with a message about Java not being
1e207bd05b5d avoid AWT test on OS X (bug #53305)
John W. Eaton <jwe@octave.org>
parents: 24684
diff changeset
3622 ## installed (it is) instead of returning false.
1e207bd05b5d avoid AWT test on OS X (bug #53305)
John W. Eaton <jwe@octave.org>
parents: 24684
diff changeset
3623 %!testif HAVE_JAVA; ! ismac () && usejava ("jvm") && usejava ("awt") && have_window_system ()
23681
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3624 %! frame = javaObject ("java.awt.Frame");
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3625 %! frame.setResizable (true);
8b5bc5e5f74b add unit tests creating and calling methods on some basic Java types
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 23671
diff changeset
3626 %! assert (frame.isResizable ());
20120
2db2db2df55b Automatically convert arrays of java primitives into Octave types (bug #44882)
Carnë Draug <carandraug@octave.org>
parents: 20028
diff changeset
3627 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
3628
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31105
diff changeset
3629 OCTAVE_END_NAMESPACE(octave)