@@ -579,20 +579,32 @@ char *filename;
579579 int ok ;
580580 Handle h ;
581581
582- if ( FSMakeFSSpec (0 , 0 , Pstring (filename ), & fss ) != noErr )
583- return 0 ; /* It doesn't exist */
584- if ( FSpGetFInfo (& fss , & finfo ) != noErr )
585- return 0 ; /* shouldn't happen, I guess */
586- oldrh = CurResFile ();
587- filerh = FSpOpenResFile (& fss , fsRdPerm );
588- if ( filerh == -1 )
589- return 0 ;
590- UseResFile (filerh );
582+ if ( strcmp (filename , PyMac_ApplicationPath ) == 0 ) {
583+ /*
584+ ** Special case: the application itself. Use a shortcut to
585+ ** forestall opening and closing the application numerous times
586+ ** (which is dead slow when running from CDROM)
587+ */
588+ oldrh = CurResFile ();
589+ UseResFile (PyMac_AppRefNum );
590+ filerh = -1 ;
591+ } else {
592+ if ( FSMakeFSSpec (0 , 0 , Pstring (filename ), & fss ) != noErr )
593+ return 0 ; /* It doesn't exist */
594+ if ( FSpGetFInfo (& fss , & finfo ) != noErr )
595+ return 0 ; /* shouldn't happen, I guess */
596+ oldrh = CurResFile ();
597+ filerh = FSpOpenResFile (& fss , fsRdPerm );
598+ if ( filerh == -1 )
599+ return 0 ;
600+ UseResFile (filerh );
601+ }
591602 SetResLoad (0 );
592603 h = Get1NamedResource ('PYC ' , Pstring (module ));
593604 SetResLoad (1 );
594605 ok = (h != NULL );
595- CloseResFile (filerh );
606+ if ( filerh != -1 )
607+ CloseResFile (filerh );
596608 UseResFile (oldrh );
597609 return ok ;
598610}
@@ -613,17 +625,28 @@ char *filename;
613625 PyObject * m , * co ;
614626 long num , size ;
615627
616- if ( (err = FSMakeFSSpec (0 , 0 , Pstring (filename ), & fss )) != noErr )
617- goto error ;
618- if ( (err = FSpGetFInfo (& fss , & finfo )) != noErr )
619- goto error ;
620- oldrh = CurResFile ();
621- filerh = FSpOpenResFile (& fss , fsRdPerm );
622- if ( filerh == -1 ) {
623- err = ResError ();
624- goto error ;
628+ if ( strcmp (filename , PyMac_ApplicationPath ) == 0 ) {
629+ /*
630+ ** Special case: the application itself. Use a shortcut to
631+ ** forestall opening and closing the application numerous times
632+ ** (which is dead slow when running from CDROM)
633+ */
634+ oldrh = CurResFile ();
635+ UseResFile (PyMac_AppRefNum );
636+ filerh = -1 ;
637+ } else {
638+ if ( (err = FSMakeFSSpec (0 , 0 , Pstring (filename ), & fss )) != noErr )
639+ goto error ;
640+ if ( (err = FSpGetFInfo (& fss , & finfo )) != noErr )
641+ goto error ;
642+ oldrh = CurResFile ();
643+ filerh = FSpOpenResFile (& fss , fsRdPerm );
644+ if ( filerh == -1 ) {
645+ err = ResError ();
646+ goto error ;
647+ }
648+ UseResFile (filerh );
625649 }
626- UseResFile (filerh );
627650 h = Get1NamedResource ('PYC ' , Pstring (module ));
628651 if ( h == NULL ) {
629652 err = ResError ();
@@ -651,7 +674,8 @@ char *filename;
651674 }
652675 }
653676 HUnlock (h );
654- CloseResFile (filerh );
677+ if ( filerh != -1 )
678+ CloseResFile (filerh );
655679 UseResFile (oldrh );
656680 if ( co ) {
657681 m = PyImport_ExecCodeModule (module , co );
0 commit comments