473,394 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Python 2.4.2 using msvcrt71.dll on Win and compatibility issues

The latest Windows distribution of Python 2.4.2 is using the
msvcrt71.dll, while PostgreSQL is using msvcrt.dll.

This lead to the following problem:

I was using PyGreSQL to connect to the PostgreSQL database. There is a
function that prints a query object q simply by writing: "print q". What
happens on the lower levels is that PyObject_Print(q, stdout) is called,
where stdout is the stdout file descriptor of msvcrt71.dll. Then,
PyGreSQL calls the PostgreSQL function PQprint, handing it over that
stdout file descriptor. PQprint in turn calls fprintf of msvcrt.dll,
with the same file descriptor of msvcrt71.dll. This leads to a Windows
exception since the file descriptors of mscvrt.dll and msvcrt71.dll are
obviously not compatible.

I can imagine that other C extensions which are using dlls based on
msvcrt can run into the same problem.

Is there a general strategy to avoid this kind of problems?

-- Christoph
Feb 7 '06 #1
7 3963
Christoph Zwerschke wrote:
Is there a general strategy to avoid this kind of problems?


In general, the only Microsoft-supported strategy is that you
must use only a single msvcrt in the entire application. So
either recompile PostGres, or recompile Python.

In the specific case, having PQprint print to a string (rather
than to a file) might work. OTOH, it appears there is no "print
to string" code in postgres.

So here is another strategy: flush the stream before going
into postgres, then obtain the fileno() of the stream, and
fdopen it with postgres' iostreams library. That might also
be tricky to implement, but could work.

Regards,
Martin
Feb 7 '06 #2
Martin v. Löwis wrote:
In general, the only Microsoft-supported strategy is that you
must use only a single msvcrt in the entire application. So
either recompile PostGres, or recompile Python.
Hm, that's really inconvenient (even more so under Windows).
In the specific case, having PQprint print to a string (rather
than to a file) might work. OTOH, it appears there is no "print
to string" code in postgres.
Yes, there is only PQprint which prints to a stream.
So here is another strategy: flush the stream before going
into postgres, then obtain the fileno() of the stream, and
fdopen it with postgres' iostreams library. That might also
be tricky to implement, but could work.


I understand what you mean. But the Postgres dll provides no means to
fdopen a new stream.

-- Christoph
Feb 7 '06 #3
Christoph Zwerschke wrote:
So here is another strategy: flush the stream before going
into postgres, then obtain the fileno() of the stream, and
fdopen it with postgres' iostreams library. That might also
be tricky to implement, but could work.

I understand what you mean. But the Postgres dll provides no means to
fdopen a new stream.


Right. So you must do so in the pygresql module. That means you have
to get hold of msvcrt.dll's (sic) fdopen implementation.

One way to do so would be through linking pygresql to msvcrt.dll,
instead of linking it to msvcr71.dll. That should be only done if
it is certain that there won't be any other resource sharing with
Python (no malloc, no locale, no stdio - see "some" mskb article
for the precise list of restrictions). I would expect that no
such resource sharing happens, but one would have to verify the code
to be certain.

The other option is to use GetProcAddress to obtain the address of
fdopen.

Regards,
Martin
Feb 7 '06 #4
Martin v. Löwis wrote:
Christoph Zwerschke wrote:
I understand what you mean. But the Postgres dll provides no means to
fdopen a new stream.
Right. So you must do so in the pygresql module. That means you have
to get hold of msvcrt.dll's (sic) fdopen implementation.

One way to do so would be through linking pygresql to msvcrt.dll,
instead of linking it to msvcr71.dll.


I think this would only shift the problem. Because then I would have to
convert the msvcr71 stream I get from Python to a msvcrt stream. Using
fileno() (of msvcrt) to get the file descriptor will probably not work.
The other option is to use GetProcAddress to obtain the address of
fdopen.


That would be an option. However, I would need to know the handle of the
PostgreSQL dll module. Is there an easy way to get it (without having to
hard-code the explicit name of the dll)? In any way, it seems I have to
insert a lot of platform-dependent, ugly code.

In my case, it is probably easier to simply mimic the Postgres PQprint()
function provided by the dll in PyGreSQL. It is not such a complicated
thing. Plus it is only called with fixed parameters, so I don't need the
complete functionality. PQprint() is considered obsolete anyway and may
vanish one day.

But thanks a lot for your help. Sometimes you don't know whether you're
doing something terribly wrong or missing a very easy solution if you
don't discuss with others.

-- Christoph
Feb 8 '06 #5
Christoph Zwerschke wrote:
I think this would only shift the problem. Because then I would have to
convert the msvcr71 stream I get from Python to a msvcrt stream. Using
fileno() (of msvcrt) to get the file descriptor will probably not work.
It actually would:

#define _fileno(_stream) ((_stream)->_file)

This definition is the same in all CRT version, plus the _file member
is at the same offset in all CRT versions. Microsoft apparently wants
to support linkage of object files build with one CRT version against
a different CRT version.

It *is* hacky, of course.
But thanks a lot for your help. Sometimes you don't know whether you're
doing something terribly wrong or missing a very easy solution if you
don't discuss with others.


Right. I come more and more to the conclusion that you shouldn't really
be using the CRT on Win32.

Anyway, I just proposed to have Python 2.5 link against msvcrt.dll
on python-dev, and got mixed responses.

Regards,
Martin
Feb 8 '06 #6

Martin v. Löwis wrote:
In general, the only Microsoft-supported strategy is that you
must use only a single msvcrt in the entire application. So
either recompile PostGres, or recompile Python.


If you want a compiled version of Python that already uses
MSVCRT then you try using pyMingGW:

http://jove.prohosting.com/iwave/ipython/pyMinGW.html

Feb 8 '06 #7
Martin v. Löwis wrote:
Christoph Zwerschke wrote:
I think this would only shift the problem. Because then I would have to
convert the msvcr71 stream I get from Python to a msvcrt stream. Using
fileno() (of msvcrt) to get the file descriptor will probably not work.


It actually would:

#define _fileno(_stream) ((_stream)->_file)

This definition is the same in all CRT version, plus the _file member
is at the same offset in all CRT versions. Microsoft apparently wants
to support linkage of object files build with one CRT version against
a different CRT version.

It *is* hacky, of course.


I see. So this approach could actually work. Thanks for the hint.

-- Christoph
Feb 8 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Pierre Rouleau | last post by:
Hi all! I am using Python 2.3.1 on Win32 (NT, 2000). Whenever a file imports the standard tempfile module, Python 2.3.1 issues the following warning: C:\Python23\lib\fcntl.py:7:...
0
by: Helmut Zeisel | last post by:
I want to build a static extension of Python using SWIG and VC++ 6.0 as described in http://www.swig.org/Doc1.3/Python.html#n8 for gcc. My file is testerl.i: ========================= %module...
1
by: Matthew | last post by:
Hi: I recently installed Python 2.4 and the Win 32 extensions on Windows XP. I had some problems with the COM makepy utility for the Excel COM libraries. I reported this problem to the...
2
by: Todd D. Levy | last post by:
I recently picked up a copy of Office 2003, but have installed it (replacing my existing installation of Office XP Pro) yet because... I am in the middle of a client project using Access 2002...
6
by: Eric G | last post by:
I took my Access 2000 db in to a school last week as a demo. The V.P.'s notebook was using Access 2003. Access 2003 complained when it tried to load the .mde file, prompting for this that and the...
1
by: Diggy | last post by:
Hi, We have developed a web based application using ASP.NET, C# and SQL Server2000. We are facing problem in using some of the functionality available like user impersonation, etc., after...
2
by: G2 | last post by:
Hi We are dealing with significant browser compatibility issues with Netscape 5.x+ browsers and Mac IE. I am sure most web developers have faced similar issues in the past. Can anyone give me their...
15
by: Logician | last post by:
I want to use UNIX to develop c# applications, does anyone have any details of compatibility issues?
0
by: cnivas | last post by:
Hi, I'm doing a small application in python using mac os x. Now, I want to insert an image in the web application. I have given the image path also... but it shows "?" this symbol.... If the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.