You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

692 lines
18 KiB

26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP version 4.0 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.02 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available at through the world-wide-web at |
  10. | http://www.php.net/license.html. |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Sam Ruby (rubys@us.ibm.com) |
  16. +----------------------------------------------------------------------+
  17. */
  18. /*
  19. * This module implements Zend OO syntax overloading support for Java
  20. * components using JNI and reflection.
  21. */
  22. #include "php.h"
  23. #include "zend_compile.h"
  24. #include "php_ini.h"
  25. #include "php_globals.h"
  26. #include <jni.h>
  27. #include <stdio.h>
  28. #define IS_EXCEPTION 86
  29. /***************************************************************************/
  30. #ifndef KAFFE
  31. #ifndef JNI_11
  32. #ifndef JNI_12
  33. #ifdef JNI_VERSION_1_2
  34. #define JNI_12
  35. #else
  36. #define JNI_11
  37. #endif
  38. #endif
  39. #endif
  40. #endif
  41. #ifdef PHP_WIN32
  42. #ifdef JNI_12
  43. #define JAVALIB "jvm.dll"
  44. #else
  45. #define JAVALIB "javai.dll"
  46. #endif
  47. #else
  48. #endif
  49. /***************************************************************************/
  50. static int le_jobject = 0;
  51. static char *classpath = 0;
  52. static char *libpath = 0;
  53. static char *javahome = 0;
  54. static char *javalib = 0;
  55. static int iniUpdated = 0;
  56. static void *dl_handle = 0;
  57. typedef struct {
  58. JavaVM *jvm;
  59. JNIEnv *jenv;
  60. jobject php_reflect;
  61. jclass reflect_class;
  62. } php_java_globals;
  63. #ifdef ZTS
  64. #define JG(v) (java_globals->v)
  65. #define JG_FETCH() php_java_globals *java_globals = ts_resource(java_globals_id)
  66. #define JG_D php_java_globals *java_globals
  67. #define JG_DC , JG_D
  68. #define JG_C dir_globals
  69. #define JG_CC , JG_C
  70. int java_globals_id;
  71. #else
  72. #define JG(v) (java_globals.v)
  73. #define JG_FETCH()
  74. #define JG_D
  75. #define JG_DC
  76. #define JG_C
  77. #define JG_CC
  78. php_java_globals javadir_globals;
  79. #endif
  80. static zend_class_entry java_class_entry;
  81. static PHP_INI_MH(OnIniUpdate) {
  82. if (new_value) *(char**)mh_arg1 = new_value;
  83. iniUpdated=1;
  84. return SUCCESS;
  85. }
  86. PHP_INI_BEGIN()
  87. PHP_INI_ENTRY1("java.class.path",
  88. NULL, PHP_INI_ALL, OnIniUpdate, &classpath)
  89. #ifndef JNI_11
  90. PHP_INI_ENTRY1("java.home",
  91. NULL, PHP_INI_ALL, OnIniUpdate, &javahome)
  92. PHP_INI_ENTRY1("java.library.path",
  93. NULL, PHP_INI_ALL, OnIniUpdate, &libpath)
  94. #endif
  95. #ifdef JAVALIB
  96. PHP_INI_ENTRY1("java.library",
  97. JAVALIB, PHP_INI_ALL, OnIniUpdate, &javalib)
  98. #else
  99. PHP_INI_ENTRY1("java.library",
  100. NULL, PHP_INI_ALL, OnIniUpdate, &javalib)
  101. #endif
  102. PHP_INI_END()
  103. /***************************************************************************/
  104. /*
  105. * Destroy a Java Virtual Machine.
  106. */
  107. void jvm_destroy() {
  108. JG_FETCH();
  109. if (JG(php_reflect)) (*JG(jenv))->DeleteGlobalRef(JG(jenv), JG(php_reflect));
  110. if (JG(jvm)) {
  111. (*JG(jvm))->DetachCurrentThread(JG(jvm));
  112. (*JG(jvm))->DestroyJavaVM(JG(jvm));
  113. JG(jvm) = 0;
  114. }
  115. if (dl_handle) DL_UNLOAD(dl_handle);
  116. JG(php_reflect) = 0;
  117. JG(jenv) = 0;
  118. }
  119. /*
  120. * Create a Java Virtual Machine.
  121. * - class.path, home, and library.path are read out of the INI file
  122. * - appropriate (pre 1.1, JDK 1.1, and JDK 1.2) initialization is performed
  123. * - net.php.reflect class file is located
  124. */
  125. #ifdef JNI_12
  126. static void addJVMOption(JavaVMInitArgs *vm_args, char *name, char *value) {
  127. char *option = (char*) malloc(strlen(name) + strlen(value) + 1);
  128. strcpy(option, name);
  129. strcat(option, value);
  130. vm_args->options[vm_args->nOptions++].optionString = option;
  131. }
  132. #endif
  133. static int jvm_create() {
  134. JG_FETCH();
  135. int rc;
  136. jobject local_php_reflect;
  137. jthrowable error;
  138. jint (JNICALL *JNI_CreateVM)(const void*,const void*,void*);
  139. #ifndef JNI_12
  140. jint (JNICALL *JNI_DefaultArgs)(void*);
  141. #endif
  142. #ifdef JNI_11
  143. JDK1_1InitArgs vm_args;
  144. #else
  145. JavaVMInitArgs vm_args;
  146. #ifdef JNI_12
  147. JavaVMOption options[3];
  148. #endif
  149. #endif
  150. iniUpdated=0;
  151. if (javalib) {
  152. dl_handle = DL_LOAD(javalib);
  153. if (!dl_handle) {
  154. php_error(E_ERROR, "Unable to load Java Library %s", javalib);
  155. return -1;
  156. }
  157. }
  158. #ifndef JAVALIB
  159. if (!dl_handle)
  160. JNI_CreateVM = &JNI_CreateJavaVM;
  161. else
  162. #endif
  163. JNI_CreateVM = (jint (JNICALL *)(const void*,const void*,void*))
  164. DL_FETCH_SYMBOL(dl_handle, "JNI_CreateJavaVM");
  165. if (!JNI_CreateVM) {
  166. php_error(E_ERROR, "Unable to locate CreateJavaVM function");
  167. return -1;
  168. }
  169. #ifdef JNI_12
  170. vm_args.version = JNI_VERSION_1_2;
  171. vm_args.ignoreUnrecognized = JNI_FALSE;
  172. vm_args.options = options;
  173. vm_args.nOptions = 0;
  174. if (classpath) addJVMOption(&vm_args, "-Djava.class.path=", classpath);
  175. if (javahome) addJVMOption(&vm_args, "-Djava.home=", javahome);
  176. if (libpath) addJVMOption(&vm_args, "-Djava.library.path=", libpath);
  177. #else
  178. #ifndef JAVALIB
  179. if (!dl_handle)
  180. JNI_DefaultArgs = &JNI_GetDefaultJavaVMInitArgs;
  181. else
  182. #endif
  183. JNI_DefaultArgs = (jint (JNICALL *)(void*))
  184. DL_FETCH_SYMBOL(dl_handle, "JNI_GetDefaultJavaVMInitArgs");
  185. if (!JNI_DefaultArgs) {
  186. php_error(E_ERROR, "Unable to locate GetDefaultJavaVMInitArgs function");
  187. return -1;
  188. }
  189. vm_args.version=0x00010001;
  190. (*JNI_DefaultArgs)(&vm_args);
  191. if (!classpath) classpath = "";
  192. vm_args.classpath = classpath;
  193. #ifdef KAFFE
  194. vm_args.classhome = javahome;
  195. vm_args.libraryhome = libpath;
  196. #endif
  197. #endif
  198. rc = (*JNI_CreateVM)(&JG(jvm), &JG(jenv), &vm_args);
  199. if (rc) {
  200. php_error(E_ERROR, "Unable to create Java Virtual Machine");
  201. return rc;
  202. }
  203. JG(reflect_class) = (*JG(jenv))->FindClass(JG(jenv), "net/php/reflect");
  204. error = (*JG(jenv))->ExceptionOccurred(JG(jenv));
  205. if (error) {
  206. jclass errClass;
  207. jmethodID toString;
  208. jobject errString;
  209. const char *errAsUTF;
  210. jboolean isCopy;
  211. JNIEnv *jenv = JG(jenv);
  212. (*jenv)->ExceptionClear(jenv);
  213. errClass = (*jenv)->GetObjectClass(jenv, error);
  214. toString = (*jenv)->GetMethodID(jenv, errClass, "toString",
  215. "()Ljava/lang/String;");
  216. errString = (*jenv)->CallObjectMethod(jenv, error, toString);
  217. errAsUTF = (*jenv)->GetStringUTFChars(jenv, errString, &isCopy);
  218. php_error(E_ERROR, "%s", errAsUTF);
  219. if (isCopy) (*jenv)->ReleaseStringUTFChars(jenv, error, errAsUTF);
  220. jvm_destroy();
  221. return -1;
  222. }
  223. local_php_reflect = (*JG(jenv))->AllocObject(JG(jenv), JG(reflect_class));
  224. JG(php_reflect) = (*JG(jenv))->NewGlobalRef(JG(jenv), local_php_reflect);
  225. return rc;
  226. }
  227. /***************************************************************************/
  228. static jobjectArray _java_makeArray(int argc, pval** argv) {
  229. JG_FETCH();
  230. JNIEnv *jenv = JG(jenv);
  231. jclass objectClass = (*jenv)->FindClass(jenv, "java/lang/Object");
  232. jobjectArray result = (*jenv)->NewObjectArray(jenv, argc, objectClass, 0);
  233. jobject arg;
  234. jmethodID makeArg;
  235. int i;
  236. pval **handle;
  237. int type;
  238. for (i=0; i<argc; i++) {
  239. switch (argv[i]->type) {
  240. case IS_STRING:
  241. arg=(*jenv)->NewByteArray(jenv,argv[i]->value.str.len);
  242. (*jenv)->SetByteArrayRegion(jenv,(jbyteArray)arg,0,
  243. argv[i]->value.str.len, argv[i]->value.str.val);
  244. break;
  245. case IS_OBJECT:
  246. zend_hash_index_find(argv[i]->value.obj.properties, 0, (void*)&handle);
  247. arg = zend_list_find((*handle)->value.lval, &type);
  248. break;
  249. case IS_BOOL:
  250. makeArg = (*jenv)->GetMethodID(jenv, JG(reflect_class), "MakeArg",
  251. "(Z)Ljava/lang/Object;");
  252. arg = (*jenv)->CallObjectMethod(jenv, JG(php_reflect), makeArg,
  253. (jboolean)(argv[i]->value.lval));
  254. break;
  255. case IS_LONG:
  256. makeArg = (*jenv)->GetMethodID(jenv, JG(reflect_class), "MakeArg",
  257. "(J)Ljava/lang/Object;");
  258. arg = (*jenv)->CallObjectMethod(jenv, JG(php_reflect), makeArg,
  259. (jlong)(argv[i]->value.lval));
  260. break;
  261. case IS_DOUBLE:
  262. makeArg = (*jenv)->GetMethodID(jenv, JG(reflect_class), "MakeArg",
  263. "(D)Ljava/lang/Object;");
  264. arg = (*jenv)->CallObjectMethod(jenv, JG(php_reflect), makeArg,
  265. (jdouble)(argv[i]->value.dval));
  266. break;
  267. default:
  268. arg=0;
  269. }
  270. (*jenv)->SetObjectArrayElement(jenv, result, i, arg);
  271. if (argv[i]->type != IS_OBJECT)
  272. (*jenv)->DeleteLocalRef(jenv, arg);
  273. }
  274. return result;
  275. }
  276. static int checkError(pval *value) {
  277. if (value->type == IS_EXCEPTION) {
  278. php_error(E_WARNING, "%s", value->value.str.val);
  279. efree(value->value.str.val);
  280. var_reset(value);
  281. return 1;
  282. };
  283. return 0;
  284. }
  285. /***************************************************************************/
  286. /*
  287. * Invoke a method on an object. If method name is "java", create a new
  288. * object instead.
  289. */
  290. void java_call_function_handler
  291. (INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference)
  292. {
  293. JG_FETCH();
  294. JNIEnv *jenv;
  295. pval *object = property_reference->object;
  296. zend_overloaded_element *function_name = (zend_overloaded_element *)
  297. property_reference->elements_list->tail->data;
  298. int arg_count = ZEND_NUM_ARGS();
  299. jlong result = 0;
  300. pval **arguments = (pval **) emalloc(sizeof(pval *)*arg_count);
  301. getParametersArray(ht, arg_count, arguments);
  302. if (iniUpdated && JG(jenv)) jvm_destroy();
  303. if (!JG(jenv)) jvm_create();
  304. if (!JG(jenv)) return;
  305. jenv = JG(jenv);
  306. if (!strcmp("java",function_name->element.value.str.val)) {
  307. /* construct a Java object:
  308. First argument is the class name. Any additional arguments will
  309. be treated as constructor parameters. */
  310. jmethodID co = (*jenv)->GetMethodID(jenv, JG(reflect_class), "CreateObject",
  311. "(Ljava/lang/String;[Ljava/lang/Object;J)V");
  312. jstring className=(*jenv)->NewStringUTF(jenv, arguments[0]->value.str.val);
  313. (pval*)(long)result = object;
  314. (*jenv)->CallVoidMethod(jenv, JG(php_reflect), co,
  315. className, _java_makeArray(arg_count-1, arguments+1), result);
  316. (*jenv)->DeleteLocalRef(jenv, className);
  317. } else {
  318. pval **handle;
  319. int type;
  320. jobject obj;
  321. jstring method;
  322. /* invoke a method on the given object */
  323. jmethodID invoke = (*jenv)->GetMethodID(jenv, JG(reflect_class), "Invoke",
  324. "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;J)V");
  325. zend_hash_index_find(object->value.obj.properties, 0, (void**) &handle);
  326. obj = zend_list_find((*handle)->value.lval, &type);
  327. method = (*jenv)->NewStringUTF(jenv, function_name->element.value.str.val);
  328. (pval*)(long)result = return_value;
  329. (*jenv)->CallVoidMethod(jenv, JG(php_reflect), invoke,
  330. obj, method, _java_makeArray(arg_count, arguments), result);
  331. (*jenv)->DeleteLocalRef(jenv, method);
  332. }
  333. efree(arguments);
  334. pval_destructor(&function_name->element);
  335. checkError((pval*)(long)result);
  336. }
  337. /***************************************************************************/
  338. PHP_FUNCTION(java_last_exception_get)
  339. {
  340. JG_FETCH();
  341. jlong result = 0;
  342. jmethodID lastEx;
  343. if (ZEND_NUM_ARGS()!=0) WRONG_PARAM_COUNT;
  344. (pval*)(long)result = return_value;
  345. lastEx = (*JG(jenv))->GetMethodID(JG(jenv), JG(reflect_class),
  346. "lastException", "(J)V");
  347. (*JG(jenv))->CallVoidMethod(JG(jenv), JG(php_reflect), lastEx, result);
  348. }
  349. /***************************************************************************/
  350. PHP_FUNCTION(java_last_exception_clear)
  351. {
  352. JG_FETCH();
  353. jlong result = 0;
  354. jmethodID clearEx;
  355. if (ZEND_NUM_ARGS()!=0) WRONG_PARAM_COUNT;
  356. (pval*)(long)result = return_value;
  357. clearEx = (*JG(jenv))->GetMethodID(JG(jenv), JG(reflect_class),
  358. "clearException", "()V");
  359. (*JG(jenv))->CallVoidMethod(JG(jenv), JG(php_reflect), clearEx);
  360. }
  361. /***************************************************************************/
  362. static pval _java_getset_property
  363. (zend_property_reference *property_reference, jobjectArray value)
  364. {
  365. JG_FETCH();
  366. JNIEnv *jenv = JG(jenv);
  367. pval presult;
  368. jlong result = 0;
  369. pval **pobject;
  370. jobject obj;
  371. int type;
  372. /* get the property name */
  373. zend_llist_element *element = property_reference->elements_list->head;
  374. zend_overloaded_element *property=(zend_overloaded_element *)element->data;
  375. jstring propName =
  376. (*jenv)->NewStringUTF(jenv, property->element.value.str.val);
  377. /* get the object */
  378. zend_hash_index_find(property_reference->object->value.obj.properties,
  379. 0, (void **) &pobject);
  380. obj = zend_list_find((*pobject)->value.lval,&type);
  381. (pval*)(long)result = &presult;
  382. var_uninit(&presult);
  383. if (!obj || (type!=le_jobject)) {
  384. php_error(E_ERROR,
  385. "Attempt to access a Java property on a non-Java object");
  386. } else {
  387. /* invoke the method */
  388. jmethodID gsp = (*jenv)->GetMethodID(jenv, JG(reflect_class), "GetSetProp",
  389. "(Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;J)V");
  390. (*jenv)->CallVoidMethod
  391. (jenv, JG(php_reflect), gsp, obj, propName, value, result);
  392. }
  393. (*jenv)->DeleteLocalRef(jenv, propName);
  394. pval_destructor(&property->element);
  395. return presult;
  396. }
  397. pval java_get_property_handler
  398. (zend_property_reference *property_reference)
  399. {
  400. pval presult = _java_getset_property(property_reference, 0);
  401. checkError(&presult);
  402. return presult;
  403. }
  404. int java_set_property_handler
  405. (zend_property_reference *property_reference, pval *value)
  406. {
  407. pval presult = _java_getset_property
  408. (property_reference, _java_makeArray(1, &value));
  409. return checkError(&presult) ? FAILURE : SUCCESS;
  410. }
  411. /***************************************************************************/
  412. static void _php_java_destructor(void *jobject) {
  413. JG_FETCH();
  414. if (JG(jenv)) (*JG(jenv))->DeleteGlobalRef(JG(jenv), jobject);
  415. }
  416. #ifdef ZTS
  417. static void alloc_java_globals_ctor(php_java_globals *java_globals) {
  418. memset(java_globals, 0, sizeof(php_java_globals));
  419. }
  420. #endif
  421. PHP_MINIT_FUNCTION(java) {
  422. INIT_OVERLOADED_CLASS_ENTRY(java_class_entry, "java", NULL,
  423. java_call_function_handler,
  424. java_get_property_handler,
  425. java_set_property_handler);
  426. zend_register_internal_class(&java_class_entry);
  427. le_jobject = register_list_destructors(_php_java_destructor,NULL);
  428. REGISTER_INI_ENTRIES();
  429. if (!classpath) classpath = getenv("CLASSPATH");
  430. if (!libpath) {
  431. PLS_FETCH();
  432. libpath=PG(extension_dir);
  433. }
  434. #ifdef ZTS
  435. java_globals_id = ts_allocate_id(sizeof(php_java_globals),
  436. (ts_allocate_ctor)alloc_java_globals_ctor, NULL);
  437. #endif
  438. return SUCCESS;
  439. }
  440. PHP_MSHUTDOWN_FUNCTION(java) {
  441. JG_FETCH();
  442. UNREGISTER_INI_ENTRIES();
  443. if (JG(jvm)) jvm_destroy();
  444. return SUCCESS;
  445. }
  446. function_entry java_functions[] = {
  447. PHP_FE(java_last_exception_get, NULL)
  448. PHP_FE(java_last_exception_clear, NULL)
  449. {NULL, NULL, NULL}
  450. };
  451. static PHP_MINFO_FUNCTION(java) {
  452. DISPLAY_INI_ENTRIES();
  453. }
  454. zend_module_entry java_module_entry = {
  455. "java",
  456. java_functions,
  457. PHP_MINIT(java),
  458. PHP_MSHUTDOWN(java),
  459. NULL,
  460. NULL,
  461. PHP_MINFO(java),
  462. STANDARD_MODULE_PROPERTIES
  463. };
  464. ZEND_GET_MODULE(java)
  465. /***************************************************************************/
  466. JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromString
  467. (JNIEnv *jenv, jclass self, jlong result, jbyteArray jvalue)
  468. {
  469. jboolean isCopy;
  470. jbyte *value = (*jenv)->GetByteArrayElements(jenv, jvalue, &isCopy);
  471. pval *presult = (pval*)(long)result;
  472. presult->type=IS_STRING;
  473. presult->value.str.len=(*jenv)->GetArrayLength(jenv, jvalue);
  474. presult->value.str.val=emalloc(presult->value.str.len+1);
  475. strcpy(presult->value.str.val, value);
  476. if (isCopy) (*jenv)->ReleaseByteArrayElements(jenv, jvalue, value, 0);
  477. }
  478. JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromLong
  479. (JNIEnv *jenv, jclass self, jlong result, jlong value)
  480. {
  481. pval *presult = (pval*)(long)result;
  482. presult->type=IS_LONG;
  483. presult->value.lval=(long)value;
  484. }
  485. JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromDouble
  486. (JNIEnv *jenv, jclass self, jlong result, jdouble value)
  487. {
  488. pval *presult = (pval*)(long)result;
  489. presult->type=IS_DOUBLE;
  490. presult->value.dval=value;
  491. }
  492. JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromBoolean
  493. (JNIEnv *jenv, jclass self, jlong result, jboolean value)
  494. {
  495. pval *presult = (pval*)(long)result;
  496. presult->type=IS_BOOL;
  497. presult->value.lval=value;
  498. }
  499. JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromObject
  500. (JNIEnv *jenv, jclass self, jlong result, jobject value)
  501. {
  502. /* wrapper the java object in a pval object */
  503. pval *presult = (pval*)(long)result;
  504. pval *handle;
  505. if (presult->type != IS_OBJECT) {
  506. presult->type=IS_OBJECT;
  507. presult->value.obj.ce=&java_class_entry;
  508. presult->value.obj.properties = (HashTable *) emalloc(sizeof(HashTable));
  509. presult->is_ref=1;
  510. presult->refcount=1;
  511. zend_hash_init(presult->value.obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
  512. };
  513. ALLOC_ZVAL(handle);
  514. handle->type = IS_LONG;
  515. handle->value.lval =
  516. zend_list_insert((*jenv)->NewGlobalRef(jenv,value), le_jobject);
  517. pval_copy_constructor(handle);
  518. INIT_PZVAL(handle);
  519. zend_hash_index_update(presult->value.obj.properties, 0,
  520. &handle, sizeof(pval *), NULL);
  521. }
  522. JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromArray
  523. (JNIEnv *jenv, jclass self, jlong result)
  524. {
  525. array_init( (pval*)(long)result );
  526. }
  527. JNIEXPORT jlong JNICALL Java_net_php_reflect_nextElement
  528. (JNIEnv *jenv, jclass self, jlong array)
  529. {
  530. pval *result;
  531. pval *handle = (pval*)(long)array;
  532. ALLOC_ZVAL(result);
  533. zend_hash_next_index_insert(handle->value.ht, &result, sizeof(zval *), NULL);
  534. return (jlong)(long)result;
  535. }
  536. JNIEXPORT void JNICALL Java_net_php_reflect_setException
  537. (JNIEnv *jenv, jclass self, jlong result, jbyteArray value)
  538. {
  539. pval *presult = (pval*)(long)result;
  540. Java_net_php_reflect_setResultFromString(jenv, self, result, value);
  541. presult->type=IS_EXCEPTION;
  542. }
  543. JNIEXPORT void JNICALL Java_net_php_reflect_setEnv
  544. (JNIEnv *newJenv, jclass self)
  545. {
  546. JG_FETCH();
  547. jobject local_php_reflect;
  548. iniUpdated=0;
  549. JG(jenv)=newJenv;
  550. if (!self) self = (*JG(jenv))->FindClass(JG(jenv), "net/php/reflect");
  551. JG(reflect_class) = self;
  552. if (JG(php_reflect)) (*JG(jenv))->DeleteGlobalRef(JG(jenv), JG(php_reflect));
  553. local_php_reflect = (*JG(jenv))->AllocObject(JG(jenv), JG(reflect_class));
  554. JG(php_reflect) = (*JG(jenv))->NewGlobalRef(JG(jenv), local_php_reflect);
  555. }