)]}'
{
  "commit": "5bb32cb5ebec07ce3f06097f1e0761046ad48850",
  "tree": "dcba6633e10b38a56d8ae8127cbe4d65a5fb2a40",
  "parents": [
    "f065fba5ddd5e5f814f9799d5397a507da8c3748"
  ],
  "author": {
    "name": "Martin Storsjö",
    "email": "martin@martin.st",
    "time": "Thu Dec 03 14:26:08 2020 +0200"
  },
  "committer": {
    "name": "Ozkan Sezer",
    "email": "sezeroz@gmail.com",
    "time": "Thu May 30 15:55:25 2024 +0300"
  },
  "message": "headers: Don\u0027t redirect _mm_malloc to _aligned_malloc\n\nThe headers have a number of brittle workarounds, all trying to make\nthe \"#define _mm_malloc _aligned_malloc\" redirect in malloc.h work\nproperly.\n\nThat define is problematic, because it behaves differently depending\non the order headers are included. If malloc.h is included before\nGCC\u0027s mm_malloc.h, malloc.h does \"#define _mm_malloc _aligned_malloc\"\nand \"#define _MM_MALLOC_H_INCLUDED\", making sure that a later include\nof GCC\u0027s mm_malloc.h define nothing. If the user code calls\n_mm_malloc() after that, it ends up calling _aligned_malloc().\n\nHowever, if the user code (implicitly) includes mm_malloc.h before\nmalloc.h, the situation is much trickier. (mm_malloc.h gets implicitly\nincluded by x86intrin.h, which is included by e.g. winnt.h.)\n\nGCC\u0027s mm_malloc.h looks like this, a little simplified:\n\n    #ifndef _MM_MALLOC_H_INCLUDED\n    #define _MM_MALLOC_H_INCLUDED\n\n    #include \u003cstdlib.h\u003e\n\n    static __inline__ void *_mm_malloc (...)\n\nThe stdlib.h include implicitly includes malloc.h, which does\n\"#define _mm_malloc _aligned_malloc\", which causes GCC\u0027s mm_malloc.h\nto suddenly define a static inline _aligned_malloc instead.\n\nThis has been halfway worked around by not defining the non-inline\n_aligned_malloc in malloc.h if _MM_MALLOC_H_INCLUDED already was\ndefined, making the inline function the only definition of it.\n\nSo when expanding malloc.h in this context, there\u0027s no way to stop the\nouter mm_malloc.h from defining a static inline function, and regardless\nof whatever name it is renamed to with a define, that static inline\nfunction is what callers to _mm_malloc end up calling.\n\nThis causes calls to both _mm_malloc and _aligned_malloc to end\nup either with the dllimported function or the static inline version,\ndepending on which header was included first. If one translation unit\ncalls _mm_malloc and another one calls _mm_free, there\u0027s a risk that\nthey end up mismatched, which is potentially fatal.\n\nThis was earlier attempted to be worked around in e.g. intrin.h, by\nforcing including malloc.h before x86intrin.h, but such workarounds\nare futile, as user code could also include x86intrin.h, immintrin.h\nor even mm_malloc.h directly, without passing through mingw headers.\n\nInstead just remove the _mm_malloc redefinition and include the\ncompiler\u0027s mm_malloc.h header. This makes sure that regardless of\nheader include order, calls to _aligned_malloc and _mm_malloc will\nalways end up to the same function, avoiding risks of mismatches\nbetween *_malloc and *_free.\n\nThis also has the effect of no longer hiding the declaration of\n_aligned_malloc when including intrin.h first.\n\nSigned-off-by: Martin Storsjö \u003cmartin@martin.st\u003e\n\n(cherry picked from commit 660e09f3cb20f181b6d6435cb623d65a3922a063)\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "8ffe7ec0c57235dfb1dd796a5f17c55ff70c945b",
      "old_mode": 33188,
      "old_path": "mingw-w64-headers/crt/intrin.h",
      "new_id": "6113e2731f4cc2826422e41d3780be26d207e942",
      "new_mode": 33188,
      "new_path": "mingw-w64-headers/crt/intrin.h"
    },
    {
      "type": "modify",
      "old_id": "e73b705971a9bc1f645fe8727da0b5619e8f78ae",
      "old_mode": 33188,
      "old_path": "mingw-w64-headers/crt/malloc.h",
      "new_id": "13911193f6b9d3886a9168fb22244580e67df409",
      "new_mode": 33188,
      "new_path": "mingw-w64-headers/crt/malloc.h"
    },
    {
      "type": "modify",
      "old_id": "a0997c46431c3ada524bd6395ba4f16b03a8a8fe",
      "old_mode": 33188,
      "old_path": "mingw-w64-headers/crt/stdlib.h",
      "new_id": "2403e4c944c15976989eb82fd190aa61c2a2b920",
      "new_mode": 33188,
      "new_path": "mingw-w64-headers/crt/stdlib.h"
    }
  ]
}
