MCPcopy Create free account
hub / github.com/SamuraiT/mecab-python3 / SWIG_Python_str_AsChar

Function SWIG_Python_str_AsChar

src/MeCab/MeCab_wrap.cpp:809–827  ·  view source on GitHub ↗

Warning: This function will allocate a new string in Python 3, * so please call SWIG_Python_str_DelForPy3(x) to free the space. */

Source from the content-addressed store, hash-verified

807 * so please call SWIG_Python_str_DelForPy3(x) to free the space.
808 */
809SWIGINTERN char*
810SWIG_Python_str_AsChar(PyObject *str)
811{
812#if PY_VERSION_HEX >= 0x03000000
813 char *newstr = 0;
814 str = PyUnicode_AsUTF8String(str);
815 if (str) {
816 char *cstr;
817 Py_ssize_t len;
818 PyBytes_AsStringAndSize(str, &cstr, &len);
819 newstr = (char *) malloc(len+1);
820 memcpy(newstr, cstr, len+1);
821 Py_XDECREF(str);
822 }
823 return newstr;
824#else
825 return PyString_AsString(str);
826#endif
827}
828
829#if PY_VERSION_HEX >= 0x03000000
830# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) )

Callers 4

SWIG_Python_AddErrorMsgFunction · 0.85
SWIG_Python_AddErrMesgFunction · 0.85
SWIG_Python_TypeErrorFunction · 0.85
MeCab_wrap.cppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected