Fix overloading for non-pointers and NULL - Guile
This commit is contained in:
parent
12eb0f81ae
commit
eb151e43be
4 changed files with 63 additions and 3 deletions
53
Examples/test-suite/guile/overload_null_runme.scm
Normal file
53
Examples/test-suite/guile/overload_null_runme.scm
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
;; The SWIG modules have "passive" Linkage, i.e., they don't generate
|
||||
;; Guile modules (namespaces) but simply put all the bindings into the
|
||||
;; current module. That's enough for such a simple test.
|
||||
(dynamic-call "scm_init_overload_null_module" (dynamic-link "./liboverload_null"))
|
||||
|
||||
(define-macro (check form)
|
||||
`(if (not ,form)
|
||||
(error "Check failed: " ',form)))
|
||||
|
||||
(define (=~ a b)
|
||||
(< (abs (- a b)) 1e-8))
|
||||
|
||||
(define o (new-Overload))
|
||||
(define x (new-X))
|
||||
|
||||
(check (=~ 1 (Overload-byval1 o x)))
|
||||
(check (=~ 2 (Overload-byval1 o #nil)))
|
||||
|
||||
(check (=~ 3 (Overload-byval2 o #nil)))
|
||||
(check (=~ 4 (Overload-byval2 o x)))
|
||||
|
||||
(check (=~ 5 (Overload-byref1 o x)))
|
||||
(check (=~ 6 (Overload-byref1 o #nil)))
|
||||
|
||||
(check (=~ 7 (Overload-byref2 o #nil)))
|
||||
(check (=~ 8 (Overload-byref2 o x)))
|
||||
|
||||
(check (=~ 9 (Overload-byconstref1 o x)))
|
||||
(check (=~ 10 (Overload-byconstref1 o #nil)))
|
||||
|
||||
(check (=~ 11 (Overload-byconstref2 o #nil)))
|
||||
(check (=~ 12 (Overload-byconstref2 o x)))
|
||||
|
||||
; const pointer references
|
||||
; No SWIGTYPE *const& typemaps for Guile yet
|
||||
;(check (=~ 13 (Overload-byval1cpr o x)))
|
||||
;(check (=~ 14 (Overload-byval1cpr o #nil)))
|
||||
|
||||
;(check (=~ 15 (Overload-byval2cpr o #nil)))
|
||||
;(check (=~ 16 (Overload-byval2cpr o x)))
|
||||
|
||||
; forward class declaration
|
||||
(check (=~ 17 (Overload-byval1forwardptr o x)))
|
||||
(check (=~ 18 (Overload-byval1forwardptr o #nil)))
|
||||
|
||||
(check (=~ 19 (Overload-byval2forwardptr o #nil)))
|
||||
(check (=~ 20 (Overload-byval2forwardptr o x)))
|
||||
|
||||
(check (=~ 21 (Overload-byval1forwardref o x)))
|
||||
|
||||
(check (=~ 22 (Overload-byval2forwardref o x)))
|
||||
|
||||
(exit 0)
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
#define SWIGGUILE_SCM
|
||||
|
||||
%runtime "swigrun.swg" // Common C API type-checking code
|
||||
%runtime "swigerrors.swg" // SWIG errors
|
||||
|
||||
%runtime "guile_scm_run.swg"
|
||||
%include <guile.i>
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
|
|||
|
||||
if (SCM_NULLP(smob)) {
|
||||
*result = NULL;
|
||||
return SWIG_OK;
|
||||
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
|
||||
#if SCM_MAJOR_VERSION >= 2
|
||||
} else if (SCM_POINTER_P(s)) {
|
||||
*result = SCM_POINTER_VALUE(s);
|
||||
|
|
|
|||
|
|
@ -444,15 +444,21 @@ typedef unsigned long SCM;
|
|||
$1 = scm_is_string($input) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] {
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE [] {
|
||||
void *ptr;
|
||||
int res = SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0);
|
||||
$1 = SWIG_CheckState(res);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE &, SWIGTYPE && {
|
||||
void *ptr;
|
||||
int res = SWIG_ConvertPtr($input, &ptr, $1_descriptor, SWIG_POINTER_NO_NULL);
|
||||
$1 = SWIG_CheckState(res);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
|
||||
void *ptr;
|
||||
int res = SWIG_ConvertPtr($input, &ptr, $&descriptor, 0);
|
||||
int res = SWIG_ConvertPtr($input, &ptr, $&descriptor, SWIG_POINTER_NO_NULL);
|
||||
$1 = SWIG_CheckState(res);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue