PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 717 - QByteArray doesn't honor \0 inside strings.
: QByteArray doesn't honor \0 inside strings.
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: QtCore
: 1.0.0
: All All
: P3 normal
Assigned To: Hugo Parente Lima
:
:
:
  Show dependency treegraph
 
Reported: 2011-03-10 21:35 EET by Hugo Parente Lima
Modified: 2011-04-29 18:06 EEST (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hugo Parente Lima 2011-03-10 21:35:15 EET
Test code:

from PySide.QtCore import *

b = QByteArray("Test")
c = QByteArray(b)
b.replace("T\0", "_")

assert(b == c)
Comment 1 Eli Stevens 2011-04-15 00:24:10 EEST
It's actually much worse than that:

>>> from PySide.QtCore import *
>>> from PySide.QtGui import *
>>> qba = QByteArray.fromRawData('a\x00b\x00c')
>>> qba.length()
1
>>> qba = QByteArray.fromRawData('a\x00b\x00c', 5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: fromRawData() takes exactly one argument (2 given)

Doesn't seem like you can have nulls in QByteArrays at all.
Comment 2 Eli Stevens 2011-04-15 01:48:46 EEST
I found a workaround for simple creation:

        qba = QByteArray()
        qba.append(data_str, len(data_str))
Comment 3 Hugo Parente Lima 2011-04-15 02:31:14 EEST
(In reply to comment #2)
> I found a workaround for simple creation:
> 
>         qba = QByteArray()
>         qba.append(data_str, len(data_str))

Plz, don't use this workaround, those C++ functions of type:

foo(const char* data, in len) will be removed because they are only necessary
on C++.

If you really need a workaround use:

qba.append(QByteArray(data_str))

A new version of PySide with whit bug fixed will be released in two weeks.
Comment 4 Hugo Parente Lima 2011-04-15 02:47:48 EEST
Fixed in commits:

apiextractor/7af96bb77c278bdae96ccdf9c67d3c66aa27e757
shiboken/79cf0547180bb6c2641d370eeaafdfc55908fa2e
pyside/13740062066be57c1494f8690fe72f2f96dd71e3

Problem with fromRawData fixed in commit:

pyside/a230b243d0e24c00a2731468ee6f2e1a3d34bd5e

Remenber that fromRawData uses the same memory of the provided data, so the
same rules for C++ applies here.
Comment 5 Eli Stevens 2011-04-15 02:49:10 EEST
Ahh, I didn't even realize that was an option.  The docs state:

http://www.pyside.org/docs/pyside/PySide/QtCore/QByteArray.html#PySide.QtCore.QByteArray

class PySide.QtCore.QByteArray
class PySide.QtCore.QByteArray(arg__1)
class PySide.QtCore.QByteArray(arg__1)
class PySide.QtCore.QByteArray(size, c)
    Parameters:    

        size – int
        arg__1 – PySide.QtCore.QByteArray
        c – char

    Constructs an empty byte array.

Which implies that QByteArray(data_str) isn't available; this is unfortunate,
since QByteArray(data_str) is all I really needed in the first place.  :-/
Comment 6 Hugo Parente Lima 2011-04-15 03:07:04 EEST
(In reply to comment #5)
> Ahh, I didn't even realize that was an option.  The docs state:
> 
> http://www.pyside.org/docs/pyside/PySide/QtCore/QByteArray.html#PySide.QtCore.QByteArray
> 
> class PySide.QtCore.QByteArray
> class PySide.QtCore.QByteArray(arg__1)
> class PySide.QtCore.QByteArray(arg__1)
> class PySide.QtCore.QByteArray(size, c)
>     Parameters:    
> 
>         size – int
>         arg__1 – PySide.QtCore.QByteArray
>         c – char
> 
>     Constructs an empty byte array.
> 
> Which implies that QByteArray(data_str) isn't available; this is unfortunate,
> since QByteArray(data_str) is all I really needed in the first place.  :-/

It's a bug in the documentation, maybe the doc must be something like:

class PySide.QtCore.QByteArray
class PySide.QtCore.QByteArray(arg__1)
class PySide.QtCore.QByteArray(arg__1)
class PySide.QtCore.QByteArray(size, c)
    Parameters:    

        size – int
        arg__1 – PySide.QtCore.QByteArray or str
        c – char

but if we have another signature like: PySide.QtCore.QByteArray(arg__1, foo)

arg__1 will be referenced in 3 signatures.. hmmm, I think we need to choose a
better way to represent C++ overloads inside a Python documentation.
Comment 7 renato filho 2011-04-29 18:06:23 EEST
PySide release 1.0.2