Skip to content

exec πŸ”—

Exec operations.

ExecMixin πŸ”—

Mixin providing the Exec operations for a Session.

This mixin is intended to be used in combination with BaseSession and should not be instantiated on its own.

Intended usage

class Session(BaseSession, ExecMixin): ...

exec πŸ”—

Performs the Exec operation.

Wraps the vaccel_exec() C operation.

Parameters:

Name Type Description Default

library πŸ”—

str | Path

The path to the shared object containing the function that will be called.

required

symbol πŸ”—

str

The name of the function contained in the above shared object.

required

arg_read πŸ”—

list[Any]

The input arguments that will be passed to the called function.

required

arg_write πŸ”—

list[Any]

The output arguments that will be passed to the called function.

required

Returns:

Type Description
list[Any]

The resulting outputs.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/exec.py
def exec(
    self,
    library: str | Path,
    symbol: str,
    arg_read: list[Any],
    arg_write: list[Any],
) -> list[Any]:
    """Performs the Exec operation.

    Wraps the `vaccel_exec()` C operation.

    Args:
        library: The path to the shared object containing the function that
            will be called.
        symbol: The name of the function contained in the above shared
            object.
        arg_read: The input arguments that will be passed to the
            called function.
        arg_write: The output arguments that will be passed to the
            called function.

    Returns:
        The resulting outputs.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    c_arg_read = CList([Arg(arg) for arg in arg_read])
    c_arg_write = CList([Arg(arg) for arg in arg_write])

    ret = lib.vaccel_exec(
        self._c_ptr,
        str(library).encode(),
        symbol.encode(),
        c_arg_read._c_ptr,
        len(c_arg_read),
        c_arg_write._c_ptr,
        len(c_arg_write),
    )
    if ret != 0:
        raise FFIError(ret, "Exec operation failed")

    return [c_arg_write[i].buf for i in range(len(c_arg_write))]

exec_with_resource πŸ”—

exec_with_resource(
    resource: Resource, symbol: str, arg_read: list[Any], arg_write: list[Any]
) -> list[Any]

Performs the Exec with resource operation.

Wraps the vaccel_exec_with_resource() C operation.

Parameters:

Name Type Description Default

resource πŸ”—

Resource

The resource of the shared object containing the function that will be called.

required

symbol πŸ”—

str

The name of the function contained in the above shared object.

required

arg_read πŸ”—

list[Any]

The input arguments that will be passed to the called function.

required

arg_write πŸ”—

list[Any]

The output arguments that will be passed to the called function.

required

Returns:

Type Description
list[Any]

The resulting outputs.

Raises:

Type Description
RuntimeError

If the Session is uninitialized.

FFIError

If the C operation fails.

Source code in vaccel/ops/exec.py
def exec_with_resource(
    self,
    resource: Resource,
    symbol: str,
    arg_read: list[Any],
    arg_write: list[Any],
) -> list[Any]:
    """Performs the Exec with resource operation.

    Wraps the `vaccel_exec_with_resource()` C operation.

    Args:
        resource: The resource of the shared object containing the function
            that will be called.
        symbol: The name of the function contained in the above shared
            object.
        arg_read: The input arguments that will be passed to the
            called function.
        arg_write: The output arguments that will be passed to the
            called function.

    Returns:
        The resulting outputs.

    Raises:
        RuntimeError: If the `Session` is uninitialized.
        FFIError: If the C operation fails.
    """
    if not self._c_ptr:
        msg = "Uninitialized session"
        raise RuntimeError(msg)

    c_arg_read = CList([Arg(arg) for arg in arg_read])
    c_arg_write = CList([Arg(arg) for arg in arg_write])

    ret = lib.vaccel_exec_with_resource(
        self._c_ptr,
        resource._c_ptr,
        symbol.encode(),
        c_arg_read._c_ptr,
        len(c_arg_read),
        c_arg_write._c_ptr,
        len(c_arg_write),
    )
    if ret != 0:
        raise FFIError(ret, "Exec with resource operation failed")

    return [c_arg_write[i].buf for i in range(len(c_arg_write))]