Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 52ac037

Browse files
committed
Added PyMac_Initialize() routine, to be used by embedding programs (in
stead of standard Py_Initialize(), which it calls).
1 parent 5cd7520 commit 52ac037

5 files changed

Lines changed: 532 additions & 516 deletions

File tree

Mac/Include/macglue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,4 @@ PyObject *PyMac_BuildEventRecord(EventRecord *); /* Convert EventRecord to PyObj
102102
int PyMac_GetFixed(PyObject *, Fixed *); /* argument parser for Fixed */
103103
PyObject *PyMac_BuildFixed(Fixed); /* Convert Fixed to PyObject */
104104
void PyMac_InitApplet(void); /* Initialize and run an Applet */
105+
void PyMac_Initialize(void); /* Initialize function for embedding Python */

Mac/Python/macmain.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ PyMac_InteractiveOptions(PyMac_PrefRecord *p, int *argcp, char ***argvp)
192192
** Initialization code, shared by interpreter and applets
193193
*/
194194
static void
195-
init_common(int *argcp, char ***argvp)
195+
init_common(int *argcp, char ***argvp, int embedded)
196196
{
197197
/* Remember resource fork refnum, for later */
198198
PyMac_AppRefNum = CurResFile();
@@ -223,11 +223,18 @@ init_common(int *argcp, char ***argvp)
223223
options.keep_error = 1; /* default-default */
224224
PyMac_PreferenceOptions(&options);
225225

226-
/* Create argc/argv. Do it before we go into the options event loop. */
227-
*argcp = PyMac_GetArgv(argvp, options.noargs);
228-
229-
/* Do interactive option setting, if allowed and <option> depressed */
230-
PyMac_InteractiveOptions(&options, argcp, argvp);
226+
if ( embedded ) {
227+
static char *emb_argv[] = {"embedded-python", 0};
228+
229+
*argcp = 1;
230+
*argvp = emb_argv;
231+
} else {
232+
/* Create argc/argv. Do it before we go into the options event loop. */
233+
*argcp = PyMac_GetArgv(argvp, options.noargs);
234+
235+
/* Do interactive option setting, if allowed and <option> depressed */
236+
PyMac_InteractiveOptions(&options, argcp, argvp);
237+
}
231238

232239
/* Copy selected options to where the machine-independent stuff wants it */
233240
Py_VerboseFlag = options.verbose;
@@ -310,7 +317,7 @@ PyMac_InitApplet()
310317
char **argv;
311318
int err;
312319

313-
init_common(&argc, &argv);
320+
init_common(&argc, &argv, 0);
314321

315322
Py_Initialize();
316323
PySys_SetArgv(argc, argv);
@@ -325,6 +332,20 @@ PyMac_InitApplet()
325332
/* XXX Should we bother to Py_Exit(sts)? */
326333
}
327334

335+
/*
336+
** Hook for embedding python.
337+
*/
338+
void
339+
PyMac_Initialize()
340+
{
341+
int argc;
342+
char **argv;
343+
344+
init_common(&argc, &argv, 1);
345+
Py_Initialize();
346+
PySys_SetArgv(argc, argv);
347+
}
348+
328349
#endif /* USE_MAC_APPLET_SUPPORT */
329350

330351
/* For normal application */
@@ -334,7 +355,7 @@ PyMac_InitApplication()
334355
int argc;
335356
char **argv;
336357

337-
init_common(&argc, &argv);
358+
init_common(&argc, &argv, 0);
338359

339360
if ( argc > 1 ) {
340361
/* We're running a script. Attempt to change current directory */

Mac/mwerks/projects/build.macppc.shared/PythonCorePPC.mu.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
inittab
2+
PyMac_Initialize
23
PyExc_ZeroDivisionError
34
PyExc_ValueError
45
PyExc_TypeError

0 commit comments

Comments
 (0)