Mailing List Archive

use PyCObject (was: CVS: python/dist/src/PC msvcrtmodule.c,1.4,1.5 _winreg.c,1.5,1.6)
While I'm very glad that I suggested PyLong_FromVoidPtr() for issues like
this, I think that returning an HKEY should probably use a PyCObject. You
will then be able to supply a "free" function that can close the HKEY.

Cheers,
-g

On Fri, Jun 30, 2000 at 10:48:54AM -0700, Fred L. Drake wrote:
> Update of /cvsroot/python/python/dist/src/PC
> In directory slayer.i.sourceforge.net:/tmp/cvs-serv11047/PC
>
> Modified Files:
> msvcrtmodule.c _winreg.c
> Log Message:
> [.*** Not tested as I don't have Windows running right now! ***]
>
> Trent Mick <trentm@activestate.com>:
>
> Fix PC/msvcrtmodule.c and PC/winreg.c for Win64. Basically:
>
> - sizeof(HKEY) > sizeof(long) on Win64, so use PyLong_FromVoidPtr()
> instead of PyInt_FromLong() to return HKEY values on Win64
>
> - Check for string overflow of an arbitrary registry value (I know
> that ensuring that a registry value does not overflow 2**31 characters
> seems ridiculous but it is *possible*).
>
> Closes SourceForge patch #100517.
>...

--
Greg Stein, http://www.lyra.org/
RE: use PyCObject (was: CVS: python/dist/src/PC msvcrtmodule.c,1.4,1.5 _winreg.c,1.5,1.6) [ In reply to ]
> While I'm very glad that I suggested PyLong_FromVoidPtr() for issues like
> this, I think that returning an HKEY should probably use a PyCObject. You
> will then be able to supply a "free" function that can close the HKEY.

This is exactly what we do. Trents patches are just for the functions that
return the underlying handle value as an integer (which is definately a
useful thing to be able to do!)

Mark.
Re: use PyCObject (was: CVS: python/dist/src/PC msvcrtmodule.c,1.4,1.5 _winreg.c,1.5,1.6) [ In reply to ]
On Sat, Jul 01, 2000 at 11:23:21PM +1000, Mark Hammond wrote:
> > While I'm very glad that I suggested PyLong_FromVoidPtr() for issues like
> > this, I think that returning an HKEY should probably use a PyCObject. You
> > will then be able to supply a "free" function that can close the HKEY.
>
> This is exactly what we do. Trents patches are just for the functions that
> return the underlying handle value as an integer (which is definately a
> useful thing to be able to do!)

But I don't understand why you want an integer. From the Python programmer's
standpoint, they just want a handle, right?

The safety of having the "free" function is quite nice. Without it, it would
seem to be "easy" to leak handles.

Without using PyCObject, we'd need a complete handle type (like the one in
win32api or wherever).

Cheers,
-g

--
Greg Stein, http://www.lyra.org/
RE: use PyCObject (was: CVS: python/dist/src/PC msvcrtmodule.c,1.4,1.5 _winreg.c,1.5,1.6) [ In reply to ]
> > This is exactly what we do. Trents patches are just for the
> functions that
> > return the underlying handle value as an integer (which is definately a
> > useful thing to be able to do!)
>
> But I don't understand why you want an integer. From the Python
> programmer's
> standpoint, they just want a handle, right?

Yes - but there _are_ functions that return the integer. This is used
mainly so the handles can be passed to external programs, or external API
functions wrapped via SWIG, etc.

The normal case is a "handle object". The "handle object" has auto-close
ability. The "handle object" _also_ has the ability to get the raw
underlying handle, should the programmer choose.

Im afraid you will never convince me this is wrong :-)

> Without using PyCObject, we'd need a complete handle type (like
> the one in
> win32api or wherever).

That is exactly what we have. Sorry - I thought "CObject" was a generic
term for any C-implemented PyObject.

Mark.
Re: use PyCObject (was: CVS: python/dist/src/PC msvcrtmodule.c,1.4,1.5 _winreg.c,1.5,1.6) [ In reply to ]
On Sun, Jul 02, 2000 at 10:21:30AM +1000, Mark Hammond wrote:
> > > This is exactly what we do. Trents patches are just for the
> > functions that
> > > return the underlying handle value as an integer (which is definately a
> > > useful thing to be able to do!)
> >
> > But I don't understand why you want an integer. From the Python
> > programmer's
> > standpoint, they just want a handle, right?
>
> Yes - but there _are_ functions that return the integer. This is used
> mainly so the handles can be passed to external programs, or external API
> functions wrapped via SWIG, etc.

All right. I see the usage now. The checkin message didn't have enough
context, so I went and look at the darn file.

Ignore me :-)

Cheers,
-g

--
Greg Stein, http://www.lyra.org/