027.phpt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. --TEST--
  2. FFI 027: Incomplete and variable length arrays
  3. --EXTENSIONS--
  4. ffi
  5. --INI--
  6. ffi.enable=1
  7. --FILE--
  8. <?php
  9. try {
  10. $p = FFI::new("int[*]");
  11. echo "ok\n";
  12. } catch (Throwable $e) {
  13. echo get_class($e) . ": " . $e->getMessage()."\n";
  14. }
  15. try {
  16. FFI::cdef("static int (*foo)[*];");
  17. echo "ok\n";
  18. } catch (Throwable $e) {
  19. echo get_class($e) . ": " . $e->getMessage()."\n";
  20. }
  21. try {
  22. FFI::cdef("typedef int foo[*];");
  23. echo "ok\n";
  24. } catch (Throwable $e) {
  25. echo get_class($e) . ": " . $e->getMessage()."\n";
  26. }
  27. try {
  28. FFI::cdef("static void foo(int[*][*]);");
  29. echo "ok\n";
  30. } catch (Throwable $e) {
  31. echo get_class($e) . ": " . $e->getMessage()."\n";
  32. }
  33. try {
  34. var_dump(FFI::sizeof(FFI::new("int[0]")));
  35. } catch (Throwable $e) {
  36. echo get_class($e) . ": " . $e->getMessage()."\n";
  37. }
  38. try {
  39. var_dump(FFI::sizeof(FFI::new("int[]")));
  40. } catch (Throwable $e) {
  41. echo get_class($e) . ": " . $e->getMessage()."\n";
  42. }
  43. try {
  44. var_dump(FFI::sizeof(FFI::cast("int[]", FFI::new("int[2]"))));
  45. } catch (Throwable $e) {
  46. echo get_class($e) . ": " . $e->getMessage()."\n";
  47. }
  48. try {
  49. FFI::cdef("struct _x {int a; int b[];};");
  50. echo "ok\n";
  51. } catch (Throwable $e) {
  52. echo get_class($e) . ": " . $e->getMessage()."\n";
  53. }
  54. try {
  55. $f = FFI::cdef("typedef int(*foo)[];");
  56. echo "ok\n";
  57. } catch (Throwable $e) {
  58. echo get_class($e) . ": " . $e->getMessage()."\n";
  59. }
  60. try {
  61. $f = FFI::cdef("typedef int foo[][2];");
  62. echo "ok\n";
  63. } catch (Throwable $e) {
  64. echo get_class($e) . ": " . $e->getMessage()."\n";
  65. }
  66. try {
  67. $f = FFI::cdef("typedef int foo[];");
  68. echo "ok\n";
  69. } catch (Throwable $e) {
  70. echo get_class($e) . ": " . $e->getMessage()."\n";
  71. }
  72. try {
  73. $f = FFI::cdef("static int foo(int[]);");
  74. echo "ok\n";
  75. } catch (Throwable $e) {
  76. echo get_class($e) . ": " . $e->getMessage()."\n";
  77. }
  78. ?>
  79. --EXPECT--
  80. FFI\ParserException: "[*]" is not allowed in other than function prototype scope at line 1
  81. FFI\ParserException: "[*]" is not allowed in other than function prototype scope at line 1
  82. FFI\ParserException: "[*]" is not allowed in other than function prototype scope at line 1
  83. ok
  84. FFI\Exception: Cannot instantiate FFI\CData of zero size
  85. FFI\ParserException: "[]" is not allowed at line 1
  86. FFI\ParserException: "[]" is not allowed at line 1
  87. ok
  88. ok
  89. ok
  90. ok
  91. ok