SWIGTYPE && input typemaps now assume object has been moved

Replicated Java implementation.

Fully implemented for:
- C#
- D
- Guile
- Javascript (UTL)
- Lua
- MzScheme
- Octave (UTL)
- Perl (UTL)
- PHP
- Python (UTL)
- Ruby (UTL)
- Tcl (UTL)

PHP std::auto_ptr std::unique_ptr minor tweaks and testcase corrections
This commit is contained in:
William S Fulton 2022-08-20 15:40:53 +01:00
commit e139a36511
31 changed files with 931 additions and 46 deletions

View file

@ -420,14 +420,15 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%}
%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0);
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type is null", 0);
return $null;
} %}
%typemap(in, canthrow=1) SWIGTYPE && %{ $1 = ($1_ltype)$input;
%typemap(in, canthrow=1, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0);
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type is null", 0);
return $null;
} %}
}
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE * %{ $result = (void *)$1; %}
%typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{
char buf[128];
@ -613,7 +614,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
"$csinput"
%typemap(csin) char *, char *&, char[ANY], char[] "$csinput"
%typemap(csin) SWIGTYPE "$&csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "$csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE && "$csclassname.swigRelease($csinput)"
%typemap(csin) SWIGTYPE (CLASS::*) "$csclassname.getCMemberPtr($csinput)"
/* The csout typemap is used for converting function return types from the return type

View file

@ -122,7 +122,7 @@
%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null");
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null");
return $null;
} %}
%typemap(out) SWIGTYPE & "$result = (void *)$1;"
@ -157,11 +157,12 @@
* Rvalue reference conversion typemaps.
*/
%typemap(in, canthrow=1) SWIGTYPE && %{ $1 = ($1_ltype)$input;
%typemap(in, canthrow=1, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null");
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null");
return $null;
} %}
}
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE && "$result = (void *)$1;"
%typemap(directorin) SWIGTYPE &&
@ -182,7 +183,7 @@
%typemap(din,
nativepointer="cast(void*)$dinput"
) SWIGTYPE && "$dclassname.swigGetCPtr($dinput)"
) SWIGTYPE && "$dclassname.swigRelease($dinput)"
%typemap(dout, excode=SWIGEXCODE,
nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}") SWIGTYPE && {
$dclassname ret = new $dclassname($imcall, $owner);$excode

View file

@ -4,12 +4,33 @@
* Guile-specific typemaps
* ----------------------------------------------------------------------------- */
/* These are defined with a view to eventually merging with those defined for other target languages in swigtypemaps.swg and exception.swg */
#define %set_output(obj) $result = obj
#define %set_varoutput(obj) $result = obj
#define %argument_fail(_code, _type, _name, _argn) scm_wrong_type_arg((char *) FUNC_NAME, _argn, $input)
#define %as_voidptr(ptr) (void*)(ptr)
#define %argument_nullref(_type, _name, _argn) scm_misc_error(FUNC_NAME, "invalid null reference for argument " #_argn " of type '" _type "'", SCM_EOL)
#define %releasenotowned_fail(_code, _type, _name, _argn) scm_misc_error(FUNC_NAME, "cannot release ownership as memory is not owned for argument " #_argn " of type '" _type "'", SCM_EOL)
/* Pointers */
%typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] {
%typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
$1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0);
}
%typemap(freearg) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "";
%typemap(in, noblock=1, fragment="<memory>") SWIGTYPE && (void *argp = 0, int res = 0, std::unique_ptr<$*1_ltype> rvrdeleter) {
res = SWIG_ConvertPtr($input, &argp, $descriptor, SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
%releasenotowned_fail(res, "$1_type", $symname, $argnum);
} else {
%argument_fail(res, "$1_type", $symname, $argnum);
}
}
if (!argp) { %argument_nullref("$1_type", $symname, $argnum); }
$1 = ($1_ltype)argp;
rvrdeleter.reset($1);
}
%typemap(freearg) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] ""
%typemap(in) void * {
$1 = ($1_ltype)SWIG_MustGetPtr($input, NULL, $argnum, 0);
@ -372,11 +393,6 @@ typedef unsigned long SCM;
* taken from typemaps/swigtype.swg
* ------------------------------------------------------------ */
#define %set_output(obj) $result = obj
#define %set_varoutput(obj) $result = obj
#define %argument_fail(code, type, name, argn) scm_wrong_type_arg((char *) FUNC_NAME, argn, $input);
#define %as_voidptr(ptr) (void*)(ptr)
%typemap(in) SWIGTYPE (CLASS::*) {
int res = SWIG_ConvertMember($input, %as_voidptr(&$1), sizeof($1), $descriptor);
if (!SWIG_IsOK(res)) {

View file

@ -692,12 +692,12 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
}
%typemap(in) SWIGTYPE & %{ $1 = *($&1_ltype)&$input;
if (!$1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type is null");
return $null;
} %}
%typemap(in, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = *($&1_ltype)&$input;
if (!$1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type is null");
return $null;
}
rvrdeleter.reset($1); %}

View file

@ -151,11 +151,17 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
}
%}
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE&&
%{
if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,$disown))){
SWIG_fail_ptr("$symname",$argnum,$descriptor);
%typemap(in,checkfn="lua_isuserdata",fragment="<memory>") SWIGTYPE&& (void *argp = 0, int res = 0, std::unique_ptr<$*1_ltype> rvrdeleter) %{
res = SWIG_ConvertPtr(L, $input, &argp, $descriptor, SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
lua_pushfstring(L, "Cannot release ownership as memory is not owned for argument $argnum of type '$1_type' in $symname"); SWIG_fail;
} else {
SWIG_fail_ptr("$symname", $argnum, $descriptor);
}
}
$1 = ($1_ltype)argp;
rvrdeleter.reset($1);
%}
// out is simple

View file

@ -8,9 +8,6 @@
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
#define %argument_fail(code, type, name, argn) scheme_wrong_type(FUNC_NAME, type, argn, argc, argv);
#define %set_output(obj) $result = obj
%define %auto_ptr(TYPE)
%typemap(in, noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);

View file

@ -8,9 +8,6 @@
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
#define %argument_fail(code, type, name, argn) scheme_wrong_type(FUNC_NAME, type, argn, argc, argv);
#define %set_output(obj) $result = obj
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);

View file

@ -4,7 +4,7 @@
#define %set_output(obj) $result = obj
#define %set_varoutput(obj) $result = obj
#define %argument_fail(code, type, name, argn) scheme_wrong_type(FUNC_NAME, type, argn, argc, argv);
#define %argument_fail(code, type, name, argn) scheme_wrong_type(FUNC_NAME, type, argn, argc, argv)
#define %as_voidptr(ptr) (void*)(ptr)
@ -72,9 +72,23 @@
#ifdef __cplusplus
%typemap(in) SWIGTYPE &, SWIGTYPE && {
%typemap(in) SWIGTYPE & {
$1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum, 0);
if ($1 == NULL) scheme_signal_error("swig-type-error (null reference)");
if ($1 == NULL) scheme_signal_error(FUNC_NAME ": swig-type-error (null reference)");
}
%typemap(in, noblock=1, fragment="<memory>") SWIGTYPE && (void *argp = 0, int res = 0, std::unique_ptr<$*1_ltype> rvrdeleter) {
res = SWIG_ConvertPtr($input, &argp, $descriptor, SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
scheme_signal_error(FUNC_NAME ": cannot release ownership as memory is not owned for argument $argnum of type '$1_type'");
} else {
%argument_fail(res, "$1_type", $symname, $argnum);
}
}
if (argp == NULL) scheme_signal_error(FUNC_NAME ": swig-type-error (null reference)");
$1 = ($1_ltype)argp;
rvrdeleter.reset($1);
}
%typemap(out) SWIGTYPE &, SWIGTYPE && {

View file

@ -125,14 +125,31 @@
swig_acquire_ownership_obj((void*)$result, own);
%}
%typemap(in, phptype="SWIGTYPE") SWIGTYPE &,
SWIGTYPE &&
%typemap(in, phptype="SWIGTYPE") SWIGTYPE &
%{
if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) {
zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
return;
}
%}
%typemap(in, fragment="<memory>") SWIGTYPE && (void *argp = 0, int res = 0, std::unique_ptr<$*1_ltype> rvrdeleter) %{
res = SWIG_ConvertPtr(&$input, &argp, $descriptor, SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
zend_type_error("Cannot release ownership as memory is not owned for argument $argnum of $1_descriptor of $symname");
return;
} else {
zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
return;
}
}
if (!argp) {
zend_type_error("Invalid null reference for argument $argnum of $1_descriptor of $symname");
return;
}
$1 = ($1_ltype)argp;
rvrdeleter.reset($1);
%}
%typemap(directorout) SWIGTYPE & ($1_ltype tmp),
SWIGTYPE && ($1_ltype tmp)

View file

@ -13,10 +13,10 @@
res = SWIG_ConvertPtr(&$input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
zend_type_error("Cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *' of $symname");
zend_type_error("Cannot release ownership as memory is not owned for argument $argnum of $descriptor(TYPE *) of $symname");
return;
} else {
zend_type_error("Expected TYPE * for argument $argnum of $symname");
zend_type_error("Expected $descriptor(TYPE *) for argument $argnum of $symname");
return;
}
}

View file

@ -13,10 +13,10 @@
res = SWIG_ConvertPtr(&$input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
zend_type_error("Cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *' of $symname");
zend_type_error("Cannot release ownership as memory is not owned for argument $argnum of $descriptor(TYPE *) of $symname");
return;
} else {
zend_type_error("Expected TYPE * for argument $argnum of $symname");
zend_type_error("Expected $descriptor(TYPE *) for argument $argnum of $symname");
return;
}
}

View file

@ -68,13 +68,18 @@
#endif
/* Rvalue reference */
%typemap(in, noblock=1) SWIGTYPE && (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor, %convertptr_flags);
%typemap(in, noblock=1, fragment="<memory>") SWIGTYPE && (void *argp = 0, int res = 0, std::unique_ptr<$*1_ltype> rvrdeleter) {
res = SWIG_ConvertPtr($input, &argp, $descriptor, SWIG_POINTER_RELEASE | %convertptr_flags);
if (!SWIG_IsOK(res)) {
%argument_fail(res, "$type", $symname, $argnum);
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
%releasenotowned_fail(res, "$type", $symname, $argnum);
} else {
%argument_fail(res, "$type", $symname, $argnum);
}
}
if (!argp) { %argument_nullref("$type", $symname, $argnum); }
$1 = %reinterpret_cast(argp, $ltype);
rvrdeleter.reset($1);
}
%typemap(freearg) SWIGTYPE && ""