L
Lonnie Princehouse
There doesn't seem to be any way to customize the behavior of "is" as
can be done for other operators... why not?
can be done for other operators... why not?
Lonnie said:There doesn't seem to be any way to customize the behavior of "is" as
can be done for other operators... why not?
Lonnie said:Dangit! I need to find a less honest programming language. Anyone
have a Perl cookbook handy? ...
There doesn't seem to be any way to customize the behavior of "is" as
can be done for other operators... why not?
Dangit! I need to find a less honest programming language. Anyone
have a Perl cookbook handy? ...
I will adopt my usual stance here of unequivocally stating that there isLonnie said:Well, mostly out of principle ;-)
But also because I'm wrapping a C library which passes around C structs
which are wrapped in shim C++ classes for a Boost.Python layer. Boost
Python does a marvelous job of translating between Python and C++ data
types; when a C structure is returned, it magically translates that
structure into a Python wrapper. The problem is that a _new_ Python
wrapper is created every time a pointer is returned, even if a wrapper
already exists for that particular pointer.
To illustrate: Suppose you have a function in C++ which is a simple
identity function, e.g.
template <typename T>
T *identity (T *x) {
return x;
}
Calling the wrapped version of this function from Python will produce a
Python wrapper which represents the same underlying C++ object, but is
not actually the same Python object:
False
I wanted to override the behavior of "is" so that (a is b) would be
True --- which shouldn't have caused a problem, since the wrapper
class's attributes are read-only from Python. As it is, I've overriden
__cmp__ and __hash__, so at least I get the correct dictionary behavior
True
It's quite possible that there is some way to do this correctly from
the Boost.Python side of things... my understanding of how to use
Boost.Python is minimal.
Well, mostly out of principle ;-)
But also because I'm wrapping a C library which passes around C structs
which are wrapped in shim C++ classes for a Boost.Python layer. Boost
Python does a marvelous job of translating between Python and C++ data
types; when a C structure is returned, it magically translates that
structure into a Python wrapper. The problem is that a _new_ Python
wrapper is created every time a pointer is returned, even if a wrapper
already exists for that particular pointer.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.