Commit Graph

319 Commits

Author SHA1 Message Date
e658ce890f
Small fix 2023-06-29 12:45:29 +02:00
Pierre Tondereau
8b87e4038e
Bump cargo-php to 0.1.8 (#248)
* Bump cargo-php to 0.1.8

* Fix docker zts installation
2023-06-26 21:34:45 +02:00
8514614521
Remove redundant fclose 2023-06-22 17:32:37 +02:00
ca2bc9ae97
Performance trick 2023-06-22 17:13:17 +02:00
6657223087
Further cleanup 2023-06-22 16:50:01 +02:00
c517931726
Cleanup 2023-06-22 16:19:24 +02:00
ae2bd550e8
Cleanup 2023-06-22 16:16:17 +02:00
064ef747c1
Fixes 2023-06-22 16:14:49 +02:00
e0ae48175d
Cleanup 2023-06-22 15:12:26 +02:00
33f9d6e4b8
Improvement 2023-06-22 14:17:49 +02:00
ab55a491d7
Cleanup 2023-06-22 14:13:01 +02:00
ee5c3e1e82
Cleanup 2023-06-22 13:33:09 +02:00
751d4f4d04
Refactoring 2023-06-22 13:31:56 +02:00
07ce8299c5
Fix option args 2023-06-19 13:07:55 +02:00
3fb905afdb
Fix borrowing of parameters in async functions 2023-06-19 11:40:14 +02:00
2088fadf38
A small hack to workaround known good lifetimes 2023-06-19 11:40:14 +02:00
10d3c50181
Update 2023-06-19 11:40:13 +02:00
cc50781903
Add async support 2023-06-19 11:40:13 +02:00
Pierre Tondereau
654692d879
Prepare 0.10.1 (#243) 2023-05-16 23:41:08 +02:00
Pierre Tondereau
eaab5f0694
chore: deps upgrade (#242) 2023-05-16 23:22:20 +02:00
Pierre Tondereau
63a76846d2
chore: Update bindgen to 0.65.1 (#241) 2023-05-16 22:49:57 +02:00
Joe Hoyle
1f9946f105
Switch to use zend apis for array iteration (#240) 2023-05-16 22:33:45 +02:00
Pierre Tondereau
6b6489fddb
chore: fix clippy warnings. (#235) 2023-03-13 18:00:45 +01:00
Dirk Stolle
5d775a5e91
docs(badge): Fix URL of shields.io badges in README.md (#233)
See <https://github.com/badges/shields/issues/8671> for more
information about the breaking change in the URL scheme.

[ci skip]
2023-03-13 11:52:00 +01:00
Dirk Stolle
812e7057db
docs: Fix some typos (#234) 2023-03-13 11:51:29 +01:00
Ryan McCue
c5eaeb242b
Stop watching Cargo.lock for changes (#232)
When loaded via Cargo, there's no Cargo.lock directly in this crate, so
the lack of file existence causes unnecessary rebuilds every time.
2023-02-24 16:24:19 +01:00
Pierre Tondereau
e6afecbddd
chore(clippy): Fix clippy warnings. (#228) 2023-02-07 22:52:56 +01:00
Joe Hoyle
0b27dc349f
Fix Zval IS_PTR type detection (#223) 2023-02-07 22:25:15 +01:00
Joe Hoyle
1875e99e93
Pass args to startup function (#226) 2023-02-07 22:24:33 +01:00
Joe Hoyle
831b3c8597
Mate GlobalExecutor::get_mut() public (#227) 2023-02-07 22:21:53 +01:00
Christian Rades
87ac43d05e
Add is_identical for zvals (#217) 2023-01-19 12:40:24 +01:00
Pierre Tondereau
7ed31ebda9
chore: Prepare 0.10.0 (#215) 2022-12-22 22:55:07 +01:00
Pierre Tondereau
11e0998bc4
feat: Add support for PHP 8.2 (#212)
## Small Fixes due to PHP8.2 upgrade:
- Internal PHP `ZendHashmap` changed the way that we access to the bucket ([commit](90b7bde615 (diff-dca4782c62f10b418ea7193e4641e688ffd7a9c97869f2b1a3a96e28da5653aaL371)))
- Internal PHP `ArrayIterator` doesn't support parent `get_iterator` ([commit](15bbf6f337 (diff-bc002b59b592b4d44c13d898f9dc3ca60b1b1c8505a51a2a3557dfde51dfeb61L273)))
2022-12-20 17:11:35 +01:00
Pierre Tondereau
6965f4a198
Prepare v0.9.0 (#211) 2022-12-11 22:10:25 +01:00
ju1ius
4ca5c0d06e
honour PHP_CONFIG & rebuild automatically when env vars change (#210)
Closes https://github.com/davidcole1340/ext-php-rs/issues/208
Closes https://github.com/davidcole1340/ext-php-rs/issues/209

## Summary of the changes

### Build scripts
* the `unix_build.rs` script now honors the `PHP_CONFIG` environment variable, like `cargo php install`
* use `cargo:rerun-if-env-changed` for the `PHP`, `PHP_CONFIG` and `PATH` environment variables, to avoid needless recompilation of the whole dependency tree.

### Documentation
While trying to document the aforementioned changes, I realized that there was no chapter about installing and setting up a PHP environment to develop PHP extensions. So, I refactored the first chapters of the book into a `Getting Started` section, including instructions on how to quickly set up a PHP environment.
2022-12-11 20:08:50 +01: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
Pierre Tondereau
9e08e253dc
Update Cargo.toml (#207) 2022-11-28 21:08:00 +01:00
Pierre Tondereau
7423da060d
Revert "chore: use php-discovery to find matching PHP build" (#206) 2022-11-28 14:57:34 +01:00
Saif Eddin Gmati
31712066c8
chore: use php-discovery to find matching PHP build (#201) 2022-11-26 13:09:59 -08:00
ju1ius
a331213670
Add instance_of() and get_class_entry() methods on ZendObject (#197)
* adds `ZendObject::get_class_entry()` to retrieve the class entry of an object without casting pointers
* adds `ZendObject::instance_of()` to allow more idiomatic instanceof checks.
* adds a mention that `ZendObject::is_instance::<T>()` does not check the parent classes or interfaces. This bit me when I tried to check if `my_object.is_instance::<MyInterface>()` and it didn't work.
2022-11-24 11:17:12 +01:00
ju1ius
580ad9f462
Describes restrictions on generic parameters for php_class (#194) 2022-11-24 11:11:23 +01:00
ju1ius
3d742262c8
Add get_id() and hash() methods on ZendObject (#196) 2022-11-24 11:07:37 +01:00
ju1ius
9a105abb63
fixes CI workflow configuration (#195)
* upgrades LLVM to v14
* migrates from the unmaintained `action-rs/*` actions to [dtolnay/rust-toolchain](https://github.com/dtolnay/rust-toolchain), using [Swatinem/rust-cache](https://github.com/Swatinem/rust-cache/) as a cache layer.
* adds a cache layer for LLVM build
* adds a weekly cron schedule for all workflows
* fixes an issue in the docblocks
2022-11-24 09:05:36 +01:00
David Cole
8d2ad7d418
fix binary slice lifetimes (#181) 2022-11-19 08:58:18 +01:00
ju1ius
4ea01f8d98
fixes inifinte loop in ClassEntry::instance_of (#188) 2022-11-16 07:25:42 +01:00
David Cole
3b1e2e3848
check docs warnings in CI (#180)
* check docs warnings in CI

* works

* format
2022-11-13 21:13:25 +13:00
David Cole
a160f2a2a0 Bump version to v0.8.2 2022-11-11 12:11:33 +13:00
David Cole
eafd3b4471
fix type links in docs.rs (#179)
[ci skip]
2022-11-11 12:08:23 +13:00
Pierre Tondereau
b72d0555d6
chore(cli): Bump Clap for CLI tool (#177) 2022-11-10 10:59:49 +01:00
David Cole
4133a0fe78
add ability to define abstract methods (#171)
* add ability to define abstract methods

`new_abstract` can be used for interface and abstract class methods.

* rustfmt
2022-11-10 13:51:20 +13:00