-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-114099: Add preprocessor declarations to support compilation on iOS #115023
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Preprocessor directives to support compilation on iOS/tvOS/watchOS were | ||
added. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,8 @@ | |
|
||
#include <mach/mach.h> | ||
|
||
#include "TargetConditionals.h" | ||
|
||
#if defined(__has_builtin) | ||
#if __has_builtin(__builtin_available) | ||
#define HAVE_BUILTIN_AVAILABLE 1 | ||
|
@@ -376,6 +378,13 @@ corresponding Unix manual entries for more information on calls."); | |
# define fsync _commit | ||
#endif /* ! __WATCOMC__ || __QNX__ */ | ||
|
||
// iOS/tvOS/watchOS *define* some POSIX methods, | ||
// but raise a compiler error if they are used. | ||
#if TARGET_OS_IPHONE | ||
# undef HAVE_GETGROUPS | ||
Comment on lines
+381
to
+384
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's a compiler error, as opposed to a runtime error, then autoconf should be able to detect the problem. The comment should explain why that wasn't sufficient. |
||
# undef HAVE_SYSTEM | ||
#endif | ||
|
||
/*[clinic input] | ||
# one of the few times we lie about this name! | ||
module os | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
|
||
/* UNIX password file access module */ | ||
|
||
#ifdef __APPLE__ | ||
# include "TargetConditionals.h" | ||
#endif /* __APPLE__ */ | ||
|
||
#include "Python.h" | ||
#include "posixmodule.h" | ||
|
||
|
@@ -183,6 +187,22 @@ pwd_getpwuid(PyObject *module, PyObject *uidobj) | |
if (nomem == 1) { | ||
return PyErr_NoMemory(); | ||
} | ||
|
||
// iPhone has a "user" with UID 501, username "mobile"; but the simulator | ||
// doesn't reflect this. Generate a simulated response. | ||
#if TARGET_OS_SIMULATOR | ||
if (uid == 501) { | ||
struct passwd mp; | ||
mp.pw_name = "mobile"; | ||
mp.pw_passwd = "/smx7MYTQIi2M"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see it's easy enough to Google, but there should still be a comment explaining what this value is and where it comes from. |
||
mp.pw_uid = 501; | ||
mp.pw_gid = 501; | ||
mp.pw_gecos = "Mobile User"; | ||
mp.pw_dir = "/var/mobile"; | ||
mp.pw_shell = "/bin/sh"; | ||
return mkpwent(module, &mp); | ||
} | ||
#endif | ||
PyObject *uid_obj = _PyLong_FromUid(uid); | ||
if (uid_obj == NULL) | ||
return NULL; | ||
|
@@ -266,6 +286,22 @@ pwd_getpwnam_impl(PyObject *module, PyObject *name) | |
PyErr_NoMemory(); | ||
} | ||
else { | ||
// iPhone has a "user" with UID 501, username "mobile"; but the simulator | ||
// doesn't reflect this. Generate a simulated response. | ||
#if TARGET_OS_SIMULATOR | ||
if (strcmp(name, "mobile") == 0) { | ||
struct passwd mp; | ||
mp.pw_name = "mobile"; | ||
mp.pw_passwd = "/smx7MYTQIi2M"; | ||
mp.pw_uid = 501; | ||
mp.pw_gid = 501; | ||
mp.pw_gecos = "Mobile User"; | ||
mp.pw_dir = "/var/mobile"; | ||
mp.pw_shell = "/bin/sh"; | ||
retval = mkpwent(module, &mp); | ||
goto out; | ||
} | ||
#endif | ||
PyErr_Format(PyExc_KeyError, | ||
"getpwnam(): name not found: %R", name); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,10 @@ | |
#include "pycore_namespace.h" // _PyNamespace_New() | ||
#include "pycore_runtime.h" // _Py_ID() | ||
|
||
#ifdef __APPLE__ | ||
# include "TargetConditionals.h" | ||
#endif /* __APPLE__ */ | ||
|
||
#include <time.h> // clock() | ||
#ifdef HAVE_SYS_TIMES_H | ||
# include <sys/times.h> // times() | ||
|
@@ -59,6 +63,10 @@ | |
# define HAVE_CLOCK_GETTIME_RUNTIME 1 | ||
#endif | ||
|
||
// iOS/tvOS/watchOS *define* clock_settime, but it can't be used | ||
#if TARGET_OS_IPHONE | ||
# undef HAVE_CLOCK_SETTIME | ||
Comment on lines
+66
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
#endif | ||
|
||
#define SEC_TO_NS (1000 * 1000 * 1000) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,16 @@ | |
#endif | ||
|
||
|
||
#ifdef __APPLE__ | ||
# include "TargetConditionals.h" | ||
#endif /* __APPLE__ */ | ||
|
||
// iOS/tvOS/watchOS *define* some POSIX methods, | ||
// but raise a compiler error if they are used. | ||
#if TARGET_OS_IPHONE | ||
# undef HAVE_GETENTROPY | ||
Comment on lines
+47
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
#endif | ||
|
||
#ifdef Py_DEBUG | ||
int _Py_HashSecret_Initialized = 0; | ||
#else | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.