Add Guile support for std::unique_ptr and std::auto_ptr
Equivalent to Python/Ruby implementations.
This commit is contained in:
parent
3a0721bfbc
commit
23ce0655a6
10 changed files with 248 additions and 7 deletions
|
|
@ -1,6 +1,6 @@
|
|||
%module cpp11_std_unique_ptr
|
||||
|
||||
#if !(defined(SWIGGO) || defined(SWIGGUILE) || defined(SWIGOCAML) || defined(SWIGMZSCHEME) || defined(SWIGR) || defined(SWIGSCILAB))
|
||||
#if !(defined(SWIGGO) || defined(SWIGOCAML) || defined(SWIGMZSCHEME) || defined(SWIGR) || defined(SWIGSCILAB))
|
||||
|
||||
%include "std_string.i"
|
||||
%include "std_unique_ptr.i"
|
||||
|
|
|
|||
3
Examples/test-suite/guile/cpp11_std_unique_ptr_runme.scm
Normal file
3
Examples/test-suite/guile/cpp11_std_unique_ptr_runme.scm
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(dynamic-call "scm_init_cpp11_std_unique_ptr_module" (dynamic-link "./libcpp11_std_unique_ptr"))
|
||||
(load "testsuite.scm")
|
||||
(load "../schemerunme/cpp11_std_unique_ptr.scm")
|
||||
3
Examples/test-suite/guile/li_std_auto_ptr_runme.scm
Normal file
3
Examples/test-suite/guile/li_std_auto_ptr_runme.scm
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(dynamic-call "scm_init_li_std_auto_ptr_module" (dynamic-link "./libli_std_auto_ptr"))
|
||||
(load "testsuite.scm")
|
||||
(load "../schemerunme/li_std_auto_ptr.scm")
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
#endif
|
||||
%}
|
||||
|
||||
#if !(defined(SWIGGO) || defined(SWIGGUILE) || defined(SWIGOCAML) || defined(SWIGMZSCHEME) || defined(SWIGR) || defined(SWIGSCILAB))
|
||||
#if !(defined(SWIGGO) || defined(SWIGOCAML) || defined(SWIGMZSCHEME) || defined(SWIGR) || defined(SWIGSCILAB))
|
||||
|
||||
%include "std_string.i"
|
||||
//#include <iostream>
|
||||
|
|
|
|||
75
Examples/test-suite/schemerunme/cpp11_std_unique_ptr.scm
Normal file
75
Examples/test-suite/schemerunme/cpp11_std_unique_ptr.scm
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
(define checkCount
|
||||
(lambda (expected-count)
|
||||
(define actual-count (Klass-getTotal-count))
|
||||
(if (not (= actual-count expected-count)) (error "Counts incorrect, expected:" expected-count " actual:" actual-count))))
|
||||
|
||||
; Test raw pointer handling involving virtual inheritance
|
||||
(define kini (new-KlassInheritance "KlassInheritanceInput"))
|
||||
(checkCount 1)
|
||||
(define s (useKlassRawPtr kini))
|
||||
(if (not (string=? s "KlassInheritanceInput"))
|
||||
(error "Incorrect string: " s))
|
||||
(delete-Klass kini)
|
||||
(checkCount 0)
|
||||
|
||||
; unique_ptr as input
|
||||
(define kin (new-Klass "KlassInput"))
|
||||
(checkCount 1)
|
||||
(define s (takeKlassUniquePtr kin))
|
||||
(checkCount 0)
|
||||
(if (not (string=? s "KlassInput"))
|
||||
(error "Incorrect string: " s))
|
||||
(if (not (is-nullptr kin))
|
||||
(error "is_nullptr failed"))
|
||||
(delete-Klass kin) ; Should not fail, even though already deleted
|
||||
(checkCount 0)
|
||||
|
||||
(define kin (new-Klass "KlassInput"))
|
||||
(checkCount 1)
|
||||
(define s (takeKlassUniquePtr kin))
|
||||
(checkCount 0)
|
||||
(if (not (string=? s "KlassInput"))
|
||||
(error "Incorrect string: " s))
|
||||
(if (not (is-nullptr kin))
|
||||
(error "is_nullptr failed"))
|
||||
(expect-throw 'misc-error
|
||||
(takeKlassUniquePtr kin))
|
||||
; TODO: check the exception message
|
||||
(delete-Klass kin) ; Should not fail, even though already deleted
|
||||
(checkCount 0)
|
||||
|
||||
(define kin (new-Klass "KlassInput"))
|
||||
(define notowned (get-not-owned-ptr kin))
|
||||
(expect-throw 'misc-error
|
||||
(takeKlassUniquePtr notowned))
|
||||
; TODO: check the exception message
|
||||
(checkCount 1)
|
||||
(delete-Klass kin)
|
||||
(checkCount 0)
|
||||
|
||||
(define kini (new-KlassInheritance "KlassInheritanceInput"))
|
||||
(checkCount 1)
|
||||
(define s (takeKlassUniquePtr kini))
|
||||
(checkCount 0)
|
||||
(if (not (string=? s "KlassInheritanceInput"))
|
||||
(error "Incorrect string: " s))
|
||||
(if (not (is-nullptr kini))
|
||||
(error "is_nullptr failed"))
|
||||
(delete-Klass kini) ; Should not fail, even though already deleted
|
||||
(checkCount 0)
|
||||
|
||||
; unique_ptr as output
|
||||
(define k1 (makeKlassUniquePtr "first"))
|
||||
(define k2 (makeKlassUniquePtr "second"))
|
||||
(checkCount 2)
|
||||
|
||||
(delete-Klass k1)
|
||||
(checkCount 1)
|
||||
|
||||
(if (not (string=? (Klass-getLabel k2) "second"))
|
||||
(error "wrong object label" ))
|
||||
|
||||
(delete-Klass k2)
|
||||
(checkCount 0)
|
||||
|
||||
(exit 0)
|
||||
75
Examples/test-suite/schemerunme/li_std_auto_ptr.scm
Normal file
75
Examples/test-suite/schemerunme/li_std_auto_ptr.scm
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
(define checkCount
|
||||
(lambda (expected-count)
|
||||
(define actual-count (Klass-getTotal-count))
|
||||
(if (not (= actual-count expected-count)) (error "Counts incorrect, expected:" expected-count " actual:" actual-count))))
|
||||
|
||||
; Test raw pointer handling involving virtual inheritance
|
||||
(define kini (new-KlassInheritance "KlassInheritanceInput"))
|
||||
(checkCount 1)
|
||||
(define s (useKlassRawPtr kini))
|
||||
(if (not (string=? s "KlassInheritanceInput"))
|
||||
(error "Incorrect string: " s))
|
||||
(delete-Klass kini)
|
||||
(checkCount 0)
|
||||
|
||||
; auto_ptr as input
|
||||
(define kin (new-Klass "KlassInput"))
|
||||
(checkCount 1)
|
||||
(define s (takeKlassAutoPtr kin))
|
||||
(checkCount 0)
|
||||
(if (not (string=? s "KlassInput"))
|
||||
(error "Incorrect string: " s))
|
||||
(if (not (is-nullptr kin))
|
||||
(error "is_nullptr failed"))
|
||||
(delete-Klass kin) ; Should not fail, even though already deleted
|
||||
(checkCount 0)
|
||||
|
||||
(define kin (new-Klass "KlassInput"))
|
||||
(checkCount 1)
|
||||
(define s (takeKlassAutoPtr kin))
|
||||
(checkCount 0)
|
||||
(if (not (string=? s "KlassInput"))
|
||||
(error "Incorrect string: " s))
|
||||
(if (not (is-nullptr kin))
|
||||
(error "is_nullptr failed"))
|
||||
(expect-throw 'misc-error
|
||||
(takeKlassAutoPtr kin))
|
||||
; TODO: check the exception message
|
||||
(delete-Klass kin) ; Should not fail, even though already deleted
|
||||
(checkCount 0)
|
||||
|
||||
(define kin (new-Klass "KlassInput"))
|
||||
(define notowned (get-not-owned-ptr kin))
|
||||
(expect-throw 'misc-error
|
||||
(takeKlassAutoPtr notowned))
|
||||
; TODO: check the exception message
|
||||
(checkCount 1)
|
||||
(delete-Klass kin)
|
||||
(checkCount 0)
|
||||
|
||||
(define kini (new-KlassInheritance "KlassInheritanceInput"))
|
||||
(checkCount 1)
|
||||
(define s (takeKlassAutoPtr kini))
|
||||
(checkCount 0)
|
||||
(if (not (string=? s "KlassInheritanceInput"))
|
||||
(error "Incorrect string: " s))
|
||||
(if (not (is-nullptr kini))
|
||||
(error "is_nullptr failed"))
|
||||
(delete-Klass kini) ; Should not fail, even though already deleted
|
||||
(checkCount 0)
|
||||
|
||||
; auto_ptr as output
|
||||
(define k1 (makeKlassAutoPtr "first"))
|
||||
(define k2 (makeKlassAutoPtr "second"))
|
||||
(checkCount 2)
|
||||
|
||||
(delete-Klass k1)
|
||||
(checkCount 1)
|
||||
|
||||
(if (not (string=? (Klass-getLabel k2) "second"))
|
||||
(error "wrong object label" ))
|
||||
|
||||
(delete-Klass k2)
|
||||
(checkCount 0)
|
||||
|
||||
(exit 0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue