Skip to content

Commit 4b42a6f

Browse files
committed
restore old uzlib; remove remaining U and u prefixes
1 parent 367e13c commit 4b42a6f

26 files changed

+548
-667
lines changed

docs/shared_bindings_matrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
}
6464

6565
ADDITIONAL_MODULES = {
66-
"_asyncio": "MICROPY_PY_UASYNCIO",
66+
"_asyncio": "MICROPY_PY_ASYNCIO",
6767
"adafruit_bus_device": "CIRCUITPY_BUSDEVICE",
6868
"adafruit_pixelbuf": "CIRCUITPY_PIXELBUF",
6969
"array": "CIRCUITPY_ARRAY",
@@ -79,7 +79,7 @@
7979
"keypad.Keys": "CIRCUITPY_KEYPAD_KEYS",
8080
"keypad.ShiftRegisterKeys": "CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS",
8181
"os.getenv": "CIRCUITPY_OS_GETENV",
82-
"select": "MICROPY_PY_USELECT_SELECT",
82+
"select": "MICROPY_PY_SELECT_SELECT",
8383
"sys": "CIRCUITPY_SYS",
8484
"terminalio": "CIRCUITPY_DISPLAYIO",
8585
"usb": "CIRCUITPY_USB_HOST",

extmod/modbinascii.c

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
#include "py/binary.h"
3333
#include "py/objstr.h"
3434

35-
//#include "lib/uzlib/tinf.h"
36-
3735
#if MICROPY_PY_BINASCII
3836

3937
static void check_not_unicode(const mp_obj_t arg) {
@@ -182,44 +180,9 @@ STATIC mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args,
182180
}
183181
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_binascii_b2a_base64_obj, 1, mod_binascii_b2a_base64);
184182

185-
// CIRCUITPY-CHANGE: uses a self-contained implementation of CRC32,
186-
// instead of depending on uzlib, like MicroPython.
187-
188-
/*
189-
* CRC32 checksum
190-
*
191-
* Copyright (c) 1998-2003 by Joergen Ibsen / Jibz
192-
* All Rights Reserved
193-
*
194-
* http://www.ibsensoftware.com/
195-
*
196-
* This software is provided 'as-is', without any express
197-
* or implied warranty. In no event will the authors be
198-
* held liable for any damages arising from the use of
199-
* this software.
200-
*
201-
* Permission is granted to anyone to use this software
202-
* for any purpose, including commercial applications,
203-
* and to alter it and redistribute it freely, subject to
204-
* the following restrictions:
205-
*
206-
* 1. The origin of this software must not be
207-
* misrepresented; you must not claim that you
208-
* wrote the original software. If you use this
209-
* software in a product, an acknowledgment in
210-
* the product documentation would be appreciated
211-
* but is not required.
212-
*
213-
* 2. Altered source versions must be plainly marked
214-
* as such, and must not be misrepresented as
215-
* being the original software.
216-
*
217-
* 3. This notice may not be removed or altered from
218-
* any source distribution.
219-
*/
220-
221-
#if MICROPY_PY_UBINASCII_CRC32
222-
//#include "lib/uzlib/uzlib.h"
183+
// CIRCUITPY-CHANGE: no deflate
184+
#if MICROPY_PY_BINASCII_CRC32
185+
#include "lib/uzlib/uzlib.h"
223186

224187
STATIC mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) {
225188
mp_buffer_info_t bufinfo;
@@ -241,14 +204,15 @@ STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = {
241204
#endif
242205
{ MP_ROM_QSTR(MP_QSTR_a2b_base64), MP_ROM_PTR(&mod_binascii_a2b_base64_obj) },
243206
{ MP_ROM_QSTR(MP_QSTR_b2a_base64), MP_ROM_PTR(&mod_binascii_b2a_base64_obj) },
207+
// CIRCUITPY-CHANGE: no deflate
244208
#if MICROPY_PY_BINASCII_CRC32
245209
{ MP_ROM_QSTR(MP_QSTR_crc32), MP_ROM_PTR(&mod_binascii_crc32_obj) },
246210
#endif
247211
};
248212

249213
STATIC MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globals_table);
250214

251-
const mp_obj_module_t mp_module_ubinascii = {
215+
const mp_obj_module_t mp_module_binascii = {
252216
.base = { &mp_type_module },
253217
.globals = (mp_obj_dict_t *)&mp_module_binascii_globals,
254218
};

extmod/modjson.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include <stdio.h>
2828

29+
#include "py/binary.h"
30+
#include "py/objarray.h"
2931
#include "py/objlist.h"
3032
#include "py/objstringio.h"
3133
#include "py/parsenum.h"
@@ -145,6 +147,7 @@ typedef struct _json_stream_t {
145147

146148
STATIC byte json_stream_next(json_stream_t *s) {
147149
mp_uint_t ret = s->read(s->stream_obj, &s->cur, 1, &s->errcode);
150+
JSON_DEBUG(" usjon_stream_next err:%2d cur: %c \n", s->errcode, s->cur);
148151
if (s->errcode != 0) {
149152
mp_raise_OSError(s->errcode);
150153
}
@@ -163,7 +166,7 @@ STATIC byte json_stream_next(json_stream_t *s) {
163166

164167
STATIC mp_uint_t json_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) {
165168
(void)size; // Ignore size because we know it's always 1.
166-
ujson_stream_t *s = obj;
169+
json_stream_t *s = obj;
167170

168171
if (s->start == s->end) {
169172
*errcode = 0;
@@ -186,7 +189,7 @@ STATIC mp_uint_t json_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, i
186189

187190
STATIC mp_obj_t _mod_json_load(mp_obj_t stream_obj, bool return_first_json) {
188191
const mp_stream_p_t *stream_p = mp_proto_get(MP_QSTR_protocol_stream, stream_obj);
189-
ujson_stream_t s;
192+
json_stream_t s;
190193
uint8_t character_buffer[CIRCUITPY_JSON_READ_CHUNK_SIZE];
191194
if (stream_p == NULL) {
192195
s.start = 0;
@@ -199,7 +202,7 @@ STATIC mp_obj_t _mod_json_load(mp_obj_t stream_obj, bool return_first_json) {
199202
s.bytearray_obj.items = character_buffer;
200203
s.python_readinto[2] = MP_OBJ_FROM_PTR(&s.bytearray_obj);
201204
s.stream_obj = &s;
202-
s.read = ujson_python_readinto;
205+
s.read = json_python_readinto;
203206
} else {
204207
stream_p = mp_get_stream_raise(stream_obj, MP_STREAM_OP_READ);
205208
s.stream_obj = stream_obj;

extmod/modrandom.c

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ STATIC uint32_t yasmarang(void) {
6767

6868
// End of Yasmarang
6969

70-
#if MICROPY_PY_URANDOM_EXTRA_FUNCS
70+
#if MICROPY_PY_RANDOM_EXTRA_FUNCS
7171

7272
// returns an unsigned integer below the given argument
7373
// n must not be zero
@@ -85,7 +85,7 @@ STATIC uint32_t yasmarang_randbelow(uint32_t n) {
8585

8686
#endif
8787

88-
STATIC mp_obj_t mod_urandom_getrandbits(mp_obj_t num_in) {
88+
STATIC mp_obj_t mod_random_getrandbits(mp_obj_t num_in) {
8989
int n = mp_obj_get_int(num_in);
9090
if (n > 32 || n < 0) {
9191
mp_raise_ValueError(MP_ERROR_TEXT("bits must be 32 or less"));
@@ -98,13 +98,13 @@ STATIC mp_obj_t mod_urandom_getrandbits(mp_obj_t num_in) {
9898
mask >>= (32 - n);
9999
return mp_obj_new_int_from_uint(yasmarang() & mask);
100100
}
101-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_urandom_getrandbits_obj, mod_urandom_getrandbits);
101+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_getrandbits_obj, mod_random_getrandbits);
102102

103-
STATIC mp_obj_t mod_urandom_seed(size_t n_args, const mp_obj_t *args) {
103+
STATIC mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) {
104104
mp_uint_t seed;
105105
if (n_args == 0 || args[0] == mp_const_none) {
106-
#ifdef MICROPY_PY_URANDOM_SEED_INIT_FUNC
107-
seed = MICROPY_PY_URANDOM_SEED_INIT_FUNC;
106+
#ifdef MICROPY_PY_RANDOM_SEED_INIT_FUNC
107+
seed = MICROPY_PY_RANDOM_SEED_INIT_FUNC;
108108
#else
109109
mp_raise_ValueError(MP_ERROR_TEXT("no default seed"));
110110
#endif
@@ -117,11 +117,11 @@ STATIC mp_obj_t mod_urandom_seed(size_t n_args, const mp_obj_t *args) {
117117
yasmarang_dat = 0;
118118
return mp_const_none;
119119
}
120-
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_urandom_seed_obj, 0, 1, mod_urandom_seed);
120+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_seed_obj, 0, 1, mod_random_seed);
121121

122-
#if MICROPY_PY_URANDOM_EXTRA_FUNCS
122+
#if MICROPY_PY_RANDOM_EXTRA_FUNCS
123123

124-
STATIC mp_obj_t mod_urandom_randrange(size_t n_args, const mp_obj_t *args) {
124+
STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) {
125125
mp_int_t start = mp_obj_get_int(args[0]);
126126
if (n_args == 1) {
127127
// range(stop)
@@ -161,9 +161,9 @@ STATIC mp_obj_t mod_urandom_randrange(size_t n_args, const mp_obj_t *args) {
161161
error:
162162
mp_raise_ValueError(NULL);
163163
}
164-
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_urandom_randrange_obj, 1, 3, mod_urandom_randrange);
164+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_randrange_obj, 1, 3, mod_random_randrange);
165165

166-
STATIC mp_obj_t mod_urandom_randint(mp_obj_t a_in, mp_obj_t b_in) {
166+
STATIC mp_obj_t mod_random_randint(mp_obj_t a_in, mp_obj_t b_in) {
167167
mp_int_t a = mp_obj_get_int(a_in);
168168
mp_int_t b = mp_obj_get_int(b_in);
169169
if (a <= b) {
@@ -172,17 +172,17 @@ STATIC mp_obj_t mod_urandom_randint(mp_obj_t a_in, mp_obj_t b_in) {
172172
mp_raise_ValueError(NULL);
173173
}
174174
}
175-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_urandom_randint_obj, mod_urandom_randint);
175+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_randint_obj, mod_random_randint);
176176

177-
STATIC mp_obj_t mod_urandom_choice(mp_obj_t seq) {
177+
STATIC mp_obj_t mod_random_choice(mp_obj_t seq) {
178178
mp_int_t len = mp_obj_get_int(mp_obj_len(seq));
179179
if (len > 0) {
180180
return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow(len)), MP_OBJ_SENTINEL);
181181
} else {
182182
mp_raise_type(&mp_type_IndexError);
183183
}
184184
}
185-
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_urandom_choice_obj, mod_urandom_choice);
185+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_choice_obj, mod_random_choice);
186186

187187
#if MICROPY_PY_BUILTINS_FLOAT
188188

@@ -199,63 +199,63 @@ STATIC mp_float_t yasmarang_float(void) {
199199
return u.f - 1;
200200
}
201201

202-
STATIC mp_obj_t mod_urandom_random(void) {
202+
STATIC mp_obj_t mod_random_random(void) {
203203
return mp_obj_new_float(yasmarang_float());
204204
}
205-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_urandom_random_obj, mod_urandom_random);
205+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_random_random_obj, mod_random_random);
206206

207-
STATIC mp_obj_t mod_urandom_uniform(mp_obj_t a_in, mp_obj_t b_in) {
207+
STATIC mp_obj_t mod_random_uniform(mp_obj_t a_in, mp_obj_t b_in) {
208208
mp_float_t a = mp_obj_get_float(a_in);
209209
mp_float_t b = mp_obj_get_float(b_in);
210210
return mp_obj_new_float(a + (b - a) * yasmarang_float());
211211
}
212-
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_urandom_uniform_obj, mod_urandom_uniform);
212+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_uniform_obj, mod_random_uniform);
213213

214214
#endif
215215

216-
#endif // MICROPY_PY_URANDOM_EXTRA_FUNCS
216+
#endif // MICROPY_PY_RANDOM_EXTRA_FUNCS
217217

218218
#if SEED_ON_IMPORT
219-
STATIC mp_obj_t mod_urandom___init__(void) {
219+
STATIC mp_obj_t mod_random___init__(void) {
220220
// This module may be imported by more than one name so need to ensure
221221
// that it's only ever seeded once.
222222
static bool seeded = false;
223223
if (!seeded) {
224224
seeded = true;
225-
mod_urandom_seed(0, NULL);
225+
mod_random_seed(0, NULL);
226226
}
227227
return mp_const_none;
228228
}
229-
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_urandom___init___obj, mod_urandom___init__);
229+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_random___init___obj, mod_random___init__);
230230
#endif
231231

232232
#if !MICROPY_ENABLE_DYNRUNTIME
233-
STATIC const mp_rom_map_elem_t mp_module_urandom_globals_table[] = {
234-
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_urandom) },
233+
STATIC const mp_rom_map_elem_t mp_module_random_globals_table[] = {
234+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_random) },
235235
#if SEED_ON_IMPORT
236-
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_urandom___init___obj) },
236+
{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_random___init___obj) },
237237
#endif
238-
{ MP_ROM_QSTR(MP_QSTR_getrandbits), MP_ROM_PTR(&mod_urandom_getrandbits_obj) },
239-
{ MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_urandom_seed_obj) },
240-
#if MICROPY_PY_URANDOM_EXTRA_FUNCS
241-
{ MP_ROM_QSTR(MP_QSTR_randrange), MP_ROM_PTR(&mod_urandom_randrange_obj) },
242-
{ MP_ROM_QSTR(MP_QSTR_randint), MP_ROM_PTR(&mod_urandom_randint_obj) },
243-
{ MP_ROM_QSTR(MP_QSTR_choice), MP_ROM_PTR(&mod_urandom_choice_obj) },
238+
{ MP_ROM_QSTR(MP_QSTR_getrandbits), MP_ROM_PTR(&mod_random_getrandbits_obj) },
239+
{ MP_ROM_QSTR(MP_QSTR_seed), MP_ROM_PTR(&mod_random_seed_obj) },
240+
#if MICROPY_PY_RANDOM_EXTRA_FUNCS
241+
{ MP_ROM_QSTR(MP_QSTR_randrange), MP_ROM_PTR(&mod_random_randrange_obj) },
242+
{ MP_ROM_QSTR(MP_QSTR_randint), MP_ROM_PTR(&mod_random_randint_obj) },
243+
{ MP_ROM_QSTR(MP_QSTR_choice), MP_ROM_PTR(&mod_random_choice_obj) },
244244
#if MICROPY_PY_BUILTINS_FLOAT
245-
{ MP_ROM_QSTR(MP_QSTR_random), MP_ROM_PTR(&mod_urandom_random_obj) },
246-
{ MP_ROM_QSTR(MP_QSTR_uniform), MP_ROM_PTR(&mod_urandom_uniform_obj) },
245+
{ MP_ROM_QSTR(MP_QSTR_random), MP_ROM_PTR(&mod_random_random_obj) },
246+
{ MP_ROM_QSTR(MP_QSTR_uniform), MP_ROM_PTR(&mod_random_uniform_obj) },
247247
#endif
248248
#endif
249249
};
250250

251-
STATIC MP_DEFINE_CONST_DICT(mp_module_urandom_globals, mp_module_urandom_globals_table);
251+
STATIC MP_DEFINE_CONST_DICT(mp_module_random_globals, mp_module_random_globals_table);
252252

253-
const mp_obj_module_t mp_module_urandom = {
253+
const mp_obj_module_t mp_module_random = {
254254
.base = { &mp_type_module },
255-
.globals = (mp_obj_dict_t *)&mp_module_urandom_globals,
255+
.globals = (mp_obj_dict_t *)&mp_module_random_globals,
256256
};
257257

258-
MP_REGISTER_MODULE(MP_QSTR_urandom, mp_module_urandom);
258+
MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_random, mp_module_random);
259259
#endif
260260

261-
#endif // MICROPY_PY_URANDOM
261+
#endif // MICROPY_PY_RANDOM

extmod/modre.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
8585
}
8686
MP_DEFINE_CONST_FUN_OBJ_2(match_group_obj, match_group);
8787

88-
#if MICROPY_PY_URE_MATCH_GROUPS
88+
#if MICROPY_PY_RE_MATCH_GROUPS
8989

9090
STATIC mp_obj_t match_groups(mp_obj_t self_in) {
9191
mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in);
@@ -102,7 +102,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(match_groups_obj, match_groups);
102102

103103
#endif
104104

105-
#if MICROPY_PY_URE_MATCH_SPAN_START_END
105+
#if MICROPY_PY_RE_MATCH_SPAN_START_END
106106

107107
STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span[2]) {
108108
mp_obj_match_t *self = MP_OBJ_TO_PTR(args[0]);

extmod/modselect.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,9 @@ STATIC mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size
372372
if (mp_hal_is_interrupted()) {
373373
return 0;
374374
}
375-
// end CIRCUITPY
376-
MICROPY_EVENT_POLL_HOOK
375+
#ifdef MICROPY_EVENT_POLL_HOOK
376+
MICROPY_EVENT_POLL_HOOK;
377+
#endif
377378
}
378379

379380
#endif

lib/uzlib/adler32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
3737
*/
3838

39-
#include "uzlib.h"
39+
#include "tinf.h"
4040

4141
#define A32_BASE 65521
4242
#define A32_NMAX 5552

lib/uzlib/crc32.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
3737
*/
3838

39-
#include "uzlib.h"
39+
#include "tinf.h"
4040

4141
static const unsigned int tinf_crc32tab[16] = {
4242
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190,

0 commit comments

Comments
 (0)