Thread View: pl.comp.lang.python
3 messages
3 total messages
Started by kenubi
Wed, 15 Sep 2010 14:58
[C] PyUnicode_FromFormat(%U) -crash
Author: kenubi
Date: Wed, 15 Sep 2010 14:58
Date: Wed, 15 Sep 2010 14:58
30 lines
1636 bytes
1636 bytes
Mam dziwny objaw (python 3.1.2 / gcc 4.5.0).
w module pomocniczym w C używam ~takiej konstrukcji:
static PyObject *w_cudzyslowy (PyObject *self,PyObject *uo)
{
PyObject *tmp;
tmp = PyUnicode_FromFormat("'%U'", uo);
return tmp;
}
uo - jest oczywiście obiektem Unicode.
I program po chwili upada - naruszenie ochrony pamięci.
Sprawdzam banalnie wyrzucajac sobie wartosci (bo może jakieś PL znaczki(?)).
print(type(value))
<class 'str'>
print("<%s>" % value)
<>
util.w_cudzyslow('dupa')
"'dupa'"
util.w_cudzyslow('')
Naruszenie ochrony pamieci.
"SystemError:Object/unicodeobject:438:bad argument to internal function"
Najwyraźniej dla pustego stringu (unicode) następuje upadek (dla "%U" też)
czy ja czegoś nie wiem?
Re: [C] PyUnicode_FromFormat(%U) -crash
Author: Artur M. Piwko
Date: Thu, 16 Sep 2010 06:35
Date: Thu, 16 Sep 2010 06:35
36 lines
2147 bytes
2147 bytes
In the darkest hour on Wed, 15 Sep 2010 16:58:49 +0200,
kenubi <nono@no.pl> screamed:
> Mam dziwny objaw (python 3.1.2 / gcc 4.5.0).
>
> w module pomocniczym w C używam ~takiej konstrukcji:
>
> static PyObject *w_cudzyslowy (PyObject *self,PyObject *uo)
> {
> PyObject *tmp;
> tmp = PyUnicode_FromFormat("'%U'", uo);
> return tmp;
> }
>
> uo - jest oczywiście obiektem Unicode.
>
Z tego co widzę...
PyObject* PyUnicode_FromFormat(const char *format, ...) ¶
Take a C printf()-style format string and a variable number of
arguments, calculate the size of the resulting Python unicode string and
return a string with the values formatted into it. The variable
^^^^^^^^^^^^
arguments must be C types and must correspond exactly to the format
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
characters in the format ASCII-encoded string. [...]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
http://docs.python.org/dev/py3k/c-api/unicode.html?highlight=pyunicode_fromformat#PyUnicode_FromFormat
--
[ Artur M. Piwko : Pipen : AMP29-RIPE : RLU:100918 : From == Trap! : SIG:239B ]
[ 08:33:17 user up 12562 days, 20:28, 1 user, load average: 0.94, 0.10, 0.06 ]
Women are nothing but machines for producing children. -- Napolean Bonaparte
Re: [C] PyUnicode_FromFormat(%U) -crash
Author: kenubi
Date: Thu, 16 Sep 2010 09:20
Date: Thu, 16 Sep 2010 09:20
22 lines
1895 bytes
1895 bytes
Artur M. Piwko wrote: > In the darkest hour on Wed, 15 Sep 2010 16:58:49 +0200, > kenubi <nono@no.pl> screamed: > return a string with the values formatted into it. The variable > ^^^^^^^^^^^^ > arguments must be C types and must correspond exactly to the format > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > characters in the format ASCII-encoded string. [...] > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > http://docs.python.org/dev/py3k/c- api/unicode.html?highlight=pyunicode_fromformat#PyUnicode_FromFormat > rozumiałem, że jednak tabelka: %U PyObject* A unicode object. Ewentualnie nie rozumiem tego zdania poprawnie (słaby ang.). Zresztą dla ciągów niepustych działa (z PL znakami też). Mogę sobie wpisywać 'żółty', ' ','żółty bocian' ale jak dam '' to wysypuje się.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads