Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
0d165fec
Commit
0d165fec
authored
Dec 13, 2018
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py/qstr: Put a lower bound on new qstr pool allocation.
parent
0c464193
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
4 deletions
+13
-4
py/qstr.c
py/qstr.c
+13
-4
No files found.
py/qstr.c
View file @
0d165fec
...
...
@@ -80,6 +80,10 @@
#define QSTR_EXIT()
#endif
// Initial number of entries for qstr pool, set so that the first dynamically
// allocated pool is twice this size. The value here must be <= MP_QSTRnumber_of.
#define MICROPY_ALLOC_QSTR_ENTRIES_INIT (10)
// this must match the equivalent function in makeqstrdata.py
mp_uint_t
qstr_compute_hash
(
const
byte
*
data
,
size_t
len
)
{
// djb2 algorithm; see http://www.cse.yorku.ca/~oz/hash.html
...
...
@@ -98,7 +102,7 @@ mp_uint_t qstr_compute_hash(const byte *data, size_t len) {
const
qstr_pool_t
mp_qstr_const_pool
=
{
NULL
,
// no previous pool
0
,
// no previous pool
10
,
// set so that the first dynamically allocated pool is twice this size; must be <= the len (just below)
MICROPY_ALLOC_QSTR_ENTRIES_INIT
,
MP_QSTRnumber_of
,
// corresponds to number of strings in array just below
{
#ifndef NO_QSTR
...
...
@@ -141,14 +145,19 @@ STATIC qstr qstr_add(const byte *q_ptr) {
// make sure we have room in the pool for a new qstr
if
(
MP_STATE_VM
(
last_pool
)
->
len
>=
MP_STATE_VM
(
last_pool
)
->
alloc
)
{
qstr_pool_t
*
pool
=
m_new_obj_var_maybe
(
qstr_pool_t
,
const
char
*
,
MP_STATE_VM
(
last_pool
)
->
alloc
*
2
);
size_t
new_alloc
=
MP_STATE_VM
(
last_pool
)
->
alloc
*
2
;
#ifdef MICROPY_QSTR_EXTRA_POOL
// Put a lower bound on the allocation size in case the extra qstr pool has few entries
new_alloc
=
MAX
(
MICROPY_ALLOC_QSTR_ENTRIES_INIT
,
new_alloc
);
#endif
qstr_pool_t
*
pool
=
m_new_obj_var_maybe
(
qstr_pool_t
,
const
char
*
,
new_alloc
);
if
(
pool
==
NULL
)
{
QSTR_EXIT
();
m_malloc_fail
(
MP_STATE_VM
(
last_pool
)
->
alloc
*
2
);
m_malloc_fail
(
new_alloc
);
}
pool
->
prev
=
MP_STATE_VM
(
last_pool
);
pool
->
total_prev_len
=
MP_STATE_VM
(
last_pool
)
->
total_prev_len
+
MP_STATE_VM
(
last_pool
)
->
len
;
pool
->
alloc
=
MP_STATE_VM
(
last_pool
)
->
alloc
*
2
;
pool
->
alloc
=
new_alloc
;
pool
->
len
=
0
;
MP_STATE_VM
(
last_pool
)
=
pool
;
DEBUG_printf
(
"QSTR: allocate new pool of size %d
\n
"
,
MP_STATE_VM
(
last_pool
)
->
alloc
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment