len-l | 2 Jan 2005 22:29

Re: Setting a pointer to NULL

On 30 Dec 2004 at 20:43, Thomas Heller wrote:

> It's the intended behaviour that POINTER(ctype)() creates a NULL
> pointer, so that has to be the recommended way up currently.
> 
> But, assigning None to structure fields containing POINTER types
> *should* also work, so I've changed this in CVS.
> 
> Thanks for the heads up.
> 
Your welcome. And thanks for the information. I have forwarded it to
comp.lang.python where I had earlier posted a ctypes example.

Lenard Lindstrom
<len-l <at> telus.net>

-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
Guillaume Proux | 4 Jan 2005 07:13

Re: Looking for examples of DirectX filter written in ctypes.com

Hi Dave,

Thank you for your answer.

Yes, I did add the needed reg keys into the places you indicate in your 
email.
For the rest, i thought this is a typical COM stuff that ctype.com knew 
how to deal with.
The ctypes.pyd DLL that should be used by COM when instantiating my 
server clearly exports DllGetClassObject and DllCanUnloadNow...

The only thing which I am totally confused with is the FilterData that 
appears in the {083863F1-70DE-11d0-BD40-00A0C911CE86} sub-regkey

This could be the cause of my issue but the MSDN doc as to how to 
generate that data is hard to come by.

Thanks... and a Merry New Year!

Guillaume

>
> Hi Guillaume,
>
> I've written one in C++ and for quite some time debated whether or not 
> to redo it in Python (I hate maintaining & modifying that C++ code! :) ).
>
> Anyway, have you confirmed that your filter is writing to the Windows 
> registry all the necessary entries? You at least need to have entries in
>
(Continue reading)

Guillaume Proux | 4 Jan 2005 09:03

Re: Looking for examples of DirectX filter written in ctypes.com

Dave,

Re-answering to myself, I eventually managed to get the filter to appear 
in the grafedit list.
The problem came from the fact that being very new to DirectShow and the 
rest, I was reluctant to touch too many things at the same time.
However, since then, I wrote big pieces of program with ctypes.com and 
felt a bit more confident.
Eventually, instantiating the FilterMapper2 and passing it all the 
correct information did the job!
This is one issue with Python... Everything is so easy that you start 
being lazy and do not want to do all the painful stuff that Microsoft 
exposes us to!

Great.

If I ever manage to finish writing this filter and if it works (!!!), I 
consider posting it as a O'Reilly recipes.

Guillaume

Dave Brueck wrote:

> Hi Guillaume,
>
> I've written one in C++ and for quite some time debated whether or not 
> to redo it in Python (I hate maintaining & modifying that C++ code! :) ).
>
> Anyway, have you confirmed that your filter is writing to the Windows 
> registry all the necessary entries? You at least need to have entries in
(Continue reading)

Simon Wittber | 6 Jan 2005 07:52
Picon
Gravatar

ctypes vs pyrex vs C

I'm considering the use of ctypes to allow my python software to talk
directly to SDL.dll and libSDL.so. I wish to do this to avoid the
somewhat hefty pygame dependency.

I specifically want to use the SDL window management and input event
handling functions.

The event handling functions will be called hundreds of times per second.

Will I experience any significant speed difference between using
ctypes and, say, pyrex or pygame? (pygame is a C extension which wraps
SDL)

Sw.

-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
Niki Spahiev | 6 Jan 2005 09:07
Picon

Re: ctypes vs pyrex vs C

Simon Wittber wrote:
> I'm considering the use of ctypes to allow my python software to talk
> directly to SDL.dll and libSDL.so. I wish to do this to avoid the
> somewhat hefty pygame dependency.
> 
> I specifically want to use the SDL window management and input event
> handling functions.
> 
> The event handling functions will be called hundreds of times per second.
> 
> Will I experience any significant speed difference between using
> ctypes and, say, pyrex or pygame? (pygame is a C extension which wraps
> SDL)

IMO start with ctypes then profile and compile some parts with pyrex. 
Pyrex and pygame should be equally fast.

Niki Spahiev

-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
Thomas Heller | 6 Jan 2005 22:16
Favicon

Re: ctypes vs pyrex vs C

Simon Wittber <simonwittber <at> gmail.com> writes:

> I'm considering the use of ctypes to allow my python software to talk
> directly to SDL.dll and libSDL.so. I wish to do this to avoid the
> somewhat hefty pygame dependency.
>
> I specifically want to use the SDL window management and input event
> handling functions.
>
> The event handling functions will be called hundreds of times per second.

I'm much interested in a not too small, and not too large,
cross-platform libary wrapping with ctypes as a reference
implementation, and might even spend some work myself.
Is SDL such a library, and will your work be open source?

I have a toolchain, nearly production ready, that creates ctypes
wrappers from header files automatically.  As a proof of concept, I
created a wrapping for GLUT, which went very well - although some manual
hacking on the created file was necessary.

Thomas

-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
Simon Wittber | 7 Jan 2005 01:34
Picon
Gravatar

Re: ctypes vs pyrex vs C

> I'm much interested in a not too small, and not too large,
> cross-platform libary wrapping with ctypes as a reference
> implementation, and might even spend some work myself.
> Is SDL such a library, and will your work be open source?

SDL stands for 'Simple Directmedia Layer' and is used to provide cross
platform graphics, audio and input handling for game-like
applications. I did about 30 minutes work on this last night, which
you can view here:

http://metaplay.com.au/svn/LGT/

The ctypes wrapper is under the SDL folder. I've not achieved much
yet, but am attempting something similar to what you describe below.

> I have a toolchain, nearly production ready, that creates ctypes
> wrappers from header files automatically.  As a proof of concept, I
> created a wrapping for GLUT, which went very well - although some manual
> hacking on the created file was necessary
.
Is this toolchain open source?

Sw.

-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
Thomas Heller | 7 Jan 2005 21:42
Favicon

Re: ctypes vs pyrex vs C

Thomas Heller <theller <at> python.net> writes:

[about wrapping SDL with ctypes]

> All this stuff requires the CVS version of ctypes, which is not yet
> released. But as I said, I will prepare a zip containing ctypes snapshot
> binary windows installers, the gccxml setup program, and the generated
> SDL files.  Only tested on Windows, so expect a couple of bugs under
> linux or whatever you use.

Here's the zipfile (~ 2MB):
http://starship.python.net/crew/theller/ctypes-codegen-20050107.zip

Contains:

binary ctypes installers for windows, Python 2.3 and 2.4:
  ctypes-0.9.3-win32-py2.3.exe
  ctypes-0.9.3-win32-py2.4.exe

An unofficial, binary windows installer for gccxml:
  snapshot/gccxml-20041217-setup.exe

  AFAIK, MSVC is required to run gccxml, because gccxml needs the MSVC
  header files.

  Linux/Mac users must get gccxml from CVS (the released 0.6 version
  doesn't have the features required) and build from source.

  If you don't want to build/install gccxml, you can use the genereated
  sdl.xml file which is also included.
(Continue reading)

Thomas Heller | 7 Jan 2005 20:27
Favicon

Re: ctypes vs pyrex vs C

Simon Wittber <simonwittber <at> gmail.com> writes:

>> I'm much interested in a not too small, and not too large,
>> cross-platform libary wrapping with ctypes as a reference
>> implementation, and might even spend some work myself.
>> Is SDL such a library, and will your work be open source?
>
> SDL stands for 'Simple Directmedia Layer' and is used to provide cross
> platform graphics, audio and input handling for game-like
> applications. I did about 30 minutes work on this last night, which
> you can view here:
>
> http://metaplay.com.au/svn/LGT/
>
> The ctypes wrapper is under the SDL folder. I've not achieved much
> yet, but am attempting something similar to what you describe below.

I haven't seen this, but it seems I didn't miss too much (except for the
constants module, maybe).

>> I have a toolchain, nearly production ready, that creates ctypes
>> wrappers from header files automatically.  As a proof of concept, I
>> created a wrapping for GLUT, which went very well - although some manual
>> hacking on the created file was necessary
> .
> Is this toolchain open source?

Yes, and I'll upload a snapshot somewhere this night.  The toolchain
consists of two scripts, and it requires gccxml to be installed.

(Continue reading)

Thomas Heller | 7 Jan 2005 21:23
Favicon

wrapping api calls with decorators

I've checked in a preliminary 'decorators' module into ctypes CVS.  The
decorators are used to simplify calling functions exported from dlls.

There are two variants: stdcall for the __stdcall calling convention,
cdecl for the standard C calling convention, named __cdecl on Windows.

This is a simple example wrapping the ansi MessageBox api function:

 <at>  stdcall(c_int, "user32", [HWND, LPCTSTR, LPCTSTR, c_uint])
def MessageBoxA(hwnd, text, title=None, flags=MB_OK):
    "Display a message box"

That's all, for simple cases!
stdcall() and cdecl() require three arguments, the first specifying the
return type of the function, the second is the name (or pathname) of the
dll that exports this function, and the third is a sequence specifying
the argument types.

The name of the exported function is supplied by the decorated function
itself.  In simple cases, the decorated function does not need to
have a function body - the decorator creates a function body which will
call the exported function, with all parameters that the decorated
function has, and returns the result.

Sometimes, this is not enough: Consider the win32 GetModuleFileNameA
function, which retrieves the full pathname of the specified module.
We do not want to have the caller allocate a buffer which will be filled
with the pathname, so we do this in the function body.  The exported
function can then be called by calling the 'magic' _api_ symbol:

(Continue reading)


Gmane