Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
|
|
|
|
v0.2.1 (2025-11-21) | `__chain_alloc` memory model suspended
| `chain_stringify` modification, read DOCUMENTATION
| temporary usage of `malloc`, may result in memory leaks
|
v0.2 (2025-11-20) | major memory leak fixes
| moving to single-header library
| chain_snapshot()
| `chain_snapshot`
| CHAIN_ASSERT error management
| CHAIN_PROFILER macro
|
Expand Down
31 changes: 18 additions & 13 deletions DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,25 @@ size_t chain_len(const chain* c);

/*
Converts a chain into a null-terminated C string.

The returned pointer refers to memory inside the chain’s arena.
It stays valid until the chain is modified or dropped.

The chain owns this buffer. Do not free it manually.

To obtain an independent heap-allocated string, use:

`char* temp = malloc(chain_len(c) + 1);
memcpy(temp, chain_stringify(c), chain_len(c) + 1);`

A dedicated function `chain_mstringify()` will later handle
this automatically by returning a heap-allocated buffer that the
caller is responsible for freeing.
String returned by this function is allocated by `malloc`. Caller must free it manually.
(v0.2.1 -- quick solution untill appropriate memory model idea).

==== v0.2.1 THE FOLLOWING INFORMATION IS OUTDATED
|
| The returned pointer refers to memory inside the chain’s arena.
| It stays valid until the chain is modified or dropped.
|
| To obtain an independent heap-allocated string, use:
|
| `char* temp = malloc(chain_len(c) + 1);
| memcpy(temp, chain_stringify(c), chain_len(c) + 1);`
|
| A dedicated function `chain_mstringify()` will later handle
| this automatically by returning a heap-allocated buffer that the
| caller is responsible for freeing.
|
==== v0.2.1
*/
char* chain_stringify(const chain* c);

Expand Down
2 changes: 1 addition & 1 deletion examples/cli_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int main() {

if (strncmp(input, "/undo", 5) == 0) {
// simple undo: remove last patch
if (doc->patch_count > 0) doc->patch_count--;
if (doc->array_count > 0) doc->array_count--;
} else if (strncmp(input, "/replace", 8) == 0) {
size_t pos, rlen;
char newtext[256];
Expand Down
Loading