Fix overloading for non-pointers and NULL - Php

This commit is contained in:
William S Fulton 2018-12-30 12:00:49 +00:00
commit b7db45661a
3 changed files with 57 additions and 4 deletions

View file

@ -0,0 +1,46 @@
<?php
require "tests.php";
require "overload_null.php";
$o = new Overload();
$x = new X();
check::equal(1, $o->byval1($x), "test 1");
check::equal(2, $o->byval1(null), "test 2");
check::equal(3, $o->byval2(null), "test 3");
check::equal(4, $o->byval2($x), "test 4");
check::equal(5, $o->byref1($x), "test 5");
check::equal(6, $o->byref1(null), "test 6");
check::equal(7, $o->byref2(null), "test 7");
check::equal(8, $o->byref2($x), "test 8");
check::equal(9, $o->byconstref1($x), "test 9");
check::equal(10, $o->byconstref1(null), "test 10");
check::equal(11, $o->byconstref2(null), "test 11");
check::equal(12, $o->byconstref2($x), "test 12");
# const pointer references
check::equal(13, $o->byval1cpr($x), "test 13");
check::equal(14, $o->byval1cpr(null), "test 14");
check::equal(15, $o->byval2cpr(null), "test 15");
check::equal(16, $o->byval2cpr($x), "test 16");
# forward class declaration
check::equal(17, $o->byval1forwardptr($x), "test 17");
check::equal(18, $o->byval1forwardptr(null), "test 18");
check::equal(19, $o->byval2forwardptr(null), "test 19");
check::equal(20, $o->byval2forwardptr($x), "test 20");
check::equal(21, $o->byval1forwardref($x), "test 21");
check::equal(22, $o->byval2forwardref($x), "test 22");
check::done();
?>

View file

@ -5,6 +5,7 @@
* ----------------------------------------------------------------------------- */
%runtime "swigrun.swg" // Common C API type-checking code
%runtime "swigerrors.swg" // SWIG errors
%runtime "phprun.swg" // PHP runtime functions
%include <phpinit.swg> // PHP initialization routine.
@ -470,20 +471,26 @@
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
{
void *tmp;
_v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $&1_descriptor, 0) >= 0);
_v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $&1_descriptor, SWIG_POINTER_NO_NULL) >= 0);
}
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &,
SWIGTYPE &&,
SWIGTYPE *const&
{
void *tmp;
_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0);
}
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE &,
SWIGTYPE &&
{
void *tmp;
_v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, SWIG_POINTER_NO_NULL) >= 0);
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const&
{
void *tmp;

View file

@ -217,7 +217,7 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) {
return (*ptr == NULL ? -1 : 0);
case IS_NULL:
*ptr = 0;
return 0;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
}
return -1;