File tree Expand file tree Collapse file tree 3 files changed +80
-4
lines changed
Expand file tree Collapse file tree 3 files changed +80
-4
lines changed Original file line number Diff line number Diff line change @@ -6,22 +6,25 @@ mod gc {
66
77 #[ pyfunction]
88 fn collect ( _args : FuncArgs , _vm : & VirtualMachine ) -> i32 {
9- 0
9+ let ret: usize = rustpython_vm:: object:: gc:: collect ( ) . into ( ) ;
10+ ret as i32
1011 }
1112
1213 #[ pyfunction]
1314 fn isenabled ( _args : FuncArgs , _vm : & VirtualMachine ) -> bool {
14- false
15+ rustpython_vm :: object :: gc :: isenabled ( )
1516 }
1617
1718 #[ pyfunction]
1819 fn enable ( _args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
19- Err ( vm. new_not_implemented_error ( "" . to_owned ( ) ) )
20+ rustpython_vm:: object:: gc:: enable ( ) ;
21+ Ok ( vm. new_pyobj ( true ) )
2022 }
2123
2224 #[ pyfunction]
2325 fn disable ( _args : FuncArgs , vm : & VirtualMachine ) -> PyResult {
24- Err ( vm. new_not_implemented_error ( "" . to_owned ( ) ) )
26+ rustpython_vm:: object:: gc:: disable ( ) ;
27+ Ok ( vm. new_pyobj ( true ) )
2528 }
2629
2730 #[ pyfunction]
Original file line number Diff line number Diff line change 11use crate :: common:: { boxvec:: BoxVec , lock:: PyMutex } ;
2+ #[ cfg( feature = "gc" ) ]
3+ use crate :: object:: gc:: GLOBAL_COLLECTOR ;
24use crate :: {
35 builtins:: {
46 asyncgenerator:: PyAsyncGenWrappedValue ,
@@ -349,6 +351,18 @@ impl ExecutingFrame<'_> {
349351 self . update_lasti ( |i| * i += 1 ) ;
350352 let instr = & instrs[ idx] ;
351353 let result = self . execute_instruction ( instr, vm) ;
354+ if matches ! ( instr, & bytecode:: Instruction :: ReturnValue ) {
355+ // only do gc if after certain instruction(to be decided), so to avoid strange bugs?
356+ // it seems ReturnValue is safe enough & frequent enough to do gc() after execute it?
357+ // &bytecode::Instruction::ReturnValue | &bytecode::Instruction::StoreLocal(..)
358+ #[ cfg( feature = "gc" ) ]
359+ {
360+ #[ cfg( feature = "threading" ) ]
361+ GLOBAL_COLLECTOR . gc ( ) ;
362+ #[ cfg( not( feature = "threading" ) ) ]
363+ GLOBAL_COLLECTOR . with ( |v| v. gc ( ) ) ;
364+ }
365+ }
352366 match result {
353367 Ok ( None ) => continue ,
354368 Ok ( Some ( value) ) => {
You can’t perform that action at this time.
0 commit comments