8000 use realloc instead · adafruit/circuitpython@f63b2c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f63b2c0

Browse files
committed
use realloc instead
1 parent 9e6a9e4 commit f63b2c0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ports/nrf/common-hal/neopixel_write/__init__.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,21 @@ void common_hal_neopixel_write (const digitalio_digitalinout_obj_t* digitalinout
150150
if (MP_STATE_VM(pixels_pattern_heap)) {
151151
// Old pixels_pattern_heap will be gc'd; don't free it.
152152
pixels_pattern = NULL;
153-
MP_STATE_VM(pixels_pattern_heap) = NULL;
154153
pixels_pattern_heap_size = 0;
155154
}
156155

156+
// realloc routines fall back to a plain malloc if the incoming ptr is NULL.
157157
if (sd_en) {
158158
// If the soft device is enabled then we must use PWM to
159159
// transmit. This takes a bunch of memory to do so raise an
160160
// exception if we can't.
161-
MP_STATE_VM(pixels_pattern_heap) = (uint16_t *) m_malloc(pattern_size, false);
161+
MP_STATE_VM(pixels_pattern_heap) =
162+
(uint16_t *) m_realloc(MP_STATE_VM(pixels_pattern_heap), pattern_size);
162163
} else {
163164
// Might return NULL.
164-
MP_STATE_VM(pixels_pattern_heap) = (uint16_t *) m_malloc_maybe(pattern_size, false);
165+
MP_STATE_VM(pixels_pattern_heap) =
166+
// true means move if necessary.
167+
(uint16_t *) m_realloc_maybe(MP_STATE_VM(pixels_pattern_heap), pattern_size, true);
165168
}
166169
if (MP_STATE_VM(pixels_pattern_heap)) {
167170
pixels_pattern_heap_size = pattern_size;

0 commit comments

Comments
 (0)
0