473,394 Members | 2,168 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.

printf "fails" in extension

I'm trying to "extend" Python by writing a bit of C code. I followed
the example in the Python documentation, and almost everything works
fine. I can build a DLL, fire up an interactive Python session and
import my new module. Methods work almost as expected.

The only problem I'm having is that I can't print to the screen from
the C code. Printing to a file works fine, but neither printf nor
fprintf(stdout,...) puts anything onto the screen.

I'm working in Windows2K, using Python2.3. Is there some trick to get
this to work? I'm wondering if this is a compiler issue (I'm building
the DLL using an Absoft compiler). I googled around looking for
relevant information, but I didn't find any. Perhaps I didn't have
the right key words?

Any ideas,
thanks,
-robert
Jul 18 '05 #1
6 2089
Robert Ferrell wrote:
I'm trying to "extend" Python by writing a bit of C code. I followed
the example in the Python documentation, and almost everything works
fine. I can build a DLL, fire up an interactive Python session and
import my new module. Methods work almost as expected.

The only problem I'm having is that I can't print to the screen from
the C code. Printing to a file works fine, but neither printf nor
fprintf(stdout,...) puts anything onto the screen.

I'm working in Windows2K, using Python2.3. Is there some trick to get
this to work? I'm wondering if this is a compiler issue (I'm building
the DLL using an Absoft compiler). I googled around looking for
relevant information, but I didn't find any. Perhaps I didn't have
the right key words?


This may well be the case. Python doesn't necessarily have much
to do with it: it IS a question of EXE and DLL on Windows needing
to share the _same_ stdio infrastructure -- basically, the same
instance of the same runtime libraries. Tricky enough when you
build EXE and DLL with the same compiler, because even then you
need to ensure they're using a version of the C runtime that lives
_in yet another DLL_ -- and it must be the same, not e.g. one
optimized and the other built for debug instead -- any static
linking of the runtime on either or both sides and you're hosed.
Even trickier with different compilers, unless one is specifically
built to use the C runtime DLL's from the other -- mingw32 being
an example (it's built to use MSVCRT.DLL, Microsoft's DLL version
of the C runtime libraries).

This is a well-known issue among experts of C compilers on
Windows -- particularly ones who have ever had the totally
harrowing experience of having to mix code built by multiple
compilers, but not exclusively, because even using e.g MSVC++ 6
throughout is still tricky due to the possibility of different
C runtime library instances being used by different modules
(in the Windows sense: each EXE or DLL is a module). How to
manage to google for it may be a different issue, particularly
as the workaround (if any) will depend on your "Absoft
compiler". I can however suggest to skip Python in your
searches, because it's not in the picture: what you need to
find out is, how (if at all) is it possible to use your
compiler to write a DLL which, used from a MSVC++ - made EXE,
is able to do normal output to stdout or stderr.
Alex

Jul 18 '05 #2
In article <73**************************@posting.google.com >,
fe*****@diablotech.com (Robert Ferrell) wrote:
I'm trying to "extend" Python by writing a bit of C code. I followed
the example in the Python documentation, and almost everything works
fine. I can build a DLL, fire up an interactive Python session and
import my new module. Methods work almost as expected.

The only problem I'm having is that I can't print to the screen from
the C code. Printing to a file works fine, but neither printf nor
fprintf(stdout,...) puts anything onto the screen.

I'm working in Windows2K, using Python2.3. Is there some trick to get
this to work? I'm wondering if this is a compiler issue (I'm building
the DLL using an Absoft compiler). I googled around looking for
relevant information, but I didn't find any. Perhaps I didn't have
the right key words?


Apart from these potential issues (I know nothing about them), you
should really use PySys_WriteStdout() and PySys_WriteStderr(), because
these to the right thing when sys.stdout/sys.stderr are redirected to
something else.

Just
Jul 18 '05 #3
Thanks for your response. I suspected this was a Windows DLL issue,
arising from my lack of experience with Windows, but I thought I
should confirm that I wasn't missing something obvious. My simplest
solution may be to switch to Visual Studio, although it's not clear
the customer will allow that.

Thanks for your input.
-robert

Alex Martelli <al***@aleax.it> wrote in message news:<Ma***********************@news2.tin.it>...
Robert Ferrell wrote:
I'm trying to "extend" Python by writing a bit of C code. I followed
the example in the Python documentation, and almost everything works
fine. I can build a DLL, fire up an interactive Python session and
import my new module. Methods work almost as expected.

The only problem I'm having is that I can't print to the screen from
the C code. Printing to a file works fine, but neither printf nor
fprintf(stdout,...) puts anything onto the screen.

I'm working in Windows2K, using Python2.3. Is there some trick to get
this to work? I'm wondering if this is a compiler issue (I'm building
the DLL using an Absoft compiler). I googled around looking for
relevant information, but I didn't find any. Perhaps I didn't have
the right key words?


This may well be the case. Python doesn't necessarily have much
to do with it: it IS a question of EXE and DLL on Windows needing
to share the _same_ stdio infrastructure -- basically, the same
instance of the same runtime libraries. Tricky enough when you
build EXE and DLL with the same compiler, because even then you
need to ensure they're using a version of the C runtime that lives
_in yet another DLL_ -- and it must be the same, not e.g. one
optimized and the other built for debug instead -- any static
linking of the runtime on either or both sides and you're hosed.
Even trickier with different compilers, unless one is specifically
built to use the C runtime DLL's from the other -- mingw32 being
an example (it's built to use MSVCRT.DLL, Microsoft's DLL version
of the C runtime libraries).

This is a well-known issue among experts of C compilers on
Windows -- particularly ones who have ever had the totally
harrowing experience of having to mix code built by multiple
compilers, but not exclusively, because even using e.g MSVC++ 6
throughout is still tricky due to the possibility of different
C runtime library instances being used by different modules
(in the Windows sense: each EXE or DLL is a module). How to
manage to google for it may be a different issue, particularly
as the workaround (if any) will depend on your "Absoft
compiler". I can however suggest to skip Python in your
searches, because it's not in the picture: what you need to
find out is, how (if at all) is it possible to use your
compiler to write a DLL which, used from a MSVC++ - made EXE,
is able to do normal output to stdout or stderr.
Alex

Jul 18 '05 #4
In stuff I write I can use the appropriate Python routines. However,
part of the task is to extend Python with existing routines by adding
some wrapper code. That is something I know many others have done,
and is fairly straight forward. However, I dont' have the liberty of
converting all printf's in the existing code to Python-ese.

Thanks,
-robert

Just <ju**@xs4all.nl> wrote in message news:<ju************************@news1.news.xs4all .nl>...
In article <73**************************@posting.google.com >,
fe*****@diablotech.com (Robert Ferrell) wrote:
I'm trying to "extend" Python by writing a bit of C code. I followed
the example in the Python documentation, and almost everything works
fine. I can build a DLL, fire up an interactive Python session and
import my new module. Methods work almost as expected.

The only problem I'm having is that I can't print to the screen from
the C code. Printing to a file works fine, but neither printf nor
fprintf(stdout,...) puts anything onto the screen.

I'm working in Windows2K, using Python2.3. Is there some trick to get
this to work? I'm wondering if this is a compiler issue (I'm building
the DLL using an Absoft compiler). I googled around looking for
relevant information, but I didn't find any. Perhaps I didn't have
the right key words?


Apart from these potential issues (I know nothing about them), you
should really use PySys_WriteStdout() and PySys_WriteStderr(), because
these to the right thing when sys.stdout/sys.stderr are redirected to
something else.

Just

Jul 18 '05 #5
Hi,
Robert Ferrell wrote:
Thanks for your response. I suspected this was a Windows DLL issue,
arising from my lack of experience with Windows, but I thought I
should confirm that I wasn't missing something obvious. My simplest
solution may be to switch to Visual Studio, although it's not clear
the customer will allow that.


If price is the matter, you can download the "Platform SDK" for free
from Microsoft's homepage - and AFAIK it contains the command line
version of the compiler + all libraries just like Visual Studio does.

IMHO it could save you some trouble to use the same compiler for Python
itself and your extensions. Also be sure to build *both* as debug or
release (that is, both the *same*) since you will otherwise end up with
2 different versions of the C runtime libraries!

hth

Werner

Jul 18 '05 #6
Hi,
Robert Ferrell wrote:
In stuff I write I can use the appropriate Python routines. However,
part of the task is to extend Python with existing routines by adding
some wrapper code. That is something I know many others have done,
and is fairly straight forward. However, I dont' have the liberty of
converting all printf's in the existing code to Python-ese.


Then you *certainly* want to use the same C runtime library, everything
else will cause you a lot of headaches...

And as I said in my other post, be sure to have everything built with
the same build specification (debug or release) if you use the MS tools.

hth
Werner

Jul 18 '05 #7

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

Similar topics

1
by: WMMorgan | last post by:
There's a website I like to visit that has an user-interactive java application. There's a "visual applet" component and "control applet" component. (No, it's not an adult or porno site.) But...
2
by: George Hester | last post by:
with Invalid ProgID. For additional information specific to this message please visit the Microsoft Online Support site located at: http://www.microsoft.com/contentredirect.asp. My other...
4
by: Eyal Goren | last post by:
Hi, We have troubles when we try to use the 'dbuse' calls with databases larger than 28 characters, looks like the dbuse truncates the name after it. Any ideas ???
3
by: Simon Wigzell | last post by:
I'm using : window.location.href = to redirect to a web page. From the new webpage, when you click the browser "Back" button you of course end up on the same old page and get redirected...
0
by: Bruce | last post by:
I have three tables in SQL serve tblareas (w/autoincrement ID tblprograms (w/autoincrement ID tblphases (w/autoincrement ID I've build cascading relation from tblareas <one-many> tblprograms...
3
by: Ptbrady | last post by:
"Order By" fails in form for linked table. -------------- My A2K database has worked well for several years, but now has been split into front-end/back-end and has the following problem. I have a...
13
by: John A Grandy | last post by:
apparently references of type Date can not assume the value Nothing, because the following code fails: Dim d As Date .......other code...... If d Is Nothing Then End If so then what is...
0
by: R Baker | last post by:
I have been trying to use an FTPWebRequest to upload a file to an FTP site. Invariably, the first attempt will fail on the call to GetRequestStream, with the error message "Unable to connect to the...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.