Document (free), move it out of libc.private and mention it in the "c-strings" help article (reported by Blei)
parent
26c4aec91a
commit
2b68f56c89
|
@ -60,6 +60,8 @@ $nl
|
||||||
}
|
}
|
||||||
"You must always free pointers returned by any of the above words when the block of memory is no longer in use:"
|
"You must always free pointers returned by any of the above words when the block of memory is no longer in use:"
|
||||||
{ $subsections free }
|
{ $subsections free }
|
||||||
|
"The above words record memory allocations, to help catch double frees and track down memory leaks with " { $link "tools.destructors" } ". To free memory allocated by a C library, another word can be used:"
|
||||||
|
{ $subsections (free) }
|
||||||
"Utilities for automatically freeing memory in conjunction with " { $link with-destructors } ":"
|
"Utilities for automatically freeing memory in conjunction with " { $link with-destructors } ":"
|
||||||
{ $subsections
|
{ $subsections
|
||||||
&free
|
&free
|
||||||
|
@ -148,9 +150,9 @@ $nl
|
||||||
}
|
}
|
||||||
"The first allocates " { $link byte-array } "s, and the latter allocates manually-managed memory which is not moved by the garbage collector and has to be explicitly freed by calling " { $link free } ". See " { $link "byte-arrays-gc" } " for a discussion of the two approaches."
|
"The first allocates " { $link byte-array } "s, and the latter allocates manually-managed memory which is not moved by the garbage collector and has to be explicitly freed by calling " { $link free } ". See " { $link "byte-arrays-gc" } " for a discussion of the two approaches."
|
||||||
$nl
|
$nl
|
||||||
"The C type " { $link char } { $snippet "*" } " represents a generic pointer to " { $snippet "char" } "; arguments with this type will expect and return " { $link alien } "s, and won't perform any implicit string conversion."
|
"The C type " { $snippet "char*" } " represents a generic pointer to " { $snippet "char" } "; arguments with this type will expect and return " { $link alien } "s, and won't perform any implicit string conversion."
|
||||||
$nl
|
$nl
|
||||||
"A word to read strings from arbitrary addresses:"
|
"A word to read strings from arbitrary addresses:"
|
||||||
{ $subsections alien>string }
|
{ $subsections alien>string }
|
||||||
"For example, if a C function returns a " { $link c-string } " but stipulates that the caller must deallocate the memory afterward, you must define the function as returning " { $snippet "char*" } " and call one of the above words before passing the pointer to " { $link free } "." ;
|
"For example, if a C function returns a " { $link c-string } " but stipulates that the caller must deallocate the memory afterward, you must define the function as returning " { $snippet "char*" } " and call " { $link (free) } " yourself." ;
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,7 @@ classes.struct continuations combinators compiler compiler.alien
|
||||||
core-graphics.types stack-checker kernel math namespaces make
|
core-graphics.types stack-checker kernel math namespaces make
|
||||||
quotations sequences strings words cocoa.runtime cocoa.types io
|
quotations sequences strings words cocoa.runtime cocoa.types io
|
||||||
macros memoize io.encodings.utf8 effects layouts libc
|
macros memoize io.encodings.utf8 effects layouts libc
|
||||||
libc.private lexer init core-foundation fry generalizations
|
lexer init core-foundation fry generalizations specialized-arrays ;
|
||||||
specialized-arrays ;
|
|
||||||
QUALIFIED-WITH: alien.c-types c
|
QUALIFIED-WITH: alien.c-types c
|
||||||
IN: cocoa.messages
|
IN: cocoa.messages
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,10 @@ HELP: free
|
||||||
{ $values { "alien" c-ptr } }
|
{ $values { "alien" c-ptr } }
|
||||||
{ $description "Deallocates a block of memory allocated by " { $link malloc } ", " { $link calloc } " or " { $link realloc } "." } ;
|
{ $description "Deallocates a block of memory allocated by " { $link malloc } ", " { $link calloc } " or " { $link realloc } "." } ;
|
||||||
|
|
||||||
|
HELP: (free)
|
||||||
|
{ $values { "alien" c-ptr } }
|
||||||
|
{ $description "Deallocates a block of memory allocated by an external C library." } ;
|
||||||
|
|
||||||
HELP: &free
|
HELP: &free
|
||||||
{ $values { "alien" c-ptr } }
|
{ $values { "alien" c-ptr } }
|
||||||
{ $description "Marks the block of memory for unconditional deallocation at the end of the current " { $link with-destructors } " scope." } ;
|
{ $description "Marks the block of memory for unconditional deallocation at the end of the current " { $link with-destructors } " scope." } ;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
! Copyright (C) 2004, 2005 Mackenzie Straight
|
! Copyright (C) 2004, 2005 Mackenzie Straight
|
||||||
! Copyright (C) 2007, 2009 Slava Pestov
|
! Copyright (C) 2007, 2010 Slava Pestov
|
||||||
! Copyright (C) 2007, 2008 Doug Coleman
|
! Copyright (C) 2007, 2008 Doug Coleman
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien alien.c-types assocs continuations alien.destructors kernel
|
USING: alien alien.c-types assocs continuations alien.destructors kernel
|
||||||
|
@ -18,8 +18,6 @@ IN: libc
|
||||||
: preserve-errno ( quot -- )
|
: preserve-errno ( quot -- )
|
||||||
errno [ call ] dip set-errno ; inline
|
errno [ call ] dip set-errno ; inline
|
||||||
|
|
||||||
<PRIVATE
|
|
||||||
|
|
||||||
: (malloc) ( size -- alien )
|
: (malloc) ( size -- alien )
|
||||||
void* "libc" "malloc" { ulong } alien-invoke ;
|
void* "libc" "malloc" { ulong } alien-invoke ;
|
||||||
|
|
||||||
|
@ -32,6 +30,8 @@ IN: libc
|
||||||
: (realloc) ( alien size -- newalien )
|
: (realloc) ( alien size -- newalien )
|
||||||
void* "libc" "realloc" { void* ulong } alien-invoke ;
|
void* "libc" "realloc" { void* ulong } alien-invoke ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
! We stick malloc-ptr instances in the global disposables set
|
! We stick malloc-ptr instances in the global disposables set
|
||||||
TUPLE: malloc-ptr value continuation ;
|
TUPLE: malloc-ptr value continuation ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue