22
22
import org .jcodings .Encoding ;
23
23
import org .jcodings .IntHolder ;
24
24
import org .truffleruby .Layouts ;
25
+ import org .truffleruby .RubyContext ;
25
26
import org .truffleruby .RubyLanguage ;
26
27
import org .truffleruby .builtins .CoreMethod ;
27
28
import org .truffleruby .builtins .CoreMethodArrayArgumentsNode ;
@@ -149,9 +150,9 @@ public class CExtNodes {
149
150
public static final int RUBY_TAG_THROW = 0x7 ;
150
151
public static final int RUBY_TAG_FATAL = 0x8 ;
151
152
152
- public static Pointer newNativeStringPointer (int capacity , RubyLanguage language ) {
153
+ public static Pointer newNativeStringPointer (RubyLanguage language , RubyContext context , int capacity ) {
153
154
// We need up to 4 \0 bytes for UTF-32. Always use 4 for speed rather than checking the encoding min length.
154
- Pointer pointer = Pointer .mallocAutoRelease (capacity + 4 , language );
155
+ Pointer pointer = Pointer .mallocAutoRelease (language , context , capacity + 4 );
155
156
pointer .writeInt (capacity , 0 );
156
157
return pointer ;
157
158
}
@@ -765,7 +766,7 @@ public abstract static class RbStrNewNulNode extends CoreMethodArrayArgumentsNod
765
766
@ Specialization
766
767
protected RubyString rbStrNewNul (int byteLength ,
767
768
@ Cached MutableTruffleString .FromNativePointerNode fromNativePointerNode ) {
768
- final Pointer pointer = Pointer .callocAutoRelease (byteLength + 1 , getLanguage () );
769
+ final Pointer pointer = Pointer .callocAutoRelease (getLanguage (), getContext (), byteLength + 1 );
769
770
var nativeTString = fromNativePointerNode .execute (pointer , 0 , byteLength , Encodings .BINARY .tencoding ,
770
771
false );
771
772
return createMutableString (nativeTString , Encodings .BINARY );
@@ -842,8 +843,8 @@ protected RubyString rbStrResize(RubyString string, int newByteLength,
842
843
string .clearCodeRange ();
843
844
return string ;
844
845
} else {
845
- var newNativeTString = TrStrCapaResizeNode .resize (pointer , newByteLength , newByteLength , tencoding ,
846
- fromNativePointerNode , getLanguage () );
846
+ var newNativeTString = TrStrCapaResizeNode .resize (getLanguage (), getContext (), pointer , newByteLength ,
847
+ newByteLength , tencoding , fromNativePointerNode );
847
848
string .setTString (newNativeTString );
848
849
849
850
// Like MRI's rb_str_resize()
@@ -869,18 +870,18 @@ protected RubyString trStrCapaResize(RubyString string, int newCapacity,
869
870
return string ;
870
871
} else {
871
872
int byteLength = string .tstring .byteLength (tencoding );
872
- var newNativeTString = resize (pointer , newCapacity , byteLength , tencoding , fromNativePointerNode ,
873
- getLanguage () );
873
+ var newNativeTString = resize (getLanguage (), getContext (), pointer , newCapacity , byteLength , tencoding ,
874
+ fromNativePointerNode );
874
875
string .setTString (newNativeTString );
875
876
876
877
return string ;
877
878
}
878
879
}
879
880
880
- static MutableTruffleString resize (Pointer pointer , int newCapacity , int newByteLength ,
881
- TruffleString . Encoding tencoding , MutableTruffleString . FromNativePointerNode fromNativePointerNode ,
882
- RubyLanguage language ) {
883
- final Pointer newPointer = newNativeStringPointer (newCapacity , language );
881
+ static MutableTruffleString resize (RubyLanguage language , RubyContext context , Pointer pointer , int newCapacity ,
882
+ int newByteLength , TruffleString . Encoding tencoding ,
883
+ MutableTruffleString . FromNativePointerNode fromNativePointerNode ) {
884
+ final Pointer newPointer = newNativeStringPointer (language , context , newCapacity );
884
885
newPointer .writeBytes (0 , pointer , 0 , Math .min (pointer .getSize (), newCapacity ));
885
886
886
887
return fromNativePointerNode .execute (newPointer , 0 , newByteLength , tencoding , false );
@@ -1285,8 +1286,8 @@ protected Pointer toNative(RubyString string,
1285
1286
pointer = (Pointer ) getInternalNativePointerNode .execute (tstring , tencoding );
1286
1287
} else {
1287
1288
int byteLength = tstring .byteLength (tencoding );
1288
- pointer = allocateAndCopyToNative (tstring , tencoding , byteLength , copyToNativeMemoryNode ,
1289
- getLanguage () );
1289
+ pointer = allocateAndCopyToNative (getLanguage (), getContext (), tstring , tencoding , byteLength ,
1290
+ copyToNativeMemoryNode );
1290
1291
1291
1292
var nativeTString = fromNativePointerNode .execute (pointer , 0 , byteLength , tencoding , false );
1292
1293
string .setTString (nativeTString );
@@ -1300,9 +1301,10 @@ protected Pointer toNativeImmutable(ImmutableRubyString string) {
1300
1301
return string .getNativeString (getLanguage ());
1301
1302
}
1302
1303
1303
- public static Pointer allocateAndCopyToNative (AbstractTruffleString tstring , TruffleString .Encoding tencoding ,
1304
- int capacity , TruffleString .CopyToNativeMemoryNode copyToNativeMemoryNode , RubyLanguage language ) {
1305
- final Pointer pointer = newNativeStringPointer (capacity , language );
1304
+ public static Pointer allocateAndCopyToNative (RubyLanguage language , RubyContext context ,
1305
+ AbstractTruffleString tstring , TruffleString .Encoding tencoding , int capacity ,
1306
+ TruffleString .CopyToNativeMemoryNode copyToNativeMemoryNode ) {
1307
+ final Pointer pointer = newNativeStringPointer (language , context , capacity );
1306
1308
copyToNativeMemoryNode .execute (tstring , 0 , pointer , 0 , capacity , tencoding );
1307
1309
return pointer ;
1308
1310
}
@@ -2026,7 +2028,7 @@ public abstract static class DataHolderCreate extends PrimitiveArrayArgumentsNod
2026
2028
2027
2029
@ Specialization
2028
2030
protected DataHolder create (Object address ) {
2029
- return new DataHolder (address , Pointer .NULL );
2031
+ return new DataHolder (address , Pointer .getNullPointer ( getContext ()) );
2030
2032
}
2031
2033
}
2032
2034
0 commit comments