[Cython] libcpp.string operators

Lisandro Dalcin dalcinl at gmail.com
Wed Apr 20 16:09:54 CEST 2011


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.


-- 
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169


More information about the cython-devel mailing list