deprecate <c-array>, and make malloc-array box its returned buffer in a direct array
parent
d26735c98f
commit
8a9d0e13bb
|
@ -49,12 +49,11 @@ HELP: c-setter
|
||||||
{ $errors "Throws an error if the type does not exist." } ;
|
{ $errors "Throws an error if the type does not exist." } ;
|
||||||
|
|
||||||
HELP: <c-array>
|
HELP: <c-array>
|
||||||
|
{ $deprecated "New code should use " { $link <c-type-array> } " or the " { $vocab-link "specialized-arrays" } " vocabularies." }
|
||||||
{ $values { "n" "a non-negative integer" } { "type" "a C type" } { "array" byte-array } }
|
{ $values { "n" "a non-negative integer" } { "type" "a C type" } { "array" byte-array } }
|
||||||
{ $description "Creates a byte array large enough to hold " { $snippet "n" } " values of a C type." }
|
{ $description "Creates a byte array large enough to hold " { $snippet "n" } " values of a C type." }
|
||||||
{ $errors "Throws an error if the type does not exist or the requested size is negative." } ;
|
{ $errors "Throws an error if the type does not exist or the requested size is negative." } ;
|
||||||
|
|
||||||
{ <c-array> malloc-array } related-words
|
|
||||||
|
|
||||||
HELP: <c-object>
|
HELP: <c-object>
|
||||||
{ $values { "type" "a C type" } { "array" byte-array } }
|
{ $values { "type" "a C type" } { "array" byte-array } }
|
||||||
{ $description "Creates a byte array suitable for holding a value with the given C type." }
|
{ $description "Creates a byte array suitable for holding a value with the given C type." }
|
||||||
|
@ -73,9 +72,10 @@ HELP: byte-array>memory
|
||||||
|
|
||||||
HELP: malloc-array
|
HELP: malloc-array
|
||||||
{ $values { "n" "a non-negative integer" } { "type" "a C type" } { "alien" alien } }
|
{ $values { "n" "a non-negative integer" } { "type" "a C type" } { "alien" alien } }
|
||||||
{ $description "Allocates an unmanaged memory block large enough to hold " { $snippet "n" } " values of a C type." }
|
{ $description "Allocates an unmanaged memory block large enough to hold " { $snippet "n" } " values of a C type, then wraps the memory in a sequence object using " { $link <c-type-direct-array> } "." }
|
||||||
|
{ $notes "The appropriate direct specialized array vocabulary must be loaded; otherwise, a " { $link specialized-array-vocab-not-loaded } " error will be thrown. The vocabulary can be loaded with a " { $link POSTPONE: USING: } " form as usual, or with the " { $link require-c-type-arrays } " word. See the " { $vocab-link "specialized-arrays.direct" } " vocabulary set for details on the underlying sequence type constructed." } ;
|
||||||
{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
|
{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
|
||||||
{ $errors "Throws an error if the type does not exist, if the requested size is negative, or if memory allocation fails." } ;
|
{ $errors "Throws an error if the type does not exist, if the requested size is negative, if a direct specialized array class appropriate to the type is not loaded, or if memory allocation fails." } ;
|
||||||
|
|
||||||
HELP: malloc-object
|
HELP: malloc-object
|
||||||
{ $values { "type" "a C type" } { "alien" alien } }
|
{ $values { "type" "a C type" } { "alien" alien } }
|
||||||
|
@ -89,6 +89,8 @@ HELP: malloc-byte-array
|
||||||
{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
|
{ $warning "Don't forget to deallocate the memory with a call to " { $link free } "." }
|
||||||
{ $errors "Throws an error if memory allocation fails." } ;
|
{ $errors "Throws an error if memory allocation fails." } ;
|
||||||
|
|
||||||
|
{ <c-type-array> <c-type-direct-array> malloc-array } related-words
|
||||||
|
|
||||||
HELP: box-parameter
|
HELP: box-parameter
|
||||||
{ $values { "n" integer } { "ctype" string } }
|
{ $values { "n" integer } { "ctype" string } }
|
||||||
{ $description "Generates code for converting a C value stored at offset " { $snippet "n" } " from the top of the stack into a Factor object to be pushed on the data stack." }
|
{ $description "Generates code for converting a C value stored at offset " { $snippet "n" } " from the top of the stack into a Factor object to be pushed on the data stack." }
|
||||||
|
|
|
@ -254,13 +254,13 @@ M: f byte-length drop 0 ; inline
|
||||||
] unless* ;
|
] unless* ;
|
||||||
|
|
||||||
: <c-array> ( n type -- array )
|
: <c-array> ( n type -- array )
|
||||||
heap-size * <byte-array> ; inline
|
heap-size * <byte-array> ; inline deprecated
|
||||||
|
|
||||||
: <c-object> ( type -- array )
|
: <c-object> ( type -- array )
|
||||||
1 swap <c-array> ; inline
|
1 swap <c-array> ; inline
|
||||||
|
|
||||||
: malloc-array ( n type -- alien )
|
: malloc-array ( n type -- alien )
|
||||||
heap-size calloc ; inline
|
[ heap-size calloc ] [ <c-type-direct-array> ] 2bi ; inline
|
||||||
|
|
||||||
: malloc-object ( type -- alien )
|
: malloc-object ( type -- alien )
|
||||||
1 swap malloc-array ; inline
|
1 swap malloc-array ; inline
|
||||||
|
|
|
@ -13,6 +13,9 @@ M: bad-byte-array-length summary
|
||||||
: (c-array) ( n c-type -- array )
|
: (c-array) ( n c-type -- array )
|
||||||
heap-size * (byte-array) ; inline
|
heap-size * (byte-array) ; inline
|
||||||
|
|
||||||
|
: <c-array> ( n type -- array )
|
||||||
|
heap-size * <byte-array> ; inline
|
||||||
|
|
||||||
FUNCTOR: define-array ( T -- )
|
FUNCTOR: define-array ( T -- )
|
||||||
|
|
||||||
A DEFINES-CLASS ${T}-array
|
A DEFINES-CLASS ${T}-array
|
||||||
|
|
Loading…
Reference in New Issue