@@ -40,7 +40,7 @@ public function testCastAnonymousStruct()
40
40
FFI\CData<struct <anonymous>> size 4 align 4 {
41
41
uint32_t x: 0
42
42
}
43
- PHP, \FFI ::new ('struct { uint32_t x; } ' ));
43
+ PHP, \FFI ::cdef ()-> new ('struct { uint32_t x; } ' ));
44
44
}
45
45
46
46
public function testCastNamedStruct ()
@@ -49,7 +49,7 @@ public function testCastNamedStruct()
49
49
FFI\CData<struct Example> size 4 align 4 {
50
50
uint32_t x: 0
51
51
}
52
- PHP, \FFI ::new ('struct Example { uint32_t x; } ' ));
52
+ PHP, \FFI ::cdef ()-> new ('struct Example { uint32_t x; } ' ));
53
53
}
54
54
55
55
public function testCastAnonymousUnion ()
@@ -59,7 +59,7 @@ public function testCastAnonymousUnion()
59
59
uint32_t x: 0
60
60
uint32_t y: 0
61
61
}
62
- PHP, \FFI ::new ('union { uint32_t x; uint32_t y; } ' ));
62
+ PHP, \FFI ::cdef ()-> new ('union { uint32_t x; uint32_t y; } ' ));
63
63
}
64
64
65
65
public function testCastNamedUnion ()
@@ -69,7 +69,7 @@ public function testCastNamedUnion()
69
69
uint32_t x: 0
70
70
uint32_t y: 0
71
71
}
72
- PHP, \FFI ::new ('union Example { uint32_t x; uint32_t y; } ' ));
72
+ PHP, \FFI ::cdef ()-> new ('union Example { uint32_t x; uint32_t y; } ' ));
73
73
}
74
74
75
75
public function testCastAnonymousEnum ()
@@ -78,7 +78,7 @@ public function testCastAnonymousEnum()
78
78
FFI\CData<enum <anonymous>> size 4 align 4 {
79
79
cdata: 0
80
80
}
81
- PHP, \FFI ::new ('enum { a, b } ' ));
81
+ PHP, \FFI ::cdef ()-> new ('enum { a, b } ' ));
82
82
}
83
83
84
84
public function testCastNamedEnum ()
@@ -87,7 +87,7 @@ public function testCastNamedEnum()
87
87
FFI\CData<enum Example> size 4 align 4 {
88
88
cdata: 0
89
89
}
90
- PHP, \FFI ::new ('enum Example { a, b } ' ));
90
+ PHP, \FFI ::cdef ()-> new ('enum Example { a, b } ' ));
91
91
}
92
92
93
93
public static function scalarsDataProvider (): array
@@ -118,7 +118,7 @@ public function testCastScalar(string $type, string $value, int $size, int $alig
118
118
FFI\CData< $ type> size $ size align $ align {
119
119
cdata: $ value
120
120
}
121
- PHP , \FFI ::new ($ type ));
121
+ PHP , \FFI ::cdef ()-> new ($ type ));
122
122
}
123
123
124
124
public function testCastVoidFunction ()
@@ -129,7 +129,7 @@ public function testCastVoidFunction()
129
129
$ abi callable(): void {
130
130
returnType: FFI\CType<void> size 1 align 1 {}
131
131
}
132
- PHP , \FFI ::new ('void (*)(void) ' ));
132
+ PHP , \FFI ::cdef ()-> new ('void (*)(void) ' ));
133
133
}
134
134
135
135
public function testCastIntFunction ()
@@ -140,7 +140,7 @@ public function testCastIntFunction()
140
140
$ abi callable(): uint64_t {
141
141
returnType: FFI\CType<uint64_t> size 8 align 8 {}
142
142
}
143
- PHP , \FFI ::new ('unsigned long long (*)(void) ' ));
143
+ PHP , \FFI ::cdef ()-> new ('unsigned long long (*)(void) ' ));
144
144
}
145
145
146
146
public function testCastFunctionWithArguments ()
@@ -151,14 +151,14 @@ public function testCastFunctionWithArguments()
151
151
$ abi callable(int32_t, char*): void {
152
152
returnType: FFI\CType<void> size 1 align 1 {}
153
153
}
154
- PHP , \FFI ::new ('void (*)(int a, const char* b) ' ));
154
+ PHP , \FFI ::cdef ()-> new ('void (*)(int a, const char* b) ' ));
155
155
}
156
156
157
157
public function testCastNonCuttedPointerToChar ()
158
158
{
159
159
$ actualMessage = "Hello World! \0" ;
160
160
161
- $ string = \FFI ::new ('char[100] ' );
161
+ $ string = \FFI ::cdef ()-> new ('char[100] ' );
162
162
$ pointer = \FFI ::addr ($ string [0 ]);
163
163
\FFI ::memcpy ($ pointer , $ actualMessage , \strlen ($ actualMessage ));
164
164
@@ -180,7 +180,7 @@ public function testCastCuttedPointerToChar()
180
180
.'World!Hello World!Hello World!Hello World!Hello World!Hello Wor '
181
181
.'ld!Hello World!Hel ' ;
182
182
183
- $ string = \FFI ::new ('char[ ' .$ actualLength .'] ' );
183
+ $ string = \FFI ::cdef ()-> new ('char[ ' .$ actualLength .'] ' );
184
184
$ pointer = \FFI ::addr ($ string [0 ]);
185
185
\FFI ::memcpy ($ pointer , $ actualMessage , $ actualLength );
186
186
@@ -207,13 +207,13 @@ public function testCastNonTrailingCharPointer()
207
207
$ actualMessage = 'Hello World! ' ;
208
208
$ actualLength = \strlen ($ actualMessage );
209
209
210
- $ string = \FFI ::new ('char[ ' .$ actualLength .'] ' );
210
+ $ string = \FFI ::cdef ()-> new ('char[ ' .$ actualLength .'] ' );
211
211
$ pointer = \FFI ::addr ($ string [0 ]);
212
212
213
213
\FFI ::memcpy ($ pointer , $ actualMessage , $ actualLength );
214
214
215
215
// Remove automatically addition of the trailing "\0" and remove trailing "\0"
216
- $ pointer = \FFI ::cast ('char* ' , \FFI ::cast ('void* ' , $ pointer ));
216
+ $ pointer = \FFI ::cdef ()-> cast ('char* ' , \FFI ::cast ('void* ' , $ pointer ));
217
217
$ pointer [$ actualLength ] = "\x01" ;
218
218
219
219
$ this ->assertDumpMatchesFormat (<<<PHP
@@ -328,24 +328,24 @@ public function testCastPointerToNonEmptyScalars()
328
328
CPP);
329
329
330
330
// Create values
331
- $ int = \FFI ::new ('int64_t ' );
331
+ $ int = \FFI ::cdef ()-> new ('int64_t ' );
332
332
$ int ->cdata = 42 ;
333
- $ float = \FFI ::new ('float ' );
333
+ $ float = \FFI ::cdef ()-> new ('float ' );
334
334
$ float ->cdata = 42.0 ;
335
- $ double = \FFI ::new ('double ' );
335
+ $ double = \FFI ::cdef ()-> new ('double ' );
336
336
$ double ->cdata = 42.2 ;
337
- $ bool = \FFI ::new ('bool ' );
337
+ $ bool = \FFI ::cdef ()-> new ('bool ' );
338
338
$ bool ->cdata = true ;
339
339
340
340
// Fill struct
341
341
$ struct = $ ffi ->new ('Example ' );
342
- $ struct ->a = \FFI ::addr (\FFI ::cast ('int8_t ' , $ int ));
343
- $ struct ->b = \FFI ::addr (\FFI ::cast ('uint8_t ' , $ int ));
344
- $ struct ->c = \FFI ::addr (\FFI ::cast ('int64_t ' , $ int ));
345
- $ struct ->d = \FFI ::addr (\FFI ::cast ('uint64_t ' , $ int ));
346
- $ struct ->e = \FFI ::addr (\FFI ::cast ('float ' , $ float ));
347
- $ struct ->f = \FFI ::addr (\FFI ::cast ('double ' , $ double ));
348
- $ struct ->g = \FFI ::addr (\FFI ::cast ('bool ' , $ bool ));
342
+ $ struct ->a = \FFI ::addr (\FFI ::cdef ()-> cast ('int8_t ' , $ int ));
343
+ $ struct ->b = \FFI ::addr (\FFI ::cdef ()-> cast ('uint8_t ' , $ int ));
344
+ $ struct ->c = \FFI ::addr (\FFI ::cdef ()-> cast ('int64_t ' , $ int ));
345
+ $ struct ->d = \FFI ::addr (\FFI ::cdef ()-> cast ('uint64_t ' , $ int ));
346
+ $ struct ->e = \FFI ::addr (\FFI ::cdef ()-> cast ('float ' , $ float ));
347
+ $ struct ->f = \FFI ::addr (\FFI ::cdef ()-> cast ('double ' , $ double ));
348
+ $ struct ->g = \FFI ::addr (\FFI ::cdef ()-> cast ('bool ' , $ bool ));
349
349
350
350
$ this ->assertDumpEquals (<<<'OUTPUT'
351
351
FFI\CData<struct <anonymous>> size 56 align 8 {
@@ -441,7 +441,7 @@ public function testCastComplexType()
441
441
$ var ->func = (static fn (object $ p ) => 42 );
442
442
443
443
$ abi = \PHP_OS_FAMILY === 'Windows ' ? '[cdecl] ' : '[fastcall] ' ;
444
- $ longSize = \FFI ::type ('long ' )->getSize ();
444
+ $ longSize = \FFI ::cdef ()-> type ('long ' )->getSize ();
445
445
$ longType = 8 === $ longSize ? 'int64_t ' : 'int32_t ' ;
446
446
$ structSize = 56 + $ longSize * 2 ;
447
447
0 commit comments