Commit Graph

45 Commits

Author SHA1 Message Date
Christoph M. Becker
0427dcb913 Fix bug79177.phpt wrt. JIT
JIT ignores that the `zend_write` callback is overwritten, so we define
our own callback and caller.

We also fix the "inconsistent DLL binding" warnings on Windows, by
introducing `PHP_ZEND_TEST_API`.

Closes GH-6391.
2020-10-30 15:47:18 +01:00
Christoph M. Becker
f547412cba Fix #79177: FFI doesn't handle well PHP exceptions within callback
We have to error on unhandled exceptions in FFI callbacks, to avoid
passing back undefined values.

This has been discussed and agreed upon in a previous PR[1].

[1] <https://github.com/php/php-src/pull/5120>

Closes GH-6366.
2020-10-28 13:34:56 +01:00
Nikita Popov
15443f8af4 Fixed bug #80186
Early exit in FE_RESET if get_properties() returns empty array,
as we cannot add HT iterators to zend_empty_array.
2020-10-09 16:56:08 +02:00
Christoph M. Becker
8623a85cb9 Skip test on big-endian architectures
Due to the memory layout on BE architectures, the address would be
`0x2a00000000` instead of `0x2a` on little-endian architectures.
2020-05-12 13:31:53 +02:00
Christoph M. Becker
d5300873c5 Fix #79571: FFI: var_dumping unions may segfault
We must not attempt to access arbitrary union members when retrieving
debug info, because that may not be valid.  Therefore we do no longer
dereference pointer types inside of unions, but report their address as
string in `%p` format instead.
2020-05-11 16:24:46 +02:00
Christoph M. Becker
67f9b0b754 Fix #79532: sizeof off_t can be wrong
We have to actually determine the proper `SIZEOF_OFF_T`.
Interestingly, it is `4` on Windows x64.

We also have to prevent the redefinition in pg_config.h.  The clean
solution would likely be to not include pg_config.h at all, but that's
out of scope for BC reasons for now.
2020-04-29 10:40:59 +02:00
Christoph M. Becker
8c5faf7ad1 Fix #79472: ext/ffi/tests/040.phpt TC fails on Big endian arch
For now we are choosing the simplest solution, namely to skip the test
on big-endian architectures.
2020-04-14 20:31:31 +03:00
Christoph M. Becker
280485adc1 Improve FFI test suite for Windows
We add Windows support to four existing test cases, extract some useful
utility functions, and use them to simplify further test cases.

We also remove the Windows specific code from preload.inc, since
preloading isn't supported on Windows anyway.
2020-03-18 16:53:06 +01:00
Dmitry Stogov
fee614f66b Export FFI::__BIGGEST_ALIGNMENT__ 2020-03-12 11:43:01 +03:00
Dmitry Stogov
c45552e32b Export FFI::__BIGGEST_ALIGNMENT__ 2020-03-11 15:29:58 +03:00
Dmitry Stogov
e902e4acd9 Allow to fetch function address 2020-03-11 15:13:27 +03:00
Dmitry Stogov
54ecf57fe2 Disable instantiation of zero size FFI\CData objects 2020-02-17 12:48:55 +03:00
Christoph M. Becker
05f3cd23ed Fix #79096: FFI Struct Segfault
We must not assume that the size of a function's return value is at
most `sizeof(ffi_arg)`, but rather have to use the size which already
has been determined for the return type if it is larger than
`sizeof(ffi_arg)`.

To be able to have a regression test, we export the required test
function from the zend-test extension, and make sure that the test
can be run on different platforms regardless of whether zend-tests was
built statically or dynamically.
2020-01-14 16:46:58 +01:00
Nikita Popov
59c3ddab13 Remove support for preloading on Windows
Due to ASLR restrictions, preloading on Windows does not work with
any code that has preloading dependencies on internal classes.
This effectively makes it unusable for any non-trivial codebase.

Instead of pretending like preloading is going to work, only to
make people realize that it really doesn't once they get beyond
a dummy example, we disable support for preloading on Windows
entirely.

Closes GH-4999.
2020-01-06 22:41:55 +01:00
Christoph M. Becker
58cc66e175 Skip test for clang builds
On Windows, clang builds don't use __vectorcall, so executing this test
does not make sense.
2019-12-27 15:09:19 +01:00
Christoph M. Becker
ce047e6091 Fix test case for Windows 2019-11-11 12:49:32 +01:00
Dmitry Stogov
ecd0c5b6ad Fixed bug #78714 (funcs returning pointer can't use call convention spec) 2019-11-11 12:07:48 +03:00
Christoph M. Becker
0055f1e3dc Fix #78761: Zend memory heap corruption with preload and casting
We have to reset `FFI_G(persistent)` back to zero when preloading has
finished.
2019-10-30 19:49:39 +01:00
Christoph M. Becker
1e2d3d58a8 Fix #78762: Failing FFI::cast() may leak memory
We have to release objects when we're done with them.
2019-10-30 17:21:58 +01:00
Christoph M. Becker
22523958f4 Skip test case on non Windows platforms 2019-10-29 10:05:31 +01:00
Christoph M. Becker
bedbecf56d Implement #78270: Support __vectorcall convention with FFI
To work around the limitation of the current rudimentary vectorcall
support in our patched libffi, we forbid yet unsupported declarations,
i.e. float/double parameters at certain positions (SIMD vector types
and HVA types are not supported anyway).
2019-10-29 08:57:43 +01:00
Dmitry Stogov
fea8c5481b Added suppot for glob() wildcard matching in ffi.preload directive 2019-10-24 07:40:07 +02:00
Dmitry Stogov
1417352dda Allow loading FFI bindings through ffi.preload directive 2019-10-22 17:52:56 +03:00
Christoph M. Becker
1c9bfcb6a7 Fix #78716: Function name mangling is wrong for some parameter types
We have to cater to function parameter alignment when calculating the
parameter size.
2019-10-22 11:38:58 +02:00
Christoph M. Becker
9dfbcd7248 Fix #78543: is_callable() on FFI\CData throws Exception
If `Z_OBJ_HANDLER_P(callable, get_closure)` throws, we must not let the
exeception pass to userland, if called through `is_callable()`.
2019-09-19 09:13:22 +02:00
Nikita Popov
d266ba4f2d Check for exception after calling count_values()
To avoid a duplicate error if count_values() throws.
2019-09-17 13:13:44 +02:00
Dmitry Stogov
21c3cdf668 NEWS entry, test and minor cleanup for FFI::isNull() 2019-09-10 11:23:12 +03:00
Christoph M. Becker
1ed9ebdea5 Support calling convention specific function name mangling
On Windows certain calling conventions cause C function names to be
mangled, so to import them we have to use the properly mangled names.
2019-08-04 12:14:11 +02:00
Dmitry Stogov
938d2359ae Remove XFAIL mark 2019-06-17 14:56:28 +03:00
Joe Watkins
f16b012116
fix mac tests on azure 2019-06-14 12:55:00 +02:00
Dmitry Stogov
6738241aec Avoid usage of internal get/set object handlers. They are going to be removed in PHP-8.
Scalar FFI values now should be accessed through special "cdata" property.

    $x = FFI::new("int");
    $x = 42;

    should be changed into

    $x = FFI::new("int");
    $x->cdata = 42;
2019-05-28 17:08:35 +03:00
Dmitry Stogov
9b18afcbca Fixed test on platforms that don't support fastcall calling convention 2019-05-14 00:21:00 +03:00
Peter Kokot
361d0b3426 Convert CRLF line endings to LF
This patch simplifies line endings tracked in the Git repository and
syncs them to all include the LF style instead of the CRLF files.

Newline characters:
- LF (\n) (*nix and Mac)
- CRLF (\r\n) (Windows)
- CR (\r) (old Mac, obsolete)

To see which line endings are in the index and in the working copy the
following command can be used:
`git ls-files --eol`

Git additionally provides `.gitattributes` file to specify if some files
need to have specific line endings on all platforms (either CRLF or LF).

Changed files shouldn't cause issues on modern Windows platforms because
also Git can do output conversion is core.autocrlf=true is set on
Windows and use CRLF newlines in all files in the working tree.

Unless CRLF files are tracked specifically, Git by default tracks all
files in the index using LF newlines.
2019-05-07 04:40:01 +02:00
Anatol Belski
039500adb6 Fix handling and extend ext/ffi/tests/044.phpt 2019-03-30 12:53:32 +01:00
Dmitry Stogov
61ad294f26 Partial support for GCC mode attribute. 2019-03-29 17:28:57 +03:00
Dmitry Stogov
24fa2008dd Allow usage of incomplete types for external variables, function parameters and return values 2019-03-29 14:14:56 +03:00
Dmitry Stogov
a3e52afebe Fixed bug #77768 (FFI: Builtin Types Should Not Raise Error On Redeclaration) 2019-03-29 00:02:26 +03:00
Dmitry Stogov
2ccc27bcfc Fixed incorrect error message 2019-03-20 02:41:08 +03:00
Dmitry Stogov
e623df650f Fixed bug #77707 (FFI loses type information for opaque types) 2019-03-11 14:26:17 +03:00
Dmitry Stogov
a1868d2291 Fixed bug #77706 (Improve error messages in FFI for incompatible arguments) 2019-03-11 13:27:23 +03:00
Tyson Andre
cdfe11f80d Fix ffi test on Windows
Fixes a bug in test added in
5661feb1ef, by checking that the
relevant SO exists.

Also adds an additional test that is based on zend_printf, and
should work on both Linux and Windows.
2019-02-19 10:03:14 +01:00
Dmitry Stogov
5661feb1ef Fixed bug #77632 (FFI Segfaults When Called With Variadics) 2019-02-18 18:11:55 +03:00
Nikita Popov
1449d49670 Fix FFI test on Windows 2019-02-12 13:57:44 +01:00
Dmitry Stogov
7d4de1a77e Fixed possible crash 2019-02-12 11:21:09 +03:00
Dmitry Stogov
e089d506d5 Added FFI extension 2019-01-14 11:47:50 +03:00