nghung270192 / colorama

Automatically exported from code.google.com/p/colorama
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Doesn't work properly under 64-bit Windows due to ctypes HANDLE size #43

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I ran into this when using the pss search tool -- see more at 
https://github.com/eliben/pss/issues/5

Basically colorama is broken on 64-bit Windows, or at least, works only 
intermittently with odd results. The reason is that colorama's win32.py doesn't 
use ctypes correctly, specifically it doesn't specify the argtypes for Win32 
functions. HANDLE on 64-bit Windows is a 64-bit value, so you need to specify 
these, otherwise ctypes assumes HANDLE is 32 bit. This is actually a fairly 
common (and easy-to-overlook :-) problem with ctypes on Windows. For example, 
here's another time I've run into this: 
http://tech.oyster.com/cherrypy-ctypes-and-being-explicit/

The easiest way I've found to repro this is by using pss with various command 
line options, for example "pss -C1 foo" colors correctly, but "pss -C 1 foo" 
(and note that it's nothing to do with pss or its command-line arguments, but 
the stuff that happens to be or not to be on the stack when colorama is 
called). I'm sure there's a more self-contained repro, but seeing I've already 
fixed the issue, I'm not going to pursue that.

I'm attaching a unified diff of win32.py with this fixed. I also changed it to 
use the existing wintypes types for things like DWORD and SMALL_RECT, so you 
don't have to respecify these in win32.py.

Original issue reported on code.google.com by benh...@gmail.com on 11 Jul 2013 at 11:21

Attachments:

GoogleCodeExporter commented 9 years ago
You are a star. I'm about to head out on a trip for the weekend, but will merge 
this in when I get back. Many thanks!

Original comment by tart...@gmail.com on 12 Jul 2013 at 3:10

GoogleCodeExporter commented 9 years ago
Has this been fixed yet? If so, where can I go to pull the fixed code?

Original comment by clapp...@gmail.com on 25 Sep 2013 at 3:19

GoogleCodeExporter commented 9 years ago
Nope, fraid not. I'll try over next few days. I only get about three hours per 
month to sit down and code at home.

Original comment by tart...@gmail.com on 25 Sep 2013 at 3:28

GoogleCodeExporter commented 9 years ago
@clappi77, it should work if you replace your win32.py with the attached.

Original comment by benh...@gmail.com on 25 Sep 2013 at 6:19

Attachments:

GoogleCodeExporter commented 9 years ago
This works great. Thanks for the prompt response!

Original comment by clapp...@gmail.com on 25 Sep 2013 at 6:55

GoogleCodeExporter commented 9 years ago
@benhoyt, I've added you as a committer to the project, if ever you fancy 
merging that yourself. I was thinking about when I'm going to get a moment to 
do it myself, and the answer is 'not soon'. Apologies for my non-contributions. 
Cheers.

Original comment by tart...@gmail.com on 26 Sep 2013 at 7:42

GoogleCodeExporter commented 9 years ago
This issue was closed by revision caccf8416981.

Original comment by benh...@gmail.com on 26 Sep 2013 at 8:21

GoogleCodeExporter commented 9 years ago
Thanks! Fixed in 
https://code.google.com/p/colorama/source/detail?r=caccf84169811eed1b218af2173a4
d2191440808

Original comment by benh...@gmail.com on 26 Sep 2013 at 8:23

GoogleCodeExporter commented 9 years ago
New version (0.2.7) pushed to PyPI including this fix. Thanks all!

Original comment by tart...@gmail.com on 26 Sep 2013 at 10:08