Mailing List Archive

[issue5119] inconsistent wide character parameter handling in 64-bit python
New submission from Jason R. Coombs <jaraco@jaraco.com>:

Using Python 2.5.4 and Python 2.6.1 on 32-bit python, when passing a
regular string to a function expecting pointer to a wide string
(wintypes.LPCWSTR), the function executes without problems.

When calling the same using Python 2.6.1 on 64-bit windows, the called
function appears not to recognize the parameter unless it is first
converted to unicode.

I discovered this when calling the WNetAddConnection2 function.

Assuming a properly-initialized NETRESOURCE, resource.

password = None
username = 'username@domain.com'
flags = 0

val = ctypes.windll.mpr.WNetAddConnection2W(
ctypes.byref(resource),
password,
username,
flags)

This method works fine on 32-bit python but fails on 64-bit python
unless username=unicode(username). The error returned is "The specified
password is incorrect", indicating that the username is in fact
incorrect because the correct username does not require a password.

I wish I had a better test case; I'll try to track down one that doesn't
require such a complex underlying API.

I'm not sure what the correct fix is for this, but regardless, I would
expect the behavior to be consistent for the same Python version
independent of word size.

----------
assignee: theller
components: ctypes
messages: 80883
nosy: jaraco, theller
severity: normal
status: open
title: inconsistent wide character parameter handling in 64-bit python
type: behavior
versions: Python 2.5, Python 2.6

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5119>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5119] inconsistent wide character parameter handling in 64-bit python [ In reply to ]
Jason R. Coombs <jaraco@jaraco.com> added the comment:

After putting together a more simple example without externalities, I'm
unable to continue to assert the discrepancy between 32 and 64-bit
Windows, although I do still see where narrow character strings are
treated as wide character buffers.

See the attached script that demonstrates the issue (on Python 2.5 and
Python 2.6 regardless of word size).

Now the inconsistency seems to only lie with the WNetAddConnection2W
function and not the MessageBoxW function, both of which take LPCTSTR
parameters (at least according to the documentation).

Perhaps this is a non-issue, but I'd be interested to know why the
WNetAddConnection2W example works in 32-bit but not 64-bit. Could it be
the 32-bit WNetAddConnection2W actually attempts to handle the buffer as
both wide and narrow, but MessageBoxW takes it at face value?

Added file: http://bugs.python.org/file12908/ui.py

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5119>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5119] inconsistent wide character parameter handling in 64-bit python [ In reply to ]
Jason R. Coombs <jaraco@jaraco.com> added the comment:

Or alternately, is it possible (and reasonable) for ctypes to inspect
the function signature and create wide character buffers when appropriate?

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5119>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com