Wrapping licpp.map.map into a dict-like object

43 views
Skip to first unread message

Gaël

unread,
Oct 17, 2012, 6:37:10 AM10/17/12
to cython...@googlegroups.com
Hi list,

Sorry for asking for help on something probably trivial, but I am afraid that I am being dense. I have been trying to wrap the C++ map container into a dict-like object using Cython, and I cannot seem to get it working.

So far, my best attempt is:
https://gist.github.com/3904873

However, it seems to me that it produces invalid C++ code. In the C++ version of '__new__', the constructor for the map container is called without its contained type definitions, and thus the code does not compile. I believe that this is due to the map container declared as an object-level attribute.

I am hitting this problem probably because I am not using Cython right. However, I fail to see what the right strategy would be here.

Thanks a lot for any help.

Gaël

Dag Sverre Seljebotn

unread,
Oct 17, 2012, 7:34:13 AM10/17/12
to cython...@googlegroups.com
Use a pointer to a map rather than the map itself as the object-level
attribute.

Dag Sverre

Dag Sverre Seljebotn

unread,
Oct 17, 2012, 7:35:16 AM10/17/12
to cython...@googlegroups.com
BTW, this sounds like a bug, but the support for using C++ classes by
value rather than by pointer is rather new and unstable. Robert should
comment.

Dag Sverre

Lars Buitinck

unread,
Oct 17, 2012, 7:52:17 AM10/17/12
to cython...@googlegroups.com
2012/10/17 Gaël <varo...@phare.normalesup.org>:
> Sorry for asking for help on something probably trivial, but I am afraid
> that I am being dense. I have been trying to wrap the C++ map container into
> a dict-like object using Cython, and I cannot seem to get it working.

Compiles fine with Cython 0.17.1...

--
Lars Buitinck
Scientific programmer, ILPS
University of Amsterdam

Gaël

unread,
Oct 17, 2012, 8:21:28 AM10/17/12
to cython...@googlegroups.com, l.j.bu...@uva.nl


On Wednesday, October 17, 2012 1:52:47 PM UTC+2, Lars Buitinck wrote:
Compiles fine with Cython 0.17.1...

Indeed. So I'll consider it as a Cython bug that has been fixed :). Thanks

Switching a bit gears on that: is that a way to, at Cython compilation time, fail if the Cython version is below a certain version?

Thanks for all the help,

Gaël

Robert Bradshaw

unread,
Oct 22, 2012, 9:55:58 PM10/22/12
to cython...@googlegroups.com
You could check cython.__version__ in your setup.py file. You could
also cimport cython.__version__ and check that for a runtime condition
(well, as of the next release).

- Robert
Reply all
Reply to author
Forward
0 new messages