Commit Graph

53 Commits

Author SHA1 Message Date
3d66f175c6
Merge pull request #268 from joelwurtz/feat/iterator
feat(iterator): add helper for zend_object_iterator and iterable type
2023-11-24 18:52:00 +01:00
1beaae3156 Cleanup 2023-11-24 17:20:20 +01:00
5ee907d6a6 Merge remote-tracking branch 'origin/master' into sapi 2023-11-24 17:13:38 +01:00
8d77b9eaa0 Merge remote-tracking branch 'joel/feat/iterator' 2023-11-24 14:39:00 +01:00
28b190afa6 Cleanup 2023-11-24 14:16:40 +01:00
9ff4bd4a94 Merge branch 'streams-api' into process-globals 2023-11-24 14:11:15 +01:00
21134fb618 Merge remote-tracking branch 'origin/master' into process-globals 2023-11-24 14:07:30 +01:00
3f50e7eeb4
Merge pull request #214 from davidcole1340/throw-exception-object
Add support for throwing Exception objects
2023-11-24 13:56:05 +01:00
Joe Hoyle
3cd7a8a1f7 Add support for Zval IS_INDIRECT
As mentioned in #219, I believe we're making incorrect use of IS_CALLABLE on Zval types right now. Zval type bits are never actually stored as IS_CALLABLE, which overlaps with the _actual_ type value of IS_INDIRECT. IS_INDIRECT is almost the same as IS_REFERENCE, but is a direct reference to another Zval rather than reference object. As `Zval::is_callable()` and `Zval::callable()` don't actually make use of `IS_CALLABLE` then I think it's safe to switch this out.
2023-11-24 13:31:24 +01:00
10eac2497a Expose SAPI module 2023-11-24 11:53:25 +01:00
f621e60be6 Add PHP 8.3, SAPI globals support 2023-11-21 20:13:57 +01:00
Joel Wurtz
a65282dd04
feat(sapi): add initial work on having it's own sapi 2023-10-30 16:26:41 +01:00
Joel Wurtz
5fdd8fac44
feat(zend): add helper for try catch and bailout in PHP (#275)
* feat(zend): add helper for try catch and bailout in PHP

* feat(try): add bindings for bailout

* fix(try): add missing feature flag for test

* feat(try): add a test that expose memory leak problem

* feat(try): make bailout unsafe and explain why

* feat(bailout): flag bailout as a panic function

* feat(embed): add try catch on script / eval
2023-10-25 15:15:43 +02:00
Joel Wurtz
dddc07f587
feat(test): add an example on how to test a module (#276) 2023-10-23 11:42:01 +02:00
Joel Wurtz
e5b1ebd99e
feat(iterator): add iterable, add method to get traversable or iterable 2023-10-20 16:52:01 +02:00
Joel Wurtz
8f425fe5f1
feat(iterator): use an iter key for both array and iterator 2023-10-20 16:52:01 +02:00
Joel Wurtz
2d0e587c7e
feat(embed): add embed features, add test example which run php inside it (#270)
* feat(embed): add embed features, add test example which run php inside it

* feat(embed): use a guard to prevent running in parallel

* chore(ci): update actions to not build and test with embed, add a specific build for embed testing

* feat(embed): correcly start / shutdown embed api

* chore(ci): use stable for rust in embed test

* feat(embed): add documentation, manage potential errors
2023-10-20 14:08:10 +02:00
eff7b0195f
Merge pull request #225 from davidcole1340/ini-definitions
Support registering ini definitions for modules
2023-10-10 15:32:00 +02:00
f669891931
Merge remote-tracking branch 'origin/master' 2023-08-27 16:58:22 +02:00
Joe Hoyle
7803a450a1
Merge branch 'process-globals' into streams-api 2023-07-19 15:28:56 +02:00
Joe Hoyle
7b47b46cfb Merge branch 'master' into ini-definitions 2023-07-19 15:00:59 +02:00
Joe Hoyle
650108229a Merge branch 'master' into process-globals 2023-07-19 13:29:16 +02:00
Joe Hoyle
e30f1272da Add file_globals_id to allowed bindings 2023-07-19 13:27:10 +02:00
Joe Hoyle
42ef04a8ae
Add function type_() method (#254) 2023-07-19 13:15:36 +02:00
Joe Hoyle
3e378f8cdf
Add function for requesting VM interrupt (#257) 2023-07-19 13:12:35 +02:00
Joe Hoyle
52525f249f Fix allowed bindings duplication 2023-07-19 11:36:08 +02:00
Joe Hoyle
1c550852ab Add StreamWrapper API
This allows extensions to register and unregister custom stream wrappers
2023-07-19 10:59:32 +02:00
Joe Hoyle
c9db20c2e9 Merge branch 'master' into process-globals 2023-07-19 10:54:44 +02:00
Joe Hoyle
5acdfe67c2 Add FileGlobals too 2023-07-19 10:51:20 +02:00
Joe Hoyle
a9dffe08f5
Add ability to show PHP warnings (etc) (#231)
* Add ability to show PHP warnings (etc)

I don't believe there's a way for extensions to trigger PHP notices or warnings currently. This is done using the `php_error_docref` function. I've placed a function in `ext_php_rs::php_error()` however, there might be a better place?

* Remove uneeded empty value

* Fix url
2023-07-18 22:40:24 +02:00
Joe Hoyle
b6a2d1861e Add missing binding 2023-07-13 16:32:53 +02:00
Joe Hoyle
368800b560 Merge branch 'process-globals' into sapi-globals 2023-07-13 16:30:22 +02:00
Joe Hoyle
c564f55183 Fix missing bindings 2023-07-13 15:57:29 +02:00
Joe Hoyle
a7780753dc Support registering ini definitions for modules
PHP extensions that want to provide ini settings can do so using `IniEntryDef::register()`; values can then be fetched via `GlobalExecutor::ini_values()`.
2023-07-13 14:42:08 +02:00
Joe Hoyle
003eb8a76a Add support for headers etc 2023-07-13 14:33:40 +02:00
Joe Hoyle
ca04318cf8 Add support for SapiGlobals 2023-07-12 20:05:37 +02:00
Joe Hoyle
7b2dd27fd4 Add ProcessGlobals
This is akin to ExecutorGlobals, but for the process globals
2023-07-07 13:45:51 +02:00
751d4f4d04
Refactoring 2023-06-22 13:31:56 +02:00
Joe Hoyle
1f9946f105
Switch to use zend apis for array iteration (#240) 2023-05-16 22:33:45 +02:00
Dirk Stolle
812e7057db
docs: Fix some typos (#234) 2023-03-13 11:51:29 +01:00
Christian Rades
87ac43d05e
Add is_identical for zvals (#217) 2023-01-19 12:40:24 +01:00
Joe Hoyle
33c6732a6e Merge branch 'master' into throw-exception-object 2022-12-20 14:24:22 +00:00
Joe Hoyle
d5e05f04a1 Add support for throwing Exception objects
Currently we only support throwing exception class entries, i.e. stateless exceptions. Ideally we also want to support throwing a ZVal which has a ClassEntry that extends the Exception PHP class. This can be used to throw stateful exceptions which is not uncommon.

This PR is missing one piece: `throw_object` will currently `drop` the Zval when the function is completed, causing reference / null pointer errors. It seems `ZVal::Drop` doesn't actually free the zval currently, it just sets the type to NULL (which also breaks things.) Discussed briefly in https://discord.com/channels/115233111977099271/1025314959179120714 on how best to solve this, but I'm not totally clear still! Ideally I think we want `throw_object` to own the `zval` but not free it once the function returns.
2022-12-20 14:19:51 +00:00
ju1ius
d52a878e7b
feat: allows ZendStr to contain null bytes (#202)
Closes https://github.com/davidcole1340/ext-php-rs/issues/200

## Rationale
In PHP zend_strings are binary strings with no encoding information. They can contain any byte at any position.
The current implementation use `CString` to transfer zend_strings between Rust and PHP, which prevents zend_strings containing null-bytes to roundtrip through the ffi layer. Moreover, `ZendStr::new()` accepts only a `&str`, which is incorrect since a zend_string is not required to be valid UTF8.

When reading the PHP source code, it is apparent that  most functions marked with `ZEND_API` that accept a `const *char` are convenience wrappers that convert the `const *char` to a zend_string and delegate to another function. For example [zend_throw_exception()](eb83e0206c/Zend/zend_exceptions.c (L823)) takes a `const *char message`, and just converts it to a zend_string before delegating to [zend_throw_exception_zstr()](eb83e0206c/Zend/zend_exceptions.c (L795)).

I kept this PR focused around `ZendStr` and it's usages in the library, but it should be seen as the first step of a more global effort to remove usages of `CString` everywhere possible.

Also, I didn't change the return type of the string related methods of `Zval` (e.g. I could have made `Zval::set_string()` 
 accept an `impl AsRef<[u8]>` instead of `&str` and return `()` instead of `Result<()>`). If I get feedback that it should be done in this PR, I'll do it.

## Summary of the changes:
### ZendStr
* [BC break]: `ZendStr::new()` and `ZendStr::new_interned()` now accept an `impl AsRef<[u8]>` instead of just `&str`, and are therefore infaillible (outside of the cases where we panic, e.g. when allocation fails). This is a BC break, but it's impact shouldn't be huge (users will most likely just have to remove a bunch of `?` or add a few `Ok()`).
* [BC break]: Conversely, `ZendStr::as_c_str()` now returns a `Result<&CStr>` since it can fail on strings containing null bytes.
* [BC break]: `ZensStr::as_str()` now returns a `Result<&str>` instead of an `Option<&str>` since we have to return an error in case of invalid UTF8.
* adds method `ZendStr::as_bytes()` to return the underlying byte slice.
* adds convenience methods `ZendStr::as_ptr()` and `ZendStr::as_mut_ptr()` to return raw pointers to the zend_string.

 ### ZendStr conversion traits
* adds `impl AsRef<[u8]> for ZendStr`
* [BC break]: replaces `impl TryFrom<String> for ZBox<ZendStr>` by `impl From<String> for ZBox<ZendStr>`.
* [BC break]: replaces `impl TryFrom<&str> for ZBox<ZendStr>` by `impl From<&str> for ZBox<ZendStr>`.
* [BC break]: replaces `impl From<&ZendStr> for &CStr` by `impl TryFrom<&ZendStr> for &CStr`.

### Error
* adds new enum member `Error::InvalidUtf8` used when converting a `ZendStr` to `String` or `&str`
2022-12-09 10:54:17 +01:00
David Cole
296c3add84 add note to update docs.rs bindings
[ci skip]
2022-10-16 13:13:17 +13:00
Niklas Mollenhauer
24d703d955
Add some standard zend interfaces (#164)
* Add some standard zend interfaces

The zend API also has some standard interfaces it exposes:
c8c09b4aae/Zend/zend_interfaces.h (L27-L33)
```
extern ZEND_API zend_class_entry *zend_ce_traversable;
extern ZEND_API zend_class_entry *zend_ce_aggregate;
extern ZEND_API zend_class_entry *zend_ce_iterator;
extern ZEND_API zend_class_entry *zend_ce_arrayaccess;
extern ZEND_API zend_class_entry *zend_ce_serializable;
extern ZEND_API zend_class_entry *zend_ce_countable;
extern ZEND_API zend_class_entry *zend_ce_stringable;
```

This surfaced in #163 and should make it possible to implement these interfaces.

* Add some links to the php documentation

* update docs.rs bindings

Co-authored-by: David Cole <david.cole1340@gmail.com>
2022-10-16 13:13:09 +13:00
Dirk Stolle
4bb0559ab8 Fix a few typos 2022-09-10 16:40:38 +02:00
David Cole
664981f4fb
Windows support (#128)
* Preliminary Windows support

* Start work on cross-platform build script

* Fix compilation on macOS

* Updated README, tidied up build script

* Check linker version before starting compilation

It doesn't seem like it's possible to change the linker from within the
build script, however, we can retrieve the linker in use and give the
user a suggestion if the linker will not work.

* Switch to using Github repository for bindgen

* Split Windows and Unix implementations into two files

* Fix building on Windows

* Remove `reqwest` and `zip` as dependencies on Unix

* Fix guide tests on Windows

* Started work on Windows CI

* runs -> run

* Use preinstalled LLVM on Windows

* Debugging for Windows CI

* Switch to upstream `rust-bindgen` master branch

* Switch to `rust-lld` for Windows linking

* Don't compile `cargo-php` on Windows

* Switch to using skeptic for tests

* cargo-php: Disable stub generation, fix ext install/remove

The plan is to replace the stub generation by generating them with PHP
code. This is cross-platform and means we don't need to worry about ABI.
We also don't need to embed information into the library.

* cargo-php: Fix on unix OS

* Fix clippy lint

* Updated README

* Re-add CI for Unix + PHP 8.0

* Fix building on thread-safe PHP

* Tidy up build scripts

* Use dynamic lookup on Linux, test with TS Windows

* Define `ZTS` when compiling PHP ZTS

* Combine Windows and Unix CI, fix linking for Win32TS

* Fix exclusions in build CI

* rust-toolchain -> rust

* Set LLVM version

* Only build docs.rs on Ubuntu PHP 8.1

* Fix build on Linux thread-safe

* Update guide example
2022-03-18 16:36:51 +13:00
David Cole
9c8dd7cd05 Fix cargo-php 2022-02-25 12:37:36 +13:00
David Cole
a9e1dad59f Add bindings for php_printf 2022-02-24 22:45:32 +13:00