Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
fd8b6bcf
Commit
fd8b6bcf
authored
11 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
Add gc_free function to force a block to be freed.
parent
7b2d3f38
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
py/gc.c
+24
-11
24 additions, 11 deletions
py/gc.c
py/gc.h
+2
-1
2 additions, 1 deletion
py/gc.h
with
26 additions
and
12 deletions
py/gc.c
+
24
−
11
View file @
fd8b6bcf
...
...
@@ -52,7 +52,6 @@ void gc_init(void *start, void *end) {
printf(" alloc table at %p, length %u bytes\n", gc_alloc_table_start, gc_alloc_table_byte_len);
printf(" pool at %p, length %u blocks = %u words = %u bytes\n", gc_pool_start, gc_pool_block_len, gc_pool_word_len, gc_pool_word_len * BYTES_PER_WORD);
*/
printf
(
"GC: %u bytes
\n
"
,
gc_pool_word_len
*
BYTES_PER_WORD
);
}
// ATB = allocation table byte
...
...
@@ -89,13 +88,15 @@ void gc_init(void *start, void *end) {
#define PTR_FROM_BLOCK(block) (((block) * BYTES_PER_BLOCK + (machine_uint_t)gc_pool_start))
#define ATB_FROM_BLOCK(bl) ((bl) / BLOCKS_PER_ATB)
#define VERIFY_PTR(ptr) ( \
(ptr & (BYTES_PER_BLOCK - 1)) == 0
/* must be aligned on a block */
\
&& ptr >= (machine_uint_t)gc_pool_start
/* must be above start of pool */
\
&& ptr < (machine_uint_t)gc_pool_end
/* must be below end of pool */
\
)
#define VERIFY_MARK_AND_PUSH(ptr) \
do { \
if ( \
(ptr & (BYTES_PER_BLOCK - 1)) == 0
/* must be aligned on a block */
\
&& ptr >= (machine_uint_t)gc_pool_start
/* must be above start of pool */
\
&& ptr < (machine_uint_t)gc_pool_end
/* must be below end of pool */
\
) { \
if (VERIFY_PTR(ptr)) { \
machine_uint_t _block = BLOCK_FROM_PTR(ptr); \
if (ATB_GET_KIND(_block) == AT_HEAD) { \
/* an unmarked head, mark it, and push it on gc stack */
\
...
...
@@ -283,14 +284,26 @@ found:
return
(
void
*
)(
gc_pool_start
+
start_block
*
WORDS_PER_BLOCK
);
}
// force the freeing of a piece of memory
void
gc_free
(
void
*
ptr_in
)
{
machine_uint_t
ptr
=
(
machine_uint_t
)
ptr_in
;
if
(
VERIFY_PTR
(
ptr
))
{
machine_uint_t
block
=
BLOCK_FROM_PTR
(
ptr
);
if
(
ATB_GET_KIND
(
block
)
==
AT_HEAD
)
{
// free head and all of its tail blocks
do
{
ATB_ANY_TO_FREE
(
block
);
block
+=
1
;
}
while
(
ATB_GET_KIND
(
block
)
==
AT_TAIL
);
}
}
}
machine_uint_t
gc_nbytes
(
void
*
ptr_in
)
{
machine_uint_t
ptr
=
(
machine_uint_t
)
ptr_in
;
if
(
(
ptr
&
(
BYTES_PER_BLOCK
-
1
))
==
0
// must be aligned on a block
&&
ptr
>=
(
machine_uint_t
)
gc_pool_start
// must be above start of pool
&&
ptr
<
(
machine_uint_t
)
gc_pool_end
// must be below end of pool
)
{
if
(
VERIFY_PTR
(
ptr
))
{
machine_uint_t
block
=
BLOCK_FROM_PTR
(
ptr
);
if
(
ATB_GET_KIND
(
block
)
==
AT_HEAD
)
{
// work out number of consecutive blocks in the chain starting with this on
...
...
This diff is collapsed.
Click to expand it.
py/gc.h
+
2
−
1
View file @
fd8b6bcf
...
...
@@ -4,7 +4,8 @@ void gc_collect_root(void **ptrs, machine_uint_t len);
void
gc_collect_end
();
void
gc_collect
();
void
*
gc_alloc
(
machine_uint_t
n_bytes
);
machine_uint_t
gc_nbytes
(
void
*
ptr_in
);
void
gc_free
(
void
*
ptr
);
machine_uint_t
gc_nbytes
(
void
*
ptr
);
void
*
gc_realloc
(
void
*
ptr
,
machine_uint_t
n_bytes
);
typedef
struct
_gc_info_t
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment