Liking cljdoc? Tell your friends :D

tech.v3.jna

Simple bindings to the JNA system. Fastest pathway to success is def-jna-fn. Note that the default behavior for malloc has changed; the default resource type is :gc now as opposed to [:stack :gc].

Also, for ease of use when creating derived objects from gc-managed native pointer-based objects see tech.v3.resource/chain-resources.

Simple bindings to the JNA system.  Fastest pathway to success is `def-jna-fn`.
Note that the default behavior for malloc has changed; the default resource type
is :gc now as opposed to [:stack :gc].

Also, for ease of use when creating derived objects from gc-managed native
pointer-based objects see
[`tech.v3.resource/chain-resources`](https://techascent.github.io/tech.resource/tech.v3.resource.html#var-chain-resources).
raw docstring

add-library-pathclj

(add-library-path libname pathtype path)

Add a search path. The multimethod (base/find-library pathtype path) is called to expand the pathtype, path into one or more actual paths to attempt. Valid existing pathtypes are

:system - no changes, looks in system paths. :java-library-path - Appends library to all paths in java-library-paths :resource - Uses jna Native/extractFromResourcePath

Add a search path.  The multimethod (base/find-library pathtype path) is called to
  expand the pathtype, path into one or more actual paths to attempt.  Valid existing
  pathtypes are

:system - no changes, looks in system paths.
:java-library-path - Appends library to all paths in java-library-paths
:resource - Uses jna Native/extractFromResourcePath
sourceraw docstring

as-ptrclj

(as-ptr item)

Convert this object to a jna Pointer returning nil if not possible. For a checked conversion see ensure-ptr.

Convert this object to a jna Pointer returning nil if not possible.  For a checked
conversion see `ensure-ptr`.
sourceraw docstring

c-library-nameclj

(c-library-name)

Get the c library name for your system. This can be used with def-jna-fn to bind to various c library function calls.

Get the c library name for your system.  This can be used with def-jna-fn
to bind to various c library function calls.
sourceraw docstring

char-ptr-ptr->string-vecclj

(char-ptr-ptr->string-vec num-strings char-ptr-ptr)

Decode a char** ptr.

Decode a char** ptr.
sourceraw docstring

checknilclj

(checknil value)

Check that a thing is a pointer and the integer value is not zero.

Check that a thing is a pointer and the integer value is not zero.
sourceraw docstring

clear-library-pathsclj

(clear-library-paths libname)

Clear the library search paths for a specific library. Use with care; the default if non found is: [[:system libname] [:java-library-path libname]].

Clear the library search paths for a specific library.
Use with care; the default if non found is:
[[:system libname]
 [:java-library-path libname]].
sourceraw docstring

create-ptr-ptrclj

(create-ptr-ptr ptr)

Create a pointer to a pointer.

Create a pointer to a pointer.
sourceraw docstring

def-jna-fncljmacro

(def-jna-fn libname fn-name docstring rettype & argpairs)

Define a dynamically bound fn. Upon first call, it will attempt to find the function pointer from libname. Redefinition resets the functions so it will rebind to a location.

  • rettype - Class return type or nil for void.
  • argpairs - one or more pairs of type [symbol type-coersion] where the symbol is what will be displayed in the function's docstring and type-coersion is a function that is run at function call time to ensure the type is the exact correct type. If coersion function is wrong and creates the wrong type for the function signature your program will probably crash.
(jna/def-jna-fn (jna/c-library-name) strcpy
  "Copy a (hopefully) null terminated string into a pointer.  This is a horrible idea."
  Pointer
  [dest jna/ensure-ptr]
  [src jna/ensure-ptr])
Define a dynamically bound fn.  Upon first call, it will attempt to find
  the function pointer from libname.  Redefinition resets the functions so it
  will rebind to a location.


  * `rettype` - Class return type or nil for void.
  * `argpairs` - one or more pairs of type [symbol type-coersion] where the symbol
     is what will be displayed in the function's docstring and type-coersion is a
     function that is run at function call time to ensure the type is the exact
     correct type.  If coersion function is wrong and creates the wrong type for
     the function signature your program will probably crash.

```clojure
(jna/def-jna-fn (jna/c-library-name) strcpy
  "Copy a (hopefully) null terminated string into a pointer.  This is a horrible idea."
  Pointer
  [dest jna/ensure-ptr]
  [src jna/ensure-ptr])
```
sourceraw docstring

ensure-ptrclj

(ensure-ptr item)

Convert thing to pointer or throw exception.

Convert thing to pointer or throw exception.
sourceraw docstring

ensure-ptr-ptrclj

(ensure-ptr-ptr item)

Ensure a thing is a ptr-to-a-ptr.

Ensure a thing is a ptr-to-a-ptr.
sourceraw docstring

ensure-typeclj

(ensure-type item-cls item)

Ensure a thing is derived from item-cls

Ensure a thing is derived from item-cls
sourceraw docstring

find-functionclj

(find-function fn-name libname)

Given a function name and a library name, find the function in the library. Returns a com.sun.jna Function object. For a much more user-friendly and higher level pathway see def-jna-fn

Given a function name and a library name, find the function in the library.
Returns a com.sun.jna Function object.  For a much more user-friendly and higher
level pathway see `def-jna-fn`
sourceraw docstring

library-pathsclj

(library-paths libname)

Get the current library search paths for a library.

Get the current library search paths for a library.
sourceraw docstring

load-libraryclj

(load-library libname)

Load a library. Returns

Load a library.  Returns 
sourceraw docstring

mallocclj

(malloc num-bytes)
(malloc num-bytes {:keys [resource-type log-level] :or {resource-type #{:gc}}})

Malloc a pointer of Y bytes. Track using both resource context and gc system.

Options:

  • :resource-type - :track-type in tech.v3.resource with passthrough semantics.
  • :log-level - Defaults to nil - if provided malloc/free call pairs will be logged at this level.

For a much more thorough treatment of native heap data, please see the documentation for dtype-next - native-buffer

Malloc a pointer of Y bytes.  Track using both resource context
and gc system.

Options:

 * `:resource-type` - `:track-type` in tech.v3.resource with passthrough semantics.
 * `:log-level` - Defaults to nil - if provided malloc/free call pairs will be logged
    at this level.

For a much more thorough treatment of native heap data, please see the documentation
for [dtype-next - native-buffer](https://cnuernber.github.io/dtype-next/tech.v3.datatype.native-buffer.html)
sourceraw docstring

malloc-untrackedclj

(malloc-untracked num-bytes)

Malloc pointer of Y bytes. Up to caller to call Native/free on result at some point

Malloc pointer of Y bytes.  Up to caller to call Native/free on result at some
point
sourceraw docstring

map-shared-library-nameclj

(map-shared-library-name libname)

Map a stem to a shared library name in platform specific manner

Map a stem to a shared library name in platform specific manner
sourceraw docstring

math-library-nameclj

(math-library-name)

Get the c math library name for your system. This can be used with def-jna-fn to bind to various c library function calls.

Get the c math library name for your system.  This can be used with def-jna-fn
to bind to various c library function calls.
sourceraw docstring

PToPtrcljprotocol

->ptr-backing-storeclj

(->ptr-backing-store item)

Conversion to a jna pointer type that points to the data of the object.

Conversion to a jna pointer type that points to the data of the object.

is-jna-ptr-convertible?clj

(is-jna-ptr-convertible? item)

Is this object convertible to a JNA pointer?

Is this object convertible to a JNA pointer?
source

ptr-convertible?clj

(ptr-convertible? item)

Is this object pointer convertible via the PToPtr protocol.

Is this object pointer convertible via the PToPtr protocol.
sourceraw docstring

register-direct-mapped-class!clj

(register-direct-mapped-class! libname cls-obj)

Register a direct-mapped class with a library. Calling direct-mapped functions dramatically decreases function call overhead and brings it inline with hand-built JNI bindings.

Direct-mapped classes look like normal classes with functions defined with static native attributes.

From libpython-clj:

(com.sun.jna.Native/register DirectMapped library)
Register a direct-mapped class with a library.  Calling direct-mapped functions
  *dramatically* decreases function call overhead and brings it inline with hand-built
  JNI bindings.

  Direct-mapped classes look like normal classes with functions defined with
  [`static native` attributes](https://github.com/clj-python/libpython-clj/blob/c4d0c2cb6476d053013224cf8b441f1f55241eee/java/libpython_clj/jna/DirectMapped.java).

  From [libpython-clj](https://github.com/clj-python/libpython-clj/blob/c4d0c2cb6476d053013224cf8b441f1f55241eee/src/libpython_clj/python/interpreter.clj#L431):

```clojure
(com.sun.jna.Native/register DirectMapped library)
```
sourceraw docstring

reload!clj

(reload! libname)

Reload a shared library. This means that any dynamically bound functions defined via def-jna-fn will load the new library's functions as they are dynamically found at call time every time. Any direct-mapped classes will need to be rebound via register-direct-mapped-class.

Reload a shared library.  This means that any dynamically bound functions
defined via `def-jna-fn` will load the new library's functions as they
are dynamically found at call time every time.  Any direct-mapped classes
will need to be rebound via register-direct-mapped-class.
sourceraw docstring

set-loaded-library!clj

(set-loaded-library! libname native-library)

Override the search mechanism and set the native library to X.

Override the search mechanism and set the native library to X.
sourceraw docstring

size-tclj

(size-t)
(size-t item)

Convert item to either an integer or a long depending on the size of size-t.

Convert item to either an integer or a long depending on the size of
size-t.
sourceraw docstring

size-t-compile-time-switchcljmacro

(size-t-compile-time-switch int-body long-body)

Run either int32 based code or int64 based code depending on the runtime size of size-t

Run either int32 based code or int64 based code depending
on the runtime size of size-t
sourceraw docstring

size-t-refclj

(size-t-ref)
(size-t-ref item)

Create a reference to a size-t.

Create a reference to a size-t.
sourceraw docstring

size-t-ref-typeclj

The runtime reference-by-ptr type of a c size-t

The runtime reference-by-ptr type of a c size-t
sourceraw docstring

size-t-ref-valueclj

(size-t-ref-value ref-obj)

Get the value from a size-t reference.

Get the value from a size-t reference.
sourceraw docstring

size-t-typeclj

The runtime class type of a c size-t

The runtime class type of a c size-t
sourceraw docstring

string->ptrclj

(string->ptr data)
(string->ptr data options)

Convert a string to a pointer. Track the data via the gc; when the Pointer goes out of scope the memory will be freed.

Convert a string to a pointer.  Track the data via the gc; when the Pointer
goes out of scope the memory will be freed.
sourceraw docstring

string->ptr-untrackedclj

(string->ptr-untracked data)

Convert a string to a pointer. Memory will not be automatically freed.

Convert a string to a pointer.  Memory will not be automatically freed.
sourceraw docstring

string->wide-ptrclj

(string->wide-ptr data)
(string->wide-ptr data options)

Convert a string into a wchar-t using utf-16. Default resource type is :gc.

Convert a string into a wchar-t using utf-16.  Default resource type is :gc.
sourceraw docstring

unsafe-read-byteclj

(unsafe-read-byte byte-ary idx)

Read a byte from pointer byte-ary at address idx. For bulk access convert the pointer to a tech.v3.datatype.native-buffer/NativeBuffer via:

  (tech.v3.datatype.native-buffer/wrap-address
     (com.sun.jna.Pointer/nativeValue ptr)
     ...)
Read a byte from pointer byte-ary at address idx.  For bulk access convert the
  pointer to a `tech.v3.datatype.native-buffer/NativeBuffer` via:

```clojure
  (tech.v3.datatype.native-buffer/wrap-address
     (com.sun.jna.Pointer/nativeValue ptr)
     ...)
```
sourceraw docstring

variable-byte-ptr->stringclj

(variable-byte-ptr->string ptr-addr)

Convert a c-string into a string

Convert a c-string into a string
sourceraw docstring

wide-ptr->stringclj

(wide-ptr->string wide-ptr)

Convert a wchar-t ptr to a java string

Convert a wchar-t ptr to a java string
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close