<rdar://problem/13499317>

Enabling Python commands to produce Unicode output via:

result.PutCString(u”whatever”)

llvm-svn: 180930
This commit is contained in:
Enrico Granata 2013-05-02 17:29:04 +00:00
parent 9ee5840de4
commit e55f77aec8
3 changed files with 25 additions and 2 deletions

View File

@ -84,7 +84,7 @@ public:
SetImmediateErrorFile (FILE *fh);
void
PutCString(const char* string, int len = -1);
PutCString(const char* string, int len);
// wrapping the variadic Printf() with a plain Print()
// because it is hard to support varargs in SWIG bridgings

View File

@ -442,3 +442,26 @@
#endif
$result = PyFile_FromFile($1, const_cast<char*>(""), mode, fclose);
}
%typemap(in) (const char* string, int len) {
if ($input == Py_None)
{
$1 = NULL;
$2 = 0;
}
else if (PyUnicode_Check($input))
{
$1 = PyString_AsString(PyUnicode_AsUTF8String($input));
$2 = strlen($1);
}
else if (PyString_Check($input))
{
$1 = PyString_AsString($input);
$2 = PyString_Size($input);
}
else
{
PyErr_SetString(PyExc_TypeError,"not a string-like object");
return NULL;
}
}

View File

@ -281,7 +281,7 @@ SBCommandReturnObject::PutCString(const char* string, int len)
{
if (m_opaque_ap.get())
{
if (len == 0)
if (len == 0 || string == NULL || *string == 0)
{
return;
}