Commit Graph

151 Commits

Author SHA1 Message Date
Alex Palaistras c1905f38cf Remove `NewReceiver` method, move logic to `Context` method receiver
This removes the `NewReceiver` method and moves logic for the `Define`
method from the `Engine` method receiver to `Context`.

Moving the `Define` method was required due to a bug/feature where
destroying a `Context` before all defined Receivers have also been
destroyed causes memory errors. Tying method receiver definitions
to the `Context` lifecycle implicitly fixes this issue.

This approach, however, contains a possible flaw, since class names
in PHP are defined in the global scope (i.e. the `Engine`), and
destroying a defined `Receiver` also removes the class entry for that
name, supposedly across all running contexts.
2016-02-19 21:48:24 +00:00
Alex Palaistras 7add2a76f3 Remove `Context.NewContext`, move to single call in `engine` package 2016-02-13 16:33:03 -05:00
Alex Palaistras a9eec41f3b Fix test table formatting for better readability 2016-02-12 21:15:14 -05:00
Alex Palaistras 5e3b493b30 Make Context log tests less strict with `strings.Contains` 2016-02-12 21:04:07 -05:00
Alex Palaistras 088b4b41b7 Merge pull request #16 from deuill/feature/fix-context-eval-scope
Context: Fix variable scoping issues for `Eval`
2016-01-26 16:55:24 +00:00
Alex Palaistras f578e8241b Context: Fix memory leak when not using `Eval` return value
The `Context.Eval` function invariably creates a `Value` which may
or may not end up being passed to the caller. Keep a reference to
the value and destroy it during `Context.Destroy` at the latest.
2016-01-26 16:48:37 +00:00
Alex Palaistras 976e5fe138 README: Add additional example for binding and returning values 2016-01-26 16:48:08 +00:00
Alex Palaistras bcf0e9ac16 Context: Fix variable scoping issues for `Eval`
Previously, `Context.Eval` relied on Zend's `zend_eval_script` function
for executing arbitrary strings. Unfortunately, the above contains a
curious bit of functionality where the string passed is prepended with
a `return` statement depending on whether or not a zval is passed for
writing the return value.

This, of course breaks all but the simplest scripts, as we always write
the return value to a zval (whether the user calling `Context.Eval` is
to use the return value is another matter entirely).

This commit changes the implementation to a more direct (and therefore
more controllable) approach. Some tests have been changed to cover this
bug.
2016-01-26 16:26:42 +00:00
Alex Palaistras 28f2241447 Improve documentation in README 2016-01-25 22:38:12 +00:00
Alex Palaistras 421a9172ce Merge pull request #14 from deuill/feature/seperate-tests
Add seperate tests for `engine` package
2016-01-24 22:11:26 +00:00
Alex Palaistras e57bdb7e4e Add seperate testsuites for value and receiver
This completes work on seperating tests and brings test coverage
to the ~90%. More corner cases will be covered as they arise.
2016-01-24 22:06:25 +00:00
Alex Palaistras 44fb3a79e2 More work on seperate tests
This improves test coverage to 51%, with Value and Receiver tests
remaining.
2016-01-23 19:00:59 +00:00
Alex Palaistras 3cd57686f9 Merge branch 'master' into feature/seperate-tests 2016-01-19 22:56:12 +00:00
Alex Palaistras 8b2bb744dc Bump year to 2016
Signed-off-by: Alex Palaistras <[email protected]>
2016-01-19 22:52:29 +00:00
Alex Palaistras 42aed36b5d Merge pull request #13 from deuill/feature/unify-directories
Unify packages into single `engine` package
2016-01-19 22:31:33 +00:00
Alex Palaistras 64a5958884 Unify packages into single `engine` package
This will allow for better tests, among other things, since
the previous arrangement did not allow for sub-packages of
engine to be tested individually (due to cyclic dependancy
issues).

Signed-off-by: Alex Palaistras <[email protected]>
2016-01-19 22:27:48 +00:00
Alex Palaistras 48df1d8695 Merge pull request #12 from deuill/feature/php7-support
First version of PHP 7 support
2016-01-19 21:42:20 +00:00
Alex Palaistras 9d09b483ff Value: Do not `efree` zval when destroying engine value
Signed-off-by: Alex Palaistras <[email protected]>
2016-01-19 21:35:55 +00:00
Alex Palaistras ece01c6419 Extensive rework of value and receiver packages
This contains extensive API changes for the value package C bindings
as well changes to the receiver package (addition of Destroy method
and other small changes). These changes are mainly to address issues
with PHP7 compatibility, but should also benefit PHP5 targets.

Signed-off-by: Alex Palaistras <[email protected]>
2016-01-19 21:25:05 +00:00
Alex Palaistras 384f522324 Receiver fixes for PHP 5.x 2016-01-13 19:44:25 +00:00
Alex Palaistras 91289291f1 Fix `Context.Bind` for PHP 7 2016-01-10 22:49:20 +00:00
Alex Palaistras 600978ccc6 Fix receiver bindings for PHP 7 2016-01-10 21:54:45 +00:00
Alex Palaistras 01a48ae6d8 Move all PHP version-specific definitions to own files
This removes all "#ifdef PHP_MAJOR_VERSION" directives for version-specific
header files per supported PHP version. These headers are included only when
building against the specific PHP version, and are intended to abstract
differences between implementations in a fairly clean way.

This is still a mess of preprocessor directives, however.
2016-01-09 17:27:38 +00:00
Alex Palaistras 705b0afbb7 First version of PHP 7 support
This adds support for building against PHP 7 when using the `php7`
build tag (i.e. `go build -tags php7`). PHP 5 support remains the
default and does not need passing any tags, currently, though this
may change at some point.

The code builds and basic tests run, but more advanced tests fail
with "zend_mm_heap corrupted". More to come.
2016-01-09 02:20:13 +00:00
Alex Palaistras b5a879848b Fix double-free and ZTS-related issues
Building against a ZTS-enabled build of PHP uncovered several issues,
including:

  * Use of missing `tsrm_ls` value. Added calls to TSRMLS_FETCH() where
    needed.
  * String keys returned with `value_array_keys` are now duplicated,
    and as such are correctly passed (and freed) to the caller.
  * Functions `value_array_index_get` and `value_array_key_get`
    incorrectly returned references of, rather than copies to, the
    values required.
  * Method `receiverSet` incorrectly called `Destroy` on the member
    value.
2016-01-01 23:50:31 +00:00
Alex Palaistras a75a1e52f3 Fix memory leak for receiver_exists function 2015-12-31 12:10:23 +00:00
Alex Palaistras 21a5e353c3 Style and correctness fixes for C files. 2015-12-28 23:34:15 +00:00
Alex Palaistras 87ae2165eb receiver: Add package-level documentation block 2015-12-27 23:05:48 +00:00
Alex Palaistras bd36732fd0 engine: Move C proxy functions from cgo.go to engine.go 2015-12-27 22:44:22 +00:00
Alex Palaistras b18639175f Merge pull request #10 from deuill/feature/better-receivers
Improve method receiver to class bindings
2015-12-27 22:32:43 +00:00
Alex Palaistras 33bc5fce01 Minor fixes for method receivers
Changed variable names, converted Go constructor from variadic to slice,
added some documentation and throw exception if error occurs in constructor.
2015-12-27 22:30:31 +00:00
Alex Palaistras 0fcb150d36 Improve method reciver to class bindings
This breaks API for the `engine.Define` method, which now expects a
receiver name and corresponding constructor method. The constructor
method accepts a slice of parameters as passed in by the PHP context,
and returns an instantiated receiver.

Receiver files have been moved to their own package.
2015-12-27 18:51:53 +00:00
Alex Palaistras a4ab33b4d0 Clarify EditorConfig for Markdown files 2015-12-27 00:52:38 +00:00
Alex Palaistras 4db5947a4f Add EditorConfig file for project 2015-12-27 00:50:00 +00:00
Alex Palaistras 3808dbf84d Merge branch 'master' into feature/seperate-tests 2015-12-24 17:05:27 +00:00
Alex Palaistras 556ed42c54 Simplify receiver_property_exists proxy function 2015-12-19 13:54:35 +00:00
Alex Palaistras cf089736e7 Merge pull request #9 from deuill/feature/define-method-receivers
Initial version of method receiver to class bindings
2015-12-18 23:20:40 +00:00
Alex Palaistras 1362ace12a Allow for property existence checks on method receivers 2015-12-18 23:19:25 +00:00
Alex Palaistras 4d87f7f5a3 Rename `class` to `receiver` for consistency 2015-12-18 22:07:18 +00:00
Alex Palaistras 93d78a0735 engine: Add documentation for Define method 2015-12-18 21:54:29 +00:00
Alex Palaistras f532f9a7e2 Use function handlers directly for class bindings 2015-12-18 21:13:03 +00:00
Alex Palaistras ca102ead64 Merge branch 'master' into feature/define-method-receivers 2015-12-18 13:28:24 +00:00
Alex Palaistras ccf998b1c8 Value: Implement PHP object-to-Go value conversion 2015-12-17 23:20:26 +00:00
Alex Palaistras 0b4aa32f83 Fix compiler warnings for context bindings 2015-12-16 21:22:45 +00:00
Alex Palaistras 200617beab Initial version of method receiver to class bindings
This feature implements defining PHP classes based on Go method receivers
(of any type). It allows for getting and setting internal properties
(in the case of struct method receivers with publicly-accessible fields)
and calling methods attached to the receiver passed.
2015-12-06 22:43:10 +00:00
Alex Palaistras a2627444f4 Simplify engine context functions 2015-12-03 19:20:24 +00:00
Alex Palaistras 8bcebb7b3b Add missing copyright declaration from new file 2015-12-02 21:11:26 +00:00
Alex Palaistras cdfdc79b67 Context: change engine identifier for eval'd code 2015-12-02 21:10:32 +00:00
Alex Palaistras 744774132c Merge branch 'master' into feature/seperate-tests 2015-12-02 20:55:55 +00:00
Alex Palaistras 02e68394c4 Move context-related engine methods to engine package
Functions for writing, logging and setting headers have been moved from
the context package to the engine package, to better match the layout
expected by the core PHP architecture.
2015-12-02 20:53:07 +00:00