-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy path040.phpt
105 lines (98 loc) · 1.58 KB
/
040.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--TEST--
FFI 040: Support for scalar types
--EXTENSIONS--
ffi
--SKIPIF--
<?php
if (pack('S', 0xABCD) !== pack('v', 0xABCD)) {
die('skip for little-endian architectures only');
}
?>
--INI--
ffi.enable=1
--FILE--
<?php
$ffi = FFI::cdef();
$x = $ffi->new("int");
$x->cdata = 5;
var_dump($x);
var_dump(FFI::typeof($x));
var_dump($ffi->cast("int8_t[4]", $x));
$p = FFI::addr($x);
var_dump($p);
$p[0] += 2;
var_dump($x);
var_dump(FFI::sizeof($x));
var_dump(FFI::alignof($x));
FFI::memset($x, ord("a"), 4);
var_dump(FFI::string($x, 4));
echo "\n";
$y = FFI::cdef()->new("int[2]");
$y[0] = 6;
var_dump($y[0]);
var_dump(FFI::typeof($y[0]));
var_dump(FFI::cdef()->cast("int8_t[4]", $y[0]));
$p = FFI::addr($y[0]);
var_dump($p);
$p[0] += 2;
var_dump($y[0]);
var_dump(FFI::sizeof($y[0]));
var_dump(FFI::alignof($y[0]));
FFI::memset($y[0], ord("b"), 4);
var_dump(FFI::string($y[0], 4));
echo "\n";
var_dump(FFI::memcmp($x, $y[0], 4));
FFI::memcpy($x, $y[0], 4);
var_dump(FFI::memcmp($x, $y[0], 4));
?>
--EXPECTF--
object(FFI\CData:int32_t)#%d (1) {
["cdata"]=>
int(5)
}
object(FFI\CType:int32_t)#%d (0) {
}
object(FFI\CData:int8_t[4])#%d (4) {
[0]=>
int(5)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(0)
}
object(FFI\CData:int32_t*)#%d (1) {
[0]=>
int(5)
}
object(FFI\CData:int32_t)#%d (1) {
["cdata"]=>
int(7)
}
int(4)
int(4)
string(4) "aaaa"
int(6)
object(FFI\CType:int32_t)#%d (0) {
}
object(FFI\CData:int8_t[4])#%d (4) {
[0]=>
int(6)
[1]=>
int(0)
[2]=>
int(0)
[3]=>
int(0)
}
object(FFI\CData:int32_t*)#%d (1) {
[0]=>
int(6)
}
int(8)
int(4)
int(4)
string(4) "bbbb"
int(-1)
int(0)