MacOS.c 16.2 KB
Newer Older
1
/***********************************************************
2
Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
Guido van Rossum's avatar
Guido van Rossum committed
3
The Netherlands.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its 
documentation for any purpose and without fee is hereby granted, 
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in 
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.

STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

******************************************************************/

/* Macintosh OS-specific interface */

#include "Python.h"
28
#include "pymactoolbox.h"
29

30
#include <Carbon/Carbon.h>
31
#include <ApplicationServices/ApplicationServices.h>
32

33
#ifndef HAVE_OSX105_SDK
34 35
typedef SInt16	FSIORefNum;
#endif
36

37 38
static PyObject *MacOS_Error; /* Exception MacOS.Error */

39 40
#define PATHNAMELEN 1024

41 42 43 44 45 46
/* ----------------------------------------------------- */

/* Declarations for objects of type Resource fork */

typedef struct {
	PyObject_HEAD
47
	FSIORefNum fRefNum;
48 49 50
	int isclosed;
} rfobject;

51
static PyTypeObject Rftype;
52 53 54 55 56 57



/* ---------------------------------------------------------------- */

static void
58
do_close(rfobject *self)
59 60
{
	if (self->isclosed ) return;
61
	(void)FSCloseFork(self->fRefNum);
62 63 64 65 66 67 68 69
	self->isclosed = 1;
}

static char rf_read__doc__[] = 
"Read data from resource fork"
;

static PyObject *
70
rf_read(rfobject *self, PyObject *args)
71 72 73 74
{
	long n;
	PyObject *v;
	OSErr err;
75
	ByteCount n2;
76 77 78 79 80 81 82 83 84
	
	if (self->isclosed) {
		PyErr_SetString(PyExc_ValueError, "Operation on closed file");
		return NULL;
	}
	
	if (!PyArg_ParseTuple(args, "l", &n))
		return NULL;
		
85
	v = PyBytes_FromStringAndSize((char *)NULL, n);
86 87 88
	if (v == NULL)
		return NULL;
		
89
	err = FSReadFork(self->fRefNum, fsAtMark, 0, n, PyString_AsString(v), &n2);
90 91 92 93 94
	if (err && err != eofErr) {
		PyMac_Error(err);
		Py_DECREF(v);
		return NULL;
	}
95
	_PyString_Resize(&v, n2);
96 97 98 99 100 101 102 103 104
	return v;
}


static char rf_write__doc__[] = 
"Write to resource fork"
;

static PyObject *
105
rf_write(rfobject *self, PyObject *args)
106 107 108 109 110 111 112 113 114
{
	char *buffer;
	long size;
	OSErr err;
	
	if (self->isclosed) {
		PyErr_SetString(PyExc_ValueError, "Operation on closed file");
		return NULL;
	}
115
	if (!PyArg_ParseTuple(args, "s#", &buffer, &size))
116
		return NULL;
117
	err = FSWriteFork(self->fRefNum, fsAtMark, 0, size, buffer, NULL);
118 119 120 121 122 123 124 125 126 127 128 129 130 131
	if (err) {
		PyMac_Error(err);
		return NULL;
	}
	Py_INCREF(Py_None);
	return Py_None;
}


static char rf_seek__doc__[] = 
"Set file position"
;

static PyObject *
132
rf_seek(rfobject *self, PyObject *args)
133
{
134
	long amount;
135
	int whence = SEEK_SET;
136
	int mode;
137 138 139 140 141 142
	OSErr err;
	
	if (self->isclosed) {
		PyErr_SetString(PyExc_ValueError, "Operation on closed file");
		return NULL;
	}
143
	if (!PyArg_ParseTuple(args, "l|i", &amount, &whence)) {
144
		return NULL;
145
	}
146 147 148
	
	switch (whence) {
	case SEEK_CUR:
149
		mode = fsFromMark;
150 151
		break;
	case SEEK_END:
152
		mode = fsFromLEOF;
153 154
		break;
	case SEEK_SET:
155
		mode = fsFromStart;
156 157 158 159 160
		break;
	default:
		PyErr_BadArgument();
		return NULL;
	}
161 162 163

	err = FSSetForkPosition(self->fRefNum, mode, amount);
	if (err != noErr) {
164 165 166 167 168 169 170 171 172 173 174 175 176
		PyMac_Error(err);
		return NULL;
	}
	Py_INCREF(Py_None);
	return Py_None;
}


static char rf_tell__doc__[] = 
"Get file position"
;

static PyObject *
177
rf_tell(rfobject *self, PyObject *args)
178
{
179
	long long where;
180 181 182 183 184 185 186 187
	OSErr err;
	
	if (self->isclosed) {
		PyErr_SetString(PyExc_ValueError, "Operation on closed file");
		return NULL;
	}
	if (!PyArg_ParseTuple(args, ""))
		return NULL;
188 189 190

	err = FSGetForkPosition(self->fRefNum, &where);
	if (err != noErr) {
191 192 193
		PyMac_Error(err);
		return NULL;
	}
194
	return PyLong_FromLongLong(where);
195 196 197 198 199 200 201
}

static char rf_close__doc__[] = 
"Close resource fork"
;

static PyObject *
202
rf_close(rfobject *self, PyObject *args)
203 204 205 206 207 208 209 210 211 212
{
	if (!PyArg_ParseTuple(args, ""))
		return NULL;
	do_close(self);
	Py_INCREF(Py_None);
	return Py_None;
}


static struct PyMethodDef rf_methods[] = {
213 214 215 216 217
 {"read",	(PyCFunction)rf_read,	1,	rf_read__doc__},
 {"write",	(PyCFunction)rf_write,	1,	rf_write__doc__},
 {"seek",	(PyCFunction)rf_seek,	1,	rf_seek__doc__},
 {"tell",	(PyCFunction)rf_tell,	1,	rf_tell__doc__},
 {"close",	(PyCFunction)rf_close,	1,	rf_close__doc__},
218 219 220 221 222 223 224 225
 
	{NULL,		NULL}		/* sentinel */
};

/* ---------- */


static rfobject *
226
newrfobject(void)
227 228 229 230 231 232 233 234 235 236 237 238
{
	rfobject *self;
	
	self = PyObject_NEW(rfobject, &Rftype);
	if (self == NULL)
		return NULL;
	self->isclosed = 1;
	return self;
}


static void
239
rf_dealloc(rfobject *self)
240 241
{
	do_close(self);
242
	PyObject_DEL(self);
243 244 245
}

static PyObject *
246
rf_getattr(rfobject *self, char *name)
247 248 249 250 251 252 253 254 255 256 257
{
	return Py_FindMethod(rf_methods, (PyObject *)self, name);
}

static char Rftype__doc__[] = 
"Resource fork file object"
;

static PyTypeObject Rftype = {
	PyObject_HEAD_INIT(&PyType_Type)
	0,				/*ob_size*/
258
	"MacOS.ResourceFork",		/*tp_name*/
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
	sizeof(rfobject),		/*tp_basicsize*/
	0,				/*tp_itemsize*/
	/* methods */
	(destructor)rf_dealloc,	/*tp_dealloc*/
	(printfunc)0,		/*tp_print*/
	(getattrfunc)rf_getattr,	/*tp_getattr*/
	(setattrfunc)0,	/*tp_setattr*/
	(cmpfunc)0,		/*tp_compare*/
	(reprfunc)0,		/*tp_repr*/
	0,			/*tp_as_number*/
	0,		/*tp_as_sequence*/
	0,		/*tp_as_mapping*/
	(hashfunc)0,		/*tp_hash*/
	(ternaryfunc)0,		/*tp_call*/
	(reprfunc)0,		/*tp_str*/

	/* Space for future expansion */
	0L,0L,0L,0L,
	Rftype__doc__ /* Documentation string */
};

280

281 282
/* End of code for Resource fork objects */
/* -------------------------------------------------------- */
283

284 285 286
/*----------------------------------------------------------------------*/
/* Miscellaneous File System Operations */

287
static char getcrtp_doc[] = "Get MacOS 4-char creator and type for a file";
Jack Jansen's avatar
Jack Jansen committed
288

289
static PyObject *
290
MacOS_GetCreatorAndType(PyObject *self, PyObject *args)
291
{
292
	PyObject *creator, *type, *res;
293
	OSErr err;
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
	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__ */
321
		return NULL;
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
#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);

347
	res = Py_BuildValue("OO", creator, type);
Guido van Rossum's avatar
Guido van Rossum committed
348
	Py_DECREF(creator);
349
	Py_DECREF(type);
350 351 352
	return res;
}

353
static char setcrtp_doc[] = "Set MacOS 4-char creator and type for a file";
Jack Jansen's avatar
Jack Jansen committed
354

355
static PyObject *
356
MacOS_SetCreatorAndType(PyObject *self, PyObject *args)
357
{
358
	ResType creator, type;
359 360
	FSRef ref;
	FileInfo* finfo;
361
	OSErr err;
362 363
	FSCatalogInfo	cataloginfo;

364
	if (!PyArg_ParseTuple(args, "O&O&O&",
365 366 367 368 369 370 371
			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&",
372
			PyMac_GetFSSpec, &fss, PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
			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;
#endif /* __LP64__ */
	}
	
	err = FSGetCatalogInfo(&ref, 
			kFSCatInfoFinderInfo|kFSCatInfoNodeFlags, &cataloginfo, 
			NULL, NULL, NULL);
	if (err != noErr) {
		PyErr_Mac(MacOS_Error, err);
395
		return NULL;
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
	}

	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;
	}

418 419 420 421
	Py_INCREF(Py_None);
	return Py_None;
}

422

Jack Jansen's avatar
Jack Jansen committed
423 424
static char geterr_doc[] = "Convert OSErr number to string";

425 426 427
static PyObject *
MacOS_GetErrorString(PyObject *self, PyObject *args)
{
428 429 430 431 432
	int err;
	char buf[256];
	Handle h;
	char *str;
	static int errors_loaded;
433
	
434
	if (!PyArg_ParseTuple(args, "i", &err))
435
		return NULL;
436 437 438 439 440 441 442 443 444 445 446

	h = GetResource('Estr', err);
	if (!h && !errors_loaded) {
		/*
		** Attempt to open the resource file containing the
		** Estr resources. We ignore all errors. We also try
		** this only once.
		*/
		PyObject *m, *rv;
		errors_loaded = 1;
		
447
		m = PyImport_ImportModuleNoBlock("macresource");
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
		if (!m) {
			if (Py_VerboseFlag)
				PyErr_Print();
			PyErr_Clear();
		}
		else {
			rv = PyObject_CallMethod(m, "open_error_resource", "");
			if (!rv) {
				if (Py_VerboseFlag)
					PyErr_Print();
				PyErr_Clear();
			}
			else {
				Py_DECREF(rv);
				/* And try again... */
				h = GetResource('Estr', err);
			}
Thomas Heller's avatar
Thomas Heller committed
465
			Py_DECREF(m);
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
		}
	}
	/*
	** Whether the code above succeeded or not, we won't try
	** again.
	*/
	errors_loaded = 1;
		
	if (h) {
		HLock(h);
		str = (char *)*h;
		memcpy(buf, str+1, (unsigned char)str[0]);
		buf[(unsigned char)str[0]] = '\0';
		HUnlock(h);
		ReleaseResource(h);
	}
	else {
		PyOS_snprintf(buf, sizeof(buf), "Mac OS error code %d", err);
	}

	return Py_BuildValue("s", buf);
487 488
}

489 490 491

#ifndef __LP64__

492 493 494 495 496
static char splash_doc[] = "Open a splash-screen dialog by resource-id (0=close)";

static PyObject *
MacOS_splash(PyObject *self, PyObject *args)
{
497
	int resid = -1;
498
	static DialogPtr curdialog = NULL;
Jack Jansen's avatar
Jack Jansen committed
499
	DialogPtr olddialog;
500 501
	WindowRef theWindow;
	CGrafPtr thePort;
502
#if 0
503
	short xpos, ypos, width, height, swidth, sheight;
504
#endif
505
	
506
	if (!PyArg_ParseTuple(args, "|i", &resid))
507
		return NULL;
Jack Jansen's avatar
Jack Jansen committed
508
	olddialog = curdialog;
509
	curdialog = NULL;
510

511 512
	if ( resid != -1 ) {
		curdialog = GetNewDialog(resid, NULL, (WindowPtr)-1);
513 514 515
		if ( curdialog ) {
			theWindow = GetDialogWindow(curdialog);
			thePort = GetWindowPort(theWindow);
516
#if 0
517 518 519 520 521 522 523 524
			width = thePort->portRect.right - thePort->portRect.left;
			height = thePort->portRect.bottom - thePort->portRect.top;
			swidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
			sheight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - LMGetMBarHeight();
			xpos = (swidth-width)/2;
			ypos = (sheight-height)/5 + LMGetMBarHeight();
			MoveWindow(theWindow, xpos, ypos, 0);
			ShowWindow(theWindow);
525
#endif
526
			DrawDialog(curdialog);
527
		}
528
	}
Jack Jansen's avatar
Jack Jansen committed
529 530
	if (olddialog)
		DisposeDialog(olddialog);
531 532 533 534
	Py_INCREF(Py_None);
	return Py_None;
}

535 536 537 538 539 540 541 542 543 544
static char DebugStr_doc[] = "Switch to low-level debugger with a message";

static PyObject *
MacOS_DebugStr(PyObject *self, PyObject *args)
{
	Str255 message;
	PyObject *object = 0;
	
	if (!PyArg_ParseTuple(args, "O&|O", PyMac_GetStr255, message, &object))
		return NULL;
545
	
546 547 548 549
	DebugStr(message);
	Py_INCREF(Py_None);
	return Py_None;
}
550

551

Jack Jansen's avatar
Jack Jansen committed
552 553 554 555 556 557 558 559 560 561 562 563 564 565
static char SysBeep_doc[] = "BEEEEEP!!!";

static PyObject *
MacOS_SysBeep(PyObject *self, PyObject *args)
{
	int duration = 6;
	
	if (!PyArg_ParseTuple(args, "|i", &duration))
		return NULL;
	SysBeep(duration);
	Py_INCREF(Py_None);
	return Py_None;
}

566 567
#endif /* __LP64__ */

568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
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."
	;

static PyObject *
MacOS_WMAvailable(PyObject *self, PyObject *args)
{
	static PyObject *rv = NULL;
	
	if (!PyArg_ParseTuple(args, ""))
		return NULL;
	if (!rv) {
		ProcessSerialNumber psn;
		
		/*
		** This is a fairly innocuous call to make if we don't have a window
		** manager, or if we have no permission to talk to it. It will print
		** a message on stderr, but at least it won't abort the process.
		** It appears the function caches the result itself, and it's cheap, so
		** no need for us to cache.
		*/
590 591 592 593
#ifdef kCGNullDirectDisplay
		/* On 10.1 CGMainDisplayID() isn't available, and
		** kCGNullDirectDisplay isn't defined.
		*/
594 595 596
		if (CGMainDisplayID() == 0) {
			rv = Py_False;
		} else {
597 598 599
#else
		{
#endif
600 601 602 603 604 605 606 607 608 609 610 611
			if (GetCurrentProcess(&psn) < 0 ||
				SetFrontProcess(&psn) < 0) {
				rv = Py_False;
			} else {
				rv = Py_True;
			}
		}
	}
	Py_INCREF(rv);
	return rv;
}

612 613 614 615 616
static char GetTicks_doc[] = "Return number of ticks since bootup";

static PyObject *
MacOS_GetTicks(PyObject *self, PyObject *args)
{
617
	return Py_BuildValue("i", (int)TickCount());
618 619
}

620 621 622 623 624 625 626
static char openrf_doc[] = "Open resource fork of a file";

static PyObject *
MacOS_openrf(PyObject *self, PyObject *args)
{
	OSErr err;
	char *mode = "r";
627 628
	FSRef ref;
	SInt8 permission = fsRdPerm;
629
	rfobject *fp;
630
	HFSUniStr255 name;
631
		
632
	if (!PyArg_ParseTuple(args, "O&|s", PyMac_GetFSRef, &ref, &mode))
633 634 635 636
		return NULL;
	while (*mode) {
		switch (*mode++) {
		case '*': break;
637 638
		case 'r': permission = fsRdPerm; break;
		case 'w': permission = fsWrPerm; break;
639 640 641 642 643 644
		case 'b': break;
		default:
			PyErr_BadArgument();
			return NULL;
		}
	}
645 646 647 648 649 650

	err = FSGetResourceForkName(&name);
	if (err != noErr) {
		PyMac_Error(err);
		return NULL;
	}
651 652 653
	
	if ( (fp = newrfobject()) == NULL )
		return NULL;
654

655
	
656 657
	err = FSOpenFork(&ref, name.length, name.unicode, permission, &fp->fRefNum);
	if (err != noErr) {
658 659 660 661 662 663 664 665
		Py_DECREF(fp);
		PyMac_Error(err);
		return NULL;
	}
	fp->isclosed = 0;
	return (PyObject *)fp;
}

666

667

668
static PyMethodDef MacOS_Methods[] = {
Jack Jansen's avatar
Jack Jansen committed
669 670 671 672
	{"GetCreatorAndType",		MacOS_GetCreatorAndType, 1,	getcrtp_doc},
	{"SetCreatorAndType",		MacOS_SetCreatorAndType, 1,	setcrtp_doc},
	{"GetErrorString",		MacOS_GetErrorString,	1,	geterr_doc},
	{"openrf",			MacOS_openrf, 		1, 	openrf_doc},
673
#ifndef __LP64__
Jack Jansen's avatar
Jack Jansen committed
674 675
	{"splash",			MacOS_splash,		1, 	splash_doc},
	{"DebugStr",			MacOS_DebugStr,		1,	DebugStr_doc},
Jack Jansen's avatar
Jack Jansen committed
676
	{"SysBeep",			MacOS_SysBeep,		1,	SysBeep_doc},
677 678
#endif /* __LP64__ */
	{"GetTicks",			MacOS_GetTicks,		1,	GetTicks_doc},
679
	{"WMAvailable",			MacOS_WMAvailable,		1,	WMAvailable_doc},
680
	{NULL,				NULL}		 /* Sentinel */
681 682 683 684
};


void
685
initMacOS(void)
686 687 688
{
	PyObject *m, *d;
	
689 690 691
	if (PyErr_WarnPy3k("In 3.x, MacOS is removed.", 1))
		return;
	
692 693 694 695
	m = Py_InitModule("MacOS", MacOS_Methods);
	d = PyModule_GetDict(m);
	
	/* Initialize MacOS.Error exception */
696
	MacOS_Error = PyMac_GetOSErrException();
697
	if (MacOS_Error == NULL || PyDict_SetItemString(d, "Error", MacOS_Error) != 0)
698
		return;
699 700 701
	Rftype.ob_type = &PyType_Type;
	Py_INCREF(&Rftype);
	if (PyDict_SetItemString(d, "ResourceForkType", (PyObject *)&Rftype) != 0)
702
		return;
703 704 705 706 707 708
	/*
	** This is a hack: the following constant added to the id() of a string
	** object gives you the address of the data. Unfortunately, it is needed for
	** some of the image and sound processing interfaces on the mac:-(
	*/
	{
709
		PyStringObject *p = 0;
710 711 712
		long off = (long)&(p->ob_sval[0]);
		
		if( PyDict_SetItemString(d, "string_id_to_buffer", Py_BuildValue("i", off)) != 0)
713
			return;
714
	}
715
#define PY_RUNTIMEMODEL "macho"
716 717 718
	if (PyDict_SetItemString(d, "runtimemodel", 
				Py_BuildValue("s", PY_RUNTIMEMODEL)) != 0)
		return;
719
#if defined(WITH_NEXT_FRAMEWORK)
720 721 722 723 724 725 726 727 728 729
#define PY_LINKMODEL "framework"
#elif defined(Py_ENABLE_SHARED)
#define PY_LINKMODEL "shared"
#else
#define PY_LINKMODEL "static"
#endif
	if (PyDict_SetItemString(d, "linkmodel", 
				Py_BuildValue("s", PY_LINKMODEL)) != 0)
		return;

730
}