[Python-Dev] [Python-checkins] r85934 - in python/branches/py3k: Misc/NEWS Modules/socketmodule.c (original) (raw)
"Martin v. Löwis" martin at v.loewis.de
Sat Oct 30 22:08:57 CEST 2010
- Previous message: [Python-Dev] [Python-checkins] r85934 - in python/branches/py3k: Misc/NEWS Modules/socketmodule.c
- Next message: [Python-Dev] PyMem_MALLOC vs PyMem_Malloc
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I think size should be in TCHARs, not in bytes. (MSDN says so) And GetComputerName's signature differs from MSDN. (Maybe should use GetComputerNameExW again?)
You are right. So how about this patch?
Index: Modules/socketmodule.c
--- Modules/socketmodule.c (Revision 85983) +++ Modules/socketmodule.c (Arbeitskopie) @@ -3098,16 +3098,16 @@ version of the hostname, whereas we need a Unicode string. Otherwise, gethostname apparently also returns the DNS name. */ wchar_t buf[MAX_COMPUTERNAME_LENGTH];
- DWORD size = sizeof(buf);
- DWORD size = sizeof(buf)/sizeof(wchar_t); if (!GetComputerNameExW(ComputerNamePhysicalDnsHostname, buf, &size)) { if (GetLastError() == ERROR_MORE_DATA) { /* MSDN says this may occur "because DNS allows longer names */ PyObject *result = PyUnicode_FromUnicode(NULL, size); if (!result) return NULL;
if (GetComputerName(ComputerNamePhysicalDnsHostname,
PyUnicode_AS_UNICODE(result),
size+1))
if (GetComputerNameExW(ComputerNamePhysicalDnsHostname,
PyUnicode_AS_UNICODE(result),
size+1)) return result; Py_DECREF(result); }
Regards, Martin
- Previous message: [Python-Dev] [Python-checkins] r85934 - in python/branches/py3k: Misc/NEWS Modules/socketmodule.c
- Next message: [Python-Dev] PyMem_MALLOC vs PyMem_Malloc
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]