[PATCH] fix unicode string encoding/decoding in python bindings

John (J5) Palmieri johnp at redhat.com
Thu Sep 22 06:44:07 PDT 2005


On Thu, 2005-09-22 at 01:46 +0100, Robert McQueen wrote:
> John (J5) Palmieri wrote:
> > Is that right?  c_str is typed as a char * and is not a python object.
> > Does Pyrex allow this operation on char * types?  Other than that it
> > looks good.
> 
> It compiles (although compiling even without my patch the generated
> dbus_bindings.c has hundreds of warnings) and seems to work, both my
> service and client use the python bindings at the moment, and I've fed
> Arabic glyphs through and they've come out fine at the other end. I
> don't see how this could happen if Pyrex wasn't boxing the char * into a
> Python string object for us - I think thats the general idea.
> 
> Regards,
> Rob

It is weird but so many things are in Pyrex:


01 def do_test():
02   cdef char *test
03
04   b = "cool"
05
06   test = b
07
08   print test.decode('utf8')

  /* "/home/quinticent/test.pyx":8 */
  __pyx_2 = PyString_FromString(__pyx_v_test); if (!__pyx_2)
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  __pyx_3 = PyObject_GetAttr(__pyx_2, __pyx_n_decode); if (!__pyx_3)
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0];
__pyx_lineno = 8; goto __pyx_L1;}
  Py_INCREF(__pyx_n_utf8);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_n_utf8);
  __pyx_4 = PyObject_CallObject(__pyx_3, __pyx_2); if (!__pyx_4)
{__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  if (__Pyx_PrintItem(__pyx_4) < 0) {__pyx_filename = __pyx_f[0];
__pyx_lineno = 8; goto __pyx_L1;}
  Py_DECREF(__pyx_4); __pyx_4 = 0;
  if (__Pyx_PrintNewline() < 0) {__pyx_filename = __pyx_f[0];
__pyx_lineno = 8; goto __pyx_L1;}


Good to go.  Do you have commit access or do you need me to commit the
patch?

-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list