Fix Python's handling of nsACString's with embedded null bytes.

Not part of the default build.


git-svn-id: svn://10.0.0.236/trunk@213667 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mhammond%skippinet.com.au
2006-10-15 10:53:15 +00:00
parent e0783e5272
commit 141a19ec82

View File

@@ -115,12 +115,17 @@ PyObject_FromNSString( const nsACString &s, PRBool bAssumeUTF8 /*= PR_FALSE */)
const nsCString temp(s);
ret = PyUnicode_DecodeUTF8(temp.get(), temp.Length(), NULL);
} else {
ret = PyString_FromStringAndSize(NULL, s.Length());
nsAString::size_type len = s.Length();
ret = PyString_FromStringAndSize(NULL, len);
if (!ret)
return NULL;
// Need "CopyAsciiTo"!?
char* dest = PyString_AS_STRING(ret);
PL_strncpy(dest, s.BeginReading(), s.Length());
// Need "CopyAsciiTo"!? Worse - since libxul,
// nsACString appears to have no const_iterator!
char* dest = PyString_AS_STRING(ret);
nsAString::size_type i;
for (i=0;i<len;i++)
dest[i] = s[i];
// Python string pre-terminated when created - so done!
}
}
return ret;