MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / CastPyArg2String

Function CastPyArg2String

paddle/fluid/pybind/op_function_common.cc:500–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

498}
499
500std::string CastPyArg2String(PyObject* obj,
501 const std::string& op_type,
502 ssize_t arg_pos) {
503 if (PyObject_CheckString(obj)) {
504 Py_ssize_t size = 0;
505 const char* data = nullptr;
506 data = PyUnicode_AsUTF8AndSize(obj, &size);
507 return std::string(data, (size_t)size); // NOLINT
508 } else {
509 PADDLE_THROW(common::errors::InvalidType(
510 "%s(): argument (position %d) must be "
511 "str, but got %s",
512 op_type,
513 arg_pos + 1,
514 ((PyTypeObject*)obj->ob_type)->tp_name)); // NOLINT
515 }
516
517 return "";
518}
519std::string CastPyArg2String(PyObject* obj,
520 const std::string& op_type,
521 ssize_t arg_pos,

Callers 10

static_api_parameterFunction · 0.85
static_api_set_parameterFunction · 0.85
run_python_opFunction · 0.85
parse_attrFunction · 0.85
CastPyArg2ScalarFunction · 0.85
CastPyArg2AttrStringFunction · 0.85

Calls 1

PyObject_CheckStringFunction · 0.85

Tested by

no test coverage detected