Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
| 25 | |
| 26 | #include "Python.h" |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 27 | #include "pymactoolbox.h" |
| 28 | |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | ** Find out what the current script is. |
| 32 | ** Donated by Fredrik Lund. |
| 33 | */ |
| 34 | char *PyMac_getscript() |
| 35 | { |
Martin v. Löwis | 52ea7e9 | 2002-11-26 09:05:36 +0000 | [diff] [blame] | 36 | CFStringEncoding enc = CFStringGetSystemEncoding(); |
| 37 | static CFStringRef name = NULL; |
| 38 | /* Return the code name for the encodings for which we have codecs. */ |
| 39 | switch(enc) { |
| 40 | case kCFStringEncodingMacRoman: return "mac-roman"; |
| 41 | case kCFStringEncodingMacGreek: return "mac-greek"; |
| 42 | case kCFStringEncodingMacCyrillic: return "mac-cyrillic"; |
| 43 | case kCFStringEncodingMacTurkish: return "mac-turkish"; |
| 44 | case kCFStringEncodingMacIcelandic: return "mac-icelandic"; |
| 45 | /* XXX which one is mac-latin2? */ |
| 46 | } |
| 47 | if (!name) { |
| 48 | /* This leaks a an object. */ |
| 49 | name = CFStringConvertEncodingToIANACharSetName(enc); |
| 50 | } |
Jack Jansen | 0a116f3 | 2002-12-23 21:03:36 +0000 | [diff] [blame] | 51 | return (char *)CFStringGetCStringPtr(name, 0); |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /* Like strerror() but for Mac OS error numbers */ |
| 55 | char *PyMac_StrError(int err) |
| 56 | { |
| 57 | static char buf[256]; |
| 58 | Handle h; |
| 59 | char *str; |
Jack Jansen | dde800e | 2002-11-07 23:07:05 +0000 | [diff] [blame] | 60 | static int errors_loaded; |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 61 | |
| 62 | h = GetResource('Estr', err); |
Jack Jansen | dde800e | 2002-11-07 23:07:05 +0000 | [diff] [blame] | 63 | if (!h && !errors_loaded) { |
| 64 | /* |
| 65 | ** Attempt to open the resource file containing the |
| 66 | ** Estr resources. We ignore all errors. We also try |
| 67 | ** this only once. |
| 68 | */ |
Jack Jansen | dde800e | 2002-11-07 23:07:05 +0000 | [diff] [blame] | 69 | PyObject *m, *rv; |
Michael W. Hudson | 5f26dda | 2002-11-09 14:47:18 +0000 | [diff] [blame] | 70 | errors_loaded = 1; |
Jack Jansen | dde800e | 2002-11-07 23:07:05 +0000 | [diff] [blame] | 71 | |
| 72 | m = PyImport_ImportModule("macresource"); |
| 73 | if (!m) { |
| 74 | if (Py_VerboseFlag) |
| 75 | PyErr_Print(); |
| 76 | PyErr_Clear(); |
| 77 | } else { |
| 78 | rv = PyObject_CallMethod(m, "open_error_resource", ""); |
| 79 | if (!rv) { |
| 80 | if (Py_VerboseFlag) |
| 81 | PyErr_Print(); |
| 82 | PyErr_Clear(); |
| 83 | } else { |
| 84 | Py_DECREF(rv); |
| 85 | /* And try again... */ |
| 86 | h = GetResource('Estr', err); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | /* |
| 91 | ** Whether the code above succeeded or not, we won't try |
| 92 | ** again. |
| 93 | */ |
| 94 | errors_loaded = 1; |
| 95 | |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 96 | if ( h ) { |
| 97 | HLock(h); |
| 98 | str = (char *)*h; |
| 99 | memcpy(buf, str+1, (unsigned char)str[0]); |
| 100 | buf[(unsigned char)str[0]] = '\0'; |
| 101 | HUnlock(h); |
| 102 | ReleaseResource(h); |
| 103 | } else { |
Tim Peters | 22a51ef | 2001-12-04 01:11:32 +0000 | [diff] [blame] | 104 | PyOS_snprintf(buf, sizeof(buf), "Mac OS error code %d", err); |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 105 | } |
| 106 | return buf; |
| 107 | } |
| 108 | |
| 109 | /* Exception object shared by all Mac specific modules for Mac OS errors */ |
| 110 | PyObject *PyMac_OSErrException; |
| 111 | |
| 112 | /* Initialize and return PyMac_OSErrException */ |
| 113 | PyObject * |
Jack Jansen | 697842f | 2001-09-10 22:00:39 +0000 | [diff] [blame] | 114 | PyMac_GetOSErrException(void) |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 115 | { |
| 116 | if (PyMac_OSErrException == NULL) |
Jack Jansen | 8fce2ef | 2002-10-19 22:02:21 +0000 | [diff] [blame] | 117 | PyMac_OSErrException = PyErr_NewException("MacOS.Error", NULL, NULL); |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 118 | return PyMac_OSErrException; |
| 119 | } |
| 120 | |
| 121 | /* Set a MAC-specific error from errno, and return NULL; return None if no error */ |
| 122 | PyObject * |
| 123 | PyErr_Mac(PyObject *eobj, int err) |
| 124 | { |
| 125 | char *msg; |
| 126 | PyObject *v; |
| 127 | |
| 128 | if (err == 0 && !PyErr_Occurred()) { |
| 129 | Py_INCREF(Py_None); |
| 130 | return Py_None; |
| 131 | } |
| 132 | if (err == -1 && PyErr_Occurred()) |
| 133 | return NULL; |
| 134 | msg = PyMac_StrError(err); |
| 135 | v = Py_BuildValue("(is)", err, msg); |
| 136 | PyErr_SetObject(eobj, v); |
| 137 | Py_DECREF(v); |
| 138 | return NULL; |
| 139 | } |
| 140 | |
| 141 | /* Call PyErr_Mac with PyMac_OSErrException */ |
| 142 | PyObject * |
| 143 | PyMac_Error(OSErr err) |
| 144 | { |
| 145 | return PyErr_Mac(PyMac_GetOSErrException(), err); |
| 146 | } |
| 147 | |
Jack Jansen | 697842f | 2001-09-10 22:00:39 +0000 | [diff] [blame] | 148 | |
Jack Jansen | 697842f | 2001-09-10 22:00:39 +0000 | [diff] [blame] | 149 | OSErr |
| 150 | PyMac_GetFullPathname(FSSpec *fss, char *path, int len) |
| 151 | { |
| 152 | FSRef fsr; |
| 153 | OSErr err; |
| 154 | |
| 155 | *path = '\0'; |
| 156 | err = FSpMakeFSRef(fss, &fsr); |
| 157 | if ( err == fnfErr ) { |
| 158 | /* FSSpecs can point to non-existing files, fsrefs can't. */ |
| 159 | FSSpec fss2; |
| 160 | int tocopy; |
| 161 | |
| 162 | err = FSMakeFSSpec(fss->vRefNum, fss->parID, "", &fss2); |
| 163 | if ( err ) return err; |
| 164 | err = FSpMakeFSRef(&fss2, &fsr); |
| 165 | if ( err ) return err; |
| 166 | err = (OSErr)FSRefMakePath(&fsr, path, len-1); |
| 167 | if ( err ) return err; |
| 168 | /* This part is not 100% safe: we append the filename part, but |
| 169 | ** I'm not sure that we don't run afoul of the various 8bit |
| 170 | ** encodings here. Will have to look this up at some point... |
| 171 | */ |
| 172 | strcat(path, "/"); |
| 173 | tocopy = fss->name[0]; |
| 174 | if ( strlen(path) + tocopy >= len ) |
| 175 | tocopy = len - strlen(path) - 1; |
| 176 | if ( tocopy > 0 ) |
| 177 | strncat(path, fss->name+1, tocopy); |
| 178 | } else { |
| 179 | if ( err ) return err; |
| 180 | err = (OSErr)FSRefMakePath(&fsr, path, len); |
| 181 | if ( err ) return err; |
| 182 | } |
| 183 | return 0; |
| 184 | } |
| 185 | |
Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 186 | |
| 187 | #ifdef WITH_NEXT_FRAMEWORK |
| 188 | /* |
| 189 | ** In a bundle, find a file "resourceName" of type "resourceType". Return the |
| 190 | ** full pathname in "resourceURLCstr". |
| 191 | */ |
| 192 | static int |
| 193 | locateResourcePy(CFStringRef resourceType, CFStringRef resourceName, char *resourceURLCStr, int length) |
| 194 | { |
| 195 | CFBundleRef mainBundle = NULL; |
| 196 | CFURLRef URL, absoluteURL; |
| 197 | CFStringRef filenameString, filepathString; |
| 198 | CFIndex size, i; |
| 199 | CFArrayRef arrayRef = NULL; |
| 200 | int success = 0; |
| 201 | |
Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 202 | CFURLPathStyle thePathStyle = kCFURLPOSIXPathStyle; |
Jack Jansen | 21ed16a | 2002-08-02 14:11:24 +0000 | [diff] [blame] | 203 | |
| 204 | /* Get a reference to our main bundle */ |
| 205 | mainBundle = CFBundleGetMainBundle(); |
| 206 | |
| 207 | /* If we are running inside a bundle, look through it. Otherwise, do nothing. */ |
| 208 | if (mainBundle) { |
| 209 | |
| 210 | /* Look for py files in the main bundle by type */ |
| 211 | arrayRef = CFBundleCopyResourceURLsOfType( mainBundle, |
| 212 | resourceType, |
| 213 | NULL ); |
| 214 | |
| 215 | /* See if there are any filename matches */ |
| 216 | size = CFArrayGetCount(arrayRef); |
| 217 | for (i = 0; i < size; i++) { |
| 218 | URL = CFArrayGetValueAtIndex(arrayRef, i); |
| 219 | filenameString = CFURLCopyLastPathComponent(URL); |
| 220 | if (CFStringCompare(filenameString, resourceName, 0) == kCFCompareEqualTo) { |
| 221 | /* We found a match, get the file's full path */ |
| 222 | absoluteURL = CFURLCopyAbsoluteURL(URL); |
| 223 | filepathString = CFURLCopyFileSystemPath(absoluteURL, thePathStyle); |
| 224 | CFRelease(absoluteURL); |
| 225 | |
| 226 | /* Copy the full path into the caller's character buffer */ |
| 227 | success = CFStringGetCString(filepathString, resourceURLCStr, length, |
| 228 | kCFStringEncodingMacRoman); |
| 229 | |
| 230 | CFRelease(filepathString); |
| 231 | } |
| 232 | CFRelease(filenameString); |
| 233 | } |
| 234 | CFRelease(arrayRef); |
| 235 | } |
| 236 | return success; |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | ** iff we are running in a .app framework then we could be |
| 241 | ** the main program for an applet. In that case, return the |
| 242 | ** script filename for the applet. |
| 243 | ** Otherwise return NULL. |
| 244 | */ |
| 245 | char * |
| 246 | PyMac_GetAppletScriptFile(void) |
| 247 | { |
| 248 | static char scriptpath[1024]; |
| 249 | |
| 250 | /* First we see whether we have __rawmain__.py and run that if it |
| 251 | ** is there. This is used for applets that want sys.argv to be |
| 252 | ** unix-like: __rawmain__ will construct it (from the initial appleevent) |
| 253 | ** and then call __main__.py. |
| 254 | */ |
| 255 | if (locateResourcePy(CFSTR("py"), CFSTR("__rawmain__.py"), scriptpath, 1024)) { |
| 256 | return scriptpath; |
| 257 | } else if (locateResourcePy(CFSTR("pyc"), CFSTR("__rawmain__.pyc"), scriptpath, 1024)) { |
| 258 | return scriptpath; |
| 259 | } else if (locateResourcePy(CFSTR("py"), CFSTR("__main__.py"), scriptpath, 1024)) { |
| 260 | return scriptpath; |
| 261 | } else if (locateResourcePy(CFSTR("pyc"), CFSTR("__main__.pyc"), scriptpath, 1024)) { |
| 262 | return scriptpath; |
| 263 | } |
| 264 | return NULL; |
| 265 | } |
| 266 | |
| 267 | #endif |
| 268 | |
| 269 | |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 270 | /* Convert a 4-char string object argument to an OSType value */ |
| 271 | int |
| 272 | PyMac_GetOSType(PyObject *v, OSType *pr) |
| 273 | { |
| 274 | if (!PyString_Check(v) || PyString_Size(v) != 4) { |
| 275 | PyErr_SetString(PyExc_TypeError, |
| 276 | "OSType arg must be string of 4 chars"); |
| 277 | return 0; |
| 278 | } |
| 279 | memcpy((char *)pr, PyString_AsString(v), 4); |
| 280 | return 1; |
| 281 | } |
| 282 | |
| 283 | /* Convert an OSType value to a 4-char string object */ |
| 284 | PyObject * |
| 285 | PyMac_BuildOSType(OSType t) |
| 286 | { |
| 287 | return PyString_FromStringAndSize((char *)&t, 4); |
| 288 | } |
| 289 | |
| 290 | /* Convert an NumVersion value to a 4-element tuple */ |
| 291 | PyObject * |
| 292 | PyMac_BuildNumVersion(NumVersion t) |
| 293 | { |
| 294 | return Py_BuildValue("(hhhh)", t.majorRev, t.minorAndBugRev, t.stage, t.nonRelRev); |
| 295 | } |
| 296 | |
| 297 | |
| 298 | /* Convert a Python string object to a Str255 */ |
| 299 | int |
| 300 | PyMac_GetStr255(PyObject *v, Str255 pbuf) |
| 301 | { |
| 302 | int len; |
| 303 | if (!PyString_Check(v) || (len = PyString_Size(v)) > 255) { |
| 304 | PyErr_SetString(PyExc_TypeError, |
| 305 | "Str255 arg must be string of at most 255 chars"); |
| 306 | return 0; |
| 307 | } |
| 308 | pbuf[0] = len; |
| 309 | memcpy((char *)(pbuf+1), PyString_AsString(v), len); |
| 310 | return 1; |
| 311 | } |
| 312 | |
| 313 | /* Convert a Str255 to a Python string object */ |
| 314 | PyObject * |
| 315 | PyMac_BuildStr255(Str255 s) |
| 316 | { |
| 317 | if ( s == NULL ) { |
| 318 | PyErr_SetString(PyExc_SystemError, "Str255 pointer is NULL"); |
| 319 | return NULL; |
| 320 | } |
| 321 | return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); |
| 322 | } |
| 323 | |
| 324 | PyObject * |
| 325 | PyMac_BuildOptStr255(Str255 s) |
| 326 | { |
| 327 | if ( s == NULL ) { |
| 328 | Py_INCREF(Py_None); |
| 329 | return Py_None; |
| 330 | } |
| 331 | return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); |
| 332 | } |
| 333 | |
| 334 | |
| 335 | |
| 336 | /* Convert a Python object to a Rect. |
| 337 | The object must be a (left, top, right, bottom) tuple. |
| 338 | (This differs from the order in the struct but is consistent with |
| 339 | the arguments to SetRect(), and also with STDWIN). */ |
| 340 | int |
| 341 | PyMac_GetRect(PyObject *v, Rect *r) |
| 342 | { |
| 343 | return PyArg_Parse(v, "(hhhh)", &r->left, &r->top, &r->right, &r->bottom); |
| 344 | } |
| 345 | |
| 346 | /* Convert a Rect to a Python object */ |
| 347 | PyObject * |
| 348 | PyMac_BuildRect(Rect *r) |
| 349 | { |
| 350 | return Py_BuildValue("(hhhh)", r->left, r->top, r->right, r->bottom); |
| 351 | } |
| 352 | |
| 353 | |
| 354 | /* Convert a Python object to a Point. |
| 355 | The object must be a (h, v) tuple. |
| 356 | (This differs from the order in the struct but is consistent with |
| 357 | the arguments to SetPoint(), and also with STDWIN). */ |
| 358 | int |
| 359 | PyMac_GetPoint(PyObject *v, Point *p) |
| 360 | { |
| 361 | return PyArg_Parse(v, "(hh)", &p->h, &p->v); |
| 362 | } |
| 363 | |
| 364 | /* Convert a Point to a Python object */ |
| 365 | PyObject * |
| 366 | PyMac_BuildPoint(Point p) |
| 367 | { |
| 368 | return Py_BuildValue("(hh)", p.h, p.v); |
| 369 | } |
| 370 | |
| 371 | |
| 372 | /* Convert a Python object to an EventRecord. |
| 373 | The object must be a (what, message, when, (v, h), modifiers) tuple. */ |
| 374 | int |
| 375 | PyMac_GetEventRecord(PyObject *v, EventRecord *e) |
| 376 | { |
Jack Jansen | 84c2b1b | 2003-04-17 20:44:21 +0000 | [diff] [blame] | 377 | return PyArg_Parse(v, "(Hkk(hh)H)", |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 378 | &e->what, |
| 379 | &e->message, |
| 380 | &e->when, |
| 381 | &e->where.h, |
| 382 | &e->where.v, |
| 383 | &e->modifiers); |
| 384 | } |
| 385 | |
| 386 | /* Convert a Rect to an EventRecord object */ |
| 387 | PyObject * |
| 388 | PyMac_BuildEventRecord(EventRecord *e) |
| 389 | { |
| 390 | return Py_BuildValue("(hll(hh)h)", |
| 391 | e->what, |
| 392 | e->message, |
| 393 | e->when, |
| 394 | e->where.h, |
| 395 | e->where.v, |
| 396 | e->modifiers); |
| 397 | } |
| 398 | |
| 399 | /* Convert Python object to Fixed */ |
| 400 | int |
| 401 | PyMac_GetFixed(PyObject *v, Fixed *f) |
| 402 | { |
| 403 | double d; |
| 404 | |
| 405 | if( !PyArg_Parse(v, "d", &d)) |
| 406 | return 0; |
| 407 | *f = (Fixed)(d * 0x10000); |
| 408 | return 1; |
| 409 | } |
| 410 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 411 | /* Convert a Fixed to a Python object */ |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 412 | PyObject * |
| 413 | PyMac_BuildFixed(Fixed f) |
| 414 | { |
| 415 | double d; |
| 416 | |
| 417 | d = f; |
| 418 | d = d / 0x10000; |
| 419 | return Py_BuildValue("d", d); |
| 420 | } |
| 421 | |
| 422 | /* Convert wide to/from Python int or (hi, lo) tuple. XXXX Should use Python longs */ |
| 423 | int |
| 424 | PyMac_Getwide(PyObject *v, wide *rv) |
| 425 | { |
| 426 | if (PyInt_Check(v)) { |
| 427 | rv->hi = 0; |
| 428 | rv->lo = PyInt_AsLong(v); |
| 429 | if( rv->lo & 0x80000000 ) |
| 430 | rv->hi = -1; |
| 431 | return 1; |
| 432 | } |
Jack Jansen | 84c2b1b | 2003-04-17 20:44:21 +0000 | [diff] [blame] | 433 | return PyArg_Parse(v, "(kk)", &rv->hi, &rv->lo); |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | |
| 437 | PyObject * |
| 438 | PyMac_Buildwide(wide *w) |
| 439 | { |
| 440 | if ( (w->hi == 0 && (w->lo & 0x80000000) == 0) || |
| 441 | (w->hi == -1 && (w->lo & 0x80000000) ) ) |
| 442 | return PyInt_FromLong(w->lo); |
| 443 | return Py_BuildValue("(ll)", w->hi, w->lo); |
| 444 | } |
| 445 | |
| 446 | #ifdef USE_TOOLBOX_OBJECT_GLUE |
| 447 | /* |
| 448 | ** Glue together the toolbox objects. |
| 449 | ** |
| 450 | ** Because toolbox modules interdepend on each other, they use each others |
| 451 | ** object types, on MacOSX/MachO this leads to the situation that they |
| 452 | ** cannot be dynamically loaded (or they would all have to be lumped into |
| 453 | ** a single .so, but this would be bad for extensibility). |
| 454 | ** |
| 455 | ** This file defines wrappers for all the _New and _Convert functions, |
| 456 | ** which are the Py_BuildValue and PyArg_ParseTuple helpers. The wrappers |
| 457 | ** check an indirection function pointer, and if it isn't filled in yet |
| 458 | ** they import the appropriate module, whose init routine should fill in |
| 459 | ** the pointer. |
| 460 | */ |
| 461 | |
| 462 | #define GLUE_NEW(object, routinename, module) \ |
| 463 | PyObject *(*PyMacGluePtr_##routinename)(object); \ |
| 464 | \ |
| 465 | PyObject *routinename(object cobj) { \ |
| 466 | if (!PyMacGluePtr_##routinename) { \ |
| 467 | if (!PyImport_ImportModule(module)) return NULL; \ |
| 468 | if (!PyMacGluePtr_##routinename) { \ |
| 469 | PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \ |
| 470 | return NULL; \ |
| 471 | } \ |
| 472 | } \ |
| 473 | return (*PyMacGluePtr_##routinename)(cobj); \ |
| 474 | } |
| 475 | |
| 476 | #define GLUE_CONVERT(object, routinename, module) \ |
| 477 | int (*PyMacGluePtr_##routinename)(PyObject *, object *); \ |
| 478 | \ |
| 479 | int routinename(PyObject *pyobj, object *cobj) { \ |
| 480 | if (!PyMacGluePtr_##routinename) { \ |
| 481 | if (!PyImport_ImportModule(module)) return NULL; \ |
| 482 | if (!PyMacGluePtr_##routinename) { \ |
| 483 | PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \ |
| 484 | return NULL; \ |
| 485 | } \ |
| 486 | } \ |
| 487 | return (*PyMacGluePtr_##routinename)(pyobj, cobj); \ |
| 488 | } |
Jack Jansen | fabd00f | 2001-09-01 23:39:58 +0000 | [diff] [blame] | 489 | |
Jack Jansen | ad5e76a | 2003-03-02 23:16:50 +0000 | [diff] [blame] | 490 | GLUE_NEW(FSSpec *, PyMac_BuildFSSpec, "Carbon.File") |
| 491 | GLUE_CONVERT(FSSpec, PyMac_GetFSSpec, "Carbon.File") |
| 492 | GLUE_NEW(FSRef *, PyMac_BuildFSRef, "Carbon.File") |
| 493 | GLUE_CONVERT(FSRef, PyMac_GetFSRef, "Carbon.File") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 494 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 495 | GLUE_NEW(AppleEvent *, AEDesc_New, "Carbon.AE") /* XXXX Why by address? */ |
Jack Jansen | b2a5772 | 2003-01-17 23:11:17 +0000 | [diff] [blame] | 496 | GLUE_NEW(AppleEvent *, AEDesc_NewBorrowed, "Carbon.AE") |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 497 | GLUE_CONVERT(AppleEvent, AEDesc_Convert, "Carbon.AE") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 498 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 499 | GLUE_NEW(Component, CmpObj_New, "Carbon.Cm") |
| 500 | GLUE_CONVERT(Component, CmpObj_Convert, "Carbon.Cm") |
| 501 | GLUE_NEW(ComponentInstance, CmpInstObj_New, "Carbon.Cm") |
| 502 | GLUE_CONVERT(ComponentInstance, CmpInstObj_Convert, "Carbon.Cm") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 503 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 504 | GLUE_NEW(ControlHandle, CtlObj_New, "Carbon.Ctl") |
| 505 | GLUE_CONVERT(ControlHandle, CtlObj_Convert, "Carbon.Ctl") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 506 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 507 | GLUE_NEW(DialogPtr, DlgObj_New, "Carbon.Dlg") |
| 508 | GLUE_CONVERT(DialogPtr, DlgObj_Convert, "Carbon.Dlg") |
| 509 | GLUE_NEW(DialogPtr, DlgObj_WhichDialog, "Carbon.Dlg") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 510 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 511 | GLUE_NEW(DragReference, DragObj_New, "Carbon.Drag") |
| 512 | GLUE_CONVERT(DragReference, DragObj_Convert, "Carbon.Drag") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 513 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 514 | GLUE_NEW(ListHandle, ListObj_New, "Carbon.List") |
| 515 | GLUE_CONVERT(ListHandle, ListObj_Convert, "Carbon.List") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 516 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 517 | GLUE_NEW(MenuHandle, MenuObj_New, "Carbon.Menu") |
| 518 | GLUE_CONVERT(MenuHandle, MenuObj_Convert, "Carbon.Menu") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 519 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 520 | GLUE_NEW(GrafPtr, GrafObj_New, "Carbon.Qd") |
| 521 | GLUE_CONVERT(GrafPtr, GrafObj_Convert, "Carbon.Qd") |
| 522 | GLUE_NEW(BitMapPtr, BMObj_New, "Carbon.Qd") |
| 523 | GLUE_CONVERT(BitMapPtr, BMObj_Convert, "Carbon.Qd") |
| 524 | GLUE_NEW(RGBColor *, QdRGB_New, "Carbon.Qd") /* XXXX Why? */ |
| 525 | GLUE_CONVERT(RGBColor, QdRGB_Convert, "Carbon.Qd") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 526 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 527 | GLUE_NEW(GWorldPtr, GWorldObj_New, "Carbon.Qdoffs") |
| 528 | GLUE_CONVERT(GWorldPtr, GWorldObj_Convert, "Carbon.Qdoffs") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 529 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 530 | GLUE_NEW(Track, TrackObj_New, "Carbon.Qt") |
| 531 | GLUE_CONVERT(Track, TrackObj_Convert, "Carbon.Qt") |
| 532 | GLUE_NEW(Movie, MovieObj_New, "Carbon.Qt") |
| 533 | GLUE_CONVERT(Movie, MovieObj_Convert, "Carbon.Qt") |
| 534 | GLUE_NEW(MovieController, MovieCtlObj_New, "Carbon.Qt") |
| 535 | GLUE_CONVERT(MovieController, MovieCtlObj_Convert, "Carbon.Qt") |
| 536 | GLUE_NEW(TimeBase, TimeBaseObj_New, "Carbon.Qt") |
| 537 | GLUE_CONVERT(TimeBase, TimeBaseObj_Convert, "Carbon.Qt") |
| 538 | GLUE_NEW(UserData, UserDataObj_New, "Carbon.Qt") |
| 539 | GLUE_CONVERT(UserData, UserDataObj_Convert, "Carbon.Qt") |
| 540 | GLUE_NEW(Media, MediaObj_New, "Carbon.Qt") |
| 541 | GLUE_CONVERT(Media, MediaObj_Convert, "Carbon.Qt") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 542 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 543 | GLUE_NEW(Handle, ResObj_New, "Carbon.Res") |
| 544 | GLUE_CONVERT(Handle, ResObj_Convert, "Carbon.Res") |
| 545 | GLUE_NEW(Handle, OptResObj_New, "Carbon.Res") |
| 546 | GLUE_CONVERT(Handle, OptResObj_Convert, "Carbon.Res") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 547 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 548 | GLUE_NEW(TEHandle, TEObj_New, "Carbon.TE") |
| 549 | GLUE_CONVERT(TEHandle, TEObj_Convert, "Carbon.TE") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 550 | |
Jack Jansen | 06bd323 | 2001-08-27 14:01:05 +0000 | [diff] [blame] | 551 | GLUE_NEW(WindowPtr, WinObj_New, "Carbon.Win") |
| 552 | GLUE_CONVERT(WindowPtr, WinObj_Convert, "Carbon.Win") |
| 553 | GLUE_NEW(WindowPtr, WinObj_WhichWindow, "Carbon.Win") |
Jack Jansen | 94bebc0 | 2001-08-08 13:17:31 +0000 | [diff] [blame] | 554 | |
Jack Jansen | 4eb45e7 | 2003-05-27 21:39:58 +0000 | [diff] [blame] | 555 | GLUE_CONVERT(CFTypeRef, CFObj_Convert, "Carbon.CF") |
| 556 | GLUE_NEW(CFTypeRef, CFObj_New, "Carbon.CF") |
| 557 | |
Jack Jansen | 537a69f | 2001-11-05 14:39:22 +0000 | [diff] [blame] | 558 | GLUE_CONVERT(CFTypeRef, CFTypeRefObj_Convert, "Carbon.CF") |
| 559 | GLUE_NEW(CFTypeRef, CFTypeRefObj_New, "Carbon.CF") |
| 560 | |
| 561 | GLUE_CONVERT(CFStringRef, CFStringRefObj_Convert, "Carbon.CF") |
| 562 | GLUE_NEW(CFStringRef, CFStringRefObj_New, "Carbon.CF") |
| 563 | GLUE_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert, "Carbon.CF") |
| 564 | GLUE_NEW(CFMutableStringRef, CFMutableStringRefObj_New, "Carbon.CF") |
| 565 | |
| 566 | GLUE_CONVERT(CFArrayRef, CFArrayRefObj_Convert, "Carbon.CF") |
| 567 | GLUE_NEW(CFArrayRef, CFArrayRefObj_New, "Carbon.CF") |
| 568 | GLUE_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert, "Carbon.CF") |
| 569 | GLUE_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New, "Carbon.CF") |
| 570 | |
| 571 | GLUE_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert, "Carbon.CF") |
| 572 | GLUE_NEW(CFDictionaryRef, CFDictionaryRefObj_New, "Carbon.CF") |
| 573 | GLUE_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert, "Carbon.CF") |
| 574 | GLUE_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New, "Carbon.CF") |
| 575 | |
| 576 | GLUE_CONVERT(CFURLRef, CFURLRefObj_Convert, "Carbon.CF") |
| 577 | GLUE_CONVERT(CFURLRef, OptionalCFURLRefObj_Convert, "Carbon.CF") |
| 578 | GLUE_NEW(CFURLRef, CFURLRefObj_New, "Carbon.CF") |
| 579 | |
Michael W. Hudson | 5f26dda | 2002-11-09 14:47:18 +0000 | [diff] [blame] | 580 | #endif /* USE_TOOLBOX_OBJECT_GLUE */ |