@@ -44,8 +44,13 @@ static void * (* __flint_allocate_func)(size_t) = _flint_malloc;
4444static void * (* __flint_callocate_func )(size_t , size_t ) = _flint_calloc ;
4545static void * (* __flint_reallocate_func )(void * , size_t ) = _flint_realloc ;
4646static void (* __flint_free_func )(void * ) = _flint_free ;
47+ #if HAVE_ALIGNED_ALLOC || HAVE__ALIGNED_MALLOC
4748static void * (* __flint_aligned_allocate_func )(size_t , size_t ) = _flint_aligned_alloc ;
4849static void (* __flint_aligned_free_func )(void * ) = _flint_aligned_free ;
50+ #else
51+ static void * (* __flint_aligned_allocate_func )(size_t , size_t ) = _flint_aligned_alloc2 ;
52+ static void (* __flint_aligned_free_func )(void * ) = _flint_aligned_free2 ;
53+ #endif
4954
5055FLINT_STATIC_NOINLINE void flint_memory_error (size_t size )
5156{
@@ -147,10 +152,12 @@ void flint_free(void * ptr)
147152
148153void * _flint_aligned_alloc (size_t alignment , size_t size )
149154{
150- #if defined( _MSC_VER ) || defined( __MINGW32__ ) || defined( __MINGW64__ )
155+ #if HAVE__ALIGNED_MALLOC
151156 return _aligned_malloc (size , alignment );
152- #else
157+ #elif HAVE_ALIGNED_ALLOC
153158 return aligned_alloc (alignment , size );
159+ #else
160+ return NULL ;
154161#endif
155162}
156163
@@ -163,7 +170,7 @@ void * _flint_aligned_alloc2(size_t alignment, size_t size)
163170
164171 alloc_size = size + alignment ;
165172
166- alloc_ptr = malloc (alloc_size );
173+ alloc_ptr = flint_malloc (alloc_size );
167174
168175 /* Case 1: alloc_ptr aligned with (alignment, alignment - sizeof(ulong)).
169176 We only need `size + sizeof(ulong)' bytes.
@@ -195,18 +202,20 @@ FLINT_WARN_UNUSED void * flint_aligned_alloc(size_t alignment, size_t size)
195202
196203void _flint_aligned_free (void * p )
197204{
198- #if defined( _MSC_VER ) || defined( __MINGW32__ ) || defined( __MINGW64__ )
205+ #if HAVE__ALIGNED_MALLOC
199206 _aligned_free (p );
200- #else
207+ #elif HAVE_ALIGNED_ALLOC
201208 free (p );
209+ #else
210+ return ;
202211#endif
203212}
204213
205214void _flint_aligned_free2 (void * p )
206215{
207216 size_t * ptr = p ;
208217 if (ptr != NULL )
209- free ((char * ) ptr - ptr [-1 ]);
218+ flint_free ((char * ) ptr - ptr [-1 ]);
210219}
211220
212221void flint_aligned_free (void * ptr )
0 commit comments