Mailing List Archive

Difference between Win-dll's and pyd's??
"Thomas S. Strinnhed" wrote:
> Now for the questions:
> I suspect the .pyd-files to be "Python-dll's". Right??
> No: If not, what are they, and how to use them.
> Yes: If so, can I substitute .pyd's for win-dll's and vice versa
> or can they be used in any other ways??

Yes, .pyd files are dll's. But there are a few differences. If you
have a DLL named foo.pyd, then it must have a function initfoo(). You
can then write Python "import foo", and Python will search for foo.pyd
(as well as foo.py, foo.pyc) and if it finds it, will attempt to call
initfoo() to initialize it. You do not link your .exe with foo.lib,
as that would cause Windows to require the DLL to be present.

Note that the search path for foo.pyc is PYTHONPATH, not the same as
the path that Windows uses to search for foo.dll. Also, foo.pyd need
not be present to run your program, whereas if you linked your program
with a dll, the dll is required. Of course, foo.pyd is required if
you want to say "import foo". In a dll, linkage is declared in the
source
code with __declspec(dllexport). In a .pyd, linkage is defined in a
list
of available functions.

Jim Ahlstrom

Jim
Difference between Win-dll's and pyd's?? [ In reply to ]
"Thomas S. Strinnhed" wrote:

> Now for the questions:
> I suspect the .pyd-files to be "Python-dll's". Right??

Right. They got just a different extension, "python dll".
You can rename them to .dll and inspect them with
a dll viewer.

> No: If not, what are they, and how to use them.
> Yes: If so, can I substitute .pyd's for win-dll's and vice versa
> or can they be used in any other ways??

There is one big difference. .pyd dlls usually export just
one function, which the Python interpreter wants to see:
init<modulename> must be there. Python will call it
once. The .pyd then usually initializes itself, inserts
some objects into its module dictionary and whatever.
So by design, they are usually useless if Python is not
there.
But you might of course write a standard C .dll which
publishes a number of functions for other C code
and provides an init<modulename> function as well.
This would allow to add a Python interface to your
functions in the same dll file.

ciao - chris

--
Christian Tismer :^) <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home
Difference between Win-dll's and pyd's?? [ In reply to ]
I feel some of the other responses were _slightly_ misleading.

There are _zero_ differences between the 2 from Python's POV. When you say
"import foo", a search is done for "foo.pyc", "foo.py", "foo.pyd", or
"foo.dll".

If your Python module is a DLL, it is treated in a fashion identical to
.pyd's. Windows is _not_ used to search for the DLL when requested by
Python. Python has no conditional logic based on the 2 extensions.

One of the reasons this was done is to avoid name clashes. It allows you to
have an existing 3rd party "foo.dll", and have a Python DLL interface to it
as "foo.pyd". The .pyd will be found before the .dll in the same directory.
If only .DLL was allowed, it would be more difficult to have the 3rd party
DLL named foo as well as your extension DLL named "foo"

Mark.

Thomas S. Strinnhed wrote in message <37382FD9.59EB38C6@serop.abb.se>...
>Hi
>
>I'm working on Windows NT, MS Developer Studio and are trying to embed
>the Python interpreter in an application.
>
>I also want some C-based modules to be dynamically linked to the
>embedded Python interpreter, as win-dll's.
>
>I'm using "compile.py" by David Ascher to create the MS Dev Studio
>workapsces and projects.
>
>The DLL's work, but some times tiny .pyd-files occur (not always, but
>that can be some set-up stuff).
>
>Now for the questions:
> I suspect the .pyd-files to be "Python-dll's". Right??
> No: If not, what are they, and how to use them.
> Yes: If so, can I substitute .pyd's for win-dll's and vice versa
> or can they be used in any other ways??
>
>
>Thanks
> Thomas S. Strinnhed, thstr@serop.abb.se