php_vm 1.0.2 → 1.0.3

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/README.md ADDED
@@ -0,0 +1,23 @@
1
+ php_vm
2
+ ======================
3
+ php_vm is a native bridge between Ruby and PHP.
4
+
5
+
6
+ Requirements
7
+ ------
8
+ * php (sapi/embed)
9
+
10
+
11
+ Installation
12
+ ------
13
+ $ gem install php_vm
14
+
15
+
16
+ Install PHP (sapi/embed)
17
+ ------
18
+ $ git clone git://github.com/php/php-src.git
19
+ $ cd php-src
20
+ $ ./buildconf
21
+ $ ./configure --prefix=/usr/local --enable-embed=shared --disable-cli --disable-cgi --without-pear
22
+ $ make
23
+ $ sudo make install
data/ext/php_vm/php_vm.c CHANGED
@@ -347,8 +347,8 @@ VALUE rb_php_vm_require(VALUE cls, VALUE filepath)
347
347
  filepath = rb_funcall(filepath, rb_intern("gsub"), 2, rb_str_new2("\""), rb_str_new2("\\\""));
348
348
 
349
349
  VALUE code = rb_str_new2("require \"");
350
- code = rb_str_plus(code, filepath);
351
- code = rb_str_plus(code, rb_str_new2("\";"));
350
+ rb_str_cat(code, RSTRING_PTR(filepath), RSTRING_LEN(filepath));
351
+ rb_str_cat2(code, "\";");
352
352
 
353
353
  php_eval_string(RSTRING_PTR(code), RSTRING_LEN(code));
354
354
 
@@ -362,8 +362,8 @@ VALUE rb_php_vm_require_once(VALUE cls, VALUE filepath)
362
362
  filepath = rb_funcall(filepath, rb_intern("gsub"), 2, rb_str_new2("\""), rb_str_new2("\\\""));
363
363
 
364
364
  VALUE code = rb_str_new2("require_once \"");
365
- code = rb_str_plus(code, filepath);
366
- code = rb_str_plus(code, rb_str_new2("\";"));
365
+ rb_str_cat(code, RSTRING_PTR(filepath), RSTRING_LEN(filepath));
366
+ rb_str_cat2(code, "\";");
367
367
 
368
368
  php_eval_string(RSTRING_PTR(code), RSTRING_LEN(code));
369
369
 
@@ -538,7 +538,7 @@ void Init_php_vm()
538
538
  rb_define_singleton_method(rb_mPHPVM, "exec", rb_php_vm_exec, 1);
539
539
  rb_define_singleton_method(rb_mPHPVM, "getClass", rb_php_vm_getClass, 1);
540
540
 
541
- rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.0.2"));
541
+ rb_define_const(rb_mPHPVM, "VERSION", rb_str_new2("1.0.3"));
542
542
 
543
543
  // class PHPVM::PHPClass
544
544
  rb_cPHPClass = rb_define_class_under(rb_mPHPVM, "PHPClass", rb_cObject);
@@ -10,29 +10,37 @@ 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(z);
13
+ MAKE_STD_ZVAL(new_var);
14
14
  value_to_zval(RARRAY_PTR(v)[i], new_var);
15
15
 
16
16
  zend_hash_next_index_insert(Z_ARRVAL_P(z), &new_var, sizeof(zval *), NULL);
17
17
  }
18
18
  }
19
19
 
20
+ static int hash_flatten_yield(VALUE key, VALUE value, VALUE ary)
21
+ {
22
+ rb_ary_push(ary, key);
23
+ rb_ary_push(ary, value);
24
+ return 0;
25
+ }
26
+
20
27
  static void value_to_zval_hash(VALUE v, zval *z)
21
28
  {
22
- array_init(z);
29
+ VALUE v_arr = rb_ary_new();
30
+ rb_hash_foreach(v, hash_flatten_yield, v_arr);
23
31
 
24
- v = rb_funcall(v, rb_intern("flatten"), 0);
32
+ array_init(z);
25
33
 
26
34
  long i;
27
- for (i=0; i<RARRAY_LEN(v); i+=2) {
28
- VALUE v_key = RARRAY_PTR(v)[i];
29
- StringValue(v_key);
35
+ for (i=0; i<RARRAY_LEN(v_arr); i+=2) {
36
+ VALUE v_key = RARRAY_PTR(v_arr)[i];
37
+ v_key = rb_obj_as_string(v_key);
30
38
 
31
39
  zval *z_value;
32
- MAKE_STD_ZVAL(z);
33
- value_to_zval(RARRAY_PTR(v)[i+1], z_value);
40
+ MAKE_STD_ZVAL(z_value);
41
+ value_to_zval(RARRAY_PTR(v_arr)[i+1], z_value);
34
42
 
35
- add_assoc_zval_ex(z, RSTRING_PTR(v_key), RSTRING_LEN(v), z_value);
43
+ add_assoc_zval_ex(z, RSTRING_PTR(v_key), RSTRING_LEN(v_key)+1, z_value);
36
44
  }
37
45
  }
38
46
 
@@ -71,9 +79,11 @@ void value_to_zval(VALUE v, zval *z)
71
79
  VALUE cls = CLASS_OF(v);
72
80
  if (cls==rb_cPHPObject || cls==rb_ePHPExceptionObject) {
73
81
  // wrap php object
82
+ // TODO
83
+ z = get_zval(v);
74
84
  } else {
75
85
  // other to_s
76
- StringValue(v);
86
+ v = rb_obj_as_string(v);
77
87
  ZVAL_STRING(z, RSTRING_PTR(v), 1);
78
88
  }
79
89
  }
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.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,6 +21,7 @@ extra_rdoc_files: []
21
21
  files:
22
22
  - Gemfile
23
23
  - LICENSE
24
+ - README.md
24
25
  - Rakefile
25
26
  - ext/php_vm/extconf.rb
26
27
  - ext/php_vm/php_vm.c