1. 11 Apr, 2019 1 commit
  2. 31 Oct, 2018 1 commit
  3. 25 Oct, 2018 3 commits
    • Victor Stinner's avatar
      bpo-9263: Dump Python object on GC assertion failure (GH-10062) · 626bff85
      Victor Stinner authored
      
      Changes:
      
      * Add _PyObject_AssertFailed() function.
      * Add _PyObject_ASSERT() and _PyObject_ASSERT_WITH_MSG() macros.
      * gc_decref(): replace assert() with _PyObject_ASSERT_WITH_MSG() to
        dump the faulty object if the assertion fails.
      
      _PyObject_AssertFailed() calls:
      
      * _PyMem_DumpTraceback(): try to log the traceback where the object
        memory has been allocated if tracemalloc is enabled.
      * _PyObject_Dump(): log repr(obj).
      * Py_FatalError(): log the current Python traceback.
      
      _PyObject_AssertFailed() uses _PyObject_IsFreed() heuristic to check
      if the object memory has been freed by a debug hook on Python memory
      allocators.
      
      Initial patch written by David Malcolm.
      Co-Authored-By: default avatarDavid Malcolm <dmalcolm@redhat.com>
      626bff85
    • Victor Stinner's avatar
      bpo-35053: Add Include/tracemalloc.h (GH-10091) · 6279c1c5
      Victor Stinner authored
      * Modify object.h to ensure that pymem.h is included,
        to get _Py_tracemalloc_config variable.
      * Move _PyTraceMalloc_XXX() functions to tracemalloc.h,
        they need PyObject type. Break circular dependency between pymem.h
        and object.h.
      6279c1c5
    • Victor Stinner's avatar
      bpo-35053: Enhance tracemalloc to trace free lists (GH-10063) · 9e00e80e
      Victor Stinner authored
      tracemalloc now tries to update the traceback when an object is
      reused from a "free list" (optimization for faster object creation,
      used by the builtin list type for example).
      
      Changes:
      
      * Add _PyTraceMalloc_NewReference() function which tries to update
        the Python traceback of a Python object.
      * _Py_NewReference() now calls _PyTraceMalloc_NewReference().
      * Add an unit test.
      9e00e80e
  4. 23 Oct, 2018 1 commit
    • Victor Stinner's avatar
      bpo-9263: _PyObject_Dump() detects freed memory (GH-10061) · 82af0b63
      Victor Stinner authored
      _PyObject_Dump() now uses an heuristic to check if the object memory
      has been freed: log "<freed object>" in that case.
      
      The heuristic rely on the debug hooks on Python memory allocators
      which fills the memory with DEADBYTE (0xDB) when memory is
      deallocated. Use PYTHONMALLOC=debug to always enable these debug
      hooks.
      82af0b63
  5. 06 Dec, 2017 1 commit
    • Victor Stinner's avatar
      bpo-32030: Add pymain_get_global_config() (#4735) · 6bf992a1
      Victor Stinner authored
      * Py_Main() now starts by reading Py_xxx configuration variables to
        only work on its own private structure, and then later writes back
        the configuration into these variables.
      * Replace Py_GETENV() with pymain_get_env_var() which ignores empty
        variables.
      * Add _PyCoreConfig.dump_refs
      * Add _PyCoreConfig.malloc_stats
      * _PyObject_DebugMallocStats() is now responsible to check if debug
        hooks are installed. The function returns 1 if stats were written,
        or 0 if the hooks are disabled. Mark _PyMem_PymallocEnabled() as
        static.
      6bf992a1
  6. 29 Nov, 2017 1 commit
    • Victor Stinner's avatar
      bpo-32030: Rework memory allocators (#4625) · 5d39e042
      Victor Stinner authored
      * Fix _PyMem_SetupAllocators("debug"): always restore allocators to
        the defaults, rather than only caling _PyMem_SetupDebugHooks().
      * Add _PyMem_SetDefaultAllocator() helper to set the "default"
        allocator.
      * Add _PyMem_GetAllocatorsName(): get the name of the allocators
      * main() now uses debug hooks on memory allocators if Py_DEBUG is
        defined, rather than calling directly malloc()
      * Document default memory allocators in C API documentation
      * _Py_InitializeCore() now fails with a fatal user error if
        PYTHONMALLOC value is an unknown memory allocator, instead of
        failing with a fatal internal error.
      * Add new tests on the PYTHONMALLOC environment variable
      * Add support.with_pymalloc()
      * Add the _testcapi.WITH_PYMALLOC constant and expose it as
         support.with_pymalloc().
      * sysconfig.get_config_var('WITH_PYMALLOC') doesn't work on Windows, so
         replace it with support.with_pymalloc().
      * pythoninfo: add _testcapi collector for pymem
      5d39e042
  7. 24 Nov, 2017 1 commit
    • Victor Stinner's avatar
      bpo-32030: Add _PyMainInterpreterConfig_ReadEnv() (#4542) · 46972b7b
      Victor Stinner authored
      Py_GetPath() and Py_Main() now call
      _PyMainInterpreterConfig_ReadEnv() to share the same code to get
      environment variables.
      
      Changes:
      
      * Add _PyMainInterpreterConfig_ReadEnv()
      * Add _PyMainInterpreterConfig_Clear()
      * Add _PyMem_RawWcsdup()
      * _PyMainInterpreterConfig: rename pythonhome to home
      * Rename _Py_ReadMainInterpreterConfig() to
        _PyMainInterpreterConfig_Read()
      * Use _Py_INIT_USER_ERR(), instead of _Py_INIT_ERR(), for decoding
        errors: the user is able to fix the issue, it's not a bug in
        Python. Same change was made in _Py_INIT_NO_MEMORY().
      * Remove _Py_GetPythonHomeWithConfig()
      46972b7b
  8. 15 Nov, 2017 1 commit
    • Victor Stinner's avatar
      bpo-32030: Split Py_Main() into subfunctions (#4399) · f7e5b56c
      Victor Stinner authored
      * Don't use "Python runtime" anymore to parse command line options or
        to get environment variables: pymain_init() is now a strict
        separation.
      * Use an error message rather than "crashing" directly with
        Py_FatalError(). Limit the number of calls to Py_FatalError(). It
        prepares the code to handle errors more nicely later.
      * Warnings options (-W, PYTHONWARNINGS) and "XOptions" (-X) are now
        only added to the sys module once Python core is properly
        initialized.
      * _PyMain is now the well identified owner of some important strings
        like: warnings options, XOptions, and the "program name". The
        program name string is now properly freed at exit.
        pymain_free() is now responsible to free the "command" string.
      * Rename most methods in Modules/main.c to use a "pymain_" prefix to
        avoid conflits and ease debug.
      * Replace _Py_CommandLineDetails_INIT with memset(0)
      * Reorder a lot of code to fix the initialization ordering. For
        example, initializing standard streams now comes before parsing
        PYTHONWARNINGS.
      * Py_Main() now handles errors when adding warnings options and
        XOptions.
      * Add _PyMem_GetDefaultRawAllocator() private function.
      * Cleanup _PyMem_Initialize(): remove useless global constants: move
        them into _PyMem_Initialize().
      * Call _PyRuntime_Initialize() as soon as possible:
        _PyRuntime_Initialize() now returns an error message on failure.
      * Add _PyInitError structure and following macros:
      
        * _Py_INIT_OK()
        * _Py_INIT_ERR(msg)
        * _Py_INIT_USER_ERR(msg): "user" error, don't abort() in that case
        * _Py_INIT_FAILED(err)
      f7e5b56c
  9. 05 Nov, 2017 1 commit
  10. 20 Jun, 2017 1 commit
    • Victor Stinner's avatar
      bpo-30054: Expose tracemalloc C API (#1236) · 5ea4c067
      Victor Stinner authored
      * Make PyTraceMalloc_Track() and PyTraceMalloc_Untrack() functions
        public (remove the "_" prefix)
      * Remove the _PyTraceMalloc_domain_t type: use directly unsigned
        int.
      * Document methods
      
      Note: methods are already tested in test_tracemalloc.
      5ea4c067
  11. 27 Dec, 2016 1 commit
  12. 06 Sep, 2016 1 commit
  13. 23 Mar, 2016 1 commit
    • Victor Stinner's avatar
      Issue #26588: · ca79ccd9
      Victor Stinner authored
      * Optimize tracemalloc_add_trace(): modify hashtable entry data (trace) if the
        memory block is already tracked, rather than trying to remove the old trace
        and then add a new trace.
      * Add _Py_HASHTABLE_ENTRY_WRITE_DATA() macro
      ca79ccd9
  14. 22 Mar, 2016 3 commits
  15. 14 Mar, 2016 1 commit
    • Victor Stinner's avatar
      Add PYTHONMALLOC env var · 34be807c
      Victor Stinner authored
      Issue #26516:
      
      * Add PYTHONMALLOC environment variable to set the Python memory
        allocators and/or install debug hooks.
      * PyMem_SetupDebugHooks() can now also be used on Python compiled in release
        mode.
      * The PYTHONMALLOCSTATS environment variable can now also be used on Python
        compiled in release mode. It now has no effect if set to an empty string.
      * In debug mode, debug hooks are now also installed on Python memory allocators
        when Python is configured without pymalloc.
      34be807c
  16. 02 Jun, 2014 1 commit
  17. 02 May, 2014 1 commit
  18. 03 Jan, 2014 1 commit
  19. 07 Jul, 2013 2 commits
    • Victor Stinner's avatar
      Issue #18203: Add _PyMem_RawStrdup() and _PyMem_Strdup() · 49fc8ece
      Victor Stinner authored
      Replace strdup() with _PyMem_RawStrdup() or _PyMem_Strdup(), depending if the
      GIL is held or not.
      49fc8ece
    • Victor Stinner's avatar
      Issue #3329: Implement the PEP 445 · 0507bf56
      Victor Stinner authored
      Add new enum:
      
      * PyMemAllocatorDomain
      
      Add new structures:
      
      * PyMemAllocator
      * PyObjectArenaAllocator
      
      Add new functions:
      
      * PyMem_RawMalloc(), PyMem_RawRealloc(), PyMem_RawFree()
      * PyMem_GetAllocator(), PyMem_SetAllocator()
      * PyObject_GetArenaAllocator(), PyObject_SetArenaAllocator()
      * PyMem_SetupDebugHooks()
      
      Changes:
      
      * PyMem_Malloc()/PyObject_Realloc() now always call malloc()/realloc(), instead
        of calling PyObject_Malloc()/PyObject_Realloc() in debug mode.
      * PyObject_Malloc()/PyObject_Realloc() now falls back to
        PyMem_Malloc()/PyMem_Realloc() for allocations larger than 512 bytes.
      * Redesign debug checks on memory block allocators as hooks, instead of using C
        macros
      0507bf56
  20. 15 Jun, 2013 1 commit
  21. 14 Jun, 2013 1 commit
    • Victor Stinner's avatar
      Issue #3329: Add new APIs to customize memory allocators · 4d705625
      Victor Stinner authored
      * Add a new PyMemAllocators structure
      * New functions:
      
        - PyMem_RawMalloc(), PyMem_RawRealloc(), PyMem_RawFree(): GIL-free memory
          allocator functions
        - PyMem_GetRawAllocators(), PyMem_SetRawAllocators()
        - PyMem_GetAllocators(), PyMem_SetAllocators()
        - PyMem_SetupDebugHooks()
        - _PyObject_GetArenaAllocators(), _PyObject_SetArenaAllocators()
      
      * Add unit test for PyMem_Malloc(0) and PyObject_Malloc(0)
      * Add unit test for new get/set allocators functions
      * PyObject_Malloc() now falls back on PyMem_Malloc() instead of malloc() if
        size is bigger than SMALL_REQUEST_THRESHOLD, and PyObject_Realloc() falls
        back on PyMem_Realloc() instead of realloc()
      * PyMem_Malloc() and PyMem_Realloc() now always call malloc() and realloc(),
        instead of calling PyObject_Malloc() and PyObject_Realloc() in debug mode
      4d705625
  22. 14 Feb, 2010 4 commits
  23. 10 Dec, 2009 2 commits
  24. 28 Sep, 2009 2 commits
  25. 28 Jul, 2008 1 commit
    • Neal Norwitz's avatar
      Backport code from r65182: · 83ac0144
      Neal Norwitz authored
      Issue #2620: Overflow checking when allocating or reallocating memory
      was not always being done properly in some python types and extension
      modules.  PyMem_MALLOC, PyMem_REALLOC, PyMem_NEW and PyMem_RESIZE have
      all been updated to perform better checks and places in the code that
      would previously leak memory on the error path when such an allocation
      failed have been fixed.
      83ac0144
  26. 23 Jul, 2008 1 commit
    • Georg Brandl's avatar
      Merged revisions 65182 via svnmerge from · d492ad80
      Georg Brandl authored
      svn+ssh://pythondev@svn.python.org/python/trunk
      
      ........
        r65182 | gregory.p.smith | 2008-07-22 06:46:32 +0200 (Tue, 22 Jul 2008) | 7 lines
      
        Issue #2620: Overflow checking when allocating or reallocating memory
        was not always being done properly in some python types and extension
        modules.  PyMem_MALLOC, PyMem_REALLOC, PyMem_NEW and PyMem_RESIZE have
        all been updated to perform better checks and places in the code that
        would previously leak memory on the error path when such an allocation
        failed have been fixed.
      ........
      d492ad80
  27. 22 Jul, 2008 1 commit
    • Gregory P. Smith's avatar
      Issue #2620: Overflow checking when allocating or reallocating memory · 0470bab6
      Gregory P. Smith authored
      was not always being done properly in some python types and extension
      modules.  PyMem_MALLOC, PyMem_REALLOC, PyMem_NEW and PyMem_RESIZE have
      all been updated to perform better checks and places in the code that
      would previously leak memory on the error path when such an allocation
      failed have been fixed.
      0470bab6
  28. 18 Jun, 2008 1 commit
  29. 11 Jun, 2008 1 commit
    • Gregory P. Smith's avatar
      Merge in release25-maint r60793: · 9d53457e
      Gregory P. Smith authored
       Added checks for integer overflows, contributed by Google. Some are
       only available if asserts are left in the code, in cases where they
       can't be triggered from Python code.
      9d53457e
  30. 14 Feb, 2008 1 commit