[Python-bugs-list] [ python-Bugs-566631 ] PyUnicode_Find() returns wrong results
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 10 Jun 2002 03:52:51 -0700
Bugs item #566631, was opened at 2002-06-09 20:25
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=566631&group_id=5470
Category: Unicode
Group: Python 2.1.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Andreas Jung (ajung)
>Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: PyUnicode_Find() returns wrong results
Initial Comment:
The following is used to search for u'h' inside
the string u'+#&.' (stored in self->seperator)
static PyObject *
Splitter_test(Splitter *self) {
PyObject *test, *res, *word;
test = Py_BuildValue("s","h");
word =
PyUnicode_FromEncodedObject(test,"ascii","strict");
printf("seperator: ");
PyObject_Print(self->seperator, stdout, 0);
puts("");
printf("Searching for: ");
PyObject_Print(word, stdout, 0);
puts("");
res = PyUnicode_Find(self->seperator, word, 0,
PyUnicode_GET_SIZE(self->seperator), 1);
if (res==0) puts("not found");
else puts("found");
}
The output is:
yetix(366)% python2.1 test.py
seperator: u'+#&.'
Searching for: u'h'
found
So PyUnicode_Find() returns a match although
u'h' is not contained within self->seperator.
Env: Linux 2.4, Python 2.1.3
----------------------------------------------------------------------
Comment By: Andreas Jung (ajung)
Date: 2002-06-10 06:48
Message:
Logged In: YES
user_id=11084
Looking it the source, it is a documentation bug since
PyUnicode_Find() really returns int.
Can you assign this issue to Fred to fix the docs *wink*?
-aj
----------------------------------------------------------------------
Comment By: Andreas Jung (ajung)
Date: 2002-06-10 06:45
Message:
Logged In: YES
user_id=11084
So what does PyUnicode_Find() return?
>From the docs:
PyObject* PyUnicode_Find(PyObject *str, PyObject *substr,
int start, int end, int direction)
Return value: New reference.
Return the first position of substr in str[start:end] using
the given direction (direction == 1 means to do a forward
search, direction == -1 a backward search), 0 otherwise.
Does it return an int with the position or a PyObject * ?
-aj
----------------------------------------------------------------------
Comment By: M.-A. Lemburg (lemburg)
Date: 2002-06-10 05:17
Message:
Logged In: YES
user_id=38388
You should check what res actually is rather then doing
the check for == 0. Note that res == -1 means
"not found", res == 0 maps to: match found at position
0.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=566631&group_id=5470