[Cython] libcpp.string operators
Brent Pedersen
bpederse at gmail.com
Wed Apr 20 18:29:09 CEST 2011
On Wed, Apr 20, 2011 at 9:58 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Lisandro Dalcin, 20.04.2011 16:09:
>>
>> On 19 April 2011 21:22, Brent Pedersen<bpederse at gmail.com> wrote:
>>>
>>> On Tue, Apr 19, 2011 at 6:08 PM, Brent Pedersen<bpederse at gmail.com>
>>> wrote:
>>>>
>>>> On Tue, Apr 19, 2011 at 2:45 PM, Brent Pedersen<bpederse at gmail.com>
>>>> wrote:
>>>>>
>>>>> hi, i have been using a stub for the c++<string> in a lot of my work.
>>>>> i decided to have a go at doing a proper string.pxd, pasted here:
>>>>>
>>>>> https://gist.github.com/929604
>>>>>
>>>>> other than the operators, it's mostly implemented with tests. but when
>>>>> i try the operators
>>>>> with this test:
>>>>>
>>>>> def test_equal_operator(char *a, char *b):
>>>>> """
>>>>> >>> test_equal_operator("asdf", "asdf")
>>>>> True
>>>>> """
>>>>> cdef string s = string(a)
>>>>> cdef string t = string(b)
>>>>> cdef bint same = t == s
>>>>> return same
>>>>>
>>>>> and this declaration in the pxd:
>>>>>
>>>>> bint operator==(string&, string&)
>>>>
>>>>
>>>> it seems:
>>>>
>>>> bint operator==(string&)
>>>>
>>>> is the correct syntax. i had copied the stuff from vector.pxd
>>>>
>>>>>
>>>>> i get the error below. any ideas what i'm doing wrong?
>>>>> thanks,
>>>>> -brent
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> === Got errors: ===
>>>>> 152:23: Invalid types for '==' (string, string)
>>>>>
>>>>>
>>>>> ======================================================================
>>>>> ERROR: runTest (__main__.CythonRunTestCase)
>>>>> compiling (cpp) and running cpp_stl_string
>>>>> ----------------------------------------------------------------------
>>>>> Traceback (most recent call last):
>>>>> File "runtests.py", line 569, in run
>>>>> self.runCompileTest()
>>>>> File "runtests.py", line 400, in runCompileTest
>>>>> self.test_directory, self.expect_errors, self.annotate)
>>>>> File "runtests.py", line 546, in compile
>>>>> self.assertEquals(None, unexpected_error)
>>>>> AssertionError: None != u"152:23: Invalid types for '==' (string,
>>>>> string)"
>>>>>
>>>>
>>>
>>> i updated the gist with the operators, didn't do iterators.
>>> https://gist.github.com/929604
>>>
>>
>> Looks pretty good. Could you fork the devel repo, add the pxd and the
>> test at appropriate places and make a pull request? This is just in
>> order to give you credits for your work.
>
> Looks like this wasn't tested with Python 3, there are 16 failing tests more
> now.
>
> https://sage.math.washington.edu:8091/hudson/job/cython-devel-tests-py3k-cpp/952/
>
> Stefan
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> http://mail.python.org/mailman/listinfo/cython-devel
>
is the solution to prefix the string literals with 'b'? e.g.
>>> test_indexing(b"asdf")
or something else? that passes in python 2.6, 2.7 and 3.2 for me.
More information about the cython-devel
mailing list