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

Skip to content

Commit ab57c7d

Browse files
committed
Moved macfsn hackery from macmain.c to macfsmodule.c so it loads
on demand instead of at startup.
1 parent e2ec3eb commit ab57c7d

2 files changed

Lines changed: 32 additions & 30 deletions

File tree

Mac/Modules/macfsmodule.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3939

4040
#include "getapplbycreator.h"
4141

42+
#include "pythonresources.h"
43+
extern PyMac_PrefRecord PyMac_options;
44+
4245
#ifdef USE_TOOLBOX_OBJECT_GLUE
4346
extern int _PyMac_GetFSSpec(PyObject *, FSSpec *);
4447
extern PyObject *_PyMac_BuildFSSpec(FSSpec *);
@@ -1206,6 +1209,33 @@ PyObject *PyMac_BuildFSSpec(FSSpec *v)
12061209
return (PyObject *)newmfssobject(v);
12071210
}
12081211

1212+
1213+
/*
1214+
** Import the macfsn module, which will override the Standard File
1215+
** calls in the macfs builtin module by Navigation Services versions,
1216+
** if available on this machine.
1217+
*/
1218+
static void
1219+
PyMac_InstallNavServicesForSF(void)
1220+
{
1221+
if ( !PyMac_options.nonavservice ) {
1222+
PyObject *m = PyImport_ImportModule("macfsn");
1223+
1224+
if ( m == NULL ) {
1225+
PySys_WriteStderr("'import macfsn' failed; ");
1226+
if (Py_VerboseFlag) {
1227+
PySys_WriteStderr("traceback:\n");
1228+
PyErr_Print();
1229+
}
1230+
else {
1231+
PySys_WriteStderr("use -v for traceback\n");
1232+
}
1233+
PyErr_Clear();
1234+
}
1235+
}
1236+
}
1237+
1238+
12091239
/* Initialization function for the module (*must* be called initmacfs) */
12101240

12111241
void
@@ -1235,5 +1265,6 @@ initmacfs(void)
12351265
Mfsitype.ob_type = &PyType_Type;
12361266
Py_INCREF(&Mfsitype);
12371267
PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype);
1238-
/* XXXX Add constants here */
1268+
1269+
PyMac_InstallNavServicesForSF();
12391270
}

Mac/Python/macmain.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -392,31 +392,6 @@ run_inspect(void)
392392
return sts;
393393
}
394394

395-
/*
396-
** Import the macfsn module, which will override the Standard File
397-
** calls in the macfs builtin module by Navigation Services versions,
398-
** if available on this machine.
399-
*/
400-
static void
401-
PyMac_InstallNavServicesForSF(void)
402-
{
403-
if ( !PyMac_options.nonavservice ) {
404-
PyObject *m = PyImport_ImportModule("macfsn");
405-
406-
if ( m == NULL ) {
407-
PySys_WriteStderr("'import macfsn' failed; ");
408-
if (Py_VerboseFlag) {
409-
PySys_WriteStderr("traceback:\n");
410-
PyErr_Print();
411-
}
412-
else {
413-
PySys_WriteStderr("use -v for traceback\n");
414-
}
415-
PyErr_Clear();
416-
}
417-
}
418-
}
419-
420395
#ifdef USE_MAC_APPLET_SUPPORT
421396
/* Applet support */
422397

@@ -464,7 +439,6 @@ PyMac_InitApplet(void)
464439
init_common(&argc, &argv, 0);
465440

466441
Py_Initialize();
467-
PyMac_InstallNavServicesForSF();
468442
PySys_SetArgv(argc, argv);
469443

470444
err = run_main_resource();
@@ -488,7 +462,6 @@ PyMac_Initialize(void)
488462

489463
init_common(&argc, &argv, 1);
490464
Py_Initialize();
491-
PyMac_InstallNavServicesForSF();
492465
PySys_SetArgv(argc, argv);
493466
}
494467

@@ -675,8 +648,6 @@ Py_Main(int argc, char **argv, char *filename)
675648

676649
PyUnicode_SetDefaultEncoding(PyMac_getscript());
677650

678-
PyMac_InstallNavServicesForSF();
679-
680651
PySys_SetArgv(argc, argv);
681652

682653
if (filename == NULL && isatty((int)fileno(fp))) {

0 commit comments

Comments
 (0)