php_vm 1.3.7 → 1.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/ext/php_vm/php_vm.c CHANGED
@@ -49,13 +49,11 @@ static void php_embed_error_handler(char *message)
49
49
  }
50
50
  }
51
51
 
52
- static zval *global_exception = NULL;
52
+ static zval *g_exception = NULL;
53
53
  static void php_vm_exception_hook(zval *ex TSRMLS_DC)
54
54
  {
55
55
  // TODO: no use global variable
56
- //VALUE exception = zval_to_value(ex);
57
- //rb_exc_raise(exception);
58
- global_exception = ex;
56
+ g_exception = ex;
59
57
  EG(exception) = NULL;
60
58
  }
61
59
 
@@ -181,9 +179,15 @@ int new_php_object(zend_class_entry *ce, VALUE v_args, zval *retval)
181
179
  // call constructor
182
180
  int result = call_php_method(ce, retval, ce->constructor, RARRAY_LEN(v_args), RARRAY_PTR(v_args), &retval TSRMLS_CC);
183
181
 
184
- // error
182
+ // exception
185
183
  if (result==FAILURE) {
186
- rb_raise(rb_ePHPError, "Invocation of %s's constructor failed", ce->name);
184
+ if (g_exception) {
185
+ VALUE exception = zval_to_value(g_exception);
186
+ g_exception = NULL;
187
+ rb_exc_raise(exception);
188
+ } else {
189
+ rb_raise(rb_ePHPError, "Invocation of %s's constructor failed", ce->name);
190
+ }
187
191
  }
188
192
 
189
193
  } else if (!RARRAY_LEN(v_args)) {
@@ -366,31 +370,36 @@ int call_php_method(zend_class_entry *ce, zval *obj, zend_function *mptr, int ar
366
370
 
367
371
  zend_fcall_info_args(&fci, z_args);
368
372
 
369
- // call method
370
373
  zend_try {
374
+ // call method
371
375
  result = zend_call_function(&fci, &fcc TSRMLS_CC);
372
- } zend_catch {
373
- } zend_end_try();
374
376
 
375
- // reference variable
376
- HashPosition pos;
377
- zval **arg;
378
- zend_arg_info *arg_info = mptr->common.arg_info;
379
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(z_args), &pos);
380
- for (i=0; i<argc && i<mptr->common.num_args; i++) {
381
- if (arg_info->pass_by_reference) {
382
- zend_hash_get_current_data_ex(Z_ARRVAL_P(z_args), (void *)&arg, &pos);
383
- value_copy(v_argv[i], zval_to_value(*arg));
377
+ // reference variable
378
+ HashPosition pos;
379
+ zval **arg;
380
+ zend_arg_info *arg_info = mptr->common.arg_info;
381
+ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(z_args), &pos);
382
+ for (i=0; i<argc && i<mptr->common.num_args; i++) {
383
+ if (arg_info->pass_by_reference) {
384
+ zend_hash_get_current_data_ex(Z_ARRVAL_P(z_args), (void *)&arg, &pos);
385
+ value_copy(v_argv[i], zval_to_value(*arg));
386
+ }
387
+ zend_hash_move_forward_ex(Z_ARRVAL_P(z_args), &pos);
388
+ arg_info++;
384
389
  }
385
- zend_hash_move_forward_ex(Z_ARRVAL_P(z_args), &pos);
386
- arg_info++;
387
- }
390
+ } zend_catch {
391
+ } zend_end_try();
388
392
 
389
393
  // release
390
394
  for (i=0; i<fci.param_count; i++) {
391
395
  zval_ptr_dtor(fci.params[i]);
392
396
  }
393
397
  zend_fcall_info_args_clear(&fci, 1);
398
+
399
+ // result
400
+ if (g_exception) {
401
+ result = FAILURE;
402
+ }
394
403
  return result;
395
404
  }
396
405
 
@@ -420,12 +429,14 @@ VALUE call_php_method_bridge(zend_class_entry *ce, zval *obj, zend_function *mpt
420
429
  int result = call_php_method(ce, obj, mptr, argc, argv, &z_val TSRMLS_CC);
421
430
 
422
431
  // exception
423
- if (global_exception) {
424
- VALUE exception = zval_to_value(global_exception);
425
- global_exception = NULL;
426
- rb_exc_raise(exception);
427
- } else if (result==FAILURE) {
428
- rb_raise(rb_ePHPError, "raise exception: %s", mptr->common.function_name);
432
+ if (result==FAILURE) {
433
+ if (g_exception) {
434
+ VALUE exception = zval_to_value(g_exception);
435
+ g_exception = NULL;
436
+ rb_exc_raise(exception);
437
+ } else {
438
+ rb_raise(rb_ePHPError, "raise exception: %s", mptr->common.function_name);
439
+ }
429
440
  }
430
441
 
431
442
  return zval_to_value(z_val);
@@ -445,22 +456,13 @@ VALUE call_php_method_name_bridge(zend_class_entry *ce, zval *obj, VALUE callee,
445
456
  find_zend_function(ce, RSTRING_PTR(callee), RSTRING_LEN(callee), &mptr);
446
457
 
447
458
  // call
448
- zval *z_val;
449
459
  if (mptr) {
450
460
  // call method
451
- int result = call_php_method(ce, obj, mptr, argc, argv, &z_val TSRMLS_CC);
452
-
453
- // exception
454
- if (global_exception) {
455
- VALUE exception = zval_to_value(global_exception);
456
- global_exception = NULL;
457
- rb_exc_raise(exception);
458
- } else if (result==FAILURE) {
459
- rb_raise(rb_ePHPError, "raise exception: %s", RSTRING_PTR(callee));
460
- }
461
+ return call_php_method_bridge(ce, obj, mptr, argc, argv);
461
462
  } else {
462
463
  // accessor
463
464
  VALUE is_setter = rb_funcall(callee, rb_intern("end_with?"), 1, rb_str_new2("="));
465
+ zval *z_val;
464
466
 
465
467
  if (is_setter) {
466
468
  // setter
@@ -488,10 +490,11 @@ VALUE call_php_method_name_bridge(zend_class_entry *ce, zval *obj, VALUE callee,
488
490
  // static
489
491
  z_val = zend_read_static_property(ce, RSTRING_PTR(callee), RSTRING_LEN(callee), 0 TSRMLS_CC);
490
492
  }
493
+ return zval_to_value(z_val);
491
494
  }
492
495
  }
493
496
 
494
- return zval_to_value(z_val);
497
+ return Qnil;
495
498
  }
496
499
 
497
500
  void value_copy(VALUE dst, VALUE src)
@@ -664,6 +667,7 @@ VALUE define_global_constants()
664
667
  zval *z_val;
665
668
  int result = call_php_method(NULL, NULL, mptr, 0, NULL, &z_val TSRMLS_CC);
666
669
  if (result==FAILURE) {
670
+ g_exception = NULL;
667
671
  return Qfalse;
668
672
  }
669
673
 
@@ -717,6 +721,7 @@ VALUE define_global_functions()
717
721
  zval *z_val;
718
722
  int result = call_php_method(NULL, NULL, mptr, 0, NULL, &z_val TSRMLS_CC);
719
723
  if (result==FAILURE) {
724
+ g_exception = NULL;
720
725
  return Qfalse;
721
726
  }
722
727
 
@@ -756,6 +761,7 @@ VALUE define_global_classes()
756
761
  zval *z_val;
757
762
  int result = call_php_method(NULL, NULL, mptr, 0, NULL, &z_val TSRMLS_CC);
758
763
  if (result==FAILURE) {
764
+ g_exception = NULL;
759
765
  return Qfalse;
760
766
  }
761
767
 
@@ -1335,7 +1341,7 @@ void Init_php_vm()
1335
1341
  rb_define_singleton_method(rb_mPHPVM, "get_class", rb_php_vm_get_class, 1);
1336
1342
  rb_define_singleton_method(rb_mPHPVM, "define_global", rb_php_vm_define_global, 0);
1337
1343
 
1338
- rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.3.7"));
1344
+ rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.3.8"));
1339
1345
 
1340
1346
  rb_cv_set(rb_mPHPVM, "@@output_handler", Qnil);
1341
1347
  rb_cv_set(rb_mPHPVM, "@@error_handler", Qnil);
@@ -160,5 +160,3 @@ VALUE zval_to_value(zval *z)
160
160
  }
161
161
  return Qnil;
162
162
  }
163
-
164
-
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.7
4
+ version: 1.3.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: