pit

String

Back to index

OpenPitStringView

Non-owning UTF-8 string view.

This type never owns memory. It borrows bytes from another object.

Lifetime contract:

typedef struct OpenPitStringView {
    const uint8_t * ptr;
    size_t len;
} OpenPitStringView;

OpenPitSharedString

Owning shared-string handle.

Use this type when an FFI function needs to hand a string to the caller whose lifetime must extend beyond the single FFI call and whose storage must not depend on thread-local state remaining intact on the reader side.

Ownership contract:

Read contract:

Threading contract:

typedef struct OpenPitSharedString OpenPitSharedString;

openpit_destroy_shared_string

Releases a OpenPitSharedString handle.

Null input is a no-op.

After this call, the handle and any OpenPitStringView previously obtained from it are invalid and must not be used.

void openpit_destroy_shared_string(
    OpenPitSharedString * handle
);

openpit_shared_string_view

Borrows a read-only view of the bytes stored in the handle.

Returns an unset view (ptr == null, len == 0) when handle is null.

The returned view is valid only while handle remains alive. The caller must copy the bytes if they must outlive the handle.

OpenPitStringView openpit_shared_string_view(
    const OpenPitSharedString * handle
);