1 /* DSR:2005.10.26.16.28: 2 // Ellery Newcomer is going to make this THE python header for 2.4 thru 2.7. 3 // yuck. 4 5 XXX: 6 7 - In a build process controlled by Python distutils, need to detect whether the 8 Python interpreter was built in debug build mode, and if so, make the 9 appropriate adjustments to the header mixins. 10 11 */ 12 13 /** 14 Contains all relevant definitions from python/Include 15 16 When issue 7758 is resolved, we will have this module split into 17 separate files to match python/Include (and all defs will show up in ddoc) 18 */ 19 module python; 20 21 // here's what we like 22 version(Python_2_7_Or_Later){ 23 }else version(Python_2_6_Or_Later){ 24 }else version(Python_2_5_Or_Later){ 25 }else version(Python_2_4_Or_Later){ 26 }else{ 27 static assert(false,"Python version not specified!"); 28 } 29 /+ 30 version (build) { 31 version (DigitalMars) { 32 version (Windows) { 33 pragma(link, "python25_digitalmars"); 34 } 35 } else { 36 pragma(link, "python2.5"); 37 } 38 } 39 40 version (Tango) { 41 import tango.stdc.stdio; 42 import tango.stdc.time; 43 import tango.stdc.string; 44 } else {+/ 45 import std.c.stdio; 46 import std.c.time; 47 import std.c.string; 48 import std.string: toStringz; 49 //} 50 51 52 /* D long is always 64 bits, but when the Python/C API mentions long, it is of 53 * course referring to the C type long, the size of which is 32 bits on both 54 * X86 and X86_64 under Windows, but 32 bits on X86 and 64 bits on X86_64 under 55 * most other operating systems. */ 56 57 alias long C_longlong; 58 alias ulong C_ulonglong; 59 60 version(Windows) { 61 alias int C_long; 62 alias uint C_ulong; 63 } else { 64 version (X86) { 65 alias int C_long; 66 alias uint C_ulong; 67 } else { 68 alias long C_long; 69 alias ulong C_ulong; 70 } 71 } 72 73 74 /* 75 * Py_ssize_t is defined as a signed type which is 8 bytes on X86_64 and 4 76 * bytes on X86. 77 */ 78 version(Python_2_5_Or_Later){ 79 version (X86_64) { 80 alias long Py_ssize_t; 81 } else { 82 alias int Py_ssize_t; 83 } 84 }else { 85 /* 86 * Seems Py_ssize_t didn't exist in 2.4, and int was everywhere it is now. 87 */ 88 alias int Py_ssize_t; 89 } 90 91 extern (C) { 92 /////////////////////////////////////////////////////////////////////////////// 93 // PYTHON DATA STRUCTURES AND ALIASES 94 /////////////////////////////////////////////////////////////////////////////// 95 // Python-header-file: Include/Python.h: 96 enum int Py_single_input = 256; 97 enum int Py_file_input = 257; 98 enum int Py_eval_input = 258; 99 100 // Python-header-file: Include/object.h: 101 102 // XXX:Conditionalize in if running debug build of Python interpreter: 103 /* 104 version (Python_Debug_Build) { 105 template _PyObject_HEAD_EXTRA() { 106 PyObject *_ob_next; 107 PyObject *_ob_prev; 108 } 109 } else { 110 */ 111 template _PyObject_HEAD_EXTRA() {} 112 /*}*/ 113 114 template PyObject_HEAD() { 115 mixin _PyObject_HEAD_EXTRA; 116 Py_ssize_t ob_refcnt; 117 PyTypeObject *ob_type; 118 } 119 120 struct PyObject { 121 mixin PyObject_HEAD; 122 } 123 124 /+-++ Not part of Python api!!! ++++/ 125 /** 126 Denotes a borrowed reference. 127 128 Intended use: An api function Foo returning a borrowed reference will 129 have return type Borrowed!PyObject* instead of PyObject*. Py_INCREF can 130 be used to get the original type back. 131 132 Params: 133 T = Python object type (PyObject, PyTypeObject, etc) 134 135 Example: 136 --- 137 Borrowed!PyObject* borrowed = PyTuple_GetItem(tuple, 0); 138 PyObject* item = Py_XINCREF(borrowed); 139 --- 140 */ 141 struct Borrowed(T) { 142 } 143 144 /** 145 Convert a python reference to borrowed reference. 146 */ 147 Borrowed!T* borrowed(T)(T* obj) { 148 return cast(Borrowed!T*) obj; 149 } 150 alias Borrowed!PyObject PyObject_BorrowedRef; 151 152 /+-++ End Not part of Python api!!! ++++/ 153 154 template PyObject_VAR_HEAD() { 155 mixin PyObject_HEAD; 156 Py_ssize_t ob_size; /* Number of items in variable part */ 157 } 158 159 struct PyVarObject { 160 mixin PyObject_VAR_HEAD; 161 } 162 163 version(Python_2_6_Or_Later){ 164 auto Py_REFCNT()(PyObject* ob){ return ob.ob_refcnt; } 165 auto Py_TYPE()(PyObject* ob){ return ob.ob_type; } 166 auto Py_SIZE()(PyVarObject* ob){ return ob.ob_size; } 167 } 168 169 alias PyObject* function(PyObject *) unaryfunc; 170 alias PyObject* function(PyObject *, PyObject *) binaryfunc; 171 alias PyObject* function(PyObject *, PyObject *, PyObject *) ternaryfunc; 172 alias Py_ssize_t function(PyObject *) lenfunc; 173 alias lenfunc inquiry; 174 alias int function(PyObject **, PyObject **) coercion; 175 alias PyObject* function(PyObject *, Py_ssize_t) ssizeargfunc; 176 alias PyObject* function(PyObject *, Py_ssize_t, Py_ssize_t) ssizessizeargfunc; 177 version(Python_2_5_Or_Later){ 178 }else{ 179 alias ssizeargfunc intargfunc; 180 alias ssizessizeargfunc intintargfunc; 181 } 182 alias int function(PyObject *, Py_ssize_t, PyObject *) ssizeobjargproc; 183 alias int function(PyObject *, Py_ssize_t, Py_ssize_t, PyObject *) ssizessizeobjargproc; 184 version(Python_2_5_Or_Later){ 185 }else{ 186 alias ssizeobjargproc intobjargproc; 187 alias ssizessizeobjargproc intintobjargproc; 188 } 189 alias int function(PyObject *, PyObject *, PyObject *) objobjargproc; 190 191 // ssize_t-based buffer interface 192 alias Py_ssize_t function(PyObject *, Py_ssize_t, void **) readbufferproc; 193 alias Py_ssize_t function(PyObject *, Py_ssize_t, void **) writebufferproc; 194 alias Py_ssize_t function(PyObject *, Py_ssize_t *) segcountproc; 195 alias Py_ssize_t function(PyObject *, Py_ssize_t, char **) charbufferproc; 196 version(Python_2_5_Or_Later){ 197 }else{ 198 // int-based buffer interface 199 alias readbufferproc getreadbufferproc; 200 alias writebufferproc getwritebufferproc; 201 alias segcountproc getsegcountproc; 202 alias charbufferproc getcharbufferproc; 203 } 204 205 version(Python_2_6_Or_Later){ 206 /* Py3k buffer interface */ 207 208 struct Py_buffer{ 209 void *buf; 210 Borrowed!PyObject *obj; /* borrowed reference */ 211 Py_ssize_t len; 212 Py_ssize_t itemsize; /* This is Py_ssize_t so it can be 213 pointed to by strides in simple case.*/ 214 int readonly; 215 int ndim; 216 char *format; 217 Py_ssize_t *shape; 218 Py_ssize_t *strides; 219 Py_ssize_t *suboffsets; 220 version(Python_2_7_Or_Later) { 221 Py_ssize_t[2] smalltable; 222 } 223 void *internal; 224 }; 225 226 alias int function(PyObject *, Py_buffer *, int) getbufferproc; 227 alias void function(PyObject *, Py_buffer *) releasebufferproc; 228 229 /* Flags for getting buffers */ 230 enum PyBUF_SIMPLE = 0; 231 enum PyBUF_WRITABLE = 0x0001; 232 /* we used to include an E, backwards compatible alias */ 233 enum PyBUF_WRITEABLE = PyBUF_WRITABLE; 234 enum PyBUF_FORMAT = 0x0004; 235 enum PyBUF_ND = 0x0008; 236 enum PyBUF_STRIDES = (0x0010 | PyBUF_ND); 237 enum PyBUF_C_CONTIGUOUS = (0x0020 | PyBUF_STRIDES); 238 enum PyBUF_F_CONTIGUOUS = (0x0040 | PyBUF_STRIDES); 239 enum PyBUF_ANY_CONTIGUOUS = (0x0080 | PyBUF_STRIDES); 240 enum PyBUF_INDIRECT = (0x0100 | PyBUF_STRIDES); 241 242 enum PyBUF_CONTIG = (PyBUF_ND | PyBUF_WRITABLE); 243 enum PyBUF_CONTIG_RO = (PyBUF_ND); 244 245 enum PyBUF_STRIDED = (PyBUF_STRIDES | PyBUF_WRITABLE); 246 enum PyBUF_STRIDED_RO = (PyBUF_STRIDES); 247 248 enum PyBUF_RECORDS = (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT); 249 enum PyBUF_RECORDS_RO = (PyBUF_STRIDES | PyBUF_FORMAT); 250 251 enum PyBUF_FULL = (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT); 252 enum PyBUF_FULL_RO = (PyBUF_INDIRECT | PyBUF_FORMAT); 253 254 255 enum PyBUF_READ = 0x100; 256 enum PyBUF_WRITE = 0x200; 257 enum PyBUF_SHADOW = 0x400; 258 /* end Py3k buffer interface */ 259 } 260 261 alias int function(PyObject *, PyObject *) objobjproc; 262 alias int function(PyObject *, void *) visitproc; 263 alias int function(PyObject *, visitproc, void *) traverseproc; 264 265 // Python-header-file: Include/object.h: 266 struct PyNumberMethods { 267 binaryfunc nb_add; 268 binaryfunc nb_subtract; 269 binaryfunc nb_multiply; 270 binaryfunc nb_divide; 271 binaryfunc nb_remainder; 272 binaryfunc nb_divmod; 273 ternaryfunc nb_power; 274 unaryfunc nb_negative; 275 unaryfunc nb_positive; 276 unaryfunc nb_absolute; 277 inquiry nb_nonzero; 278 unaryfunc nb_invert; 279 binaryfunc nb_lshift; 280 binaryfunc nb_rshift; 281 binaryfunc nb_and; 282 binaryfunc nb_xor; 283 binaryfunc nb_or; 284 coercion nb_coerce; 285 unaryfunc nb_int; 286 unaryfunc nb_long; 287 unaryfunc nb_float; 288 unaryfunc nb_oct; 289 unaryfunc nb_hex; 290 291 binaryfunc nb_inplace_add; 292 binaryfunc nb_inplace_subtract; 293 binaryfunc nb_inplace_multiply; 294 binaryfunc nb_inplace_divide; 295 binaryfunc nb_inplace_remainder; 296 ternaryfunc nb_inplace_power; 297 binaryfunc nb_inplace_lshift; 298 binaryfunc nb_inplace_rshift; 299 binaryfunc nb_inplace_and; 300 binaryfunc nb_inplace_xor; 301 binaryfunc nb_inplace_or; 302 303 binaryfunc nb_floor_divide; 304 binaryfunc nb_true_divide; 305 binaryfunc nb_inplace_floor_divide; 306 binaryfunc nb_inplace_true_divide; 307 308 version(Python_2_5_Or_Later){ 309 /* Added in release 2.5 */ 310 unaryfunc nb_index; 311 } 312 } 313 314 struct PySequenceMethods { 315 lenfunc sq_length; 316 binaryfunc sq_concat; 317 ssizeargfunc sq_repeat; 318 ssizeargfunc sq_item; 319 ssizessizeargfunc sq_slice; 320 ssizeobjargproc sq_ass_item; 321 ssizessizeobjargproc sq_ass_slice; 322 objobjproc sq_contains; 323 binaryfunc sq_inplace_concat; 324 ssizeargfunc sq_inplace_repeat; 325 } 326 327 struct PyMappingMethods { 328 lenfunc mp_length; 329 binaryfunc mp_subscript; 330 objobjargproc mp_ass_subscript; 331 } 332 333 struct PyBufferProcs { 334 readbufferproc bf_getreadbuffer; 335 writebufferproc bf_getwritebuffer; 336 segcountproc bf_getsegcount; 337 charbufferproc bf_getcharbuffer; 338 version(Python_2_6_Or_Later){ 339 getbufferproc bf_getbuffer; 340 releasebufferproc bf_releasebuffer; 341 } 342 } 343 344 345 alias void function(void *) freefunc; 346 alias void function(PyObject *) destructor; 347 alias int function(PyObject *, FILE *, int) printfunc; 348 alias PyObject* function(PyObject *, char *) getattrfunc; 349 alias PyObject* function(PyObject *, PyObject *) getattrofunc; 350 alias int function(PyObject *, char *, PyObject *) setattrfunc; 351 alias int function(PyObject *, PyObject *, PyObject *) setattrofunc; 352 alias int function(PyObject *, PyObject *) cmpfunc; 353 alias PyObject* function(PyObject *) reprfunc; 354 alias C_long function(PyObject *) hashfunc; 355 alias PyObject* function(PyObject *, PyObject *, int) richcmpfunc; 356 alias PyObject* function(PyObject *) getiterfunc; 357 alias PyObject* function(PyObject *) iternextfunc; 358 alias PyObject* function(PyObject *, PyObject *, PyObject *) descrgetfunc; 359 alias int function(PyObject *, PyObject *, PyObject *) descrsetfunc; 360 alias int function(PyObject *, PyObject *, PyObject *) initproc; 361 alias PyObject* function(PyTypeObject *, PyObject *, PyObject *) newfunc; 362 alias PyObject* function(PyTypeObject *, Py_ssize_t) allocfunc; 363 364 struct PyTypeObject { 365 mixin PyObject_VAR_HEAD; 366 367 Char1 *tp_name; 368 Py_ssize_t tp_basicsize, tp_itemsize; 369 370 destructor tp_dealloc; 371 printfunc tp_print; 372 getattrfunc tp_getattr; 373 setattrfunc tp_setattr; 374 cmpfunc tp_compare; 375 reprfunc tp_repr; 376 377 PyNumberMethods *tp_as_number; 378 PySequenceMethods *tp_as_sequence; 379 PyMappingMethods *tp_as_mapping; 380 381 hashfunc tp_hash; 382 ternaryfunc tp_call; 383 reprfunc tp_str; 384 getattrofunc tp_getattro; 385 setattrofunc tp_setattro; 386 387 PyBufferProcs *tp_as_buffer; 388 389 C_long tp_flags; 390 391 Char1 *tp_doc; 392 393 traverseproc tp_traverse; 394 395 inquiry tp_clear; 396 397 richcmpfunc tp_richcompare; 398 399 version(Python_2_5_Or_Later){ 400 Py_ssize_t tp_weaklistoffset; 401 }else{ 402 C_long tp_weaklistoffset; 403 } 404 405 getiterfunc tp_iter; 406 iternextfunc tp_iternext; 407 408 PyMethodDef *tp_methods; 409 PyMemberDef *tp_members; 410 PyGetSetDef *tp_getset; 411 PyTypeObject *tp_base; 412 PyObject *tp_dict; 413 descrgetfunc tp_descr_get; 414 descrsetfunc tp_descr_set; 415 version(Python_2_5_Or_Later){ 416 Py_ssize_t tp_dictoffset; 417 }else{ 418 C_long tp_dictoffset; 419 } 420 initproc tp_init; 421 allocfunc tp_alloc; 422 newfunc tp_new; 423 freefunc tp_free; 424 inquiry tp_is_gc; 425 PyObject *tp_bases; 426 PyObject *tp_mro; 427 PyObject *tp_cache; 428 PyObject *tp_subclasses; 429 PyObject *tp_weaklist; 430 destructor tp_del; 431 version(Python_2_6_Or_Later){ 432 /* Type attribute cache version tag. Added in version 2.6 */ 433 uint tp_version_tag; 434 } 435 } 436 437 //alias _typeobject PyTypeObject; 438 439 struct _heaptypeobject { 440 version(Python_2_5_Or_Later){ 441 PyTypeObject ht_type; 442 }else{ 443 PyTypeObject type; 444 } 445 PyNumberMethods as_number; 446 PyMappingMethods as_mapping; 447 PySequenceMethods as_sequence; 448 PyBufferProcs as_buffer; 449 version(Python_2_5_Or_Later){ 450 PyObject *ht_name; 451 PyObject *ht_slots; 452 }else{ 453 PyObject *name; 454 PyObject *slots; 455 } 456 } 457 alias _heaptypeobject PyHeapTypeObject; 458 459 460 // Python-header-file: Include/pymem.h: 461 void * PyMem_Malloc(size_t); 462 void * PyMem_Realloc(void *, size_t); 463 void PyMem_Free(void *); 464 465 466 /////////////////////////////////////////////////////////////////////////////// 467 // GENERIC TYPE CHECKING 468 /////////////////////////////////////////////////////////////////////////////// 469 470 int PyType_IsSubtype(PyTypeObject *, PyTypeObject *); 471 472 // D translation of C macro: 473 int PyObject_TypeCheck()(PyObject *ob, PyTypeObject *tp) { 474 return (ob.ob_type == tp || PyType_IsSubtype(ob.ob_type, tp)); 475 } 476 477 /* Note that this Python support module makes pointers to PyType_Type and 478 * other global variables exposed by the Python API available to D 479 * programmers indirectly (see this module's static initializer). */ 480 481 // D translation of C macro: 482 int PyType_Check()(PyObject *op) { 483 return PyObject_TypeCheck(op, PyType_Type_p); 484 } 485 // D translation of C macro: 486 int PyType_CheckExact()(PyObject *op) { 487 return op.ob_type == PyType_Type_p; 488 } 489 490 int PyType_Ready(PyTypeObject *); 491 PyObject * PyType_GenericAlloc(PyTypeObject *, Py_ssize_t); 492 PyObject * PyType_GenericNew(PyTypeObject *, PyObject *, PyObject *); 493 version(Python_2_6_Or_Later){ 494 uint PyType_ClearCache(); 495 void PyType_Modified(PyTypeObject *); 496 } 497 498 499 int PyObject_Print(PyObject *, FILE *, int); 500 PyObject * PyObject_Repr(PyObject *); 501 PyObject * PyObject_Str(PyObject *); 502 503 version(Python_2_6_Or_Later){ 504 alias PyObject_Str PyObject_Bytes; 505 } 506 507 PyObject * PyObject_Unicode(PyObject *); 508 509 int PyObject_Compare(PyObject *, PyObject *); 510 PyObject * PyObject_RichCompare(PyObject *, PyObject *, int); 511 int PyObject_RichCompareBool(PyObject *, PyObject *, int); 512 PyObject * PyObject_GetAttrString(PyObject *, Char1 *); 513 int PyObject_SetAttrString(PyObject *, Char1 *, PyObject *); 514 int PyObject_HasAttrString(PyObject *, Char1 *); 515 PyObject * PyObject_GetAttr(PyObject *, PyObject *); 516 int PyObject_SetAttr(PyObject *, PyObject *, PyObject *); 517 int PyObject_HasAttr(PyObject *, PyObject *); 518 PyObject * PyObject_SelfIter(PyObject *); 519 PyObject * PyObject_GenericGetAttr(PyObject *, PyObject *); 520 int PyObject_GenericSetAttr(PyObject *, 521 PyObject *, PyObject *); 522 C_long PyObject_Hash(PyObject *); 523 version(Python_2_6_Or_Later){ 524 C_long PyObject_HashNotImplemented(PyObject *); 525 } 526 int PyObject_IsTrue(PyObject *); 527 int PyObject_Not(PyObject *); 528 //int PyCallable_Check(PyObject *); 529 int PyNumber_Coerce(PyObject **, PyObject **); 530 int PyNumber_CoerceEx(PyObject **, PyObject **); 531 532 void PyObject_ClearWeakRefs(PyObject *); 533 534 PyObject * PyObject_Dir(PyObject *); 535 536 int Py_ReprEnter(PyObject *); 537 void Py_ReprLeave(PyObject *); 538 539 enum int Py_PRINT_RAW = 1; 540 541 542 enum int Py_TPFLAGS_HAVE_GETCHARBUFFER = 1L<<0; 543 enum int Py_TPFLAGS_HAVE_SEQUENCE_IN = 1L<<1; 544 enum int Py_TPFLAGS_GC = 0; 545 enum int Py_TPFLAGS_HAVE_INPLACEOPS = 1L<<3; 546 enum int Py_TPFLAGS_CHECKTYPES = 1L<<4; 547 enum int Py_TPFLAGS_HAVE_RICHCOMPARE = 1L<<5; 548 enum int Py_TPFLAGS_HAVE_WEAKREFS = 1L<<6; 549 enum int Py_TPFLAGS_HAVE_ITER = 1L<<7; 550 enum int Py_TPFLAGS_HAVE_CLASS = 1L<<8; 551 enum int Py_TPFLAGS_HEAPTYPE = 1L<<9; 552 enum int Py_TPFLAGS_BASETYPE = 1L<<10; 553 enum int Py_TPFLAGS_READY = 1L<<12; 554 enum int Py_TPFLAGS_READYING = 1L<<13; 555 enum int Py_TPFLAGS_HAVE_GC = 1L<<14; 556 557 // YYY: Should conditionalize for stackless: 558 //#ifdef STACKLESS 559 //#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION (3L<<15) 560 //#else 561 enum int Py_TPFLAGS_HAVE_STACKLESS_EXTENSION = 0; 562 //#endif 563 version(Python_2_5_Or_Later){ 564 enum Py_TPFLAGS_HAVE_INDEX = 1L<<17; 565 } 566 version(Python_2_6_Or_Later){ 567 /* Objects support type attribute cache */ 568 enum Py_TPFLAGS_HAVE_VERSION_TAG = (1L<<18); 569 enum Py_TPFLAGS_VALID_VERSION_TAG = (1L<<19); 570 571 /* Type is abstract and cannot be instantiated */ 572 enum Py_TPFLAGS_IS_ABSTRACT = (1L<<20); 573 574 /* Has the new buffer protocol */ 575 enum Py_TPFLAGS_HAVE_NEWBUFFER = (1L<<21); 576 577 /* These flags are used to determine if a type is a subclass. */ 578 enum Py_TPFLAGS_INT_SUBCLASS =(1L<<23); 579 enum Py_TPFLAGS_LONG_SUBCLASS =(1L<<24); 580 enum Py_TPFLAGS_LIST_SUBCLASS =(1L<<25); 581 enum Py_TPFLAGS_TUPLE_SUBCLASS =(1L<<26); 582 enum Py_TPFLAGS_STRING_SUBCLASS =(1L<<27); 583 enum Py_TPFLAGS_UNICODE_SUBCLASS =(1L<<28); 584 enum Py_TPFLAGS_DICT_SUBCLASS =(1L<<29); 585 enum Py_TPFLAGS_BASE_EXC_SUBCLASS =(1L<<30); 586 enum Py_TPFLAGS_TYPE_SUBCLASS =(1L<<31); 587 } 588 589 version(Python_2_5_Or_Later){ 590 enum int Py_TPFLAGS_DEFAULT = 591 Py_TPFLAGS_HAVE_GETCHARBUFFER | 592 Py_TPFLAGS_HAVE_SEQUENCE_IN | 593 Py_TPFLAGS_HAVE_INPLACEOPS | 594 Py_TPFLAGS_HAVE_RICHCOMPARE | 595 Py_TPFLAGS_HAVE_WEAKREFS | 596 Py_TPFLAGS_HAVE_ITER | 597 Py_TPFLAGS_HAVE_CLASS | 598 Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | 599 Py_TPFLAGS_HAVE_INDEX | 600 0 601 ; 602 version(Python_2_6_Or_Later){ 603 // meh 604 enum Py_TPFLAGS_DEFAULT_EXTERNAL = Py_TPFLAGS_DEFAULT; 605 } 606 }else{ 607 enum int Py_TPFLAGS_DEFAULT = 608 Py_TPFLAGS_HAVE_GETCHARBUFFER | 609 Py_TPFLAGS_HAVE_SEQUENCE_IN | 610 Py_TPFLAGS_HAVE_INPLACEOPS | 611 Py_TPFLAGS_HAVE_RICHCOMPARE | 612 Py_TPFLAGS_HAVE_WEAKREFS | 613 Py_TPFLAGS_HAVE_ITER | 614 Py_TPFLAGS_HAVE_CLASS | 615 Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | 616 0 617 ; 618 } 619 620 // D translation of C macro: 621 int PyType_HasFeature()(PyTypeObject *t, int f) { 622 return (t.tp_flags & f) != 0; 623 } 624 625 version(Python_2_6_Or_Later){ 626 alias PyType_HasFeature PyType_FastSubclass; 627 } 628 629 630 /////////////////////////////////////////////////////////////////////////////// 631 // REFERENCE COUNTING 632 /////////////////////////////////////////////////////////////////////////////// 633 // Python-header-file: Include/object.h: 634 635 auto Py_INCREF(T)(T op) 636 if(is(T == PyObject*) || is(T _unused : Borrowed!P*, P)) 637 { 638 static if(is(T _unused : Borrowed!P*, P)) { 639 PyObject* pop = cast(PyObject*) op; 640 ++pop.ob_refcnt; 641 return cast(P*) pop; 642 }else { 643 ++op.ob_refcnt; 644 } 645 } 646 647 auto Py_XINCREF(T)(T op) { 648 if (op == null) { 649 static if(is(typeof(Py_INCREF!T(op)) == void)) 650 return; 651 else { 652 import std.exception; 653 enforce(0, "INCREF on null"); 654 } 655 } 656 return Py_INCREF(op); 657 } 658 659 void Py_DECREF()(PyObject *op) { 660 // version(PY_REF_DEBUG) _Py_RefTotal++ 661 --op.ob_refcnt; 662 663 // EMN: this is a horrible idea because it takes forever to figure out 664 // what's going on if this is being called from within the garbage 665 // collector. 666 assert (op.ob_refcnt >= 0); 667 if(op.ob_refcnt != 0) { 668 // version(PY_REF_DEBUG) _Py_NegativeRefcount(__FILE__, __LINE__, cast(PyObject*)op); 669 }else { 670 op.ob_type.tp_dealloc(op); 671 } 672 } 673 674 void Py_XDECREF()(PyObject* op) 675 { 676 if(op == null) { 677 return; 678 } 679 680 Py_DECREF(op); 681 } 682 683 void Py_IncRef(PyObject *); 684 void Py_DecRef(PyObject *); 685 686 /* Rich comparison opcodes */ 687 enum int Py_LT = 0; 688 enum int Py_LE = 1; 689 enum int Py_EQ = 2; 690 enum int Py_NE = 3; 691 enum int Py_GT = 4; 692 enum int Py_GE = 5; 693 694 695 /////////////////////////////////////////////////////////////////////////////////////////////// 696 // UNICODE 697 /////////////////////////////////////////////////////////////////////////////////////////////// 698 // Python-header-file: Include/unicodeobject.h: 699 import std.c.stdarg: va_list; 700 /* The Python header explains: 701 * Unicode API names are mangled to assure that UCS-2 and UCS-4 builds 702 * produce different external names and thus cause import errors in 703 * case Python interpreters and extensions with mixed compiled in 704 * Unicode width assumptions are combined. */ 705 706 707 version (Python_Unicode_UCS2) { 708 version (Windows) { 709 alias wchar Py_UNICODE; 710 } else { 711 alias ushort Py_UNICODE; 712 } 713 } else { 714 alias uint Py_UNICODE; 715 } 716 717 struct PyUnicodeObject { 718 mixin PyObject_HEAD; 719 720 Py_ssize_t length; 721 Py_UNICODE *str; 722 C_long hash; 723 PyObject *defenc; 724 } 725 726 // &PyUnicode_Type is accessible via PyUnicode_Type_p. 727 // D translations of C macros: 728 int PyUnicode_Check()(PyObject *op) { 729 return PyObject_TypeCheck(op, PyUnicode_Type_p); 730 } 731 int PyUnicode_CheckExact()(PyObject *op) { 732 return op.ob_type == PyUnicode_Type_p; 733 } 734 735 size_t PyUnicode_GET_SIZE()(PyUnicodeObject *op) { 736 return op.length; 737 } 738 size_t PyUnicode_GET_DATA_SIZE()(PyUnicodeObject *op) { 739 return op.length * Py_UNICODE.sizeof; 740 } 741 Py_UNICODE *PyUnicode_AS_UNICODE()(PyUnicodeObject *op) { 742 return op.str; 743 } 744 const(char) *PyUnicode_AS_DATA()(PyUnicodeObject *op) { 745 return cast(const(char)*) op.str; 746 } 747 748 Py_UNICODE Py_UNICODE_REPLACEMENT_CHARACTER = 0xFFFD; 749 750 version(Python_Unicode_UCS2) { 751 enum PyUnicode_ = "PyUnicodeUCS2_"; 752 }else{ 753 enum PyUnicode_ = "PyUnicodeUCS4_"; 754 } 755 756 /* 757 this function takes defs PyUnicode_XX and transforms them to 758 PyUnicodeUCS4_XX(); 759 alias PyUnicodeUCS4_XX PyUnicode_XX; 760 761 */ 762 string substitute_and_alias()(string code) { 763 import std.algorithm; 764 import std.array; 765 string[] newcodes; 766 LOOP: 767 while(true) { 768 if(startsWith(code,"/*")) { 769 size_t comm_end_index = countUntil(code[2 .. $], "*/"); 770 if(comm_end_index == -1) break; 771 newcodes ~= code[0 .. comm_end_index]; 772 code = code[comm_end_index .. $]; 773 continue; 774 } 775 if(!(startsWith(code,"PyUnicode_") || startsWith(code,"_PyUnicode"))) { 776 size_t index = 0; 777 while(index < code.length) { 778 if(code[index] == '_') { 779 if(startsWith(code[index .. $], "_PyUnicode_")) { 780 break; 781 } 782 }else if(code[index] == 'P') { 783 if(startsWith(code[index .. $], "PyUnicode_")) { 784 break; 785 } 786 }else if(code[index] == '/') { 787 if(startsWith(code[index .. $], "/*")) { 788 break; 789 } 790 } 791 index++; 792 } 793 if(index == code.length) break; 794 newcodes ~= code[0 .. index]; 795 code = code[index .. $]; 796 continue; 797 } 798 size_t end_index = countUntil(code, "("); 799 if(end_index == -1) break; 800 string alias_name = code[0 .. end_index]; 801 string func_name = replace(alias_name, "PyUnicode_", PyUnicode_); 802 size_t index0 = end_index+1; 803 int parencount = 1; 804 while(parencount && index0 < code.length) { 805 if(startsWith(code[index0 .. $], "/*")) { 806 size_t comm_end_index = countUntil(code[index0+2 .. $], "*/"); 807 if(comm_end_index == -1) break LOOP; 808 index0 += comm_end_index; 809 continue; 810 }else if(code[index0] == '(') { 811 parencount++; 812 index0++; 813 }else if(code[index0] == ')') { 814 parencount--; 815 index0++; 816 }else{ 817 index0++; 818 } 819 } 820 size_t semi = countUntil(code[index0 .. $], ";"); 821 if(semi == -1) break; 822 index0 += semi+1; 823 824 string alias_line = "\nalias " ~ func_name ~ " " ~ alias_name ~ ";\n"; 825 newcodes ~= func_name; 826 newcodes ~= code[end_index .. index0]; 827 newcodes ~= alias_line; 828 829 code = code[index0 .. $]; 830 } 831 832 string newcode; 833 foreach(c; newcodes) { 834 newcode ~= c; 835 } 836 return newcode; 837 } 838 839 enum string unicode_funs = q{ 840 version(Python_2_6_Or_Later) { 841 842 /* Similar to PyUnicode_FromUnicode(), but u points to Latin-1 encoded bytes */ 843 PyObject* PyUnicode_FromStringAndSize( 844 const(char)* u, /* char buffer */ 845 Py_ssize_t size /* size of buffer */ 846 ); 847 848 /* Similar to PyUnicode_FromUnicode(), but u points to null-terminated 849 Latin-1 encoded bytes */ 850 PyObject* PyUnicode_FromString( 851 const(char)* u /* string */ 852 ); 853 PyObject* PyUnicode_FromFormatV(const(char)*, va_list); 854 PyObject* PyUnicode_FromFormat(const(char)*, ...); 855 856 /* Format the object based on the format_spec, as defined in PEP 3101 857 (Advanced String Formatting). */ 858 PyObject * _PyUnicode_FormatAdvanced(PyObject *obj, 859 Py_UNICODE *format_spec, 860 Py_ssize_t format_spec_len); 861 int PyUnicode_ClearFreeList(); 862 PyObject* PyUnicode_DecodeUTF7Stateful( 863 const(char)* string, /* UTF-7 encoded string */ 864 Py_ssize_t length, /* size of string */ 865 const(char)* errors, /* error handling */ 866 Py_ssize_t * consumed /* bytes consumed */ 867 ); 868 PyObject* PyUnicode_DecodeUTF32( 869 const(char)* string, /* UTF-32 encoded string */ 870 Py_ssize_t length, /* size of string */ 871 const(char)* errors, /* error handling */ 872 int *byteorder /* pointer to byteorder to use 873 0=native;-1=LE,1=BE; updated on 874 exit */ 875 ); 876 877 PyObject* PyUnicode_DecodeUTF32Stateful( 878 const(char)*string, /* UTF-32 encoded string */ 879 Py_ssize_t length, /* size of string */ 880 const(char)*errors, /* error handling */ 881 int *byteorder, /* pointer to byteorder to use 882 0=native;-1=LE,1=BE; updated on 883 exit */ 884 Py_ssize_t *consumed /* bytes consumed */ 885 ); 886 /* Returns a Python string using the UTF-32 encoding in native byte 887 order. The string always starts with a BOM mark. */ 888 889 PyObject* PyUnicode_AsUTF32String( 890 PyObject *unicode /* Unicode object */ 891 ); 892 893 /* Returns a Python string object holding the UTF-32 encoded value of 894 the Unicode data. 895 896 If byteorder is not 0, output is written according to the following 897 byte order: 898 899 byteorder == -1: little endian 900 byteorder == 0: native byte order (writes a BOM mark) 901 byteorder == 1: big endian 902 903 If byteorder is 0, the output string will always start with the 904 Unicode BOM mark (U+FEFF). In the other two modes, no BOM mark is 905 prepended. 906 907 */ 908 909 PyObject* PyUnicode_EncodeUTF32( 910 const Py_UNICODE *data, /* Unicode char buffer */ 911 Py_ssize_t length, /* number of Py_UNICODE chars to encode */ 912 const(char)*errors, /* error handling */ 913 int byteorder /* byteorder to use 0=BOM+native;-1=LE,1=BE */ 914 ); 915 } 916 917 PyObject *PyUnicode_FromUnicode(Py_UNICODE *u, Py_ssize_t size); 918 Py_UNICODE *PyUnicode_AsUnicode(PyObject *unicode); 919 Py_ssize_t PyUnicode_GetSize(PyObject *unicode); 920 Py_UNICODE PyUnicode_GetMax(); 921 922 int PyUnicode_Resize(PyObject **unicode, Py_ssize_t length); 923 PyObject *PyUnicode_FromEncodedObject(PyObject *obj, const(char) *encoding, const(char) *errors); 924 PyObject *PyUnicode_FromObject(PyObject *obj); 925 926 PyObject *PyUnicode_FromWideChar(const(wchar) *w, Py_ssize_t size); 927 Py_ssize_t PyUnicode_AsWideChar(PyUnicodeObject *unicode, const(wchar) *w, Py_ssize_t size); 928 929 PyObject *PyUnicode_FromOrdinal(int ordinal); 930 931 PyObject *_PyUnicode_AsDefaultEncodedString(PyObject *, const(char)*); 932 933 const(char)*PyUnicode_GetDefaultEncoding(); 934 int PyUnicode_SetDefaultEncoding(const(char)*encoding); 935 936 PyObject *PyUnicode_Decode(const(char) *s, Py_ssize_t size, const(char) *encoding, const(char) *errors); 937 PyObject *PyUnicode_Encode(Py_UNICODE *s, Py_ssize_t size, const(char) *encoding, const(char) *errors); 938 PyObject *PyUnicode_AsEncodedObject(PyObject *unicode, const(char) *encoding, const(char) *errors); 939 PyObject *PyUnicode_AsEncodedString(PyObject *unicode, const(char) *encoding, const(char) *errors); 940 941 PyObject *PyUnicode_DecodeUTF7(const(char) *string, Py_ssize_t length, const(char) *errors); 942 PyObject *PyUnicode_EncodeUTF7(Py_UNICODE *data, Py_ssize_t length, 943 int encodeSetO, int encodeWhiteSpace, const(char) *errors 944 ); 945 946 PyObject *PyUnicode_DecodeUTF8(const(char) *string, Py_ssize_t length, const(char) *errors); 947 PyObject *PyUnicode_DecodeUTF8Stateful(const(char) *string, Py_ssize_t length, 948 const(char) *errors, Py_ssize_t *consumed 949 ); 950 PyObject *PyUnicode_AsUTF8String(PyObject *unicode); 951 PyObject *PyUnicode_EncodeUTF8(Py_UNICODE *data, Py_ssize_t length, const(char) *errors); 952 953 PyObject *PyUnicode_DecodeUTF16(const(char) *string, Py_ssize_t length, const(char) *errors, int *byteorder); 954 PyObject *PyUnicode_DecodeUTF16Stateful(const(char) *string, Py_ssize_t length, 955 const(char) *errors, int *byteorder, Py_ssize_t *consumed 956 ); 957 PyObject *PyUnicode_AsUTF16String(PyObject *unicode); 958 PyObject *PyUnicode_EncodeUTF16(Py_UNICODE *data, Py_ssize_t length, 959 const(char) *errors, int byteorder 960 ); 961 962 PyObject *PyUnicode_DecodeUnicodeEscape(const(char) *string, Py_ssize_t length, const(char) *errors); 963 PyObject *PyUnicode_AsUnicodeEscapeString(PyObject *unicode); 964 PyObject *PyUnicode_EncodeUnicodeEscape(Py_UNICODE *data, Py_ssize_t length); 965 PyObject *PyUnicode_DecodeRawUnicodeEscape(const(char) *string, Py_ssize_t length, const(char) *errors); 966 PyObject *PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode); 967 PyObject *PyUnicode_EncodeRawUnicodeEscape(Py_UNICODE *data, Py_ssize_t length); 968 969 PyObject *_PyUnicode_DecodeUnicodeInternal(const(char) *string, Py_ssize_t length, const(char) *errors); 970 971 PyObject *PyUnicode_DecodeLatin1(const(char) *string, Py_ssize_t length, const(char) *errors); 972 PyObject *PyUnicode_AsLatin1String(PyObject *unicode); 973 PyObject *PyUnicode_EncodeLatin1(Py_UNICODE *data, Py_ssize_t length, const(char) *errors); 974 975 PyObject *PyUnicode_DecodeASCII(const(char) *string, Py_ssize_t length, const(char) *errors); 976 PyObject *PyUnicode_AsASCIIString(PyObject *unicode); 977 PyObject *PyUnicode_EncodeASCII(Py_UNICODE *data, Py_ssize_t length, const(char) *errors); 978 979 PyObject *PyUnicode_DecodeCharmap(const(char) *string, Py_ssize_t length, 980 PyObject *mapping, const(char) *errors 981 ); 982 PyObject *PyUnicode_AsCharmapString(PyObject *unicode, PyObject *mapping); 983 PyObject *PyUnicode_EncodeCharmap(Py_UNICODE *data, Py_ssize_t length, 984 PyObject *mapping, const(char) *errors 985 ); 986 PyObject *PyUnicode_TranslateCharmap(Py_UNICODE *data, Py_ssize_t length, 987 PyObject *table, const(char) *errors 988 ); 989 990 version (Windows) { 991 PyObject *PyUnicode_DecodeMBCS(const(char) *string, Py_ssize_t length, const(char) *errors); 992 PyObject *PyUnicode_AsMBCSString(PyObject *unicode); 993 PyObject *PyUnicode_EncodeMBCS(Py_UNICODE *data, Py_ssize_t length, const(char) *errors); 994 } 995 996 int PyUnicode_EncodeDecimal(Py_UNICODE *s, Py_ssize_t length, char *output, const(char) *errors); 997 998 PyObject *PyUnicode_Concat(PyObject *left, PyObject *right); 999 PyObject *PyUnicode_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit); 1000 PyObject *PyUnicode_Splitlines(PyObject *s, int keepends); 1001 PyObject *PyUnicode_RSplit(PyObject *s, PyObject *sep, Py_ssize_t maxsplit); 1002 PyObject *PyUnicode_Translate(PyObject *str, PyObject *table, const(char) *errors); 1003 PyObject *PyUnicode_Join(PyObject *separator, PyObject *seq); 1004 Py_ssize_t PyUnicode_Tailmatch(PyObject *str, PyObject *substr, 1005 Py_ssize_t start, Py_ssize_t end, int direction 1006 ); 1007 Py_ssize_t PyUnicode_Find(PyObject *str, PyObject *substr, 1008 Py_ssize_t start, Py_ssize_t end, int direction 1009 ); 1010 Py_ssize_t PyUnicode_Count(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end); 1011 PyObject *PyUnicode_Replace(PyObject *str, PyObject *substr, 1012 PyObject *replstr, Py_ssize_t maxcount 1013 ); 1014 int PyUnicode_Compare(PyObject *left, PyObject *right); 1015 PyObject *PyUnicode_Format(PyObject *format, PyObject *args); 1016 int PyUnicode_Contains(PyObject *container, PyObject *element); 1017 PyObject *_PyUnicode_XStrip(PyUnicodeObject *self, int striptype, 1018 PyObject *sepobj 1019 ); 1020 1021 int _PyUnicode_IsLowercase(Py_UNICODE ch); 1022 int _PyUnicode_IsUppercase(Py_UNICODE ch); 1023 int _PyUnicode_IsTitlecase(Py_UNICODE ch); 1024 int _PyUnicode_IsWhitespace(Py_UNICODE ch); 1025 int _PyUnicode_IsLinebreak(Py_UNICODE ch); 1026 Py_UNICODE _PyUnicode_ToLowercase(Py_UNICODE ch); 1027 Py_UNICODE _PyUnicode_ToUppercase(Py_UNICODE ch); 1028 Py_UNICODE _PyUnicode_ToTitlecase(Py_UNICODE ch); 1029 int _PyUnicode_ToDecimalDigit(Py_UNICODE ch); 1030 int _PyUnicode_ToDigit(Py_UNICODE ch); 1031 double _PyUnicode_ToNumeric(Py_UNICODE ch); 1032 int _PyUnicode_IsDecimalDigit(Py_UNICODE ch); 1033 int _PyUnicode_IsDigit(Py_UNICODE ch); 1034 int _PyUnicode_IsNumeric(Py_UNICODE ch); 1035 int _PyUnicode_IsAlpha(Py_UNICODE ch); 1036 1037 }; 1038 1039 mixin(substitute_and_alias(unicode_funs)); 1040 1041 alias _PyUnicode_IsWhitespace Py_UNICODE_ISSPACE; 1042 alias _PyUnicode_IsLowercase Py_UNICODE_ISLOWER; 1043 alias _PyUnicode_IsUppercase Py_UNICODE_ISUPPER; 1044 alias _PyUnicode_IsTitlecase Py_UNICODE_ISTITLE; 1045 alias _PyUnicode_IsLinebreak Py_UNICODE_ISLINEBREAK; 1046 alias _PyUnicode_ToLowercase Py_UNICODE_TOLOWER; 1047 alias _PyUnicode_ToUppercase Py_UNICODE_TOUPPER; 1048 alias _PyUnicode_ToTitlecase Py_UNICODE_TOTITLE; 1049 alias _PyUnicode_IsDecimalDigit Py_UNICODE_ISDECIMAL; 1050 alias _PyUnicode_IsDigit Py_UNICODE_ISDIGIT; 1051 alias _PyUnicode_IsNumeric Py_UNICODE_ISNUMERIC; 1052 alias _PyUnicode_ToDecimalDigit Py_UNICODE_TODECIMAL; 1053 alias _PyUnicode_ToDigit Py_UNICODE_TODIGIT; 1054 alias _PyUnicode_ToNumeric Py_UNICODE_TONUMERIC; 1055 alias _PyUnicode_IsAlpha Py_UNICODE_ISALPHA; 1056 1057 int Py_UNICODE_ISALNUM()(Py_UNICODE ch) { 1058 return ( 1059 Py_UNICODE_ISALPHA(ch) 1060 || Py_UNICODE_ISDECIMAL(ch) 1061 || Py_UNICODE_ISDIGIT(ch) 1062 || Py_UNICODE_ISNUMERIC(ch) 1063 ); 1064 } 1065 1066 void Py_UNICODE_COPY()(void *target, void *source, size_t length) { 1067 memcpy(target, source, cast(uint)(length * Py_UNICODE.sizeof)); 1068 } 1069 1070 void Py_UNICODE_FILL()(Py_UNICODE *target, Py_UNICODE value, size_t length) { 1071 for (size_t i = 0; i < length; i++) { 1072 target[i] = value; 1073 } 1074 } 1075 1076 int Py_UNICODE_MATCH()(PyUnicodeObject *string, size_t offset, 1077 PyUnicodeObject *substring 1078 ) 1079 { 1080 return ( 1081 (*(string.str + offset) == *(substring.str)) 1082 && !memcmp(string.str + offset, substring.str, 1083 substring.length * Py_UNICODE.sizeof 1084 ) 1085 ); 1086 } 1087 1088 1089 /////////////////////////////////////////////////////////////////////////////// 1090 // INT INTERFACE 1091 /////////////////////////////////////////////////////////////////////////////// 1092 // Python-header-file: Include/intobject.h: 1093 1094 struct PyIntObject { 1095 mixin PyObject_HEAD; 1096 1097 C_long ob_ival; 1098 } 1099 1100 // &PyInt_Type is accessible via PyInt_Type_p. 1101 1102 // D translation of C macro: 1103 int PyInt_Check()(PyObject *op) { 1104 return PyObject_TypeCheck(op, PyInt_Type_p); 1105 } 1106 // D translation of C macro: 1107 int PyInt_CheckExact()(PyObject *op) { 1108 return op.ob_type == PyInt_Type_p; 1109 } 1110 1111 PyObject *PyInt_FromString(char *, char **, int); 1112 PyObject *PyInt_FromUnicode(Py_UNICODE *, Py_ssize_t, int); 1113 PyObject *PyInt_FromLong(C_long); 1114 version(Python_2_5_Or_Later){ 1115 PyObject *PyInt_FromSize_t(size_t); 1116 PyObject *PyInt_FromSsize_t(Py_ssize_t); 1117 1118 Py_ssize_t PyInt_AsSsize_t(PyObject*); 1119 } 1120 1121 C_long PyInt_AsLong(PyObject *); 1122 C_ulong PyInt_AsUnsignedLongMask(PyObject *); 1123 C_ulonglong PyInt_AsUnsignedLongLongMask(PyObject *); 1124 1125 C_long PyInt_GetMax(); /* Accessible at the Python level as sys.maxint */ 1126 1127 C_ulong PyOS_strtoul(char *, char **, int); 1128 C_long PyOS_strtol(char *, char **, int); 1129 version(Python_2_6_Or_Later){ 1130 C_long PyOS_strtol(char *, char **, int); 1131 1132 /* free list api */ 1133 int PyInt_ClearFreeList(); 1134 1135 /* Convert an integer to the given base. Returns a string. 1136 If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'. 1137 If newstyle is zero, then use the pre-2.6 behavior of octal having 1138 a leading "0" */ 1139 PyObject* _PyInt_Format(PyIntObject* v, int base, int newstyle); 1140 1141 /* Format the object based on the format_spec, as defined in PEP 3101 1142 (Advanced String Formatting). */ 1143 PyObject * _PyInt_FormatAdvanced(PyObject *obj, 1144 char *format_spec, 1145 Py_ssize_t format_spec_len); 1146 } 1147 1148 1149 /////////////////////////////////////////////////////////////////////////////// 1150 // BOOL INTERFACE 1151 /////////////////////////////////////////////////////////////////////////////// 1152 // Python-header-file: Include/boolobject.h: 1153 1154 alias PyIntObject PyBoolObject; 1155 1156 // &PyBool_Type is accessible via PyBool_Type_p. 1157 1158 // D translation of C macro: 1159 int PyBool_Check()(PyObject *x) { 1160 return x.ob_type == PyBool_Type_p; 1161 } 1162 1163 // Py_False and Py_True are actually macros in the Python/C API, so they're 1164 // loaded as PyObject pointers in this module static initializer. 1165 1166 PyObject * PyBool_FromLong(C_long); 1167 1168 1169 /////////////////////////////////////////////////////////////////////////////// 1170 // LONG INTERFACE 1171 /////////////////////////////////////////////////////////////////////////////// 1172 // Python-header-file: Include/longobject.h: 1173 1174 // &PyLong_Type is accessible via PyLong_Type_p. 1175 1176 version(Python_2_6_Or_Later){ 1177 int PyLong_Check()(PyObject* op){ 1178 return PyType_FastSubclass((op).ob_type, Py_TPFLAGS_LONG_SUBCLASS); 1179 } 1180 }else{ 1181 // D translation of C macro: 1182 int PyLong_Check()(PyObject *op) { 1183 return PyObject_TypeCheck(op, PyLong_Type_p); 1184 } 1185 } 1186 // D translation of C macro: 1187 int PyLong_CheckExact()(PyObject *op) { 1188 return op.ob_type == PyLong_Type_p; 1189 } 1190 1191 PyObject * PyLong_FromLong(C_long); 1192 PyObject * PyLong_FromUnsignedLong(C_ulong); 1193 1194 PyObject * PyLong_FromLongLong(C_longlong); 1195 PyObject * PyLong_FromUnsignedLongLong(C_ulonglong); 1196 1197 PyObject * PyLong_FromDouble(double); 1198 version(Python_2_6_Or_Later){ 1199 PyObject * PyLong_FromSize_t(size_t); 1200 PyObject * PyLong_FromSsize_t(Py_ssize_t); 1201 } 1202 PyObject * PyLong_FromVoidPtr(void *); 1203 1204 C_long PyLong_AsLong(PyObject *); 1205 C_ulong PyLong_AsUnsignedLong(PyObject *); 1206 C_ulong PyLong_AsUnsignedLongMask(PyObject *); 1207 version(Python_2_6_Or_Later){ 1208 Py_ssize_t PyLong_AsSsize_t(PyObject *); 1209 } 1210 1211 C_longlong PyLong_AsLongLong(PyObject *); 1212 C_ulonglong PyLong_AsUnsignedLongLong(PyObject *); 1213 C_ulonglong PyLong_AsUnsignedLongLongMask(PyObject *); 1214 version(Python_2_7_Or_Later) { 1215 C_long PyLong_AsLongAndOverflow(PyObject*, int*); 1216 C_longlong PyLong_AsLongLongAndOverflow(PyObject*, int*); 1217 } 1218 1219 double PyLong_AsDouble(PyObject *); 1220 PyObject * PyLong_FromVoidPtr(void *); 1221 void * PyLong_AsVoidPtr(PyObject *); 1222 1223 PyObject * PyLong_FromString(char *, char **, int); 1224 PyObject * PyLong_FromUnicode(Py_UNICODE *, int, int); 1225 int _PyLong_Sign(PyObject* v); 1226 size_t _PyLong_NumBits(PyObject* v); 1227 PyObject* _PyLong_FromByteArray( 1228 const(ubyte)* bytes, size_t n, 1229 int little_endian, int is_signed); 1230 int _PyLong_AsByteArray(PyLongObject* v, 1231 ubyte* bytes, size_t n, 1232 int little_endian, int is_signed); 1233 1234 version(Python_2_6_Or_Later){ 1235 /* _PyLong_Format: Convert the long to a string object with given base, 1236 appending a base prefix of 0[box] if base is 2, 8 or 16. 1237 Add a trailing "L" if addL is non-zero. 1238 If newstyle is zero, then use the pre-2.6 behavior of octal having 1239 a leading "0", instead of the prefix "0o" */ 1240 PyObject * _PyLong_Format(PyObject *aa, int base, int addL, int newstyle); 1241 1242 /* Format the object based on the format_spec, as defined in PEP 3101 1243 (Advanced String Formatting). */ 1244 PyObject * _PyLong_FormatAdvanced(PyObject *obj, 1245 char *format_spec, 1246 Py_ssize_t format_spec_len); 1247 } 1248 1249 // Python-header-file: Include/longintrepr.h: 1250 1251 struct PyLongObject { 1252 mixin PyObject_VAR_HEAD; 1253 ushort ob_digit[1]; 1254 } 1255 1256 PyLongObject* _PyLong_New(int); 1257 1258 /* Return a copy of src. */ 1259 PyObject* _PyLong_Copy(PyLongObject* src); 1260 1261 /////////////////////////////////////////////////////////////////////////////// 1262 // FLOAT INTERFACE 1263 /////////////////////////////////////////////////////////////////////////////// 1264 // Python-header-file: Include/floatobject.h: 1265 1266 struct PyFloatObject { 1267 mixin PyObject_HEAD; 1268 1269 double ob_fval; 1270 } 1271 1272 // &PyFloat_Type is accessible via PyFloat_Type_p. 1273 1274 // D translation of C macro: 1275 int PyFloat_Check()(PyObject *op) { 1276 return PyObject_TypeCheck(op, PyFloat_Type_p); 1277 } 1278 // D translation of C macro: 1279 int PyFloat_CheckExact()(PyObject *op) { 1280 return op.ob_type == PyFloat_Type_p; 1281 } 1282 1283 version(Python_2_6_Or_Later){ 1284 double PyFloat_GetMax(); 1285 double PyFloat_GetMin(); 1286 PyObject * PyFloat_GetInfo(); 1287 } 1288 1289 PyObject * PyFloat_FromString(PyObject *, char** junk); 1290 PyObject * PyFloat_FromDouble(double); 1291 1292 double PyFloat_AsDouble(PyObject *); 1293 void PyFloat_AsReprString(char *, PyFloatObject *v); 1294 void PyFloat_AsString(char *, PyFloatObject *v); 1295 1296 version(Python_2_6_Or_Later){ 1297 // _PyFloat_Digits ?? 1298 // _PyFloat_DigitsInit ?? 1299 /* free list api */ 1300 int PyFloat_ClearFreeList(); 1301 // _PyFloat_FormatAdvanced ?? 1302 } 1303 1304 1305 /////////////////////////////////////////////////////////////////////////////// 1306 // COMPLEX INTERFACE 1307 /////////////////////////////////////////////////////////////////////////////// 1308 // Python-header-file: Include/complexobject.h: 1309 1310 struct Py_complex { 1311 double real_; // real is the name of a D type, so must rename 1312 double imag; 1313 } 1314 1315 struct PyComplexObject { 1316 mixin PyObject_HEAD; 1317 1318 Py_complex cval; 1319 } 1320 1321 Py_complex c_sum(Py_complex, Py_complex); 1322 Py_complex c_diff(Py_complex, Py_complex); 1323 Py_complex c_neg(Py_complex); 1324 Py_complex c_prod(Py_complex, Py_complex); 1325 Py_complex c_quot(Py_complex, Py_complex); 1326 Py_complex c_pow(Py_complex, Py_complex); 1327 version(Python_2_6_Or_Later){ 1328 double c_abs(Py_complex); 1329 } 1330 1331 // &PyComplex_Type is accessible via PyComplex_Type_p. 1332 1333 // D translation of C macro: 1334 int PyComplex_Check()(PyObject *op) { 1335 return PyObject_TypeCheck(op, PyComplex_Type_p); 1336 } 1337 // D translation of C macro: 1338 int PyComplex_CheckExact()(PyObject *op) { 1339 return op.ob_type == PyComplex_Type_p; 1340 } 1341 1342 PyObject * PyComplex_FromCComplex(Py_complex); 1343 PyObject * PyComplex_FromDoubles(double real_, double imag); 1344 1345 double PyComplex_RealAsDouble(PyObject *op); 1346 double PyComplex_ImagAsDouble(PyObject *op); 1347 Py_complex PyComplex_AsCComplex(PyObject *op); 1348 1349 1350 /////////////////////////////////////////////////////////////////////////////// 1351 // RANGE INTERFACE 1352 /////////////////////////////////////////////////////////////////////////////// 1353 // Python-header-file: Include/rangeobject.h: 1354 1355 // &PyRange_Type is accessible via PyRange_Type_p. 1356 1357 // D translation of C macro: 1358 int PyRange_Check()(PyObject *op) { 1359 return op.ob_type == PyRange_Type_p; 1360 } 1361 1362 version(Python_2_5_Or_Later){ 1363 // Removed in 2.5 1364 }else{ 1365 PyObject * PyRange_New(C_long, C_long, C_long, int); 1366 } 1367 1368 1369 /////////////////////////////////////////////////////////////////////////////// 1370 // STRING INTERFACE 1371 /////////////////////////////////////////////////////////////////////////////// 1372 // Python-header-file: Include/stringobject.h: 1373 1374 struct PyStringObject { 1375 mixin PyObject_VAR_HEAD; 1376 1377 C_long ob_shash; 1378 int ob_sstate; 1379 // DSR:XXX:LAYOUT: 1380 // Will the D layout for a 1-char array be the same as the C layout? I 1381 // think the D array will be larger. 1382 char _ob_sval[1]; 1383 char* ob_sval()() { 1384 return _ob_sval.ptr; 1385 } 1386 } 1387 1388 // &PyBaseString_Type is accessible via PyBaseString_Type_p. 1389 // &PyString_Type is accessible via PyString_Type_p. 1390 1391 // D translation of C macro: 1392 int PyString_Check()(PyObject *op) { 1393 return PyObject_TypeCheck(op, PyString_Type_p); 1394 } 1395 // D translation of C macro: 1396 int PyString_CheckExact()(PyObject *op) { 1397 return op.ob_type == PyString_Type_p; 1398 } 1399 1400 PyObject * PyString_FromStringAndSize(const(char) *, Py_ssize_t); 1401 PyObject * PyString_FromString(const(char) *); 1402 // PyString_FromFormatV omitted 1403 PyObject * PyString_FromFormat(const(char)*, ...); 1404 Py_ssize_t PyString_Size(PyObject *); 1405 const(char)* PyString_AsString(PyObject *); 1406 /* Use only if you know it's a string */ 1407 int PyString_CHECK_INTERNED()(PyObject* op) { 1408 return (cast(PyStringObject*)op).ob_sstate; 1409 } 1410 /* Macro, trading safety for speed */ 1411 const(char)* PyString_AS_STRING()(PyObject* op) { 1412 return (cast(PyStringObject*)op).ob_sval; 1413 } 1414 Py_ssize_t PyString_GET_SIZE()(PyObject* op) { 1415 return (cast(PyStringObject*)op).ob_size; 1416 } 1417 PyObject * PyString_Repr(PyObject *, int); 1418 void PyString_Concat(PyObject **, PyObject *); 1419 void PyString_ConcatAndDel(PyObject **, PyObject *); 1420 PyObject * PyString_Format(PyObject *, PyObject *); 1421 PyObject * PyString_DecodeEscape(const(char) *, Py_ssize_t, const(char) *, Py_ssize_t, const(char) *); 1422 1423 void PyString_InternInPlace(PyObject **); 1424 void PyString_InternImmortal(PyObject **); 1425 PyObject * PyString_InternFromString(const(char) *); 1426 1427 PyObject * _PyString_Join(PyObject *sep, PyObject *x); 1428 1429 1430 PyObject* PyString_Decode(const(char) *s, Py_ssize_t size, const(char) *encoding, const(char) *errors); 1431 PyObject* PyString_Encode(const(char) *s, Py_ssize_t size, const(char) *encoding, const(char) *errors); 1432 1433 PyObject* PyString_AsEncodedObject(PyObject *str, const(char) *encoding, const(char) *errors); 1434 PyObject* PyString_AsDecodedObject(PyObject *str, const(char) *encoding, const(char) *errors); 1435 1436 // Since no one has legacy Python extensions written in D, the deprecated 1437 // functions PyString_AsDecodedString and PyString_AsEncodedString were 1438 // omitted. 1439 1440 int PyString_AsStringAndSize(PyObject *obj, char **s, int *len); 1441 1442 version(Python_2_6_Or_Later){ 1443 /* Using the current locale, insert the thousands grouping 1444 into the string pointed to by buffer. For the argument descriptions, 1445 see Objects/stringlib/localeutil.h */ 1446 1447 int _PyString_InsertThousandsGrouping(char *buffer, 1448 Py_ssize_t n_buffer, 1449 Py_ssize_t n_digits, 1450 Py_ssize_t buf_size, 1451 Py_ssize_t *count, 1452 int append_zero_char); 1453 1454 /* Format the object based on the format_spec, as defined in PEP 3101 1455 (Advanced String Formatting). */ 1456 PyObject * _PyBytes_FormatAdvanced(PyObject *obj, 1457 char *format_spec, 1458 Py_ssize_t format_spec_len); 1459 } 1460 1461 1462 /////////////////////////////////////////////////////////////////////////////// 1463 // BUFFER INTERFACE 1464 /////////////////////////////////////////////////////////////////////////////// 1465 // Python-header-file: Include/bufferobject.h: 1466 1467 // &PyBuffer_Type is accessible via PyBuffer_Type_p. 1468 1469 // D translation of C macro: 1470 int PyBuffer_Check()(PyObject *op) { 1471 return op.ob_type == PyBuffer_Type_p; 1472 } 1473 1474 enum int Py_END_OF_BUFFER = -1; 1475 1476 PyObject * PyBuffer_FromObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size); 1477 PyObject * PyBuffer_FromReadWriteObject(PyObject *base, Py_ssize_t offset, Py_ssize_t size); 1478 1479 PyObject * PyBuffer_FromMemory(void *ptr, Py_ssize_t size); 1480 PyObject * PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size); 1481 1482 PyObject * PyBuffer_New(Py_ssize_t size); 1483 1484 1485 /////////////////////////////////////////////////////////////////////////////// 1486 // TUPLE INTERFACE 1487 /////////////////////////////////////////////////////////////////////////////// 1488 // Python-header-file: Include/tupleobject.h: 1489 1490 struct PyTupleObject { 1491 mixin PyObject_VAR_HEAD; 1492 1493 // DSR:XXX:LAYOUT: 1494 // Will the D layout for a 1-PyObject* array be the same as the C layout? 1495 // I think the D array will be larger. 1496 PyObject *_ob_item[1]; 1497 PyObject** ob_item()() { 1498 return _ob_item.ptr; 1499 } 1500 } 1501 1502 // &PyTuple_Type is accessible via PyTuple_Type_p. 1503 1504 // D translation of C macro: 1505 int PyTuple_Check()(PyObject *op) { 1506 return PyObject_TypeCheck(op, PyTuple_Type_p); 1507 } 1508 // D translation of C macro: 1509 int PyTuple_CheckExact()(PyObject *op) { 1510 return op.ob_type == PyTuple_Type_p; 1511 } 1512 1513 PyObject * PyTuple_New(Py_ssize_t size); 1514 Py_ssize_t PyTuple_Size(PyObject *); 1515 Borrowed!PyObject* PyTuple_GetItem(PyObject*, Py_ssize_t); 1516 int PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *); 1517 PyObject * PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t); 1518 int _PyTuple_Resize(PyObject **, Py_ssize_t); 1519 PyObject * PyTuple_Pack(Py_ssize_t, ...); 1520 1521 // D translations of C macros: 1522 // XXX: These do not work. 1523 Borrowed!PyObject* PyTuple_GET_ITEM()(PyObject* op, Py_ssize_t i) { 1524 return (cast(PyTupleObject *) op).ob_item[i]; 1525 } 1526 size_t PyTuple_GET_SIZE()(PyObject *op) { 1527 return (cast(PyTupleObject *) op).ob_size; 1528 } 1529 PyObject *PyTuple_SET_ITEM()(PyObject *op, Py_ssize_t i, PyObject *v) { 1530 PyTupleObject *opAsTuple = cast(PyTupleObject *) op; 1531 opAsTuple.ob_item[i] = v; 1532 return v; 1533 } 1534 1535 version(Python_2_6_Or_Later){ 1536 int PyTuple_ClearFreeList(); 1537 } 1538 1539 /////////////////////////////////////////////////////////////////////////////// 1540 // LIST INTERFACE 1541 /////////////////////////////////////////////////////////////////////////////// 1542 // Python-header-file: Include/listobject.h: 1543 1544 struct PyListObject { 1545 mixin PyObject_VAR_HEAD; 1546 1547 PyObject **ob_item; 1548 Py_ssize_t allocated; 1549 } 1550 1551 // &PyList_Type is accessible via PyList_Type_p. 1552 1553 // D translation of C macro: 1554 int PyList_Check()(PyObject *op) { 1555 return PyObject_TypeCheck(op, PyList_Type_p); 1556 } 1557 // D translation of C macro: 1558 int PyList_CheckExact()(PyObject *op) { 1559 return op.ob_type == PyList_Type_p; 1560 } 1561 1562 PyObject * PyList_New(Py_ssize_t size); 1563 Py_ssize_t PyList_Size(PyObject *); 1564 1565 Borrowed!PyObject* PyList_GetItem(PyObject*, Py_ssize_t); 1566 int PyList_SetItem(PyObject*, Py_ssize_t, PyObject*); 1567 int PyList_Insert(PyObject*, Py_ssize_t, PyObject*); 1568 int PyList_Append(PyObject*, PyObject*); 1569 PyObject* PyList_GetSlice(PyObject*, Py_ssize_t, Py_ssize_t); 1570 int PyList_SetSlice(PyObject*, Py_ssize_t, Py_ssize_t, PyObject*); 1571 int PyList_Sort(PyObject*); 1572 int PyList_Reverse(PyObject*); 1573 PyObject* PyList_AsTuple(PyObject*); 1574 1575 // D translations of C macros: 1576 Borrowed!PyObject* PyList_GET_ITEM()(PyObject* op, Py_ssize_t i) { 1577 return (cast(PyListObject*) op).ob_item[i]; 1578 } 1579 void PyList_SET_ITEM()(PyObject *op, Py_ssize_t i, PyObject *v) { 1580 (cast(PyListObject*)op).ob_item[i] = v; 1581 } 1582 Py_ssize_t PyList_GET_SIZE()(PyObject *op) { 1583 return (cast(PyListObject *) op).ob_size; 1584 } 1585 1586 1587 /////////////////////////////////////////////////////////////////////////////// 1588 // DICTIONARY OBJECT TYPE 1589 /////////////////////////////////////////////////////////////////////////////// 1590 // Python-header-file: Include/dictobject.h: 1591 1592 enum int PyDict_MINSIZE = 8; 1593 1594 struct PyDictEntry { 1595 version(Python_2_5_Or_Later){ 1596 Py_ssize_t me_hash; 1597 }else{ 1598 C_long me_hash; 1599 } 1600 PyObject *me_key; 1601 PyObject *me_value; 1602 } 1603 1604 struct _dictobject { 1605 mixin PyObject_HEAD; 1606 1607 Py_ssize_t ma_fill; 1608 Py_ssize_t ma_used; 1609 Py_ssize_t ma_mask; 1610 PyDictEntry *ma_table; 1611 PyDictEntry* function(PyDictObject *mp, PyObject *key, C_long hash) ma_lookup; 1612 PyDictEntry ma_smalltable[PyDict_MINSIZE]; 1613 } 1614 alias _dictobject PyDictObject; 1615 1616 // &PyDict_Type is accessible via PyDict_Type_p. 1617 1618 // D translation of C macro: 1619 int PyDict_Check()(PyObject *op) { 1620 return PyObject_TypeCheck(op, PyDict_Type_p); 1621 } 1622 // D translation of C macro: 1623 int PyDict_CheckExact()(PyObject *op) { 1624 return op.ob_type == PyDict_Type_p; 1625 } 1626 1627 PyObject* PyDict_New(); 1628 Borrowed!PyObject* PyDict_GetItem(PyObject* mp, PyObject* key); 1629 int PyDict_SetItem(PyObject* mp, PyObject* key, PyObject* item); 1630 int PyDict_DelItem(PyObject *mp, PyObject *key); 1631 void PyDict_Clear(PyObject *mp); 1632 int PyDict_Next(PyObject *mp, Py_ssize_t *pos, Borrowed!PyObject** key, Borrowed!PyObject** value); 1633 PyObject * PyDict_Keys(PyObject *mp); 1634 PyObject * PyDict_Values(PyObject *mp); 1635 PyObject * PyDict_Items(PyObject *mp); 1636 Py_ssize_t PyDict_Size(PyObject *mp); 1637 PyObject * PyDict_Copy(PyObject *mp); 1638 int PyDict_Contains(PyObject *mp, PyObject *key); 1639 1640 int PyDict_Update(PyObject *mp, PyObject *other); 1641 int PyDict_Merge(PyObject *mp, PyObject *other, int override_); 1642 int PyDict_MergeFromSeq2(PyObject *d, PyObject *seq2, int override_); 1643 1644 Borrowed!PyObject* PyDict_GetItemString(PyObject* dp, const(char)* key); 1645 int PyDict_SetItemString(PyObject* dp, const(char)* key, PyObject* item); 1646 int PyDict_DelItemString(PyObject* dp, const(char)* key); 1647 1648 1649 /////////////////////////////////////////////////////////////////////////////// 1650 // PYTHON EXTENSION FUNCTION INTERFACE 1651 /////////////////////////////////////////////////////////////////////////////// 1652 // Python-header-file: Include/methodobject.h: 1653 1654 // &PyCFunction_Type is accessible via PyCFunction_Type_p. 1655 1656 // D translation of C macro: 1657 int PyCFunction_Check()(PyObject *op) { 1658 return op.ob_type == PyCFunction_Type_p; 1659 } 1660 1661 alias PyObject* function(PyObject *, PyObject *) PyCFunction; 1662 alias PyObject* function(PyObject *, PyObject *,PyObject *) PyCFunctionWithKeywords; 1663 alias PyObject* function(PyObject *) PyNoArgsFunction; 1664 1665 PyCFunction PyCFunction_GetFunction(PyObject *); 1666 PyObject * PyCFunction_GetSelf(PyObject *); 1667 int PyCFunction_GetFlags(PyObject *); 1668 1669 PyObject * PyCFunction_Call(PyObject *, PyObject *, PyObject *); 1670 1671 version(Python_2_5_Or_Later){ 1672 alias const(char) Char1; 1673 }else{ 1674 alias char Char1; 1675 } 1676 struct PyMethodDef { 1677 Char1 *ml_name; 1678 PyCFunction ml_meth; 1679 int ml_flags; 1680 Char1 *ml_doc; 1681 } 1682 1683 PyObject * Py_FindMethod(PyMethodDef[], PyObject *, Char1 *); 1684 PyObject * PyCFunction_NewEx(PyMethodDef *, PyObject *,PyObject *); 1685 PyObject * PyCFunction_New()(PyMethodDef* ml, PyObject* self) { 1686 return PyCFunction_NewEx(ml, self, null); 1687 } 1688 1689 enum int METH_OLDARGS = 0x0000; 1690 enum int METH_VARARGS = 0x0001; 1691 enum int METH_KEYWORDS= 0x0002; 1692 enum int METH_NOARGS = 0x0004; 1693 enum int METH_O = 0x0008; 1694 enum int METH_CLASS = 0x0010; 1695 enum int METH_STATIC = 0x0020; 1696 enum int METH_COEXIST = 0x0040; 1697 1698 struct PyMethodChain { 1699 PyMethodDef *methods; 1700 PyMethodChain *link; 1701 } 1702 1703 PyObject * Py_FindMethodInChain(PyMethodChain *, PyObject *, Char1 *); 1704 1705 struct PyCFunctionObject { 1706 mixin PyObject_HEAD; 1707 1708 PyMethodDef *m_ml; 1709 PyObject *m_self; 1710 PyObject *m_module; 1711 } 1712 1713 version(Python_2_6_Or_Later){ 1714 int PyCFunction_ClearFreeList(); 1715 } 1716 1717 1718 /////////////////////////////////////////////////////////////////////////////// 1719 // MODULE INTERFACE 1720 /////////////////////////////////////////////////////////////////////////////// 1721 // Python-header-file: Include/moduleobject.h: 1722 1723 // &PyModule_Type is accessible via PyModule_Type_p. 1724 1725 // D translation of C macro: 1726 int PyModule_Check()(PyObject *op) { 1727 return PyObject_TypeCheck(op, PyModule_Type_p); 1728 } 1729 // D translation of C macro: 1730 int PyModule_CheckExact()(PyObject *op) { 1731 return op.ob_type == PyModule_Type_p; 1732 } 1733 1734 PyObject* PyModule_New(Char1*); 1735 Borrowed!PyObject* PyModule_GetDict(PyObject*); 1736 char* PyModule_GetName(PyObject*); 1737 char* PyModule_GetFilename(PyObject*); 1738 void _PyModule_Clear(PyObject *); 1739 1740 // Python-header-file: Include/modsupport.h: 1741 1742 version(Python_2_5_Or_Later){ 1743 enum PYTHON_API_VERSION = 1013; 1744 enum PYTHON_API_STRING = "1013"; 1745 }else version(Python_2_4_Or_Later){ 1746 enum PYTHON_API_VERSION = 1012; 1747 enum PYTHON_API_STRING = "1012"; 1748 } 1749 1750 int PyArg_Parse(PyObject *, Char1 *, ...); 1751 int PyArg_ParseTuple(PyObject *, Char1 *, ...); 1752 int PyArg_ParseTupleAndKeywords(PyObject *, PyObject *, 1753 Char1 *, char **, ...); 1754 int PyArg_UnpackTuple(PyObject *, Char1 *, Py_ssize_t, Py_ssize_t, ...); 1755 PyObject * Py_BuildValue(Char1 *, ...); 1756 1757 int PyModule_AddObject(PyObject *, Char1 *, PyObject *); 1758 int PyModule_AddIntConstant(PyObject *, Char1 *, C_long); 1759 int PyModule_AddStringConstant(PyObject *, Char1 *, Char1 *); 1760 1761 version(Python_2_5_Or_Later){ 1762 version(X86_64){ 1763 enum Py_InitModuleSym = "Py_InitModule4_64"; 1764 }else{ 1765 enum Py_InitModuleSym = "Py_InitModule4"; 1766 } 1767 }else{ 1768 enum Py_InitModuleSym = "Py_InitModule4"; 1769 } 1770 mixin("Borrowed!PyObject* "~Py_InitModuleSym~"(Char1 *name, PyMethodDef *methods, Char1 *doc, 1771 PyObject *self, int apiver); 1772 1773 Borrowed!PyObject* Py_InitModule()(string name, PyMethodDef *methods) 1774 { 1775 return "~Py_InitModuleSym~"(cast(Char1*) name.ptr, methods, cast(Char1 *)(null), 1776 cast(PyObject *)(null), PYTHON_API_VERSION); 1777 } 1778 1779 Borrowed!PyObject* Py_InitModule3()(string name, PyMethodDef *methods, string doc) { 1780 return "~Py_InitModuleSym~"(cast(Char1*)name.ptr, methods, cast(Char1*) doc, cast(PyObject *)null, 1781 PYTHON_API_VERSION); 1782 }"); 1783 1784 1785 /////////////////////////////////////////////////////////////////////////////// 1786 // PYTHON FUNCTION INTERFACE (to functions created by the 'def' statement) 1787 /////////////////////////////////////////////////////////////////////////////// 1788 // Python-header-file: Include/funcobject.h: 1789 1790 struct PyFunctionObject { 1791 mixin PyObject_HEAD; 1792 1793 PyObject *func_code; 1794 PyObject *func_globals; 1795 PyObject *func_defaults; 1796 PyObject *func_closure; 1797 PyObject *func_doc; 1798 PyObject *func_name; 1799 PyObject *func_dict; 1800 PyObject *func_weakreflist; 1801 PyObject *func_module; 1802 } 1803 1804 // &PyFunction_Type is accessible via PyFunction_Type_p. 1805 1806 // D translation of C macro: 1807 int PyFunction_Check()(PyObject *op) { 1808 return op.ob_type == PyFunction_Type_p; 1809 } 1810 1811 PyObject * PyFunction_New(PyObject *, PyObject *); 1812 Borrowed!PyObject* PyFunction_GetCode(PyObject*); 1813 Borrowed!PyObject* PyFunction_GetGlobals(PyObject*); 1814 Borrowed!PyObject* PyFunction_GetModule(PyObject*); 1815 Borrowed!PyObject* PyFunction_GetDefaults(PyObject*); 1816 int PyFunction_SetDefaults(PyObject *, PyObject *); 1817 Borrowed!PyObject* PyFunction_GetClosure(PyObject *); 1818 int PyFunction_SetClosure(PyObject *, PyObject *); 1819 1820 PyObject* PyFunction_GET_CODE()(PyObject* func) { 1821 return (cast(PyFunctionObject*)func).func_code; 1822 } 1823 PyObject* PyFunction_GET_GLOBALS()(PyObject* func) { 1824 return (cast(PyFunctionObject*)func).func_globals; 1825 } 1826 PyObject* PyFunction_GET_MODULE()(PyObject* func) { 1827 return (cast(PyFunctionObject*)func).func_module; 1828 } 1829 PyObject* PyFunction_GET_DEFAULTS()(PyObject* func) { 1830 return (cast(PyFunctionObject*)func).func_defaults; 1831 } 1832 PyObject* PyFunction_GET_CLOSURE()(PyObject* func) { 1833 return (cast(PyFunctionObject*)func).func_closure; 1834 } 1835 1836 // &PyClassMethod_Type is accessible via PyClassMethod_Type_p. 1837 // &PyStaticMethod_Type is accessible via PyStaticMethod_Type_p. 1838 1839 PyObject * PyClassMethod_New(PyObject *); 1840 PyObject * PyStaticMethod_New(PyObject *); 1841 1842 1843 /////////////////////////////////////////////////////////////////////////////// 1844 // PYTHON CLASS INTERFACE 1845 /////////////////////////////////////////////////////////////////////////////// 1846 // Python-header-file: Include/classobject.h: 1847 1848 struct PyClassObject { 1849 mixin PyObject_HEAD; 1850 1851 PyObject *cl_bases; /* A tuple of class objects */ 1852 PyObject *cl_dict; /* A dictionary */ 1853 PyObject *cl_name; /* A string */ 1854 /* The following three are functions or null */ 1855 PyObject *cl_getattr; 1856 PyObject *cl_setattr; 1857 PyObject *cl_delattr; 1858 } 1859 1860 struct PyInstanceObject { 1861 mixin PyObject_HEAD; 1862 1863 PyClassObject *in_class; 1864 PyObject *in_dict; 1865 PyObject *in_weakreflist; 1866 } 1867 1868 struct PyMethodObject { 1869 mixin PyObject_HEAD; 1870 1871 PyObject *im_func; 1872 PyObject *im_self; 1873 PyObject *im_class; 1874 PyObject *im_weakreflist; 1875 } 1876 1877 // &PyClass_Type is accessible via PyClass_Type_p. 1878 // D translation of C macro: 1879 int PyClass_Check()(PyObject *op) { 1880 return op.ob_type == PyClass_Type_p; 1881 } 1882 1883 // &PyInstance_Type is accessible via PyInstance_Type_p. 1884 // D translation of C macro: 1885 int PyInstance_Check()(PyObject *op) { 1886 return op.ob_type == PyInstance_Type_p; 1887 } 1888 1889 // &PyMethod_Type is accessible via PyMethod_Type_p. 1890 // D translation of C macro: 1891 int PyMethod_Check()(PyObject *op) { 1892 return op.ob_type == PyMethod_Type_p; 1893 } 1894 1895 PyObject * PyClass_New(PyObject *, PyObject *, PyObject *); 1896 PyObject * PyInstance_New(PyObject *, PyObject *, 1897 PyObject *); 1898 PyObject * PyInstance_NewRaw(PyObject *, PyObject *); 1899 PyObject * PyMethod_New(PyObject *, PyObject *, PyObject *); 1900 1901 Borrowed!PyObject* PyMethod_Function(PyObject *); 1902 Borrowed!PyObject* PyMethod_Self(PyObject *); 1903 Borrowed!PyObject* PyMethod_Class(PyObject*); 1904 1905 PyObject * _PyInstance_Lookup(PyObject *pinst, PyObject *name); 1906 1907 Borrowed!PyObject* PyMethod_GET_FUNCTION()(PyObject* meth) { 1908 return (cast(PyMethodObject*)meth).im_func; 1909 } 1910 Borrowed!PyObject* PyMethod_GET_SELF()(PyObject* meth) { 1911 return (cast(PyMethodObject*)meth).im_self; 1912 } 1913 Borrowed!PyObject* PyMethod_GET_CLASS()(PyObject* meth) { 1914 return borrowed((cast(PyMethodObject*)meth).im_class); 1915 } 1916 1917 int PyClass_IsSubclass(PyObject *, PyObject *); 1918 1919 version(Python_2_6_Or_Later){ 1920 int PyMethod_ClearFreeList(); 1921 } 1922 1923 1924 /////////////////////////////////////////////////////////////////////////////// 1925 // FILE INTERFACE 1926 /////////////////////////////////////////////////////////////////////////////// 1927 // Python-header-file: Include/fileobject.h: 1928 1929 struct PyFileObject { 1930 mixin PyObject_HEAD; 1931 1932 FILE *f_fp; 1933 PyObject *f_name; 1934 PyObject *f_mode; 1935 int function(FILE *) f_close; 1936 int f_softspace; 1937 int f_binary; 1938 char* f_buf; 1939 char* f_bufend; 1940 char* f_bufptr; 1941 char *f_setbuf; 1942 int f_univ_newline; 1943 int f_newlinetypes; 1944 int f_skipnextlf; 1945 PyObject *f_encoding; 1946 version(Python_2_6_Or_Later){ 1947 PyObject *f_errors; 1948 } 1949 PyObject *weakreflist; 1950 version(Python_2_6_Or_Later){ 1951 int unlocked_count; /* Num. currently running sections of code 1952 using f_fp with the GIL released. */ 1953 int readable; 1954 int writable; 1955 } 1956 } 1957 1958 // &PyFile_Type is accessible via PyFile_Type_p. 1959 // D translation of C macro: 1960 int PyFile_Check()(PyObject *op) { 1961 return PyObject_TypeCheck(op, PyFile_Type_p); 1962 } 1963 // D translation of C macro: 1964 int PyFile_CheckExact()(PyObject *op) { 1965 return op.ob_type == PyFile_Type_p; 1966 } 1967 1968 PyObject * PyFile_FromString(char *, char *); 1969 void PyFile_SetBufSize(PyObject *, int); 1970 int PyFile_SetEncoding(PyObject *, const(char) *); 1971 version(Python_2_6_Or_Later){ 1972 int PyFile_SetEncodingAndErrors(PyObject *, const(char)*, const(char)*errors); 1973 } 1974 PyObject * PyFile_FromFile(FILE *, char *, char *, 1975 int function(FILE *)); 1976 FILE * PyFile_AsFile(PyObject *); 1977 version(Python_2_6_Or_Later){ 1978 void PyFile_IncUseCount(PyFileObject *); 1979 void PyFile_DecUseCount(PyFileObject *); 1980 } 1981 Borrowed!PyObject* PyFile_Name(PyObject*); 1982 PyObject * PyFile_GetLine(PyObject *, int); 1983 int PyFile_WriteObject(PyObject *, PyObject *, int); 1984 int PyFile_SoftSpace(PyObject *, int); 1985 int PyFile_WriteString(const(char)*, PyObject *); 1986 int PyObject_AsFileDescriptor(PyObject *); 1987 1988 // We deal with char *Py_FileSystemDefaultEncoding in the global variables 1989 // section toward the bottom of this file. 1990 1991 enum PY_STDIOTEXTMODE = "b"; 1992 1993 char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *); 1994 size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *); 1995 1996 1997 /////////////////////////////////////////////////////////////////////////////// 1998 // COBJECT INTERFACE 1999 /////////////////////////////////////////////////////////////////////////////// 2000 // Python-header-file: Include/cobject.h: 2001 2002 // PyCObject_Type is a Python type for transporting an arbitrary C pointer 2003 // from the C level to Python and back (in essence, an opaque handle). 2004 2005 // &PyCObject_Type is accessible via PyCObject_Type_p. 2006 // D translation of C macro: 2007 int PyCObject_Check()(PyObject *op) { 2008 return op.ob_type == PyCObject_Type_p; 2009 } 2010 2011 PyObject * PyCObject_FromVoidPtr(void *cobj, void function(void*) destruct); 2012 PyObject * PyCObject_FromVoidPtrAndDesc(void *cobj, void *desc, 2013 void function(void*,void*) destruct); 2014 void * PyCObject_AsVoidPtr(PyObject *); 2015 void * PyCObject_GetDesc(PyObject *); 2016 void * PyCObject_Import(char *module_name, char *cobject_name); 2017 int PyCObject_SetVoidPtr(PyObject *self, void *cobj); 2018 2019 version(Python_2_6_Or_Later){ 2020 struct PyCObject { 2021 mixin PyObject_HEAD; 2022 void *cobject; 2023 void *desc; 2024 void function(void *) destructor; 2025 }; 2026 } 2027 2028 2029 /////////////////////////////////////////////////////////////////////////////////////////////// 2030 // TRACEBACK INTERFACE 2031 /////////////////////////////////////////////////////////////////////////////////////////////// 2032 // Python-header-file: Include/traceback.h: 2033 2034 struct PyTracebackObject { 2035 mixin PyObject_HEAD; 2036 2037 PyTracebackObject *tb_next; 2038 PyFrameObject *tb_frame; 2039 int tb_lasti; 2040 int tb_lineno; 2041 } 2042 2043 int PyTraceBack_Here(PyFrameObject *); 2044 int PyTraceBack_Print(PyObject *, PyObject *); 2045 version(Python_2_6_Or_Later){ 2046 int _Py_DisplaySourceLine(PyObject *, const(char)*, int, int); 2047 } 2048 2049 // &PyTraceBack_Type is accessible via PyTraceBack_Type_p. 2050 // D translation of C macro: 2051 int PyTraceBack_Check()(PyObject *v) { 2052 return v.ob_type == PyTraceBack_Type_p; 2053 } 2054 2055 2056 /////////////////////////////////////////////////////////////////////////////// 2057 // SLICE INTERFACE 2058 /////////////////////////////////////////////////////////////////////////////// 2059 // Python-header-file: Include/sliceobject.h: 2060 2061 // We deal with Py_Ellipsis in the global variables section toward the bottom 2062 // of this file. 2063 2064 struct PySliceObject { 2065 mixin PyObject_HEAD; 2066 2067 PyObject *start; 2068 PyObject *stop; 2069 PyObject *step; 2070 } 2071 2072 // &PySlice_Type is accessible via PySlice_Type_p. 2073 // D translation of C macro: 2074 int PySlice_Check()(PyObject *op) { 2075 return op.ob_type == PySlice_Type_p; 2076 } 2077 2078 PyObject * PySlice_New(PyObject *start, PyObject *stop, PyObject *step); 2079 int PySlice_GetIndices(PySliceObject *r, Py_ssize_t length, 2080 Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step); 2081 int PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length, 2082 Py_ssize_t *start, Py_ssize_t *stop, 2083 Py_ssize_t *step, Py_ssize_t *slicelength); 2084 2085 2086 /////////////////////////////////////////////////////////////////////////////// 2087 // CELL INTERFACE 2088 /////////////////////////////////////////////////////////////////////////////// 2089 // Python-header-file: Include/cellobject.h: 2090 2091 struct PyCellObject { 2092 mixin PyObject_HEAD; 2093 2094 PyObject *ob_ref; 2095 } 2096 2097 // &PyCell_Type is accessible via PyCell_Type_p. 2098 // D translation of C macro: 2099 int PyCell_Check()(PyObject *op) { 2100 return op.ob_type == PyCell_Type_p; 2101 } 2102 2103 PyObject * PyCell_New(PyObject *); 2104 PyObject * PyCell_Get(PyObject *); 2105 int PyCell_Set(PyObject *, PyObject *); 2106 2107 2108 /////////////////////////////////////////////////////////////////////////////// 2109 // ITERATOR INTERFACE 2110 /////////////////////////////////////////////////////////////////////////////// 2111 // Python-header-file: Include/iterobject.h: 2112 2113 // &PySeqIter_Type is accessible via PySeqIter_Type_p. 2114 // D translation of C macro: 2115 int PySeqIter_Check()(PyObject *op) { 2116 return op.ob_type == PySeqIter_Type_p; 2117 } 2118 2119 PyObject * PySeqIter_New(PyObject *); 2120 2121 // &PyCallIter_Type is accessible via PyCallIter_Type_p. 2122 // D translation of C macro: 2123 int PyCallIter_Check()(PyObject *op) { 2124 return op.ob_type == PyCallIter_Type_p; 2125 } 2126 2127 PyObject * PyCallIter_New(PyObject *, PyObject *); 2128 2129 2130 /////////////////////////////////////////////////////////////////////////////// 2131 // DESCRIPTOR INTERFACE 2132 /////////////////////////////////////////////////////////////////////////////// 2133 // Python-header-file: Include/descrobject.h: 2134 2135 alias PyObject* function(PyObject *, void *) getter; 2136 alias int function(PyObject *, PyObject *, void *) setter; 2137 2138 struct PyGetSetDef { 2139 char *name; 2140 getter get; 2141 setter set; 2142 char *doc; 2143 void *closure; 2144 } 2145 2146 alias PyObject* function(PyObject *, PyObject *, void *) wrapperfunc; 2147 alias PyObject* function(PyObject *, PyObject *, void *, PyObject *) wrapperfunc_kwds; 2148 2149 struct wrapperbase { 2150 char *name; 2151 int offset; 2152 void *function_; 2153 wrapperfunc wrapper; 2154 char *doc; 2155 int flags; 2156 PyObject *name_strobj; 2157 } 2158 2159 enum PyWrapperFlag_KEYWORDS = 1; 2160 2161 template PyDescr_COMMON() { 2162 mixin PyObject_HEAD; 2163 PyTypeObject *d_type; 2164 PyObject *d_name; 2165 } 2166 2167 struct PyDescrObject { 2168 mixin PyDescr_COMMON; 2169 } 2170 2171 struct PyMethodDescrObject { 2172 mixin PyDescr_COMMON; 2173 PyMethodDef *d_method; 2174 } 2175 2176 struct PyMemberDescrObject { 2177 mixin PyDescr_COMMON; 2178 PyMemberDef *d_member; 2179 } 2180 2181 struct PyGetSetDescrObject { 2182 mixin PyDescr_COMMON; 2183 PyGetSetDef *d_getset; 2184 } 2185 2186 struct PyWrapperDescrObject { 2187 mixin PyDescr_COMMON; 2188 wrapperbase *d_base; 2189 void *d_wrapped; 2190 } 2191 2192 // PyWrapperDescr_Type is currently not accessible from D. 2193 version(Python_2_6_Or_Later){ 2194 // nor PyDictProxy_Type; 2195 // norPyGetSetDescr_Type; 2196 // nor PyMemberDescr_Type; 2197 } 2198 2199 PyObject * PyDescr_NewMethod(PyTypeObject *, PyMethodDef *); 2200 PyObject * PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *); 2201 PyObject * PyDescr_NewMember(PyTypeObject *, PyMemberDef *); 2202 PyObject * PyDescr_NewGetSet(PyTypeObject *, PyGetSetDef *); 2203 PyObject * PyDescr_NewWrapper(PyTypeObject *, wrapperbase *, void *); 2204 PyObject * PyDictProxy_New(PyObject *); 2205 PyObject * PyWrapper_New(PyObject *, PyObject *); 2206 2207 // &PyProperty_Type is accessible via PyProperty_Type_p. 2208 2209 2210 /////////////////////////////////////////////////////////////////////////////// 2211 // WEAK REFERENCE INTERFACE 2212 /////////////////////////////////////////////////////////////////////////////// 2213 // Python-header-file: Include/weakrefobject.h: 2214 2215 struct PyWeakReference { 2216 mixin PyObject_HEAD; 2217 2218 PyObject *wr_object; 2219 PyObject *wr_callback; 2220 C_long hash; 2221 PyWeakReference *wr_prev; 2222 PyWeakReference *wr_next; 2223 } 2224 2225 // &_PyWeakref_RefType is accessible via _PyWeakref_RefType_p. 2226 // &_PyWeakref_ProxyType is accessible via _PyWeakref_ProxyType_p. 2227 // &_PyWeakref_CallableProxyType is accessible via _PyWeakref_CallableProxyType_p. 2228 2229 // D translations of C macros: 2230 int PyWeakref_CheckRef()(PyObject *op) { 2231 return PyObject_TypeCheck(op, _PyWeakref_RefType_p); 2232 } 2233 int PyWeakref_CheckRefExact()(PyObject *op) { 2234 return op.ob_type == _PyWeakref_RefType_p; 2235 } 2236 int PyWeakref_CheckProxy()(PyObject *op) { 2237 return op.ob_type == _PyWeakref_ProxyType_p 2238 || op.ob_type == _PyWeakref_CallableProxyType_p; 2239 } 2240 int PyWeakref_Check()(PyObject *op) { 2241 return PyWeakref_CheckRef(op) || PyWeakref_CheckProxy(op); 2242 } 2243 2244 PyObject* PyWeakref_NewRef(PyObject* ob, PyObject* callback); 2245 PyObject* PyWeakref_NewProxy(PyObject* ob, PyObject* callback); 2246 Borrowed!PyObject* PyWeakref_GetObject(PyObject* _ref); 2247 2248 version(Python_2_5_Or_Later){ 2249 Py_ssize_t _PyWeakref_GetWeakrefCount(PyWeakReference* head); 2250 }else{ 2251 C_long _PyWeakref_GetWeakrefCount(PyWeakReference *head); 2252 } 2253 void _PyWeakref_ClearRef(PyWeakReference *self); 2254 2255 Borrowed!PyObject* PyWeakref_GET_OBJECT()(PyObject* _ref) { 2256 return (cast(PyWeakReference *) _ref).wr_object; 2257 } 2258 2259 2260 /////////////////////////////////////////////////////////////////////////////// 2261 // CODEC REGISTRY AND SUPPORT INTERFACE 2262 /////////////////////////////////////////////////////////////////////////////// 2263 // Python-header-file: Include/codecs.h: 2264 2265 int PyCodec_Register(PyObject *search_function); 2266 PyObject * _PyCodec_Lookup(const(char)*encoding); 2267 PyObject * PyCodec_Encode(PyObject *object, const(char)*encoding, const(char)*errors); 2268 PyObject * PyCodec_Decode(PyObject *object, const(char)*encoding, const(char)*errors); 2269 PyObject * PyCodec_Encoder(const(char)*encoding); 2270 PyObject * PyCodec_Decoder(const(char) *encoding); 2271 PyObject * PyCodec_StreamReader(const(char) *encoding, PyObject *stream, const(char) *errors); 2272 PyObject * PyCodec_StreamWriter(const(char) *encoding, PyObject *stream, const(char) *errors); 2273 2274 ///////////////////////////////////////////////////////////////////////////// 2275 // UNICODE ENCODING INTERFACE 2276 ///////////////////////////////////////////////////////////////////////////// 2277 2278 int PyCodec_RegisterError(const(char) *name, PyObject *error); 2279 PyObject * PyCodec_LookupError(const(char) *name); 2280 PyObject * PyCodec_StrictErrors(PyObject *exc); 2281 PyObject * PyCodec_IgnoreErrors(PyObject *exc); 2282 PyObject * PyCodec_ReplaceErrors(PyObject *exc); 2283 PyObject * PyCodec_XMLCharRefReplaceErrors(PyObject *exc); 2284 PyObject * PyCodec_BackslashReplaceErrors(PyObject *exc); 2285 2286 2287 /////////////////////////////////////////////////////////////////////////////// 2288 // ERROR HANDLING INTERFACE 2289 /////////////////////////////////////////////////////////////////////////////// 2290 // Python-header-file: Include/pyerrors.h: 2291 2292 version(Python_2_5_Or_Later){ 2293 /* Error objects */ 2294 2295 struct PyBaseExceptionObject { 2296 mixin PyObject_HEAD; 2297 PyObject *dict; 2298 PyObject *args; 2299 PyObject *message; 2300 } 2301 2302 struct PySyntaxErrorObject { 2303 mixin PyObject_HEAD; 2304 PyObject *dict; 2305 PyObject *args; 2306 PyObject *message; 2307 PyObject *msg; 2308 PyObject *filename; 2309 PyObject *lineno; 2310 PyObject *offset; 2311 PyObject *text; 2312 PyObject *print_file_and_line; 2313 } 2314 2315 struct PyUnicodeErrorObject { 2316 mixin PyObject_HEAD; 2317 PyObject *dict; 2318 PyObject *args; 2319 PyObject *message; 2320 PyObject *encoding; 2321 PyObject *object; 2322 version(Python_2_6_Or_Later){ 2323 Py_ssize_t start; 2324 Py_ssize_t end; 2325 }else{ 2326 PyObject *start; 2327 PyObject *end; 2328 } 2329 PyObject *reason; 2330 } 2331 2332 struct PySystemExitObject { 2333 mixin PyObject_HEAD; 2334 PyObject *dict; 2335 PyObject *args; 2336 PyObject *message; 2337 PyObject *code; 2338 } 2339 2340 struct PyEnvironmentErrorObject { 2341 mixin PyObject_HEAD; 2342 PyObject *dict; 2343 PyObject *args; 2344 PyObject *message; 2345 PyObject *myerrno; 2346 PyObject *strerror; 2347 PyObject *filename; 2348 } 2349 2350 version(Windows) { 2351 struct PyWindowsErrorObject { 2352 mixin PyObject_HEAD; 2353 PyObject *dict; 2354 PyObject *args; 2355 PyObject *message; 2356 PyObject *myerrno; 2357 PyObject *strerror; 2358 PyObject *filename; 2359 PyObject *winerror; 2360 } 2361 } 2362 } 2363 2364 void PyErr_SetNone(PyObject *); 2365 void PyErr_SetObject(PyObject *, PyObject *); 2366 void PyErr_SetString(PyObject *, const(char) *); 2367 PyObject * PyErr_Occurred(); 2368 void PyErr_Clear(); 2369 void PyErr_Fetch(PyObject **, PyObject **, PyObject **); 2370 void PyErr_Restore(PyObject *, PyObject *, PyObject *); 2371 2372 int PyErr_GivenExceptionMatches(PyObject *, PyObject *); 2373 int PyErr_ExceptionMatches(PyObject *); 2374 void PyErr_NormalizeException(PyObject **, PyObject **, PyObject **); 2375 2376 // All predefined Python exception types are dealt with in the global 2377 // variables section toward the end of this file. 2378 2379 int PyErr_BadArgument(); 2380 PyObject * PyErr_NoMemory(); 2381 PyObject * PyErr_SetFromErrno(PyObject *); 2382 PyObject * PyErr_SetFromErrnoWithFilenameObject(PyObject *, PyObject *); 2383 PyObject * PyErr_SetFromErrnoWithFilename(PyObject *, char *); 2384 PyObject * PyErr_SetFromErrnoWithUnicodeFilename(PyObject *, Py_UNICODE *); 2385 2386 PyObject * PyErr_Format(PyObject *, const(char) *, ...); 2387 2388 version (Windows) { 2389 PyObject * PyErr_SetFromWindowsErrWithFilenameObject(int, const(char) *); 2390 PyObject * PyErr_SetFromWindowsErrWithFilename(int, const(char) *); 2391 PyObject * PyErr_SetFromWindowsErrWithUnicodeFilename(int, Py_UNICODE *); 2392 PyObject * PyErr_SetFromWindowsErr(int); 2393 PyObject * PyErr_SetExcFromWindowsErrWithFilenameObject(PyObject *, int, PyObject *); 2394 PyObject * PyErr_SetExcFromWindowsErrWithFilename(PyObject *, int, const(char) *); 2395 PyObject * PyErr_SetExcFromWindowsErrWithUnicodeFilename(PyObject *, int, Py_UNICODE *); 2396 PyObject * PyErr_SetExcFromWindowsErr(PyObject *, int); 2397 } 2398 2399 // PyErr_BadInternalCall and friends purposely omitted. 2400 2401 PyObject * PyErr_NewException(char *name, PyObject *base, PyObject *dict); 2402 void PyErr_WriteUnraisable(PyObject *); 2403 2404 version(Python_2_5_Or_Later){ 2405 int PyErr_WarnEx(PyObject*, char*, Py_ssize_t); 2406 }else{ 2407 int PyErr_Warn(PyObject *, char *); 2408 } 2409 int PyErr_WarnExplicit(PyObject *, const(char) *, const(char) *, int, const(char) *, PyObject *); 2410 2411 int PyErr_CheckSignals(); 2412 void PyErr_SetInterrupt(); 2413 2414 void PyErr_SyntaxLocation(const(char) *, int); 2415 PyObject * PyErr_ProgramText(const(char) *, int); 2416 2417 ///////////////////////////////////////////////////////////////////////////// 2418 // UNICODE ENCODING ERROR HANDLING INTERFACE 2419 ///////////////////////////////////////////////////////////////////////////// 2420 PyObject *PyUnicodeDecodeError_Create(const(char) *, const(char) *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const(char) *); 2421 2422 PyObject *PyUnicodeEncodeError_Create(const(char) *, Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const(char) *); 2423 2424 PyObject *PyUnicodeTranslateError_Create(Py_UNICODE *, Py_ssize_t, Py_ssize_t, Py_ssize_t, const(char) *); 2425 2426 PyObject *PyUnicodeEncodeError_GetEncoding(PyObject *); 2427 PyObject *PyUnicodeDecodeError_GetEncoding(PyObject *); 2428 2429 PyObject *PyUnicodeEncodeError_GetObject(PyObject *); 2430 PyObject *PyUnicodeDecodeError_GetObject(PyObject *); 2431 PyObject *PyUnicodeTranslateError_GetObject(PyObject *); 2432 2433 int PyUnicodeEncodeError_GetStart(PyObject *, Py_ssize_t *); 2434 int PyUnicodeDecodeError_GetStart(PyObject *, Py_ssize_t *); 2435 int PyUnicodeTranslateError_GetStart(PyObject *, Py_ssize_t *); 2436 2437 int PyUnicodeEncodeError_SetStart(PyObject *, Py_ssize_t); 2438 int PyUnicodeDecodeError_SetStart(PyObject *, Py_ssize_t); 2439 int PyUnicodeTranslateError_SetStart(PyObject *, Py_ssize_t); 2440 2441 int PyUnicodeEncodeError_GetEnd(PyObject *, Py_ssize_t *); 2442 int PyUnicodeDecodeError_GetEnd(PyObject *, Py_ssize_t *); 2443 int PyUnicodeTranslateError_GetEnd(PyObject *, Py_ssize_t *); 2444 2445 int PyUnicodeEncodeError_SetEnd(PyObject *, Py_ssize_t); 2446 int PyUnicodeDecodeError_SetEnd(PyObject *, Py_ssize_t); 2447 int PyUnicodeTranslateError_SetEnd(PyObject *, Py_ssize_t); 2448 2449 PyObject *PyUnicodeEncodeError_GetReason(PyObject *); 2450 PyObject *PyUnicodeDecodeError_GetReason(PyObject *); 2451 PyObject *PyUnicodeTranslateError_GetReason(PyObject *); 2452 2453 int PyUnicodeEncodeError_SetReason(PyObject *, const(char) *); 2454 int PyUnicodeDecodeError_SetReason(PyObject *, const(char) *); 2455 int PyUnicodeTranslateError_SetReason(PyObject *, const(char) *); 2456 2457 int PyOS_snprintf(char *str, size_t size, const(char) *format, ...); 2458 int PyOS_vsnprintf(char *str, size_t size, const(char) *format, va_list va); 2459 2460 2461 /////////////////////////////////////////////////////////////////////////////// 2462 // BYTECODE INTERFACE 2463 /////////////////////////////////////////////////////////////////////////////// 2464 // Python-header-file: Include/code.h: 2465 2466 struct PyCodeObject { /* Bytecode object */ 2467 mixin PyObject_HEAD; 2468 2469 int co_argcount; 2470 int co_nlocals; 2471 int co_stacksize; 2472 int co_flags; 2473 PyObject *co_code; 2474 PyObject *co_consts; 2475 PyObject *co_names; 2476 PyObject *co_varnames; 2477 PyObject *co_freevars; 2478 PyObject *co_cellvars; 2479 2480 PyObject *co_filename; 2481 PyObject *co_name; 2482 int co_firstlineno; 2483 PyObject *co_lnotab; 2484 version(Python_2_5_Or_Later){ 2485 void *co_zombieframe; 2486 } 2487 2488 } 2489 2490 /* Masks for co_flags above */ 2491 enum int CO_OPTIMIZED = 0x0001; 2492 enum int CO_NEWLOCALS = 0x0002; 2493 enum int CO_VARARGS = 0x0004; 2494 enum int CO_VARKEYWORDS = 0x0008; 2495 enum int CO_NESTED = 0x0010; 2496 enum int CO_GENERATOR = 0x0020; 2497 enum int CO_NOFREE = 0x0040; 2498 2499 version(Python_2_5_Or_Later){ 2500 // Removed in 2.5 2501 }else{ 2502 enum int CO_GENERATOR_ALLOWED = 0x1000; 2503 } 2504 enum int CO_FUTURE_DIVISION = 0x2000; 2505 version(Python_2_5_Or_Later){ 2506 enum int CO_FUTURE_ABSOLUTE_IMPORT = 0x4000; 2507 enum int CO_FUTURE_WITH_STATEMENT = 0x8000; 2508 enum int CO_FUTURE_PRINT_FUNCTION = 0x10000; 2509 enum int CO_FUTURE_UNICODE_LITERALS = 0x20000; 2510 } 2511 2512 enum int CO_MAXBLOCKS = 20; 2513 2514 // &PyCode_Type is accessible via PyCode_Type_p. 2515 // D translations of C macros: 2516 int PyCode_Check()(PyObject *op) { 2517 return op.ob_type == PyCode_Type_p; 2518 } 2519 size_t PyCode_GetNumFree()(PyObject *op) { 2520 return PyObject_Length((cast(PyCodeObject *) op).co_freevars); 2521 } 2522 2523 PyCodeObject *PyCode_New( 2524 int, int, int, int, PyObject *, PyObject *, PyObject *, PyObject *, 2525 PyObject *, PyObject *, PyObject *, PyObject *, int, PyObject *); 2526 int PyCode_Addr2Line(PyCodeObject *, int); 2527 2528 struct PyAddrPair { 2529 int ap_lower; 2530 int ap_upper; 2531 } 2532 2533 int PyCode_CheckLineNumber(PyCodeObject* co, int lasti, PyAddrPair *bounds); 2534 version(Python_2_6_Or_Later){ 2535 PyObject* PyCode_Optimize(PyObject *code, PyObject* consts, 2536 PyObject *names, PyObject *lineno_obj); 2537 } 2538 2539 // Python-header-file: Include/pyarena.h: 2540 struct PyArena; 2541 2542 version(Python_2_5_Or_Later){ 2543 PyArena* PyArena_New(); 2544 void PyArena_Free(PyArena*); 2545 2546 void* PyArena_Malloc(PyArena*, size_t); 2547 int PyArena_AddPyObject(PyArena*, PyObject*); 2548 } 2549 2550 /////////////////////////////////////////////////////////////////////////////// 2551 // COMPILATION INTERFACE 2552 /////////////////////////////////////////////////////////////////////////////// 2553 // Python-header-file: Include/node.h 2554 struct node { 2555 short n_type; 2556 char *n_str; 2557 int n_lineno; 2558 version(Python_2_5_Or_Later){ 2559 int n_col_offset; 2560 } 2561 int n_nchildren; 2562 node *n_child; 2563 } 2564 node * PyNode_New(int type); 2565 int PyNode_AddChild(node *n, int type, 2566 char *str, int lineno, int col_offset); 2567 void PyNode_Free(node *n); 2568 void PyNode_ListTree(node *); 2569 2570 // Python-header-file: Include/compile.h: 2571 PyCodeObject *PyNode_Compile(node *, const(char) *); 2572 2573 struct PyFutureFeatures { 2574 version(Python_2_5_Or_Later){ 2575 }else{ 2576 int ff_found_docstring; 2577 int ff_last_linno; 2578 } 2579 int ff_features; 2580 version(Python_2_5_Or_Later){ 2581 int ff_lineno; 2582 } 2583 } 2584 2585 version(Python_2_5_Or_Later){ 2586 }else{ 2587 PyFutureFeatures *PyNode_Future(node *, const(char) *); 2588 PyCodeObject *PyNode_CompileFlags(node *, const(char) *, PyCompilerFlags *); 2589 } 2590 2591 enum FUTURE_NESTED_SCOPES = "nested_scopes"; 2592 enum FUTURE_GENERATORS = "generators"; 2593 enum FUTURE_DIVISION = "division"; 2594 version(Python_2_5_Or_Later){ 2595 enum FUTURE_ABSOLUTE_IMPORT = "absolute_import"; 2596 enum FUTURE_WITH_STATEMENT = "with_statement"; 2597 version(Python_2_6_Or_Later){ 2598 enum FUTURE_PRINT_FUNCTION = "print_function"; 2599 enum FUTURE_UNICODE_LITERALS = "unicode_literals"; 2600 } 2601 2602 struct _mod; /* Declare the existence of this type */ 2603 PyCodeObject * PyAST_Compile(_mod *, const(char) *, PyCompilerFlags *, PyArena *); 2604 PyFutureFeatures * PyFuture_FromAST(_mod *, const(char) *); 2605 2606 // Python-header-file: Include/ast.h 2607 _mod* PyAST_FromNode(node*, PyCompilerFlags*, const(char)*, PyArena*); 2608 } 2609 2610 2611 /////////////////////////////////////////////////////////////////////////////// 2612 // CODE EXECUTION INTERFACE 2613 /////////////////////////////////////////////////////////////////////////////// 2614 // Python-header-file: Include/pythonrun.h: 2615 2616 struct PyCompilerFlags { 2617 int cf_flags; 2618 } 2619 2620 void Py_SetProgramName(char *); 2621 char *Py_GetProgramName(); 2622 2623 void Py_SetPythonHome(char *); 2624 char *Py_GetPythonHome(); 2625 2626 void Py_Initialize(); 2627 void Py_InitializeEx(int); 2628 void Py_Finalize(); 2629 int Py_IsInitialized(); 2630 PyThreadState *Py_NewInterpreter(); 2631 void Py_EndInterpreter(PyThreadState *); 2632 2633 version(Python_2_5_Or_Later){ 2634 int PyRun_AnyFile()(FILE *fp, const(char) *name) { 2635 return PyRun_AnyFileExFlags(fp, name, 0, null); 2636 } 2637 int PyRun_AnyFileEx()(FILE *fp, const(char) *name, int closeit) { 2638 return PyRun_AnyFileExFlags(fp, name, closeit, null); 2639 } 2640 int PyRun_AnyFileFlags()(FILE *fp, const(char) *name, PyCompilerFlags *flags) { 2641 return PyRun_AnyFileExFlags(fp, name, 0, flags); 2642 } 2643 int PyRun_SimpleString()(const(char) *s) { 2644 return PyRun_SimpleStringFlags(s, null); 2645 } 2646 int PyRun_SimpleFile()(FILE *f, const(char) *p) { 2647 return PyRun_SimpleFileExFlags(f, p, 0, null); 2648 } 2649 int PyRun_SimpleFileEx()(FILE *f, const(char) *p, int c) { 2650 return PyRun_SimpleFileExFlags(f, p, c, null); 2651 } 2652 int PyRun_InteractiveOne()(FILE *f, const(char) *p) { 2653 return PyRun_InteractiveOneFlags(f, p, null); 2654 } 2655 int PyRun_InteractiveLoop()(FILE *f, const(char) *p) { 2656 return PyRun_InteractiveLoopFlags(f, p, null); 2657 } 2658 }else{ 2659 int PyRun_AnyFile(FILE *, const(char) *); 2660 int PyRun_AnyFileEx(FILE *, const(char) *,int); 2661 2662 int PyRun_AnyFileFlags(FILE *, const(char) *, PyCompilerFlags *); 2663 int PyRun_SimpleString(const(char) *); 2664 int PyRun_SimpleFile(FILE *, const(char) *); 2665 int PyRun_SimpleFileEx(FILE *, const(char) *, int); 2666 int PyRun_InteractiveOne(FILE *, const(char) *); 2667 int PyRun_InteractiveLoop(FILE *, const(char) *); 2668 } 2669 2670 int PyRun_AnyFileExFlags(FILE *, const(char) *, int, PyCompilerFlags *); 2671 2672 int PyRun_SimpleStringFlags(const(char) *, PyCompilerFlags *); 2673 2674 int PyRun_SimpleFileExFlags(FILE *, const(char) *, int, PyCompilerFlags *); 2675 2676 int PyRun_InteractiveOneFlags(FILE *, const(char) *, PyCompilerFlags *); 2677 int PyRun_InteractiveLoopFlags(FILE *, const(char) *, PyCompilerFlags *); 2678 2679 version(Python_2_5_Or_Later){ 2680 _mod* PyParser_ASTFromString(const(char) *, const(char) *, 2681 int, PyCompilerFlags *, PyArena *); 2682 _mod* PyParser_ASTFromFile(FILE *, const(char) *, int, 2683 char *, char *, PyCompilerFlags *, int *, PyArena *); 2684 node *PyParser_SimpleParseString()(const(char) *s, int b) { 2685 return PyParser_SimpleParseStringFlags(s, b, 0); 2686 } 2687 node *PyParser_SimpleParseFile()(FILE *f, const(char) *s, int b) { 2688 return PyParser_SimpleParseFileFlags(f, s, b, 0); 2689 } 2690 }else{ 2691 node *PyParser_SimpleParseString(const(char) *, int); 2692 node *PyParser_SimpleParseFile(FILE *, const(char) *, int); 2693 node *PyParser_SimpleParseStringFlagsFilename(const(char) *, const(char) *, int, int); 2694 } 2695 2696 node *PyParser_SimpleParseStringFlags(const(char) *, int, int); 2697 node *PyParser_SimpleParseFileFlags(FILE *, const(char) *,int, int); 2698 2699 PyObject *PyRun_StringFlags( const(char) *, int, PyObject *, PyObject *, PyCompilerFlags *); 2700 version(Python_2_5_Or_Later){ 2701 PyObject *PyRun_String()(const(char) *str, int s, PyObject *g, PyObject *l) { 2702 return PyRun_StringFlags(str, s, g, l, null); 2703 } 2704 PyObject *PyRun_File()(FILE *fp, const(char) *p, int s, PyObject *g, PyObject *l) { 2705 return PyRun_FileExFlags(fp, p, s, g, l, 0, null); 2706 } 2707 PyObject *PyRun_FileEx()(FILE *fp, const(char) *p, int s, PyObject *g, PyObject *l, int c) { 2708 return PyRun_FileExFlags(fp, p, s, g, l, c, null); 2709 } 2710 PyObject *PyRun_FileFlags()(FILE *fp, const(char) *p, int s, PyObject *g, 2711 PyObject *l, PyCompilerFlags *flags) { 2712 return PyRun_FileExFlags(fp, p, s, g, l, 0, flags); 2713 } 2714 PyObject *Py_CompileString()(const(char) *str, const(char) *p, int s) { 2715 return Py_CompileStringFlags(str, p, s, null); 2716 } 2717 }else{ 2718 PyObject *PyRun_String(const(char) *, int, PyObject *, PyObject *); 2719 PyObject *PyRun_File(FILE *, const(char) *, int, PyObject *, PyObject *); 2720 PyObject *PyRun_FileEx(FILE *, const(char) *, int, PyObject *, PyObject *, int); 2721 PyObject *PyRun_FileFlags(FILE *, const(char) *, int, PyObject *, PyObject *, 2722 PyCompilerFlags *); 2723 PyObject *Py_CompileString(const(char) *, const(char) *, int); 2724 } 2725 2726 PyObject *PyRun_FileExFlags(FILE *, const(char) *, int, PyObject *, PyObject *, int, PyCompilerFlags *); 2727 2728 PyObject *Py_CompileStringFlags(const(char) *, const(char) *, int, PyCompilerFlags *); 2729 // Py_SymtableString is undocumented, so it's omitted here. 2730 2731 void PyErr_Print(); 2732 void PyErr_PrintEx(int); 2733 void PyErr_Display(PyObject *, PyObject *, PyObject *); 2734 2735 int Py_AtExit(void function() func); 2736 2737 void Py_Exit(int); 2738 2739 int Py_FdIsInteractive(FILE *, const(char) *); 2740 2741 /////////////////////////////////////////////////////////////////////////////// 2742 // BOOTSTRAPPING INTERFACE (for embedding Python in D) 2743 /////////////////////////////////////////////////////////////////////////////// 2744 // Python-header-file: Include/pythonrun.h: 2745 2746 int Py_Main(int argc, char **argv); 2747 2748 char *Py_GetProgramFullPath(); 2749 char *Py_GetPrefix(); 2750 char *Py_GetExecPrefix(); 2751 char *Py_GetPath(); 2752 2753 const(char) *Py_GetVersion(); 2754 const(char) *Py_GetPlatform(); 2755 const(char) *Py_GetCopyright(); 2756 const(char) *Py_GetCompiler(); 2757 const(char) *Py_GetBuildInfo(); 2758 version(Python_2_5_Or_Later){ 2759 const(char) * _Py_svnversion(); 2760 const(char) * Py_SubversionRevision(); 2761 const(char) * Py_SubversionShortBranch(); 2762 } 2763 2764 version(Python_2_6_Or_Later){ 2765 int PyByteArray_Init(); 2766 } 2767 2768 ///////////////////////////////////////////////////////////////////////////// 2769 // ONE-TIME INITIALIZERS 2770 ///////////////////////////////////////////////////////////////////////////// 2771 2772 PyObject *_PyBuiltin_Init(); 2773 PyObject *_PySys_Init(); 2774 void _PyImport_Init(); 2775 void _PyExc_Init(); 2776 void _PyImportHooks_Init(); 2777 int _PyFrame_Init(); 2778 int _PyInt_Init(); 2779 2780 ///////////////////////////////////////////////////////////////////////////// 2781 // FINALIZERS 2782 ///////////////////////////////////////////////////////////////////////////// 2783 2784 void _PyExc_Fini(); 2785 void _PyImport_Fini(); 2786 void PyMethod_Fini(); 2787 void PyFrame_Fini(); 2788 void PyCFunction_Fini(); 2789 version(Python_2_6_Or_Later){ 2790 void PyDict_Fini(); 2791 } 2792 void PyTuple_Fini(); 2793 void PyString_Fini(); 2794 void PyInt_Fini(); 2795 void PyFloat_Fini(); 2796 void PyOS_FiniInterrupts(); 2797 version(Python_2_6_Or_Later){ 2798 void PyByteArray_Fini(); 2799 } 2800 2801 ///////////////////////////////////////////////////////////////////////////// 2802 // VARIOUS (API members documented as having "no proper home") 2803 ///////////////////////////////////////////////////////////////////////////// 2804 char *PyOS_Readline(FILE *, FILE *, char *); 2805 __gshared int function() PyOS_InputHook; 2806 __gshared char* function(FILE *, FILE *, char *) PyOS_ReadlineFunctionPointer; 2807 // _PyOS_ReadlineTState omitted. 2808 enum PYOS_STACK_MARGIN = 2048; 2809 // PyOS_CheckStack omitted. 2810 2811 ///////////////////////////////////////////////////////////////////////////// 2812 // SIGNALS 2813 ///////////////////////////////////////////////////////////////////////////// 2814 2815 alias void function(int) PyOS_sighandler_t; 2816 PyOS_sighandler_t PyOS_getsig(int); 2817 PyOS_sighandler_t PyOS_setsig(int, PyOS_sighandler_t); 2818 2819 2820 /////////////////////////////////////////////////////////////////////////////// 2821 // EVAL CALLS (documented as "Interface to random parts in ceval.c") 2822 /////////////////////////////////////////////////////////////////////////////// 2823 // Python-header-file: Include/ceval.h: 2824 PyObject *PyEval_CallObjectWithKeywords(PyObject *, PyObject *, PyObject *); 2825 version(Python_2_5_Or_Later){ 2826 PyObject *PyEval_CallObject()(PyObject *func, PyObject *arg) { 2827 return PyEval_CallObjectWithKeywords(func, arg, null); 2828 } 2829 }else{ 2830 PyObject *PyEval_CallObject(PyObject *, PyObject *); 2831 } 2832 PyObject *PyEval_CallFunction(PyObject *obj, Char1 *format, ...); 2833 PyObject *PyEval_CallMethod(PyObject *obj, Char1 *methodname, Char1 *format, ...); 2834 2835 void PyEval_SetProfile(Py_tracefunc, PyObject *); 2836 void PyEval_SetTrace(Py_tracefunc, PyObject *); 2837 2838 Borrowed!PyObject* PyEval_GetBuiltins(); 2839 Borrowed!PyObject* PyEval_GetGlobals(); 2840 Borrowed!PyObject* PyEval_GetLocals(); 2841 Borrowed!PyFrameObject* PyEval_GetFrame(); 2842 int PyEval_GetRestricted(); 2843 2844 int PyEval_MergeCompilerFlags(PyCompilerFlags *cf); 2845 int Py_FlushLine(); 2846 int Py_AddPendingCall(int function(void *) func, void *arg); 2847 int Py_MakePendingCalls(); 2848 2849 void Py_SetRecursionLimit(int); 2850 int Py_GetRecursionLimit(); 2851 2852 // The following API members are undocumented, so they're omitted here: 2853 // Py_EnterRecursiveCall 2854 // Py_LeaveRecursiveCall 2855 // _Py_CheckRecursiveCall 2856 // _Py_CheckRecursionLimit 2857 // _Py_MakeRecCheck 2858 2859 Char1 *PyEval_GetFuncName(PyObject *); 2860 Char1 *PyEval_GetFuncDesc(PyObject *); 2861 2862 PyObject *PyEval_GetCallStats(PyObject *); 2863 PyObject *PyEval_EvalFrame(PyFrameObject *); 2864 version(Python_2_5_Or_Later){ 2865 PyObject *PyEval_EvalFrameEx(PyFrameObject *, int); 2866 } 2867 2868 2869 /////////////////////////////////////////////////////////////////////////////// 2870 // SYSTEM MODULE INTERFACE 2871 /////////////////////////////////////////////////////////////////////////////// 2872 // Python-header-file: Include/sysmodule.h: 2873 2874 PyObject *PySys_GetObject(char *); 2875 int PySys_SetObject(char *, PyObject *); 2876 FILE *PySys_GetFile(char *, FILE *); 2877 void PySys_SetArgv(int, char **); 2878 version(Python_2_6_Or_Later){ 2879 void PySys_SetArgvEx(int, char **, int); 2880 } 2881 void PySys_SetPath(char *); 2882 2883 void PySys_WriteStdout(const(char) *format, ...); 2884 void PySys_WriteStderr(const(char) *format, ...); 2885 2886 void PySys_ResetWarnOptions(); 2887 void PySys_AddWarnOption(char *); 2888 version(Python_2_6_Or_Later){ 2889 int PySys_HasWarnOptions(); 2890 } 2891 2892 2893 /////////////////////////////////////////////////////////////////////////////// 2894 // INTERRUPT INTERFACE 2895 /////////////////////////////////////////////////////////////////////////////// 2896 // Python-header-file: Include/intrcheck.h: 2897 2898 int PyOS_InterruptOccurred(); 2899 void PyOS_InitInterrupts(); 2900 void PyOS_AfterFork(); 2901 2902 2903 /////////////////////////////////////////////////////////////////////////////// 2904 // FRAME INTERFACE 2905 /////////////////////////////////////////////////////////////////////////////// 2906 // Python-header-file: Include/frameobject.h: 2907 2908 struct PyTryBlock { 2909 int b_type; 2910 int b_handler; 2911 int b_level; 2912 } 2913 2914 struct PyFrameObject { 2915 mixin PyObject_VAR_HEAD; 2916 2917 PyFrameObject *f_back; 2918 PyCodeObject *f_code; 2919 PyObject *f_builtins; 2920 PyObject *f_globals; 2921 PyObject *f_locals; 2922 PyObject **f_valuestack; 2923 PyObject **f_stacktop; 2924 PyObject *f_trace; 2925 PyObject *f_exc_type; 2926 PyObject *f_exc_value; 2927 PyObject *f_exc_traceback; 2928 PyThreadState *f_tstate; 2929 int f_lasti; 2930 int f_lineno; 2931 version(Python_2_5_Or_Later){ 2932 }else{ 2933 int f_restricted; 2934 } 2935 int f_iblock; 2936 PyTryBlock f_blockstack[CO_MAXBLOCKS]; 2937 version(Python_2_5_Or_Later){ 2938 }else{ 2939 int f_nlocals; 2940 int f_ncells; 2941 int f_nfreevars; 2942 int f_stacksize; 2943 } 2944 PyObject *_f_localsplus[1]; 2945 PyObject** f_localsplus()() { 2946 return _f_localsplus.ptr; 2947 } 2948 } 2949 2950 // &PyFrame_Type is accessible via PyFrame_Type_p. 2951 // D translation of C macro: 2952 int PyFrame_Check()(PyObject *op) { 2953 return op.ob_type == PyFrame_Type_p; 2954 } 2955 version(Python_2_5_Or_Later){ 2956 int PyFrame_IsRestricted()(PyFrameObject* f) { 2957 return f.f_builtins != f.f_tstate.interp.builtins; 2958 } 2959 } 2960 2961 PyFrameObject *PyFrame_New(PyThreadState *, PyCodeObject *, 2962 PyObject *, PyObject *); 2963 2964 void PyFrame_BlockSetup(PyFrameObject *, int, int, int); 2965 PyTryBlock *PyFrame_BlockPop(PyFrameObject *); 2966 PyObject **PyFrame_ExtendStack(PyFrameObject *, int, int); 2967 2968 void PyFrame_LocalsToFast(PyFrameObject *, int); 2969 void PyFrame_FastToLocals(PyFrameObject *); 2970 version(Python_2_6_Or_Later){ 2971 int PyFrame_ClearFreeList(); 2972 } 2973 2974 2975 /////////////////////////////////////////////////////////////////////////////// 2976 // INTERPRETER STATE AND THREAD STATE INTERFACES 2977 /////////////////////////////////////////////////////////////////////////////// 2978 // Python-header-file: Include/pystate.h: 2979 2980 struct PyInterpreterState { 2981 PyInterpreterState *next; 2982 PyThreadState *tstate_head; 2983 2984 PyObject *modules; 2985 PyObject *sysdict; 2986 PyObject *builtins; 2987 2988 PyObject *codec_search_path; 2989 PyObject *codec_search_cache; 2990 PyObject *codec_error_registry; 2991 2992 int dlopenflags; 2993 2994 // XXX: Not sure what WITH_TSC refers to, or how to conditionalize it in D: 2995 //#ifdef WITH_TSC 2996 // int tscdump; 2997 //#endif 2998 } 2999 3000 alias int function(PyObject *, PyFrameObject *, int, PyObject *) Py_tracefunc; 3001 3002 enum PyTrace_CALL = 0; 3003 enum PyTrace_EXCEPTION = 1; 3004 enum PyTrace_LINE = 2; 3005 enum PyTrace_RETURN = 3; 3006 enum PyTrace_C_CALL = 4; 3007 enum PyTrace_C_EXCEPTION = 5; 3008 enum PyTrace_C_RETURN = 6; 3009 3010 struct PyThreadState { 3011 PyThreadState *next; 3012 PyInterpreterState *interp; 3013 3014 PyFrameObject *frame; 3015 int recursion_depth; 3016 int tracing; 3017 int use_tracing; 3018 3019 Py_tracefunc c_profilefunc; 3020 Py_tracefunc c_tracefunc; 3021 PyObject *c_profileobj; 3022 PyObject *c_traceobj; 3023 3024 PyObject *curexc_type; 3025 PyObject *curexc_value; 3026 PyObject *curexc_traceback; 3027 3028 PyObject *exc_type; 3029 PyObject *exc_value; 3030 PyObject *exc_traceback; 3031 3032 PyObject *dict; 3033 3034 int tick_counter; 3035 int gilstate_counter; 3036 3037 PyObject *async_exc; 3038 C_long thread_id; 3039 } 3040 3041 PyInterpreterState *PyInterpreterState_New(); 3042 void PyInterpreterState_Clear(PyInterpreterState *); 3043 void PyInterpreterState_Delete(PyInterpreterState *); 3044 3045 PyThreadState *PyThreadState_New(PyInterpreterState *); 3046 version(Python_2_6_Or_Later){ 3047 PyThreadState * _PyThreadState_Prealloc(PyInterpreterState *); 3048 void _PyThreadState_Init(PyThreadState *); 3049 } 3050 void PyThreadState_Clear(PyThreadState *); 3051 void PyThreadState_Delete(PyThreadState *); 3052 void PyThreadState_DeleteCurrent(); 3053 3054 PyThreadState* PyThreadState_Get(); 3055 PyThreadState* PyThreadState_Swap(PyThreadState *); 3056 Borrowed!PyObject* PyThreadState_GetDict(); 3057 int PyThreadState_SetAsyncExc(C_long, PyObject *); 3058 3059 enum PyGILState_STATE {PyGILState_LOCKED, PyGILState_UNLOCKED}; 3060 3061 PyGILState_STATE PyGILState_Ensure(); 3062 void PyGILState_Release(PyGILState_STATE); 3063 PyThreadState *PyGILState_GetThisThreadState(); 3064 PyInterpreterState *PyInterpreterState_Head(); 3065 PyInterpreterState *PyInterpreterState_Next(PyInterpreterState *); 3066 PyThreadState *PyInterpreterState_ThreadHead(PyInterpreterState *); 3067 PyThreadState *PyThreadState_Next(PyThreadState *); 3068 3069 alias PyFrameObject* function(PyThreadState *self_) PyThreadFrameGetter; 3070 3071 // Python-header-file: Include/ceval.h: 3072 PyThreadState *PyEval_SaveThread(); 3073 void PyEval_RestoreThread(PyThreadState *); 3074 3075 int PyEval_ThreadsInitialized(); 3076 void PyEval_InitThreads(); 3077 void PyEval_AcquireLock(); 3078 void PyEval_ReleaseLock(); 3079 void PyEval_AcquireThread(PyThreadState *tstate); 3080 void PyEval_ReleaseThread(PyThreadState *tstate); 3081 void PyEval_ReInitThreads(); 3082 3083 // YYY: The following macros need to be implemented somehow, but DSR doesn't 3084 // think D's mixin feature is up to the job. 3085 // Py_BEGIN_ALLOW_THREADS 3086 // Py_BLOCK_THREADS 3087 // Py_UNBLOCK_THREADS 3088 // Py_END_ALLOW_THREADS 3089 3090 3091 /////////////////////////////////////////////////////////////////////////////// 3092 // MODULE IMPORT INTERFACE 3093 /////////////////////////////////////////////////////////////////////////////// 3094 // Python-header-file: Include/import.h: 3095 3096 C_long PyImport_GetMagicNumber(); 3097 PyObject *PyImport_ExecCodeModule(char *name, PyObject *co); 3098 PyObject *PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname); 3099 PyObject *PyImport_GetModuleDict(); 3100 PyObject *PyImport_AddModule(Char1 *name); 3101 PyObject *PyImport_ImportModule(Char1 *name); 3102 3103 version(Python_2_5_Or_Later){ 3104 PyObject *PyImport_ImportModuleLevel(char *name, 3105 PyObject *globals, PyObject *locals, PyObject *fromlist, 3106 int level); 3107 } 3108 version(Python_2_6_Or_Later){ 3109 PyObject * PyImport_ImportModuleNoBlock(const(char)*); 3110 }else version(Python_2_5_Or_Later){ 3111 PyObject *PyImport_ImportModuleEx()(char *n, PyObject *g, PyObject *l, 3112 PyObject *f) { 3113 return PyImport_ImportModuleLevel(n, g, l, f, -1); 3114 } 3115 }else{ 3116 PyObject *PyImport_ImportModuleEx(char *, PyObject *, PyObject *, PyObject *); 3117 } 3118 3119 version(Python_2_6_Or_Later){ 3120 PyObject * PyImport_GetImporter(PyObject *path); 3121 } 3122 PyObject *PyImport_Import(PyObject *name); 3123 PyObject *PyImport_ReloadModule(PyObject *m); 3124 void PyImport_Cleanup(); 3125 int PyImport_ImportFrozenModule(char *); 3126 3127 // The following API members are undocumented, so they're omitted here: 3128 // _PyImport_FindModule 3129 // _PyImport_IsScript 3130 // _PyImport_ReInitLock 3131 3132 PyObject *_PyImport_FindExtension(char *, char *); 3133 PyObject *_PyImport_FixupExtension(char *, char *); 3134 3135 struct _inittab { 3136 char *name; 3137 void function() initfunc; 3138 } 3139 3140 // PyNullImporter_Type not available in d 3141 // PyImport_Inittab not available in d 3142 3143 version(Python_2_7_Or_Later){ 3144 alias const(char) Char2; 3145 }else{ 3146 alias char Char2; 3147 } 3148 3149 int PyImport_AppendInittab(Char2 *name, void function() initfunc); 3150 int PyImport_ExtendInittab(_inittab *newtab); 3151 3152 struct _frozen { 3153 char *name; 3154 ubyte *code; 3155 int size; 3156 } 3157 3158 // Omitted: 3159 // PyImport_FrozenModules 3160 3161 3162 /////////////////////////////////////////////////////////////////////////////// 3163 // ABSTRACT OBJECT INTERFACE 3164 /////////////////////////////////////////////////////////////////////////////// 3165 // Python-header-file: Include/abstract.h: 3166 3167 // D translations of C macros: 3168 int PyObject_DelAttrString()(PyObject *o, Char1 *a) { 3169 return PyObject_SetAttrString(o, a, null); 3170 } 3171 int PyObject_DelAttr()(PyObject *o, PyObject *a) { 3172 return PyObject_SetAttr(o, a, null); 3173 } 3174 3175 int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result); 3176 3177 ///////////////////////////////////////////////////////////////////////////// 3178 // CALLABLES 3179 ///////////////////////////////////////////////////////////////////////////// 3180 int PyCallable_Check(PyObject *o); 3181 3182 PyObject *PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw); 3183 PyObject *PyObject_CallObject(PyObject *callable_object, PyObject *args); 3184 version(Python_2_5_Or_Later){ 3185 }else{ 3186 PyObject *PyObject_CallFunction(PyObject *callable_object, char *format, ...); 3187 PyObject *PyObject_CallMethod(PyObject *o, char *m, char *format, ...); 3188 } 3189 PyObject *_PyObject_CallFunction_SizeT(PyObject *callable, char *format, ...); 3190 PyObject *_PyObject_CallMethod_SizeT(PyObject *o, char *name, char *format, ...); 3191 version(Python_2_5_Or_Later){ 3192 alias _PyObject_CallFunction_SizeT PyObject_CallFunction; 3193 alias _PyObject_CallMethod_SizeT PyObject_CallMethod; 3194 } 3195 PyObject *PyObject_CallFunctionObjArgs(PyObject *callable, ...); 3196 PyObject *PyObject_CallMethodObjArgs(PyObject *o,PyObject *m, ...); 3197 3198 ///////////////////////////////////////////////////////////////////////////// 3199 // GENERIC 3200 ///////////////////////////////////////////////////////////////////////////// 3201 PyObject *PyObject_Type(PyObject *o); 3202 3203 ///////////////////////////////////////////////////////////////////////////// 3204 // CONTAINERS 3205 ///////////////////////////////////////////////////////////////////////////// 3206 3207 Py_ssize_t PyObject_Size(PyObject *o); 3208 //int PyObject_Length(PyObject *o); 3209 alias PyObject_Size PyObject_Length; 3210 version(Python_2_6_Or_Later){ 3211 Py_ssize_t _PyObject_LengthHint(PyObject*, Py_ssize_t); 3212 }else version(Python_2_5_Or_Later){ 3213 Py_ssize_t _PyObject_LengthHint(PyObject*); 3214 } 3215 3216 PyObject *PyObject_GetItem(PyObject *o, PyObject *key); 3217 int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); 3218 int PyObject_DelItemString(PyObject *o, char *key); 3219 int PyObject_DelItem(PyObject *o, PyObject *key); 3220 3221 int PyObject_AsCharBuffer(PyObject *obj, const(char) **buffer, Py_ssize_t *buffer_len); 3222 int PyObject_CheckReadBuffer(PyObject *obj); 3223 int PyObject_AsReadBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len); 3224 int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len); 3225 3226 version(Python_2_6_Or_Later){ 3227 /* new buffer API */ 3228 3229 int PyObject_CheckBuffer()(PyObject *obj){ 3230 return (obj.ob_type.tp_as_buffer !is null) && 3231 PyType_HasFeature(obj.ob_type, Py_TPFLAGS_HAVE_NEWBUFFER) && 3232 (obj.ob_type.tp_as_buffer.bf_getbuffer !is null); 3233 } 3234 3235 /* Return 1 if the getbuffer function is available, otherwise 3236 return 0 */ 3237 3238 int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, 3239 int flags); 3240 3241 /* This is a C-API version of the getbuffer function call. It checks 3242 to make sure object has the required function pointer and issues the 3243 call. Returns -1 and raises an error on failure and returns 0 on 3244 success 3245 */ 3246 3247 3248 void* PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices); 3249 3250 /* Get the memory area pointed to by the indices for the buffer given. 3251 Note that view->ndim is the assumed size of indices 3252 */ 3253 3254 int PyBuffer_SizeFromFormat(const(char) *); 3255 3256 /* Return the implied itemsize of the data-format area from a 3257 struct-style description */ 3258 3259 3260 3261 int PyBuffer_ToContiguous(void *buf, Py_buffer *view, 3262 Py_ssize_t len, char fort); 3263 3264 int PyBuffer_FromContiguous(Py_buffer *view, void *buf, 3265 Py_ssize_t len, char fort); 3266 3267 3268 /* Copy len bytes of data from the contiguous chunk of memory 3269 pointed to by buf into the buffer exported by obj. Return 3270 0 on success and return -1 and raise a PyBuffer_Error on 3271 error (i.e. the object does not have a buffer interface or 3272 it is not working). 3273 3274 If fort is 'F' and the object is multi-dimensional, 3275 then the data will be copied into the array in 3276 Fortran-style (first dimension varies the fastest). If 3277 fort is 'C', then the data will be copied into the array 3278 in C-style (last dimension varies the fastest). If fort 3279 is 'A', then it does not matter and the copy will be made 3280 in whatever way is more efficient. 3281 3282 */ 3283 3284 int PyObject_CopyData(PyObject *dest, PyObject *src); 3285 3286 /* Copy the data from the src buffer to the buffer of destination 3287 */ 3288 3289 int PyBuffer_IsContiguous(Py_buffer *view, char fort); 3290 3291 3292 void PyBuffer_FillContiguousStrides(int ndims, 3293 Py_ssize_t *shape, 3294 Py_ssize_t *strides, 3295 int itemsize, 3296 char fort); 3297 3298 /* Fill the strides array with byte-strides of a contiguous 3299 (Fortran-style if fort is 'F' or C-style otherwise) 3300 array of the given shape with the given number of bytes 3301 per element. 3302 */ 3303 3304 int PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf, 3305 Py_ssize_t len, int readonly, 3306 int flags); 3307 3308 /* Fills in a buffer-info structure correctly for an exporter 3309 that can only share a contiguous chunk of memory of 3310 "unsigned bytes" of the given length. Returns 0 on success 3311 and -1 (with raising an error) on error. 3312 */ 3313 3314 void PyBuffer_Release(Py_buffer *view); 3315 3316 /* Releases a Py_buffer obtained from getbuffer ParseTuple's s*. 3317 */ 3318 3319 PyObject* PyObject_Format(PyObject* obj, 3320 PyObject *format_spec); 3321 /* 3322 Takes an arbitrary object and returns the result of 3323 calling obj.__format__(format_spec). 3324 */ 3325 3326 } 3327 3328 ///////////////////////////////////////////////////////////////////////////// 3329 // ITERATORS 3330 ///////////////////////////////////////////////////////////////////////////// 3331 PyObject *PyObject_GetIter(PyObject *); 3332 3333 // D translation of C macro: 3334 int PyIter_Check()(PyObject *obj) { 3335 return PyType_HasFeature(obj.ob_type, Py_TPFLAGS_HAVE_ITER) 3336 && obj.ob_type.tp_iternext != null; 3337 } 3338 3339 PyObject *PyIter_Next(PyObject *); 3340 3341 ///////////////////////////////////////////////////////////////////////////// 3342 // NUMBERS 3343 ///////////////////////////////////////////////////////////////////////////// 3344 3345 int PyNumber_Check(PyObject *o); 3346 3347 PyObject *PyNumber_Add(PyObject *o1, PyObject *o2); 3348 PyObject *PyNumber_Subtract(PyObject *o1, PyObject *o2); 3349 PyObject *PyNumber_Multiply(PyObject *o1, PyObject *o2); 3350 PyObject *PyNumber_Divide(PyObject *o1, PyObject *o2); 3351 PyObject *PyNumber_FloorDivide(PyObject *o1, PyObject *o2); 3352 PyObject *PyNumber_TrueDivide(PyObject *o1, PyObject *o2); 3353 PyObject *PyNumber_Remainder(PyObject *o1, PyObject *o2); 3354 PyObject *PyNumber_Divmod(PyObject *o1, PyObject *o2); 3355 PyObject *PyNumber_Power(PyObject *o1, PyObject *o2, PyObject *o3); 3356 PyObject *PyNumber_Negative(PyObject *o); 3357 PyObject *PyNumber_Positive(PyObject *o); 3358 PyObject *PyNumber_Absolute(PyObject *o); 3359 PyObject *PyNumber_Invert(PyObject *o); 3360 PyObject *PyNumber_Lshift(PyObject *o1, PyObject *o2); 3361 PyObject *PyNumber_Rshift(PyObject *o1, PyObject *o2); 3362 PyObject *PyNumber_And(PyObject *o1, PyObject *o2); 3363 PyObject *PyNumber_Xor(PyObject *o1, PyObject *o2); 3364 PyObject *PyNumber_Or(PyObject *o1, PyObject *o2); 3365 3366 version(Python_2_5_Or_Later){ 3367 int PyIndex_Check()(PyObject* obj) { 3368 return obj.ob_type.tp_as_number !is null && 3369 PyType_HasFeature(obj.ob_type, Py_TPFLAGS_HAVE_INDEX) && 3370 obj.ob_type.tp_as_number.nb_index !is null; 3371 } 3372 PyObject *PyNumber_Index(PyObject *o); 3373 Py_ssize_t PyNumber_AsSsize_t(PyObject* o, PyObject* exc); 3374 } 3375 version(Python_2_6_Or_Later){ 3376 /* 3377 Returns the Integral instance converted to an int. The 3378 instance is expected to be int or long or have an __int__ 3379 method. Steals integral's reference. error_format will be 3380 used to create the TypeError if integral isn't actually an 3381 Integral instance. error_format should be a format string 3382 that can accept a char* naming integral's type. 3383 */ 3384 3385 PyObject * _PyNumber_ConvertIntegralToInt( 3386 PyObject *integral, 3387 const(char)* error_format); 3388 } 3389 3390 PyObject *PyNumber_Int(PyObject *o); 3391 PyObject *PyNumber_Long(PyObject *o); 3392 PyObject *PyNumber_Float(PyObject *o); 3393 3394 PyObject *PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); 3395 PyObject *PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); 3396 PyObject *PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); 3397 PyObject *PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2); 3398 PyObject *PyNumber_InPlaceFloorDivide(PyObject *o1, PyObject *o2); 3399 PyObject *PyNumber_InPlaceTrueDivide(PyObject *o1, PyObject *o2); 3400 PyObject *PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); 3401 PyObject *PyNumber_InPlacePower(PyObject *o1, PyObject *o2, PyObject *o3); 3402 PyObject *PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); 3403 PyObject *PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); 3404 PyObject *PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); 3405 PyObject *PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); 3406 PyObject *PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); 3407 3408 version(Python_2_6_Or_Later){ 3409 PyObject* PyNumber_ToBase(PyObject *n, int base); 3410 3411 /* 3412 Returns the integer n converted to a string with a base, with a base 3413 marker of 0b, 0o or 0x prefixed if applicable. 3414 If n is not an int object, it is converted with PyNumber_Index first. 3415 */ 3416 } 3417 3418 ///////////////////////////////////////////////////////////////////////////// 3419 // SEQUENCES 3420 ///////////////////////////////////////////////////////////////////////////// 3421 3422 int PySequence_Check(PyObject *o); 3423 Py_ssize_t PySequence_Size(PyObject *o); 3424 alias PySequence_Size PySequence_Length; 3425 3426 PyObject *PySequence_Concat(PyObject *o1, PyObject *o2); 3427 PyObject *PySequence_Repeat(PyObject *o, Py_ssize_t count); 3428 PyObject *PySequence_GetItem(PyObject *o, Py_ssize_t i); 3429 PyObject *PySequence_GetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 3430 3431 int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); 3432 int PySequence_DelItem(PyObject *o, Py_ssize_t i); 3433 int PySequence_SetSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2, PyObject *v); 3434 int PySequence_DelSlice(PyObject *o, Py_ssize_t i1, Py_ssize_t i2); 3435 3436 PyObject *PySequence_Tuple(PyObject *o); 3437 PyObject *PySequence_List(PyObject *o); 3438 3439 PyObject *PySequence_Fast(PyObject *o, const(char)* m); 3440 // D translations of C macros: 3441 Py_ssize_t PySequence_Fast_GET_SIZE()(PyObject *o) { 3442 return PyList_Check(o) ? cast(Py_ssize_t) PyList_GET_SIZE(o) : 3443 cast(Py_ssize_t) PyTuple_GET_SIZE(o); 3444 } 3445 PyObject *PySequence_Fast_GET_ITEM()(PyObject *o, Py_ssize_t i) { 3446 return PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i); 3447 } 3448 PyObject *PySequence_ITEM()(PyObject *o, Py_ssize_t i) { 3449 return o.ob_type.tp_as_sequence.sq_item(o, i); 3450 } 3451 PyObject **PySequence_Fast_ITEMS()(PyObject *sf) { 3452 return 3453 PyList_Check(sf) ? 3454 (cast(PyListObject *)sf).ob_item 3455 : (cast(PyTupleObject *)sf).ob_item 3456 ; 3457 } 3458 3459 Py_ssize_t PySequence_Count(PyObject *o, PyObject *value); 3460 int PySequence_Contains(PyObject *seq, PyObject *ob); 3461 3462 int PY_ITERSEARCH_COUNT = 1; 3463 int PY_ITERSEARCH_INDEX = 2; 3464 int PY_ITERSEARCH_CONTAINS = 3; 3465 3466 Py_ssize_t _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation); 3467 //int PySequence_In(PyObject *o, PyObject *value); 3468 alias PySequence_Contains PySequence_In; 3469 Py_ssize_t PySequence_Index(PyObject *o, PyObject *value); 3470 3471 PyObject * PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); 3472 PyObject * PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count); 3473 3474 ///////////////////////////////////////////////////////////////////////////// 3475 // MAPPINGS 3476 ///////////////////////////////////////////////////////////////////////////// 3477 int PyMapping_Check(PyObject *o); 3478 Py_ssize_t PyMapping_Size(PyObject *o); 3479 //int PyMapping_Length(PyObject *o); 3480 alias PyMapping_Size PyMapping_Length; 3481 3482 // D translations of C macros: 3483 int PyMapping_DelItemString()(PyObject *o, char *k) { 3484 return PyObject_DelItemString(o, k); 3485 } 3486 int PyMapping_DelItem()(PyObject *o, PyObject *k) { 3487 return PyObject_DelItem(o, k); 3488 } 3489 3490 int PyMapping_HasKeyString(PyObject *o, char *key); 3491 int PyMapping_HasKey(PyObject *o, PyObject *key); 3492 3493 // D translations of C macros: 3494 PyObject *PyMapping_Keys()(PyObject *o) { 3495 return PyObject_CallMethod(o, "keys".dup.ptr, null); 3496 } 3497 PyObject *PyMapping_Values()(PyObject *o) { 3498 return PyObject_CallMethod(o, "values".dup.ptr, null); 3499 } 3500 PyObject *PyMapping_Items()(PyObject *o) { 3501 return PyObject_CallMethod(o, "items".dup.ptr, null); 3502 } 3503 3504 PyObject *PyMapping_GetItemString(PyObject *o, char *key); 3505 int PyMapping_SetItemString(PyObject *o, char *key, PyObject *value); 3506 3507 ///////////////////////////////////////////////////////////////////////////// 3508 // GENERIC 3509 ///////////////////////////////////////////////////////////////////////////// 3510 int PyObject_IsInstance(PyObject *object, PyObject *typeorclass); 3511 int PyObject_IsSubclass(PyObject *object, PyObject *typeorclass); 3512 3513 version(Python_2_6_Or_Later){ 3514 int _PyObject_RealIsInstance(PyObject *inst, PyObject *cls); 3515 3516 int _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls); 3517 } 3518 3519 3520 /////////////////////////////////////////////////////////////////////////////// 3521 // OBJECT CREATION AND GARBAGE COLLECTION 3522 /////////////////////////////////////////////////////////////////////////////// 3523 // Python-header-file: Include/objimpl.h: 3524 3525 void * PyObject_Malloc(size_t); 3526 void * PyObject_Realloc(void *, size_t); 3527 void PyObject_Free(void *); 3528 3529 Borrowed!PyObject* PyObject_Init(PyObject*, PyTypeObject*); 3530 3531 Borrowed!PyVarObject* PyObject_InitVar(PyVarObject*, 3532 PyTypeObject *, Py_ssize_t); 3533 /* Without macros, DSR knows of no way to translate PyObject_New and 3534 * PyObject_NewVar to D; the lower-level _PyObject_New and _PyObject_NewVar 3535 * will have to suffice. 3536 * YYY: Perhaps D's mixins could be used? 3537 * KGM: Pfft, it's a simple template function. */ 3538 PyObject * _PyObject_New(PyTypeObject *); 3539 PyVarObject * _PyObject_NewVar(PyTypeObject *, Py_ssize_t); 3540 type* PyObject_New(type)(PyTypeObject* o) { 3541 return cast(type*)_PyObject_New(o); 3542 } 3543 type* PyObject_NewVar(type)(PyTypeObject* o, Py_ssize_t n) { 3544 return cast(type*)_PyObject_NewVar(o, n); 3545 } 3546 3547 3548 C_long PyGC_Collect(); 3549 3550 // D translations of C macros: 3551 int PyType_IS_GC()(PyTypeObject *t) { 3552 return PyType_HasFeature(t, Py_TPFLAGS_HAVE_GC); 3553 } 3554 int PyObject_IS_GC()(PyObject *o) { 3555 return PyType_IS_GC(o.ob_type) 3556 && (o.ob_type.tp_is_gc == null || o.ob_type.tp_is_gc(o)); 3557 } 3558 PyVarObject *_PyObject_GC_Resize(PyVarObject *, Py_ssize_t); 3559 // XXX: Can D mixins allows trans of PyObject_GC_Resize? 3560 // KGM: No, but template functions can. 3561 type* PyObject_GC_Resize(type) (PyVarObject *op, Py_ssize_t n) { 3562 return cast(type*)_PyObject_GC_Resize(op, n); 3563 } 3564 3565 3566 union PyGC_Head { 3567 struct gc { 3568 PyGC_Head *gc_next; 3569 PyGC_Head *gc_prev; 3570 Py_ssize_t gc_refs; 3571 } 3572 real dummy; // XXX: C type was long double; is this equiv? 3573 } 3574 3575 // Numerous macro definitions that appear in objimpl.h at this point are not 3576 // document. They appear to be for internal use, so they're omitted here. 3577 3578 PyObject *_PyObject_GC_Malloc(size_t); 3579 PyObject *_PyObject_GC_New(PyTypeObject *); 3580 PyVarObject *_PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t); 3581 void PyObject_GC_Track(void *); 3582 void PyObject_GC_UnTrack(void *); 3583 void PyObject_GC_Del(void *); 3584 3585 // XXX: DSR currently knows of no way to translate the PyObject_GC_New and 3586 // PyObject_GC_NewVar macros to D. 3587 // KGM does, though. 3588 type* PyObject_GC_New(type) (PyTypeObject* o) { 3589 return cast(type*)_PyObject_GC_New(o); 3590 } 3591 type* PyObject_GC_NewVar(type) (PyTypeObject* o, Py_ssize_t n) { 3592 return cast(type*)_PyObject_GC_NewVar(o, n); 3593 } 3594 3595 ///////////////////////////////////////////////////////////////////////////// 3596 // MISCELANEOUS 3597 ///////////////////////////////////////////////////////////////////////////// 3598 // Python-header-file: Include/pydebug.h: 3599 void Py_FatalError(char *message); 3600 3601 3602 /////////////////////////////////////////////////////////////////////////////// 3603 // cStringIO (Must be explicitly imported with PycString_IMPORT().) 3604 /////////////////////////////////////////////////////////////////////////////// 3605 // Python-header-file: Include/cStringIO.h: 3606 3607 PycStringIO_CAPI *PycStringIO = null; 3608 3609 PycStringIO_CAPI *PycString_IMPORT()() { 3610 if (PycStringIO == null) { 3611 PycStringIO = cast(PycStringIO_CAPI *) 3612 PyCObject_Import("cStringIO".dup.ptr, "cStringIO_CAPI".dup.ptr); 3613 } 3614 return PycStringIO; 3615 } 3616 3617 struct PycStringIO_CAPI { 3618 int function(PyObject *, char **, Py_ssize_t) cread; 3619 int function(PyObject *, char **) creadline; 3620 int function(PyObject *, Char1 *, Py_ssize_t) cwrite; 3621 PyObject* function(PyObject *) cgetvalue; 3622 PyObject* function(int) NewOutput; 3623 PyObject* function(PyObject *) NewInput; 3624 PyTypeObject *InputType; 3625 PyTypeObject *OutputType; 3626 } 3627 3628 // D translations of C macros: 3629 int PycStringIO_InputCheck()(PyObject *o) { 3630 return o.ob_type == PycStringIO.InputType; 3631 } 3632 int PycStringIO_OutputCheck()(PyObject *o) { 3633 return o.ob_type == PycStringIO.OutputType; 3634 } 3635 3636 3637 /////////////////////////////////////////////////////////////////////////////// 3638 // datetime (Must be explicitly imported with PycString_IMPORT().) 3639 /////////////////////////////////////////////////////////////////////////////// 3640 // Python-header-file: Include/datetime.h: 3641 3642 enum _PyDateTime_DATE_DATASIZE = 4; 3643 enum _PyDateTime_TIME_DATASIZE = 6; 3644 enum _PyDateTime_DATETIME_DATASIZE = 10; 3645 3646 struct PyDateTime_Delta { 3647 mixin PyObject_HEAD; 3648 3649 C_long hashcode; 3650 int days; 3651 int seconds; 3652 int microseconds; 3653 } 3654 3655 struct PyDateTime_TZInfo { 3656 mixin PyObject_HEAD; 3657 } 3658 3659 template _PyTZINFO_HEAD() { 3660 mixin PyObject_HEAD; 3661 C_long hashcode; 3662 ubyte hastzinfo; 3663 } 3664 3665 struct _PyDateTime_BaseTZInfo { 3666 mixin _PyTZINFO_HEAD; 3667 } 3668 3669 template _PyDateTime_TIMEHEAD() { 3670 mixin _PyTZINFO_HEAD; 3671 ubyte data[_PyDateTime_TIME_DATASIZE]; 3672 } 3673 3674 struct _PyDateTime_BaseTime { 3675 mixin _PyDateTime_TIMEHEAD; 3676 } 3677 3678 struct PyDateTime_Time { 3679 mixin _PyDateTime_TIMEHEAD; 3680 PyObject *tzinfo; 3681 } 3682 3683 struct PyDateTime_Date { 3684 mixin _PyTZINFO_HEAD; 3685 ubyte data[_PyDateTime_DATE_DATASIZE]; 3686 } 3687 3688 template _PyDateTime_DATETIMEHEAD() { 3689 mixin _PyTZINFO_HEAD; 3690 ubyte data[_PyDateTime_DATETIME_DATASIZE]; 3691 } 3692 3693 struct _PyDateTime_BaseDateTime { 3694 mixin _PyDateTime_DATETIMEHEAD; 3695 } 3696 3697 struct PyDateTime_DateTime { 3698 mixin _PyDateTime_DATETIMEHEAD; 3699 PyObject *tzinfo; 3700 } 3701 3702 // D translations of C macros: 3703 int PyDateTime_GET_YEAR()(PyObject *o) { 3704 PyDateTime_Date *ot = cast(PyDateTime_Date *) o; 3705 return (ot.data[0] << 8) | ot.data[1]; 3706 } 3707 int PyDateTime_GET_MONTH()(PyObject *o) { 3708 PyDateTime_Date *ot = cast(PyDateTime_Date *) o; 3709 return ot.data[2]; 3710 } 3711 int PyDateTime_GET_DAY()(PyObject *o) { 3712 PyDateTime_Date *ot = cast(PyDateTime_Date *) o; 3713 return ot.data[3]; 3714 } 3715 3716 int PyDateTime_DATE_GET_HOUR()(PyObject *o) { 3717 PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o; 3718 return ot.data[4]; 3719 } 3720 int PyDateTime_DATE_GET_MINUTE()(PyObject *o) { 3721 PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o; 3722 return ot.data[5]; 3723 } 3724 int PyDateTime_DATE_GET_SECOND()(PyObject *o) { 3725 PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o; 3726 return ot.data[6]; 3727 } 3728 int PyDateTime_DATE_GET_MICROSECOND()(PyObject *o) { 3729 PyDateTime_DateTime *ot = cast(PyDateTime_DateTime *) o; 3730 return (ot.data[7] << 16) | (ot.data[8] << 8) | ot.data[9]; 3731 } 3732 3733 int PyDateTime_TIME_GET_HOUR()(PyObject *o) { 3734 PyDateTime_Time *ot = cast(PyDateTime_Time *) o; 3735 return ot.data[0]; 3736 } 3737 int PyDateTime_TIME_GET_MINUTE()(PyObject *o) { 3738 PyDateTime_Time *ot = cast(PyDateTime_Time *) o; 3739 return ot.data[1]; 3740 } 3741 int PyDateTime_TIME_GET_SECOND()(PyObject *o) { 3742 PyDateTime_Time *ot = cast(PyDateTime_Time *) o; 3743 return ot.data[2]; 3744 } 3745 int PyDateTime_TIME_GET_MICROSECOND()(PyObject *o) { 3746 PyDateTime_Time *ot = cast(PyDateTime_Time *) o; 3747 return (ot.data[3] << 16) | (ot.data[4] << 8) | ot.data[5]; 3748 } 3749 3750 struct PyDateTime_CAPI { 3751 PyTypeObject *DateType; 3752 PyTypeObject *DateTimeType; 3753 PyTypeObject *TimeType; 3754 PyTypeObject *DeltaType; 3755 PyTypeObject *TZInfoType; 3756 3757 PyObject* function(int, int, int, PyTypeObject*) Date_FromDate; 3758 PyObject* function(int, int, int, int, int, int, int, 3759 PyObject*, PyTypeObject*) DateTime_FromDateAndTime; 3760 PyObject* function(int, int, int, int, PyObject*, PyTypeObject*) Time_FromTime; 3761 PyObject* function(int, int, int, int, PyTypeObject*) Delta_FromDelta; 3762 3763 PyObject* function(PyObject*, PyObject*, PyObject*) DateTime_FromTimestamp; 3764 PyObject* function(PyObject*, PyObject*) Date_FromTimestamp; 3765 } 3766 3767 enum DATETIME_API_MAGIC = 0x414548d5; 3768 PyDateTime_CAPI *PyDateTimeAPI; 3769 3770 PyDateTime_CAPI *PyDateTime_IMPORT()() { 3771 if (PyDateTimeAPI == null) { 3772 PyDateTimeAPI = cast(PyDateTime_CAPI *) 3773 PyCObject_Import("datetime".dup.ptr, "datetime_CAPI".dup.ptr); 3774 } 3775 return PyDateTimeAPI; 3776 } 3777 3778 // D translations of C macros: 3779 int PyDate_Check()(PyObject *op) { 3780 return PyObject_TypeCheck(op, PyDateTimeAPI.DateType); 3781 } 3782 int PyDate_CheckExact()(PyObject *op) { 3783 return op.ob_type == PyDateTimeAPI.DateType; 3784 } 3785 int PyDateTime_Check()(PyObject *op) { 3786 return PyObject_TypeCheck(op, PyDateTimeAPI.DateTimeType); 3787 } 3788 int PyDateTime_CheckExact()(PyObject *op) { 3789 return op.ob_type == PyDateTimeAPI.DateTimeType; 3790 } 3791 int PyTime_Check()(PyObject *op) { 3792 return PyObject_TypeCheck(op, PyDateTimeAPI.TimeType); 3793 } 3794 int PyTime_CheckExact()(PyObject *op) { 3795 return op.ob_type == PyDateTimeAPI.TimeType; 3796 } 3797 int PyDelta_Check()(PyObject *op) { 3798 return PyObject_TypeCheck(op, PyDateTimeAPI.DeltaType); 3799 } 3800 int PyDelta_CheckExact()(PyObject *op) { 3801 return op.ob_type == PyDateTimeAPI.DeltaType; 3802 } 3803 int PyTZInfo_Check()(PyObject *op) { 3804 return PyObject_TypeCheck(op, PyDateTimeAPI.TZInfoType); 3805 } 3806 int PyTZInfo_CheckExact()(PyObject *op) { 3807 return op.ob_type == PyDateTimeAPI.TZInfoType; 3808 } 3809 3810 PyObject *PyDate_FromDate()(int year, int month, int day) { 3811 return PyDateTimeAPI.Date_FromDate(year, month, day, PyDateTimeAPI.DateType); 3812 } 3813 PyObject *PyDateTime_FromDateAndTime()(int year, int month, int day, int hour, int min, int sec, int usec) { 3814 return PyDateTimeAPI.DateTime_FromDateAndTime(year, month, day, hour, 3815 min, sec, usec, Py_None, PyDateTimeAPI.DateTimeType); 3816 } 3817 PyObject *PyTime_FromTime()(int hour, int minute, int second, int usecond) { 3818 return PyDateTimeAPI.Time_FromTime(hour, minute, second, usecond, 3819 Py_None, PyDateTimeAPI.TimeType); 3820 } 3821 PyObject *PyDelta_FromDSU()(int days, int seconds, int useconds) { 3822 return PyDateTimeAPI.Delta_FromDelta(days, seconds, useconds, 1, 3823 PyDateTimeAPI.DeltaType); 3824 } 3825 PyObject *PyDateTime_FromTimestamp()(PyObject *args) { 3826 return PyDateTimeAPI.DateTime_FromTimestamp( 3827 cast(PyObject*) (PyDateTimeAPI.DateTimeType), args, null); 3828 } 3829 PyObject *PyDate_FromTimestamp()(PyObject *args) { 3830 return PyDateTimeAPI.Date_FromTimestamp( 3831 cast(PyObject*) (PyDateTimeAPI.DateType), args); 3832 } 3833 3834 3835 /////////////////////////////////////////////////////////////////////////////// 3836 // Interface to execute compiled code 3837 /////////////////////////////////////////////////////////////////////////////// 3838 // Python-header-file: Include/eval.h: 3839 PyObject *PyEval_EvalCode(PyCodeObject *, PyObject *, PyObject *); 3840 PyObject *PyEval_EvalCodeEx( 3841 PyCodeObject *co, 3842 PyObject *globals, 3843 PyObject *locals, 3844 PyObject **args, int argc, 3845 PyObject **kwds, int kwdc, 3846 PyObject **defs, int defc, 3847 PyObject *closure 3848 ); 3849 PyObject *_PyEval_CallTracing(PyObject *func, PyObject *args); 3850 3851 3852 /////////////////////////////////////////////////////////////////////////////// 3853 // Generator object interface 3854 /////////////////////////////////////////////////////////////////////////////// 3855 // Python-header-file: Include/genobject.h: 3856 struct PyGenObject { 3857 mixin PyObject_HEAD; 3858 PyFrameObject *gi_frame; 3859 int gi_running; 3860 version(Python_2_6_Or_Later){ 3861 /* The code object backing the generator */ 3862 PyObject *gi_code; 3863 } 3864 PyObject *gi_weakreflist; 3865 } 3866 3867 // &PyGen_Type is accessible via PyGen_Type_p. 3868 // D translations of C macros: 3869 int PyGen_Check()(PyObject *op) { 3870 return PyObject_TypeCheck(op, PyGen_Type_p); 3871 } 3872 int PyGen_CheckExact()(PyObject *op) { 3873 return op.ob_type == PyGen_Type_p; 3874 } 3875 3876 PyObject *PyGen_New(PyFrameObject *); 3877 int PyGen_NeedsFinalizing(PyGenObject *); 3878 3879 3880 /////////////////////////////////////////////////////////////////////////////// 3881 // Interface for marshal.c 3882 /////////////////////////////////////////////////////////////////////////////// 3883 // Python-header-file: Include/marshal.h: 3884 3885 version(Python_2_5_Or_Later){ 3886 enum Py_MARSHAL_VERSION = 2; 3887 } else version(Python_2_4_Or_Later){ 3888 enum Py_MARSHAL_VERSION = 1; 3889 } 3890 3891 void PyMarshal_WriteLongToFile(C_long, FILE *, int); 3892 void PyMarshal_WriteObjectToFile(PyObject *, FILE *, int); 3893 PyObject * PyMarshal_WriteObjectToString(PyObject *, int); 3894 3895 C_long PyMarshal_ReadLongFromFile(FILE *); 3896 int PyMarshal_ReadShortFromFile(FILE *); 3897 PyObject *PyMarshal_ReadObjectFromFile(FILE *); 3898 PyObject *PyMarshal_ReadLastObjectFromFile(FILE *); 3899 PyObject *PyMarshal_ReadObjectFromString(char *, Py_ssize_t); 3900 3901 3902 /////////////////////////////////////////////////////////////////////////////// 3903 // Platform-independent wrappers around strod, etc (probably not needed in D) 3904 /////////////////////////////////////////////////////////////////////////////// 3905 // Python-header-file: Include/pystrtod.h: 3906 3907 double PyOS_ascii_strtod(const(char) *str, char **ptr); 3908 double PyOS_ascii_atof(const(char) *str); 3909 char *PyOS_ascii_formatd(char *buffer, size_t buf_len, const(char) *format, double d); 3910 3911 3912 /////////////////////////////////////////////////////////////////////////////// 3913 // INTERFACE TO THE STDLIB 'THREAD' MODULE 3914 /////////////////////////////////////////////////////////////////////////////// 3915 // Python-header-file: Include/pythread.h: 3916 3917 alias void * PyThread_type_lock; 3918 alias void * PyThread_type_sema; 3919 3920 void PyThread_init_thread(); 3921 C_long PyThread_start_new_thread(void function(void *), void *); 3922 void PyThread_exit_thread(); 3923 void PyThread__PyThread_exit_thread(); 3924 C_long PyThread_get_thread_ident(); 3925 3926 PyThread_type_lock PyThread_allocate_lock(); 3927 void PyThread_free_lock(PyThread_type_lock); 3928 int PyThread_acquire_lock(PyThread_type_lock, int); 3929 enum WAIT_LOCK = 1; 3930 enum NOWAIT_LOCK = 0; 3931 void PyThread_release_lock(PyThread_type_lock); 3932 3933 version(Python_2_5_Or_Later){ 3934 size_t PyThread_get_stacksize(); 3935 int PyThread_set_stacksize(size_t); 3936 } 3937 3938 void PyThread_exit_prog(int); 3939 void PyThread__PyThread_exit_prog(int); 3940 3941 int PyThread_create_key(); 3942 void PyThread_delete_key(int); 3943 int PyThread_set_key_value(int, void *); 3944 void *PyThread_get_key_value(int); 3945 void PyThread_delete_key_value(int key); 3946 3947 3948 /////////////////////////////////////////////////////////////////////////////// 3949 // SET INTERFACE (built-in types set and frozenset) 3950 /////////////////////////////////////////////////////////////////////////////// 3951 // Python-header-file: Include/setobject.h: 3952 3953 version(Python_2_5_Or_Later){ 3954 enum PySet_MINSIZE = 8; 3955 3956 struct setentry { 3957 C_long hash; 3958 PyObject *key; 3959 } 3960 } 3961 3962 struct PySetObject { 3963 mixin PyObject_HEAD; 3964 3965 version(Python_2_5_Or_Later){ 3966 Py_ssize_t fill; 3967 Py_ssize_t used; 3968 3969 Py_ssize_t mask; 3970 3971 setentry *table; 3972 setentry* function(PySetObject *so, PyObject *key, C_long hash) lookup; 3973 setentry smalltable[PySet_MINSIZE]; 3974 }else{ 3975 PyObject *data; 3976 } 3977 3978 C_long hash; 3979 PyObject *weakreflist; 3980 } 3981 3982 // &PySet_Type is accessible via PySet_Type_p. 3983 // &PyFrozenSet_Type is accessible via PyFrozenSet_Type_p. 3984 3985 // D translations of C macros: 3986 int PyFrozenSet_CheckExact()(PyObject *ob) { 3987 return ob.ob_type == PyFrozenSet_Type_p; 3988 } 3989 int PyAnySet_CheckExact()(PyObject* ob) { 3990 return ob.ob_type == PySet_Type_p || ob.ob_type == PyFrozenSet_Type_p; 3991 } 3992 int PyAnySet_Check()(PyObject *ob) { 3993 return ( 3994 ob.ob_type == PySet_Type_p 3995 || ob.ob_type == PyFrozenSet_Type_p 3996 || PyType_IsSubtype(ob.ob_type, PySet_Type_p) 3997 || PyType_IsSubtype(ob.ob_type, PyFrozenSet_Type_p) 3998 ); 3999 } 4000 version(Python_2_6_Or_Later){ 4001 bool PySet_Check()(PyObject *ob) { 4002 return (ob.ob_type == &PySet_Type || 4003 PyType_IsSubtype(ob.ob_type, &PySet_Type)); 4004 } 4005 bool PyFrozenSet_Check()(PyObject *ob) { 4006 return (ob.ob_type == &PyFrozenSet_Type || 4007 PyType_IsSubtype(ob.ob_type, &PyFrozenSet_Type)); 4008 } 4009 } 4010 4011 version(Python_2_5_Or_Later){ 4012 PyObject *PySet_New(PyObject *); 4013 PyObject *PyFrozenSet_New(PyObject *); 4014 Py_ssize_t PySet_Size(PyObject *anyset); 4015 Py_ssize_t PySet_GET_SIZE()(PyObject* so) { 4016 return (cast(PySetObject*)so).used; 4017 } 4018 int PySet_Clear(PyObject *set); 4019 int PySet_Contains(PyObject *anyset, PyObject *key); 4020 int PySet_Discard(PyObject *set, PyObject *key); 4021 int PySet_Add(PyObject *set, PyObject *key); 4022 int _PySet_Next(PyObject *set, Py_ssize_t *pos, PyObject **entry); 4023 PyObject *PySet_Pop(PyObject *set); 4024 int _PySet_Update(PyObject *set, PyObject *iterable); 4025 } 4026 4027 /////////////////////////////////////////////////////////////////////////////// 4028 // Interface to map C struct members to Python object attributes 4029 /////////////////////////////////////////////////////////////////////////////// 4030 // Python-header-file: Include/structmember.h: 4031 4032 struct PyMemberDef { 4033 char *name; 4034 int type; 4035 Py_ssize_t offset; 4036 int flags; 4037 char *doc; 4038 } 4039 4040 enum T_SHORT = 0; 4041 enum T_INT = 1; 4042 enum T_LONG = 2; 4043 enum T_FLOAT = 3; 4044 enum T_DOUBLE = 4; 4045 enum T_STRING = 5; 4046 enum T_OBJECT = 6; 4047 enum T_CHAR = 7; 4048 enum T_BYTE = 8; 4049 enum T_UBYTE = 9; 4050 enum T_USHORT = 10; 4051 enum T_UINT = 11; 4052 enum T_ULONG = 12; 4053 enum T_STRING_INPLACE = 13; 4054 version(Python_2_6_Or_Later){ 4055 enum T_BOOL = 14; 4056 } 4057 enum T_OBJECT_EX = 16; 4058 version(Python_2_5_Or_Later){ 4059 enum T_LONGLONG = 17; 4060 enum T_ULONGLONG = 18; 4061 } 4062 version(Python_2_6_Or_Later){ 4063 enum T_PYSSIZET = 19; 4064 } 4065 4066 enum READONLY = 1; 4067 alias READONLY RO; 4068 enum READ_RESTRICTED = 2; 4069 enum WRITE_RESTRICTED = 4; 4070 enum RESTRICTED = (READ_RESTRICTED | WRITE_RESTRICTED); 4071 4072 PyObject *PyMember_GetOne(Char1 *, PyMemberDef *); 4073 int PyMember_SetOne(char *, PyMemberDef *, PyObject *); 4074 4075 4076 /////////////////////////////////////////////////////////////////////////////// 4077 // INTERFACE FOR TUPLE-LIKE "STRUCTURED SEQUENCES" 4078 /////////////////////////////////////////////////////////////////////////////// 4079 // Python-header-file: Include/structseq.h: 4080 4081 struct PyStructSequence_Field { 4082 char *name; 4083 char *doc; 4084 } 4085 4086 struct PyStructSequence_Desc { 4087 char *name; 4088 char *doc; 4089 PyStructSequence_Field *fields; 4090 int n_in_sequence; 4091 } 4092 4093 // XXX: What about global var PyStructSequence_UnnamedField? 4094 4095 void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc); 4096 PyObject *PyStructSequence_New(PyTypeObject* type); 4097 4098 struct PyStructSequence { 4099 mixin PyObject_VAR_HEAD; 4100 // DSR:XXX:LAYOUT: 4101 // Will the D layout for a 1-obj array be the same as the C layout? I 4102 // think the D array will be larger. 4103 PyObject *_ob_item[1]; 4104 PyObject** ob_item()() { 4105 return _ob_item.ptr; 4106 } 4107 } 4108 4109 // D translation of C macro: 4110 PyObject *PyStructSequence_SET_ITEM()(PyObject *op, int i, PyObject *v) { 4111 PyStructSequence *ot = cast(PyStructSequence *) op; 4112 ot.ob_item[i] = v; 4113 return v; 4114 } 4115 4116 4117 /////////////////////////////////////////////////////////////////////////////// 4118 // UTILITY FUNCTION RELATED TO TIMEMODULE.C 4119 /////////////////////////////////////////////////////////////////////////////// 4120 // Python-header-file: Include/timefuncs.h: 4121 4122 time_t _PyTime_DoubleToTimet(double x); 4123 4124 4125 4126 } /* extern (C) */ 4127 4128 4129 /* The following global variables will contain pointers to certain immutable 4130 * Python objects that Python/C API programmers expect. 4131 * 4132 * In order to make these global variables from the Python library available 4133 * to D, I tried the extern workaround documented at: 4134 * http://www.digitalmars.com/d/archives/digitalmars/D/15427.html 4135 * but it didn't work (Python crashed when attempting to manipulate the 4136 * pointers). 4137 * Besides, in some cases, canonical use of the Python/C API *requires* macros. 4138 * I ultimately resorted to traversing the Python module structure and loading 4139 * pointers to the required objects manually (see 4140 * python_support.d/_loadPythonSupport). */ 4141 4142 private { 4143 4144 /* Singletons: */ 4145 PyObject* m_Py_None; 4146 PyObject* m_Py_NotImplemented; 4147 PyObject* m_Py_Ellipsis; 4148 PyObject* m_Py_True; 4149 PyObject* m_Py_False; 4150 4151 /* Types: */ 4152 PyTypeObject* m_PyType_Type_p; 4153 PyTypeObject* m_PyBaseObject_Type_p; 4154 PyTypeObject* m_PySuper_Type_p; 4155 4156 PyTypeObject* m_PyNone_Type_p; 4157 4158 PyTypeObject* m_PyUnicode_Type_p; 4159 PyTypeObject* m_PyInt_Type_p; 4160 PyTypeObject* m_PyBool_Type_p; 4161 PyTypeObject* m_PyLong_Type_p; 4162 PyTypeObject* m_PyFloat_Type_p; 4163 PyTypeObject* m_PyComplex_Type_p; 4164 PyTypeObject* m_PyRange_Type_p; 4165 PyTypeObject* m_PyBaseString_Type_p; 4166 PyTypeObject* m_PyString_Type_p; 4167 PyTypeObject* m_PyBuffer_Type_p; 4168 PyTypeObject* m_PyTuple_Type_p; 4169 PyTypeObject* m_PyList_Type_p; 4170 PyTypeObject* m_PyDict_Type_p; 4171 PyTypeObject* m_PyEnum_Type_p; 4172 PyTypeObject* m_PyReversed_Type_p; 4173 PyTypeObject* m_PyCFunction_Type_p; 4174 PyTypeObject* m_PyModule_Type_p; 4175 PyTypeObject* m_PyFunction_Type_p; 4176 PyTypeObject* m_PyClassMethod_Type_p; 4177 PyTypeObject* m_PyStaticMethod_Type_p; 4178 PyTypeObject* m_PyClass_Type_p; 4179 PyTypeObject* m_PyInstance_Type_p; 4180 PyTypeObject* m_PyMethod_Type_p; 4181 PyTypeObject* m_PyFile_Type_p; 4182 PyTypeObject* m_PyCode_Type_p; 4183 PyTypeObject* m_PyFrame_Type_p; 4184 PyTypeObject* m_PyGen_Type_p; 4185 PyTypeObject* m_PySet_Type_p; 4186 PyTypeObject* m_PyFrozenSet_Type_p; 4187 4188 /* YYY: Python's default encoding can actually be changed during program 4189 * with sys.setdefaultencoding, so perhaps it would be better not to expose 4190 * this at all: */ 4191 char* m_Py_FileSystemDefaultEncoding; 4192 4193 PyTypeObject* m_PyCObject_Type_p; 4194 PyTypeObject* m_PyTraceBack_Type_p; 4195 PyTypeObject* m_PySlice_Type_p; 4196 PyTypeObject* m_PyCell_Type_p; 4197 PyTypeObject* m_PySeqIter_Type_p; 4198 PyTypeObject* m_PyCallIter_Type_p; 4199 /* PyWrapperDescr_Type_p omitted. */ 4200 PyTypeObject* m_PyProperty_Type_p; 4201 4202 PyTypeObject* m__PyWeakref_RefType_p; 4203 PyTypeObject* m__PyWeakref_ProxyType_p; 4204 PyTypeObject* m__PyWeakref_CallableProxyType_p; 4205 4206 /* Exceptions: */ 4207 PyObject* m_PyExc_Exception; 4208 PyObject* m_PyExc_StopIteration; 4209 PyObject* m_PyExc_StandardError; 4210 PyObject* m_PyExc_ArithmeticError; 4211 PyObject* m_PyExc_LookupError; 4212 4213 PyObject* m_PyExc_AssertionError; 4214 PyObject* m_PyExc_AttributeError; 4215 PyObject* m_PyExc_EOFError; 4216 PyObject* m_PyExc_FloatingPointError; 4217 PyObject* m_PyExc_EnvironmentError; 4218 PyObject* m_PyExc_IOError; 4219 PyObject* m_PyExc_OSError; 4220 PyObject* m_PyExc_ImportError; 4221 PyObject* m_PyExc_IndexError; 4222 PyObject* m_PyExc_KeyError; 4223 PyObject* m_PyExc_KeyboardInterrupt; 4224 PyObject* m_PyExc_MemoryError; 4225 PyObject* m_PyExc_NameError; 4226 PyObject* m_PyExc_OverflowError; 4227 PyObject* m_PyExc_RuntimeError; 4228 PyObject* m_PyExc_NotImplementedError; 4229 PyObject* m_PyExc_SyntaxError; 4230 PyObject* m_PyExc_IndentationError; 4231 PyObject* m_PyExc_TabError; 4232 PyObject* m_PyExc_ReferenceError; 4233 PyObject* m_PyExc_SystemError; 4234 PyObject* m_PyExc_SystemExit; 4235 PyObject* m_PyExc_TypeError; 4236 PyObject* m_PyExc_UnboundLocalError; 4237 PyObject* m_PyExc_UnicodeError; 4238 PyObject* m_PyExc_UnicodeEncodeError; 4239 PyObject* m_PyExc_UnicodeDecodeError; 4240 PyObject* m_PyExc_UnicodeTranslateError; 4241 PyObject* m_PyExc_ValueError; 4242 PyObject* m_PyExc_ZeroDivisionError; 4243 version (Windows) { 4244 PyObject* m_PyExc_WindowsError; 4245 } 4246 /* PyExc_MemoryErrorInst omitted. */ 4247 4248 PyObject* m_PyExc_Warning; 4249 PyObject* m_PyExc_UserWarning; 4250 PyObject* m_PyExc_DeprecationWarning; 4251 PyObject* m_PyExc_PendingDeprecationWarning; 4252 PyObject* m_PyExc_SyntaxWarning; 4253 /* PyExc_OverflowWarning omitted, because it'll go away in Python 2.5. */ 4254 PyObject* m_PyExc_RuntimeWarning; 4255 PyObject* m_PyExc_FutureWarning; 4256 4257 PyObject *eval()(string code) { 4258 PyObject *pyGlobals = Py_INCREF(PyEval_GetGlobals()); /* borrowed ref */ 4259 scope(exit) Py_DECREF(pyGlobals); 4260 PyObject *res = PyRun_String(toStringz(code), Py_eval_input, 4261 pyGlobals, pyGlobals 4262 ); /* New ref, or NULL on error. */ 4263 if (res == null) { 4264 throw new Exception("XXX: write error message; make PythonException D class"); 4265 } 4266 4267 return res; 4268 } 4269 4270 PyObject* m_builtins, m_types, m_weakref; 4271 4272 } /* end private */ 4273 4274 // These template functions will lazily-load the various singleton objects, 4275 // removing the need for a "load" function that does it all at once. 4276 typeof(Ptr) lazy_sys(alias Ptr, string name) () { 4277 if (Ptr is null) { 4278 PyObject* sys_modules = PyImport_GetModuleDict(); 4279 Ptr = cast(typeof(Ptr)) PyDict_GetItemString(sys_modules, 4280 toStringz(name)); 4281 } 4282 assert (Ptr !is null, "python.d couldn't load " ~ name ~ " attribute!"); 4283 return Ptr; 4284 } 4285 4286 alias lazy_sys!(m_builtins, "__builtin__") builtins; 4287 alias lazy_sys!(m_types, "types") types; 4288 alias lazy_sys!(m_weakref, "weakref") weakref; 4289 4290 @property typeof(Ptr) lazy_load(alias from, alias Ptr, string name) () { 4291 if (Ptr is null) { 4292 Ptr = cast(typeof(Ptr)) PyObject_GetAttrString(from(), toStringz(name)); 4293 } 4294 assert (Ptr !is null, "python.d couldn't load " ~ name ~ " attribute!"); 4295 return Ptr; 4296 } 4297 4298 typeof(Ptr) lazy_eval(alias Ptr, string code) () { 4299 if (Ptr is null) { 4300 Ptr = cast(typeof(Ptr)) eval(code); 4301 } 4302 assert (Ptr !is null, "python.d couldn't lazily eval something..."); 4303 return Ptr; 4304 } 4305 4306 4307 //void _loadPythonSupport() { 4308 //static this() { 4309 //printf("[_loadPythonSupport started (Py_None is null: %d)]\n", Py_None is null); 4310 4311 /+ 4312 PyObject *sys_modules = PyImport_GetModuleDict(); 4313 4314 PyObject *builtins = PyDict_GetItemString(sys_modules, "__builtin__"); 4315 assert (builtins != null); 4316 PyObject *types = PyDict_GetItemString(sys_modules, "types"); 4317 assert (types != null); 4318 4319 PyObject *weakref = PyImport_ImportModule("weakref"); 4320 assert (weakref != null); 4321 +/ 4322 4323 /* Since Python never unloads an extension module once it has been loaded, 4324 * we make no attempt to release these references. */ 4325 4326 /* Singletons: */ 4327 alias lazy_load!(builtins, m_Py_None, "None") Py_None; 4328 alias lazy_load!(builtins, m_Py_NotImplemented, "NotImplemented") Py_NotImplemented; 4329 alias lazy_load!(builtins, m_Py_Ellipsis, "Ellipsis") Py_Ellipsis; 4330 alias lazy_load!(builtins, m_Py_True, "True") Py_True; 4331 alias lazy_load!(builtins, m_Py_False, "False") Py_False; 4332 4333 /* Types: */ 4334 alias lazy_load!(builtins, m_PyType_Type_p, "type") PyType_Type_p; 4335 alias lazy_load!(builtins, m_PyBaseObject_Type_p, "object") PyBaseObject_Type_p; 4336 alias lazy_load!(builtins, m_PySuper_Type_p, "super") PySuper_Type_p; 4337 4338 alias lazy_load!(types, m_PyNone_Type_p, "NoneType") PyNone_Type_p; 4339 4340 alias lazy_load!(builtins, m_PyUnicode_Type_p, "unicode") PyUnicode_Type_p; 4341 alias lazy_load!(builtins, m_PyInt_Type_p, "int") PyInt_Type_p; 4342 alias lazy_load!(builtins, m_PyBool_Type_p, "bool") PyBool_Type_p; 4343 alias lazy_load!(builtins, m_PyLong_Type_p, "long") PyLong_Type_p; 4344 alias lazy_load!(builtins, m_PyFloat_Type_p, "float") PyFloat_Type_p; 4345 alias lazy_load!(builtins, m_PyComplex_Type_p, "complex") PyComplex_Type_p; 4346 alias lazy_load!(builtins, m_PyRange_Type_p, "xrange") PyRange_Type_p; 4347 alias lazy_load!(builtins, m_PyBaseString_Type_p, "basestring") PyBaseString_Type_p; 4348 alias lazy_load!(builtins, m_PyString_Type_p, "str") PyString_Type_p; 4349 alias lazy_load!(builtins, m_PyBuffer_Type_p, "buffer") PyBuffer_Type_p; 4350 alias lazy_load!(builtins, m_PyTuple_Type_p, "tuple") PyTuple_Type_p; 4351 alias lazy_load!(builtins, m_PyList_Type_p, "list") PyList_Type_p; 4352 alias lazy_load!(builtins, m_PyDict_Type_p, "dict") PyDict_Type_p; 4353 alias lazy_load!(builtins, m_PyEnum_Type_p, "enumerate") PyEnum_Type_p; 4354 alias lazy_load!(builtins, m_PyReversed_Type_p, "reversed") PyReversed_Type_p; 4355 4356 alias lazy_load!(types, m_PyCFunction_Type_p, "BuiltinFunctionType") PyCFunction_Type_p; 4357 alias lazy_load!(types, m_PyModule_Type_p, "ModuleType") PyModule_Type_p; 4358 alias lazy_load!(types, m_PyFunction_Type_p, "FunctionType") PyFunction_Type_p; 4359 4360 alias lazy_load!(builtins, m_PyClassMethod_Type_p, "classmethod") PyClassMethod_Type_p; 4361 alias lazy_load!(builtins, m_PyStaticMethod_Type_p, "staticmethod") PyStaticMethod_Type_p; 4362 4363 alias lazy_load!(types, m_PyClass_Type_p, "ClassType") PyClass_Type_p; 4364 alias lazy_load!(types, m_PyInstance_Type_p, "InstanceType") PyInstance_Type_p; 4365 alias lazy_load!(types, m_PyMethod_Type_p, "MethodType") PyMethod_Type_p; 4366 4367 alias lazy_load!(builtins, m_PyFile_Type_p, "file") PyFile_Type_p; 4368 4369 const(char)* Py_FileSystemDefaultEncoding()() { 4370 if (m_Py_FileSystemDefaultEncoding is null) { 4371 m_Py_FileSystemDefaultEncoding = PyUnicode_GetDefaultEncoding(); 4372 assert (m_Py_FileSystemDefaultEncoding !is null, 4373 "python.d couldn't load PyUnicode_DefaultEncoding attribute!"); 4374 } 4375 return m_Py_FileSystemDefaultEncoding; 4376 } 4377 4378 /* Python's "CObject" type is intended to serve as an opaque handle for 4379 * passing a C void pointer from C code to Python code and back. */ 4380 PyTypeObject* PyCObject_Type_p()() { 4381 if (m_PyCObject_Type_p is null) { 4382 PyObject *aCObject = PyCObject_FromVoidPtr(null, null); 4383 m_PyCObject_Type_p = cast(PyTypeObject *) PyObject_Type(aCObject); 4384 Py_DECREF(aCObject); 4385 } 4386 return m_PyCObject_Type_p; 4387 } 4388 4389 alias lazy_load!(types, m_PyTraceBack_Type_p, "TracebackType") PyTraceBack_Type_p; 4390 alias lazy_load!(types, m_PySlice_Type_p, "SliceType") PySlice_Type_p; 4391 4392 PyTypeObject* PyCell_Type_p()() { 4393 if (m_PyCell_Type_p is null) { 4394 PyObject *cell = PyCell_New(null); 4395 assert (cell != null); 4396 m_PyCell_Type_p = cast(PyTypeObject *) PyObject_Type(cell); 4397 assert (PyCell_Type_p != null); 4398 Py_DECREF(cell); 4399 } 4400 return m_PyCell_Type_p; 4401 } 4402 4403 alias lazy_eval!(m_PySeqIter_Type_p, "type(iter(''))") PySeqIter_Type_p; 4404 alias lazy_eval!(m_PyCallIter_Type_p, "type(iter(lambda: None, None))") PyCallIter_Type_p; 4405 4406 /* PyWrapperDescr_Type_p omitted. */ 4407 alias lazy_load!(builtins, m_PyProperty_Type_p, "property") PyProperty_Type_p; 4408 4409 alias lazy_load!(weakref, m__PyWeakref_RefType_p, "ReferenceType") _PyWeakref_RefType_p; 4410 alias lazy_load!(weakref, m__PyWeakref_ProxyType_p, "ProxyType") _PyWeakref_ProxyType_p; 4411 alias lazy_load!(weakref, m__PyWeakref_CallableProxyType_p, "CallableProxyType") _PyWeakref_CallableProxyType_p; 4412 4413 alias lazy_load!(types, m_PyCode_Type_p, "CodeType") PyCode_Type_p; 4414 alias lazy_load!(types, m_PyFrame_Type_p, "FrameType") PyFrame_Type_p; 4415 alias lazy_load!(types, m_PyGen_Type_p, "GeneratorType") PyGen_Type_p; 4416 4417 alias lazy_load!(builtins, m_PySet_Type_p, "set") PySet_Type_p; 4418 alias lazy_load!(builtins, m_PyFrozenSet_Type_p, "frozenset") PyFrozenSet_Type_p; 4419 4420 /* Exceptions: */ 4421 alias lazy_load!(builtins, m_PyExc_ArithmeticError, "ArithmeticError") PyExc_ArithmeticError; 4422 alias lazy_load!(builtins, m_PyExc_AssertionError, "AssertionError") PyExc_AssertionError; 4423 alias lazy_load!(builtins, m_PyExc_AttributeError, "AttributeError") PyExc_AttributeError; 4424 alias lazy_load!(builtins, m_PyExc_DeprecationWarning, "DeprecationWarning") PyExc_DeprecationWarning; 4425 alias lazy_load!(builtins, m_PyExc_EOFError, "EOFError") PyExc_EOFError; 4426 alias lazy_load!(builtins, m_PyExc_EnvironmentError, "EnvironmentError") PyExc_EnvironmentError; 4427 alias lazy_load!(builtins, m_PyExc_Exception, "Exception") PyExc_Exception; 4428 alias lazy_load!(builtins, m_PyExc_FloatingPointError, "FloatingPointError") PyExc_FloatingPointError; 4429 alias lazy_load!(builtins, m_PyExc_FutureWarning, "FutureWarning") PyExc_FutureWarning; 4430 alias lazy_load!(builtins, m_PyExc_IOError, "IOError") PyExc_IOError; 4431 alias lazy_load!(builtins, m_PyExc_ImportError, "ImportError") PyExc_ImportError; 4432 alias lazy_load!(builtins, m_PyExc_IndentationError, "IndentationError") PyExc_IndentationError; 4433 alias lazy_load!(builtins, m_PyExc_IndexError, "IndexError") PyExc_IndexError; 4434 alias lazy_load!(builtins, m_PyExc_KeyError, "KeyError") PyExc_KeyError; 4435 alias lazy_load!(builtins, m_PyExc_KeyboardInterrupt, "KeyboardInterrupt") PyExc_KeyboardInterrupt; 4436 alias lazy_load!(builtins, m_PyExc_LookupError, "LookupError") PyExc_LookupError; 4437 alias lazy_load!(builtins, m_PyExc_MemoryError, "MemoryError") PyExc_MemoryError; 4438 /* PyExc_MemoryErrorInst omitted. */ 4439 alias lazy_load!(builtins, m_PyExc_NameError, "NameError") PyExc_NameError; 4440 alias lazy_load!(builtins, m_PyExc_NotImplementedError, "NotImplementedError") PyExc_NotImplementedError; 4441 alias lazy_load!(builtins, m_PyExc_OSError, "OSError") PyExc_OSError; 4442 alias lazy_load!(builtins, m_PyExc_OverflowError, "OverflowError") PyExc_OverflowError; 4443 alias lazy_load!(builtins, m_PyExc_PendingDeprecationWarning, "PendingDeprecationWarning") PyExc_PendingDeprecationWarning; 4444 alias lazy_load!(builtins, m_PyExc_ReferenceError, "ReferenceError") PyExc_ReferenceError; 4445 alias lazy_load!(builtins, m_PyExc_RuntimeError, "RuntimeError") PyExc_RuntimeError; 4446 alias lazy_load!(builtins, m_PyExc_RuntimeWarning, "RuntimeWarning") PyExc_RuntimeWarning; 4447 alias lazy_load!(builtins, m_PyExc_StandardError, "StandardError") PyExc_StandardError; 4448 alias lazy_load!(builtins, m_PyExc_StopIteration, "StopIteration") PyExc_StopIteration; 4449 alias lazy_load!(builtins, m_PyExc_SyntaxError, "SyntaxError") PyExc_SyntaxError; 4450 alias lazy_load!(builtins, m_PyExc_SyntaxWarning, "SyntaxWarning") PyExc_SyntaxWarning; 4451 alias lazy_load!(builtins, m_PyExc_SystemError, "SystemError") PyExc_SystemError; 4452 alias lazy_load!(builtins, m_PyExc_SystemExit, "SystemExit") PyExc_SystemExit; 4453 alias lazy_load!(builtins, m_PyExc_TabError, "TabError") PyExc_TabError; 4454 alias lazy_load!(builtins, m_PyExc_TypeError, "TypeError") PyExc_TypeError; 4455 alias lazy_load!(builtins, m_PyExc_UnboundLocalError, "UnboundLocalError") PyExc_UnboundLocalError; 4456 alias lazy_load!(builtins, m_PyExc_UnicodeDecodeError, "UnicodeDecodeError") PyExc_UnicodeDecodeError; 4457 alias lazy_load!(builtins, m_PyExc_UnicodeEncodeError, "UnicodeEncodeError") PyExc_UnicodeEncodeError; 4458 alias lazy_load!(builtins, m_PyExc_UnicodeError, "UnicodeError") PyExc_UnicodeError; 4459 alias lazy_load!(builtins, m_PyExc_UnicodeTranslateError, "UnicodeTranslateError") PyExc_UnicodeTranslateError; 4460 alias lazy_load!(builtins, m_PyExc_UserWarning, "UserWarning") PyExc_UserWarning; 4461 alias lazy_load!(builtins, m_PyExc_ValueError, "ValueError") PyExc_ValueError; 4462 alias lazy_load!(builtins, m_PyExc_Warning, "Warning") PyExc_Warning; 4463 4464 version (Windows) { 4465 alias lazy_load!(builtins, m_PyExc_WindowsError, "WindowsError") PyExc_WindowsError; 4466 } 4467 4468 alias lazy_load!(builtins, m_PyExc_ZeroDivisionError, "ZeroDivisionError") PyExc_ZeroDivisionError; 4469 4470 // Python-header-file: Modules/arraymodule.c: 4471 4472 struct arraydescr{ 4473 int typecode; 4474 int itemsize; 4475 PyObject* function(arrayobject*, Py_ssize_t) getitem; 4476 int function(arrayobject*, Py_ssize_t, PyObject*) setitem; 4477 } 4478 4479 struct arrayobject { 4480 mixin PyObject_VAR_HEAD; 4481 ubyte* ob_item; 4482 Py_ssize_t allocated; 4483 arraydescr* ob_descr; 4484 PyObject* weakreflist; /* List of weak references */ 4485 }