Mercurial > octave-nkf
comparison libinterp/octave-value/ov-java.cc @ 17898:8c33abdd2f9a
maint: Avoid using NULL in C++ code.
* qtinfo/parser.cc, profiler.cc, profiler.h, txt-eng-ft.cc,
__init_fltk__.cc, ov-fcn-handle.cc, ov-java.cc, mkoctfile.in.cc:
Avoid using NULL in C++ code.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 11 Nov 2013 01:49:57 -0500 |
parents | 175b392e91fe |
children | 6a71e5030df5 446c46af4b42 |
comparison
equal
deleted
inserted
replaced
17897:185038fe7a16 | 17898:8c33abdd2f9a |
---|---|
239 static void | 239 static void |
240 set_dll_directory (const std::string& dir = "") | 240 set_dll_directory (const std::string& dir = "") |
241 { | 241 { |
242 typedef BOOL (WINAPI *dllfcn_t) (LPCTSTR path); | 242 typedef BOOL (WINAPI *dllfcn_t) (LPCTSTR path); |
243 | 243 |
244 static dllfcn_t dllfcn = NULL; | 244 static dllfcn_t dllfcn = 0; |
245 static bool first = true; | 245 static bool first = true; |
246 | 246 |
247 if (! dllfcn && first) | 247 if (! dllfcn && first) |
248 { | 248 { |
249 HINSTANCE hKernel32 = GetModuleHandle ("kernel32"); | 249 HINSTANCE hKernel32 = GetModuleHandle ("kernel32"); |
251 "SetDllDirectoryA")); | 251 "SetDllDirectoryA")); |
252 first = false; | 252 first = false; |
253 } | 253 } |
254 | 254 |
255 if (dllfcn) | 255 if (dllfcn) |
256 dllfcn (dir.empty () ? NULL : dir.c_str ()); | 256 dllfcn (dir.empty () ? 0 : dir.c_str ()); |
257 } | 257 } |
258 #endif | 258 #endif |
259 | 259 |
260 static std::string | 260 static std::string |
261 initial_java_dir (void) | 261 initial_java_dir (void) |
422 // Most of the time JVM already exists and has been initialized. | 422 // Most of the time JVM already exists and has been initialized. |
423 if (jvm) | 423 if (jvm) |
424 return; | 424 return; |
425 | 425 |
426 JNIEnv *current_env; | 426 JNIEnv *current_env; |
427 const char *static_locale = setlocale (LC_ALL, NULL); | 427 const char *static_locale = setlocale (LC_ALL, 0); |
428 const std::string locale (static_locale); | 428 const std::string locale (static_locale); |
429 | 429 |
430 #if defined (__WIN32__) | 430 #if defined (__WIN32__) |
431 | 431 |
432 HMODULE hMod = GetModuleHandle ("jvm.dll"); | 432 HMODULE hMod = GetModuleHandle ("jvm.dll"); |
433 std::string jvm_lib_path; | 433 std::string jvm_lib_path; |
434 std::string old_cwd; | 434 std::string old_cwd; |
435 | 435 |
436 if (hMod == NULL) | 436 if (hMod) |
437 { | |
438 // JVM seems to be already loaded, better to use that DLL instead | |
439 // of looking in the registry, to avoid opening a different JVM. | |
440 jvm_lib_path = get_module_filename (hMod); | |
441 | |
442 if (jvm_lib_path.empty ()) | |
443 throw std::string ("unable to find Java Runtime Environment"); | |
444 } | |
445 else | |
437 { | 446 { |
438 // In windows, find the location of the JRE from the registry | 447 // In windows, find the location of the JRE from the registry |
439 // and load the symbol from the dll. | 448 // and load the symbol from the dll. |
440 std::string key, value; | 449 std::string key, value; |
441 | 450 |
469 old_cwd = octave_env::get_current_directory (); | 478 old_cwd = octave_env::get_current_directory (); |
470 | 479 |
471 set_dll_directory (jvm_bin_path); | 480 set_dll_directory (jvm_bin_path); |
472 octave_env::chdir (jvm_bin_path); | 481 octave_env::chdir (jvm_bin_path); |
473 } | 482 } |
474 } | |
475 else | |
476 { | |
477 // JVM seems to be already loaded, better to use that DLL instead | |
478 // of looking in the registry, to avoid opening a different JVM. | |
479 jvm_lib_path = get_module_filename (hMod); | |
480 | |
481 if (jvm_lib_path.empty ()) | |
482 throw std::string ("unable to find Java Runtime Environment"); | |
483 } | 483 } |
484 | 484 |
485 #else // Not Win32 system | 485 #else // Not Win32 system |
486 | 486 |
487 // JAVA_LDPATH determined by configure and set in config.h | 487 // JAVA_LDPATH determined by configure and set in config.h |
542 case JNI_EDETACHED: | 542 case JNI_EDETACHED: |
543 // Attach the current thread | 543 // Attach the current thread |
544 JavaVMAttachArgs vm_args; | 544 JavaVMAttachArgs vm_args; |
545 vm_args.version = JNI_VERSION_1_2; | 545 vm_args.version = JNI_VERSION_1_2; |
546 vm_args.name = const_cast<char *> ("octave"); | 546 vm_args.name = const_cast<char *> ("octave"); |
547 vm_args.group = NULL; | 547 vm_args.group = 0; |
548 if (jvm->AttachCurrentThread (reinterpret_cast<void **> (¤t_env), | 548 if (jvm->AttachCurrentThread (reinterpret_cast<void **> (¤t_env), |
549 &vm_args) < 0) | 549 &vm_args) < 0) |
550 throw std::string ("JVM internal error, unable to attach octave to existing JVM"); | 550 throw std::string ("JVM internal error, unable to attach octave to existing JVM"); |
551 break; | 551 break; |
552 | 552 |
1593 } | 1593 } |
1594 | 1594 |
1595 JNIEnv * | 1595 JNIEnv * |
1596 octave_java::thread_jni_env (void) | 1596 octave_java::thread_jni_env (void) |
1597 { | 1597 { |
1598 JNIEnv *env = NULL; | 1598 JNIEnv *env = 0; |
1599 | 1599 |
1600 if (jvm) | 1600 if (jvm) |
1601 jvm->GetEnv (reinterpret_cast<void **> (&env), JNI_VERSION_1_2); | 1601 jvm->GetEnv (reinterpret_cast<void **> (&env), JNI_VERSION_1_2); |
1602 | 1602 |
1603 return env; | 1603 return env; |