031.phpt 830 B

1234567891011121314151617181920212223242526272829
  1. --TEST--
  2. FFI 031: bit-fields packing
  3. --EXTENSIONS--
  4. ffi
  5. --INI--
  6. ffi.enable=1
  7. --FILE--
  8. <?php
  9. function test_size($expected_size, $type) {
  10. try {
  11. $size = FFI::sizeof(FFI::new($type));
  12. if ($size !== $expected_size) {
  13. echo "FAIL: sizeof($type) != $expected_size ($size)\n";
  14. }
  15. } catch (Throwable $e) {
  16. echo $type . "=>" . get_class($e) . ": " . $e->getMessage()."\n";
  17. }
  18. }
  19. test_size( 4, "struct {int a:2; int b:2;}");
  20. test_size( 1, "struct __attribute__((packed)) {int a:2; int b:2;}");
  21. test_size( 8, "struct {int a:2; unsigned long long :60; int b:2;}");
  22. test_size( 9, "struct __attribute__((packed)) {int a:2; unsigned long long :64; int b:2;}");
  23. test_size( 4, "union {int a:2; int b:8;}");
  24. test_size( 1, "union __attribute__((packed)) {int a:2; int b:8;}");
  25. ?>
  26. ok
  27. --EXPECT--
  28. ok