036.phpt 476 B

12345678910111213141516171819202122232425262728
  1. --TEST--
  2. FFI 036: Type memory management
  3. --EXTENSIONS--
  4. ffi
  5. --INI--
  6. ffi.enable=1
  7. --FILE--
  8. <?php
  9. $type = FFI::type("int*");
  10. function foo($ptr) {
  11. global $type;
  12. //$buf = FFI::new("int*[1]"); /* this loses type and crash */
  13. $buf = FFI::new(FFI::arrayType($type, [1]));
  14. $buf[0] = $ptr;
  15. //...
  16. return $buf[0];
  17. }
  18. $int = FFI::new("int");
  19. $int->cdata = 42;
  20. var_dump(foo(FFI::addr($int)));
  21. ?>
  22. --EXPECTF--
  23. object(FFI\CData:int32_t*)#%d (1) {
  24. [0]=>
  25. int(42)
  26. }