From 4abfe06b51e36338033259710a353ad541d2b188 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Mon, 28 Sep 2009 08:48:39 -0500 Subject: [PATCH] Fixing various test failures caused by C type parser change, and clarify C type docs some more --- basis/alien/c-types/c-types-docs.factor | 59 ++++++++++++++++--- basis/classes/struct/struct-docs.factor | 2 +- basis/compiler/tests/alien.factor | 2 +- basis/cpu/x86/x86.factor | 2 +- .../specialization-tests.factor | 8 ++- basis/math/vectors/vectors-docs.factor | 4 +- basis/math/vectors/vectors-tests.factor | 2 +- basis/pango/layouts/layouts-tests.factor | 2 +- basis/sequences/complex/complex-docs.factor | 4 +- basis/serialize/serialize-tests.factor | 2 +- .../specialized-arrays-tests.factor | 2 +- .../specialized-vectors-tests.factor | 2 +- basis/unix/linux/linux.factor | 2 +- core/alien/alien-docs.factor | 3 +- core/assocs/assocs-tests.factor | 2 +- extra/id3/id3.factor | 3 +- extra/jamshred/tunnel/tunnel-tests.factor | 3 +- 17 files changed, 75 insertions(+), 29 deletions(-) diff --git a/basis/alien/c-types/c-types-docs.factor b/basis/alien/c-types/c-types-docs.factor index eb4be08764..ea5016e563 100755 --- a/basis/alien/c-types/c-types-docs.factor +++ b/basis/alien/c-types/c-types-docs.factor @@ -3,6 +3,7 @@ byte-arrays strings hashtables alien.syntax alien.strings sequences io.encodings.string debugger destructors vocabs.loader classes.struct ; QUALIFIED: math +QUALIFIED: sequences IN: alien.c-types HELP: byte-length @@ -164,10 +165,8 @@ $nl { $subsection *void* } "Note that while structure and union types do not get these words defined for them, there is no loss of generality since " { $link } " and " { $link *void* } " may be used." ; -ARTICLE: "c-types-specs" "C type specifiers" -"C types are identified by special words, and type names occur as parameters to the " { $link alien-invoke } ", " { $link alien-indirect } " and " { $link alien-callback } " words. New C types can be defined by the words " { $link POSTPONE: STRUCT: } ", " { $link POSTPONE: UNION-STRUCT: } ", " { $link POSTPONE: CALLBACK: } ", and " { $link POSTPONE: TYPEDEF: } "." -$nl -"The following numerical types are available; a " { $snippet "u" } " prefix denotes an unsigned type:" +ARTICLE: "c-types.primitives" "Primitive C types" +"The following numerical types are defined in the " { $vocab-link "alien.c-types" } " vocabulary; a " { $snippet "u" } " prefix denotes an unsigned type:" { $table { "C type" "Notes" } { { $link char } "always 1 byte" } @@ -182,15 +181,57 @@ $nl { { $link ulonglong } { } } { { $link float } { "single-precision float (not the same as Factor's " { $link math:float } " class!)" } } { { $link double } { "double-precision float (the same format as Factor's " { $link math:float } " objects)" } } +} +"The following C99 complex number types are defined in the " { $vocab-link "alien.complex" } " vocabulary:" +{ $table { { $link complex-float } { "C99 or Fortran " { $snippet "complex float" } " type, converted to and from Factor " { $link math:complex } " values" } } { { $link complex-double } { "C99 or Fortran " { $snippet "complex double" } " type, converted to and from Factor " { $link math:complex } " values" } } } -"When making alien calls, Factor numbers are converted to and from the above types in a canonical way. Converting a Factor number to a C value may result in a loss of precision." -$nl +"When making alien calls, Factor numbers are converted to and from the above types in a canonical way. Converting a Factor number to a C value may result in a loss of precision." ; + +ARTICLE: "c-types.pointers" "Pointer and array types" "Pointer types are specified by suffixing a C type with " { $snippet "*" } ", for example " { $snippet "float*" } ". One special case is " { $link void* } ", which denotes a generic pointer; " { $link void } " by itself is not a valid C type specifier. With the exception of strings (see " { $link "c-strings" } "), all pointer types are identical to " { $snippet "void*" } " as far as the C library interface is concerned." $nl "Fixed-size array types are supported; the syntax consists of a C type name followed by dimension sizes in brackets; the following denotes a 3 by 4 array of integers:" { $code "int[3][4]" } -"Fixed-size arrays differ from pointers in that they are allocated inside structures and unions; however when used as function parameters they behave exactly like pointers and thus the dimensions only serve as documentation." -$nl -"Structure and union types are specified by the name of the structure or union." ; +"Fixed-size arrays differ from pointers in that they are allocated inside structures and unions; however when used as function parameters they behave exactly like pointers and thus the dimensions only serve as documentation." ; + +ARTICLE: "c-types.ambiguity" "Word name clashes with C types" +"Note that some of the C type word names clash with commonly-used Factor words:" +{ $list + { { $link short } " clashes with the " { $link sequences:short } " word in the " { $vocab-link "sequences" } " vocabulary" } + { { $link float } " clashes with the " { $link math:float } " word in the " { $vocab-link "math" } " vocabulary" } +} +"If you use the wrong vocabulary, you will see a " { $link no-c-type } " error. For example, the following is " { $strong "not" } " valid, and will raise an error because the " { $link math:float } " word from the " { $vocab-link "math" } " vocabulary is not a C type:" +{ $code + "USING: alien.syntax math prettyprint ;" + "FUNCTION: float magic_number ( ) ;" + "magic_number 3.0 + ." +} +"The following won't work either; now the problem is that there are two vocabularies in the search path that define a word named " { $snippet "float" } ":" +{ $code + "USING: alien.c-types alien.syntax math prettyprint ;" + "FUNCTION: float magic_number ( ) ;" + "magic_number 3.0 + ." +} +"The correct solution is to use one of " { $link POSTPONE: FROM: } ", " { $link POSTPONE: QUALIFIED: } " or " { $link POSTPONE: QUALIFIED-WITH: } " to disambiguate word lookup:" +{ $code + "USING: alien.syntax math prettyprint ;" + "QUALIFIED-WITH: alien.c-types c" + "FUNCTION: c:float magic_number ( ) ;" + "magic_number 3.0 + ." +} +"See " { $link "word-search-semantics" } " for details." ; + +ARTICLE: "c-types.structs" "Struct and union types" +"Struct and union types are identified by their class word. See " { $link "classes.struct" } "." ; + +ARTICLE: "c-types-specs" "C type specifiers" +"C types are identified by special words, and type names occur as parameters to the " { $link alien-invoke } ", " { $link alien-indirect } " and " { $link alien-callback } " words. New C types can be defined by the words " { $link POSTPONE: STRUCT: } ", " { $link POSTPONE: UNION-STRUCT: } ", " { $link POSTPONE: CALLBACK: } ", and " { $link POSTPONE: TYPEDEF: } "." +{ $subsection "c-types.primitives" } +{ $subsection "c-types.pointers" } +{ $subsection "c-types.ambiguity" } +{ $subsection "c-types.structs" } +; + +ABOUT: "c-types-specs" diff --git a/basis/classes/struct/struct-docs.factor b/basis/classes/struct/struct-docs.factor index a38bd3c588..5eff4c077e 100644 --- a/basis/classes/struct/struct-docs.factor +++ b/basis/classes/struct/struct-docs.factor @@ -163,7 +163,7 @@ $nl } ; ARTICLE: "classes.struct" "Struct classes" -{ $link struct } " classes are similar to " { $link tuple } "s, but their slots exhibit value semantics, and they are backed by a contiguous structured block of memory. Structs can be used for structured access to C memory or Factor byte arrays and for passing struct values in and out of the FFI." +"The " { $vocab-link "classes.struct" } " vocabulary implements " { $link struct } " classes. They are similar to " { $link tuple } " classes, but their slots exhibit value semantics, and they are backed by a contiguous structured block of memory. Structs can be used for space-efficient storage of data in the Factor heap, as well as for passing data to and from C libraries using the " { $link "alien" } "." { $subsection "classes.struct.examples" } { $subsection "classes.struct.define" } { $subsection "classes.struct.create" } diff --git a/basis/compiler/tests/alien.factor b/basis/compiler/tests/alien.factor index 9d3a66df5b..eaa8be72f0 100755 --- a/basis/compiler/tests/alien.factor +++ b/basis/compiler/tests/alien.factor @@ -4,7 +4,7 @@ compiler continuations effects io io.backend io.pathnames io.streams.string kernel math memory namespaces namespaces.private parser quotations sequences specialized-arrays stack-checker stack-checker.errors -system threads tools.test words ; +system threads tools.test words alien.complex ; FROM: alien.c-types => float short ; SPECIALIZED-ARRAY: float SPECIALIZED-ARRAY: char diff --git a/basis/cpu/x86/x86.factor b/basis/cpu/x86/x86.factor index 63356aa5bb..a4597dc861 100644 --- a/basis/cpu/x86/x86.factor +++ b/basis/cpu/x86/x86.factor @@ -101,7 +101,7 @@ M: x86 %set-slot ( src obj slot -- ) [+] swap MOV ; M: x86 %set-slot-imm ( src obj slot tag -- ) (%slot-imm) swap MOV ; :: two-operand ( dst src1 src2 rep -- dst src ) - dst src2 eq? [ "Cannot handle this case" throw ] when + dst src2 eq? dst src1 eq? not and [ "Cannot handle this case" throw ] when dst src1 rep %copy dst src2 ; inline diff --git a/basis/math/vectors/specialization/specialization-tests.factor b/basis/math/vectors/specialization/specialization-tests.factor index 649685b898..f4d4fd93e8 100644 --- a/basis/math/vectors/specialization/specialization-tests.factor +++ b/basis/math/vectors/specialization/specialization-tests.factor @@ -1,9 +1,11 @@ IN: math.vectors.specialization.tests USING: compiler.tree.debugger math.vectors tools.test kernel kernel.private math specialized-arrays ; -SPECIALIZED-ARRAY: double -SPECIALIZED-ARRAY: complex-float -SPECIALIZED-ARRAY: float +QUALIFIED-WITH: alien.c-types c +QUALIFIED-WITH: alien.complex c +SPECIALIZED-ARRAY: c:double +SPECIALIZED-ARRAY: c:complex-float +SPECIALIZED-ARRAY: c:float [ V{ t } ] [ [ { double-array double-array } declare distance 0.0 < not ] final-literals diff --git a/basis/math/vectors/vectors-docs.factor b/basis/math/vectors/vectors-docs.factor index 32c354354f..34b2c0bec6 100644 --- a/basis/math/vectors/vectors-docs.factor +++ b/basis/math/vectors/vectors-docs.factor @@ -171,14 +171,14 @@ HELP: vs+ { $examples "With saturation:" { $example - "USING: math.vectors prettyprint specialized-arrays ;" + "USING: alien.c-types math.vectors prettyprint specialized-arrays ;" "SPECIALIZED-ARRAY: uchar" "uchar-array{ 100 200 150 } uchar-array{ 70 70 70 } vs+ ." "uchar-array{ 170 255 220 }" } "Without saturation:" { $example - "USING: math.vectors prettyprint specialized-arrays ;" + "USING: alien.c-types math.vectors prettyprint specialized-arrays ;" "SPECIALIZED-ARRAY: uchar" "uchar-array{ 100 200 150 } uchar-array{ 70 70 70 } v+ ." "uchar-array{ 170 14 220 }" diff --git a/basis/math/vectors/vectors-tests.factor b/basis/math/vectors/vectors-tests.factor index 91c5c0326f..54ffc92481 100644 --- a/basis/math/vectors/vectors-tests.factor +++ b/basis/math/vectors/vectors-tests.factor @@ -1,6 +1,6 @@ IN: math.vectors.tests USING: math.vectors tools.test kernel specialized-arrays compiler -kernel.private ; +kernel.private alien.c-types ; SPECIALIZED-ARRAY: int [ { 1 2 3 } ] [ 1/2 { 2 4 6 } n*v ] unit-test diff --git a/basis/pango/layouts/layouts-tests.factor b/basis/pango/layouts/layouts-tests.factor index 5959eddb07..a4a83f79a8 100644 --- a/basis/pango/layouts/layouts-tests.factor +++ b/basis/pango/layouts/layouts-tests.factor @@ -1,5 +1,5 @@ IN: pango.layouts.tests -USING: pango.layouts tools.test glib fonts accessors +USING: pango.layouts pango.cairo tools.test glib fonts accessors sequences combinators.short-circuit math destructors ; [ t ] [ diff --git a/basis/sequences/complex/complex-docs.factor b/basis/sequences/complex/complex-docs.factor index a2f508648d..c2fd27ec5d 100644 --- a/basis/sequences/complex/complex-docs.factor +++ b/basis/sequences/complex/complex-docs.factor @@ -12,7 +12,7 @@ ABOUT: "sequences.complex" HELP: complex-sequence { $class-description "Sequence wrapper class that transforms a sequence of " { $link real } " number values into a sequence of " { $link complex } " values, treating the underlying sequence as pairs of alternating real and imaginary values." } { $examples { $example """USING: prettyprint specialized-arrays -sequences.complex sequences arrays ; +sequences.complex sequences alien.c-types arrays ; SPECIALIZED-ARRAY: double double-array{ 1.0 -1.0 -2.0 2.0 3.0 0.0 } >array .""" "{ C{ 1.0 -1.0 } C{ -2.0 2.0 } C{ 3.0 0.0 } }" } } ; @@ -21,7 +21,7 @@ HELP: { $values { "sequence" sequence } { "complex-sequence" complex-sequence } } { $description "Wraps " { $snippet "sequence" } " in a " { $link complex-sequence } "." } { $examples { $example """USING: prettyprint specialized-arrays -sequences.complex sequences arrays ; +sequences.complex sequences alien.c-types arrays ; SPECIALIZED-ARRAY: double double-array{ 1.0 -1.0 -2.0 2.0 3.0 0.0 } second .""" "C{ -2.0 2.0 }" } } ; diff --git a/basis/serialize/serialize-tests.factor b/basis/serialize/serialize-tests.factor index 99c8adefb6..cebf69595f 100644 --- a/basis/serialize/serialize-tests.factor +++ b/basis/serialize/serialize-tests.factor @@ -4,7 +4,7 @@ USING: tools.test kernel serialize io io.streams.byte-array alien arrays byte-arrays bit-arrays specialized-arrays sequences math prettyprint parser classes math.constants -io.encodings.binary random assocs serialize.private ; +io.encodings.binary random assocs serialize.private alien.c-types ; SPECIALIZED-ARRAY: double IN: serialize.tests diff --git a/basis/specialized-arrays/specialized-arrays-tests.factor b/basis/specialized-arrays/specialized-arrays-tests.factor index 070323a5d6..b7d3371f45 100755 --- a/basis/specialized-arrays/specialized-arrays-tests.factor +++ b/basis/specialized-arrays/specialized-arrays-tests.factor @@ -138,7 +138,7 @@ SPECIALIZED-ARRAY: __does_not_exist__ """ eval( -- ) [ ] [ """ IN: specialized-arrays.tests -USING: classes.struct specialized-arrays ; +USING: alien.c-types classes.struct specialized-arrays ; STRUCT: __does_not_exist__ { x int } ; diff --git a/basis/specialized-vectors/specialized-vectors-tests.factor b/basis/specialized-vectors/specialized-vectors-tests.factor index edff828b13..c7a045a7e1 100644 --- a/basis/specialized-vectors/specialized-vectors-tests.factor +++ b/basis/specialized-vectors/specialized-vectors-tests.factor @@ -1,6 +1,6 @@ IN: specialized-vectors.tests USING: specialized-arrays specialized-vectors -tools.test kernel sequences ; +tools.test kernel sequences alien.c-types ; SPECIALIZED-ARRAY: float SPECIALIZED-VECTOR: float SPECIALIZED-VECTOR: double diff --git a/basis/unix/linux/linux.factor b/basis/unix/linux/linux.factor index 4035dbb307..93bf621acd 100644 --- a/basis/unix/linux/linux.factor +++ b/basis/unix/linux/linux.factor @@ -61,7 +61,7 @@ CONSTANT: max-un-path 108 STRUCT: sockaddr-un { family ushort } - { path { "char" max-un-path } } ; + { path { char max-un-path } } ; CONSTANT: SOCK_STREAM 1 CONSTANT: SOCK_DGRAM 2 diff --git a/core/alien/alien-docs.factor b/core/alien/alien-docs.factor index 7bbd8542e5..70ce13b0e6 100644 --- a/core/alien/alien-docs.factor +++ b/core/alien/alien-docs.factor @@ -258,12 +258,13 @@ ARTICLE: "alien" "C library interface" $nl "The C library interface is entirely self-contained; there is no C code which one must write in order to wrap a library." $nl -"C library interface words are found in the " { $vocab-link "alien" } " vocabulary." +"C library interface words are found in the " { $vocab-link "alien" } " vocabulary and its subvocabularies." { $warning "C does not perform runtime type checking, automatic memory management or array bounds checks. Incorrect usage of C library functions can lead to crashes, data corruption, and security exploits." } { $subsection "loading-libs" } { $subsection "alien-invoke" } { $subsection "alien-callback" } { $subsection "c-data" } +{ $subsection "classes.struct" } { $subsection "dll.private" } { $subsection "embedding" } ; diff --git a/core/assocs/assocs-tests.factor b/core/assocs/assocs-tests.factor index 78c17a1cc0..53c3adcf3e 100644 --- a/core/assocs/assocs-tests.factor +++ b/core/assocs/assocs-tests.factor @@ -1,6 +1,6 @@ USING: kernel math namespaces make tools.test vectors sequences sequences.private hashtables io prettyprint assocs -continuations specialized-arrays ; +continuations specialized-arrays alien.c-types ; SPECIALIZED-ARRAY: double IN: assocs.tests diff --git a/extra/id3/id3.factor b/extra/id3/id3.factor index 22474a7526..6a14280e6e 100644 --- a/extra/id3/id3.factor +++ b/extra/id3/id3.factor @@ -7,6 +7,7 @@ io.encodings.utf16 assocs math.parser combinators.short-circuit fry namespaces combinators.smart splitting io.encodings.ascii arrays io.files.info unicode.case io.directories.search literals math.functions continuations ; +FROM: alien.c-types => uchar ; IN: id3 : mp3>id3 ( path -- id3/f ) [ - [ ] dip "uchar" + [ ] dip uchar [ dup id3v1? [ read-v1-tags merge-id3v1 ] [ drop ] if ] [ dup id3v1+? [ read-v1+-tags merge-id3v1 ] [ drop ] if ] [ dup id3v2? [ read-v2-tags ] [ drop ] if ] diff --git a/extra/jamshred/tunnel/tunnel-tests.factor b/extra/jamshred/tunnel/tunnel-tests.factor index 6f85389099..e2e1c20122 100644 --- a/extra/jamshred/tunnel/tunnel-tests.factor +++ b/extra/jamshred/tunnel/tunnel-tests.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2007, 2008 Alex Chapman ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays jamshred.oint jamshred.tunnel kernel -math.vectors sequences specialized-arrays tools.test ; +math.vectors sequences specialized-arrays tools.test +alien.c-types ; SPECIALIZED-ARRAY: float IN: jamshred.tunnel.tests -- 2.34.1