io.sockets.secure,alien.libraries: new word word>dlsym to replace the dlsym? word
parent
b42668ebeb
commit
2ba659dcb1
|
@ -1,47 +1,9 @@
|
||||||
! Copyright (C) 2009 Slava Pestov.
|
! Copyright (C) 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien alien.syntax assocs help.markup
|
USING: alien alien.syntax assocs help.markup help.syntax strings words
|
||||||
help.syntax io.backend kernel namespaces strings ;
|
;
|
||||||
IN: alien.libraries
|
IN: alien.libraries
|
||||||
|
|
||||||
HELP: make-library
|
|
||||||
{ $values
|
|
||||||
{ "path" "a pathname string" } { "abi" "the ABI used by the library, either " { $link cdecl } " or " { $link stdcall } }
|
|
||||||
{ "library" library } }
|
|
||||||
{ $description "Opens a C library using the path and ABI parameters and outputs a library tuple." }
|
|
||||||
{ $notes "User code should use " { $link add-library } " so that the opened library is added to a global hashtable, " { $link libraries } "." } ;
|
|
||||||
|
|
||||||
HELP: libraries
|
|
||||||
{ $description "A global hashtable that keeps a list of open libraries. Use the " { $link add-library } " word to construct a library and add it with a single call." } ;
|
|
||||||
|
|
||||||
HELP: library
|
|
||||||
{ $values { "name" string } { "library" assoc } }
|
|
||||||
{ $description "Looks up a library by its logical name. The library object is a hashtable with the following keys:"
|
|
||||||
{ $list
|
|
||||||
{ { $snippet "name" } " - the full path of the C library binary" }
|
|
||||||
{ { $snippet "abi" } " - the ABI used by the library, either " { $link cdecl } " or " { $link stdcall } }
|
|
||||||
{ { $snippet "dll" } " - an instance of the " { $link dll } " class; only set if the library is loaded" }
|
|
||||||
}
|
|
||||||
} ;
|
|
||||||
|
|
||||||
HELP: dlopen
|
|
||||||
{ $values { "path" "a pathname string" } { "dll" "a DLL handle" } }
|
|
||||||
{ $description "Opens a native library and outputs a handle which may be passed to " { $link dlsym } " or " { $link dlclose } "." }
|
|
||||||
{ $errors "Throws an error if the library could not be found, or if loading fails for some other reason." }
|
|
||||||
{ $notes "This is the low-level facility used to implement " { $link load-library } ". Use the latter instead." } ;
|
|
||||||
|
|
||||||
HELP: dlsym
|
|
||||||
{ $values { "name" "a C symbol name" } { "dll" "a DLL handle" } { "alien" { $maybe alien } } }
|
|
||||||
{ $description "Looks up a symbol in a native library. If " { $snippet "dll" } " is " { $link f } " looks for the symbol in the runtime executable. If the symbol was not found, outputs " { $link f } "." } ;
|
|
||||||
|
|
||||||
HELP: dlclose
|
|
||||||
{ $values { "dll" "a DLL handle" } }
|
|
||||||
{ $description "Closes a DLL handle created by " { $link dlopen } ". This word might not be implemented on all platforms." } ;
|
|
||||||
|
|
||||||
HELP: load-library
|
|
||||||
{ $values { "name" string } { "dll" "a DLL handle" } }
|
|
||||||
{ $description "Loads a library by logical name and outputs a handle which may be passed to " { $link dlsym } " or " { $link dlclose } ". If the library is already loaded, returns the existing handle." } ;
|
|
||||||
|
|
||||||
HELP: add-library
|
HELP: add-library
|
||||||
{ $values { "name" string } { "path" string } { "abi" "one of " { $link cdecl } " or " { $link stdcall } } }
|
{ $values { "name" string } { "path" string } { "abi" "one of " { $link cdecl } " or " { $link stdcall } } }
|
||||||
{ $description "Defines a new logical library named " { $snippet "name" } " located in the file system at " { $snippet "path" } " and the specified ABI. You can find the location of the library via words in " { $vocab-link "alien.libraries.finder" } ". The logical library name can then be used by a " { $link POSTPONE: LIBRARY: } " form to specify the logical library for subsequent " { $link POSTPONE: FUNCTION: } " definitions." }
|
{ $description "Defines a new logical library named " { $snippet "name" } " located in the file system at " { $snippet "path" } " and the specified ABI. You can find the location of the library via words in " { $vocab-link "alien.libraries.finder" } ". The logical library name can then be used by a " { $link POSTPONE: LIBRARY: } " form to specify the logical library for subsequent " { $link POSTPONE: FUNCTION: } " definitions." }
|
||||||
|
@ -68,10 +30,52 @@ HELP: deploy-library
|
||||||
{ $values { "name" string } }
|
{ $values { "name" string } }
|
||||||
{ $description "Specifies that the logical library named " { $snippet "name" } " should be included during " { $link "tools.deploy" } ". " { $snippet "name" } " must be the name of a library previously loaded with " { $link add-library } "." } ;
|
{ $description "Specifies that the logical library named " { $snippet "name" } " should be included during " { $link "tools.deploy" } ". " { $snippet "name" } " must be the name of a library previously loaded with " { $link add-library } "." } ;
|
||||||
|
|
||||||
|
HELP: dlclose
|
||||||
|
{ $values { "dll" "a DLL handle" } }
|
||||||
|
{ $description "Closes a DLL handle created by " { $link dlopen } ". This word might not be implemented on all platforms." } ;
|
||||||
|
|
||||||
|
HELP: dlopen
|
||||||
|
{ $values { "path" "a pathname string" } { "dll" "a DLL handle" } }
|
||||||
|
{ $description "Opens a native library and outputs a handle which may be passed to " { $link dlsym } " or " { $link dlclose } "." }
|
||||||
|
{ $errors "Throws an error if the library could not be found, or if loading fails for some other reason." }
|
||||||
|
{ $notes "This is the low-level facility used to implement " { $link load-library } ". Use the latter instead." } ;
|
||||||
|
|
||||||
|
HELP: dlsym
|
||||||
|
{ $values { "name" "a C symbol name" } { "dll" "a DLL handle" } { "alien" { $maybe alien } } }
|
||||||
|
{ $description "Looks up a symbol in a native library. If " { $snippet "dll" } " is " { $link f } " looks for the symbol in the runtime executable. If the symbol was not found, outputs " { $link f } "." } ;
|
||||||
|
|
||||||
|
HELP: make-library
|
||||||
|
{ $values
|
||||||
|
{ "path" "a pathname string" } { "abi" "the ABI used by the library, either " { $link cdecl } " or " { $link stdcall } }
|
||||||
|
{ "library" library } }
|
||||||
|
{ $description "Opens a C library using the path and ABI parameters and outputs a library tuple." }
|
||||||
|
{ $notes "User code should use " { $link add-library } " so that the opened library is added to a global hashtable, " { $link libraries } "." } ;
|
||||||
|
|
||||||
|
HELP: libraries
|
||||||
|
{ $description "A global hashtable that keeps a list of open libraries. Use the " { $link add-library } " word to construct a library and add it with a single call." } ;
|
||||||
|
|
||||||
|
HELP: library
|
||||||
|
{ $values { "name" string } { "library" assoc } }
|
||||||
|
{ $description "Looks up a library by its logical name. The library object is a hashtable with the following keys:"
|
||||||
|
{ $list
|
||||||
|
{ { $snippet "name" } " - the full path of the C library binary" }
|
||||||
|
{ { $snippet "abi" } " - the ABI used by the library, either " { $link cdecl } " or " { $link stdcall } }
|
||||||
|
{ { $snippet "dll" } " - an instance of the " { $link dll } " class; only set if the library is loaded" }
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
HELP: load-library
|
||||||
|
{ $values { "name" string } { "dll" "a DLL handle" } }
|
||||||
|
{ $description "Loads a library by logical name and outputs a handle which may be passed to " { $link dlsym } " or " { $link dlclose } ". If the library is already loaded, returns the existing handle." } ;
|
||||||
|
|
||||||
HELP: remove-library
|
HELP: remove-library
|
||||||
{ $values { "name" string } }
|
{ $values { "name" string } }
|
||||||
{ $description "Unloads a library and removes it from the internal list of libraries. The " { $snippet "name" } " parameter should be a name that was previously passed to " { $link add-library } ". If no library with that name exists, this word does nothing." } ;
|
{ $description "Unloads a library and removes it from the internal list of libraries. The " { $snippet "name" } " parameter should be a name that was previously passed to " { $link add-library } ". If no library with that name exists, this word does nothing." } ;
|
||||||
|
|
||||||
|
HELP: word>dlsym
|
||||||
|
{ $values { "word" word } { "alien/f" maybe{ alien } } }
|
||||||
|
{ $description "Takes a word which calls a C library function and outputs the address of the symbol it points to as an alien. If the symbol isn't loaded, outputs f." } ;
|
||||||
|
|
||||||
ARTICLE: "loading-libs" "Loading native libraries"
|
ARTICLE: "loading-libs" "Loading native libraries"
|
||||||
"Before calling a C library, you must associate its path name on disk with a logical name which Factor uses to identify the library:"
|
"Before calling a C library, you must associate its path name on disk with a logical name which Factor uses to identify the library:"
|
||||||
{ $subsections
|
{ $subsections
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
USING: alien alien.libraries alien.syntax kernel tools.test ;
|
USING: accessors alien alien.libraries alien.syntax kernel libc
|
||||||
|
tools.test ;
|
||||||
|
IN: alien.libraries.tests
|
||||||
|
|
||||||
{ f } [ DLL" fadfasdfsada" dll-valid? ] unit-test
|
{ f } [ DLL" fadfasdfsada" dll-valid? ] unit-test
|
||||||
|
|
||||||
|
@ -25,3 +27,12 @@ USING: alien alien.libraries alien.syntax kernel tools.test ;
|
||||||
"test-library" "blah" cdecl add-library?
|
"test-library" "blah" cdecl add-library?
|
||||||
"blah" remove-library
|
"blah" remove-library
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
{ "blah" f } [
|
||||||
|
"blah" cdecl make-library [ path>> ] [ dll>> dll-valid? ] bi
|
||||||
|
] unit-test
|
||||||
|
|
||||||
|
! word>dlsym
|
||||||
|
{ t } [
|
||||||
|
\ errno word>dlsym alien?
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -27,12 +27,11 @@ TUPLE: library { path string } dll dlerror { abi abi initial: cdecl } ;
|
||||||
|
|
||||||
C: <library> library
|
C: <library> library
|
||||||
|
|
||||||
: lookup-library ( name -- library ) libraries get at ;
|
: lookup-library ( name -- library/f ) libraries get at ;
|
||||||
|
|
||||||
ERROR: no-library-named name ;
|
: word>dlsym ( word -- alien/f )
|
||||||
GENERIC: dlsym? ( name string/dll -- ? )
|
def>> [ third ] [ second dup [ lookup-library dll>> ] when ] bi
|
||||||
M: string dlsym? dup lookup-library [ nip dll>> dlsym? ] [ no-library-named ] if* ;
|
dlsym ;
|
||||||
M: dll dlsym? dlsym >boolean ;
|
|
||||||
|
|
||||||
: open-dll ( path -- dll dll-error/f )
|
: open-dll ( path -- dll dll-error/f )
|
||||||
[ dlopen dup dll-valid? [ f ] [ dlerror ] if ]
|
[ dlopen dup dll-valid? [ f ] [ dlerror ] if ]
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2008, 2010 Slava Pestov.
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.libraries calendar combinators delegate
|
USING: accessors alien.libraries calendar combinators delegate
|
||||||
destructors io io.sockets io.sockets.private kernel memoize
|
destructors io io.sockets io.sockets.private kernel memoize namespaces
|
||||||
namespaces present sequences summary system vocabs ;
|
openssl.libssl present sequences summary system vocabs ;
|
||||||
IN: io.sockets.secure
|
IN: io.sockets.secure
|
||||||
|
|
||||||
SYMBOL: secure-socket-timeout
|
SYMBOL: secure-socket-timeout
|
||||||
|
@ -23,9 +23,9 @@ ERROR: no-tls-supported ;
|
||||||
|
|
||||||
MEMO: best-tls-method ( -- class )
|
MEMO: best-tls-method ( -- class )
|
||||||
{
|
{
|
||||||
{ [ "TLSv1_2_method" "libssl" dlsym? ] [ TLSv1.2 ] }
|
{ [ \ TLSv1_2_method word>dlsym ] [ TLSv1.2 ] }
|
||||||
{ [ "TLSv1_1_method" "libssl" dlsym? ] [ TLSv1.1 ] }
|
{ [ \ TLSv1_1_method word>dlsym ] [ TLSv1.1 ] }
|
||||||
{ [ "TLSv1_method" "libssl" dlsym? ] [ TLSv1 ] }
|
{ [ \ TLSv1_method word>dlsym ] [ TLSv1 ] }
|
||||||
[ no-tls-supported ]
|
[ no-tls-supported ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue