You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.2 KiB

24 years ago
Give Python a debug-mode pymalloc, much as sketched on Python-Dev. When WITH_PYMALLOC is defined, define PYMALLOC_DEBUG to enable the debug allocator. This can be done independent of build type (release or debug). A debug build automatically defines PYMALLOC_DEBUG when pymalloc is enabled. It's a detected error to define PYMALLOC_DEBUG when pymalloc isn't enabled. Two debugging entry points defined only under PYMALLOC_DEBUG: + _PyMalloc_DebugCheckAddress(const void *p) can be used (e.g., from gdb) to sanity-check a memory block obtained from pymalloc. It sprays info to stderr (see next) and dies via Py_FatalError if the block is detectably damaged. + _PyMalloc_DebugDumpAddress(const void *p) can be used to spray info about a debug memory block to stderr. A tiny start at implementing "API family" checks isn't good for anything yet. _PyMalloc_DebugRealloc() has been optimized to do little when the new size is <= old size. However, if the new size is larger, it really can't call the underlying realloc() routine without either violating its contract, or knowing something non-trivial about how the underlying realloc() works. A memcpy is always done in this case. This was a disaster for (and only) one of the std tests: test_bufio creates single text file lines up to a million characters long. On Windows, fileobject.c's get_line() uses the horridly funky getline_via_fgets(), which keeps growing and growing a string object hoping to find a newline. It grew the string object 1000 bytes each time, so for a million-character string it took approximately forever (I gave up after a few minutes). So, also: fileobject.c, getline_via_fgets(): When a single line is outrageously long, grow the string object at a mildly exponential rate, instead of just 1000 bytes at a time. That's enough so that a debug-build test_bufio finishes in about 5 seconds on my Win98SE box. I'm curious to try this on Win2K, because it has very different memory behavior than Win9X, and test_bufio always took a factor of 10 longer to complete on Win2K. It *could* be that the endless reallocs were simply killing it on Win2K even in the release build.
24 years ago
Marc-Andre's third try at this bulk patch seems to work (except that his copy of test_contains.py seems to be broken -- the lines he deleted were already absent). Checkin messages: New Unicode support for int(), float(), complex() and long(). - new APIs PyInt_FromUnicode() and PyLong_FromUnicode() - added support for Unicode to PyFloat_FromString() - new encoding API PyUnicode_EncodeDecimal() which converts Unicode to a decimal char* string (used in the above new APIs) - shortcuts for calls like int(<int object>) and float(<float obj>) - tests for all of the above Unicode compares and contains checks: - comparing Unicode and non-string types now works; TypeErrors are masked, all other errors such as ValueError during Unicode coercion are passed through (note that PyUnicode_Compare does not implement the masking -- PyObject_Compare does this) - contains now works for non-string types too; TypeErrors are masked and 0 returned; all other errors are passed through Better testing support for the standard codecs. Misc minor enhancements, such as an alias dbcs for the mbcs codec. Changes: - PyLong_FromString() now applies the same error checks as does PyInt_FromString(): trailing garbage is reported as error and not longer silently ignored. The only characters which may be trailing the digits are 'L' and 'l' -- these are still silently ignored. - string.ato?() now directly interface to int(), long() and float(). The error strings are now a little different, but the type still remains the same. These functions are now ready to get declared obsolete ;-) - PyNumber_Int() now also does a check for embedded NULL chars in the input string; PyNumber_Long() already did this (and still does) Followed by: Looks like I've gone a step too far there... (and test_contains.py seem to have a bug too). I've changed back to reporting all errors in PyUnicode_Contains() and added a few more test cases to test_contains.py (plus corrected the join() NameError).
26 years ago
Merged revisions 61750,61752,61754,61756,61760,61763,61768,61772,61775,61805,61809,61812,61819,61917,61920,61930,61933-61934 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/trunk-bytearray ........ r61750 | christian.heimes | 2008-03-22 20:47:44 +0100 (Sat, 22 Mar 2008) | 1 line Copied files from py3k w/o modifications ........ r61752 | christian.heimes | 2008-03-22 20:53:20 +0100 (Sat, 22 Mar 2008) | 7 lines Take One * Added initialization code, warnings, flags etc. to the appropriate places * Added new buffer interface to string type * Modified tests * Modified Makefile.pre.in to compile the new files * Added bytesobject.c to Python.h ........ r61754 | christian.heimes | 2008-03-22 21:22:19 +0100 (Sat, 22 Mar 2008) | 2 lines Disabled bytearray.extend for now since it causes an infinite recursion Fixed serveral unit tests ........ r61756 | christian.heimes | 2008-03-22 21:43:38 +0100 (Sat, 22 Mar 2008) | 5 lines Added PyBytes support to several places: str + bytearray ord(bytearray) bytearray(str, encoding) ........ r61760 | christian.heimes | 2008-03-22 21:56:32 +0100 (Sat, 22 Mar 2008) | 1 line Fixed more unit tests related to type('') is not unicode ........ r61763 | christian.heimes | 2008-03-22 22:20:28 +0100 (Sat, 22 Mar 2008) | 2 lines Fixed more unit tests Fixed bytearray.extend ........ r61768 | christian.heimes | 2008-03-22 22:40:50 +0100 (Sat, 22 Mar 2008) | 1 line Implemented old buffer interface for bytearray ........ r61772 | christian.heimes | 2008-03-22 23:24:52 +0100 (Sat, 22 Mar 2008) | 1 line Added backport of the io module ........ r61775 | christian.heimes | 2008-03-23 03:50:49 +0100 (Sun, 23 Mar 2008) | 1 line Fix str assignement to bytearray. Assignment of a str of size 1 is interpreted as a single byte ........ r61805 | christian.heimes | 2008-03-23 19:33:48 +0100 (Sun, 23 Mar 2008) | 3 lines Fixed more tests Fixed bytearray() comparsion with unicode() Fixed iterator assignment of bytearray ........ r61809 | christian.heimes | 2008-03-23 21:02:21 +0100 (Sun, 23 Mar 2008) | 2 lines str(bytesarray()) now returns the bytes and not the representation of the bytearray object Enabled and fixed more unit tests ........ r61812 | christian.heimes | 2008-03-23 21:53:08 +0100 (Sun, 23 Mar 2008) | 3 lines Clear error PyNumber_AsSsize_t() fails Use CHARMASK for ob_svall access disabled a test with memoryview again ........ r61819 | christian.heimes | 2008-03-23 23:05:57 +0100 (Sun, 23 Mar 2008) | 1 line Untested updates to the PCBuild directory ........ r61917 | christian.heimes | 2008-03-26 00:57:06 +0100 (Wed, 26 Mar 2008) | 1 line The type system of Python 2.6 has subtle differences to 3.0's. I've removed the Py_TPFLAGS_BASETYPE flags from bytearray for now. bytearray can't be subclasses until the issues with bytearray subclasses are fixed. ........ r61920 | christian.heimes | 2008-03-26 01:44:08 +0100 (Wed, 26 Mar 2008) | 2 lines Disabled last failing test I don't understand what the test is testing and how it suppose to work. Ka-Ping, please check it out. ........ r61930 | christian.heimes | 2008-03-26 12:46:18 +0100 (Wed, 26 Mar 2008) | 1 line Re-enabled bytes warning code ........ r61933 | christian.heimes | 2008-03-26 13:20:46 +0100 (Wed, 26 Mar 2008) | 1 line Fixed a bug in the new buffer protocol. The buffer slots weren't copied into a subclass. ........ r61934 | christian.heimes | 2008-03-26 13:25:09 +0100 (Wed, 26 Mar 2008) | 1 line Re-enabled bytearray subclassing - all tests are passing. ........
18 years ago
  1. #ifndef Py_PYTHON_H
  2. #define Py_PYTHON_H
  3. /* Since this is a "meta-include" file, no #ifdef __cplusplus / extern "C" { */
  4. /* Include nearly all Python header files */
  5. #include "patchlevel.h"
  6. #include "pyconfig.h"
  7. #include "pymacconfig.h"
  8. /* Cyclic gc is always enabled, starting with release 2.3a1. Supply the
  9. * old symbol for the benefit of extension modules written before then
  10. * that may be conditionalizing on it. The core doesn't use it anymore.
  11. */
  12. #ifndef WITH_CYCLE_GC
  13. #define WITH_CYCLE_GC 1
  14. #endif
  15. #include <limits.h>
  16. #ifndef UCHAR_MAX
  17. #error "Something's broken. UCHAR_MAX should be defined in limits.h."
  18. #endif
  19. #if UCHAR_MAX != 255
  20. #error "Python's source code assumes C's unsigned char is an 8-bit type."
  21. #endif
  22. #if defined(__sgi) && defined(WITH_THREAD) && !defined(_SGI_MP_SOURCE)
  23. #define _SGI_MP_SOURCE
  24. #endif
  25. #include <stdio.h>
  26. #ifndef NULL
  27. # error "Python.h requires that stdio.h define NULL."
  28. #endif
  29. #include <string.h>
  30. #ifdef HAVE_ERRNO_H
  31. #include <errno.h>
  32. #endif
  33. #include <stdlib.h>
  34. #ifdef HAVE_UNISTD_H
  35. #include <unistd.h>
  36. #endif
  37. /* For size_t? */
  38. #ifdef HAVE_STDDEF_H
  39. #include <stddef.h>
  40. #endif
  41. /* CAUTION: Build setups should ensure that NDEBUG is defined on the
  42. * compiler command line when building Python in release mode; else
  43. * assert() calls won't be removed.
  44. */
  45. #include <assert.h>
  46. #include "pyport.h"
  47. /* pyconfig.h or pyport.h may or may not define DL_IMPORT */
  48. #ifndef DL_IMPORT /* declarations for DLL import/export */
  49. #define DL_IMPORT(RTYPE) RTYPE
  50. #endif
  51. #ifndef DL_EXPORT /* declarations for DLL import/export */
  52. #define DL_EXPORT(RTYPE) RTYPE
  53. #endif
  54. /* Debug-mode build with pymalloc implies PYMALLOC_DEBUG.
  55. * PYMALLOC_DEBUG is in error if pymalloc is not in use.
  56. */
  57. #if defined(Py_DEBUG) && defined(WITH_PYMALLOC) && !defined(PYMALLOC_DEBUG)
  58. #define PYMALLOC_DEBUG
  59. #endif
  60. #if defined(PYMALLOC_DEBUG) && !defined(WITH_PYMALLOC)
  61. #error "PYMALLOC_DEBUG requires WITH_PYMALLOC"
  62. #endif
  63. #include "pymath.h"
  64. #include "pymem.h"
  65. #include "object.h"
  66. #include "objimpl.h"
  67. #include "pydebug.h"
  68. #include "unicodeobject.h"
  69. #include "intobject.h"
  70. #include "boolobject.h"
  71. #include "longobject.h"
  72. #include "floatobject.h"
  73. #ifndef WITHOUT_COMPLEX
  74. #include "complexobject.h"
  75. #endif
  76. #include "rangeobject.h"
  77. #include "stringobject.h"
  78. #include "memoryobject.h"
  79. #include "bufferobject.h"
  80. #include "bytesobject.h"
  81. #include "bytearrayobject.h"
  82. #include "tupleobject.h"
  83. #include "listobject.h"
  84. #include "dictobject.h"
  85. #include "enumobject.h"
  86. #include "setobject.h"
  87. #include "methodobject.h"
  88. #include "moduleobject.h"
  89. #include "funcobject.h"
  90. #include "classobject.h"
  91. #include "fileobject.h"
  92. #include "cobject.h"
  93. #include "pycapsule.h"
  94. #include "traceback.h"
  95. #include "sliceobject.h"
  96. #include "cellobject.h"
  97. #include "iterobject.h"
  98. #include "genobject.h"
  99. #include "descrobject.h"
  100. #include "warnings.h"
  101. #include "weakrefobject.h"
  102. #include "codecs.h"
  103. #include "pyerrors.h"
  104. #include "pystate.h"
  105. #include "pyarena.h"
  106. #include "modsupport.h"
  107. #include "pythonrun.h"
  108. #include "ceval.h"
  109. #include "sysmodule.h"
  110. #include "intrcheck.h"
  111. #include "import.h"
  112. #include "abstract.h"
  113. #include "compile.h"
  114. #include "eval.h"
  115. #include "pyctype.h"
  116. #include "pystrtod.h"
  117. #include "pystrcmp.h"
  118. #include "dtoa.h"
  119. /* _Py_Mangle is defined in compile.c */
  120. PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
  121. /* PyArg_GetInt is deprecated and should not be used, use PyArg_Parse(). */
  122. #define PyArg_GetInt(v, a) PyArg_Parse((v), "i", (a))
  123. /* PyArg_NoArgs should not be necessary.
  124. Set ml_flags in the PyMethodDef to METH_NOARGS. */
  125. #define PyArg_NoArgs(v) PyArg_Parse(v, "")
  126. /* Argument must be a char or an int in [-128, 127] or [0, 255]. */
  127. #define Py_CHARMASK(c) ((unsigned char)((c) & 0xff))
  128. #include "pyfpe.h"
  129. /* These definitions must match corresponding definitions in graminit.h.
  130. There's code in compile.c that checks that they are the same. */
  131. #define Py_single_input 256
  132. #define Py_file_input 257
  133. #define Py_eval_input 258
  134. #ifdef HAVE_PTH
  135. /* GNU pth user-space thread support */
  136. #include <pth.h>
  137. #endif
  138. /* Define macros for inline documentation. */
  139. #define PyDoc_VAR(name) static char name[]
  140. #define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str)
  141. #ifdef WITH_DOC_STRINGS
  142. #define PyDoc_STR(str) str
  143. #else
  144. #define PyDoc_STR(str) ""
  145. #endif
  146. #endif /* !Py_PYTHON_H */