Skip to content

Commit

Permalink
Revert "Add SDL_aligned_alloc() and SDL_aligned_free()"
Browse files Browse the repository at this point in the history
This reverts commit 968b85a.
  • Loading branch information
1bsyl committed Jan 5, 2023
1 parent ca29aa2 commit aa89b8a
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 50 deletions.
1 change: 0 additions & 1 deletion WhatsNew.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ General:
* The timestamp member of the SDL_Event structure is now in nanoseconds, filled in with the time the event was generated, or the time it was queued if that's not available
* Added SDL_modf() and SDL_modff() to separate the whole and fractional portions of a floating point number
* Added SDL_GetRenderVSync() to get vsync of the given renderer
* Added SDL_aligned_alloc() and SDL_aligned_free() to allocate aligned memory with explicit 'alignment' parameter
21 changes: 0 additions & 21 deletions include/SDL3/SDL_cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -457,27 +457,6 @@ extern DECLSPEC void * SDLCALL SDL_SIMDRealloc(void *mem, const size_t len);
*/
extern DECLSPEC void SDLCALL SDL_SIMDFree(void *ptr);

/**
* Allocate aligned memory with explicit 'alignment' parameter.
* \param alignment alignment requirement
* \param size The size, in bytes, of the block to allocate.
* \returns a pointer to the newly-allocated block, NULL if out of memory.
*
* \sa SDL_aligned_free
*/
extern DECLSPEC void * SDLCALL SDL_aligned_alloc(size_t alignment, size_t size);

/**
* Deallocate memory obtained from SDL_aligned_alloc
*
* \param ptr The pointer, returned from SDL_aligned_alloc, to
* deallocate. NULL is a legal no-op.
*
*
* \sa SDL_aligned_alloc
*/
extern DECLSPEC void SDLCALL SDL_aligned_free(void *ptr);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
Expand Down
25 changes: 3 additions & 22 deletions src/cpuinfo/SDL_cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,26 +1099,13 @@ SDL_SIMDAlloc(const size_t len)
{
const size_t alignment = SDL_SIMDGetAlignment();
const size_t padding = (alignment - (len % alignment)) % alignment;
size_t to_allocate;

/* Check for overflow */
if (SDL_size_add_overflow(len, padding, &to_allocate)) {
return NULL;
}

return SDL_aligned_alloc(alignment, to_allocate);
}

void *
SDL_aligned_alloc(size_t alignment, size_t size)
{
Uint8 *retval = NULL;
Uint8 *ptr;
size_t to_allocate;

/* Check for overflow */
if (SDL_size_add_overflow(size, alignment, &to_allocate) ||
SDL_size_add_overflow(to_allocate, sizeof (void *), &to_allocate)) {
/* alignment + padding + sizeof (void *) is bounded (a few hundred
* bytes max), so no need to check for overflow within that argument */
if (SDL_size_add_overflow(len, alignment + padding + sizeof(void *), &to_allocate)) {
return NULL;
}

Expand Down Expand Up @@ -1185,12 +1172,6 @@ SDL_SIMDRealloc(void *mem, const size_t len)
return retval;
}

void
SDL_aligned_free(void *ptr)
{
SDL_SIMDFree(ptr);
}

void SDL_SIMDFree(void *ptr)
{
if (ptr) {
Expand Down
2 changes: 0 additions & 2 deletions src/dynapi/SDL_dynapi.sym
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,6 @@ SDL3_0.0.0 {
SDL_modf;
SDL_modff;
SDL_GetRenderVSync;
SDL_aligned_alloc;
SDL_aligned_free;
# extra symbols go here (don't modify this line)
local: *;
};
2 changes: 0 additions & 2 deletions src/dynapi/SDL_dynapi_overrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,5 +870,3 @@
#define SDL_modf SDL_modf_REAL
#define SDL_modff SDL_modff_REAL
#define SDL_GetRenderVSync SDL_GetRenderVSync_REAL
#define SDL_aligned_alloc SDL_aligned_alloc_REAL
#define SDL_aligned_free SDL_aligned_free_REAL
2 changes: 0 additions & 2 deletions src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -915,5 +915,3 @@ SDL_DYNAPI_PROC(wchar_t*,SDL_wcsstr,(const wchar_t *a, const wchar_t *b),(a,b),r
SDL_DYNAPI_PROC(double,SDL_modf,(double a, double *b),(a,b),return)
SDL_DYNAPI_PROC(float,SDL_modff,(float a, float *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderVSync,(SDL_Renderer *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_aligned_alloc,(size_t a, size_t b),(a,b),return)
SDL_DYNAPI_PROC(void,SDL_aligned_free,(void *a),(a),)

0 comments on commit aa89b8a

Please sign in to comment.