There are two parts to this patch...
1) it changes zend_execute_API.c/call_user_function_ex to allow
overloaded object to handle this callback.
2) Takes advantage of the change above allowing java object to
be searlized and/or "sessionable"
here are two examples...
<?
$java = new Java("java.util.Stack");
$java->push("bottom");
$java->push("middle");
$java->push("top");
$stack = serialize($java);
$java2 = unserialize($stack);
$java2->pop();
$java2->push("new top");
echo $java2->tostring();
?>
<?
session_register("javaobj");
session_register("counter");
if(!isset($javaobj))
$javaobj = new Java("java.util.Stack");
else
$javaobj->push($counter++);
echo $javaobj->toString();
?>
Does anyone wanna review/apply the patch?
/* Brad */
__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards�
http://movies.yahoo.com/
--- zend_execute_API_cvs.c Thu Mar 21 18:44:34 2002
+++ zend_execute_API.c Thu Mar 21 18:46:38 2002
@@ -446,8 +446,18 @@
original_function_state_ptr = EG(function_state_ptr);
if (zend_hash_find(function_table, function_name_copy.value.str.val,
function_name_copy.value.str.len+1, (void **) &function_state.function)==FAILURE) {
- zval_dtor(&function_name_copy);
- return FAILURE;
+ if((*object_pp)->value.obj.ce->handle_function_call != NULL)
+ {
+ function_state.function = (zend_function *)
+emalloc(sizeof(zend_function));
+ function_state.function->type = ZEND_OVERLOADED_FUNCTION;
+ function_state.function->common.arg_types = NULL;
+ function_state.function->overloaded_function.function_name =
+Z_STRVAL_P(function_name);
+ }
+ else
+ {
+ zval_dtor(&function_name_copy);
+ return FAILURE;
+ }
}
zval_dtor(&function_name_copy);
@@ -527,6 +537,28 @@
EG(free_op2) = orig_free_op2;
EG(unary_op) = orig_unary_op;
EG(binary_op) = orig_binary_op;
+ } else if(function_state.function->type == ZEND_OVERLOADED_FUNCTION) {
+ zend_overloaded_element overloaded_element;
+ zend_property_reference property_reference;
+
+ overloaded_element.element = *function_name;
+ overloaded_element.type = OE_IS_METHOD;
+ zval_copy_ctor(&overloaded_element.element);
+
+ property_reference.object = *object_pp;
+ property_reference.type = BP_VAR_NA;
+ property_reference.elements_list = (zend_llist
+*)emalloc(sizeof(zend_llist));
+ zend_llist_init(property_reference.elements_list,
+sizeof(zend_overloaded_element), NULL, 0);
+ zend_llist_add_element(property_reference.elements_list,
+&overloaded_element);
+
+ ALLOC_INIT_ZVAL(*retval_ptr_ptr);
+ Z_OBJCE_PP(object_pp)->handle_function_call(param_count,
+*retval_ptr_ptr, *object_pp, 1 TSRMLS_CC, &property_reference);
+ INIT_PZVAL(*retval_ptr_ptr);
+
+ zend_llist_destroy(property_reference.elements_list);
+ efree(property_reference.elements_list);
+ efree(function_state.function);
+
} else {
ALLOC_INIT_ZVAL(*retval_ptr_ptr);
((zend_internal_function *)
function_state.function)->handler(param_count, *retval_ptr_ptr,
(object_pp?*object_pp:NULL), 1 TSRMLS_CC);
--- java_cvs.c Thu Mar 21 18:58:50 2002
+++ java1.c Thu Mar 21 18:59:02 2002
@@ -449,6 +449,55 @@
(*jenv)->DeleteLocalRef(jenv, className);
+ } else if (!strcmp("__wakeup", function_name->element.value.str.val)) {
+ zval **data;
+ jmethodID invoke;
+ jbyteArray jdata;
+
+ if(zend_hash_find(Z_OBJPROP_P(object), "__data__", sizeof("__data__"), (void
+**) &data) == FAILURE)
+ php_error(E_ERROR, "Could not unserialize the java object");
+
+ jdata = (*jenv)->NewByteArray(jenv, Z_STRLEN_PP(data));
+ (*jenv)->SetByteArrayRegion(jenv, jdata, 0, Z_STRLEN_PP(data), (jbyte
+*)Z_STRVAL_PP(data));
+
+ invoke = (*jenv)->GetMethodID(jenv, JG(reflect_class), "Deserialize", "([BJ)V");
+ if(!invoke)
+ php_error(E_ERROR, "Coulnd't find function");
+
+ result = (jlong)(long)object;
+ (*jenv)->CallVoidMethod(jenv, JG(php_reflect), invoke, jdata, result);
+
+ (*jenv)->DeleteLocalRef(jenv, jdata);
+ zend_hash_del(Z_OBJPROP_P(object), "__data__", sizeof("__data__"));
+
+ } else if (!strcmp("__sleep", function_name->element.value.str.val)) {
+ pval **handle;
+ int type;
+ jobject obj;
+ zval *data;
+ zval *data_name;
+ jmethodID invoke;
+
+ MAKE_STD_ZVAL(data);
+ MAKE_STD_ZVAL(data_name);
+
+ ZVAL_STRING(data_name, "__data__", 1);
+
+ invoke = (*jenv)->GetMethodID(jenv, JG(reflect_class), "Serialize",
+"(Ljava/lang/Object;J)V");
+
+ zend_hash_index_find(Z_OBJPROP_P(object), 0, (void**) &handle);
+ obj = zend_list_find((*handle)->value.lval, &type);
+
+ result = (jlong)(long)data;
+ (*jenv)->CallVoidMethod(jenv, JG(php_reflect), invoke, obj, result);
+
+ if(Z_TYPE_P(data) == IS_EXCEPTION)
+ php_error(E_ERROR, "Error while serializing java object (%s)",
+Z_STRVAL_P(data));
+
+ zend_hash_update(Z_OBJPROP_P(object), "__data__", sizeof("__data__"), &data,
+sizeof(zval *), NULL);
+ array_init(return_value);
+ zend_hash_index_update(Z_ARRVAL_P(return_value), 0, &data_name, sizeof(zval
+*), NULL);
+
} else {
pval **handle;
--- reflect_cvs.java Thu Mar 21 18:56:16 2002
+++ reflect.java Thu Mar 21 19:01:42 2002
@@ -23,6 +23,7 @@
import java.lang.reflect.*;
import java.util.*;
import java.beans.*;
+import java.io.*;
public class reflect {
@@ -409,6 +410,34 @@
setException(result, e);
}
}
+
+ public void Deserialize(byte data[], long result)
+ {
+ try {
+ ByteArrayInputStream istream = new ByteArrayInputStream(data);
+ ObjectInputStream q = new ObjectInputStream(istream);
+ Object object = q.readObject();
+ istream.close();
+ //setResultFromString(result, object.toString().getBytes());
+ setResultFromObject(result, object);
+ } catch (Exception e) {
+ setException(result, e);
+ }
+ }
+
+ public void Serialize(Object object, long result)
+ {
+ try {
+ ByteArrayOutputStream ostream = new ByteArrayOutputStream();
+ ObjectOutputStream p = new ObjectOutputStream(ostream);
+ p.writeObject(object);
+ ostream.close();
+ setResultFromString(result, ostream.toByteArray());
+ } catch (Exception e) {
+ setException(result, e);
+ }
+ }
+
//
// Helper routines for the C implementation
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php