That depends on the specific win32 interface you want to call.
Typically, the answer is "yes".
> Is there any plan to get ctypes batteries into the standard Python build?
I don't have such a plan. To my knowledge, ctypes has never been
contributed to Python, either, so its author apparently has no plan,
either.
Regards,
Martin
> Is there any plan to get ctypes batteries into
> the standard Python build?
It is unlikely that ctypes will be included in the standard Python
build as it allows unsafe memory access making it much easier to crash
Python.
Neil
Has anyone from Python.org asked him or her?
I can't answer that question. I haven't (and I personally
share Neil Hodgson's reservation wrt. to the possibility
of crashing the interpreter).
Regards,
Martin
Does extending Python with any C/C++ function not do the same thing?
I have used _winreg and I see winsound in the doc.
I need to call GetVersionInfo() and handle VERSIONINFO information. I
thought that distutils might have something, but I do not see it yet.
Any suggestions?
> Neil Hodgson wrote:
>> It is unlikely that ctypes will be included in the standard Python
>> build as it allows unsafe memory access making it much easier to crash
>> Python.
> Does extending Python with any C/C++ function not do the same thing?
No. It is the responsibility of the extension author to ensure that
there is no possibility of crashing Python. With ctypes, you have a
generic mechanism that enables Python code to cause a crash.
Neil
http://docs.python.org/lib/module-dl.html
would seem to also do that.
You could write this specific API in VB, and then run cscript.exe in
a pipe; or you could write a wrapper module just for that specific
API (in case PythonWin is too large for you).
Regards,
Martin
That's correct. It has the same (unhealable) flaw.
No surprise, though: it provides the same functionality.
Regards,
Martin
Aahhh, come on. ctypes is crazy useful. Besides:
exarkun@kunai:~$ python < .
Segmentation fault
exarkun@kunai:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import marshal
>>> for i in range(1024):
... try:
... marshal.loads(os.urandom(16))
... except:
... pass
...
Segmentation fault
exarkun@kunai:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dl
>>> dl.open('/lib/libc.so.6').call('memcpy', 1, 2, 3)
Segmentation fault
exarkun@kunai:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.setrecursionlimit(1000000000)
__main__:1: DeprecationWarning: integer argument expected, got float
>>> (lambda f: f(f))(lambda f: f(f))
Segmentation fault
exarkun@kunai:~$
I could probably dig up a few more, if you want. So what's ctypes on top of this?
Jean-Paul
>
> Neil
>--
>http://mail.python.org/mailman/listinfo/python-list
>
another one:
cfbolz@gauss:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import weakref
>>> ref = None
>>> class Target:
... def __del__(self):
... global ref
... ref = weakref.ref(self)
...
>>> def g():
... w = Target()
... w = None
... print ref()
...
>>> g()
Segmentation fault
There are dozends of segfaults in Python indeed.
Cheers,
Carl Friedrich Bolz
I cannot find any way to get to GetVersionInfo in VBScript (cscript).
If so, this appears to leave me with no choice but to produce a Windows
executable, whether a .exe or C code wrapped from Python. Right?
Well, in VB6, you have ctypes. So you can call any API function you
like to.
For one implementation, see
http://www.andreavb.com/tip030020.html
Regards,
Martin
As the author, I would be happy to see ctypes included with the standard
Python build.
Thomas
> I cannot find any way to get to GetVersionInfo in VBScript (cscript).
Set objFSO = CreateObject("Scripting.FileSystemObject")
Wscript.Echo objFSO.GetFileVersion("c:\bin\SciLexer.dll")
Neil
Many thanks. Just what I needed. (Short of ctypes.) Thank you for
tolerating a VBScript question here.
This information is provided with sys.getwindowsversion().
> As the author, I would be happy to see ctypes included with the
> standard Python build.
I'm sure you know the magical incantation to get that to happen ...
1. Propose it on python-dev.
2. Commit to maintain it in the python core (or alternatively, propose
to use the ElementTree maintenance method).
3. Get it accepted by Guido.
4. Do it.
If a library isn't put forward for inclusion by the *author*, it won't
be included - even if it's obviously best-of-breed. This was the
sticking point for ElementTree (until the author found out what was
going on and happily put it forward).
Tim Delaney
I have done 1. I commit myself to 2. I promise to do 3., if someone
convinces Guido to accept it (or whoever has the power to accept it).
This is my response to Martin v. Löwis, who wrote:
> I don't have such a plan. To my knowledge, ctypes has never been
> contributed to Python, either, so its author apparently has no plan,
> either.
It has been proposed to include it in core Python, but Guido didn't
accept it. The thread starts here:
http://mail.python.org/pipermail/python-dev/2004-January/thread.html#41814
And Guido's last word was this (see the end of the message):
http://mail.python.org/pipermail/python-dev/2004-January/041856.html
Thomas
Cya,
Gerald
-----Ursprüngliche Nachricht-----
Von: python-list-bounces+gerald.klix=kli...@python.org
[mailto:python-list-bounces+gerald.klix=kli...@python.org] Im Auftrag von
Thomas Heller
Gesendet: Dienstag, 10. Januar 2006 12:07
An: pytho...@python.org
Betreff: Re: Calling foreign functions from Python? ctypes?
http://mail.python.org/pipermail/python-dev/2004-January/thread.html#41814
http://mail.python.org/pipermail/python-dev/2004-January/041856.html
> I read the whol email thread carefully and could not find any sentence by
> Guido, which states that he does not accept ctypes for the standard library.
> He just declined to rewrite winreg. Did I miss something?
Maybe I misinterpreted what he wrote myself. Ok, I'll propose on
python-dev to include ctypes into core python.
Thomas
He didn't accept it - he didn't reject it, either.
Notice that this thread did *not* propose to include ctypes: instead,
it suggested to include ctypes *in order to implement _winreg*.
This is something completely different, and this is what Guido
rejected: Implementing _winreg with ctypes is indeed a bad idea,
IMO. Whether or not ctypes should be included is a different story.
Regards,
Martin
It was a misunderstanding then - I simply wanted to demonstrate how some
of the _winreg functions could be implemented with ctypes.
Anyway, I've just posted a request to include ctypes to python-dev.
We'll see.
Thomas
Ctypes doesn't work to call arbitrary C++ code, is that correct?
Skip
Yes, that's correct. It doesn't do C++ name-(un)mangling, nor has it
the C++ calling conventions. And so on...
Thomas