The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

external: Update jnipp

+126 -4
+5
src/external/jnipp/.editorconfig
··· 1 + 2 + [.h,.cpp] 3 + indent_size = 4 4 + indent_style = space 5 + trim_trailing_whitespace = true
+89 -2
src/external/jnipp/jnipp.cpp
··· 6 6 #else 7 7 // UNIX Dependencies 8 8 # include <dlfcn.h> 9 + # include <unistd.h> 10 + # include <tuple> 9 11 #endif 10 12 11 13 // External Dependencies ··· 24 26 static std::atomic_bool isVm(false); 25 27 static JavaVM* javaVm = nullptr; 26 28 29 + static bool isAttached(JavaVM *vm) { 30 + JNIEnv *env = nullptr; 31 + return vm->GetEnv((void **)&env, JNI_VERSION_1_2) == JNI_OK; 32 + } 27 33 /** 28 34 Maintains the lifecycle of a JNIEnv. 29 35 */ ··· 57 63 if (vm == nullptr) 58 64 throw InitializationException("JNI not initialized"); 59 65 60 - if (vm->GetEnv((void**)&_env, JNI_VERSION_1_2) != JNI_OK) 66 + if (!isAttached(vm)) 61 67 { 62 68 #ifdef __ANDROID__ 63 69 if (vm->AttachCurrentThread(&_env, nullptr) != 0) ··· 150 156 { 151 157 static thread_local ScopedEnv env; 152 158 159 + if (env.get() != nullptr && !isAttached(javaVm)) 160 + { 161 + // we got detached, so clear it. 162 + // will be re-populated from static javaVm below. 163 + env = ScopedEnv{}; 164 + } 165 + 153 166 if (env.get() == nullptr) 167 + { 154 168 env.init(javaVm); 169 + } 155 170 156 171 return env.get(); 157 172 } ··· 1270 1285 1271 1286 typedef jint (JNICALL *CreateVm_t)(JavaVM**, void**, void*); 1272 1287 1288 + #ifndef _WIN32 1289 + static bool fileExists(const std::string& filePath) 1290 + { 1291 + return access(filePath.c_str(), F_OK) != -1; 1292 + } 1293 + 1294 + template <size_t N> 1295 + static ssize_t readlink_safe(const char *pathname, char (&output)[N]) { 1296 + auto len = readlink(pathname, output, N - 1); 1297 + if (len > 0) { 1298 + output[len] = '\0'; 1299 + } 1300 + return len; 1301 + } 1302 + 1303 + static std::pair<ssize_t, std::string> 1304 + readlink_as_string(const char *pathname) { 1305 + char buf[2048] = {}; 1306 + auto len = readlink_safe(pathname, buf); 1307 + if (len <= 0) { 1308 + return {len, {}}; 1309 + } 1310 + return {len, std::string{buf, static_cast<size_t>(len)}}; 1311 + } 1312 + static std::string readlink_deep(const char *pathname) { 1313 + std::string prev{pathname}; 1314 + ssize_t len = 0; 1315 + std::string next; 1316 + while (true) { 1317 + std::tie(len, next) = readlink_as_string(prev.c_str()); 1318 + if (!next.empty()) { 1319 + prev = next; 1320 + } else { 1321 + return prev; 1322 + } 1323 + } 1324 + } 1273 1325 1326 + static std::string drop_path_components(const std::string & path, size_t num_components) { 1327 + size_t pos = std::string::npos; 1328 + size_t slash_pos = std::string::npos; 1329 + for (size_t i = 0; i < num_components; ++i) { 1330 + slash_pos = path.find_last_of('/', pos); 1331 + if (slash_pos == std::string::npos || slash_pos == 0) { 1332 + return {}; 1333 + } 1334 + pos = slash_pos - 1; 1335 + } 1336 + return std::string{path.c_str(), slash_pos}; 1337 + } 1338 + #endif 1274 1339 static std::string detectJvmPath() 1275 1340 { 1276 1341 std::string result; ··· 1321 1386 javaHome + "\\bin\\server\\jvm.dll" 1322 1387 }; 1323 1388 1324 - for (auto i : options) 1389 + for (auto const& i : options) 1325 1390 if (fileExists(i)) 1326 1391 return i; 1327 1392 } ··· 1338 1403 #endif 1339 1404 result = libJvmPath; 1340 1405 } else { 1406 + std::string path = readlink_deep("/usr/bin/java"); 1407 + if (!path.empty()) { 1408 + // drop bin and java 1409 + auto javaHome = drop_path_components(path, 2); 1410 + if (!javaHome.empty()) { 1411 + std::string options[] = { 1412 + javaHome + "/jre/lib/amd64/server/libjvm.so", 1413 + javaHome + "/jre/lib/amd64/client/libjvm.so", 1414 + javaHome + "/jre/lib/server/libjvm.so", 1415 + javaHome + "/jre/lib/client/libjvm.so", 1416 + javaHome + "/lib/server/libjvm.so", 1417 + javaHome + "/lib/client/libjvm.so", 1418 + }; 1419 + 1420 + for (auto const &i : options) { 1421 + fprintf(stderr, "trying %s\n", i.c_str()); 1422 + if (fileExists(i)) { 1423 + return i; 1424 + } 1425 + } 1426 + } 1427 + } 1341 1428 // Best guess so far. 1342 1429 result = "/usr/lib/jvm/default-java/jre/lib/amd64/server/libjvm.so"; 1343 1430 }
+21 -1
src/external/jnipp/jnipp.h
··· 175 175 value_t values[sizeof...(TArgs)]; 176 176 }; 177 177 178 + /* specialization for empty array - no args. Avoids "empty array" warning. */ 179 + template <> 180 + class ArgArray<> 181 + { 182 + public: 183 + ArgArray() { 184 + std::memset(this, 0, sizeof(ArgArray<>)); 185 + } 186 + 187 + ~ArgArray() { 188 + } 189 + 190 + value_t values[1]; 191 + }; 178 192 long getArrayLength(jarray array); 179 193 194 + /** 195 + * @brief Used as a tag type for dispatching internally based on return type. 196 + * 197 + * @tparam T The type to wrap. 198 + */ 180 199 template<typename T> 181 - struct ReturnTypeWrapper{ 200 + struct ReturnTypeWrapper 201 + { 182 202 using type = T; 183 203 }; 184 204 }
+1 -1
src/external/jnipp/makefile
··· 15 15 16 16 JAVA_HOME ?= /usr/lib/jvm/default-java 17 17 18 - CXXFLAGS=-I. -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(OS_NAME) -ldl -std=c++11 18 + CXXFLAGS=-I. -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(OS_NAME) -ldl -std=c++11 -Wall -g 19 19 20 20 SRC=jnipp.o main.o 21 21 VPATH=tests
+10
src/external/jnipp/tests/main.cpp
··· 249 249 ASSERT(b.isNull()); 250 250 } 251 251 252 + TEST(Object_nullary_construct_from_signature) 253 + { 254 + jni::Class String("java/lang/String"); 255 + jni::method_t init = String.getMethod("<init>", "()V"); 256 + jni::Object i = String.newInstance(init); 257 + ASSERT(!i.isNull()); 258 + jni::internal::ArgArray<> a; 259 + } 260 + 252 261 TEST(Object_call) 253 262 { 254 263 jni::Class Integer("java/lang/Integer"); ··· 575 584 576 585 // jni::Object Tests 577 586 RUN_TEST(Object_defaultConstructor_isNull); 587 + RUN_TEST(Object_nullary_construct_from_signature); 578 588 RUN_TEST(Object_copyConstructorIsSameObject); 579 589 RUN_TEST(Object_moveConstructor); 580 590 RUN_TEST(Object_copyAssignmentOperator);