MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / py_str_as_str

Function py_str_as_str

libsigrokdecode4DSL/util.c:391–420  ·  view source on GitHub ↗

* Get the value of a Python unicode string object, returned as a newly * allocated char *. * * @param[in] py_str The unicode string object. * @param[out] outstr ptr to char * storage to be filled in. * * @return SRD_OK upon success, a (negative) error code otherwise. * The 'outstr' argument points to a malloc()ed string upon success. * * @private */

Source from the content-addressed store, hash-verified

389 * @private
390 */
391SRD_PRIV int py_str_as_str(PyObject *py_str, char **outstr)
392{
393 PyObject *py_bytes;
394 char *str;
395 PyGILState_STATE gstate;
396
397 gstate = PyGILState_Ensure();
398
399 if (!PyUnicode_Check(py_str)) {
400 srd_dbg("Object is not a string object.");
401 PyGILState_Release(gstate);
402 return SRD_ERR_PYTHON;
403 }
404
405 py_bytes = PyUnicode_AsUTF8String(py_str);
406 if (py_bytes) {
407 str = g_strdup(PyBytes_AsString(py_bytes));
408 Py_DECREF(py_bytes);
409 if (str) {
410 *outstr = str;
411 PyGILState_Release(gstate);
412 return SRD_OK;
413 }
414 }
415 srd_exception_catch(NULL, "Failed to extract string");
416
417 PyGILState_Release(gstate);
418
419 return SRD_ERR_PYTHON;
420}
421
422/*
423*/

Callers 8

py_attr_as_strFunction · 0.85
py_dictitem_as_strFunction · 0.85
py_listitem_as_strFunction · 0.85
py_dict_value_to_strFunction · 0.85
get_optionsFunction · 0.85
get_annotation_rowsFunction · 0.85
srd_decoder_doc_getFunction · 0.85

Calls 1

srd_exception_catchFunction · 0.85

Tested by

no test coverage detected