-USING: alien strings arrays help.markup help.syntax ;
+USING: alien strings arrays help.markup help.syntax destructors ;
IN: core-foundation
HELP: CF>array
{ $values { "name" "a pathname string" } }
{ $description "Loads a Core Foundation framework." } ;
+HELP: &CFRelease
+{ $values { "alien" "Pointer to a Core Foundation object" } }
+{ $description "Marks the given Core Foundation object for unconditional release via " { $link CFRelease } " at the end of the enclosing " { $link with-destructors } " scope." } ;
+
+HELP: |CFRelease
+{ $values { "interface" "Pointer to a Core Foundation object" } }
+{ $description "Marks the given Core Foundation object for release via " { $link CFRelease } " in the event of an error at the end of the enclosing " { $link with-destructors } " scope." } ;
+
+{ CFRelease |CFRelease &CFRelease } related-words
+
ARTICLE: "core-foundation" "Core foundation utilities"
"The " { $vocab-link "core-foundation" } " vocabulary defines bindings for some frequently-used Core Foundation functions. It also provides some utility words."
$nl
{ $subsection <CFFileSystemURL> }
{ $subsection <CFURL> }
"Frameworks:"
-{ $subsection load-framework } ;
+{ $subsection load-framework }
+"Memory management:"
+{ $subsection &CFRelease }
+{ $subsection |CFRelease } ;
-IN: core-foundation
ABOUT: "core-foundation"
! Copyright (C) 2006, 2008 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types alien.strings alien.syntax kernel
-math sequences io.encodings.utf16 ;
+math sequences io.encodings.utf16 destructors accessors ;
IN: core-foundation
TYPEDEF: void* CFAllocatorRef
"Cannot load bundled named " prepend throw
] ?if ;
+TUPLE: CFRelease-destructor alien disposed ;
+M: CFRelease-destructor dispose* alien>> CFRelease ;
+: &CFRelease ( alien -- alien )
+ dup f CFRelease-destructor boa &dispose drop ; inline
+: |CFRelease ( alien -- alien )
+ dup f CFRelease-destructor boa |dispose drop ; inline
combinators kernel sequences debugger io accessors ;
IN: iokit
-<< {
- { [ os macosx? ] [ "/System/Library/Frameworks/IOKit.framework" load-framework ] }
- [ "IOKit only supported on Mac OS X" ]
-} cond >>
+<<
+ os macosx?
+ [ "/System/Library/Frameworks/IOKit.framework" load-framework ]
+ when
+>>
: kIOKitBuildVersionKey "IOKitBuildVersion" ; inline
: kIOKitDiagnosticsKey "IOKitDiagnostics" ; inline
USING: help.markup help.syntax io kernel math quotations\r
-multiline ;\r
+multiline destructors ;\r
IN: windows.com\r
\r
HELP: com-query-interface\r
HELP: com-release\r
{ $values { "interface" "Pointer to a COM interface implementing " { $snippet "IUnknown" } } }\r
{ $description "A small wrapper around " { $link IUnknown::Release } ". Decrements the reference count on " { $snippet "interface" } ", releasing the underlying object if the reference count has reached zero." } ;\r
+\r
+HELP: &com-release\r
+{ $values { "interface" "Pointer to a COM interface implementing " { $snippet "IUnknown" } } }\r
+{ $description "Marks the given COM interface for unconditional release via " { $link com-release } " at the end of the enclosing " { $link with-destructors } " scope." } ;\r
+\r
+HELP: |com-release\r
+{ $values { "interface" "Pointer to a COM interface implementing " { $snippet "IUnknown" } } }\r
+{ $description "Marks the given COM interface for release via " { $link com-release } " in the event of an error at the end of the enclosing " { $link with-destructors } " scope." } ;\r
+\r
+{ com-release &com-release |com-release } related-words\r
+\r
USING: alien alien.c-types windows.com.syntax windows.ole32\r
-windows.types continuations kernel alien.syntax libc ;\r
+windows.types continuations kernel alien.syntax libc\r
+destructors accessors ;\r
IN: windows.com\r
\r
LIBRARY: ole32\r
\r
: with-com-interface ( interface quot -- )\r
over [ slip ] [ com-release ] [ ] cleanup ; inline\r
+\r
+TUPLE: com-destructor interface disposed ;\r
+M: com-destructor dispose* interface>> com-release ;\r
+\r
+: &com-release ( interface -- interface )\r
+ dup f com-destructor boa &dispose drop ;\r
+: |com-release ( interface -- interface )\r
+ dup f com-destructor boa |dispose drop ;\r
alien alien.c-types alien.syntax kernel system namespaces math ;
IN: windows.dinput
-<< os windows?
+<<
+ os windows?
[ "dinput" "dinput8.dll" "stdcall" add-library ]
- [ "DirectInput only supported on Windows" throw ] if
+ when
>>
LIBRARY: dinput