Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
ff9a24f6
Commit
ff9a24f6
authored
Jan 04, 2014
by
John R. Lenton
Browse files
Merge remote-tracking branch 'upstream/master' into list_count
parents
a58cf679
32f88410
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/objstr.c
View file @
ff9a24f6
...
...
@@ -41,9 +41,20 @@ mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
int
len
=
strlen
(
lhs_str
);
if
(
start
<
0
)
{
start
=
len
+
start
;
if
(
start
<
0
)
{
start
=
0
;
}
}
else
if
(
start
>
len
)
{
start
=
len
;
}
if
(
stop
<=
0
)
{
stop
=
len
+
stop
;
// CPython returns empty string in such case
if
(
stop
<
0
)
{
stop
=
start
;
}
}
else
if
(
stop
>
len
)
{
stop
=
len
;
}
return
mp_obj_new_str
(
qstr_from_strn_copy
(
lhs_str
+
start
,
stop
-
start
));
#endif
...
...
stm/storage.c
View file @
ff9a24f6
...
...
@@ -49,6 +49,18 @@ static uint8_t *cache_get_addr_for_write(uint32_t flash_addr) {
return
(
uint8_t
*
)
CACHE_MEM_START_ADDR
+
flash_addr
-
flash_sector_start
;
}
static
uint8_t
*
cache_get_addr_for_read
(
uint32_t
flash_addr
)
{
uint32_t
flash_sector_start
;
uint32_t
flash_sector_size
;
uint32_t
flash_sector_id
=
flash_get_sector_info
(
flash_addr
,
&
flash_sector_start
,
&
flash_sector_size
);
if
(
cache_flash_sector_id
==
flash_sector_id
)
{
// in cache, copy from there
return
(
uint8_t
*
)
CACHE_MEM_START_ADDR
+
flash_addr
-
flash_sector_start
;
}
// not in cache, copy straight from flash
return
(
uint8_t
*
)
flash_addr
;
}
void
storage_init
(
void
)
{
if
(
!
is_initialised
)
{
cache_flash_sector_id
=
0
;
...
...
@@ -131,8 +143,9 @@ bool storage_read_block(uint8_t *dest, uint32_t block) {
return
true
;
}
else
if
(
FLASH_PART1_START_BLOCK
<=
block
&&
block
<
FLASH_PART1_START_BLOCK
+
FLASH_PART1_NUM_BLOCKS
)
{
// non-MBR block, just copy straight from flash
uint8_t
*
src
=
(
uint8_t
*
)
FLASH_MEM_START_ADDR
+
(
block
-
FLASH_PART1_START_BLOCK
)
*
BLOCK_SIZE
;
// non-MBR block, get data from flash memory, possibly via cache
uint32_t
flash_addr
=
FLASH_MEM_START_ADDR
+
(
block
-
FLASH_PART1_START_BLOCK
)
*
BLOCK_SIZE
;
uint8_t
*
src
=
cache_get_addr_for_read
(
flash_addr
);
memcpy
(
dest
,
src
,
BLOCK_SIZE
);
return
true
;
...
...
tests/basics/tests/slice-bstr1.py
View file @
ff9a24f6
...
...
@@ -22,6 +22,11 @@ print(b"123"[0:])
print
(
b
"123"
[:
0
])
print
(
b
"123"
[:
-
3
])
print
(
b
"123"
[:
-
4
])
# Range check testing, don't segfault, please ;-)
print
(
b
"123"
[:
1000000
])
print
(
b
"123"
[
1000000
:])
print
(
b
"123"
[:
-
1000000
])
print
(
b
"123"
[
-
1000000
:])
# No IndexError!
print
(
b
""
[
1
:
1
])
print
(
b
""
[
-
1
:
-
1
])
Write
Preview
Supports
Markdown
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