]> gitweb.factorcode.org Git - factor.git/commitdiff
make classes.struct work with string pointer slots
authorJoe Groff <arcata@gmail.com>
Tue, 25 Aug 2009 18:18:20 +0000 (13:18 -0500)
committerJoe Groff <arcata@gmail.com>
Tue, 25 Aug 2009 18:18:20 +0000 (13:18 -0500)
extra/classes/struct/struct-tests.factor
extra/classes/struct/struct.factor

index 536737d2d038b6809fc371c93c14cf9182d97747..51df207003e7ff89de111fa8fbc9ed0d4d34bfa1 100644 (file)
@@ -1,7 +1,7 @@
 ! (c)Joe Groff bsd license
 USING: accessors alien.c-types alien.libraries
 alien.structs.fields alien.syntax classes.struct combinators
-io.pathnames io.streams.string kernel libc literals math
+destructors io.pathnames io.streams.string kernel libc literals math
 multiline namespaces prettyprint prettyprint.config see system
 tools.test ;
 IN: classes.struct.tests
@@ -54,7 +54,18 @@ UNION-STRUCT: struct-test-float-and-bits
 [ 1.0 ] [ struct-test-float-and-bits <struct> 1.0 float>bits >>bits f>> ] unit-test
 [ 4 ] [ struct-test-float-and-bits heap-size ] unit-test
 
-[ ] [ struct-test-foo malloc-struct free ] unit-test
+[ ] [ [ struct-test-foo malloc-struct &free drop ] with-destructors ] unit-test
+
+STRUCT: struct-test-string-ptr
+    { x char* } ;
+
+[ "hello world" ] [
+    [
+        struct-test-string-ptr <struct>
+        "hello world" utf8 malloc-string &free >>x
+        x>>
+    ] with-destructors
+] unit-test
 
 [ "S{ struct-test-foo { y 7654 } }" ]
 [
index 33e5ba89ae15d152ba2390333ea8c0a99dfe6edc..51df296f1a24ac7d039e8ae4fc568609bbe89ca6 100644 (file)
@@ -204,7 +204,7 @@ M: struct-class heap-size
 ERROR: invalid-struct-slot token ;
 
 : struct-slot-class ( c-type -- class' )
-    c-type boxed-class>>
+    c-type c-type-boxed-class
     dup \ byte-array = [ drop \ c-ptr ] when ;
 
 : parse-struct-slot ( -- slot )