Skip to content

Commit 46c61a9

Browse files
committed
fix more array.tostring() removal issues in Python 3.9
Several shell.py script versions use the depreciated array.tostring() method, which has been removed in Python 3.9. I changed these instances to .tobytes(), and adjusted .ljust()'s second argument to be a byte string. I also fixed a related issue, where #flash'ing from a shell.py which assumes a 2-cell wide Forth to a non-.hex file would error because the unsigned short array returned from serialize() would be written to file with assumptions of signed short: open(dest, "wb").write(array.array("h", d).tobytes()) This would cause an overflow error. Changing "h" to "H" in that last code snippet (in swapforth.py), lines up the signdedness.
1 parent 8dbff77 commit 46c61a9

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

j1a/nandland-go/shell.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def serialize(self):
5858
for l in lines:
5959
l = l.split()
6060
s += [int(b, 16) for b in l[1:17]]
61-
s = array.array('B', s).tostring().ljust(8192, chr(0xff))
61+
s = array.array('B', s).tobytes().ljust(8192, bytes([0xFF]))
6262
return array.array('H', s)
6363

6464
if __name__ == '__main__':

j1a/shell.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def serialize(self):
6565
for l in lines:
6666
l = l.split()
6767
s += [int(b, 16) for b in l[1:17]]
68-
s = array.array('B', s).tostring().ljust(8192, chr(0xff))
68+
s = array.array('B', s).tobytes().ljust(8192, bytes([0xFF]))
6969
return array.array('H', s)
7070

7171
if __name__ == '__main__':

j1a/verilator/shell.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def serialize(self):
4646
for l in lines:
4747
l = l.split()
4848
s += [int(b, 16) for b in l[1:17]]
49-
s = array.array('B', s).tostring().ljust(8192, chr(0xff))
49+
s = array.array('B', s).tobytes().ljust(8192, bytes([0xFF]))
5050
return array.array('H', s)
5151

5252
if __name__ == '__main__':

j1a/verilator/simshell4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def serialize(self):
4646
for l in lines:
4747
l = l.split()
4848
s += [int(b, 16) for b in l[1:17]]
49-
s = array.array('B', s).tostring().ljust(8192, chr(0xff))
49+
s = array.array('B', s).tobytes().ljust(8192, bytes([0xFF]))
5050
return array.array('H', s)
5151

5252
if __name__ == '__main__':

j1b/shell.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def serialize(self):
5454
for l in lines:
5555
l = l.split()
5656
s += [int(b, 16) for b in l[1:17]]
57-
s = array.array('B', s).tostring().ljust(32768, chr(0xff))
57+
s = array.array('B', s).tobytes().ljust(8192, bytes([0xFF]))
5858
return array.array('i', s)
5959

6060
if __name__ == '__main__':

shell/swapforth.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ def shellcmd(self, cmd):
200200
if dest.endswith('.hex'):
201201
open(dest, "w").write("".join(["%08x\n" % (x & 0xffffffff) for x in d]))
202202
else:
203-
open(dest, "wb").write(array.array("i", d).tostring())
203+
open(dest, "wb").write(array.array("i", d).tobytes())
204204
else:
205205
if dest.endswith('.hex'):
206206
open(dest, "w").write("".join(["%04x\n" % (x & 0xffff) for x in d]))
207207
else:
208-
open(dest, "wb").write(array.array("h", d).tostring())
208+
open(dest, "wb").write(array.array("H", d).tobytes())
209209
elif cmd.startswith('#setclock'):
210210
n = datetime.utcnow()
211211
cmd = "decimal %d %d %d %d %d %d >time&date" % (n.second, n.minute, n.hour, n.day, n.month, n.year)

0 commit comments

Comments
 (0)