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 πŸ”—

exec(
    library: str | Path,
    symbol: str,
    arg_read: list[Any] | None = None,
    arg_write: list[Any] | None = None,
) -> list[Any] | None

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] | None

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

None

arg_write πŸ”—

list[Any] | None

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

None

Returns:

Type Description
list[Any] | None

The resulting outputs.

Raises:

Type Description
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] | None = None,
    arg_write: list[Any] | None = None,
) -> list[Any] | None:
    """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:
        FFIError: If the C operation fails.
    """
    if arg_read is not None:
        c_arg_read = CList([Arg(arg) for arg in arg_read])
        c_arg_read_ptr = c_arg_read._c_ptr
        c_arg_read_len = len(c_arg_read)
    else:
        c_arg_read = None
        c_arg_read_ptr = ffi.NULL
        c_arg_read_len = 0

    if arg_write is not None:
        c_arg_write = CList([Arg(arg) for arg in arg_write])
        c_arg_write_ptr = c_arg_write._c_ptr
        c_arg_write_len = len(c_arg_write)
    else:
        c_arg_write = None
        c_arg_write_ptr = ffi.NULL
        c_arg_write_len = 0

    ret = lib.vaccel_exec(
        self._c_ptr_or_raise,
        str(library).encode(),
        symbol.encode(),
        c_arg_read_ptr,
        c_arg_read_len,
        c_arg_write_ptr,
        c_arg_write_len,
    )
    if ret != 0:
        raise FFIError(ret, "Exec operation failed")

    if c_arg_write is not None:
        return [c_arg_write[i].buf for i in range(len(c_arg_write))]
    return None

exec_with_resource πŸ”—

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

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] | None

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

None

arg_write πŸ”—

list[Any] | None

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

None

Returns:

Type Description
list[Any] | None

The resulting outputs.

Raises:

Type Description
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] | None = None,
    arg_write: list[Any] | None = None,
) -> list[Any] | None:
    """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:
        FFIError: If the C operation fails.
    """
    if arg_read is not None:
        c_arg_read = CList([Arg(arg) for arg in arg_read])
        c_arg_read_ptr = c_arg_read._c_ptr
        c_arg_read_len = len(c_arg_read)
    else:
        c_arg_read = None
        c_arg_read_ptr = ffi.NULL
        c_arg_read_len = 0

    if arg_write is not None:
        c_arg_write = CList([Arg(arg) for arg in arg_write])
        c_arg_write_ptr = c_arg_write._c_ptr
        c_arg_write_len = len(c_arg_write)
    else:
        c_arg_write = None
        c_arg_write_ptr = ffi.NULL
        c_arg_write_len = 0

    ret = lib.vaccel_exec_with_resource(
        self._c_ptr_or_raise,
        resource._c_ptr,
        symbol.encode(),
        c_arg_read_ptr,
        c_arg_read_len,
        c_arg_write_ptr,
        c_arg_write_len,
    )
    if ret != 0:
        raise FFIError(ret, "Exec with resource operation failed")

    if c_arg_write is not None:
        return [c_arg_write[i].buf for i in range(len(c_arg_write))]
    return None