Skip to content

Added support for MacOSX backend for PyPy #12633

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

Merged
merged 2 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/users/next_whats_new/2018-10-26-DM.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added support for MacOSX backend for PyPy
-----------------------------------------

Fixed issue with MacOSX backend for PyPy and also for non-framework Python
installations.
22 changes: 8 additions & 14 deletions src/_macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,11 @@ static void lazy_init(void) {
backend_inited = true;

NSApp = [NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

#ifndef PYPY
/* TODO: remove ifndef after the new PyPy with the PyOS_InputHook implementation
get released: https://bitbucket.org/pypy/pypy/commits/caaf91a */
PyOS_InputHook = wait_for_stdin;
#endif

Expand Down Expand Up @@ -2579,26 +2582,13 @@ static void context_cleanup(const void* info)
Timer_new, /* tp_new */
};

#ifndef COMPILING_FOR_10_6
static bool verify_framework(void)
{
ProcessSerialNumber psn;
/* These methods are deprecated, but they don't require the app to
have started */
#ifdef COMPILING_FOR_10_6
NSApp = [NSApplication sharedApplication];
NSApplicationActivationPolicy activationPolicy = [NSApp activationPolicy];
switch (activationPolicy) {
case NSApplicationActivationPolicyRegular:
case NSApplicationActivationPolicyAccessory:
return true;
case NSApplicationActivationPolicyProhibited:
break;
}
#else
if (CGMainDisplayID()!=0
&& GetCurrentProcess(&psn)==noErr
&& SetFrontProcess(&psn)==noErr) return true;
#endif
PyErr_SetString(PyExc_ImportError,
"Python is not installed as a framework. The Mac OS X backend will "
"not be able to function correctly if Python is not installed as a "
Expand All @@ -2610,6 +2600,7 @@ static bool verify_framework(void)
"Matplotlib FAQ for more information.");
return false;
}
#endif

static struct PyMethodDef methods[] = {
{"event_loop_is_running",
Expand Down Expand Up @@ -2660,8 +2651,11 @@ static bool verify_framework(void)
|| PyType_Ready(&TimerType) < 0)
return NULL;

#ifndef COMPILING_FOR_10_6
/* if >=10.6 invoke setActivationPolicy in lazy_init */
if (!verify_framework())
return NULL;
#endif

module = PyModule_Create(&moduledef);
if (!module)
Expand Down