]> gitweb.factorcode.org Git - factor.git/commitdiff
Document (free), move it out of libc.private and mention it in the "c-strings" help...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 30 Mar 2010 21:31:41 +0000 (17:31 -0400)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 30 Mar 2010 21:32:51 +0000 (17:32 -0400)
basis/alien/data/data-docs.factor
basis/cocoa/messages/messages.factor
basis/libc/libc-docs.factor
basis/libc/libc.factor

index 4600ea68371406961468afc9be8a664fe2115c2b..d36a4d5fd2b2840efb84eb27b87b4a5badd60d33 100644 (file)
@@ -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:"
 { $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 } ":"
 { $subsections
     &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."
 $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
 "A word to read strings from arbitrary addresses:"
 { $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." ;
 
index a74408703711c7e8f3ed70d9f73dfc3089c303a9..c422d85423eb39c3dafb5f2cd9a1435649ddddcd 100644 (file)
@@ -5,8 +5,7 @@ classes.struct continuations combinators compiler compiler.alien
 core-graphics.types stack-checker kernel math namespaces make
 quotations sequences strings words cocoa.runtime cocoa.types io
 macros memoize io.encodings.utf8 effects layouts libc
-libc.private lexer init core-foundation fry generalizations
-specialized-arrays ;
+lexer init core-foundation fry generalizations specialized-arrays ;
 QUALIFIED-WITH: alien.c-types c
 IN: cocoa.messages
 
index b89f4174bfa3776a4a8e7c8fbcee053f062c04db..74e96b08d3c82ef7481ef99afdba657f04dbe31e 100644 (file)
@@ -32,6 +32,10 @@ HELP: free
 { $values { "alien" c-ptr } }
 { $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
 { $values { "alien" c-ptr } }
 { $description "Marks the block of memory for unconditional deallocation at the end of the current " { $link with-destructors } " scope." } ;
index 5f6a808b2e1b2678796c1451a2b6e6a3c1698cc3..4a887e695ffff7f122b288a84c91df8807e0a647 100644 (file)
@@ -1,5 +1,5 @@
 ! Copyright (C) 2004, 2005 Mackenzie Straight
-! Copyright (C) 2007, 2009 Slava Pestov
+! Copyright (C) 2007, 2010 Slava Pestov
 ! Copyright (C) 2007, 2008 Doug Coleman
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types assocs continuations alien.destructors kernel
@@ -18,8 +18,6 @@ IN: libc
 : preserve-errno ( quot -- )
     errno [ call ] dip set-errno ; inline
 
-<PRIVATE
-
 : (malloc) ( size -- alien )
     void* "libc" "malloc" { ulong } alien-invoke ;
 
@@ -32,6 +30,8 @@ IN: libc
 : (realloc) ( alien size -- newalien )
     void* "libc" "realloc" { void* ulong } alien-invoke ;
 
+<PRIVATE
+
 ! We stick malloc-ptr instances in the global disposables set
 TUPLE: malloc-ptr value continuation ;