Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af8f974

Browse files
committed
Add a note about how to do the memory deallocation a bit.
This needs a lot of work.
1 parent e76adcd commit af8f974

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Python/ast.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@
2020
- syntax errors
2121
*/
2222

23+
/*
24+
Note:
25+
26+
You should rarely need to use the asdl_seq_free() in this file.
27+
If you use asdl_seq_free(), you will leak any objects held in the seq.
28+
If there is an appropriate asdl_*_seq_free() function, use it.
29+
If there isn't an asdl_*_seq_free() function for you, you will
30+
need to loop over the data in the sequence and free it.
31+
32+
asdl_seq* seq;
33+
int i;
34+
35+
for (i = 0; i < asdl_seq_LEN(seq); i++)
36+
free_***(asdl_seq_GET(seq, i));
37+
asdl_seq_free(seq);
38+
39+
Almost all of the ast functions return a seq of expr, so you should
40+
use asdl_expr_seq_free(). The exception is ast_for_suite() which
41+
returns a seq of stmt's, so use asdl_stmt_seq_free() to free it.
42+
*/
2343

2444
/* Data structure used internally */
2545
struct compiling {

0 commit comments

Comments
 (0)