php_vm 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,3 +21,8 @@ Install PHP (sapi/embed)
21
21
  $ ./configure --prefix=/usr/local --enable-embed=shared --disable-cli --disable-cgi --without-pear
22
22
  $ make
23
23
  $ sudo make install
24
+
25
+
26
+ Examples
27
+ ------
28
+ https://github.com/yoshida-eth0/ruby-php_vm/tree/master/sample
data/ext/php_vm/php_vm.c CHANGED
@@ -118,6 +118,8 @@ int new_php_object(zend_class_entry *ce, VALUE v_args, zval *retval)
118
118
  int result = FAILURE;
119
119
 
120
120
  if (ce->constructor) {
121
+ TSRMLS_FETCH();
122
+
121
123
  // defined constructor
122
124
  /*
123
125
  if (!(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) {
@@ -310,6 +312,8 @@ VALUE get_callee_name()
310
312
 
311
313
  VALUE call_php_method_bridge(zend_class_entry *ce, zval *obj, VALUE callee, int argc, VALUE *argv)
312
314
  {
315
+ TSRMLS_FETCH();
316
+
313
317
  // callee
314
318
  if (callee==Qnil) {
315
319
  VALUE exception = rb_exc_new2(rb_ePHPError, "callee is nil");
@@ -351,6 +355,9 @@ VALUE call_php_method_bridge(zend_class_entry *ce, zval *obj, VALUE callee, int
351
355
  zend_update_static_property(ce, RSTRING_PTR(callee), RSTRING_LEN(callee), z_val TSRMLS_CC);
352
356
  }
353
357
 
358
+ // release
359
+ zval_ptr_dtor(&z_val);
360
+
354
361
  return Qnil;
355
362
  } else {
356
363
  // getter
@@ -372,6 +379,10 @@ VALUE call_php_method_bridge(zend_class_entry *ce, zval *obj, VALUE callee, int
372
379
 
373
380
  void php_native_resource_delete(PHPNativeResource *p)
374
381
  {
382
+ if (p->zobj) {
383
+ zval_ptr_dtor(&p->zobj);
384
+ p->zobj = NULL;
385
+ }
375
386
  free(p);
376
387
  }
377
388
 
@@ -440,6 +451,7 @@ VALUE rb_php_vm_require_once(VALUE cls, VALUE filepath)
440
451
 
441
452
  VALUE rb_php_vm_exec(VALUE cls, VALUE code)
442
453
  {
454
+ TSRMLS_FETCH();
443
455
  php_eval_string(RSTRING_PTR(code), RSTRING_LEN(code) TSRMLS_CC);
444
456
  return Qnil;
445
457
  }
@@ -493,7 +505,7 @@ VALUE rb_php_class_initialize(VALUE self, VALUE v_name)
493
505
  VALUE resource = Data_Wrap_Struct(CLASS_OF(self), 0, php_native_resource_delete, p);
494
506
  rb_iv_set(self, "php_native_resource", resource);
495
507
 
496
- // define php static methods
508
+ // define php static properties and methods
497
509
  define_php_properties(self, *ce, 1);
498
510
  define_php_methods(self, *ce, 1);
499
511
 
@@ -510,6 +522,7 @@ VALUE rb_php_class_new(int argc, VALUE *argv, VALUE self)
510
522
  VALUE args;
511
523
  rb_scan_args(argc, argv, "*", &args);
512
524
 
525
+ // alloc
513
526
  VALUE obj = Qnil;
514
527
  zend_class_entry *ce = get_zend_class_entry(self);
515
528
  if (is_exception_zend_class_entry(ce)) {
@@ -519,7 +532,7 @@ VALUE rb_php_class_new(int argc, VALUE *argv, VALUE self)
519
532
  }
520
533
  rb_php_object_initialize(obj, self, args);
521
534
 
522
- // define php instance method
535
+ // define php instance properties and methods
523
536
  define_php_properties(obj, ce, 0);
524
537
  define_php_methods(obj, ce, 0);
525
538
 
@@ -614,6 +627,7 @@ VALUE rb_php_exception_object_initialize(int argc, VALUE *argv, VALUE self)
614
627
 
615
628
  void php_vm_module_init()
616
629
  {
630
+ TSRMLS_FETCH();
617
631
  int argc = 1;
618
632
  char *argv[2] = {"php_vm", NULL};
619
633
  php_embed_init(argc, argv PTSRMLS_CC);
@@ -622,6 +636,7 @@ void php_vm_module_init()
622
636
 
623
637
  void php_vm_module_exit()
624
638
  {
639
+ TSRMLS_FETCH();
625
640
  php_embed_shutdown(TSRMLS_C);
626
641
  }
627
642
 
@@ -641,7 +656,7 @@ void Init_php_vm()
641
656
  rb_define_singleton_method(rb_mPHPVM, "exec", rb_php_vm_exec, 1);
642
657
  rb_define_singleton_method(rb_mPHPVM, "getClass", rb_php_vm_getClass, 1);
643
658
 
644
- rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.1.1"));
659
+ rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.1.2"));
645
660
 
646
661
  // class PHPVM::PHPClass
647
662
  rb_cPHPClass = rb_define_class_under(rb_mPHPVM, "PHPClass", rb_cObject);
@@ -79,6 +79,8 @@ void value_to_zval(VALUE v, zval *z)
79
79
  zval *resource_zobj = get_zval(v);
80
80
  if (resource_zobj) {
81
81
  // php native resource
82
+ //zval_ptr_dtor(&z);
83
+ zval_dtor(z);
82
84
  *z = *resource_zobj;
83
85
  } else {
84
86
  // other to_s
@@ -76,6 +76,8 @@ static VALUE zval_to_value_hash(HashTable* ht)
76
76
 
77
77
  static VALUE zval_to_value_object(zval *z)
78
78
  {
79
+ TSRMLS_FETCH();
80
+
79
81
  // class name
80
82
  const char *name = "";
81
83
  zend_uint name_len = 0;
@@ -102,6 +104,9 @@ static VALUE zval_to_value_object(zval *z)
102
104
  rb_iv_set(obj, "php_class", class);
103
105
  }
104
106
 
107
+ // retain
108
+ Z_ADDREF_P(z);
109
+
105
110
  // resource
106
111
  PHPNativeResource *p = ALLOC(PHPNativeResource);
107
112
  p->ce = get_zend_class_entry(class);
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.1.1
4
+ version: 1.1.2
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: 2012-12-24 00:00:00.000000000 Z
12
+ date: 2012-12-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: php_vm is a native bridge between Ruby and PHP.
15
15
  email: