Skip to content
Jaskirat Rajasansir edited this page Jan 12, 2021 · 1 revision

Shared Object Function Manager

This library provides a mechanism for searching for shared objects and dynamically loading functions from them via 2: into a kdb+ process.

The search is performed on paths stored within the OS-specific shared object search environment variable. See os.q for the environment variables used.

All functions loaded through this mechanism are cached in a specific sub-namespace of the .so library and can be used directly or copied into other namespace references as necessary.

.so.findSharedObject[soName]

Attempts to find a matching shared object library file based on the specified name. The name should include the required suffix of the file.

Note that if multiple files match the specified name, only the first will be returned.

> export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/git/jas/kdb-systemd-lib/build
q) .require.lib`so;
q) .so.findSharedObject `libkdbsystemd.so
`:/home/jas/git/kdb-systemd-lib/build/libkdbsystemd.so

/ Can specify specific version if necessary
q) .so.findSharedObject `libkdbsystemd.so.1.0.1
`:/home/jas/git/kdb-systemd-lib/build/libkdbsystemd.so.1.0.1

/ Null symbol returned if none found
q) .so.findSharedObject `libkdbsystem.so
2021.01.10 16:50:44.006 WARN pid-2406 jas 0 No matching paths found for shared object [ Shared Object: libkdbsystem.so ] [ Source Env Var: LD_LIBRARY_PATH ]
`

.so.loadFunction[soName; soFunctionName; soFunctionArgs]

Loads the specified function from the specified shared object.

soName can be the name of the shared object to find (which will use .so.findSharedObject to find the path) or the full path to the shared object to load the function from.

The function returns a symbol reference to the cached version of the shared object function loaded. If the same function is requested again, a reference to the cached version of the function will be returned.

> export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/git/jas/kdb-systemd-lib/build
q) .require.lib`so;
q).so.loadFunction[`libkdbsystemd.so; `sendReady; 1]
2021.01.10 16:53:07.119 INFO pid-2794 jas 0 Loading function from shared object [ Shared Object: libkdbsystemd.so (:/home/jas/git/kdb-systemd-lib/build/libkdbsystemd.so) ] [ Function: sendReady -> .so.libs.libkdbsystemd.sendReady ] [ Args: 1 ]
2021.01.10 16:53:07.136 INFO pid-2794 jas 0 Shared object function loaded OK [ Shared Object: libkdbsystemd.so ] [ Function: .so.libs.libkdbsystemd.sendReady ]
`.so.libs.libkdbsystemd.sendReady

/ If the specified function doesn't exist
q) .so.loadFunction[`libkdbsystemd.so; `badFunction; 1]
2021.01.10 16:54:43.762 INFO pid-2794 jas 0 Loading function from shared object [ Shared Object: libkdbsystemd.so (:/home/jas/git/kdb-systemd-lib/build/libkdbsystemd.so) ] [ Function: badFunction -> .so.libs.libkdbsystemd.badFunction ] [ Args: 1 ]
'/home/jas/git/kdb-systemd-lib/build/libkdbsystemd.so.1.0.1: undefined symbol: badFunction
  [1]  /home/jas/git/kdb-common/src/so.q:82: .so.loadFunction:

    set[kdbFunctionName;] soLoadPath 2: (soFunctionName; soFunctionArgs);

/ The function is only loaded once
q) .so.loadFunction[`$":/home/jas/git/kdb-systemd-lib/build/libkdbsystemd.so.1.0.1"; `sendReady; 1]
2021.01.11 16:57:31.430 INFO pid-2794 jas 0 Shared object function already loaded [ Shared Object: :/home/jas/git/kdb-systemd-lib/build/libkdbsystemd.so.1.0.1 ] [ Function: sendReady ]
`.so.libs.libkdbsystemd.sendReady
Clone this wiki locally