Commit Graph

276 Commits

Author SHA1 Message Date
David
626c944218
Added #[php_extern] macro (#51)
* Fixed memory leak with `phpinfo()` table

* Added `#[php_extern]` macro
2021-08-19 12:36:33 +12:00
David
a2781b794a
Modify string parameters to be consistent (#50)
* Fix memory leaks with strings and zvals

Add PhpAllocator - not meant for usage, only for memory leak debugging.

* Replace `impl AsRef<str>` with `&str`

* Added `ZendString::as_str()`

* Tidy up

* Replace owned string parameters with `Into<String>`

* Remove backtrace feature, un-import allocator
2021-08-18 23:25:35 +12:00
David
84aaa07d3e
Add abstraction macros (#49)
* Remove uses of `unwrap`, improve library safety

* Started work on `#[php_function]` attribute

* Added `PhantomData` to `ZendHashTable`

Proper lifetimes for `HashTable` type

* `#[php_function]` now accepts `Vec<T>`

Refactored `ZendHashTable` iterators - there is now `Iter` and
`IntoIter` depending on whether it will consume the HashTable or not.

* Add support for nullable types

* Allow `optional` parameter on attribute

* Support primitive and `Option` return types

* Tidied and refactored attribute

* Added documentation for `#[php_function]`

Implemented `IntoZval` for `Option<T>` when `IntoZval` is also
implemented for `T`. `None` resolves to `null`.

* Added `#[php_method]` attribute

* Added `Callable` type, implemented `Drop` on `Zval`

While implementing `Drop`, the `Copy` derivation was removed, however,
this should not have been there in the first place (`Zval` is not valid
for `Copy` if it contains a string).

* Added some macro functions to example

* Add support for boolean arguments

* Added wrapper around binary data

Future support for binary arguments with `#[php_function]` macros.
Unpacking binary data is no longer unsafe. It was never really unsafe in
the beginning, as we were always reading valid memory, just the contents
of the data could not be trusted.

* Added `#[php_module]` attribute, added support for binary arguments

* Added defaults for functions

* Add defaults for methods

* Add startup function macro and prelude

* Refactored method adding

Now done through impl attribute

* Don't rename functions - generate another internal fn

Also hide all generated functions from docs

* Generate startup function when not already defined

* Add support for class and global constants

* Updated `skel` project

* Updated macro documentation, added executor globals

* Remove `Copy` bound for HashMap to Zval

* Updated documentation

* Add `FromZval` trait, updated docs

* Fixed clippy lints

* Fixed ZTS executor globals

* Fix clippy lint
2021-08-18 13:15:25 +12:00
David Cole
496e3501e1 Bumped ext-php-rs-derive version 2021-08-11 12:41:31 +12:00
David Cole
8259a49520 v0.1.0 not v1.0.0 2021-08-11 12:39:56 +12:00
David Cole
ad51a66193 v0.1.0: bumped version 2021-08-11 12:39:20 +12:00
David
2a0e1f8086
Remove uses of unwrap, improve library safety (#47)
* Remove uses of `unwrap`, improve library safety

* `set_array` doesn't return `Result`
2021-08-11 12:34:08 +12:00
David Cole
0031df1604 ClassEntry::build now returns a reference
Useful for when you want to throw a custom exception. Store the
reference to the class (which should extend one of the base exceptions)
in a static mutable variable, and then use `throw`.
2021-07-31 20:44:46 +12:00
David Cole
e946066598 Change extends to take a reference rather than pointer 2021-07-28 21:31:31 +12:00
David
317201bbb9
Update Discord image location 2021-06-10 08:44:42 +12:00
David Cole
5e0466f343 Added iter function on ZendHashTable
We cannot implement `IntoIterator` for the `ZendHashTable` object as we
do not manage the memory, therefore we don't actually 'consume' the
object as the trait intends. Therefore, `IntoIterator` is implemented on
`&'a ZendHashTable`. This `ZendHashTable::iter` function simply forwards
the call.
2021-06-09 12:40:15 +12:00
David Cole
196ddb3e20 Zval::reference should return a reference 2021-06-02 14:09:08 +12:00
David
c98bf495ea
v0.0.7: bumped version (#43) 2021-05-21 17:16:36 +12:00
David
b23b678a3d
Better interactions with objects (#41)
* Object functions now return references to objects

Added ability to get object class name as well as hashtable of
properties

* Return mutable reference to objects

* Optimized `unwrap_or_else` calls
2021-05-21 17:11:15 +12:00
David Cole
4946613b5d Fixed docs link for ZendString 2021-05-21 15:14:17 +12:00
David Cole
f4d0bd7ea9 Updated README 2021-05-21 15:12:35 +12:00
David
de326e3171
Added ability to get and set properties (#39)
* Fixed adding properties to classes

* Removed unused function from wrapper header

* Moved property functions into `ZendObject`

* Introduced `ZendString` wrapper for raw pointer

* Set refcount of Zval to 0 when setting string properties

* Added ability to check if a property exists

Made some lifetimes explicit, check if property exists before attempting
to get.

* Removed unused file

* Removed unused lifetimes

Clippy was complaining, they were added to ensure that a `'static`
lifetime wasn't returned.
2021-05-21 15:08:10 +12:00
David
4d364d9765
Removed unused #[macro_use] attributes (#38) 2021-05-19 20:54:08 +12:00
David
0db6888c46
Added support for PHP ZTS (#37)
* Added support for PHP ZTS

* Added GitHub action for ZTS

Runs seperate from the other tests, as the setup-php action does not
support ZTS, therefore we run the tests in a Docker container.

* Source Rust env file before building

* No `source` command on docker

* Another attempt at fixing Rust in Docker
2021-05-19 20:45:39 +12:00
David Cole
5ac8aeecc4 Moved contribution section of README 2021-05-16 15:27:32 +12:00
David Cole
ee2c394102 v0.0.6: bumped version and changelog 2021-05-11 21:49:09 +12:00
Will Browning
e0743b1589
Remove default-features=false from bindgen (#36) 2021-05-07 10:35:46 +12:00
David
a75fcb50d2
Added ability to unpack and pack from Rust (#32)
* Added ability to `unpack` and `pack` from Rust

* Updated `Pack::pack_into` documentation

* Replaced constant with new flags, fixed example

* Accept slices/arrays when using `Zval::set_binary`
2021-05-05 22:43:06 +12:00
David
fcdd9332f5
Build and deploy docs to Github pages (#35)
* Added Github action for building and publishing docs

* Create index redirect page for docs

* Only deploy on master, fixed redirect
2021-05-04 11:42:52 +12:00
David
042c70af97
Fixed memory leak when returning an array (#34) 2021-05-03 19:59:29 +12:00
David Cole
d73788e093 Fixed extension panicing with invalid string 2021-05-01 22:06:56 +12:00
David Cole
e5a092d5f7 v0.0.5: bumped version and changelog 2021-04-24 13:39:06 +12:00
David
d1e719ef7a
Only run CI on pushes to master and PRs 2021-04-24 13:29:53 +12:00
David
62a43e64d9
Added Debug and Clone implementations (#30)
* Implemented Debug and Clone for most types

* Added `throw!` macro to throw and return
2021-04-24 13:28:05 +12:00
David
f11451fe58
Replace unit errors with error enum (#29)
* WIP: Replacing unit type errors with actual error

* Tidied up errors
2021-04-24 12:22:56 +12:00
David
439f2ae981
Relicense under MIT or Apache 2.0 (#27)
* Relicense under MIT or Apache 2.0

* Updated license in README to match Rust guidelines
2021-04-22 20:01:30 +12:00
David Cole
7042018222 Added Clang to requirements 2021-04-20 16:40:35 +12:00
David Cole
281d82fe5b Added TryFrom implementation for HashMap 2021-04-18 23:07:21 +12:00
David
d4c6aa26ba
Replaced manual TryFrom implementations with macro (#24)
* Updated traits for building Zval

* Replaced manual implementations with macro impl
2021-04-18 23:04:43 +12:00
David
815452f799
Refactored ZendHashTable conversions (#23)
We shouldn't really be returning Zval objects, rather references to Zval
objects. There is currently a memory leak with arrays that need to be
resolved.
2021-04-18 21:57:40 +12:00
David Cole
87f1503ca5 Fixed HashTable -> Vec 2021-04-18 20:56:06 +12:00
David Cole
3917c413b5 Added From<ZendHashTable> impl for Vec 2021-04-18 20:50:00 +12:00
David Cole
75f99c6837 Updated Discord invite to use vanity URL 2021-04-18 17:02:04 +12:00
David Cole
136cc4138d Added opus-php to examples 2021-04-18 17:01:31 +12:00
David
472e26e8fb
Added ability to register constants (#22) 2021-04-18 16:48:58 +12:00
David
349d497793
Added ability to throw exceptions (#21)
* Exceptions have static lifetimes

* Added functions for throwing exceptions

Changed the `ClassEntry` implementation to unwrap the result before
returning, as these types are guaranteed to be valid. Also replaced the
'a lifetime with 'static lifetimes.
2021-04-18 15:52:02 +12:00
David Cole
35808d9e49 Updated inline documentation 2021-04-18 14:41:51 +12:00
David Cole
45c7242f1e Added parse_args! macro for parsing arguments 2021-04-18 14:35:04 +12:00
David Cole
f1a63c3600 Release 0.0.4 2021-04-17 21:59:59 +12:00
David Cole
5f89a5f970 Fixed typo v2 2021-04-17 00:25:07 +12:00
David Cole
b08fad5aad Fixed typo 2021-04-17 00:20:17 +12:00
David Cole
53e69f3820 Fixed CI by installing LLVM 2021-04-17 00:17:02 +12:00
David Cole
e38d987d15 Added gitignore to derive crate 2021-04-17 00:07:37 +12:00
Will Browning
cea3cb2dc4
Updated Bindgen to 0.58.1 (#20)
* Update bindgen

* Fix failing test

* Add env llvm and libclang variables

* Fixed doc comment for table macros

* Removed newline

Co-authored-by: David Cole <david.cole1340@gmail.com>
2021-04-17 00:05:17 +12:00
David
3503b10289
Added Discord link to README 2021-04-09 12:36:30 +12:00