Skip to content

Commit 93a60ee

Browse files
authored
Merge pull request #5946 from tammymakesthings/pr4218-neopixel-show-after-deinit
Fixes neopixel show() after deinit() not raising an exception
2 parents 6d8efa7 + 748834c commit 93a60ee

23 files changed

+105
-91
lines changed

ports/atmel-samd/mpconfigport.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ifeq ($(CHIP_FAMILY),samd21)
2020
# fit in 256kB of flash
2121

2222
CIRCUITPY_AESIO ?= 0
23+
CIRCUITPY_ATEXIT ?= 0
2324
CIRCUITPY_AUDIOMIXER ?= 0
2425
CIRCUITPY_BINASCII ?= 0
2526
CIRCUITPY_BITBANGIO ?= 0
@@ -33,6 +34,7 @@ CIRCUITPY_COUNTIO ?= 0
3334
# Not enough RAM for framebuffers
3435
CIRCUITPY_FRAMEBUFFERIO ?= 0
3536
CIRCUITPY_FREQUENCYIO ?= 0
37+
CIRCUITPY_GETPASS ?= 0
3638
CIRCUITPY_GIFIO ?= 0
3739
CIRCUITPY_I2CPERIPHERAL ?= 0
3840
CIRCUITPY_JSON ?= 0

shared-bindings/neopixel_write/__init__.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@
2929
#include "py/mphal.h"
3030
#include "py/runtime.h"
3131
#include "shared-bindings/digitalio/DigitalInOut.h"
32+
#include "shared-bindings/util.h"
3233
#include "supervisor/shared/translate.h"
3334

35+
STATIC void check_for_deinit(digitalio_digitalinout_obj_t *self) {
36+
if (common_hal_digitalio_digitalinout_deinited(self)) {
37+
raise_deinited_error();
38+
}
39+
}
40+
3441
//| """Low-level neopixel implementation
3542
//|
3643
//| The `neopixel_write` module contains a helper method to write out bytes in
@@ -60,8 +67,13 @@ STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj
6067
if (!mp_obj_is_type(digitalinout_obj, &digitalio_digitalinout_type)) {
6168
mp_raise_TypeError_varg(translate("Expected a %q"), digitalio_digitalinout_type.name);
6269
}
70+
6371
// Convert parameters into expected types.
6472
const digitalio_digitalinout_obj_t *digitalinout = MP_OBJ_TO_PTR(digitalinout_obj);
73+
74+
// Check to see if the NeoPixel has been deinited before writing to it.
75+
check_for_deinit(digitalinout_obj);
76+
6577
mp_buffer_info_t bufinfo;
6678
mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ);
6779
// Call platform's neopixel write function with provided buffer and options.

tests/circuitpython-manual/audiobusio/i2s_sample_loop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# signed 16 bit
2020
s16 = array.array("h", [0] * length)
2121
for i in range(length):
22-
s16[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 15))
22+
s16[i] = int(math.sin(math.pi * 2 * i / length) * (2**15))
2323
print(s16[i])
2424

2525
sample = audiocore.RawSample(s16, sample_rate=8000)

tests/circuitpython-manual/audiopwmio/single_buffer_loop.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@
1919
# unsigned 8 bit
2020
u8 = array.array("B", [0] * length)
2121
for i in range(length):
22-
u8[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 7) + 2 ** 7)
22+
u8[i] = int(math.sin(math.pi * 2 * i / length) * (2**7) + 2**7)
2323

2424
samples.append(audiocore.RawSample(u8, sample_rate=4000))
2525

2626
# signed 8 bit
2727
s8 = array.array("b", [0] * length)
2828
for i in range(length):
29-
s8[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 7))
29+
s8[i] = int(math.sin(math.pi * 2 * i / length) * (2**7))
3030

3131
samples.append(audiocore.RawSample(s8, sample_rate=16000))
3232

3333
# unsigned 16 bit
3434
u16 = array.array("H", [0] * length)
3535
for i in range(length):
36-
u16[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 15) + 2 ** 15)
36+
u16[i] = int(math.sin(math.pi * 2 * i / length) * (2**15) + 2**15)
3737

3838
samples.append(audiocore.RawSample(u16, sample_rate=8000))
3939

4040

4141
# signed 16 bit
4242
s16 = array.array("h", [0] * length)
4343
for i in range(length):
44-
s16[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 15))
44+
s16[i] = int(math.sin(math.pi * 2 * i / length) * (2**15))
4545

4646
samples.append(audiocore.RawSample(s16, sample_rate=8000))
4747

tests/cpydiff/modules_random_randint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
import random
99

1010

11-
x = random.randint(2 ** 128 - 1, 2 ** 128)
11+
x = random.randint(2**128 - 1, 2**128)
1212
print("x={}".format(x))

tests/extmod/uhashlib_sha1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
sha1 = hashlib.sha1(b"hello")
2424
try:
25-
sha1.update(u"world")
25+
sha1.update("world")
2626
except TypeError as e:
2727
print("TypeError")
2828
print(sha1.digest())

tests/extmod/uhashlib_sha256.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
sha256 = hashlib.sha256(b"hello")
3030
try:
31-
sha256.update(u"world")
31+
sha256.update("world")
3232
except TypeError as e:
3333
print("TypeError")
3434
print(sha256.digest())

tests/float/complex1.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
print(1j / 2)
2828
print((1j / 2j).real)
2929
print(1j / (1 + 2j))
30-
ans = 0j ** 0
30+
ans = 0j**0
3131
print("%.5g %.5g" % (ans.real, ans.imag))
32-
ans = 0j ** 1
32+
ans = 0j**1
3333
print("%.5g %.5g" % (ans.real, ans.imag))
34-
ans = 0j ** 0j
34+
ans = 0j**0j
3535
print("%.5g %.5g" % (ans.real, ans.imag))
36-
ans = 1j ** 2.5
36+
ans = 1j**2.5
3737
print("%.5g %.5g" % (ans.real, ans.imag))
38-
ans = 1j ** 2.5j
38+
ans = 1j**2.5j
3939
print("%.5g %.5g" % (ans.real, ans.imag))
4040

4141
# comparison
@@ -116,10 +116,10 @@
116116

117117
# zero division via power
118118
try:
119-
0j ** -1
119+
0j**-1
120120
except ZeroDivisionError:
121121
print("ZeroDivisionError")
122122
try:
123-
0j ** 1j
123+
0j**1j
124124
except ZeroDivisionError:
125125
print("ZeroDivisionError")

tests/float/float1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
print("ZeroDivisionError")
8989

9090
try:
91-
0.0 ** -1
91+
0.0**-1
9292
except ZeroDivisionError:
9393
print("ZeroDivisionError")
9494

tests/float/float2int_doubleprec_intbig.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@
3535
print(int(1418774543.0))
3636
print("%d" % 1418774543.0)
3737
if ll_type == 3:
38-
print(int(2.0 ** 100))
39-
print("%d" % 2.0 ** 100)
38+
print(int(2.0**100))
39+
print("%d" % 2.0**100)
4040
else:
4141
print(int(1073741823.0))
4242
print("%d" % 1073741823.0)
4343

4444
testpass = True
4545
p2_rng = ((30, 63, 1024), (62, 63, 1024))[is_64bit][ll_type]
4646
for i in range(0, p2_rng):
47-
bitcnt = len(bin(int(2.0 ** i))) - 3
47+
bitcnt = len(bin(int(2.0**i))) - 3
4848
if i != bitcnt:
4949
print("fail: 2**%u was %u bits long" % (i, bitcnt))
5050
testpass = False
@@ -53,7 +53,7 @@
5353
testpass = True
5454
p10_rng = ((9, 18, 23), (18, 18, 23))[is_64bit][ll_type]
5555
for i in range(0, p10_rng):
56-
digcnt = len(str(int(10.0 ** i))) - 1
56+
digcnt = len(str(int(10.0**i))) - 1
5757
if i != digcnt:
5858
print("fail: 10**%u was %u digits long" % (i, digcnt))
5959
testpass = False
@@ -72,28 +72,28 @@ def fp2int_test(num, name, should_fail):
7272
if ll_type != 2:
7373
if ll_type == 0:
7474
if is_64bit:
75-
neg_bad_fp = -1.00000005 * 2.0 ** 62.0
76-
pos_bad_fp = 2.0 ** 62.0
77-
neg_good_fp = -(2.0 ** 62.0)
78-
pos_good_fp = 0.99999993 * 2.0 ** 62.0
75+
neg_bad_fp = -1.00000005 * 2.0**62.0
76+
pos_bad_fp = 2.0**62.0
77+
neg_good_fp = -(2.0**62.0)
78+
pos_good_fp = 0.99999993 * 2.0**62.0
7979
else:
80-
neg_bad_fp = -1.00000005 * 2.0 ** 30.0
81-
pos_bad_fp = 2.0 ** 30.0
82-
neg_good_fp = -(2.0 ** 30.0)
83-
pos_good_fp = 0.9999999499 * 2.0 ** 30.0
80+
neg_bad_fp = -1.00000005 * 2.0**30.0
81+
pos_bad_fp = 2.0**30.0
82+
neg_good_fp = -(2.0**30.0)
83+
pos_good_fp = 0.9999999499 * 2.0**30.0
8484
else:
85-
neg_bad_fp = -0.51 * 2.0 ** 64.0
86-
pos_bad_fp = 2.0 ** 63.0
87-
neg_good_fp = -(2.0 ** 63.0)
88-
pos_good_fp = 1.9999998 * 2.0 ** 62.0
85+
neg_bad_fp = -0.51 * 2.0**64.0
86+
pos_bad_fp = 2.0**63.0
87+
neg_good_fp = -(2.0**63.0)
88+
pos_good_fp = 1.9999998 * 2.0**62.0
8989

9090
fp2int_test(neg_bad_fp, "neg bad", True)
9191
fp2int_test(pos_bad_fp, "pos bad", True)
9292
fp2int_test(neg_good_fp, "neg good", False)
9393
fp2int_test(pos_good_fp, "pos good", False)
9494
else:
95-
fp2int_test(-1.9999999999999981 * 2.0 ** 1023.0, "large neg", False)
96-
fp2int_test(1.9999999999999981 * 2.0 ** 1023.0, "large pos", False)
95+
fp2int_test(-1.9999999999999981 * 2.0**1023.0, "large neg", False)
96+
fp2int_test(1.9999999999999981 * 2.0**1023.0, "large pos", False)
9797

9898
fp2int_test(float("inf"), "inf test", True)
9999
fp2int_test(float("-inf"), "inf test", True)

tests/float/float2int_fp30_intbig.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
print(int(14187744.0))
3535
print("%d" % 14187744.0)
3636
if ll_type == 2:
37-
print(int(2.0 ** 100))
38-
print("%d" % 2.0 ** 100)
37+
print(int(2.0**100))
38+
print("%d" % 2.0**100)
3939

4040
testpass = True
4141
p2_rng = ((30, 63, 127), (62, 63, 127))[is_64bit][ll_type]
4242
for i in range(0, p2_rng):
43-
bitcnt = len(bin(int(2.0 ** i))) - 3
43+
bitcnt = len(bin(int(2.0**i))) - 3
4444
if i != bitcnt:
4545
print("fail: 2.**%u was %u bits long" % (i, bitcnt))
4646
testpass = False
@@ -50,7 +50,7 @@
5050
testpass = True
5151
p10_rng = 9
5252
for i in range(0, p10_rng):
53-
digcnt = len(str(int(10.0 ** i))) - 1
53+
digcnt = len(str(int(10.0**i))) - 1
5454
if i != digcnt:
5555
print("fail: 10.**%u was %u digits long" % (i, digcnt))
5656
testpass = False
@@ -69,28 +69,28 @@ def fp2int_test(num, name, should_fail):
6969
if ll_type != 2:
7070
if ll_type == 0:
7171
if is_64bit:
72-
neg_bad_fp = -1.00000005 * 2.0 ** 62.0
73-
pos_bad_fp = 2.0 ** 62.0
74-
neg_good_fp = -(2.0 ** 62.0)
75-
pos_good_fp = 0.99999993 * 2.0 ** 62.0
72+
neg_bad_fp = -1.00000005 * 2.0**62.0
73+
pos_bad_fp = 2.0**62.0
74+
neg_good_fp = -(2.0**62.0)
75+
pos_good_fp = 0.99999993 * 2.0**62.0
7676
else:
77-
neg_bad_fp = -1.00000005 * 2.0 ** 30.0
78-
pos_bad_fp = 2.0 ** 30.0
79-
neg_good_fp = -(2.0 ** 30.0)
80-
pos_good_fp = 0.9999999499 * 2.0 ** 30.0
77+
neg_bad_fp = -1.00000005 * 2.0**30.0
78+
pos_bad_fp = 2.0**30.0
79+
neg_good_fp = -(2.0**30.0)
80+
pos_good_fp = 0.9999999499 * 2.0**30.0
8181
else:
82-
neg_bad_fp = -0.51 * 2.0 ** 64.0
83-
pos_bad_fp = 2.0 ** 63.0
84-
neg_good_fp = -(2.0 ** 63.0)
85-
pos_good_fp = 1.9999998 * 2.0 ** 62.0
82+
neg_bad_fp = -0.51 * 2.0**64.0
83+
pos_bad_fp = 2.0**63.0
84+
neg_good_fp = -(2.0**63.0)
85+
pos_good_fp = 1.9999998 * 2.0**62.0
8686

8787
fp2int_test(neg_bad_fp, "neg bad", True)
8888
fp2int_test(pos_bad_fp, "pos bad", True)
8989
fp2int_test(neg_good_fp, "neg good", False)
9090
fp2int_test(pos_good_fp, "pos good", False)
9191
else:
92-
fp2int_test(-1.999999879 * 2.0 ** 126.0, "large neg", False)
93-
fp2int_test(1.999999879 * 2.0 ** 126.0, "large pos", False)
92+
fp2int_test(-1.999999879 * 2.0**126.0, "large neg", False)
93+
fp2int_test(1.999999879 * 2.0**126.0, "large pos", False)
9494

9595
fp2int_test(float("inf"), "inf test", True)
9696
fp2int_test(float("-inf"), "inf test", True)

tests/float/float2int_intbig.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
print("%d" % 14187745.)
3838
# fmt: on
3939
if ll_type == 2:
40-
print(int(2.0 ** 100))
41-
print("%d" % 2.0 ** 100)
40+
print(int(2.0**100))
41+
print("%d" % 2.0**100)
4242

4343
testpass = True
4444
p2_rng = ((30, 63, 127), (62, 63, 127))[is_64bit][ll_type]
4545
for i in range(0, p2_rng):
46-
bitcnt = len(bin(int(2.0 ** i))) - 3
46+
bitcnt = len(bin(int(2.0**i))) - 3
4747
if i != bitcnt:
4848
print("fail: 2.**%u was %u bits long" % (i, bitcnt))
4949
testpass = False
@@ -53,7 +53,7 @@
5353
testpass = True
5454
p10_rng = 9 if (ll_type == 0 and ~is_64bit) else 11
5555
for i in range(0, p10_rng):
56-
digcnt = len(str(int(10.0 ** i))) - 1
56+
digcnt = len(str(int(10.0**i))) - 1
5757
if i != digcnt:
5858
print("fail: 10.**%u was %u digits long" % (i, digcnt))
5959
testpass = False
@@ -72,28 +72,28 @@ def fp2int_test(num, name, should_fail):
7272
if ll_type != 2:
7373
if ll_type == 0:
7474
if is_64bit:
75-
neg_bad_fp = -1.00000005 * 2.0 ** 62.0
76-
pos_bad_fp = 2.0 ** 62.0
77-
neg_good_fp = -(2.0 ** 62.0)
78-
pos_good_fp = 0.99999993 * 2.0 ** 62.0
75+
neg_bad_fp = -1.00000005 * 2.0**62.0
76+
pos_bad_fp = 2.0**62.0
77+
neg_good_fp = -(2.0**62.0)
78+
pos_good_fp = 0.99999993 * 2.0**62.0
7979
else:
80-
neg_bad_fp = -1.00000005 * 2.0 ** 30.0
81-
pos_bad_fp = 2.0 ** 30.0
82-
neg_good_fp = -(2.0 ** 30.0)
83-
pos_good_fp = 0.9999999499 * 2.0 ** 30.0
80+
neg_bad_fp = -1.00000005 * 2.0**30.0
81+
pos_bad_fp = 2.0**30.0
82+
neg_good_fp = -(2.0**30.0)
83+
pos_good_fp = 0.9999999499 * 2.0**30.0
8484
else:
85-
neg_bad_fp = -0.51 * 2.0 ** 64.0
86-
pos_bad_fp = 2.0 ** 63.0
87-
neg_good_fp = -(2.0 ** 63.0)
88-
pos_good_fp = 1.9999998 * 2.0 ** 62.0
85+
neg_bad_fp = -0.51 * 2.0**64.0
86+
pos_bad_fp = 2.0**63.0
87+
neg_good_fp = -(2.0**63.0)
88+
pos_good_fp = 1.9999998 * 2.0**62.0
8989

9090
fp2int_test(neg_bad_fp, "neg bad", True)
9191
fp2int_test(pos_bad_fp, "pos bad", True)
9292
fp2int_test(neg_good_fp, "neg good", False)
9393
fp2int_test(pos_good_fp, "pos good", False)
9494
else:
95-
fp2int_test(-1.999999879 * 2.0 ** 127.0, "large neg", False)
96-
fp2int_test(1.999999879 * 2.0 ** 127.0, "large pos", False)
95+
fp2int_test(-1.999999879 * 2.0**127.0, "large neg", False)
96+
fp2int_test(1.999999879 * 2.0**127.0, "large pos", False)
9797

9898
fp2int_test(float("inf"), "inf test", True)
9999
fp2int_test(float("nan"), "NaN test", True)

tests/float/inf_nan_arith.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
except ZeroDivisionError:
1515
print(" / ZeroDivisionError")
1616
try:
17-
print(" ** pow", x ** y, pow(x, y))
17+
print(" ** pow", x**y, pow(x, y))
1818
except ZeroDivisionError:
1919
print(" ** pow ZeroDivisionError")
2020
print(" == != < <= > >=", x == y, x != y, x < y, x <= y, x > y, x >= y)

tests/float/int_big_float.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
print("%.5g" % (i * 1.2j).imag)
2020

2121
# negative power should produce float
22-
print("%.5g" % (i ** -1))
22+
print("%.5g" % (i**-1))
2323
print("%.5g" % ((2 + i - i) ** -3))
2424

2525
try:

tests/float/int_divzero.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
print("ZeroDivisionError")
55

66
try:
7-
0 ** -1
7+
0**-1
88
except ZeroDivisionError:
99
print("ZeroDivisionError")

0 commit comments

Comments
 (0)