From 787f6c161ad85d25dda9c166cf598203385655a6 Mon Sep 17 00:00:00 2001 From: Piers Harding Date: Wed, 5 Oct 2011 05:34:41 +1300 Subject: [PATCH] Fix unicode handling of strings Signed-off-by: Piers Harding --- ChangeLog | 3 +++ src/nwsaprfcutil.c | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4d04e3b..9c5296c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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) diff --git a/src/nwsaprfcutil.c b/src/nwsaprfcutil.c index 79ede30..b530810 100644 --- a/src/nwsaprfcutil.c +++ b/src/nwsaprfcutil.c @@ -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; } @@ -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; }