[Python-checkins] python/dist/src/Mac/Modules/cg _CGmodule.c, 1.12, 1.13 cgsupport.py, 1.7, 1.8

jackjansen at users.sourceforge.net jackjansen at users.sourceforge.net
Wed Nov 19 11:34:05 EST 2003


Update of /cvsroot/python/python/dist/src/Mac/Modules/cg
In directory sc8-pr-cvs1:/tmp/cvs-serv32109/Mac/Modules/cg

Modified Files:
	_CGmodule.c cgsupport.py 
Log Message:
Getting rid of code conditional on TARGET_API_MAC_*.


Index: _CGmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/cg/_CGmodule.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** _CGmodule.c	19 Nov 2003 16:13:24 -0000	1.12
--- _CGmodule.c	19 Nov 2003 16:34:03 -0000	1.13
***************
*** 23,133 ****
  #include <ApplicationServices/ApplicationServices.h>
  
- #if !TARGET_API_MAC_OSX
- 	/* This code is adapted from the CallMachOFramework demo at:
-        http://developer.apple.com/samplecode/Sample_Code/Runtime_Architecture/CallMachOFramework.htm
-        It allows us to call Mach-O functions from CFM apps. */
- 
- 	#include <Folders.h>
- 	#include "CFMLateImport.h"
- 
- 	static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr)
- 		// This routine finds a the named framework and creates a CFBundle 
- 		// object for it.  It looks for the framework in the frameworks folder, 
- 		// as defined by the Folder Manager.  Currently this is 
- 		// "/System/Library/Frameworks", but we recommend that you avoid hard coded 
- 		// paths to ensure future compatibility.
- 		//
- 		// You might think that you could use CFBundleGetBundleWithIdentifier but 
- 		// that only finds bundles that are already loaded into your context. 
- 		// That would work in the case of the System framework but it wouldn't 
- 		// work if you're using some other, less-obvious, framework.
- 	{
- 		OSStatus 	err;
- 		FSRef 		frameworksFolderRef;
- 		CFURLRef	baseURL;
- 		CFURLRef	bundleURL;
- 		
- 		*bundlePtr = nil;
- 		
- 		baseURL = nil;
- 		bundleURL = nil;
- 		
- 		// Find the frameworks folder and create a URL for it.
- 		
- 		err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef);
- 		if (err == noErr) {
- 			baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
- 			if (baseURL == nil) {
- 				err = coreFoundationUnknownErr;
- 			}
- 		}
- 		
- 		// Append the name of the framework to the URL.
- 		
- 		if (err == noErr) {
- 			bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework, false);
- 			if (bundleURL == nil) {
- 				err = coreFoundationUnknownErr;
- 			}
- 		}
- 		
- 		// Create a bundle based on that URL and load the bundle into memory.
- 		// We never unload the bundle, which is reasonable in this case because 
- 		// the sample assumes that you'll be calling functions from this 
- 		// framework throughout the life of your application.
- 		
- 		if (err == noErr) {
- 			*bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
- 			if (*bundlePtr == nil) {
- 				err = coreFoundationUnknownErr;
- 			}
- 		}
- 		if (err == noErr) {
- 		    if ( ! CFBundleLoadExecutable( *bundlePtr ) ) {
- 				err = coreFoundationUnknownErr;
- 		    }
- 		}
- 
- 		// Clean up.
- 		
- 		if (err != noErr && *bundlePtr != nil) {
- 			CFRelease(*bundlePtr);
- 			*bundlePtr = nil;
- 		}
- 		if (bundleURL != nil) {
- 			CFRelease(bundleURL);
- 		}	
- 		if (baseURL != nil) {
- 			CFRelease(baseURL);
- 		}	
- 		
- 		return err;
- 	}
- 
- 
- 
- 	// The CFMLateImport approach requires that you define a fragment 
- 	// initialisation routine that latches the fragment's connection 
- 	// ID and locator.  If your code already has a fragment initialiser 
- 	// you will have to integrate the following into it.
- 
- 	static CFragConnectionID 			gFragToFixConnID;
- 	static FSSpec 						gFragToFixFile;
- 	static CFragSystem7DiskFlatLocator 	gFragToFixLocator;
- 
- 	extern OSErr FragmentInit(const CFragInitBlock *initBlock);
- 	extern OSErr FragmentInit(const CFragInitBlock *initBlock)
- 	{
- 		__initialize(initBlock); /* call the "original" initializer */
- 		gFragToFixConnID	= (CFragConnectionID) initBlock->closureID;
- 		gFragToFixFile 		= *(initBlock->fragLocator.u.onDisk.fileSpec);
- 		gFragToFixLocator 	= initBlock->fragLocator.u.onDisk;
- 		gFragToFixLocator.fileSpec = &gFragToFixFile;
- 		
- 		return noErr;
- 	}
- 
- #endif
- 
  extern int GrafObj_Convert(PyObject *, GrafPtr *);
  
--- 23,26 ----
***************
*** 1369,1389 ****
  
  
- 
- #if !TARGET_API_MAC_OSX
- 	CFBundleRef sysBundle;
- 	OSStatus err;
- 
- 	if (&LoadFrameworkBundle == NULL) {
- 		PyErr_SetString(PyExc_ImportError, "CoreCraphics not supported");
- 		return;
- 	}
- 	err = LoadFrameworkBundle(CFSTR("ApplicationServices.framework"), &sysBundle);
- 	if (err == noErr)
- 		err = CFMLateImportBundle(&gFragToFixLocator, gFragToFixConnID, FragmentInit, "\pCGStubLib", sysBundle);
- 	if (err != noErr) {
- 		PyErr_SetString(PyExc_ImportError, "CoreCraphics not supported");
- 		return;
- 	};
- #endif  /* !TARGET_API_MAC_OSX */
  
  
--- 1262,1265 ----

Index: cgsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/cg/cgsupport.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** cgsupport.py	19 Nov 2003 16:13:25 -0000	1.7
--- cgsupport.py	19 Nov 2003 16:34:03 -0000	1.8
***************
*** 26,136 ****
  #include <ApplicationServices/ApplicationServices.h>
  
- #if !TARGET_API_MAC_OSX
- 	/* This code is adapted from the CallMachOFramework demo at:
-        http://developer.apple.com/samplecode/Sample_Code/Runtime_Architecture/CallMachOFramework.htm
-        It allows us to call Mach-O functions from CFM apps. */
- 
- 	#include <Folders.h>
- 	#include "CFMLateImport.h"
- 
- 	static OSStatus LoadFrameworkBundle(CFStringRef framework, CFBundleRef *bundlePtr)
- 		// This routine finds a the named framework and creates a CFBundle 
- 		// object for it.  It looks for the framework in the frameworks folder, 
- 		// as defined by the Folder Manager.  Currently this is 
- 		// "/System/Library/Frameworks", but we recommend that you avoid hard coded 
- 		// paths to ensure future compatibility.
- 		//
- 		// You might think that you could use CFBundleGetBundleWithIdentifier but 
- 		// that only finds bundles that are already loaded into your context. 
- 		// That would work in the case of the System framework but it wouldn't 
- 		// work if you're using some other, less-obvious, framework.
- 	{
- 		OSStatus 	err;
- 		FSRef 		frameworksFolderRef;
- 		CFURLRef	baseURL;
- 		CFURLRef	bundleURL;
- 		
- 		*bundlePtr = nil;
- 		
- 		baseURL = nil;
- 		bundleURL = nil;
- 		
- 		// Find the frameworks folder and create a URL for it.
- 		
- 		err = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, true, &frameworksFolderRef);
- 		if (err == noErr) {
- 			baseURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &frameworksFolderRef);
- 			if (baseURL == nil) {
- 				err = coreFoundationUnknownErr;
- 			}
- 		}
- 		
- 		// Append the name of the framework to the URL.
- 		
- 		if (err == noErr) {
- 			bundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL, framework, false);
- 			if (bundleURL == nil) {
- 				err = coreFoundationUnknownErr;
- 			}
- 		}
- 		
- 		// Create a bundle based on that URL and load the bundle into memory.
- 		// We never unload the bundle, which is reasonable in this case because 
- 		// the sample assumes that you'll be calling functions from this 
- 		// framework throughout the life of your application.
- 		
- 		if (err == noErr) {
- 			*bundlePtr = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL);
- 			if (*bundlePtr == nil) {
- 				err = coreFoundationUnknownErr;
- 			}
- 		}
- 		if (err == noErr) {
- 		    if ( ! CFBundleLoadExecutable( *bundlePtr ) ) {
- 				err = coreFoundationUnknownErr;
- 		    }
- 		}
- 
- 		// Clean up.
- 		
- 		if (err != noErr && *bundlePtr != nil) {
- 			CFRelease(*bundlePtr);
- 			*bundlePtr = nil;
- 		}
- 		if (bundleURL != nil) {
- 			CFRelease(bundleURL);
- 		}	
- 		if (baseURL != nil) {
- 			CFRelease(baseURL);
- 		}	
- 		
- 		return err;
- 	}
- 
- 
- 
- 	// The CFMLateImport approach requires that you define a fragment 
- 	// initialisation routine that latches the fragment's connection 
- 	// ID and locator.  If your code already has a fragment initialiser 
- 	// you will have to integrate the following into it.
- 
- 	static CFragConnectionID 			gFragToFixConnID;
- 	static FSSpec 						gFragToFixFile;
- 	static CFragSystem7DiskFlatLocator 	gFragToFixLocator;
- 
- 	extern OSErr FragmentInit(const CFragInitBlock *initBlock);
- 	extern OSErr FragmentInit(const CFragInitBlock *initBlock)
- 	{
- 		__initialize(initBlock); /* call the "original" initializer */
- 		gFragToFixConnID	= (CFragConnectionID) initBlock->closureID;
- 		gFragToFixFile 		= *(initBlock->fragLocator.u.onDisk.fileSpec);
- 		gFragToFixLocator 	= initBlock->fragLocator.u.onDisk;
- 		gFragToFixLocator.fileSpec = &gFragToFixFile;
- 		
- 		return noErr;
- 	}
- 
- #endif
- 
  extern int GrafObj_Convert(PyObject *, GrafPtr *);
  
--- 26,29 ----
***************
*** 204,226 ****
  	return 1;
  }
- """
- 
- initstuff = initstuff + """
- #if !TARGET_API_MAC_OSX
- CFBundleRef sysBundle;
- OSStatus err;
- 
- if (&LoadFrameworkBundle == NULL) {
- 	PyErr_SetString(PyExc_ImportError, "CoreCraphics not supported");
- 	return;
- }
- err = LoadFrameworkBundle(CFSTR("ApplicationServices.framework"), &sysBundle);
- if (err == noErr)
- 	err = CFMLateImportBundle(&gFragToFixLocator, gFragToFixConnID, FragmentInit, "\pCGStubLib", sysBundle);
- if (err != noErr) {
- 	PyErr_SetString(PyExc_ImportError, "CoreCraphics not supported");
- 	return;
- };
- #endif  /* !TARGET_API_MAC_OSX */
  """
  
--- 97,100 ----





More information about the Python-checkins mailing list