003.phpt 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. FFI 003: Forward tag/typedef declarations
  3. --EXTENSIONS--
  4. ffi
  5. --INI--
  6. ffi.enable=1
  7. --FILE--
  8. <?php
  9. $ffi = FFI::cdef(<<<EOF
  10. struct _a;
  11. struct _a {int x;};
  12. struct _b {int x;};
  13. struct _b;
  14. typedef struct _c c;
  15. struct _c {int x;};
  16. struct _d {int x;};
  17. typedef struct _d d;
  18. struct _e;
  19. struct _f;
  20. typedef struct _f f;
  21. EOF
  22. );
  23. var_dump($ffi->new("struct _a"));
  24. var_dump($ffi->new("struct _b"));
  25. var_dump($ffi->new("c"));
  26. var_dump($ffi->new("d"));
  27. try {
  28. var_dump($ffi->new("struct _e"));
  29. } catch (Throwable $e) {
  30. echo get_class($e) . ": " . $e->getMessage()."\n";
  31. }
  32. try {
  33. var_dump($ffi->new("f"));
  34. } catch (Throwable $e) {
  35. echo get_class($e) . ": " . $e->getMessage()."\n";
  36. }
  37. echo "ok\n";
  38. ?>
  39. --EXPECTF--
  40. object(FFI\CData:struct _a)#%d (1) {
  41. ["x"]=>
  42. int(0)
  43. }
  44. object(FFI\CData:struct _b)#%d (1) {
  45. ["x"]=>
  46. int(0)
  47. }
  48. object(FFI\CData:struct _c)#%d (1) {
  49. ["x"]=>
  50. int(0)
  51. }
  52. object(FFI\CData:struct _d)#%d (1) {
  53. ["x"]=>
  54. int(0)
  55. }
  56. FFI\ParserException: Incomplete struct "_e" at line 1
  57. FFI\ParserException: Incomplete struct "_f" at line 1
  58. ok