Skip to content

Commit cb8f491

Browse files
authored
bpo-40280: Optimize ints and and startup on wasm (GH-29887)
1 parent a6c3b0f commit cb8f491

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Include/pyport.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ Used in: Py_SAFE_DOWNCAST
8787

8888
/* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all
8989
the necessary integer types are available, and we're on a 64-bit platform
90-
(as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */
90+
(as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits.
91+
92+
From pyodide: WASM has 32 bit pointers but has native 64 bit arithmetic
93+
so it is more efficient to use 30 bit digits.
94+
*/
9195

9296
#ifndef PYLONG_BITS_IN_DIGIT
93-
#if SIZEOF_VOID_P >= 8
94-
#define PYLONG_BITS_IN_DIGIT 30
97+
#if SIZEOF_VOID_P >= 8 || defined(__wasm__)
98+
# define PYLONG_BITS_IN_DIGIT 30
9599
#else
96-
#define PYLONG_BITS_IN_DIGIT 15
100+
# define PYLONG_BITS_IN_DIGIT 15
97101
#endif
98102
#endif
99103

Python/pylifecycle.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,11 @@ is_valid_fd(int fd)
21452145
if (fd < 0) {
21462146
return 0;
21472147
}
2148-
#if defined(F_GETFD) && (defined(__linux__) || defined(__APPLE__) || defined(MS_WINDOWS))
2148+
#if defined(F_GETFD) && ( \
2149+
defined(__linux__) || \
2150+
defined(__APPLE__) || \
2151+
defined(MS_WINDOWS) || \
2152+
defined(__wasm__))
21492153
int res;
21502154
_Py_BEGIN_SUPPRESS_IPH
21512155
res = fcntl(fd, F_GETFD);

0 commit comments

Comments
 (0)