Commit Graph

269 Commits

Author SHA1 Message Date
Olly Betts 979d48b0b4 Remove obsolete FIXME
We no longer have the PHP code wrappers.
2021-03-29 17:41:01 +13:00
Olly Betts 3f1286ba4f Use standard SWIG overload dispatch
Instead of having a slightly modified PHP-specific variant of
Swig_overload_dispatch we now advance the ParmList over the this
pointer.
2021-03-29 17:41:01 +13:00
Olly Betts 7142acbf93 Fix whitespace oddities 2021-03-29 17:29:59 +13:00
Olly Betts 0e7d6a4c8d More PHP8 compatibility fixes 2021-03-29 09:37:44 +13:00
Olly Betts 73a149200f Remove more code which is no longer used 2021-03-28 19:47:16 +13:00
Olly Betts 1c5573d0d0 Remove code which is no longer used 2021-03-28 08:54:24 +13:00
Olly Betts c58149bc45 Simplify printing code a little
Remove unused Printf parameter, and use Printv where it's more readable.
2021-03-27 19:59:30 +13:00
Olly Betts dfa5353f27 Eliminate extras hash table
This was used to store custom properties, but we can just ask the PHP
object to store them like it normally would, after checking for our
custom pseudo-properties.
2021-03-27 19:57:37 +13:00
Olly Betts 799cb68a8a Use ZEND_THIS instead of getThis()
getThis(z) checks that z is a PHP object and returns ZEND_THIS if it
is, and NULL otherwise.  In all our uses we know that z is a PHP object
(and we'd try to dereference NULL if it were returned!)
2021-03-27 19:51:24 +13:00
Olly Betts 232308b494 Drop unnecessary casts to swig_object_wrapper* 2021-03-27 19:49:49 +13:00
Olly Betts c03679acef Improve how we allocate swig_object_wrapper
Use zend_object_alloc() and put the zend_object member last so that
Zend can put object properties after it.
2021-03-26 17:15:34 +13:00
Olly Betts 4aff93942a Improve arginfo generation
Fixes some failing examples and testcases.
2021-03-26 15:34:29 +13:00
Olly Betts f77113ea71 php: Eliminate SWIG_ZEND_NAMED_FE
It existed to work around const-correctness issues in older versions of
PHP's C API.  It's conceivable user code might be using it, but unlikely
and the switch to creating classes via the API is a natural time for a
compatibility break.
2021-03-26 13:58:02 +13:00
Olly Betts 2ba0f82720 Merge branch 'master' into gsoc2017-php7-classes-via-c-api 2021-03-26 12:00:59 +13:00
Olly Betts b840911410 Remove outdated FIXME/TODO from php.cxx
See #1529
2021-03-26 11:18:07 +13:00
Olly Betts 8ded9d8dae Merge branch 'master' into gsoc2017-php7-classes-via-c-api 2021-03-25 17:45:17 +13:00
Olly Betts d15fe23c5f Merge branch 'gsoc2017-php7-classes-via-c-api' of https://github.com/nihal95/swig into gsoc2017-php7-classes-via-c-api 2021-03-25 16:25:33 +13:00
Olly Betts 786efd0ae0 Eliminate irrelevant formatting differences from master 2021-03-24 11:59:25 +13:00
Olly Betts 3584c7d49c Add initial support for PHP8
Testcase director_overload2 is failing, but the rest of the testsuite
passes.
2021-03-19 19:30:27 +13:00
Olly Betts 2e7da86b2c php: Fix overloaded directed methods with non-void return
We were treating  such methods like constructors and assigning to the
internal _cPtr, which just seems bizarrely wrong.

Fixes #1900
2021-03-18 10:58:44 +13:00
William S Fulton 2cf075558c Replace all exit() with SWIG_exit()
For consistent cleanup on error
2019-07-31 00:08:49 +01:00
Frederik Schubert b3a3c4f09e Don't add a closing php-tag
This PR removes the closing `?>` PHP tag from generated files. [PSR-2](https://www.php-fig.org/psr/psr-2/) states:

> The closing `?>` tag MUST be omitted from files containing only PHP.

A problem might occur if files with any character after the closing tag are used with `include` or `require`. It might trigger an output and disallow HTTP header manipulation. See the popular [_headers already sent_](https://stackoverflow.com/a/8028987/1847340) debate on SO.
2019-05-22 11:35:08 +12:00
Olly Betts 950473d77e [php] Whitespace improvements in generated C/C++ code 2019-02-12 10:14:25 +13:00
Olly Betts 123eabf200 [PHP] Wrap renamed constructor as static method
Previously it was wrapped as a non-static method, which results in
a diagnostic from PHP if called as a static method.
2019-02-09 12:51:45 +13:00
Olly Betts 3f9ebb31b9 [PHP] Don't generate code referencing undefined $r
This could happen in overloaded methods which returned void and took at
least one const std::string& parameter.
2019-02-08 18:09:52 +13:00
William S Fulton df86ec5af6 Consistent use of target language version of options
If a version number is supported by the target language prefer to show it in the -help.
For example, -perl5 instead of -perl.
2019-02-05 19:18:46 +00:00
William S Fulton 29d30bd319 Consistent implementation for disabled languages
The deprecated php4 and php5 use the new Disabled language handling
recently implemented for a consistent implementation
2019-02-05 19:04:59 +00:00
Olly Betts d7ac8581b1 [php] Drop support for long-deprecated %pragma(php4)
Finally removed support for %pragma(php4) which was deprecated back in
2008.  The replacement is %pragma(php), which has been supported since
at least 2005.
2018-06-07 18:09:14 +12:00
Olly Betts d6d5db122b Remove support for PHP5
PHP5 is no longer actively supported by the PHP developers and security
support for it ends completely at the end of 2018, so it doesn't make
sense to include support for it in the upcoming SWIG 4.0.0 release.

See #701.
2018-06-07 18:09:03 +12:00
Olly Betts 224bb9e023 [PHP] Use ZEND_MODULE_GLOBALS_ACCESSOR to access globals
This should make the generated code work with PHP 7.2.0.
2017-12-08 15:50:14 +13:00
William S Fulton ae044c1c2f Generation of director method declarations fixes
- Fixes generation of director method declarations containing C++11 ref-qualifiers.
- Fixes generation of director method declarations returning more complex types such
  as const ref pointers.
- Rewrite Swig_method_call to use more up to date code in the core.
2017-10-23 18:55:14 +01:00
William S Fulton 3f8b8fe734 Enhancements for directorin typemaps
The directorin typemaps will now generate a temporary variable
(specified after the type), such as:
%typemap(directorin) MyType (MyType *temp) { ... use temp ... }

The shared_ptr director typemaps have been fixed for use in functions
that take more than one parameter.
2017-10-16 19:28:27 +01:00
Olly Betts 0c56d0cb72 [PHP] Fix incorrect wrapper code generation
Fix code generated when there's a combination of overloading, parameters
with a default value and %newobject.  Fixes
https://sourceforge.net/p/swig/bugs/1350/
2017-10-09 10:40:27 +13:00
Nihal 6c3f5155b2 Refactor declarations inside if-else block.
- This is to support C90
2017-09-23 12:13:20 +05:30
Nihal d1f7ad5af5 Fix evil_diamond_prop test case.
- This fixes the problem of no reaching parent class variables.

Note: Any extra variables set by __set function are stored in the parent class's extras
hastable under swig_object_wrapper.
2017-09-22 09:26:17 +05:30
Nihal 7e66388cf3 Fix director_basic test case
- This fixes director_basic test case. Uses the new flow in director class methods.
- It also correctly fixes the double free problem in director_detect.
2017-09-14 01:23:18 +05:30
Nihal 9451f52f74 Fix global_scope_types test case.
- Problem with Dingaling ambiguous class/struct.
2017-09-13 00:41:35 +05:30
Nihal 98d1a2f8c5 Fix bug in *const& "in" typemaps.
- Refactored the reference check logic to Lib files.
2017-09-13 00:41:03 +05:30
Nihal f054f76544 Bug Fix Director upcall functions to return object pointers
- Refactor php.swg to adhere to checkstyle
2017-09-03 10:29:18 +05:30
Nihal 38f282d847 Fix class-constant bug.
- zend_declare_class_constant ends up having "" values.
2017-09-02 11:02:10 +05:30
Nihal e11b4711a7 Remove abstarct on Directed methods to allow dispatch pass through 2017-09-01 00:21:17 +05:30
Nihal a8db1e4aa6 Remove all checks of ':' on name attribute.
- Remove use of getWrapperMethodName
2017-09-01 00:19:56 +05:30
Nihal 0343a01a8c Refactor checks/use of ':' with name attribute 2017-08-28 13:06:07 +05:30
Nihal e4f56a8ed5 Fix operator_overload test-case
- Friend function is not under class methods.
- Also fix friend function overloading.
2017-08-28 12:22:28 +05:30
Nihal 9c40bbdb85 Refactor SWIG_SetZval to simplify the arguments. Solve constructor rename bug
- Refactor SWIG_SetZval.
- Fix the Renamed constructor - turn into static factory method bug.

Conflicts:
	Source/Modules/php.cxx
2017-08-28 11:22:51 +05:30
Nihal aa180f2c4d Refactor code and adhere to codestyle/checkstyle.
- Remove noproxy processing code.
2017-08-28 04:07:40 +05:30
Nihal 4252b31f8f Refactor code to rename class entry variables and ConvertPtr to work with wrapped objects.
- Rename class entry variables to SWIGTYPE_class_ce
- Refactor factory code to use SWIGTYPE_class_ce to create objects
- Refactor ConvertPtr to work of wrapped class objects.
2017-08-20 01:54:07 +05:30
Nihal 9fea6fc5ac Refactor code and solve few test cases.
- Change the need of runtime check on old or new flow at wrapper generation time.
- Change the check on add ZEND_ACC_ABSTRACT to GetFlag(n, "abstract") && Swig_directorclass(Swig_methodclass(n))
  - workaround to solve abstract testcases at the moment.
- Remove redundant code in class handler for getting namespaces (Not the correct approact) and use of zend_register_class_alias_ex.
- Refactor choosing of class name to use sym:name by default.
2017-08-18 09:02:47 +05:30
Nihal a687b020e2 Refactor code and change change enum_scope_template test to use class enums. Fix few test cases.
- Change enum_scope_template test to use class enums.
- Move the conversion of void* of ptr in swig wrapper to class pointer to Lib files.
- Synchronize between old and new flow. Old flow to accept newly created objects,
with the use of a new property SWIG_classWrapper to newly created objects.
- ZEND_BEGIN_ARG_INFO_EX to hold exact number of arguments required.
- Fix the constructor overloading bug in the in-house Swig_class_overload_dispatch function
- Add helper function to check if the class is wrapped.
- Add ZEND_ACC_ABSTRACT to virtual functions to make the class abstract.
- Change how wname is selected for staticmemberfn.
- Helper function to get names without namespace getNameWithoutNamespace.
- Fix bugs on class entry level at class handler.
  - Move all entry level code to class handler from class decleration.
  - Checking if base.item is null before using it.
  - Check if the parent class is wrapped before using its class entry.
2017-08-18 08:54:05 +05:30
Nihal da53351cac Refactor code and introduce some functionalities.
Code Refactor
- Refactor code for return type of SWIGTYPE
- Workaround for Namespaced classes.
- Refactor code of SWIG_SetZval to take care of objects in class constructor.
- Introduce SWIG_generalize_object to generalize each object to swig object wrapper.
- Catch feature:immutable instead of feature:warnfilter - 462 for missing setter.
- Refactor code to create PHP objects for all instances of value, reference and pointer return types of C++ objects.
- Introduce getAccessMode to get the Access Mode of a method for generating Wrapper.
- Refactor free_object creation to include need_free condition. This is to check if there is a need to free. (Virtual Protected Destructors)
- Support for feature:exceptionclass. Extends class Exception.
- Improve condition check in Director class constructor to distinguish between, extended class creation or not.
  Swig::Director::swig_is_overridden_method is used.
2017-08-12 10:11:47 +05:30
Nihal a930743932 Refactor Code and Support phpinterfaces, factory dispatch
- rewire return of type SWIGTYPE
- {NULL, NULL, NULL} to ZEND_FE_END
- feature:warnfilter - 462 of missing setter
- refactor code of return type (replaced)
- support conversion_operator
2017-08-04 23:13:19 +05:30
Nihal 67fb198b73 SWIG Director Support with Class Structure. Refactor Code to support rename.
Refactor Code
- Support Director Classes.
- %rename support of class names and method names.
- Creation and destruction methods after inline code.
- Test case check::function return true. - Needs Fixup
2017-08-01 11:01:15 +05:30
Nihal 6b8aae188f Refactor Code.
- Support different return types of pointers. - Fixup
- Support the rename functionality in class names.
- Redirect the resource destructor to the class desctructor if its a class resource - Object pointers.
2017-07-23 09:54:23 +05:30
Nihal 4c55919975 Refactor Code to use swig_object_wrapper for wrapping classes.
And use void * to store class pointers.
2017-07-19 22:52:46 +05:30
Nihal b38e6d9584 Remove SWIG_Get_Type function usage in class constants.
Add class constant typemaps. (classconsttab)
2017-07-19 20:49:40 +05:30
Nihal a71b349204 Add overload Support.
Use in house SWIG_overload_dispatch for class overloaded methods.
2017-07-19 20:49:37 +05:30
Nihal 290198495f Support Disown functionality.
Creating newobject variable under struct which stores this pointer.
Using that to implement Disown.
2017-07-19 20:49:33 +05:30
Nihal 4458040975 Refactor Code: Change Approach to emit necessary code for pointer params.
Use in typemap.
2017-07-19 20:49:26 +05:30
Nihal c6cfad2aab Remove SWIG_Get_Type in magic getter and setter methods.
Use respective getter and setter methods.
2017-07-19 20:49:22 +05:30
Nihal de31666c3a Fixup: Remove TRMS Stuff (Not used in PHP7).
Remove Cmp of class_name with NULL.
Reuse code to find "_get" (getters) methods of member variables.
2017-07-19 20:48:50 +05:30
Nihal 58aff09ebe Add magic methods support (__get, __set, and __isset) inherently to the extensions.
This to to maintain compatibility and consistency.
2017-07-19 20:48:46 +05:30
Nihal 42f012b2d1 Bug Fix of double freeing. It used to create a new object for all get commands of class/struct pointers.
Now creating only if newobject is lit, or else creating a basic zend object to return to user.
2017-07-19 20:48:27 +05:30
Nihal 9addd37640 Use pre-exisiting function is_class to check a valid class/struct defenition. 2017-07-19 20:48:24 +05:30
Nihal ce04574059 Add support to access static member variables in different way.
This is to keep compatibility and consistency with the older way.
Shape::nshapes static variable's setter and getter methods can be
accessed by Shape::nshapes(10),Shape::nshapes() respectively.
2017-07-19 20:48:19 +05:30
Nihal 4de2f257f9 Using wname variable for function name generated in .cxx or .c wrapper.
This is to ensure compatibility and consistency
2017-07-19 20:48:15 +05:30
Nihal 5e001d5288 Add class constants support to access class enums and class constants.
"flat" constants changed to class constatns.
Example: Foo_IMPULSE -> Foo::IMPULSE
2017-07-19 20:48:01 +05:30
Nihal 11e2f53840 Object Structure approach Code
Takes care of simple class wrapping with pointers, enum, values, variables, and inheritance.
2017-07-19 20:47:53 +05:30
Nihal 251d25346d Fix OUTPUT Typemap not having return statement bug in PHP wrapper. 2017-06-28 09:47:33 +12:00
Olly Betts 9a0180c56c Merge pull request #970 from nihal95/master
Adds pragma version directive for php5 and php7.  Fixes #360.
2017-05-16 17:47:35 +12:00
William S Fulton ebd37155a8 Fix potential use of uninitialized variables in directors 2017-05-13 22:40:59 +01:00
Nihal eb9e72f3b2 Add new pragma to specify version to PHP5 and PHP7 extensions.
See issue #360, feature request to have version in php5 and php7 extensions.
2017-05-08 11:43:38 +05:30
Christophe Duvernois 4777a0ad3c #526 : propagate c++11 noexcept to director classes 2017-04-27 23:37:15 +02:00
Olly Betts 0aac18b2a1 [PHP] destroy_globals function is empty, so drop
We can just pass NULL instead.
2016-12-30 16:02:01 +13:00
Olly Betts 36ee653d3b Omit module functions when there's no code
MSHUTDOWN, RINIT, RSHUTDOWN and MINFO are often empty, so check and
omit them if this is the case, and set the module structure entry to
NULL instead.  Reduces code size, number of external functions on the
module, and runtime overhead a little (RINIT and RSHUTDOWN are called
on every request when used with a webserver).
2016-12-30 15:36:08 +13:00
Olly Betts cf60bb8895 [php7] Drop special code for PHP < 5.4 2016-12-30 14:56:53 +13:00
Olly Betts 4a2ede0820 [PHP7] Remove lingering generated ZTS code
ZTS is gone in PHP7 so these are dead code.
2016-12-30 12:41:19 +13:00
Olly Betts 2b4c1cdd5e Fix "set but not used" warning 2016-12-13 11:40:45 +13:00
Olly Betts 2aa2219f28 Fix reference example under PHP 7.1
PHP 7.1 no longer supports calling methods with fewer parameters
than declared, so we need to generate __construct() with default
values for all but the first parameter.
2016-12-06 11:01:55 +13:00
Olly Betts da1dd2ffd2 [PHP] Pick a default dtor which can't collide 2016-12-01 15:09:53 +13:00
Olly Betts 76a98b0b1a [PHP] Emit at most one copy of the default dtor
Can reduce the wrapper source size significantly, though at least
with recent GCC the stripped compiled size seems unchanged.
2016-12-01 14:21:29 +13:00
Olly Betts 659116a1b2 Fix memory leaks introduced by previous commit 2016-12-01 14:04:10 +13:00
Olly Betts 4993991d28 [PHP] Only emit one copy of each distinct arginfo
Previously we emitted a separate one for every wrapped function,
but typically many functions have the same number of parameters
and combinations of parameters passed by reference or not.

This change significantly reduces both the size of the generated
wrapper, and of the compiled PHP extension module (e.g. by ~6% for
the stripped extension module for Xapian's PHP7 bindings).
2016-12-01 13:05:41 +13:00
Olly Betts 75a00cd15e [PHP7] Make default C++ extension .cxx
This is SWIG's default for every language except PHP, and now is a
good time to make this change so that once we drop PHP5 support, we'll
have the same default everywhere.  It's easy to override the default
with -cppext cxx to get the PHP5 behaviour.
2016-11-30 13:27:13 +13:00
Olly Betts 1169874f59 [PHP] Add support for PHP7.
PHP5's C extension API has changed substantially so you need to use
-php7 to specify you want PHP7 compatible wrappers.
Fixes https://github.com/swig/swig/issues/571
2016-11-30 13:05:59 +13:00
Olly Betts 1adfe2f537 [PHP] Fix code generated for feature("director:except")
Previously the return value of call_user_function() was ignored and we
checked an uninitialised value instead.  Fixes #627.  Based on patch
from Sergey Seroshtan.
2016-09-25 14:42:04 +13:00
Olly Betts 26bbc96d58 Arrange to return after calling zend_throw_exception()
Fixes github issue#240.
2016-09-16 17:54:02 +12:00
William S Fulton ac495d5c66 Merge branch 'char-escaping'
* char-escaping:
  Add missing string_constant.i testcase
  changes file update for char wrappers
  C# char wrappers fixes for enum values, static const member char values and %csconst
  D testing added for %dmanifestconst and char constants
  Fix wrapping D constants using %dmanifestconst
  Php fix for enum value of '\0'
  Fix static const char member variables wrappers with %javaconst(1).
  Expand char testing in enums and %constant
  Java char changes file update
  Java enum and static member variable escaping fix for chars
  Add tests for enum values and static const member variables chars containing escape sequences
  Minor documentation tweak

Conflicts:
	CHANGES.current
2016-03-12 23:27:51 +00:00
William S Fulton 539aca58a5 Php fix for enum value of '\0' 2016-03-12 00:26:49 +00:00
William S Fulton 21ee09fc19 Multiple inheritance warning wording tweak 2016-03-06 10:45:39 +00:00
Petre Eftime 0a07cd4c30 Prevent redefinition warnings when compiling with SWIG<module> defined
Signed-off-by: Petre Eftime <petre.p.eftime@intel.com>
2015-12-22 14:33:21 +02:00
William S Fulton 6a61f8271f Php fix for -Wmissing-field-initializers warning
Use ZEND_FE_END (introduced sometime around 5.2) to obtain the correct
number of arguments for zend_function_entry. Fallback to the original
3 argument initializer if not defined, however, this will not fix the
initializer warning though for some older versions of PHP.
2015-12-19 16:21:23 +00:00
William S Fulton edcdaaec16 Warning fixes for 64bit visual c++ on Windows 2015-07-03 20:59:24 +01:00
Nils Gladitz 925cec3a82 Add a space between literal and string macro
In C++11 a space between a literal and string macro is required.
2015-07-03 20:59:23 +01:00
Olly Betts 7ba0652677 Create director_common.swg for language-indep code
Move -DSWIG_DIRECTOR_STATIC handling there, so this is now supported for
all languages with director support, not just Python and PHP.
2015-03-12 19:51:11 +13:00
Olly Betts b3003f1f9f [PHP] When wrapping a returned resource as an object, check if all
cases wrap it in the same class, and if so eliminate the pointless
switch statement wrapper we previously generated.
2015-01-23 13:56:13 +13:00
Olly Betts 0dd685bad2 Fix PHP crash in director_finalizer 2015-01-14 15:38:55 +13:00
Olly Betts ea5be4e508 Fix PHP backend for default_args testcase 2015-01-14 10:44:54 +13:00
Olly Betts 682b4dd843 [PHP] Fix segfault in director upcall check
Manifest only when using PHP built with ZTS enabled.
2015-01-12 13:53:01 +13:00
William S Fulton 06e361dbf2 Fix linux gcc warnings and strtol corrections 2015-01-11 17:30:25 +00:00
Olly Betts cd16059c66 Provide -cppext as a general command line option
Provide -cppext as a general command line option for setting the
extension used for generated C++ files (previously it was specific
to the PHP backend).  Deprecate the equivalent -suffix option
provided by the Ocaml backend, but continue to support that for
now.
2015-01-08 10:54:37 +13:00