MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ConvertOneString

Function ConvertOneString

tensorflow/python/lib/core/py_seq_tensor.cc:446–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

444// String support
445
446const char* ConvertOneString(PyObject* v, string* out) {
447 if (PyBytes_Check(v)) {
448 out->assign(PyBytes_AS_STRING(v), PyBytes_GET_SIZE(v));
449 return nullptr;
450 }
451 if (PyUnicode_Check(v)) {
452#if PY_MAJOR_VERSION >= 3
453 Py_ssize_t size;
454 const char* str = PyUnicode_AsUTF8AndSize(v, &size);
455 if (str == nullptr) return ErrorConvertingUnicodeString;
456 out->assign(str, size);
457 return nullptr;
458#else
459 PyObject* py_str = PyUnicode_AsUTF8String(v);
460 if (py_str == nullptr) return ErrorConvertingUnicodeString;
461 out->assign(PyBytes_AS_STRING(py_str), PyBytes_GET_SIZE(py_str));
462 Py_DECREF(py_str);
463 return nullptr;
464#endif
465 }
466 return ErrorMixedTypes;
467}
468
469DEFINE_HELPER(ConvertString, string, DT_STRING, ConvertOneString);
470

Callers 1

PyReprFunction · 0.85

Calls 1

assignMethod · 0.45

Tested by

no test coverage detected