[C++-sig] problems with lvalue_from_pytype

Mark Russell mrussell8081 at pacbell.net
Sat Nov 23 04:07:08 CET 2002


As I understand the situation from your last reply:


As I wrote several messages ago:

> So if you want to convert to HWND, your converter's execute function
> must return a reference to the type that HWND points to

<from several messages ago>

So if you want to convert to HWND, your converter's
execute function must return a reference to the type that HWND points
to (remove_pointer<HWND>::type& if your compiler supported partial
specialization, which it doesn't).

> struct convertNoddy {
> 	static HWND& execute(PyObject& o) {
> 		static long magic = call_method<long>(&o, "getMagicNum");
> 		static HWND hmagic = reinterpret_cast<HWND>(magic);
> 		return hmagic;
> 	}
> };

I cannot simply cast the int to an HWND I have to use an mpl construct that
describes the returned type.  I have read your paper on mpl and looked
through the refs--very interesting and I will want to explore this more but
I can't workout how to return this.  If vc supported partial specialization
I take it that I could do the following:

> 		return remove_pointer<HWND>::type&hmagic;

But since it doesn't I need to find a work around.  It this correct?
 Thanks --Mark

-----Original Message-----
From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org]On
Behalf Of David Abrahams
Sent: Friday, November 22, 2002 5:55 PM
To: c++-sig at python.org
Subject: Re: [C++-sig] problems with lvalue_from_pytype

Mark Russell <mrussell8081 at pacbell.net> writes:

> David,
> From your last reply:
> snip...
> One way is just to find out what the real type of the pointee is on your
> own, by
> examining the header file.
> An HWND is a pointer to an HWND__ struct defined as follows:
> struct HWND__ { int unused; };
> typedef struct HWND__* HWND
> I have attached three files noddy.cpp cn.cpp, and cnl.cpp-- cnl
> contains my conversion for noddy objects just using longs cn does
> the same thing using HWND.  The following python session shows how
> it works for longs:
> C:\developer\com-hacking\boost hacking\convert noddy long>python
> Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import noddy,cnl
>>>> n=noddy.noddy()
>>>> m=cnl.magic()
>>>> m.magicnum
> 1957
>>>> m.magicnum=n
>>>> m.magicnum
> 453311
> cnl (convert noddy long) contains a struct called magic with a single data
> member--magicnum.  The struct initializes magicnum to 1957.  Noddy's all
> have an int value attribute 453311.  I assign a noddy to m.magicnum
> (setattr) and my converter correctly retrieves values and assigns it to
> magicnum data member.  The problem is indeed occurring when I try to do
> same thing using pointers (my attempt is in cn.cpp).  I just want to pass
> int from python to my converter--have the converter cast the int to an
> (pointer).  How does knowing the real type help me in this situation?

                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

C++-sig mailing list
C++-sig at python.org

More information about the Cplusplus-sig mailing list