Skip to content

Commit 77dd973

Browse files
authored
gh-152433: Windows: allow build socketmodule for UWP (#152601)
1 parent d0b2e07 commit 77dd973

3 files changed

Lines changed: 31 additions & 20 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow build :mod:`socket` module for Universal Windows Platform.

Modules/clinic/socketmodule.c.h

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/socketmodule.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ shutdown(how) -- shut down traffic in one or both directions\n\
290290
/* Helpers needed for AF_HYPERV */
291291
# include <Rpc.h>
292292

293+
#ifndef RPC_S_OK
294+
#define RPC_S_OK 0L
295+
#endif
296+
293297
/* Macros based on the IPPROTO enum, see: https://bugs.python.org/issue29515 */
294298
#define IPPROTO_ICMP IPPROTO_ICMP
295299
#define IPPROTO_IGMP IPPROTO_IGMP
@@ -631,14 +635,14 @@ _PyLong_##NAME##_Converter(PyObject *obj, void *ptr) \
631635
return 1; \
632636
}
633637

634-
#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)
638+
#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS_DESKTOP)
635639
# ifdef MS_WINDOWS
636640
UNSIGNED_INT_CONVERTER(NetIfindex, NET_IFINDEX)
637641
# else
638642
# define _PyLong_NetIfindex_Converter _PyLong_UnsignedInt_Converter
639643
# define NET_IFINDEX unsigned int
640644
# endif
641-
#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)
645+
#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS_DESKTOP)
642646

643647
/*[python input]
644648
class NET_IFINDEX_converter(CConverter):
@@ -5924,10 +5928,12 @@ _socket_gethostname_impl(PyObject *module)
59245928
Otherwise, gethostname apparently also returns the DNS name. */
59255929
wchar_t buf[MAX_COMPUTERNAME_LENGTH + 1];
59265930
DWORD size = Py_ARRAY_LENGTH(buf);
5927-
wchar_t *name;
5928-
PyObject *result;
59295931

5932+
#ifdef MS_WINDOWS_DESKTOP
59305933
if (GetComputerNameExW(ComputerNamePhysicalDnsHostname, buf, &size))
5934+
#else
5935+
if (GetComputerNameW(buf, &size))
5936+
#endif
59315937
return PyUnicode_FromWideChar(buf, size);
59325938

59335939
if (GetLastError() != ERROR_MORE_DATA)
@@ -5936,9 +5942,12 @@ _socket_gethostname_impl(PyObject *module)
59365942
if (size == 0)
59375943
return Py_GetConstant(Py_CONSTANT_EMPTY_STR);
59385944

5945+
#ifndef MS_WINDOWS_DESKTOP
5946+
return NULL;
5947+
#else
59395948
/* MSDN says ERROR_MORE_DATA may occur because DNS allows longer
59405949
names */
5941-
name = PyMem_New(wchar_t, size);
5950+
wchar_t* name = PyMem_New(wchar_t, size);
59425951
if (!name) {
59435952
PyErr_NoMemory();
59445953
return NULL;
@@ -5952,9 +5961,10 @@ _socket_gethostname_impl(PyObject *module)
59525961
return NULL;
59535962
}
59545963

5955-
result = PyUnicode_FromWideChar(name, size);
5964+
PyObject* result = PyUnicode_FromWideChar(name, size);
59565965
PyMem_Free(name);
59575966
return result;
5967+
#endif
59585968
#else
59595969
char buf[1024];
59605970
int res;
@@ -7321,7 +7331,7 @@ _socket_setdefaulttimeout(PyObject *module, PyObject *arg)
73217331
}
73227332

73237333

7324-
#if defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)
7334+
#if defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS_DESKTOP)
73257335
/* Python API for getting interface indices and names */
73267336

73277337
/*[clinic input]
@@ -7412,9 +7422,9 @@ _socket_if_nameindex_impl(PyObject *module)
74127422
#endif
74137423
}
74147424

7415-
#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)
7425+
#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS_DESKTOP)
74167426

7417-
#if defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS)
7427+
#if defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS_DESKTOP)
74187428

74197429
/*[clinic input]
74207430
_socket.if_nametoindex
@@ -7444,9 +7454,9 @@ _socket_if_nametoindex_impl(PyObject *module, PyObject *oname)
74447454
return PyLong_FromUnsignedLong(index);
74457455
}
74467456

7447-
#endif // defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS)
7457+
#endif // defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS_DESKTOP)
74487458

7449-
#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)
7459+
#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS_DESKTOP)
74507460

74517461
/*[clinic input]
74527462
@permit_long_summary
@@ -7471,7 +7481,7 @@ _socket_if_indextoname_impl(PyObject *module, NET_IFINDEX index)
74717481
return PyUnicode_DecodeFSDefault(name);
74727482
}
74737483

7474-
#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)
7484+
#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS_DESKTOP)
74757485

74767486

74777487
#ifdef CMSG_LEN
@@ -9374,7 +9384,7 @@ socket_exec(PyObject *m)
93749384
#endif
93759385
#endif /* _MSTCPIP_ */
93769386

9377-
#ifdef MS_WINDOWS
9387+
#ifdef MS_WINDOWS_DESKTOP
93789388
/* remove some flags on older version Windows during run-time */
93799389
if (remove_unusable_flags(m) < 0) {
93809390
goto error;

0 commit comments

Comments
 (0)