tursodatabase / tursodatabase/libsql

Return string length alongside pointer in C bindings

Open
#509 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
17.2k
Forks
531
Avg merge
1h 12m
Merged PRs (30d)
1

Description

Currently the C bindings function has the following signature:

pub unsafe extern "C" fn libsql_get_string(
    res: libsql_row_t,
    col: std::ffi::c_int,
    out_value: *mut *const std::ffi::c_char,
    out_err_msg: *mut *const std::ffi::c_char,
) -> std::ffi::c_int

I think it would be a good idea to include the length of the string which I understand is already available to the Rust runtime instead of making the foreign runtime traverse the pointer to find the null character to copy it into its own memory.

  pub unsafe extern "C" fn libsql_get_string(
      res: libsql_row_t,
      col: std::ffi::c_int,
      out_value: *mut *const std::ffi::c_char,
+     out_len: *mut *const c_int,
      out_err_msg: *mut *const std::ffi::c_char,
  ) -> std::ffi::c_int

or whatever type is appropriate.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the implementation and foreign callers of the libsql_get_string C binding; the issue does not name a file or test. Determine the appropriate length type and how the existing string length is exposed, then update the binding and verify that callers can receive the length without scanning for a null character.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
api, databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.