Skip to content

Resource ownership rules when integrating with C++ #736

@yfinkelstein

Description

@yfinkelstein

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?
  1. 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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions