Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-12-07 14:48:24

As it says in the documentation, the first step if you can't avoid the
problem is to figure out what the pointer means. As far as the API is
concerned, if you could (theoretically) change all void*s to the following
without changing the semantics.
    class MagicNumber {
        private: void* value;
        friend SomethingBehindTheAPIWallWhichExtractsValue;
then you could wrap the void* by sticking it in a CObject (see the Python
documentation on CObject). The correct to_/from_python functions for void*
<-> CObject should be fairly obvious. In fact, I think it might be
appropriate to add them to the BPL's set of default conversions, though I
worry a bit about picking up the to_python(void*) conversions
unintentionally for other pointers. Let me know how it works out for you.

Do you have some C++ code which will check the pointer for when it is passed
as a parameter? If not, you may find yourself crashing the program from
Python. I generally think of Python as an arena in which I can play without
crashing anything, so this is something to consider (and one reason I didn't
put automatic arbitrary pointer conversions into the BPL).

Another thing to keep in mind is that you will be creating a new CObject
instance each time a wrapped void* is returned from a function. I'm not sure
whether Python effectively implements __cmp__ or __hash__ for these objects.
If not, it will rely on Python object identity for equality checks, so,

void* null() { return 0; } // wrap this

>>> null() == null()

Not neccessarily what you expected. On the other hand, if you're just
passing these back and forth to C++ without expecting them to be useful from
Python, you'll be fine.



To: David Abrahams/Dragon Systems USA_at_Dragon Systems USA
Subject: Py_cpp and void*
Is there an issue wrapping void* as parameters and/or return values?
Or rather, since one typically casts such a thing, and Python can't do that,
how would
you recommend handling a void*? It comes up in utterance handling and in

Boost list run by bdawes at, gregod at, cpdaniel at, john at