Skip to content

Commit 3d488be

Browse files
committed
Add comments
1 parent 5f9b3e0 commit 3d488be

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

c_src/pythonx/pythonx.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ ERL_NIF_TERM py_str_to_binary_term(ErlNifEnv *env, PyObjectPtr py_object) {
271271
auto buffer = PyUnicode_AsUTF8AndSize(py_object, &size);
272272
raise_if_failed(env, buffer);
273273

274+
// The buffer is immutable and lives as long as the Python object,
275+
// so we create the term as a resource binary to make it zero-copy.
274276
Py_IncRef(py_object);
275277
auto ex_object_resource = fine::make_resource<ExObjectResource>(py_object);
276278
return fine::make_resource_binary(env, ex_object_resource, buffer, size);
@@ -915,6 +917,8 @@ fine::Term decode_once(ErlNifEnv *env, ExObject ex_object) {
915917
auto result = PyBytes_AsStringAndSize(py_object, &buffer, &size);
916918
raise_if_failed(env, result);
917919

920+
// The buffer is immutable and lives as long as the Python object,
921+
// so we create the term as a resource binary to make it zero-copy.
918922
Py_IncRef(py_object);
919923
auto ex_object_resource = fine::make_resource<ExObjectResource>(py_object);
920924
return fine::make_resource_binary(env, ex_object_resource, buffer, size);

0 commit comments

Comments
 (0)