Skip to content

Commit

Permalink
Fix unicode handling of strings
Browse files Browse the repository at this point in the history
Signed-off-by: Piers Harding <piers@catalyst.net.nz>
  • Loading branch information
piersharding committed Oct 4, 2011
1 parent 011868c commit 787f6c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Expand Up @@ -28,3 +28,6 @@ Added fixes, typos, and silly debug comments + removed dependence on py yaml - t

Fri Jul 15 06:16:44 NZST 2011
Fix incorrect type coersion for error handling - thanks guettli (Thomas Güttler)

Wed Oct 5 05:33:43 NZDT 2011
* fix unicode handling of strings - thanks guettli (Thomas Güttler)
14 changes: 11 additions & 3 deletions src/nwsaprfcutil.c
Expand Up @@ -155,14 +155,22 @@ SAP_UC * u8to16(PyObject *str) {
RFC_ERROR_INFO errorInfo;
SAP_UC *sapuc;
unsigned sapucSize, resultLength;
PyObject *tmp;

sapucSize = PyString_Size(str) + 1;
if (PyUnicode_Check(str)) {
tmp = PyUnicode_AsUTF8String(str);
}
else {
tmp = str;
}

sapucSize = PyString_Size(tmp) + 1;
sapuc = mallocU(sapucSize);
memsetU(sapuc, 0, sapucSize);

resultLength = 0;

rc = RfcUTF8ToSAPUC((RFC_BYTE *)PyString_AsString(str), PyString_Size(str), sapuc, &sapucSize, &resultLength, &errorInfo);
rc = RfcUTF8ToSAPUC((RFC_BYTE *)PyString_AsString(tmp), PyString_Size(tmp), sapuc, &sapucSize, &resultLength, &errorInfo);
return sapuc;
}

Expand Down Expand Up @@ -1423,7 +1431,7 @@ void set_char_value(DATA_CONTAINER_HANDLE hcont, SAP_UC *name, PyObject * value,
RFC_ERROR_INFO errorInfo;
SAP_UC *p_value;

if (! PyString_Check(value)){
if (! PyString_Check(value) && !PyUnicode_Check(value)){
SAPNW_rfc_call_error1("RfcSetChar invalid Input value type:", PyString_AsString(PyObject_Repr(value)));
return;
}
Expand Down

0 comments on commit 787f6c1

Please sign in to comment.