File tree Expand file tree Collapse file tree 3 files changed +39
-4
lines changed
src/main/java/org/truffleruby/cext Expand file tree Collapse file tree 3 files changed +39
-4
lines changed Original file line number Diff line number Diff line change @@ -498,10 +498,11 @@ MUST_INLINE int RB_FLOAT_TYPE_P(VALUE obj);
498
498
499
499
bool RB_TYPE_P (VALUE value , int type );
500
500
501
- #define HAVE_RB_GC_GUARDED_PTR_VAL 1
502
- #define rb_gc_guarded_ptr_val (ptr , val ) (ptr)
503
- #define RB_GC_GUARD (v ) (v)
504
- #define RB_GC_GUARD_PTR (ptr ) (ptr)
501
+ #define RB_GC_GUARD (v ) \
502
+ (*__extension__ ({ \
503
+ VALUE *rb_gc_guarded_ptr = rb_tr_gc_guard(v); \
504
+ rb_gc_guarded_ptr; \
505
+ }))
505
506
506
507
#ifdef __GNUC__
507
508
#define RB_UNUSED_VAR (x ) x __attribute__ ((unused))
Original file line number Diff line number Diff line change @@ -48,6 +48,14 @@ MUST_INLINE VALUE rb_tr_unwrap(VALUE object) {
48
48
return polyglot_invoke (RUBY_CEXT , "rb_tr_unwrap" , object );
49
49
}
50
50
51
+ // Needed for GC guarding
52
+
53
+ MUST_INLINE VALUE * rb_tr_gc_guard (VALUE v ) {
54
+ VALUE * ptr = & v ;
55
+ polyglot_invoke (RUBY_CEXT , "rb_tr_gc_guard" , v );
56
+ return ptr ;
57
+ }
58
+
51
59
#include <ruby/thread_native.h>
52
60
53
61
// Helpers
Original file line number Diff line number Diff line change @@ -1384,6 +1384,32 @@ protected UnwrapNode createUnwrapNode() {
1384
1384
}
1385
1385
}
1386
1386
1387
+ @ CoreMethod (names = "rb_tr_gc_guard" , onSingleton = true , required = 1 )
1388
+ public abstract static class GCGuardNode extends CoreMethodArrayArgumentsNode {
1389
+
1390
+ @ Specialization
1391
+ public DynamicObject addToMarkList (VirtualFrame frmae , Object guardedObject ,
1392
+ @ Cached ("create()" ) BranchProfile exceptionProfile ,
1393
+ @ Cached ("create()" ) UnwrapNode .ToWrapperNode toWrapperNode ) {
1394
+ ValueWrapper wrappedValue = toWrapperNode .execute (guardedObject );
1395
+ if (wrappedValue == null ) {
1396
+ exceptionProfile .enter ();
1397
+ throw new RaiseException (getContext (), coreExceptions ().runtimeError (exceptionMessage (guardedObject ), this ));
1398
+ }
1399
+ getContext ().getMarkingService ().keepObject (guardedObject );
1400
+ return nil ();
1401
+ }
1402
+
1403
+ @ TruffleBoundary
1404
+ private String exceptionMessage (Object value ) {
1405
+ return String .format ("native handle not found (%s) to guard it" , value );
1406
+ }
1407
+
1408
+ protected UnwrapNode createUnwrapNode () {
1409
+ return UnwrapNodeGen .create ();
1410
+ }
1411
+ }
1412
+
1387
1413
@ CoreMethod (names = "set_mark_list_on_object" , onSingleton = true , required = 1 )
1388
1414
public abstract static class SetMarkList extends CoreMethodArrayArgumentsNode {
1389
1415
You can’t perform that action at this time.
0 commit comments