Changeset 1138
- Timestamp:
- Oct 24, 2010, 11:16:11 PM (13 years ago)
- File:
-
- 1 edited
-
branches/experimental/py3k/genshi/_speedups.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/experimental/py3k/genshi/_speedups.c
r995 r1138 15 15 #include <structmember.h> 16 16 17 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) 18 typedef int Py_ssize_t; 19 #define PY_SSIZE_T_MAX INT_MAX 20 #define PY_SSIZE_T_MIN INT_MIN 17 #if PY_MAJOR_VERSION > 2 18 # define IS_PY3K 19 #elif PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) 20 typedef int Py_ssize_t; 21 # define PY_SSIZE_T_MAX INT_MAX 22 # define PY_SSIZE_T_MIN INT_MIN 23 #endif 24 25 /* We only use Unicode Strings in this module */ 26 #ifndef IS_PY3K 27 # define PyObject_Str PyObject_Unicode 21 28 #endif 22 29 … … 74 81 return ret; 75 82 } 76 in = (PyUnicodeObject *) PyObject_ Unicode(text);83 in = (PyUnicodeObject *) PyObject_Str(text); 77 84 if (in == NULL) { 78 85 return NULL; … … 391 398 392 399 if (PyObject_TypeCheck(self, &MarkupType)) { 393 unicode = PyObject_ Unicode(self);400 unicode = PyObject_Str(self); 394 401 if (unicode == NULL) return NULL; 395 402 result = PyNumber_Multiply(unicode, num); 396 403 } else { // __rmul__ 397 unicode = PyObject_ Unicode(num);404 unicode = PyObject_Str(num); 398 405 if (unicode == NULL) return NULL; 399 406 result = PyNumber_Multiply(unicode, self); … … 419 426 PyObject *format, *result, *args; 420 427 428 #ifdef IS_PY3K 429 format = PyUnicode_FromString("<Markup %r>"); 430 #else 421 431 format = PyString_FromString("<Markup %r>"); 432 #endif 422 433 if (format == NULL) return NULL; 423 result = PyObject_ Unicode(self);434 result = PyObject_Str(self); 424 435 if (result == NULL) { 425 436 Py_DECREF(format); … … 433 444 } 434 445 PyTuple_SET_ITEM(args, 0, result); 446 #ifdef IS_PY3K 447 result = PyUnicode_Format(format, args); 448 #else 435 449 result = PyString_Format(format, args); 450 #endif 436 451 Py_DECREF(format); 437 452 Py_DECREF(args); … … 554 569 0, /*nb_subtract*/ 555 570 Markup_mul, /*nb_multiply*/ 571 #ifndef IS_PY3K 556 572 0, /*nb_divide*/ 573 #endif 557 574 Markup_mod, /*nb_remainder*/ 558 575 }; 559 576 560 577 PyTypeObject MarkupType = { 578 #ifdef IS_PY3K 579 PyVarObject_HEAD_INIT(NULL, 0) 580 #else 561 581 PyObject_HEAD_INIT(NULL) 562 582 0, 583 #endif 563 584 "genshi._speedups.Markup", 564 585 sizeof(MarkupObject), … … 568 589 0, /*tp_getattr*/ 569 590 0, /*tp_setattr*/ 591 #ifdef IS_PY3K 592 0, /*tp_reserved*/ 593 #else 570 594 0, /*tp_compare*/ 595 #endif 571 596 Markup_repr, /*tp_repr*/ 572 597 &Markup_as_number, /*tp_as_number*/ … … 581 606 0, /*tp_as_buffer*/ 582 607 608 #ifdef IS_PY3K 609 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_UNICODE_SUBCLASS, /*tp_flags*/ 610 #elif defined(Py_TPFLAGS_UNICODE_SUBCLASS) 611 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES | Py_TPFLAGS_UNICODE_SUBCLASS, /*tp_flags*/ 612 #else 583 613 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES, /*tp_flags*/ 614 #endif 615 584 616 Markup__doc__,/*tp_doc*/ 585 617 … … 617 649 }; 618 650 651 #ifdef IS_PY3K 652 struct PyModuleDef module_def = { 653 PyModuleDef_HEAD_INIT, /*m_base*/ 654 "_speedups", /*m_name*/ 655 NULL, /*m_doc*/ 656 -1, /*m_size*/ 657 NULL, /*m_methods*/ 658 NULL, /*m_reload*/ 659 NULL, /*m_traverse*/ 660 NULL, /*m_clear*/ 661 NULL /*m_free*/ 662 }; 663 664 PyObject * 665 PyInit__speedups(void) 666 #else 619 667 PyMODINIT_FUNC 620 668 init_speedups(void) 669 #endif 621 670 { 622 671 PyObject *module; … … 627 676 628 677 if (PyType_Ready(&MarkupType) < 0) 678 #ifdef IS_PY3K 679 return NULL; 680 #else 629 681 return; 682 #endif 630 683 631 684 init_constants(); 632 685 686 #ifdef IS_PY3K 687 module = PyModule_Create(&module_def); 688 #else 633 689 module = Py_InitModule("_speedups", NULL); 690 #endif 634 691 Py_INCREF(&MarkupType); 635 692 PyModule_AddObject(module, "Markup", (PyObject *) &MarkupType); 636 } 693 694 #ifdef IS_PY3K 695 return module; 696 #endif 697 }
Note: See TracChangeset
for help on using the changeset viewer.
