circuitpython/shared-module/_protomatter/allocator.h
Jeff Epler 880fff80e9 protomatter: Respond to review comments
- rename oe_pin -> output_enable_pin
 - improve and reorganize docstrings
 - rename swapbuffers->refresh
 - rename "paused" -> "brightness", change semantics slightly
 - common_hal several functions
 - clarify why the common_hal routines can't be used directly in the
   protocol's function pointers
 - whitespace cleanups
 - remove prototypes for nonexistent functions
2020-04-14 18:24:59 -05:00

30 lines
806 B
C

#ifndef MICROPY_INCLUDED_SHARED_MODULE_PROTOMATTER_ALLOCATOR_H
#define MICROPY_INCLUDED_SHARED_MODULE_PROTOMATTER_ALLOCATOR_H
#include <stdbool.h>
#include "py/gc.h"
#include "py/misc.h"
#include "supervisor/memory.h"
#define _PM_ALLOCATOR _PM_allocator_impl
#define _PM_FREE(x) (_PM_free_impl((x)), (x)=NULL, (void)0)
static inline void *_PM_allocator_impl(size_t sz) {
if (gc_alloc_possible()) {
return m_malloc(sz + sizeof(void*), true);
} else {
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
return allocation ? allocation->ptr : NULL;
}
}
static inline void _PM_free_impl(void *ptr_in) {
supervisor_allocation *allocation = allocation_from_ptr(ptr_in);
if (allocation) {
free_memory(allocation);
}
}
#endif