File tree Expand file tree Collapse file tree 1 file changed +4
-0
lines changed Expand file tree Collapse file tree 1 file changed +4
-0
lines changed Original file line number Diff line number Diff 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);
You can’t perform that action at this time.
0 commit comments