MacOS X: Enable 4-way universal builds

This patch adds a new configure argument on OSX:
        --with-universal-archs=[32-bit|64-bit|all]

When used with the --enable-universalsdk option this controls which
CPU architectures are includes in the framework. The default is 32-bit,
meaning i386 and ppc. The most useful alternative is 'all', which includes
all 4 CPU architectures supported by MacOS X (i386, ppc, x86_64 and ppc64).

This includes limited support for the Carbon bindings in 64-bit mode as well,
limited because (a) I haven't done extensive testing and (b) a large portion
of the Carbon API's aren't available in 64-bit mode anyway.

I've also duplicated a feature of Apple's build of python: setting the
environment variable 'ARCHFLAGS' controls the '-arch' flags used for building
extensions using distutils.
diff --git a/Mac/IDLE/Makefile.in b/Mac/IDLE/Makefile.in
index 600f1fc..c06ca06 100644
--- a/Mac/IDLE/Makefile.in
+++ b/Mac/IDLE/Makefile.in
@@ -42,7 +42,7 @@
 		$(srcdir)/../Icons/PythonSource.icns \
 		$(srcdir)/../Icons/PythonCompiled.icns Info.plist
 	rm -fr IDLE.app
-	$(RUNSHARED) $(BUILDPYTHON) $(BUNDLEBULDER) \
+	$(RUNSHARED) arch -ppc -i386 $(BUILDPYTHON) $(BUNDLEBULDER) \
 		--builddir=. \
 		--name=IDLE \
 		--link-exec \
@@ -51,7 +51,7 @@
 		--iconfile=$(srcdir)/../Icons/IDLE.icns \
 		--resource=$(srcdir)/../Icons/PythonSource.icns \
 		--resource=$(srcdir)/../Icons/PythonCompiled.icns \
-		--python=$(prefix)/Resources/Python.app/Contents/MacOS/Python \
+		--python=$(prefix)/Resources/Python.app/Contents/MacOS/$(PYTHONFRAMEWORK)`test -f "$(DESTDIR)$(prefix)/Resources/Python.app/Contents/MacOS/$(PYTHONFRAMEWORK)-32" && echo "-32"`  \
 		build
 
 
diff --git a/Mac/IDLE/idlemain.py b/Mac/IDLE/idlemain.py
index aa75d4c..9b52738 100644
--- a/Mac/IDLE/idlemain.py
+++ b/Mac/IDLE/idlemain.py
@@ -13,7 +13,10 @@
 # Make sure sys.executable points to the python interpreter inside the
 # framework, instead of at the helper executable inside the application
 # bundle (the latter works, but doesn't allow access to the window server)
-sys.executable = os.path.join(sys.prefix, 'bin', 'python')
+if sys.executable.endswith('-32'):
+    sys.executable = os.path.join(sys.prefix, 'bin', 'python-32')
+else:
+    sys.executable = os.path.join(sys.prefix, 'bin', 'python')
 
 # Look for the -psn argument that the launcher adds and remove it, it will
 # only confuse the IDLE startup code.
diff --git a/Mac/Makefile.in b/Mac/Makefile.in
index 34734d0..b241fa4 100644
--- a/Mac/Makefile.in
+++ b/Mac/Makefile.in
@@ -49,12 +49,42 @@
 installapps: install_Python install_BuildApplet install_PythonLauncher \
 	install_IDLE checkapplepython install_pythonw install_versionedtools
 
+installapps4way: install_Python4way install_BuildApplet install_PythonLauncher install_IDLE install_pythonw4way install_versionedtools
+
+
 install_pythonw: pythonw
 	$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)"
 	$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/python$(VERSION)"
 	ln -sf python$(VERSION) "$(DESTDIR)$(prefix)/bin/python"
 	ln -sf pythonw$(VERSION) "$(DESTDIR)$(prefix)/bin/pythonw"
 
+
+# Install 3 variants of python/pythonw: 
+# 	- 32-bit (i386 and ppc)
+# 	- 64-bit (x86_64 and ppc64)
+# 	- all    (all four architectures)
+# 	- Make 'python' and 'pythonw' aliases for the 32-bit variant
+install_pythonw4way: pythonw-32 pythonw-64 pythonw
+	$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw-64 "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)-64"
+	$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw-64 "$(DESTDIR)$(prefix)/bin/python$(VERSION)-64"
+	ln -sf python$(VERSION)-64 "$(DESTDIR)$(prefix)/bin/python-64"
+	ln -sf pythonw$(VERSION)-64 "$(DESTDIR)$(prefix)/bin/pythonw-64"
+
+	$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw-32 "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)-32"
+	$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw-32 "$(DESTDIR)$(prefix)/bin/python$(VERSION)-32"
+	ln -sf python$(VERSION)-32 "$(DESTDIR)$(prefix)/bin/python-32"
+	ln -sf pythonw$(VERSION)-32 "$(DESTDIR)$(prefix)/bin/pythonw-32"
+
+	$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)-all"
+	$(INSTALL_PROGRAM) $(STRIPFLAG) pythonw "$(DESTDIR)$(prefix)/bin/python$(VERSION)-all"
+	ln -sf python$(VERSION)-all "$(DESTDIR)$(prefix)/bin/python-all"
+	ln -sf pythonw$(VERSION)-all "$(DESTDIR)$(prefix)/bin/pythonw-all"
+
+	ln -sf pythonw$(VERSION)-32	"$(DESTDIR)$(prefix)/bin/pythonw$(VERSION)"
+	ln -sf python$(VERSION)-32	"$(DESTDIR)$(prefix)/bin/python$(VERSION)"
+	ln -sf pythonw$(VERSION)-32	"$(DESTDIR)$(prefix)/bin/pythonw"
+	ln -sf python$(VERSION)-32	"$(DESTDIR)$(prefix)/bin/python"
+
 #
 # Install unix tools in /usr/local/bin. These are just aliases for the 
 # actual installation inside the framework.
@@ -65,11 +95,16 @@
 	fi
 	for fn in python pythonw idle pydoc python-config smtpd.py   \
 		  python$(VERSION) pythonw$(VERSION) idle$(VERSION) \
-		  pydoc$(VERSION) python-config$(VERSION) smtpd$(VERSION).py ;\
+		  pydoc$(VERSION) python$(VERSION)-config smtpd$(VERSION).py ;\
 	do \
 		ln -fs "$(prefix)/bin/$${fn}" "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin/$${fn}" ;\
 	done
 
+
+# TODO: install symlinks for -32, -64 and -all as well
+installunixtools4way: installunixtools
+
+
 #
 # Like installunixtools, but only install links to the versioned binaries.
 #
@@ -78,18 +113,20 @@
 		$(INSTALL) -d -m $(DIRMODE) "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" ;\
 	fi
 	for fn in python$(VERSION) pythonw$(VERSION) idle$(VERSION) \
-		  pydoc$(VERSION) python-config$(VERSION) smtpd$(VERSION).py ;\
+		  pydoc$(VERSION) python$(VERSION)-config) smtpd$(VERSION).py ;\
 	do \
 		ln -fs "$(prefix)/bin/$${fn}" "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin/$${fn}" ;\
 	done
 
+# TODO: -32, -64 and -all variants
+altinstallunixtools4way: altinstallunixtools
 
 # By default most tools are installed without a version in their basename, to
 # make it easier to install (and use) several python versions side-by-side move
 # the tools to a version-specific name and add the non-versioned name as an
 # alias.
 install_versionedtools:
-	for fn in idle pydoc python-config ;\
+	for fn in idle pydoc ;\
 	do \
 		if [ -h "$(DESTDIR)$(prefix)/bin/$${fn}" ]; then \
 			continue ;\
@@ -97,6 +134,10 @@
 		mv "$(DESTDIR)$(prefix)/bin/$${fn}" "$(DESTDIR)$(prefix)/bin/$${fn}$(VERSION)"  ;\
 		ln -sf "$${fn}$(VERSION)" "$(DESTDIR)$(prefix)/bin/$${fn}" ;\
 	done
+	if [ ! -h "$(DESTDIR)$(prefix)/bin/python-config" ]; then \
+		mv "$(DESTDIR)$(prefix)/bin/python-config" "$(DESTDIR)$(prefix)/bin/python$(VERSION)-config" ;\
+		ln -sf "python$(VERSION)-config" "$(DESTDIR)$(prefix)/bin/python-config" ; \
+	fi
 	if [ ! -h "$(DESTDIR)$(prefix)/bin/smtpd.py" ]; then \
 		mv "$(DESTDIR)$(prefix)/bin/smtpd.py" "$(DESTDIR)$(prefix)/bin/smtpd$(VERSION).py"  ;\
 		ln -sf "smtpd$(VERSION).py" "$(DESTDIR)$(prefix)/bin/smtpd.py" ;\
@@ -107,6 +148,13 @@
 	$(CC) $(LDFLAGS) -o $@ $(srcdir)/Tools/pythonw.c \
 		-DPYTHONWEXECUTABLE='"$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)"'
 
+pythonw-32: $(srcdir)/Tools/pythonw.c Makefile
+	$(CC) $(LDFLAGS) -o $@ -arch i386 -arch ppc $(srcdir)/Tools/pythonw.c \
+		-DPYTHONWEXECUTABLE='"$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)-32"'
+
+pythonw-64: $(srcdir)/Tools/pythonw.c Makefile
+	$(CC) $(LDFLAGS) -o $@ -arch x86_64 -arch ppc64 $(srcdir)/Tools/pythonw.c \
+		-DPYTHONWEXECUTABLE='"$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)-64"'
 
 install_PythonLauncher:
 	cd PythonLauncher && make install DESTDIR=$(DESTDIR)
@@ -159,13 +207,19 @@
 	done
 	$(INSTALL_PROGRAM) $(STRIPFLAG) $(BUILDPYTHON) "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)"
 
+install_Python4way: install_Python
+	lipo  -extract i386 -extract ppc7400 -output "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)-32" "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)"
+	lipo  -extract x86_64 -extract ppc64 -output "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)-64" "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)"
+
+
+
 install_IDLE:
 	cd IDLE && make install
 
 install_BuildApplet:
-	$(RUNSHARED) $(BUILDPYTHON) $(srcdir)/scripts/BuildApplet.py \
+	$(RUNSHARED) arch -ppc -i386 $(BUILDPYTHON) $(srcdir)/scripts/BuildApplet.py \
 		--destroot "$(DESTDIR)" \
-		--python $(INSTALLED_PYTHONAPP) \
+		--python=$(prefix)/Resources/Python.app/Contents/MacOS/$(PYTHONFRAMEWORK)`test -f "$(DESTDIR)$(prefix)/Resources/Python.app/Contents/MacOS/$(PYTHONFRAMEWORK)-32" && echo "-32"`  \
 		--output "$(DESTDIR)$(PYTHONAPPSDIR)/Build Applet.app" \
 		$(srcdir)/scripts/BuildApplet.py
 
@@ -225,7 +279,7 @@
 	done
 
 
-	$(RUNSHARED) $(BUILDPYTHON) $(CACHERSRC) -v $(DESTDIR)$(MACLIBDEST) $(DESTDIR)$(MACTOOLSDEST)
+	$(RUNSHARED) arch -ppc -i386 $(BUILDPYTHON) $(CACHERSRC) -v $(DESTDIR)$(MACLIBDEST) $(DESTDIR)$(MACTOOLSDEST)
 	$(RUNSHARED) $(BUILDPYTHON) -Wi -tt $(compileall) -d $(MACTOOLSDEST) -x badsyntax $(DESTDIR)$(MACTOOLSDEST)
 	$(RUNSHARED) $(BUILDPYTHON) -O -Wi -tt $(compileall) -d $(MACTOOLSDEST) -x badsyntax $(DESTDIR)$(MACTOOLSDEST)
 
diff --git a/Mac/Modules/ColorPickermodule.c b/Mac/Modules/ColorPickermodule.c
index c29e0a4..4406426 100644
--- a/Mac/Modules/ColorPickermodule.c
+++ b/Mac/Modules/ColorPickermodule.c
@@ -27,6 +27,9 @@
 
 /* ----------------------------------------------------- */
 
+
+#ifndef __LP64__
+
 static char cp_GetColor__doc__[] =
 "GetColor(prompt, (r, g, b)) -> (r, g, b), ok"
 ;
@@ -46,11 +49,14 @@
 	
 	return Py_BuildValue("O&h", QdRGB_New, &outColor, ok);
 }
+#endif /* __LP64__ */
 
 /* List of methods defined in the module */
 
 static struct PyMethodDef cp_methods[] = {
+#ifndef __LP64__
 	{"GetColor",	(PyCFunction)cp_GetColor,	METH_VARARGS,	cp_GetColor__doc__},
+#endif /* __LP64__ */
 	{NULL,	 		(PyCFunction)NULL, 			0, 				NULL}		/* sentinel */
 };
 
diff --git a/Mac/Modules/MacOS.c b/Mac/Modules/MacOS.c
index a888320..99e531b 100644
--- a/Mac/Modules/MacOS.c
+++ b/Mac/Modules/MacOS.c
@@ -30,6 +30,7 @@
 #include <Carbon/Carbon.h>
 #include <ApplicationServices/ApplicationServices.h>
 
+
 static PyObject *MacOS_Error; /* Exception MacOS.Error */
 
 #define PATHNAMELEN 1024
@@ -40,7 +41,7 @@
 
 typedef struct {
 	PyObject_HEAD
-	short fRefNum;
+	FSIORefNum fRefNum;
 	int isclosed;
 } rfobject;
 
@@ -54,7 +55,7 @@
 do_close(rfobject *self)
 {
 	if (self->isclosed ) return;
-	(void)FSClose(self->fRefNum);
+	(void)FSCloseFork(self->fRefNum);
 	self->isclosed = 1;
 }
 
@@ -68,6 +69,7 @@
 	long n;
 	PyObject *v;
 	OSErr err;
+	ByteCount n2;
 	
 	if (self->isclosed) {
 		PyErr_SetString(PyExc_ValueError, "Operation on closed file");
@@ -81,13 +83,13 @@
 	if (v == NULL)
 		return NULL;
 		
-	err = FSRead(self->fRefNum, &n, PyBytes_AsString(v));
+	err = FSReadFork(self->fRefNum, fsAtMark, 0, n, PyString_AsString(v), &n2);
 	if (err && err != eofErr) {
 		PyMac_Error(err);
 		Py_DECREF(v);
 		return NULL;
 	}
-	_PyBytes_Resize(&v, n);
+	_PyString_Resize(&v, n2);
 	return v;
 }
 
@@ -109,7 +111,7 @@
 	}
 	if (!PyArg_ParseTuple(args, "s#", &buffer, &size))
 		return NULL;
-	err = FSWrite(self->fRefNum, &size, buffer);
+	err = FSWriteFork(self->fRefNum, fsAtMark, 0, size, buffer, NULL);
 	if (err) {
 		PyMac_Error(err);
 		return NULL;
@@ -126,47 +128,36 @@
 static PyObject *
 rf_seek(rfobject *self, PyObject *args)
 {
-	long amount, pos;
+	long amount;
 	int whence = SEEK_SET;
-	long eof;
+	int mode;
 	OSErr err;
 	
 	if (self->isclosed) {
 		PyErr_SetString(PyExc_ValueError, "Operation on closed file");
 		return NULL;
 	}
-	if (!PyArg_ParseTuple(args, "l|i", &amount, &whence))
+	if (!PyArg_ParseTuple(args, "l|i", &amount, &whence)) {
 		return NULL;
-	
-	if ((err = GetEOF(self->fRefNum, &eof)))
-		goto ioerr;
+	}
 	
 	switch (whence) {
 	case SEEK_CUR:
-		if ((err = GetFPos(self->fRefNum, &pos)))
-			goto ioerr; 
+		mode = fsFromMark;
 		break;
 	case SEEK_END:
-		pos = eof;
+		mode = fsFromLEOF;
 		break;
 	case SEEK_SET:
-		pos = 0;
+		mode = fsFromStart;
 		break;
 	default:
 		PyErr_BadArgument();
 		return NULL;
 	}
-	
-	pos += amount;
-	
-	/* Don't bother implementing seek past EOF */
-	if (pos > eof || pos < 0) {
-		PyErr_BadArgument();
-		return NULL;
-	}
-	
-	if ((err = SetFPos(self->fRefNum, fsFromStart, pos)) ) {
-ioerr:
+
+	err = FSSetForkPosition(self->fRefNum, mode, amount);
+	if (err != noErr) {
 		PyMac_Error(err);
 		return NULL;
 	}
@@ -182,7 +173,7 @@
 static PyObject *
 rf_tell(rfobject *self, PyObject *args)
 {
-	long where;
+	long long where;
 	OSErr err;
 	
 	if (self->isclosed) {
@@ -191,11 +182,13 @@
 	}
 	if (!PyArg_ParseTuple(args, ""))
 		return NULL;
-	if ((err = GetFPos(self->fRefNum, &where)) ) {
+
+	err = FSGetForkPosition(self->fRefNum, &where);
+	if (err != noErr) {
 		PyMac_Error(err);
 		return NULL;
 	}
-	return PyInt_FromLong(where);
+	return PyLong_FromLongLong(where);
 }
 
 static char rf_close__doc__[] = 
@@ -281,6 +274,7 @@
 	Rftype__doc__ /* Documentation string */
 };
 
+
 /* End of code for Resource fork objects */
 /* -------------------------------------------------------- */
 
@@ -292,17 +286,61 @@
 static PyObject *
 MacOS_GetCreatorAndType(PyObject *self, PyObject *args)
 {
-	FSSpec fss;
-	FInfo info;
 	PyObject *creator, *type, *res;
 	OSErr err;
-	
-	if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
+	FSRef ref;
+	FSCatalogInfo	cataloginfo;
+	FileInfo* finfo;
+
+	if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &ref)) {
+#ifndef __LP64__
+		/* This function is documented to take an FSSpec as well,
+		 * which only works in 32-bit mode.
+		 */
+		PyErr_Clear();
+		FSSpec fss;
+		FInfo info;
+
+		if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
+			return NULL;
+
+		if ((err = FSpGetFInfo(&fss, &info)) != noErr) {
+			return PyErr_Mac(MacOS_Error, err);
+		}
+		creator = PyString_FromStringAndSize(
+				(char *)&info.fdCreator, 4);
+		type = PyString_FromStringAndSize((char *)&info.fdType, 4);
+		res = Py_BuildValue("OO", creator, type);
+		Py_DECREF(creator);
+		Py_DECREF(type);
+		return res;
+#else	/* __LP64__ */
 		return NULL;
-	if ((err = FSpGetFInfo(&fss, &info)) != noErr)
-		return PyErr_Mac(MacOS_Error, err);
-	creator = PyBytes_FromStringAndSize((char *)&info.fdCreator, 4);
-	type = PyBytes_FromStringAndSize((char *)&info.fdType, 4);
+#endif	/* __LP64__ */
+	}
+
+	err = FSGetCatalogInfo(&ref, 
+			kFSCatInfoFinderInfo|kFSCatInfoNodeFlags, &cataloginfo, 
+			NULL, NULL, NULL);
+	if (err != noErr) {
+		PyErr_Mac(MacOS_Error, err);
+		return NULL;
+	}
+
+	if ((cataloginfo.nodeFlags & kFSNodeIsDirectoryMask) != 0) {
+		/* Directory: doesn't have type/creator info.
+		 *
+		 * The specific error code is for backward compatibility with
+		 * earlier versions.
+		 */
+		PyErr_Mac(MacOS_Error, fnfErr);
+		return NULL;
+
+	} 
+	finfo = (FileInfo*)&(cataloginfo.finderInfo);
+	creator = PyString_FromStringAndSize((char*)&(finfo->fileCreator), 4);
+	type = PyString_FromStringAndSize((char*)&(finfo->fileType), 4);
+
 	res = Py_BuildValue("OO", creator, type);
 	Py_DECREF(creator);
 	Py_DECREF(type);
@@ -314,20 +352,66 @@
 static PyObject *
 MacOS_SetCreatorAndType(PyObject *self, PyObject *args)
 {
-	FSSpec fss;
 	ResType creator, type;
-	FInfo info;
+	FSRef ref;
+	FileInfo* finfo;
 	OSErr err;
-	
+	FSCatalogInfo	cataloginfo;
+
 	if (!PyArg_ParseTuple(args, "O&O&O&",
+			PyMac_GetFSRef, &ref, PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) {
+#ifndef __LP64__
+		/* Try to handle FSSpec arguments, for backward compatibility */
+		FSSpec fss;
+		FInfo info;
+
+		if (!PyArg_ParseTuple(args, "O&O&O&",
 			PyMac_GetFSSpec, &fss, PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
+			return NULL;
+
+		if ((err = FSpGetFInfo(&fss, &info)) != noErr)
+			return PyErr_Mac(MacOS_Error, err);
+
+		info.fdCreator = creator;
+		info.fdType = type;
+
+		if ((err = FSpSetFInfo(&fss, &info)) != noErr)
+			return PyErr_Mac(MacOS_Error, err);
+		Py_INCREF(Py_None);
+		return Py_None;
+#else /* __LP64__ */
 		return NULL;
-	if ((err = FSpGetFInfo(&fss, &info)) != noErr)
-		return PyErr_Mac(MacOS_Error, err);
-	info.fdCreator = creator;
-	info.fdType = type;
-	if ((err = FSpSetFInfo(&fss, &info)) != noErr)
-		return PyErr_Mac(MacOS_Error, err);
+#endif /* __LP64__ */
+	}
+	
+	err = FSGetCatalogInfo(&ref, 
+			kFSCatInfoFinderInfo|kFSCatInfoNodeFlags, &cataloginfo, 
+			NULL, NULL, NULL);
+	if (err != noErr) {
+		PyErr_Mac(MacOS_Error, err);
+		return NULL;
+	}
+
+	if ((cataloginfo.nodeFlags & kFSNodeIsDirectoryMask) != 0) {
+		/* Directory: doesn't have type/creator info.
+		 *
+		 * The specific error code is for backward compatibility with
+		 * earlier versions.
+		 */
+		PyErr_Mac(MacOS_Error, fnfErr);
+		return NULL;
+
+	} 
+	finfo = (FileInfo*)&(cataloginfo.finderInfo);
+	finfo->fileCreator = creator;
+	finfo->fileType = type;
+
+	err = FSSetCatalogInfo(&ref, kFSCatInfoFinderInfo, &cataloginfo);
+	if (err != noErr) {
+		PyErr_Mac(MacOS_Error, fnfErr);
+		return NULL;
+	}
+
 	Py_INCREF(Py_None);
 	return Py_None;
 }
@@ -399,6 +483,9 @@
 	return Py_BuildValue("s", buf);
 }
 
+
+#ifndef __LP64__
+
 static char splash_doc[] = "Open a splash-screen dialog by resource-id (0=close)";
 
 static PyObject *
@@ -417,7 +504,7 @@
 		return NULL;
 	olddialog = curdialog;
 	curdialog = NULL;
-		
+
 	if ( resid != -1 ) {
 		curdialog = GetNewDialog(resid, NULL, (WindowPtr)-1);
 		if ( curdialog ) {
@@ -452,11 +539,13 @@
 	
 	if (!PyArg_ParseTuple(args, "O&|O", PyMac_GetStr255, message, &object))
 		return NULL;
+	
 	DebugStr(message);
 	Py_INCREF(Py_None);
 	return Py_None;
 }
 
+
 static char SysBeep_doc[] = "BEEEEEP!!!";
 
 static PyObject *
@@ -471,6 +560,8 @@
 	return Py_None;
 }
 
+#endif /* __LP64__ */
+
 static char WMAvailable_doc[] = 
 	"True if this process can interact with the display."
 	"Will foreground the application on the first call as a side-effect."
@@ -530,51 +621,37 @@
 {
 	OSErr err;
 	char *mode = "r";
-	FSSpec fss;
-	SignedByte permission = 1;
+	FSRef ref;
+	SInt8 permission = fsRdPerm;
 	rfobject *fp;
+	HFSUniStr255 name;
 		
-	if (!PyArg_ParseTuple(args, "O&|s", PyMac_GetFSSpec, &fss, &mode))
+	if (!PyArg_ParseTuple(args, "O&|s", PyMac_GetFSRef, &ref, &mode))
 		return NULL;
 	while (*mode) {
 		switch (*mode++) {
 		case '*': break;
-		case 'r': permission = 1; break;
-		case 'w': permission = 2; break;
+		case 'r': permission = fsRdPerm; break;
+		case 'w': permission = fsWrPerm; break;
 		case 'b': break;
 		default:
 			PyErr_BadArgument();
 			return NULL;
 		}
 	}
+
+	err = FSGetResourceForkName(&name);
+	if (err != noErr) {
+		PyMac_Error(err);
+		return NULL;
+	}
 	
 	if ( (fp = newrfobject()) == NULL )
 		return NULL;
-		
-	err = HOpenRF(fss.vRefNum, fss.parID, fss.name, permission, &fp->fRefNum);
+
 	
-	if ( err == fnfErr ) {
-		/* In stead of doing complicated things here to get creator/type
-		** correct we let the standard i/o library handle it
-		*/
-		FILE *tfp;
-		char pathname[PATHNAMELEN];
-		
-		if ( (err=PyMac_GetFullPathname(&fss, pathname, PATHNAMELEN)) ) {
-			PyMac_Error(err);
-			Py_DECREF(fp);
-			return NULL;
-		}
-		
-		if ( (tfp = fopen(pathname, "w")) == NULL ) {
-			PyMac_Error(fnfErr); /* What else... */
-			Py_DECREF(fp);
-			return NULL;
-		}
-		fclose(tfp);
-		err = HOpenRF(fss.vRefNum, fss.parID, fss.name, permission, &fp->fRefNum);
-	}
-	if ( err ) {
+	err = FSOpenFork(&ref, name.length, name.unicode, permission, &fp->fRefNum);
+	if (err != noErr) {
 		Py_DECREF(fp);
 		PyMac_Error(err);
 		return NULL;
@@ -584,15 +661,18 @@
 }
 
 
+
 static PyMethodDef MacOS_Methods[] = {
 	{"GetCreatorAndType",		MacOS_GetCreatorAndType, 1,	getcrtp_doc},
 	{"SetCreatorAndType",		MacOS_SetCreatorAndType, 1,	setcrtp_doc},
 	{"GetErrorString",		MacOS_GetErrorString,	1,	geterr_doc},
 	{"openrf",			MacOS_openrf, 		1, 	openrf_doc},
+#ifndef __LP64__
 	{"splash",			MacOS_splash,		1, 	splash_doc},
 	{"DebugStr",			MacOS_DebugStr,		1,	DebugStr_doc},
-	{"GetTicks",			MacOS_GetTicks,		1,	GetTicks_doc},
 	{"SysBeep",			MacOS_SysBeep,		1,	SysBeep_doc},
+#endif /* __LP64__ */
+	{"GetTicks",			MacOS_GetTicks,		1,	GetTicks_doc},
 	{"WMAvailable",			MacOS_WMAvailable,		1,	WMAvailable_doc},
 	{NULL,				NULL}		 /* Sentinel */
 };
diff --git a/Mac/Modules/Nav.c b/Mac/Modules/Nav.c
index 773664d..3e2d9d6 100644
--- a/Mac/Modules/Nav.c
+++ b/Mac/Modules/Nav.c
@@ -184,18 +184,22 @@
 		} else if( strcmp(keystr, "preferenceKey") == 0 ) {
 			if ( !PyArg_Parse(value, "O&", PyMac_GetOSType, &opt->preferenceKey) )
 				return 0;
+#ifndef __LP64__
 		} else if( strcmp(keystr, "popupExtension") == 0 ) {
 			if ( !PyArg_Parse(value, "O&", ResObj_Convert, &opt->popupExtension) )
 				return 0;
+#endif /* !__LP64__ */
 		} else if( eventProcP && strcmp(keystr, "eventProc") == 0 ) {
 			*eventProcP = my_eventProcUPP;
 		} else if( previewProcP && strcmp(keystr, "previewProc") == 0 ) {
 			*previewProcP = my_previewProcUPP;
 		} else if( filterProcP && strcmp(keystr, "filterProc") == 0 ) {
 			*filterProcP = my_filterProcUPP;
+#ifndef __LP64__
 		} else if( typeListP && strcmp(keystr, "typeList") == 0 ) {
 			if ( !PyArg_Parse(value, "O&", ResObj_Convert, typeListP) )
 				return 0;
+#endif /* !__LP64__ */
 		} else if( fileTypeP && strcmp(keystr, "fileType") == 0 ) {
 			if ( !PyArg_Parse(value, "O&", PyMac_GetOSType, fileTypeP) )
 				return 0;
@@ -301,13 +305,26 @@
 static PyObject *
 navrr_getattr(navrrobject *self, char *name)
 {
-	FSSpec fss;
 	FSRef fsr;
+#ifndef __LP64__
+	FSSpec fss;
+#endif /* !__LP64__ */
 	
 	if( strcmp(name, "__members__") == 0 )
-		return Py_BuildValue("ssssssssss", "version", "validRecord", "replacing",
-			"isStationery", "translationNeeded", "selection", "selection_fsr",
+		return Py_BuildValue(
+#ifndef __LP64__
+				"ssssssssss", 
+#else /* __LP64__ */
+				"ssssssssss", 
+#endif /* __LP64__ */
+				"version", "validRecord", "replacing",
+			"isStationery", "translationNeeded", 
+#ifndef __LP64__
+			"selection", 
+#endif /* !__LP64__ */
+			"selection_fsr",
 			"fileTranslation", "keyScript", "saveFileName");
+
 	if( strcmp(name, "version") == 0 )
 		return Py_BuildValue("h", self->itself.version);
 	if( strcmp(name, "validRecord") == 0 )
@@ -318,8 +335,10 @@
 		return Py_BuildValue("l", (long)self->itself.isStationery);
 	if( strcmp(name, "translationNeeded") == 0 )
 		return Py_BuildValue("l", (long)self->itself.translationNeeded);
+#ifndef __LP64__
 	if( strcmp(name, "selection") == 0 ) {
-		SInt32 i, count;
+		SInt32 i;
+		long count;
 		OSErr err;
 		PyObject *rv, *rvitem;
 		AEDesc desc;
@@ -348,8 +367,10 @@
 		}
 		return rv;
 	}
+#endif /* !__LP64__ */
 	if( strcmp(name, "selection_fsr") == 0 ) {
-		SInt32 i, count;
+		SInt32 i;
+		long count;
 		OSErr err;
 		PyObject *rv, *rvitem;
 		AEDesc desc;
@@ -378,8 +399,10 @@
 		}
 		return rv;
 	}
+#ifndef __LP64__
 	if( strcmp(name, "fileTranslation") == 0 )
 		return ResObj_New((Handle)self->itself.fileTranslation);
+#endif
 	if( strcmp(name, "keyScript") == 0 )
 		return Py_BuildValue("h", (short)self->itself.keyScript);
 	if( strcmp(name, "saveFileName") == 0 )
@@ -861,7 +884,12 @@
 		PyErr_Mac(ErrorObject, err);
 		return NULL;
 	}
-	return Py_BuildValue("{s:h,s:l,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&}",
+	return Py_BuildValue(
+#ifndef __LP64__
+			"{s:h,s:l,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&}",
+#else /* __LP64__ */
+			"{s:h,s:l,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&}",
+#endif /* __LP64__ */
 		"version", dialogOptions.version,
 		"dialogOptionFlags", dialogOptions.dialogOptionFlags,
 		"location", PyMac_BuildPoint, dialogOptions.location,
@@ -871,8 +899,11 @@
 		"cancelButtonLabel", PyMac_BuildStr255, &dialogOptions.cancelButtonLabel,
 		"savedFileName", PyMac_BuildStr255, &dialogOptions.savedFileName,
 		"message", PyMac_BuildStr255, &dialogOptions.message,
-		"preferenceKey", PyMac_BuildOSType, dialogOptions.preferenceKey,
-		"popupExtension", OptResObj_New, dialogOptions.popupExtension);
+		"preferenceKey", PyMac_BuildOSType, dialogOptions.preferenceKey
+#ifndef __LP64__
+		,"popupExtension", OptResObj_New, dialogOptions.popupExtension
+#endif /* __LP64__ */
+		);
 }
 
 /* List of methods defined in the module */
diff --git a/Mac/Modules/OSATerminology.c b/Mac/Modules/OSATerminology.c
index 66fb969..e56a0db 100644
--- a/Mac/Modules/OSATerminology.c
+++ b/Mac/Modules/OSATerminology.c
@@ -11,6 +11,7 @@
 
 #include <Carbon/Carbon.h>
 
+#ifndef __LP64__
 static PyObject *
 PyOSA_GetAppTerminology(PyObject* self, PyObject* args)
 {
@@ -68,12 +69,14 @@
 	if (err) return PyMac_Error(err);
 	return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
 }
+#endif /* !__LP64__ */
 
 /* 
  * List of methods defined in the module
  */
 static struct PyMethodDef OSATerminology_methods[] =
 {
+#ifndef __LP64__
   	{"GetAppTerminology", 
 		(PyCFunction) PyOSA_GetAppTerminology,
 		METH_VARARGS,
@@ -82,14 +85,14 @@
 		(PyCFunction) PyOSA_GetSysTerminology,
 		METH_VARARGS,
 		"Get an applications system terminology, as an AEDesc object."},
+#endif /* !__LP64__ */
 	{NULL, (PyCFunction) NULL, 0, NULL}
 };
 
-
 void
 initOSATerminology(void)
 {
 	if (PyErr_WarnPy3k("In 3.x, OSATerminology is removed.", 1) < 0)
 		return;
 	Py_InitModule("OSATerminology", OSATerminology_methods);
-}
\ No newline at end of file
+}
diff --git a/Mac/Modules/ae/_AEmodule.c b/Mac/Modules/ae/_AEmodule.c
index b883e70..dd154c7 100644
--- a/Mac/Modules/ae/_AEmodule.c
+++ b/Mac/Modules/ae/_AEmodule.c
@@ -683,7 +683,8 @@
 		return NULL;
 	_err = AEResumeTheCurrentEvent(&_self->ob_itself,
 	                               &reply,
-	                               dispatcher__proc__, (long)dispatcher);
+	                               dispatcher__proc__, 
+				       (SRefCon)dispatcher);
 	if (_err != noErr) return PyMac_Error(_err);
 	Py_INCREF(Py_None);
 	_res = Py_None;
@@ -1154,7 +1155,7 @@
 		return NULL;
 	_err = AEInstallEventHandler(theAEEventClass,
 	                             theAEEventID,
-	                             handler__proc__, (long)handler,
+	                             handler__proc__, (SRefCon)handler,
 	                             0);
 	if (_err != noErr) return PyMac_Error(_err);
 	Py_INCREF(Py_None);
@@ -1203,7 +1204,7 @@
 		return NULL;
 	_err = AEGetEventHandler(theAEEventClass,
 	                         theAEEventID,
-	                         &handler__proc__, (long *)&handler,
+	                         &handler__proc__, (SRefCon *)&handler,
 	                         0);
 	if (_err != noErr) return PyMac_Error(_err);
 	_res = Py_BuildValue("O",
diff --git a/Mac/Modules/app/_Appmodule.c b/Mac/Modules/app/_Appmodule.c
index 3a368bf..52d17f5 100644
--- a/Mac/Modules/app/_Appmodule.c
+++ b/Mac/Modules/app/_Appmodule.c
@@ -3,6 +3,8 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
+	/* Carbon GUI stuff, not available in 64-bit mode */
 
 
 #include "pymactoolbox.h"
@@ -18,7 +20,7 @@
 #include <Carbon/Carbon.h>
 
 
-int ThemeButtonDrawInfo_Convert(PyObject *v, ThemeButtonDrawInfo *p_itself)
+static int ThemeButtonDrawInfo_Convert(PyObject *v, ThemeButtonDrawInfo *p_itself)
 {
         return PyArg_Parse(v, "(iHH)", &p_itself->state, &p_itself->value, &p_itself->adornment);
 }
@@ -1792,17 +1794,25 @@
 };
 
 
+#else  	/* __LP64__ */
+
+static PyMethodDef App_methods[] = {
+	{NULL, NULL, 0}
+};
+
+#endif /* __LP64__ */
 
 
 void init_App(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
-
-
+#endif /* !__LP64__ */
 
 
 	m = Py_InitModule("_App", App_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	App_Error = PyMac_GetOSErrException();
 	if (App_Error == NULL ||
@@ -1815,6 +1825,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&ThemeDrawingState_Type);
 	PyModule_AddObject(m, "ThemeDrawingStateType", (PyObject *)&ThemeDrawingState_Type);
+#endif /* __LP64__ */
 }
 
 /* ======================== End module _App ========================= */
diff --git a/Mac/Modules/carbonevt/_CarbonEvtmodule.c b/Mac/Modules/carbonevt/_CarbonEvtmodule.c
index fd4b266..66e4e27 100755
--- a/Mac/Modules/carbonevt/_CarbonEvtmodule.c
+++ b/Mac/Modules/carbonevt/_CarbonEvtmodule.c
@@ -3,7 +3,7 @@
 
 #include "Python.h"
 
-
+#ifndef __LP64__
 
 #include "pymactoolbox.h"
 
@@ -2141,20 +2141,28 @@
 	{NULL, NULL, 0}
 };
 
+#else /* __LP64__ */
+
+static PyMethodDef CarbonEvents_methods[] = {
+	{NULL, NULL, 0}
+};
+
+#endif /* __LP64__ */
 
 
 
 void init_CarbonEvt(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
-
-
-
-	myEventHandlerUPP = NewEventHandlerUPP(myEventHandler);
+#endif /* !__LP64__ */
 
 
 	m = Py_InitModule("_CarbonEvt", CarbonEvents_methods);
+
+#ifndef __LP64__
+	myEventHandlerUPP = NewEventHandlerUPP(myEventHandler);
 	d = PyModule_GetDict(m);
 	CarbonEvents_Error = PyMac_GetOSErrException();
 	if (CarbonEvents_Error == NULL ||
@@ -2216,6 +2224,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&EventHotKeyRef_Type);
 	PyModule_AddObject(m, "EventHotKeyRefType", (PyObject *)&EventHotKeyRef_Type);
+#endif /* !__LP64__ */
 }
 
 /* ===================== End module _CarbonEvt ====================== */
diff --git a/Mac/Modules/cg/_CGmodule.c b/Mac/Modules/cg/_CGmodule.c
index 8115614..e36fce9 100755
--- a/Mac/Modules/cg/_CGmodule.c
+++ b/Mac/Modules/cg/_CGmodule.c
@@ -1025,6 +1025,7 @@
 	return _res;
 }
 
+#ifndef __LP64__
 static PyObject *CGContextRefObj_SyncCGContextOriginWithPort(CGContextRefObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -1055,6 +1056,7 @@
 	_res = Py_None;
 	return _res;
 }
+#endif
 
 static PyMethodDef CGContextRefObj_methods[] = {
 	{"CGContextSaveGState", (PyCFunction)CGContextRefObj_CGContextSaveGState, 1,
@@ -1173,10 +1175,12 @@
 	 PyDoc_STR("() -> None")},
 	{"CGContextSetShouldAntialias", (PyCFunction)CGContextRefObj_CGContextSetShouldAntialias, 1,
 	 PyDoc_STR("(int shouldAntialias) -> None")},
+#ifndef __LP64__
 	{"SyncCGContextOriginWithPort", (PyCFunction)CGContextRefObj_SyncCGContextOriginWithPort, 1,
 	 PyDoc_STR("(CGrafPtr port) -> None")},
 	{"ClipCGContextToRegion", (PyCFunction)CGContextRefObj_ClipCGContextToRegion, 1,
 	 PyDoc_STR("(Rect portRect, RgnHandle region) -> None")},
+#endif
 	{NULL, NULL, 0}
 };
 
@@ -1254,6 +1258,7 @@
 /* ------------------ End object type CGContextRef ------------------ */
 
 
+#ifndef __LP64__
 static PyObject *CG_CreateCGContextForPort(PyObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -1271,10 +1276,13 @@
 	return _res;
 
 }
+#endif
 
 static PyMethodDef CG_methods[] = {
+#ifndef __LP64__
 	{"CreateCGContextForPort", (PyCFunction)CG_CreateCGContextForPort, 1,
 	 PyDoc_STR("(CGrafPtr) -> CGContextRef")},
+#endif
 	{NULL, NULL, 0}
 };
 
diff --git a/Mac/Modules/cm/_Cmmodule.c b/Mac/Modules/cm/_Cmmodule.c
index 3c6be6b..03a25dd 100644
--- a/Mac/Modules/cm/_Cmmodule.c
+++ b/Mac/Modules/cm/_Cmmodule.c
@@ -178,6 +178,7 @@
 	return _res;
 }
 
+#ifndef __LP64__
 static PyObject *CmpInstObj_ComponentFunctionImplemented(ComponentInstanceObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -228,6 +229,7 @@
 	                     _rv);
 	return _res;
 }
+#endif /* !__LP64__*/
 
 static PyMethodDef CmpInstObj_methods[] = {
 	{"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1,
@@ -240,12 +242,14 @@
 	 PyDoc_STR("() -> (Handle _rv)")},
 	{"SetComponentInstanceStorage", (PyCFunction)CmpInstObj_SetComponentInstanceStorage, 1,
 	 PyDoc_STR("(Handle theStorage) -> None")},
+#ifndef __LP64__
 	{"ComponentFunctionImplemented", (PyCFunction)CmpInstObj_ComponentFunctionImplemented, 1,
 	 PyDoc_STR("(short ftnNumber) -> (long _rv)")},
 	{"GetComponentVersion", (PyCFunction)CmpInstObj_GetComponentVersion, 1,
 	 PyDoc_STR("() -> (long _rv)")},
 	{"ComponentSetTarget", (PyCFunction)CmpInstObj_ComponentSetTarget, 1,
 	 PyDoc_STR("(ComponentInstance target) -> (long _rv)")},
+#endif /* !__LP64__ */
 	{NULL, NULL, 0}
 };
 
@@ -631,6 +635,7 @@
 	return _res;
 }
 
+#ifndef __LP64__
 static PyObject *CmpObj_GetComponentIconSuite(ComponentObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -648,6 +653,7 @@
 	                     ResObj_New, iconSuite);
 	return _res;
 }
+#endif /* !__LP64__ */
 
 static PyMethodDef CmpObj_methods[] = {
 	{"UnregisterComponent", (PyCFunction)CmpObj_UnregisterComponent, 1,
@@ -678,8 +684,10 @@
 	 PyDoc_STR("(Component capturingComponent) -> (Component _rv)")},
 	{"UncaptureComponent", (PyCFunction)CmpObj_UncaptureComponent, 1,
 	 PyDoc_STR("() -> None")},
+#ifndef __LP64__
 	{"GetComponentIconSuite", (PyCFunction)CmpObj_GetComponentIconSuite, 1,
 	 PyDoc_STR("() -> (Handle iconSuite)")},
+#endif /* !__LP64__ */
 	{NULL, NULL, 0}
 };
 
diff --git a/Mac/Modules/ctl/_Ctlmodule.c b/Mac/Modules/ctl/_Ctlmodule.c
index c6287e0..d7d4d0a 100644
--- a/Mac/Modules/ctl/_Ctlmodule.c
+++ b/Mac/Modules/ctl/_Ctlmodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -5765,14 +5766,21 @@
         return (ControlPartCode)c_rv;
 }
 
+#else /* __LP64__ */
+
+static PyMethodDef Ctl_methods[] = {
+	{NULL, NULL, 0}
+};
+
+#endif /* __LP64__ */
 
 void init_Ctl(void)
 {
 	PyObject *m;
+
+#ifndef __LP64__
 	PyObject *d;
 
-
-
 	mytracker_upp = NewControlActionUPP(mytracker);
 	myactionproc_upp = NewControlActionUPP(myactionproc);
 	mykeydownproc_upp = NewControlUserPaneKeyDownUPP(mykeydownproc);
@@ -5783,9 +5791,11 @@
 	mytrackingproc_upp = NewControlUserPaneTrackingUPP(mytrackingproc);
 	PyMac_INIT_TOOLBOX_OBJECT_NEW(ControlHandle, CtlObj_New);
 	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ControlHandle, CtlObj_Convert);
-
+#endif /* !__LP64__ */
 
 	m = Py_InitModule("_Ctl", Ctl_methods);
+
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Ctl_Error = PyMac_GetOSErrException();
 	if (Ctl_Error == NULL ||
@@ -5798,6 +5808,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&Control_Type);
 	PyModule_AddObject(m, "ControlType", (PyObject *)&Control_Type);
+#endif /* !__LP64__ */
 }
 
 /* ======================== End module _Ctl ========================= */
diff --git a/Mac/Modules/dlg/_Dlgmodule.c b/Mac/Modules/dlg/_Dlgmodule.c
index 46009a8..9afa477 100644
--- a/Mac/Modules/dlg/_Dlgmodule.c
+++ b/Mac/Modules/dlg/_Dlgmodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -1564,10 +1565,19 @@
         return it;
 }
 
+#else /* __LP64__ */
+
+static PyMethodDef Dlg_methods[] = {
+	{NULL, NULL, 0}
+};
+
+#endif /* __LP64__ */
+
 
 void init_Dlg(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
 
 
@@ -1575,9 +1585,11 @@
 	        PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_New);
 	        PyMac_INIT_TOOLBOX_OBJECT_NEW(DialogPtr, DlgObj_WhichDialog);
 	        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DialogPtr, DlgObj_Convert);
-
+#endif /* !__LP64__ */
 
 	m = Py_InitModule("_Dlg", Dlg_methods);
+
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Dlg_Error = PyMac_GetOSErrException();
 	if (Dlg_Error == NULL ||
@@ -1590,6 +1602,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&Dialog_Type);
 	PyModule_AddObject(m, "DialogType", (PyObject *)&Dialog_Type);
+#endif /* !__LP64__ */
 }
 
 /* ======================== End module _Dlg ========================= */
diff --git a/Mac/Modules/drag/_Dragmodule.c b/Mac/Modules/drag/_Dragmodule.c
index 180fcab..797fb32 100644
--- a/Mac/Modules/drag/_Dragmodule.c
+++ b/Mac/Modules/drag/_Dragmodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -1106,21 +1107,28 @@
     return 0;
 }
 #endif
-
+#else /* __LP64__ */
+static PyMethodDef Drag_methods[] = {
+	{NULL, NULL, 0}
+};
+#endif /* __LP64__ */
 
 
 void init_Drag(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
 
 
 
 	        PyMac_INIT_TOOLBOX_OBJECT_NEW(DragRef, DragObj_New);
 	        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(DragRef, DragObj_Convert);
+#endif /* !__LP64__ */
 
 
 	m = Py_InitModule("_Drag", Drag_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Drag_Error = PyMac_GetOSErrException();
 	if (Drag_Error == NULL ||
@@ -1142,6 +1150,7 @@
 	dragglue_DrawingUPP = NewDragDrawingUPP(dragglue_Drawing);
 #endif
 
+#endif /* !__LP64__ */
 
 }
 
diff --git a/Mac/Modules/evt/_Evtmodule.c b/Mac/Modules/evt/_Evtmodule.c
index f7129cf..04f3b23 100644
--- a/Mac/Modules/evt/_Evtmodule.c
+++ b/Mac/Modules/evt/_Evtmodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -526,22 +527,32 @@
 };
 
 
+#else /* __LP64__ */
+
+static PyMethodDef Evt_methods[] = {
+	{NULL, NULL, 0}
+};
+#endif /* __LP64__ */
 
 
 void init_Evt(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
+#endif /* __LP64__ */
 
 
 
 
 	m = Py_InitModule("_Evt", Evt_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Evt_Error = PyMac_GetOSErrException();
 	if (Evt_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Evt_Error) != 0)
 		return;
+#endif /* __LP64__ */
 }
 
 /* ======================== End module _Evt ========================= */
diff --git a/Mac/Modules/file/_Filemodule.c b/Mac/Modules/file/_Filemodule.c
index fca92bf..8ff007f 100644
--- a/Mac/Modules/file/_Filemodule.c
+++ b/Mac/Modules/file/_Filemodule.c
@@ -18,30 +18,45 @@
 #include <Carbon/Carbon.h>
 
 #ifdef USE_TOOLBOX_OBJECT_GLUE
-extern int _PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
-extern int _PyMac_GetFSRef(PyObject *v, FSRef *fsr);
-extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
-extern PyObject *_PyMac_BuildFSRef(FSRef *spec);
 
+#ifndef __LP64__
+extern int _PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
+extern PyObject *_PyMac_BuildFSSpec(FSSpec *spec);
+#define PyMac_BuildFSSpec _PyMac_BuildFSSpec
+#endif /* __LP64__*/
+
+extern int _PyMac_GetFSRef(PyObject *v, FSRef *fsr);
+extern PyObject *_PyMac_BuildFSRef(FSRef *spec);
+#define PyMac_BuildFSRef _PyMac_BuildFSRef
 #define PyMac_GetFSSpec _PyMac_GetFSSpec
 #define PyMac_GetFSRef _PyMac_GetFSRef
-#define PyMac_BuildFSSpec _PyMac_BuildFSSpec
-#define PyMac_BuildFSRef _PyMac_BuildFSRef
-#else
+
+#else	/* !USE_TOOLBOX_OBJECT_GLUE */
+
+#ifndef __LP64__
 extern int PyMac_GetFSSpec(PyObject *v, FSSpec *spec);
-extern int PyMac_GetFSRef(PyObject *v, FSRef *fsr);
 extern PyObject *PyMac_BuildFSSpec(FSSpec *spec);
+#endif /* !__LP64__*/
+
+extern int PyMac_GetFSRef(PyObject *v, FSRef *fsr);
 extern PyObject *PyMac_BuildFSRef(FSRef *spec);
-#endif
+
+#endif	/* !USE_TOOLBOX_OBJECT_GLUE */
 
 /* Forward declarations */
-static PyObject *FInfo_New(FInfo *itself);
 static PyObject *FSRef_New(FSRef *itself);
+#ifndef __LP64__
+static PyObject *FInfo_New(FInfo *itself);
+
 static PyObject *FSSpec_New(FSSpec *itself);
-static PyObject *Alias_New(AliasHandle itself);
-static int FInfo_Convert(PyObject *v, FInfo *p_itself);
-#define FSRef_Convert PyMac_GetFSRef
 #define FSSpec_Convert PyMac_GetFSSpec
+#endif /* !__LP64__ */
+
+static PyObject *Alias_New(AliasHandle itself);
+#ifndef __LP64__
+static int FInfo_Convert(PyObject *v, FInfo *p_itself);
+#endif /* !__LP64__ */
+#define FSRef_Convert PyMac_GetFSRef
 static int Alias_Convert(PyObject *v, AliasHandle *p_itself);
 
 /*
@@ -62,6 +77,7 @@
 /*
 ** Optional fsspec and fsref pointers. None will pass NULL
 */
+#ifndef __LP64__
 static int
 myPyMac_GetOptFSSpecPtr(PyObject *v, FSSpec **spec)
 {
@@ -71,6 +87,7 @@
         }
         return PyMac_GetFSSpec(v, *spec);
 }
+#endif /* !__LP64__ */
 
 static int
 myPyMac_GetOptFSRefPtr(PyObject *v, FSRef **ref)
@@ -92,6 +109,7 @@
         return Py_BuildValue("u#", itself->unicode, itself->length);
 }
 
+#ifndef __LP64__
 static OSErr
 _PyMac_GetFullPathname(FSSpec *fss, char *path, int len)
 {
@@ -135,6 +153,7 @@
 	}
 	return 0;
 }
+#endif /* !__LP64__ */
 
 
 static PyObject *File_Error;
@@ -174,6 +193,10 @@
 static void FSCatalogInfo_dealloc(FSCatalogInfoObject *self)
 {
 	/* Cleanup of self->ob_itself goes here */
+	FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
+	if (info->fileSec != NULL) {
+		CFRelease(info->fileSec);
+	}
 	self->ob_type->tp_free((PyObject *)self);
 }
 
@@ -282,12 +305,28 @@
 
 static PyObject *FSCatalogInfo_get_permissions(FSCatalogInfoObject *self, void *closure)
 {
-	return Py_BuildValue("(llll)", self->ob_itself.permissions[0], self->ob_itself.permissions[1], self->ob_itself.permissions[2], self->ob_itself.permissions[3]);
+	FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
+	return Py_BuildValue("(llll)", info->userID, info->groupID, info->userAccess, info->mode);
 }
 
 static int FSCatalogInfo_set_permissions(FSCatalogInfoObject *self, PyObject *v, void *closure)
 {
-	return PyArg_Parse(v, "(llll)", &self->ob_itself.permissions[0], &self->ob_itself.permissions[1], &self->ob_itself.permissions[2], &self->ob_itself.permissions[3])-1;
+	long userID;
+	long groupID;
+	long userAccess;
+	long mode;
+	int r;
+
+	FSPermissionInfo* info = (FSPermissionInfo*)&(self->ob_itself.permissions);
+
+	r = PyArg_Parse(v, "(llll)", &userID, &groupID, &userAccess, &mode);
+	if (!r) {
+		return -1;
+	}
+	info->userID = userID;
+	info->groupID = groupID;
+	info->userAccess = userAccess;
+	info->mode = mode;
 	return 0;
 }
 
@@ -501,6 +540,8 @@
 
 /* ----------------------- Object type FInfo ------------------------ */
 
+#ifndef __LP64__
+
 static PyTypeObject FInfo_Type;
 
 #define FInfo_Check(x) ((x)->ob_type == &FInfo_Type || PyObject_TypeCheck((x), &FInfo_Type))
@@ -682,6 +723,7 @@
 	FInfo_tp_free, /* tp_free */
 };
 
+#endif /* !__LP64__ */
 /* --------------------- End object type FInfo ---------------------- */
 
 
@@ -729,6 +771,7 @@
 	self->ob_type->tp_free((PyObject *)self);
 }
 
+#ifndef __LP64__
 static PyObject *Alias_ResolveAlias(AliasObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -818,6 +861,7 @@
 	                     wasChanged);
 	return _res;
 }
+#endif /* !__LP64__ */
 
 static PyObject *Alias_FSResolveAliasWithMountFlags(AliasObject *_self, PyObject *_args)
 {
@@ -891,6 +935,7 @@
 }
 
 static PyMethodDef Alias_methods[] = {
+#ifndef __LP64__
 	{"ResolveAlias", (PyCFunction)Alias_ResolveAlias, 1,
 	 PyDoc_STR("(FSSpec fromFile) -> (FSSpec target, Boolean wasChanged)")},
 	{"GetAliasInfo", (PyCFunction)Alias_GetAliasInfo, 1,
@@ -899,6 +944,7 @@
 	 PyDoc_STR("(FSSpec fromFile, unsigned long mountFlags) -> (FSSpec target, Boolean wasChanged)")},
 	{"FollowFinderAlias", (PyCFunction)Alias_FollowFinderAlias, 1,
 	 PyDoc_STR("(FSSpec fromFile, Boolean logon) -> (FSSpec target, Boolean wasChanged)")},
+#endif /* !__LP64__ */
 	{"FSResolveAliasWithMountFlags", (PyCFunction)Alias_FSResolveAliasWithMountFlags, 1,
 	 PyDoc_STR("(FSRef fromFile, unsigned long mountFlags) -> (FSRef target, Boolean wasChanged)")},
 	{"FSResolveAlias", (PyCFunction)Alias_FSResolveAlias, 1,
@@ -1033,6 +1079,7 @@
 
 
 /* ----------------------- Object type FSSpec ----------------------- */
+#ifndef __LP64__
 
 static PyTypeObject FSSpec_Type;
 
@@ -1488,6 +1535,7 @@
 	FSSpec_tp_free, /* tp_free */
 };
 
+#endif /* !__LP64__ */
 /* --------------------- End object type FSSpec --------------------- */
 
 
@@ -1568,7 +1616,9 @@
 	FSCatalogInfoBitmap whichInfo;
 	FSCatalogInfo catalogInfo;
 	FSRef newRef;
+#ifndef __LP64__
 	FSSpec newSpec;
+#endif
 	if (!PyArg_ParseTuple(_args, "u#lO&",
 	                      &nameLength__in__, &nameLength__in_len__,
 	                      &whichInfo,
@@ -1580,11 +1630,22 @@
 	                           whichInfo,
 	                           &catalogInfo,
 	                           &newRef,
-	                           &newSpec);
+#ifndef __LP64__
+	                           &newSpec
+#else	/* __LP64__ */
+				   NULL
+#endif /* __LP64__*/
+				  );
 	if (_err != noErr) return PyMac_Error(_err);
+
+#ifndef __LP64__
 	_res = Py_BuildValue("O&O&",
 	                     FSRef_New, &newRef,
 	                     FSSpec_New, &newSpec);
+#else /* __LP64__ */
+	_res = Py_BuildValue("O&O", FSRef_New, &newRef, Py_None);
+#endif /* __LP64__ */
+
 	return _res;
 }
 
@@ -1598,7 +1659,9 @@
 	FSCatalogInfoBitmap whichInfo;
 	FSCatalogInfo catalogInfo;
 	FSRef newRef;
+#ifndef __LP64__
 	FSSpec newSpec;
+#endif /* !__LP64__ */
 	UInt32 newDirID;
 	if (!PyArg_ParseTuple(_args, "u#lO&",
 	                      &nameLength__in__, &nameLength__in_len__,
@@ -1611,13 +1674,25 @@
 	                                whichInfo,
 	                                &catalogInfo,
 	                                &newRef,
+#ifndef __LP64__
 	                                &newSpec,
+#else /* !__LP64__ */
+					NULL,
+#endif /* !__LP64__ */
 	                                &newDirID);
 	if (_err != noErr) return PyMac_Error(_err);
+
+#ifndef __LP64__
 	_res = Py_BuildValue("O&O&l",
 	                     FSRef_New, &newRef,
 	                     FSSpec_New, &newSpec,
 	                     newDirID);
+#else	/* __LP64__ */
+	_res = Py_BuildValue("O&Ol",
+	                     FSRef_New, &newRef,
+	                     Py_None,
+	                     newDirID);
+#endif /* __LP64__ */
 	return _res;
 }
 
@@ -1699,7 +1774,9 @@
 	FSCatalogInfoBitmap whichInfo;
 	FSCatalogInfo catalogInfo;
 	HFSUniStr255 outName;
+#ifndef __LP64__
 	FSSpec fsSpec;
+#endif /* !__LP64__ */
 	FSRef parentRef;
 	if (!PyArg_ParseTuple(_args, "l",
 	                      &whichInfo))
@@ -1708,14 +1785,27 @@
 	                        whichInfo,
 	                        &catalogInfo,
 	                        &outName,
+#ifndef __LP64__
 	                        &fsSpec,
+#else	/* __LP64__ */
+				NULL,
+#endif /* __LP64__ */
 	                        &parentRef);
 	if (_err != noErr) return PyMac_Error(_err);
+
+#ifndef __LP64__
 	_res = Py_BuildValue("O&O&O&O&",
 	                     FSCatalogInfo_New, &catalogInfo,
 	                     PyMac_BuildHFSUniStr255, &outName,
 	                     FSSpec_New, &fsSpec,
 	                     FSRef_New, &parentRef);
+#else	/* __LP64__ */
+	_res = Py_BuildValue("O&O&OO&",
+	                     FSCatalogInfo_New, &catalogInfo,
+	                     PyMac_BuildHFSUniStr255, &outName,
+	                     Py_None,
+	                     FSRef_New, &parentRef);
+#endif /* __LP64__ */
 	return _res;
 }
 
@@ -1784,7 +1874,7 @@
 	UniCharCount forkNameLength__len__;
 	int forkNameLength__in_len__;
 	SInt8 permissions;
-	SInt16 forkRefNum;
+	FSIORefNum forkRefNum;
 	if (!PyArg_ParseTuple(_args, "u#b",
 	                      &forkNameLength__in__, &forkNameLength__in_len__,
 	                      &permissions))
@@ -2034,7 +2124,7 @@
 
 /* --------------------- End object type FSRef ---------------------- */
 
-
+#ifndef __LP64__
 static PyObject *File_UnmountVol(PyObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -2562,6 +2652,7 @@
 	                     FSSpec_New, &spec);
 	return _res;
 }
+#endif /* !__LP64__ */
 
 static PyObject *File_FSGetForkPosition(PyObject *_self, PyObject *_args)
 {
@@ -2785,6 +2876,7 @@
 	return _res;
 }
 
+#ifndef __LP64__
 static PyObject *File_NewAlias(PyObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -2933,6 +3025,7 @@
 	                     wasAliased);
 	return _res;
 }
+#endif /* !__LP64__ */
 
 static PyObject *File_FSNewAlias(PyObject *_self, PyObject *_args)
 {
@@ -3050,6 +3143,7 @@
 }
 
 static PyMethodDef File_methods[] = {
+#ifndef __LP64__
 	{"UnmountVol", (PyCFunction)File_UnmountVol, 1,
 	 PyDoc_STR("(Str63 volName, short vRefNum) -> None")},
 	{"FlushVol", (PyCFunction)File_FlushVol, 1,
@@ -3100,6 +3194,7 @@
 	 PyDoc_STR("(short vRefNum, long dirID, Str255 oldName, long newDirID, Str255 newName) -> None")},
 	{"FSMakeFSSpec", (PyCFunction)File_FSMakeFSSpec, 1,
 	 PyDoc_STR("(short vRefNum, long dirID, Str255 fileName) -> (FSSpec spec)")},
+#endif /* !__LP64__*/
 	{"FSGetForkPosition", (PyCFunction)File_FSGetForkPosition, 1,
 	 PyDoc_STR("(SInt16 forkRefNum) -> (SInt64 position)")},
 	{"FSSetForkPosition", (PyCFunction)File_FSSetForkPosition, 1,
@@ -3124,6 +3219,7 @@
 	 PyDoc_STR("(UInt8 * path, FNMessage message, OptionBits flags) -> None")},
 	{"FNNotifyAll", (PyCFunction)File_FNNotifyAll, 1,
 	 PyDoc_STR("(FNMessage message, OptionBits flags) -> None")},
+#ifndef  __LP64__
 	{"NewAlias", (PyCFunction)File_NewAlias, 1,
 	 PyDoc_STR("(FSSpec fromFile, FSSpec target) -> (AliasHandle alias)")},
 	{"NewAliasMinimalFromFullPath", (PyCFunction)File_NewAliasMinimalFromFullPath, 1,
@@ -3136,6 +3232,7 @@
 	 PyDoc_STR("(FSSpec fromFile, FSSpec target, AliasHandle alias) -> (Boolean wasChanged)")},
 	{"ResolveAliasFileWithMountFlagsNoUI", (PyCFunction)File_ResolveAliasFileWithMountFlagsNoUI, 1,
 	 PyDoc_STR("(FSSpec theSpec, Boolean resolveAliasChains, unsigned long mountFlags) -> (FSSpec theSpec, Boolean targetIsFolder, Boolean wasAliased)")},
+#endif /* !__LP64__ */
 	{"FSNewAlias", (PyCFunction)File_FSNewAlias, 1,
 	 PyDoc_STR("(FSRef fromFile, FSRef target) -> (AliasHandle inAlias)")},
 	{"FSResolveAliasFileWithMountFlags", (PyCFunction)File_FSResolveAliasFileWithMountFlags, 1,
@@ -3150,7 +3247,7 @@
 };
 
 
-
+#ifndef __LP64__
 int
 PyMac_GetFSSpec(PyObject *v, FSSpec *spec)
 {
@@ -3188,12 +3285,15 @@
         }
         return 0;
 }
+#endif /* !__LP64__ */
 
 int
 PyMac_GetFSRef(PyObject *v, FSRef *fsr)
 {
         OSStatus err;
+#ifndef __LP64__
         FSSpec fss;
+#endif /* !__LP64__ */
 
         if (FSRef_Check(v)) {
                 *fsr = ((FSRefObject *)v)->ob_itself;
@@ -3205,12 +3305,14 @@
                 char *path = NULL;
                 if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path))
                         return 0;
-                if ( (err=FSPathMakeRef(path, fsr, NULL)) )
+                if ( (err=FSPathMakeRef((unsigned char*)path, fsr, NULL)) )
                         PyMac_Error(err);
                 PyMem_Free(path);
                 return !err;
         }
         /* XXXX Should try unicode here too */
+
+#ifndef __LP64__
         /* Otherwise we try to go via an FSSpec */
         if (FSSpec_Check(v)) {
                 fss = ((FSSpecObject *)v)->ob_itself;
@@ -3219,15 +3321,19 @@
                 PyMac_Error(err);
                 return 0;
         }
+#endif /* !__LP64__ */
+
         PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required");
         return 0;
 }
 
+#ifndef __LP64__
 extern PyObject *
 PyMac_BuildFSSpec(FSSpec *spec)
 {
         return FSSpec_New(spec);
 }
+#endif /* !__LP64__ */
 
 extern PyObject *
 PyMac_BuildFSRef(FSRef *spec)
@@ -3242,10 +3348,12 @@
 	PyObject *d;
 
 
-
+#ifndef __LP64__
 	PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
-	PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
 	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
+#endif /* !__LP64__ */
+
+	PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
 	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
 
 
@@ -3262,6 +3370,8 @@
 	/* Backward-compatible name */
 	Py_INCREF(&FSCatalogInfo_Type);
 	PyModule_AddObject(m, "FSCatalogInfoType", (PyObject *)&FSCatalogInfo_Type);
+
+#ifndef __LP64__
 	FInfo_Type.ob_type = &PyType_Type;
 	if (PyType_Ready(&FInfo_Type) < 0) return;
 	Py_INCREF(&FInfo_Type);
@@ -3269,6 +3379,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&FInfo_Type);
 	PyModule_AddObject(m, "FInfoType", (PyObject *)&FInfo_Type);
+#endif /* !__LP64__ */
 	Alias_Type.ob_type = &PyType_Type;
 	if (PyType_Ready(&Alias_Type) < 0) return;
 	Py_INCREF(&Alias_Type);
@@ -3276,6 +3387,8 @@
 	/* Backward-compatible name */
 	Py_INCREF(&Alias_Type);
 	PyModule_AddObject(m, "AliasType", (PyObject *)&Alias_Type);
+
+#ifndef __LP64__
 	FSSpec_Type.ob_type = &PyType_Type;
 	if (PyType_Ready(&FSSpec_Type) < 0) return;
 	Py_INCREF(&FSSpec_Type);
@@ -3283,6 +3396,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&FSSpec_Type);
 	PyModule_AddObject(m, "FSSpecType", (PyObject *)&FSSpec_Type);
+#endif /* !__LP64__ */
 	FSRef_Type.ob_type = &PyType_Type;
 	if (PyType_Ready(&FSRef_Type) < 0) return;
 	Py_INCREF(&FSRef_Type);
diff --git a/Mac/Modules/file/filesupport.py b/Mac/Modules/file/filesupport.py
index 37aeb50..88f88cd 100644
--- a/Mac/Modules/file/filesupport.py
+++ b/Mac/Modules/file/filesupport.py
@@ -6,6 +6,13 @@
 # XXXX TO DO:
 # - Implement correct missing FSSpec handling for Alias methods
 # - Implement FInfo
+#
+# WARNING WARNING WARNING
+#   The file _Filemodule.c was modified manually, don't run this script
+#   unless you really know what you're doing.
+
+import sys
+sys.exit(42)
 
 import string
 
@@ -199,6 +206,7 @@
         return Py_BuildValue("u#", itself->unicode, itself->length);
 }
 
+#ifndef __LP64__
 /*
 ** Get pathname for a given FSSpec
 */
@@ -244,10 +252,13 @@
         }
         return 0;
 }
+#endif /* !__LP64__ */
 
 """
 
 finalstuff = finalstuff + """
+
+#ifndef __LP64__
 int
 PyMac_GetFSSpec(PyObject *v, FSSpec *spec)
 {
@@ -286,6 +297,8 @@
         return 0;
 }
 
+#endif /* !__LP64__ */
+
 int
 PyMac_GetFSRef(PyObject *v, FSRef *fsr)
 {
@@ -309,6 +322,7 @@
         }
         /* XXXX Should try unicode here too */
         /* Otherwise we try to go via an FSSpec */
+#ifndef __LP64__
         if (FSSpec_Check(v)) {
                 fss = ((FSSpecObject *)v)->ob_itself;
                 if ((err=FSpMakeFSRef(&fss, fsr)) == 0)
@@ -317,14 +331,19 @@
                 return 0;
         }
         PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required");
+#else /* __LP64__ */
+        PyErr_SetString(PyExc_TypeError, "FSRef or pathname required");
+#endif /* __LP64__ */
         return 0;
 }
 
+#ifndef __LP64__
 extern PyObject *
 PyMac_BuildFSSpec(FSSpec *spec)
 {
         return FSSpec_New(spec);
 }
+#endif /* __LP64__ */
 
 extern PyObject *
 PyMac_BuildFSRef(FSRef *spec)
@@ -334,9 +353,11 @@
 """
 
 initstuff = initstuff + """
+#ifndef __LP64__
 PyMac_INIT_TOOLBOX_OBJECT_NEW(FSSpec *, PyMac_BuildFSSpec);
-PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSSpec, PyMac_GetFSSpec);
+#endif /* !__LP64__*/
+PyMac_INIT_TOOLBOX_OBJECT_NEW(FSRef *, PyMac_BuildFSRef);
 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(FSRef, PyMac_GetFSRef);
 """
 
diff --git a/Mac/Modules/fm/_Fmmodule.c b/Mac/Modules/fm/_Fmmodule.c
index 890af54..b982cc3 100644
--- a/Mac/Modules/fm/_Fmmodule.c
+++ b/Mac/Modules/fm/_Fmmodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -335,23 +336,32 @@
 	{NULL, NULL, 0}
 };
 
+#else  /* __LP64__ */
 
+static PyMethodDef Fm_methods[] = {
+	{NULL, NULL, 0}
+};
 
+#endif  /* __LP64__ */
 
 void init_Fm(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
+#endif  /* __LP64__ */
 
 
 
 
 	m = Py_InitModule("_Fm", Fm_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Fm_Error = PyMac_GetOSErrException();
 	if (Fm_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Fm_Error) != 0)
 		return;
+#endif  /* __LP64__ */
 }
 
 /* ========================= End module _Fm ========================= */
diff --git a/Mac/Modules/folder/_Foldermodule.c b/Mac/Modules/folder/_Foldermodule.c
index bd33b8e..035dab8 100644
--- a/Mac/Modules/folder/_Foldermodule.c
+++ b/Mac/Modules/folder/_Foldermodule.c
@@ -27,8 +27,8 @@
 	short vRefNum;
 	OSType folderType;
 	Boolean createFolder;
-	short foundVRefNum;
-	long foundDirID;
+	FSVolumeRefNum  foundVRefNum;
+	SInt32 foundDirID;
 	if (!PyArg_ParseTuple(_args, "hO&b",
 	                      &vRefNum,
 	                      PyMac_GetOSType, &folderType,
@@ -158,6 +158,7 @@
 	return _res;
 }
 
+#ifndef __LP64__
 static PyObject *Folder_GetFolderName(PyObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -248,6 +249,7 @@
 	                     flags);
 	return _res;
 }
+#endif /* !__LP64__ */
 
 static PyObject *Folder_InvalidateFolderDescriptorCache(PyObject *_self, PyObject *_args)
 {
@@ -300,6 +302,7 @@
 	 PyDoc_STR("(UInt32 requestedTypeCount) -> (UInt32 totalTypeCount, FolderType theTypes)")},
 	{"RemoveFolderDescriptor", (PyCFunction)Folder_RemoveFolderDescriptor, 1,
 	 PyDoc_STR("(FolderType foldType) -> None")},
+#ifndef __LP64__
 	{"GetFolderName", (PyCFunction)Folder_GetFolderName, 1,
 	 PyDoc_STR("(short vRefNum, OSType foldType, Str255 name) -> (short foundVRefNum)")},
 	{"AddFolderRouting", (PyCFunction)Folder_AddFolderRouting, 1,
@@ -308,6 +311,7 @@
 	 PyDoc_STR("(OSType fileType, FolderType routeFromFolder) -> None")},
 	{"FindFolderRouting", (PyCFunction)Folder_FindFolderRouting, 1,
 	 PyDoc_STR("(OSType fileType, FolderType routeFromFolder) -> (FolderType routeToFolder, RoutingFlags flags)")},
+#endif /* !__LP64__ */
 	{"InvalidateFolderDescriptorCache", (PyCFunction)Folder_InvalidateFolderDescriptorCache, 1,
 	 PyDoc_STR("(short vRefNum, long dirID) -> None")},
 	{"IdentifyFolder", (PyCFunction)Folder_IdentifyFolder, 1,
diff --git a/Mac/Modules/help/_Helpmodule.c b/Mac/Modules/help/_Helpmodule.c
index b9c9599..a6eccf3 100644
--- a/Mac/Modules/help/_Helpmodule.c
+++ b/Mac/Modules/help/_Helpmodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -144,7 +145,10 @@
 	return _res;
 }
 
+#endif /* __LP64__ */
+
 static PyMethodDef Help_methods[] = {
+#ifndef __LP64__
 	{"HMGetHelpMenu", (PyCFunction)Help_HMGetHelpMenu, 1,
 	 PyDoc_STR("() -> (MenuRef outHelpMenu, MenuItemIndex outFirstCustomItemIndex)")},
 	{"HMAreHelpTagsDisplayed", (PyCFunction)Help_HMAreHelpTagsDisplayed, 1,
@@ -161,6 +165,7 @@
 	 PyDoc_STR("(DialogPtr inDialog, SInt16 inHdlgRsrcID, SInt16 inItemStart) -> None")},
 	{"HMHideTag", (PyCFunction)Help_HMHideTag, 1,
 	 PyDoc_STR("() -> None")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
@@ -170,17 +175,21 @@
 void init_Help(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
+#endif /* __LP64__ */
 
 
 
 
 	m = Py_InitModule("_Help", Help_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Help_Error = PyMac_GetOSErrException();
 	if (Help_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Help_Error) != 0)
 		return;
+#endif /* __LP64__ */
 }
 
 /* ======================== End module _Help ======================== */
diff --git a/Mac/Modules/ibcarbon/_IBCarbon.c b/Mac/Modules/ibcarbon/_IBCarbon.c
index 6baad7c..c7c819c 100644
--- a/Mac/Modules/ibcarbon/_IBCarbon.c
+++ b/Mac/Modules/ibcarbon/_IBCarbon.c
@@ -4,6 +4,7 @@
 #include "Python.h"
 
 
+#ifndef __LP64__
 
 #include <Carbon/Carbon.h>
 #include "pymactoolbox.h"
@@ -224,10 +225,13 @@
 	                     IBNibRefObj_New, outNibRef);
 	return _res;
 }
+#endif /* __LP64__ */
 
 static PyMethodDef IBCarbon_methods[] = {
+#ifndef __LP64__
 	{"CreateNibReference", (PyCFunction)IBCarbon_CreateNibReference, 1,
 	 PyDoc_STR("(CFStringRef inNibName) -> (IBNibRef outNibRef)")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
@@ -237,13 +241,16 @@
 void init_IBCarbon(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
+#endif /* __LP64__ */
 
 
 
 
 
 	m = Py_InitModule("_IBCarbon", IBCarbon_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	IBCarbon_Error = PyMac_GetOSErrException();
 	if (IBCarbon_Error == NULL ||
@@ -256,6 +263,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&IBNibRef_Type);
 	PyModule_AddObject(m, "IBNibRefType", (PyObject *)&IBNibRef_Type);
+#endif /* __LP64__ */
 }
 
 /* ====================== End module _IBCarbon ====================== */
diff --git a/Mac/Modules/icn/_Icnmodule.c b/Mac/Modules/icn/_Icnmodule.c
index 2b43ed4..80201a2 100644
--- a/Mac/Modules/icn/_Icnmodule.c
+++ b/Mac/Modules/icn/_Icnmodule.c
@@ -4,6 +4,7 @@
 #include "Python.h"
 
 
+#ifndef __LP64__
 
 #include "pymactoolbox.h"
 
@@ -1447,8 +1448,10 @@
 	_res = Py_None;
 	return _res;
 }
+#endif /* __LP64__ */
 
 static PyMethodDef Icn_methods[] = {
+#ifndef __LP64__
 	{"GetCIcon", (PyCFunction)Icn_GetCIcon, 1,
 	 PyDoc_STR("(SInt16 iconID) -> (CIconHandle _rv)")},
 	{"PlotCIcon", (PyCFunction)Icn_PlotCIcon, 1,
@@ -1573,6 +1576,7 @@
 	 PyDoc_STR("(FSRef ref) -> (IconFamilyHandle iconFamily)")},
 	{"WriteIconFile", (PyCFunction)Icn_WriteIconFile, 1,
 	 PyDoc_STR("(IconFamilyHandle iconFamily, FSSpec iconFile) -> None")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
@@ -1582,17 +1586,21 @@
 void init_Icn(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
+#endif /* __LP64__ */
 
 
 
 
 	m = Py_InitModule("_Icn", Icn_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Icn_Error = PyMac_GetOSErrException();
 	if (Icn_Error == NULL ||
 	    PyDict_SetItemString(d, "Error", Icn_Error) != 0)
 		return;
+#endif /* __LP64__ */
 }
 
 /* ======================== End module _Icn ========================= */
diff --git a/Mac/Modules/launch/_Launchmodule.c b/Mac/Modules/launch/_Launchmodule.c
index fac55ee..fa21ece 100644
--- a/Mac/Modules/launch/_Launchmodule.c
+++ b/Mac/Modules/launch/_Launchmodule.c
@@ -50,6 +50,7 @@
 PyObject *
 LSItemInfoRecord_New(LSItemInfoRecord *it)
 {
+#ifndef __LP64__
         return Py_BuildValue("{s:is:O&s:O&s:O&s:O&s:i}",
                 "flags", it->flags,
                 "filetype", PyMac_BuildOSType, it->filetype,
@@ -57,6 +58,13 @@
                 "extension", OptCFStringRefObj_New, it->extension,
                 "iconFileName", OptCFStringRefObj_New, it->iconFileName,
                 "kindID", it->kindID);
+#else
+        return Py_BuildValue("{s:is:O&s:O&s:O&}",
+                "flags", it->flags,
+                "filetype", PyMac_BuildOSType, it->filetype,
+                "creator", PyMac_BuildOSType, it->creator,
+                "extension", OptCFStringRefObj_New, it->extension);
+#endif
 }
 
 static PyObject *Launch_Error;
diff --git a/Mac/Modules/list/_Listmodule.c b/Mac/Modules/list/_Listmodule.c
index 21a7f02..0797404 100644
--- a/Mac/Modules/list/_Listmodule.c
+++ b/Mac/Modules/list/_Listmodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -1032,8 +1033,10 @@
 	return _res;
 
 }
+#endif /* __LP64__ */
 
 static PyMethodDef List_methods[] = {
+#ifndef __LP64__
 	{"CreateCustomList", (PyCFunction)List_CreateCustomList, 1,
 	 PyDoc_STR("(Rect rView, Rect dataBounds, Point cellSize, ListDefSpec theSpec, WindowPtr theWindow, Boolean drawIt, Boolean hasGrow, Boolean scrollHoriz, Boolean scrollVert) -> (ListHandle outList)")},
 	{"LNew", (PyCFunction)List_LNew, 1,
@@ -1056,9 +1059,11 @@
 	 PyDoc_STR("(ListHandle list, OptionBits selectionFlags) -> None")},
 	{"as_List", (PyCFunction)List_as_List, 1,
 	 PyDoc_STR("(Resource)->List.\nReturns List object (which is not auto-freed!)")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
+#ifndef __LP64__
 
 
 static void myListDefFunction(SInt16 message,
@@ -1096,11 +1101,13 @@
                 Py_DECREF(rv);
         }
 }
+#endif /* __LP64__ */
 
 
 void init_List(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
 
 
@@ -1109,9 +1116,11 @@
 
 	PyMac_INIT_TOOLBOX_OBJECT_NEW(ListHandle, ListObj_New);
 	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ListHandle, ListObj_Convert);
+#endif /* __LP64__ */
 
 
 	m = Py_InitModule("_List", List_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	List_Error = PyMac_GetOSErrException();
 	if (List_Error == NULL ||
@@ -1124,6 +1133,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&List_Type);
 	PyModule_AddObject(m, "ListType", (PyObject *)&List_Type);
+#endif /* __LP64__ */
 }
 
 /* ======================== End module _List ======================== */
diff --git a/Mac/Modules/menu/_Menumodule.c b/Mac/Modules/menu/_Menumodule.c
index e6a7f2f..66ebf79 100644
--- a/Mac/Modules/menu/_Menumodule.c
+++ b/Mac/Modules/menu/_Menumodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -3347,8 +3348,10 @@
 	_res = Py_None;
 	return _res;
 }
+#endif /* __LP64__ */
 
 static PyMethodDef Menu_methods[] = {
+#ifndef __LP64__
 	{"NewMenu", (PyCFunction)Menu_NewMenu, 1,
 	 PyDoc_STR("(MenuID menuID, Str255 menuTitle) -> (MenuHandle _rv)")},
 	{"MacGetMenu", (PyCFunction)Menu_MacGetMenu, 1,
@@ -3433,6 +3436,7 @@
 	 PyDoc_STR("(MenuHandle inMenu, MenuCommand inCommandID, OSType inPropertyCreator, OSType inPropertyTag) -> (ByteCount outSize)")},
 	{"RemoveMenuCommandProperty", (PyCFunction)Menu_RemoveMenuCommandProperty, 1,
 	 PyDoc_STR("(MenuHandle inMenu, MenuCommand inCommandID, OSType inPropertyCreator, OSType inPropertyTag) -> None")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
@@ -3442,15 +3446,18 @@
 void init_Menu(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
 
 
 
 	        PyMac_INIT_TOOLBOX_OBJECT_NEW(MenuHandle, MenuObj_New);
 	        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(MenuHandle, MenuObj_Convert);
+#endif /* __LP64__ */
 
 
 	m = Py_InitModule("_Menu", Menu_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Menu_Error = PyMac_GetOSErrException();
 	if (Menu_Error == NULL ||
@@ -3463,6 +3470,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&Menu_Type);
 	PyModule_AddObject(m, "MenuType", (PyObject *)&Menu_Type);
+#endif /* __LP64__ */
 }
 
 /* ======================== End module _Menu ======================== */
diff --git a/Mac/Modules/mlte/_Mltemodule.c b/Mac/Modules/mlte/_Mltemodule.c
index a79b257..1a6b6a4 100644
--- a/Mac/Modules/mlte/_Mltemodule.c
+++ b/Mac/Modules/mlte/_Mltemodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -1622,7 +1623,10 @@
 
 }
 
+#endif /* __LP64__ */
+
 static PyMethodDef Mlte_methods[] = {
+#ifndef __LP64__
 	{"TXNNewObject", (PyCFunction)Mlte_TXNNewObject, 1,
 	 PyDoc_STR("(FSSpec * iFileSpec, WindowPtr iWindow, Rect iFrame, TXNFrameOptions iFrameOptions, TXNFrameType iFrameType, TXNFileType iFileType, TXNPermanentTextEncodingType iPermanentEncoding) -> (TXNObject oTXNObject, TXNFrameID oTXNFrameID)")},
 	{"TXNTerminateTextension", (PyCFunction)Mlte_TXNTerminateTextension, 1,
@@ -1639,6 +1643,7 @@
 	 PyDoc_STR("() -> (TXNVersionValue _rv, TXNFeatureBits oFeatureFlags)")},
 	{"TXNInitTextension", (PyCFunction)Mlte_TXNInitTextension, 1,
 	 PyDoc_STR("(TXNInitOptions) -> None")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
@@ -1648,14 +1653,17 @@
 void init_Mlte(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
 
 
 
 	//      PyMac_INIT_TOOLBOX_OBJECT_NEW(xxxx);
 
+#endif /* __LP64__ */
 
 	m = Py_InitModule("_Mlte", Mlte_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Mlte_Error = PyMac_GetOSErrException();
 	if (Mlte_Error == NULL ||
@@ -1675,6 +1683,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&TXNFontMenuObject_Type);
 	PyModule_AddObject(m, "TXNFontMenuObjectType", (PyObject *)&TXNFontMenuObject_Type);
+#endif /* __LP64__ */
 }
 
 /* ======================== End module _Mlte ======================== */
diff --git a/Mac/Modules/qd/_Qdmodule.c b/Mac/Modules/qd/_Qdmodule.c
index f0ff9ad..f2202e01 100644
--- a/Mac/Modules/qd/_Qdmodule.c
+++ b/Mac/Modules/qd/_Qdmodule.c
@@ -4,6 +4,7 @@
 #include "Python.h"
 
 
+#ifndef __LP64__
 
 #include "pymactoolbox.h"
 
@@ -6544,8 +6545,10 @@
 	return _res;
 
 }
+#endif /* __LP64__ */
 
 static PyMethodDef Qd_methods[] = {
+#ifndef __LP64__
 	{"GetPort", (PyCFunction)Qd_GetPort, 1,
 	 PyDoc_STR("() -> (GrafPtr port)")},
 	{"GrafDevice", (PyCFunction)Qd_GrafDevice, 1,
@@ -7080,10 +7083,12 @@
 	 PyDoc_STR("Take (string, int, Rect) argument and create BitMap")},
 	{"RawBitMap", (PyCFunction)Qd_RawBitMap, 1,
 	 PyDoc_STR("Take string BitMap and turn into BitMap object")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
 
+#ifndef __LP64__
 
 /* Like BMObj_New, but the original bitmap data structure is copied (and
 ** released when the object is released)
@@ -7101,11 +7106,13 @@
         return (PyObject *)it;
 }
 
+#endif /* __LP64__ */
 
 
 void init_Qd(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
 
 
@@ -7117,8 +7124,10 @@
 	        PyMac_INIT_TOOLBOX_OBJECT_NEW(RGBColorPtr, QdRGB_New);
 	        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(RGBColor, QdRGB_Convert);
 
+#endif /* __LP64__ */
 
 	m = Py_InitModule("_Qd", Qd_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Qd_Error = PyMac_GetOSErrException();
 	if (Qd_Error == NULL ||
@@ -7138,6 +7147,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&BitMap_Type);
 	PyModule_AddObject(m, "BitMapType", (PyObject *)&BitMap_Type);
+#endif /* __LP64__ */
 }
 
 /* ========================= End module _Qd ========================= */
diff --git a/Mac/Modules/qdoffs/_Qdoffsmodule.c b/Mac/Modules/qdoffs/_Qdoffsmodule.c
index f87e6b7..337754a 100644
--- a/Mac/Modules/qdoffs/_Qdoffsmodule.c
+++ b/Mac/Modules/qdoffs/_Qdoffsmodule.c
@@ -4,6 +4,7 @@
 #include "Python.h"
 
 
+#ifndef __LP64__
 
 #include "pymactoolbox.h"
 
@@ -630,8 +631,10 @@
 	return _res;
 
 }
+#endif /* __LP64__ */
 
 static PyMethodDef Qdoffs_methods[] = {
+#ifndef __LP64__
 	{"NewGWorld", (PyCFunction)Qdoffs_NewGWorld, 1,
 	 PyDoc_STR("(short PixelDepth, Rect boundsRect, CTabHandle cTable, GDHandle aGDevice, GWorldFlags flags) -> (GWorldPtr offscreenGWorld)")},
 	{"LockPixels", (PyCFunction)Qdoffs_LockPixels, 1,
@@ -678,6 +681,7 @@
 	 PyDoc_STR("(pixmap, int start, int size) -> string. Return bytes from the pixmap")},
 	{"PutPixMapBytes", (PyCFunction)Qdoffs_PutPixMapBytes, 1,
 	 PyDoc_STR("(pixmap, int start, string data). Store bytes into the pixmap")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
@@ -687,6 +691,7 @@
 void init_Qdoffs(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
 
 
@@ -694,8 +699,10 @@
 	        PyMac_INIT_TOOLBOX_OBJECT_NEW(GWorldPtr, GWorldObj_New);
 	        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(GWorldPtr, GWorldObj_Convert);
 
+#endif /* __LP64__ */
 
 	m = Py_InitModule("_Qdoffs", Qdoffs_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Qdoffs_Error = PyMac_GetOSErrException();
 	if (Qdoffs_Error == NULL ||
@@ -708,6 +715,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&GWorld_Type);
 	PyModule_AddObject(m, "GWorldType", (PyObject *)&GWorld_Type);
+#endif /* __LP64__ */
 }
 
 /* ======================= End module _Qdoffs ======================= */
diff --git a/Mac/Modules/qt/_Qtmodule.c b/Mac/Modules/qt/_Qtmodule.c
index 65cec4b..7b17c9b 100644
--- a/Mac/Modules/qt/_Qtmodule.c
+++ b/Mac/Modules/qt/_Qtmodule.c
@@ -4,6 +4,7 @@
 #include "Python.h"
 
 
+#ifndef __LP64__
 
 #include "pymactoolbox.h"
 
@@ -26294,8 +26295,10 @@
 	_res = Py_None;
 	return _res;
 }
+#endif /* __LP64__ */
 
 static PyMethodDef Qt_methods[] = {
+#ifndef __LP64__
 	{"EnterMovies", (PyCFunction)Qt_EnterMovies, 1,
 	 PyDoc_STR("() -> None")},
 	{"ExitMovies", (PyCFunction)Qt_ExitMovies, 1,
@@ -27988,6 +27991,7 @@
 	 PyDoc_STR("(WindowPtr wp, Point startPt, Rect boundsRect) -> None")},
 	{"MoviesTask", (PyCFunction)Qt_MoviesTask, 1,
 	 PyDoc_STR("(long maxMilliSecToUse) -> None")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
@@ -27997,6 +28001,7 @@
 void init_Qt(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
 
 
@@ -28013,9 +28018,11 @@
 	        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(UserData, UserDataObj_Convert);
 	        PyMac_INIT_TOOLBOX_OBJECT_NEW(Media, MediaObj_New);
 	        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Media, MediaObj_Convert);
+#endif /* __LP64__ */
 
 
 	m = Py_InitModule("_Qt", Qt_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Qt_Error = PyMac_GetOSErrException();
 	if (Qt_Error == NULL ||
@@ -28077,6 +28084,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&SGOutput_Type);
 	PyModule_AddObject(m, "SGOutputType", (PyObject *)&SGOutput_Type);
+#endif /* __LP64__ */
 }
 
 /* ========================= End module _Qt ========================= */
diff --git a/Mac/Modules/res/_Resmodule.c b/Mac/Modules/res/_Resmodule.c
index 011c575..207037a 100644
--- a/Mac/Modules/res/_Resmodule.c
+++ b/Mac/Modules/res/_Resmodule.c
@@ -4,7 +4,6 @@
 #include "Python.h"
 
 
-
 #include "pymactoolbox.h"
 
 /* Macro to test whether a weak-loaded CFM function exists */
@@ -414,6 +413,7 @@
 	return _res;
 }
 
+#ifndef __LP64__
 static PyObject *ResObj_as_Control(ResourceObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -431,6 +431,7 @@
 	return _res;
 
 }
+#endif /* !__LP64__ */
 
 static PyObject *ResObj_LoadResource(ResourceObject *_self, PyObject *_args)
 {
@@ -501,10 +502,12 @@
 	 PyDoc_STR("(long newSize) -> None")},
 	{"GetNextFOND", (PyCFunction)ResObj_GetNextFOND, 1,
 	 PyDoc_STR("() -> (Handle _rv)")},
+#ifndef __LP64__
 	{"as_Control", (PyCFunction)ResObj_as_Control, 1,
 	 PyDoc_STR("Return this resource/handle as a Control")},
 	{"as_Menu", (PyCFunction)ResObj_as_Menu, 1,
 	 PyDoc_STR("Return this resource/handle as a Menu")},
+#endif /* !__LP64__ */
 	{"LoadResource", (PyCFunction)ResObj_LoadResource, 1,
 	 PyDoc_STR("() -> None")},
 	{"AutoDispose", (PyCFunction)ResObj_AutoDispose, 1,
@@ -1152,6 +1155,7 @@
 	return _res;
 }
 
+#ifndef __LP64__
 static PyObject *Res_OpenRFPerm(PyObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -1287,6 +1291,7 @@
 	_res = Py_None;
 	return _res;
 }
+#endif /* !__LP64__ */
 
 static PyObject *Res_InsertResourceFile(PyObject *_self, PyObject *_args)
 {
@@ -1327,6 +1332,7 @@
 	return _res;
 }
 
+#ifndef __LP64__
 static PyObject *Res_FSpResourceFileAlreadyOpen(PyObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -1394,6 +1400,7 @@
 	return _res;
 }
 
+
 static PyObject *Res_GetNextResourceFile(PyObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -1413,6 +1420,7 @@
 	                     nextRefNum);
 	return _res;
 }
+#endif /* !__LP64__ */
 
 static PyObject *Res_FSOpenResFile(PyObject *_self, PyObject *_args)
 {
@@ -1438,6 +1446,8 @@
 	return _res;
 }
 
+
+#ifndef __LP64__
 static PyObject *Res_FSCreateResFile(PyObject *_self, PyObject *_args)
 {
 	PyObject *_res = NULL;
@@ -1534,6 +1544,7 @@
 	                     PyMac_BuildFSSpec, &newSpec);
 	return _res;
 }
+#endif /* __LP64__ */
 
 static PyObject *Res_FSOpenResourceFile(PyObject *_self, PyObject *_args)
 {
@@ -1544,7 +1555,7 @@
 	UniCharCount forkNameLength__len__;
 	int forkNameLength__in_len__;
 	SignedByte permissions;
-	SInt16 refNum;
+	ResFileRefNum refNum;
 #ifndef FSOpenResourceFile
 	PyMac_PRECHECK(FSOpenResourceFile);
 #endif
@@ -1637,6 +1648,7 @@
 	 PyDoc_STR("(short refNum) -> (short _rv)")},
 	{"SetResFileAttrs", (PyCFunction)Res_SetResFileAttrs, 1,
 	 PyDoc_STR("(short refNum, short attrs) -> None")},
+#ifndef __LP64__
 	{"OpenRFPerm", (PyCFunction)Res_OpenRFPerm, 1,
 	 PyDoc_STR("(Str255 fileName, short vRefNum, SignedByte permission) -> (short _rv)")},
 	{"HOpenResFile", (PyCFunction)Res_HOpenResFile, 1,
@@ -1647,10 +1659,12 @@
 	 PyDoc_STR("(FSSpec spec, SignedByte permission) -> (short _rv)")},
 	{"FSpCreateResFile", (PyCFunction)Res_FSpCreateResFile, 1,
 	 PyDoc_STR("(FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None")},
+#endif /* !__LP64__ */
 	{"InsertResourceFile", (PyCFunction)Res_InsertResourceFile, 1,
 	 PyDoc_STR("(SInt16 refNum, RsrcChainLocation where) -> None")},
 	{"DetachResourceFile", (PyCFunction)Res_DetachResourceFile, 1,
 	 PyDoc_STR("(SInt16 refNum) -> None")},
+#ifndef __LP64__
 	{"FSpResourceFileAlreadyOpen", (PyCFunction)Res_FSpResourceFileAlreadyOpen, 1,
 	 PyDoc_STR("(FSSpec resourceFile) -> (Boolean _rv, Boolean inChain, SInt16 refNum)")},
 	{"FSpOpenOrphanResFile", (PyCFunction)Res_FSpOpenOrphanResFile, 1,
@@ -1659,14 +1673,17 @@
 	 PyDoc_STR("() -> (SInt16 refNum)")},
 	{"GetNextResourceFile", (PyCFunction)Res_GetNextResourceFile, 1,
 	 PyDoc_STR("(SInt16 curRefNum) -> (SInt16 nextRefNum)")},
+#endif /* __LP64__ */
 	{"FSOpenResFile", (PyCFunction)Res_FSOpenResFile, 1,
 	 PyDoc_STR("(FSRef ref, SignedByte permission) -> (short _rv)")},
+#ifndef __LP64__
 	{"FSCreateResFile", (PyCFunction)Res_FSCreateResFile, 1,
 	 PyDoc_STR("(FSRef parentRef, Buffer nameLength) -> (FSRef newRef, FSSpec newSpec)")},
 	{"FSResourceFileAlreadyOpen", (PyCFunction)Res_FSResourceFileAlreadyOpen, 1,
 	 PyDoc_STR("(FSRef resourceFileRef) -> (Boolean _rv, Boolean inChain, SInt16 refNum)")},
 	{"FSCreateResourceFile", (PyCFunction)Res_FSCreateResourceFile, 1,
 	 PyDoc_STR("(FSRef parentRef, Buffer nameLength, Buffer forkNameLength) -> (FSRef newRef, FSSpec newSpec)")},
+#endif /* __LP64__ */
 	{"FSOpenResourceFile", (PyCFunction)Res_FSOpenResourceFile, 1,
 	 PyDoc_STR("(FSRef ref, Buffer forkNameLength, SignedByte permissions) -> (SInt16 refNum)")},
 	{"Handle", (PyCFunction)Res_Handle, 1,
@@ -1676,7 +1693,6 @@
 
 
 
-
 /* Alternative version of ResObj_New, which returns None for null argument */
 PyObject *OptResObj_New(Handle itself)
 {
diff --git a/Mac/Modules/scrap/_Scrapmodule.c b/Mac/Modules/scrap/_Scrapmodule.c
index 2ba8130..f6f4e8c 100644
--- a/Mac/Modules/scrap/_Scrapmodule.c
+++ b/Mac/Modules/scrap/_Scrapmodule.c
@@ -4,6 +4,7 @@
 #include "Python.h"
 
 
+#ifndef __LP64__
 
 #include "pymactoolbox.h"
 
@@ -315,8 +316,10 @@
 	_res = Py_None;
 	return _res;
 }
+#endif /* __LP64__ */
 
 static PyMethodDef Scrap_methods[] = {
+#ifndef __LP64__
 	{"LoadScrap", (PyCFunction)Scrap_LoadScrap, 1,
 	 PyDoc_STR("() -> None")},
 	{"UnloadScrap", (PyCFunction)Scrap_UnloadScrap, 1,
@@ -327,6 +330,7 @@
 	 PyDoc_STR("() -> None")},
 	{"CallInScrapPromises", (PyCFunction)Scrap_CallInScrapPromises, 1,
 	 PyDoc_STR("() -> None")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
@@ -336,12 +340,15 @@
 void init_Scrap(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
+#endif /* __LP64__ */
 
 
 
 
 	m = Py_InitModule("_Scrap", Scrap_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Scrap_Error = PyMac_GetOSErrException();
 	if (Scrap_Error == NULL ||
@@ -351,6 +358,7 @@
 	Py_INCREF(&Scrap_Type);
 	if (PyDict_SetItemString(d, "ScrapType", (PyObject *)&Scrap_Type) != 0)
 		Py_FatalError("can't initialize ScrapType");
+#endif /* __LP64__ */
 }
 
 /* ======================= End module _Scrap ======================== */
diff --git a/Mac/Modules/snd/_Sndmodule.c b/Mac/Modules/snd/_Sndmodule.c
index fcaee5f..c0c739a 100644
--- a/Mac/Modules/snd/_Sndmodule.c
+++ b/Mac/Modules/snd/_Sndmodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -981,8 +982,10 @@
 	                     byteCount);
 	return _res;
 }
+#endif /* __LP64__ */
 
 static PyMethodDef Snd_methods[] = {
+#ifndef __LP64__
 	{"SPB", (PyCFunction)Snd_SPB, 1,
 	 PyDoc_STR(NULL)},
 	{"SysBeep", (PyCFunction)Snd_SysBeep, 1,
@@ -1047,10 +1050,12 @@
 	 PyDoc_STR("(long inRefNum) -> (long milliseconds)")},
 	{"SPBBytesToMilliseconds", (PyCFunction)Snd_SPBBytesToMilliseconds, 1,
 	 PyDoc_STR("(long inRefNum) -> (long byteCount)")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
 
+#ifndef __LP64__
 
 /* Routine passed to Py_AddPendingCall -- call the Python callback */
 static int
@@ -1113,19 +1118,23 @@
                 SetA5(A5);
         }
 }
+#endif /* __LP64__ */
 
 
 
 void init_Snd(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
+#endif /* __LP64__ */
 
 
 
 
 
 	m = Py_InitModule("_Snd", Snd_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Snd_Error = PyMac_GetOSErrException();
 	if (Snd_Error == NULL ||
@@ -1145,6 +1154,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&SPB_Type);
 	PyModule_AddObject(m, "SPBType", (PyObject *)&SPB_Type);
+#endif /* __LP64__ */
 }
 
 /* ======================== End module _Snd ========================= */
diff --git a/Mac/Modules/te/_TEmodule.c b/Mac/Modules/te/_TEmodule.c
index 047b872..f182688 100644
--- a/Mac/Modules/te/_TEmodule.c
+++ b/Mac/Modules/te/_TEmodule.c
@@ -3,6 +3,7 @@
 
 #include "Python.h"
 
+#ifndef __LP64__
 
 
 #include "pymactoolbox.h"
@@ -1267,8 +1268,10 @@
 	                     TEObj_New, _rv);
 	return _res;
 }
+#endif /* __LP64__ */
 
 static PyMethodDef TE_methods[] = {
+#ifndef __LP64__
 	{"TEScrapHandle", (PyCFunction)TE_TEScrapHandle, 1,
 	 PyDoc_STR("() -> (Handle _rv)")},
 	{"TEGetScrapLength", (PyCFunction)TE_TEGetScrapLength, 1,
@@ -1295,6 +1298,7 @@
 	 PyDoc_STR("(UInt8 value) -> None")},
 	{"as_TE", (PyCFunction)TE_as_TE, 1,
 	 PyDoc_STR("(Handle h) -> (TEHandle _rv)")},
+#endif /* __LP64__ */
 	{NULL, NULL, 0}
 };
 
@@ -1304,6 +1308,7 @@
 void init_TE(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
 
 
@@ -1311,8 +1316,10 @@
 	        PyMac_INIT_TOOLBOX_OBJECT_NEW(TEHandle, TEObj_New);
 	        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(TEHandle, TEObj_Convert);
 
+#endif /* __LP64__ */
 
 	m = Py_InitModule("_TE", TE_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	TE_Error = PyMac_GetOSErrException();
 	if (TE_Error == NULL ||
@@ -1325,6 +1332,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&TE_Type);
 	PyModule_AddObject(m, "TEType", (PyObject *)&TE_Type);
+#endif /* __LP64__ */
 }
 
 /* ========================= End module _TE ========================= */
diff --git a/Mac/Modules/win/_Winmodule.c b/Mac/Modules/win/_Winmodule.c
index 21682b6..1562a38 100644
--- a/Mac/Modules/win/_Winmodule.c
+++ b/Mac/Modules/win/_Winmodule.c
@@ -3,7 +3,7 @@
 
 #include "Python.h"
 
-
+#ifndef __LP64__
 
 #include "pymactoolbox.h"
 
@@ -3147,8 +3147,10 @@
 	                     WinObj_WhichWindow, theWindow);
 	return _res;
 }
+#endif /* __LP64__ */
 
 static PyMethodDef Win_methods[] = {
+#ifndef __LP64__
 	{"GetNewCWindow", (PyCFunction)Win_GetNewCWindow, 1,
 	 PyDoc_STR("(short windowID, WindowPtr behind) -> (WindowPtr _rv)")},
 	{"NewWindow", (PyCFunction)Win_NewWindow, 1,
@@ -3200,10 +3202,12 @@
 	{"FindWindow", (PyCFunction)Win_FindWindow, 1,
 	 PyDoc_STR("(Point thePoint) -> (short _rv, WindowPtr theWindow)")},
 	{NULL, NULL, 0}
+#endif /* __LP64__ */
 };
 
 
 
+#ifndef __LP64__
 /* Return the object corresponding to the window, or NULL */
 
 PyObject *
@@ -3226,20 +3230,22 @@
         return it;
 }
 
+#endif /* __LP64__ */
 
 void init_Win(void)
 {
 	PyObject *m;
+#ifndef __LP64__
 	PyObject *d;
 
+	PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_New);
+	PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_WhichWindow);
+	PyMac_INIT_TOOLBOX_OBJECT_CONVERT(WindowPtr, WinObj_Convert);
 
-
-	        PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_New);
-	        PyMac_INIT_TOOLBOX_OBJECT_NEW(WindowPtr, WinObj_WhichWindow);
-	        PyMac_INIT_TOOLBOX_OBJECT_CONVERT(WindowPtr, WinObj_Convert);
-
+#endif /* __LP64__ */
 
 	m = Py_InitModule("_Win", Win_methods);
+#ifndef __LP64__
 	d = PyModule_GetDict(m);
 	Win_Error = PyMac_GetOSErrException();
 	if (Win_Error == NULL ||
@@ -3252,6 +3258,7 @@
 	/* Backward-compatible name */
 	Py_INCREF(&Window_Type);
 	PyModule_AddObject(m, "WindowType", (PyObject *)&Window_Type);
+#endif /* __LP64__ */
 }
 
 /* ======================== End module _Win ========================= */