Resource ownership rules when integrating with C++
- Dominant language
- Python
- Stars
- 16.8k
- Forks
- 603
- Avg merge
- 4d 23h
- Merged PRs (30d)
- 6
Description
These questions apply to both embedded JIT mode as well as to "as a shared library" mode.
On Codon side:
```
extern
def f1(s:str) -> str
```
On C++ side
```
struct CodonString {
seq_int_t len;
char *str;
};
extern "C" CodonString f2( CodonString s);
```
Questions:
1. C++ side invokes f1:
* Who owns string memory in incoming argument `s` ? If it's codon - can C++ "ref count" it and later unref or it must copy ?
* Who owns string memory of return string? C++ has generated this string by allocating it with `seq_alloc_atomic`. But who will release it and when?
2. Codon side invokes f2:
* Who owns string memory in `s`?
* Who owns string memory of return string?
These rules must be explained and documented.
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.