mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Got the first MacPython module working under MacOSX/MachO (gestalt). Main changes
are including Carbon/Carbon.h in stead of the old headers (unless WITHOUT_FRAMEWORKS is defined, as it will be for classic MacPython) and selectively disabling all the stuff that is unneeded in a unix-Python (event handling, etc).
This commit is contained in:
parent
6e68a7e74f
commit
0194ad5c7d
3 changed files with 55 additions and 54 deletions
|
@ -22,10 +22,14 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
|
#ifdef WITHOUT_FRAMEWORKS
|
||||||
#include <Types.h>
|
#include <Types.h>
|
||||||
#include <Files.h>
|
#include <Files.h>
|
||||||
#include <Events.h>
|
#include <Events.h>
|
||||||
#include <StandardFile.h>
|
#include <StandardFile.h>
|
||||||
|
#else
|
||||||
|
#include <Carbon/Carbon.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -47,6 +51,8 @@ extern void PyMac_SetGUSISpin(void); /* Install our private GUSI spin routine *
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *PyMac_StrError(int); /* strerror with mac errors */
|
char *PyMac_StrError(int); /* strerror with mac errors */
|
||||||
|
PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */
|
||||||
|
PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */
|
||||||
unsigned char *Pstring(char *str); /* Convert c-string to pascal-string in static buffer */
|
unsigned char *Pstring(char *str); /* Convert c-string to pascal-string in static buffer */
|
||||||
|
|
||||||
#ifdef USE_GUSI
|
#ifdef USE_GUSI
|
||||||
|
@ -65,19 +71,20 @@ extern int PyMac_AppearanceCompliant; /* True if in appearance support mode */
|
||||||
extern PyObject *PyMac_OSErrException; /* Exception for OSErr */
|
extern PyObject *PyMac_OSErrException; /* Exception for OSErr */
|
||||||
PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */
|
PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */
|
||||||
|
|
||||||
|
#if !TARGET_API_MAC_OSX
|
||||||
void PyMac_GetSchedParams(PyMacSchedParams *); /* Get schedulers params */
|
void PyMac_GetSchedParams(PyMacSchedParams *); /* Get schedulers params */
|
||||||
void PyMac_SetSchedParams(PyMacSchedParams *); /* Set schedulers params */
|
void PyMac_SetSchedParams(PyMacSchedParams *); /* Set schedulers params */
|
||||||
PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */
|
|
||||||
PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */
|
|
||||||
int PyMac_DoYield(int, int); /* Yield cpu. First arg is maxtime, second ok to call python */
|
int PyMac_DoYield(int, int); /* Yield cpu. First arg is maxtime, second ok to call python */
|
||||||
|
#endif
|
||||||
int PyMac_HandleEvent(EventRecord *); /* Handle one event, possibly in Python */
|
int PyMac_HandleEvent(EventRecord *); /* Handle one event, possibly in Python */
|
||||||
void PyMac_HandleEventIntern(EventRecord *); /* Handle one event internal only */
|
void PyMac_HandleEventIntern(EventRecord *); /* Handle one event internal only */
|
||||||
int PyMac_SetEventHandler(PyObject *); /* set python-coded event handler */
|
int PyMac_SetEventHandler(PyObject *); /* set python-coded event handler */
|
||||||
|
|
||||||
|
#if !TARGET_API_MAC_OSX
|
||||||
void PyMac_InitMenuBar(void); /* Setup menu bar as we want it */
|
void PyMac_InitMenuBar(void); /* Setup menu bar as we want it */
|
||||||
void PyMac_RestoreMenuBar(void); /* Restore menu bar for ease of exiting */
|
void PyMac_RestoreMenuBar(void); /* Restore menu bar for ease of exiting */
|
||||||
void PyMac_RaiseConsoleWindow(); /* Bring console window to front, if it exists */
|
void PyMac_RaiseConsoleWindow(); /* Bring console window to front, if it exists */
|
||||||
|
#endif
|
||||||
int PyMac_FindResourceModule(PyStringObject *, char *, char *); /* Test for 'PYC ' resource in a file */
|
int PyMac_FindResourceModule(PyStringObject *, char *, char *); /* Test for 'PYC ' resource in a file */
|
||||||
PyObject * PyMac_LoadResourceModule(char *, char *); /* Load 'PYC ' resource from file */
|
PyObject * PyMac_LoadResourceModule(char *, char *); /* Load 'PYC ' resource from file */
|
||||||
int PyMac_FindCodeResourceModule(PyStringObject *, char *, char *); /* Test for 'PYD ' resource in a file */
|
int PyMac_FindCodeResourceModule(PyStringObject *, char *, char *); /* Test for 'PYD ' resource in a file */
|
||||||
|
|
|
@ -27,8 +27,12 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "macglue.h"
|
#include "macglue.h"
|
||||||
|
|
||||||
|
#ifdef WITHOUT_FRAMEWORKS
|
||||||
#include <Types.h>
|
#include <Types.h>
|
||||||
#include <Gestalt.h>
|
#include <Gestalt.h>
|
||||||
|
#else
|
||||||
|
#include <Carbon/Carbon.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
gestalt_gestalt(self, args)
|
gestalt_gestalt(self, args)
|
||||||
|
|
|
@ -22,24 +22,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
#ifdef __CFM68K__
|
|
||||||
/* cfm68k InterfaceLib exports GetEventQueue, but Events.h doesn't know this
|
|
||||||
** and defines it as GetEvQHdr (which is correct for PPC). This fix is for
|
|
||||||
** CW9, check that the workaround is still needed for the next release.
|
|
||||||
*/
|
|
||||||
#define GetEvQHdr GetEventQueue
|
|
||||||
#endif /* __CFM68K__ */
|
|
||||||
|
|
||||||
#include <Events.h>
|
|
||||||
|
|
||||||
#if !TARGET_API_MAC_OS8
|
|
||||||
/* Unfortunately this call is probably slower... */
|
|
||||||
#define LMGetTicks() TickCount()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __CFM68K__
|
|
||||||
#undef GetEventQueue
|
|
||||||
#endif /* __CFM68K__ */
|
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
|
||||||
|
@ -50,6 +32,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "pythonresources.h"
|
#include "pythonresources.h"
|
||||||
|
|
||||||
|
#ifdef WITHOUT_FRAMEWORKS
|
||||||
#include <OSUtils.h> /* for Set(Current)A5 */
|
#include <OSUtils.h> /* for Set(Current)A5 */
|
||||||
#include <Files.h>
|
#include <Files.h>
|
||||||
#include <StandardFile.h>
|
#include <StandardFile.h>
|
||||||
|
@ -61,6 +44,29 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <Fonts.h>
|
#include <Fonts.h>
|
||||||
#include <Menus.h>
|
#include <Menus.h>
|
||||||
#include <TextUtils.h>
|
#include <TextUtils.h>
|
||||||
|
#include <LowMem.h>
|
||||||
|
#ifdef __CFM68K__
|
||||||
|
/* cfm68k InterfaceLib exports GetEventQueue, but Events.h doesn't know this
|
||||||
|
** and defines it as GetEvQHdr (which is correct for PPC). This fix is for
|
||||||
|
** CW9, check that the workaround is still needed for the next release.
|
||||||
|
*/
|
||||||
|
#define GetEvQHdr GetEventQueue
|
||||||
|
#endif /* __CFM68K__ */
|
||||||
|
|
||||||
|
#include <Events.h>
|
||||||
|
|
||||||
|
#ifdef __CFM68K__
|
||||||
|
#undef GetEventQueue
|
||||||
|
#endif /* __CFM68K__ */
|
||||||
|
#else
|
||||||
|
#include <Carbon/Carbon.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !TARGET_API_MAC_OS8
|
||||||
|
/* Unfortunately this call is probably slower... */
|
||||||
|
#define LMGetTicks() TickCount()
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __MWERKS__
|
#ifdef __MWERKS__
|
||||||
#include <SIOUX.h>
|
#include <SIOUX.h>
|
||||||
extern void SIOUXSetupMenus(void);
|
extern void SIOUXSetupMenus(void);
|
||||||
|
@ -80,7 +86,6 @@ extern pascal unsigned char *PLstrrchr(unsigned char *, unsigned char);
|
||||||
#include <TFileSpec.h> /* For Path2FSSpec */
|
#include <TFileSpec.h> /* For Path2FSSpec */
|
||||||
#include <GUSI.h>
|
#include <GUSI.h>
|
||||||
#endif
|
#endif
|
||||||
#include <LowMem.h>
|
|
||||||
|
|
||||||
/* The ID of the Sioux apple menu */
|
/* The ID of the Sioux apple menu */
|
||||||
#define SIOUX_APPLEID 32000
|
#define SIOUX_APPLEID 32000
|
||||||
|
@ -132,7 +137,9 @@ extern PyObject *newmfssobject(FSSpec *);
|
||||||
static int interrupted; /* Set to true when cmd-. seen */
|
static int interrupted; /* Set to true when cmd-. seen */
|
||||||
static RETSIGTYPE intcatcher(int);
|
static RETSIGTYPE intcatcher(int);
|
||||||
|
|
||||||
|
#if !TARGET_API_MAC_OSX
|
||||||
static int PyMac_Yield(void);
|
static int PyMac_Yield(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** These are the real scheduling parameters that control what we check
|
** These are the real scheduling parameters that control what we check
|
||||||
|
@ -466,6 +473,7 @@ PyOS_CheckStack()
|
||||||
}
|
}
|
||||||
#endif /* USE_STACKCHECK */
|
#endif /* USE_STACKCHECK */
|
||||||
|
|
||||||
|
#if !TARGET_API_MAC_OSX
|
||||||
/* The catcher routine (which may not be used for all compilers) */
|
/* The catcher routine (which may not be used for all compilers) */
|
||||||
static RETSIGTYPE
|
static RETSIGTYPE
|
||||||
intcatcher(sig)
|
intcatcher(sig)
|
||||||
|
@ -539,31 +547,13 @@ PyErr_CheckSignals()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
/*
|
|
||||||
** This routine is called if we know that an external library yielded
|
|
||||||
** to background tasks, so we shouldn't count that time in our computation
|
|
||||||
** of how much CPU we used.
|
|
||||||
** This happens with SIOUX, and the routine is called from our modified
|
|
||||||
** GUSISIOUX.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
PyMac_LibraryDidYield(int howlong)
|
|
||||||
{
|
|
||||||
unsigned long maxnextcheck = (unsigned long)LMGetTicks() + schedparams.check_interval;
|
|
||||||
|
|
||||||
schedparams.next_check = schedparams.next_check + howlong;
|
|
||||||
if (schedparams.next_check > maxnextcheck )
|
|
||||||
schedparams.next_check = maxnextcheck;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int
|
int
|
||||||
PyOS_InterruptOccurred()
|
PyOS_InterruptOccurred()
|
||||||
{
|
{
|
||||||
scan_event_queue(1);
|
scan_event_queue(1);
|
||||||
return interrupted;
|
return interrupted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether we are in the foreground */
|
/* Check whether we are in the foreground */
|
||||||
static int
|
static int
|
||||||
PyMac_InForeground(void)
|
PyMac_InForeground(void)
|
||||||
|
@ -582,8 +572,8 @@ PyMac_InForeground(void)
|
||||||
else if ( SameProcess(&ours, &curfg, &eq) < 0 )
|
else if ( SameProcess(&ours, &curfg, &eq) < 0 )
|
||||||
eq = 1;
|
eq = 1;
|
||||||
return (int)eq;
|
return (int)eq;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
PyMac_SetEventHandler(PyObject *evh)
|
PyMac_SetEventHandler(PyObject *evh)
|
||||||
|
@ -655,6 +645,7 @@ PyMac_HandleEvent(evp)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !TARGET_API_MAC_OSX
|
||||||
/*
|
/*
|
||||||
** Yield the CPU to other tasks without processing events.
|
** Yield the CPU to other tasks without processing events.
|
||||||
*/
|
*/
|
||||||
|
@ -845,18 +836,9 @@ SIOUXDoAboutBox(void)
|
||||||
DisposeDialog(theDialog);
|
DisposeDialog(theDialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#endif /* !TARGET_API_MAC_OSX */
|
||||||
int
|
|
||||||
PyMac_FileExists(char *name)
|
|
||||||
{
|
|
||||||
FSSpec fss;
|
|
||||||
|
|
||||||
if ( FSMakeFSSpec(0, 0, Pstring(name), &fss) == noErr )
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#if TARGET_API_MAC_OS8
|
||||||
/*
|
/*
|
||||||
** Helper routine for GetDirectory
|
** Helper routine for GetDirectory
|
||||||
*/
|
*/
|
||||||
|
@ -878,7 +860,7 @@ myhook_proc(short item, DialogPtr theDialog, struct hook_args *dataptr)
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
#if TARGET_API_MAC_OS8
|
|
||||||
/*
|
/*
|
||||||
** Ask the user for a directory. I still can't understand
|
** Ask the user for a directory. I still can't understand
|
||||||
** why Apple doesn't provide a standard solution for this...
|
** why Apple doesn't provide a standard solution for this...
|
||||||
|
@ -1016,12 +998,15 @@ PyMac_GetFSSpec(PyObject *v, FSSpec *fs)
|
||||||
OSErr err;
|
OSErr err;
|
||||||
FSSpec *fs2;
|
FSSpec *fs2;
|
||||||
|
|
||||||
|
#if !TARGET_API_MAC_OSX
|
||||||
|
/* XXX This #if is temporary */
|
||||||
/* first check whether it already is an FSSpec */
|
/* first check whether it already is an FSSpec */
|
||||||
fs2 = mfs_GetFSSpecFSSpec(v);
|
fs2 = mfs_GetFSSpecFSSpec(v);
|
||||||
if ( fs2 ) {
|
if ( fs2 ) {
|
||||||
(void)FSMakeFSSpec(fs2->vRefNum, fs2->parID, fs2->name, fs);
|
(void)FSMakeFSSpec(fs2->vRefNum, fs2->parID, fs2->name, fs);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if ( PyString_Check(v) ) {
|
if ( PyString_Check(v) ) {
|
||||||
/* It's a pathname */
|
/* It's a pathname */
|
||||||
if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) )
|
if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) )
|
||||||
|
@ -1045,7 +1030,12 @@ PyMac_GetFSSpec(PyObject *v, FSSpec *fs)
|
||||||
/* Convert FSSpec to PyObject */
|
/* Convert FSSpec to PyObject */
|
||||||
PyObject *PyMac_BuildFSSpec(FSSpec *v)
|
PyObject *PyMac_BuildFSSpec(FSSpec *v)
|
||||||
{
|
{
|
||||||
|
#if TARGET_API_MAC_OSX
|
||||||
|
PyErr_SetString(PyExc_NotImplementedError, "FSSpec not yet done for OSX");
|
||||||
|
return NULL;
|
||||||
|
#else
|
||||||
return newmfssobject(v);
|
return newmfssobject(v);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert a Python object to a Rect.
|
/* Convert a Python object to a Rect.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue