Improve lsm_str API #17

Open
opened 2023-11-16 18:05:39 +01:00 by Jef Roosens · 0 comments

The current design for lsm_str is turning out to be rather cumbersome to use. Therefore I think the following changes are in order:

  • Make the lsm_str struct publicly available, as to allow allocating them on the stack
  • Make them read-only by default, allowing them to be safely used with stack-allocated strings. Only when a write operation is applied to the string, should the original string be copied to a new buffer and the write performed. The string object should then keep track of whether it owns the buffer, so it knows whether to free the buffer or not.
  • Store null-terminated strings, as passing an lsm_str to any C function that takes a C string is currently very cumbersome, having to copy the string to a new buffer. Ideally, we could just pass the result of lsm_str_ptr as a C string.
  • Add a new lsm_str_set function that serves the same purpose as lsm_str_overwrite, but does not free the previous string's contents; this to allow setting an empty stack-allocated string object for the first time

These changes will make working with the lsm_str library much nicer.

The current design for `lsm_str` is turning out to be rather cumbersome to use. Therefore I think the following changes are in order: * Make the `lsm_str` struct publicly available, as to allow allocating them on the stack * Make them read-only by default, allowing them to be safely used with stack-allocated strings. Only when a write operation is applied to the string, should the original string be *copied* to a new buffer and the write performed. The string object should then keep track of whether it owns the buffer, so it knows whether to free the buffer or not. * Store null-terminated strings, as passing an `lsm_str` to any C function that takes a C string is currently very cumbersome, having to copy the string to a new buffer. Ideally, we could just pass the result of `lsm_str_ptr` as a C string. * Add a new `lsm_str_set` function that serves the same purpose as `lsm_str_overwrite`, but does not free the previous string's contents; this to allow setting an empty stack-allocated string object for the first time These changes will make working with the `lsm_str` library much nicer.
Jef Roosens added the
Kind/Enhancement
label 2023-11-16 18:05:39 +01:00
Jef Roosens added the
Project/Lander
label 2024-08-26 10:42:18 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Chewing_Bever/lander#17
There is no content yet.