php_vm 1.3.5 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/php_vm/php_vm.c CHANGED
@@ -245,9 +245,6 @@ void define_php_properties(VALUE v_obj, zend_class_entry *ce, int is_static)
245
245
  void define_php_methods(VALUE v_obj, zend_class_entry *ce, int is_static)
246
246
  {
247
247
  // TODO: access scope
248
- // TODO: __toString
249
- // TODO: __clone
250
- // TODO: __isset
251
248
 
252
249
  HashPosition pos;
253
250
  zend_function *mptr;
@@ -282,18 +279,6 @@ void define_php_methods(VALUE v_obj, zend_class_entry *ce, int is_static)
282
279
  if (strcmp("__construct", fname)==0 || strcmp(ce->name, fname)==0) {
283
280
  // __construct => no define
284
281
  is_pass_define = 1;
285
-
286
- } else if (strcmp("__call", fname)==0) {
287
- // __call => method_missing
288
- rb_define_singleton_method(v_obj, "method_missing", rb_php_object_call_method_missing, -1);
289
-
290
- } else if (strcmp("__get", fname)==0) {
291
- // __get => method_missing
292
- rb_define_singleton_method(v_obj, "method_missing", rb_php_object_call_method_missing, -1);
293
-
294
- } else if (strcmp("__set", fname)==0) {
295
- // __set => method_missing
296
- rb_define_singleton_method(v_obj, "method_missing", rb_php_object_call_method_missing, -1);
297
282
  }
298
283
 
299
284
  // other method
@@ -307,6 +292,45 @@ void define_php_methods(VALUE v_obj, zend_class_entry *ce, int is_static)
307
292
  }
308
293
  }
309
294
 
295
+ void define_php_magic_method(VALUE v_obj, zend_class_entry *ce, int is_static)
296
+ {
297
+ if (is_static) {
298
+ // static method
299
+ if (ce->__callstatic) {
300
+ rb_define_singleton_method(v_obj, "__callStatic", rb_php_class_call_magic___callstatic, 2);
301
+ rb_define_singleton_method(v_obj, "method_missing", rb_php_class_call_method_missing, -1);
302
+ }
303
+ } else {
304
+ // instance method
305
+ if (ce->clone) {
306
+ rb_define_singleton_method(v_obj, "__clone", rb_php_object_call_magic_clone, 0);
307
+ rb_define_singleton_method(v_obj, "dup", rb_php_object_call_magic_clone, 0);
308
+ rb_define_singleton_method(v_obj, "clone", rb_php_object_call_magic_clone, 0);
309
+ }
310
+ if (ce->__get) {
311
+ rb_define_singleton_method(v_obj, "__get", rb_php_object_call_magic___get, 1);
312
+ }
313
+ if (ce->__set) {
314
+ rb_define_singleton_method(v_obj, "__set", rb_php_object_call_magic___set, 2);
315
+ }
316
+ if (ce->__unset) {
317
+ rb_define_singleton_method(v_obj, "__unset", rb_php_object_call_magic___unset, 1);
318
+ }
319
+ if (ce->__isset) {
320
+ rb_define_singleton_method(v_obj, "__isset", rb_php_object_call_magic___isset, 1);
321
+ }
322
+ if (ce->__call) {
323
+ rb_define_singleton_method(v_obj, "__call", rb_php_object_call_magic___call, 2);
324
+ }
325
+ if (ce->__tostring) {
326
+ rb_define_singleton_method(v_obj, "__toString", rb_php_object_call_magic___tostring, 0);
327
+ }
328
+ if (ce->__call || ce->__get || ce->__set) {
329
+ rb_define_singleton_method(v_obj, "method_missing", rb_php_object_call_method_missing, -1);
330
+ }
331
+ }
332
+ }
333
+
310
334
  int call_php_method(zend_class_entry *ce, zval *obj, zend_function *mptr, int argc, VALUE *v_argv, zval **retval_ptr TSRMLS_DC)
311
335
  {
312
336
  int result = FAILURE;
@@ -339,8 +363,7 @@ int call_php_method(zend_class_entry *ce, zval *obj, zend_function *mptr, int ar
339
363
  long i;
340
364
  for (i=0; i<argc; i++) {
341
365
  zval *new_var;
342
- MAKE_STD_ZVAL(new_var);
343
- value_to_zval(v_argv[i], new_var);
366
+ value_to_zval(v_argv[i], &new_var);
344
367
 
345
368
  zend_hash_next_index_insert(Z_ARRVAL_P(z_args), &new_var, sizeof(zval *), NULL);
346
369
  }
@@ -351,8 +374,6 @@ int call_php_method(zend_class_entry *ce, zval *obj, zend_function *mptr, int ar
351
374
  zend_try {
352
375
  result = zend_call_function(&fci, &fcc TSRMLS_CC);
353
376
  } zend_catch {
354
- // EG(exception) is NULL... Why??
355
- //printf("call_php_method exception: %p\n", EG(exception));
356
377
  } zend_end_try();
357
378
 
358
379
  // reference variable
@@ -396,7 +417,26 @@ VALUE get_callee_name()
396
417
  return Qnil;
397
418
  }
398
419
 
399
- VALUE call_php_method_bridge(zend_class_entry *ce, zval *obj, VALUE callee, int argc, VALUE *argv)
420
+ VALUE call_php_method_bridge(zend_class_entry *ce, zval *obj, zend_function *mptr, int argc, VALUE *argv)
421
+ {
422
+ // call
423
+ zval *z_val;
424
+ int result = call_php_method(ce, obj, mptr, argc, argv, &z_val TSRMLS_CC);
425
+
426
+ // exception
427
+ if (result==FAILURE) {
428
+ const char *mname = mptr->common.function_name;
429
+ char *message = malloc(32+strlen(mname));
430
+ sprintf(message, "raise exception: %s", mname);
431
+ VALUE exception = rb_exc_new2(rb_ePHPError, message);
432
+ free(message);
433
+ rb_exc_raise(exception);
434
+ }
435
+
436
+ return zval_to_value(z_val);
437
+ }
438
+
439
+ VALUE call_php_method_name_bridge(zend_class_entry *ce, zval *obj, VALUE callee, int argc, VALUE *argv)
400
440
  {
401
441
  TSRMLS_FETCH();
402
442
 
@@ -431,8 +471,7 @@ VALUE call_php_method_bridge(zend_class_entry *ce, zval *obj, VALUE callee, int
431
471
  if (is_setter) {
432
472
  // setter
433
473
  rb_funcall(callee, rb_intern("gsub!"), 2, rb_str_new2("="), rb_str_new2(""));
434
- MAKE_STD_ZVAL(z_val);
435
- value_to_zval(argv[0], z_val);
474
+ value_to_zval(argv[0], &z_val);
436
475
 
437
476
  if (obj) {
438
477
  // instance
@@ -545,7 +584,7 @@ VALUE rb_php_vm_get_output_handler(VALUE cls)
545
584
 
546
585
  VALUE rb_php_vm_set_output_handler(VALUE cls, VALUE proc)
547
586
  {
548
- if (proc!=Qnil && !rb_obj_is_proc(proc)) {
587
+ if (proc!=Qnil && !rb_obj_is_kind_of(proc, rb_cProc)) {
549
588
  rb_raise(rb_eArgError, "proc is not proc object");
550
589
  }
551
590
  rb_cv_set(rb_mPHPVM, "@@output_handler", proc);
@@ -559,7 +598,7 @@ VALUE rb_php_vm_get_error_handler(VALUE cls)
559
598
 
560
599
  VALUE rb_php_vm_set_error_handler(VALUE cls, VALUE proc)
561
600
  {
562
- if (proc!=Qnil && !rb_obj_is_proc(proc)) {
601
+ if (proc!=Qnil && !rb_obj_is_kind_of(proc, rb_cProc)) {
563
602
  rb_raise(rb_eArgError, "proc is not proc object");
564
603
  }
565
604
  rb_cv_set(rb_mPHPVM, "@@error_handler", proc);
@@ -763,7 +802,7 @@ VALUE rb_php_vm_define_global(VALUE cls)
763
802
  VALUE rb_php_global_function_call(int argc, VALUE *argv, VALUE self)
764
803
  {
765
804
  VALUE callee = get_callee_name();
766
- return call_php_method_bridge(NULL, NULL, callee, argc, argv);
805
+ return call_php_method_name_bridge(NULL, NULL, callee, argc, argv);
767
806
  }
768
807
 
769
808
  VALUE rb_php_global_class_call(VALUE self)
@@ -828,7 +867,7 @@ VALUE rb_php_global_echo(int argc, VALUE *argv, VALUE cls)
828
867
  for (i=0; i<argc; i++) {
829
868
  argv2[i+1] = argv[i];
830
869
  }
831
- call_php_method_bridge(NULL, NULL, rb_str_new2("printf"), argc+1, argv2);
870
+ call_php_method_name_bridge(NULL, NULL, rb_str_new2("printf"), argc+1, argv2);
832
871
 
833
872
  // release
834
873
  free(format);
@@ -902,6 +941,7 @@ VALUE rb_php_class_initialize(VALUE self, VALUE v_name)
902
941
  // define php static properties and methods
903
942
  define_php_properties(self, *ce, 1);
904
943
  define_php_methods(self, *ce, 1);
944
+ define_php_magic_method(self, *ce, 1);
905
945
 
906
946
  return self;
907
947
  }
@@ -929,6 +969,7 @@ VALUE rb_php_class_new(int argc, VALUE *argv, VALUE self)
929
969
  // define php instance properties and methods
930
970
  define_php_properties(obj, ce, 0);
931
971
  define_php_methods(obj, ce, 0);
972
+ define_php_magic_method(obj, ce, 0);
932
973
 
933
974
  return obj;
934
975
  }
@@ -937,21 +978,30 @@ VALUE rb_php_class_getter(VALUE self)
937
978
  {
938
979
  zend_class_entry *ce = get_zend_class_entry(self);
939
980
  VALUE callee = get_callee_name();
940
- return call_php_method_bridge(ce, NULL, callee, 0, NULL);
981
+ return call_php_method_name_bridge(ce, NULL, callee, 0, NULL);
941
982
  }
942
983
 
943
984
  VALUE rb_php_class_setter(VALUE self, VALUE value)
944
985
  {
945
986
  zend_class_entry *ce = get_zend_class_entry(self);
946
987
  VALUE callee = get_callee_name();
947
- return call_php_method_bridge(ce, NULL, callee, 1, &value);
988
+ return call_php_method_name_bridge(ce, NULL, callee, 1, &value);
948
989
  }
949
990
 
950
991
  VALUE rb_php_class_call(int argc, VALUE *argv, VALUE self)
951
992
  {
952
993
  zend_class_entry *ce = get_zend_class_entry(self);
953
994
  VALUE callee = get_callee_name();
954
- return call_php_method_bridge(ce, NULL, callee, argc, argv);
995
+ return call_php_method_name_bridge(ce, NULL, callee, argc, argv);
996
+ }
997
+
998
+ VALUE rb_php_class_call_magic___callstatic(VALUE self, VALUE name, VALUE args)
999
+ {
1000
+ zend_class_entry *ce = get_zend_class_entry(self);
1001
+ zval *zobj = get_zval(self);
1002
+ VALUE argv[2] = {name, args};
1003
+
1004
+ return call_php_method_bridge(ce, zobj, ce->__callstatic, 2, argv);
955
1005
  }
956
1006
 
957
1007
  VALUE rb_php_class_call_method_missing(int argc, VALUE *argv, VALUE self)
@@ -962,7 +1012,7 @@ VALUE rb_php_class_call_method_missing(int argc, VALUE *argv, VALUE self)
962
1012
  rb_scan_args(argc, argv, "1*", &name, &args);
963
1013
  VALUE argv2[2] = {name, args};
964
1014
 
965
- return call_php_method_bridge(ce, NULL, rb_str_new2("__callStatic"), 2, argv2);
1015
+ return call_php_method_bridge(ce, NULL, ce->__callstatic, 2, argv2);
966
1016
  }
967
1017
 
968
1018
 
@@ -999,7 +1049,7 @@ VALUE rb_php_object_getter(VALUE self)
999
1049
  zend_class_entry *ce = get_zend_class_entry(self);
1000
1050
  zval *zobj = get_zval(self);
1001
1051
  VALUE callee = get_callee_name();
1002
- return call_php_method_bridge(ce, zobj, callee, 0, NULL);
1052
+ return call_php_method_name_bridge(ce, zobj, callee, 0, NULL);
1003
1053
  }
1004
1054
 
1005
1055
  VALUE rb_php_object_setter(VALUE self, VALUE value)
@@ -1007,7 +1057,7 @@ VALUE rb_php_object_setter(VALUE self, VALUE value)
1007
1057
  zend_class_entry *ce = get_zend_class_entry(self);
1008
1058
  zval *zobj = get_zval(self);
1009
1059
  VALUE callee = get_callee_name();
1010
- return call_php_method_bridge(ce, zobj, callee, 1, &value);
1060
+ return call_php_method_name_bridge(ce, zobj, callee, 1, &value);
1011
1061
  }
1012
1062
 
1013
1063
  VALUE rb_php_object_call(int argc, VALUE *argv, VALUE self)
@@ -1015,7 +1065,73 @@ VALUE rb_php_object_call(int argc, VALUE *argv, VALUE self)
1015
1065
  zend_class_entry *ce = get_zend_class_entry(self);
1016
1066
  zval *zobj = get_zval(self);
1017
1067
  VALUE callee = get_callee_name();
1018
- return call_php_method_bridge(ce, zobj, callee, argc, argv);
1068
+ return call_php_method_name_bridge(ce, zobj, callee, argc, argv);
1069
+ }
1070
+
1071
+ VALUE rb_php_object_call_magic_clone(VALUE self)
1072
+ {
1073
+ zval *zobj = get_zval(self);
1074
+
1075
+ zend_object_clone_obj_t clone_call = Z_OBJ_HT_P(zobj)->clone_obj;
1076
+ zval *retval;
1077
+
1078
+ ALLOC_ZVAL(retval);
1079
+ Z_OBJVAL_P(retval) = clone_call(zobj TSRMLS_CC);
1080
+ Z_TYPE_P(retval) = IS_OBJECT;
1081
+ Z_SET_REFCOUNT_P(retval, 1);
1082
+ Z_SET_ISREF_P(retval);
1083
+
1084
+ return zval_to_value(retval);
1085
+ }
1086
+
1087
+ VALUE rb_php_object_call_magic___get(VALUE self, VALUE name)
1088
+ {
1089
+ zend_class_entry *ce = get_zend_class_entry(self);
1090
+ zval *zobj = get_zval(self);
1091
+
1092
+ return call_php_method_bridge(ce, zobj, ce->__get, 1, &name);
1093
+ }
1094
+
1095
+ VALUE rb_php_object_call_magic___set(VALUE self, VALUE name, VALUE arg)
1096
+ {
1097
+ zend_class_entry *ce = get_zend_class_entry(self);
1098
+ zval *zobj = get_zval(self);
1099
+ VALUE args[2] = {name, arg};
1100
+
1101
+ return call_php_method_bridge(ce, zobj, ce->__set, 2, args);
1102
+ }
1103
+
1104
+ VALUE rb_php_object_call_magic___unset(VALUE self, VALUE name)
1105
+ {
1106
+ zend_class_entry *ce = get_zend_class_entry(self);
1107
+ zval *zobj = get_zval(self);
1108
+
1109
+ return call_php_method_bridge(ce, zobj, ce->__unset, 1, &name);
1110
+ }
1111
+
1112
+ VALUE rb_php_object_call_magic___isset(VALUE self, VALUE name)
1113
+ {
1114
+ zend_class_entry *ce = get_zend_class_entry(self);
1115
+ zval *zobj = get_zval(self);
1116
+
1117
+ return call_php_method_bridge(ce, zobj, ce->__isset, 1, &name);
1118
+ }
1119
+
1120
+ VALUE rb_php_object_call_magic___call(VALUE self, VALUE name, VALUE args)
1121
+ {
1122
+ zend_class_entry *ce = get_zend_class_entry(self);
1123
+ zval *zobj = get_zval(self);
1124
+ VALUE argv[2] = {name, args};
1125
+
1126
+ return call_php_method_bridge(ce, zobj, ce->__call, 2, argv);
1127
+ }
1128
+
1129
+ VALUE rb_php_object_call_magic___tostring(VALUE self)
1130
+ {
1131
+ zend_class_entry *ce = get_zend_class_entry(self);
1132
+ zval *zobj = get_zval(self);
1133
+
1134
+ return call_php_method_bridge(ce, zobj, ce->__tostring, 0, NULL);
1019
1135
  }
1020
1136
 
1021
1137
  VALUE rb_php_object_call_method_missing(int argc, VALUE *argv, VALUE self)
@@ -1023,15 +1139,14 @@ VALUE rb_php_object_call_method_missing(int argc, VALUE *argv, VALUE self)
1023
1139
  zend_class_entry *ce = get_zend_class_entry(self);
1024
1140
  zval *zobj = get_zval(self);
1025
1141
 
1026
- VALUE call_method = rb_str_new2("__call");
1027
- if (has_zend_function(ce, call_method)) {
1142
+ if (ce->__call) {
1028
1143
  // __call
1029
1144
  VALUE name, args;
1030
1145
  rb_scan_args(argc, argv, "1*", &name, &args);
1031
1146
  name = rb_str_new2(rb_id2name(SYM2ID(name)));
1032
1147
  VALUE argv2[2] = {name, args};
1033
1148
 
1034
- return call_php_method_bridge(ce, zobj, call_method, 2, argv2);
1149
+ return call_php_method_bridge(ce, zobj, ce->__call, 2, argv2);
1035
1150
  } else {
1036
1151
  // accessor
1037
1152
  VALUE name, val;
@@ -1042,11 +1157,15 @@ VALUE rb_php_object_call_method_missing(int argc, VALUE *argv, VALUE self)
1042
1157
  VALUE is_setter = rb_funcall(name, rb_intern("end_with?"), 1, rb_str_new2("="));
1043
1158
  if (is_setter) {
1044
1159
  // __set
1045
- rb_funcall(name, rb_intern("gsub!"), 2, rb_str_new2("="), rb_str_new2(""));
1046
- return call_php_method_bridge(ce, zobj, rb_str_new2("__set"), 2, argv2);
1160
+ if (ce->__set) {
1161
+ rb_funcall(name, rb_intern("gsub!"), 2, rb_str_new2("="), rb_str_new2(""));
1162
+ return call_php_method_bridge(ce, zobj, ce->__set, 2, argv2);
1163
+ }
1047
1164
  } else {
1048
1165
  // __get
1049
- return call_php_method_bridge(ce, zobj, rb_str_new2("__get"), 1, argv2);
1166
+ if (ce->__get) {
1167
+ return call_php_method_bridge(ce, zobj, ce->__get, 1, argv2);
1168
+ }
1050
1169
  }
1051
1170
  }
1052
1171
  return Qnil;
@@ -1072,7 +1191,7 @@ VALUE rb_php_error_reporting_initialize(int argc, VALUE *argv, VALUE self)
1072
1191
  VALUE file = Qnil;
1073
1192
  VALUE line = Qnil;
1074
1193
 
1075
- if (argc==1 &&TYPE( argv[0])==T_STRING) {
1194
+ if (argc==1 && TYPE(argv[0])==T_STRING) {
1076
1195
  log_message = argv[0];
1077
1196
  VALUE re_str = rb_str_new2("^PHP ([^:]+?)(?: error)?: {0,2}(.+) in (.+) on line (\\d+)$");
1078
1197
  VALUE re_option = rb_const_get(rb_cRegexp, rb_intern("MULTILINE"));
@@ -1171,7 +1290,7 @@ void Init_php_vm()
1171
1290
  rb_define_singleton_method(rb_mPHPVM, "get_class", rb_php_vm_get_class, 1);
1172
1291
  rb_define_singleton_method(rb_mPHPVM, "define_global", rb_php_vm_define_global, 0);
1173
1292
 
1174
- rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.3.5"));
1293
+ rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.3.6"));
1175
1294
 
1176
1295
  rb_cv_set(rb_mPHPVM, "@@output_handler", Qnil);
1177
1296
  rb_cv_set(rb_mPHPVM, "@@error_handler", Qnil);
data/ext/php_vm/php_vm.h CHANGED
@@ -38,7 +38,8 @@ extern int call_php_method(zend_class_entry *ce, zval *obj, zend_function *mptr,
38
38
 
39
39
  // Ruby
40
40
  extern VALUE get_callee_name();
41
- extern VALUE call_php_method_bridge(zend_class_entry *ce, zval *obj, VALUE callee, int argc, VALUE *argv);
41
+ extern VALUE call_php_method_bridge(zend_class_entry *ce, zval *obj, zend_function *mptr, int argc, VALUE *argv);
42
+ extern VALUE call_php_method_name_bridge(zend_class_entry *ce, zval *obj, VALUE callee, int argc, VALUE *argv);
42
43
  extern void value_copy(VALUE dst, VALUE src);
43
44
 
44
45
  // PHP Native resource
@@ -77,6 +78,7 @@ extern VALUE rb_php_class_new(int argc, VALUE *argv, VALUE self);
77
78
  extern VALUE rb_php_class_getter(VALUE self);
78
79
  extern VALUE rb_php_class_setter(VALUE self, VALUE value);
79
80
  extern VALUE rb_php_class_call(int argc, VALUE *argv, VALUE self);
81
+ extern VALUE rb_php_class_call_magic___callstatic(VALUE self, VALUE name, VALUE args);
80
82
  extern VALUE rb_php_class_call_method_missing(int argc, VALUE *argv, VALUE self);
81
83
 
82
84
  // class PHPVM::PHPObject
@@ -85,6 +87,13 @@ extern VALUE rb_php_object_php_class(VALUE self);
85
87
  extern VALUE rb_php_object_getter(VALUE self);
86
88
  extern VALUE rb_php_object_setter(VALUE self, VALUE value);
87
89
  extern VALUE rb_php_object_call(int argc, VALUE *argv, VALUE self);
90
+ extern VALUE rb_php_object_call_magic_clone(VALUE self);
91
+ extern VALUE rb_php_object_call_magic___get(VALUE self, VALUE name);
92
+ extern VALUE rb_php_object_call_magic___set(VALUE self, VALUE name, VALUE arg);
93
+ extern VALUE rb_php_object_call_magic___unset(VALUE self, VALUE name);
94
+ extern VALUE rb_php_object_call_magic___isset(VALUE self, VALUE name);
95
+ extern VALUE rb_php_object_call_magic___call(VALUE self, VALUE name, VALUE args);
96
+ extern VALUE rb_php_object_call_magic___tostring(VALUE self);
88
97
  extern VALUE rb_php_object_call_method_missing(int argc, VALUE *argv, VALUE self);
89
98
 
90
99
  // module
@@ -10,8 +10,7 @@ static void value_to_zval_array(VALUE v, zval *z)
10
10
  long i;
11
11
  for (i=0; i<RARRAY_LEN(v); i++) {
12
12
  zval *new_var;
13
- MAKE_STD_ZVAL(new_var);
14
- value_to_zval(RARRAY_PTR(v)[i], new_var);
13
+ value_to_zval(RARRAY_PTR(v)[i], &new_var);
15
14
 
16
15
  zend_hash_next_index_insert(Z_ARRVAL_P(z), &new_var, sizeof(zval *), NULL);
17
16
  }
@@ -37,55 +36,61 @@ static void value_to_zval_hash(VALUE v, zval *z)
37
36
  v_key = rb_obj_as_string(v_key);
38
37
 
39
38
  zval *z_value;
40
- MAKE_STD_ZVAL(z_value);
41
- value_to_zval(RARRAY_PTR(v_arr)[i+1], z_value);
39
+ value_to_zval(RARRAY_PTR(v_arr)[i+1], &z_value);
42
40
 
43
41
  add_assoc_zval_ex(z, RSTRING_PTR(v_key), RSTRING_LEN(v_key)+1, z_value);
44
42
  }
45
43
  }
46
44
 
47
45
 
48
- void value_to_zval(VALUE v, zval *z)
46
+ void value_to_zval(VALUE v, zval **z)
49
47
  {
50
48
  switch (TYPE(v)) {
51
49
  // nil
52
50
  case T_NIL:
53
- ZVAL_NULL(z);
51
+ MAKE_STD_ZVAL(*z);
52
+ ZVAL_NULL(*z);
54
53
  break;
55
54
  // bool
56
55
  case T_TRUE:
57
- ZVAL_TRUE(z);
56
+ MAKE_STD_ZVAL(*z);
57
+ ZVAL_TRUE(*z);
58
58
  break;
59
59
  case T_FALSE:
60
- ZVAL_FALSE(z);
60
+ MAKE_STD_ZVAL(*z);
61
+ ZVAL_FALSE(*z);
61
62
  break;
62
63
  // number
63
64
  case T_FIXNUM:
64
- ZVAL_LONG(z, NUM2LONG(v));
65
+ MAKE_STD_ZVAL(*z);
66
+ ZVAL_LONG(*z, NUM2LONG(v));
65
67
  break;
66
68
  case T_FLOAT:
67
- ZVAL_DOUBLE(z, RFLOAT_VALUE(v));
69
+ MAKE_STD_ZVAL(*z);
70
+ ZVAL_DOUBLE(*z, RFLOAT_VALUE(v));
68
71
  break;
69
72
  // array
70
73
  case T_ARRAY:
71
- value_to_zval_array(v, z);
74
+ MAKE_STD_ZVAL(*z);
75
+ value_to_zval_array(v, *z);
72
76
  break;
73
77
  // hash
74
78
  case T_HASH:
75
- value_to_zval_hash(v, z);
79
+ MAKE_STD_ZVAL(*z);
80
+ value_to_zval_hash(v, *z);
76
81
  break;
77
82
  // object string
78
83
  default:{
79
84
  zval *resource_zobj = get_zval(v);
80
85
  if (resource_zobj) {
81
86
  // php native resource
82
- //zval_ptr_dtor(&z);
83
- zval_dtor(z);
84
- *z = *resource_zobj;
87
+ *z = resource_zobj;
88
+ Z_ADDREF_PP(z);
85
89
  } else {
86
90
  // other to_s
87
91
  v = rb_obj_as_string(v);
88
- ZVAL_STRING(z, RSTRING_PTR(v), 1);
92
+ MAKE_STD_ZVAL(*z);
93
+ ZVAL_STRING(*z, RSTRING_PTR(v), 1);
89
94
  }
90
95
  }
91
96
  }
@@ -4,6 +4,6 @@
4
4
  #include <ruby.h>
5
5
  #include <sapi/embed/php_embed.h>
6
6
 
7
- extern void value_to_zval(VALUE v, zval *z);
7
+ extern void value_to_zval(VALUE v, zval **z);
8
8
 
9
9
  #endif
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: php_vm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.3.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-01 00:00:00.000000000 Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: php_vm is a native bridge between Ruby and PHP.
15
15
  email: