Skip to content

Commit 3153a33

Browse files
committed
Run C extensions natively
* libtruffleruby.so is still run on Sulong to limit the changes needed. * libtrufflerubytrampoline.so is a new library which declares C API functions in native and forwards to Sulong. * st.c is copied to libtrufflerubytrampoline.so since it does not need to run on Sulong. * Define TRUFFLERUBY_ABI_VERSION in headers directly for simplicity and reliability, trampoline.c and st.c need it but have no easy way to get the value from Ruby. * Remove dependencies on polyglot.h in public extension headers, since that functionality is not available when not running on Sulong.
1 parent e5a12e1 commit 3153a33

File tree

120 files changed

+4107
-1174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+4107
-1174
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ lib/gems/gems/debug-*/ext/debug/debug_version.h
4747
src/main/c/*/Makefile
4848
!src/main/c/spawn-helper/Makefile
4949
!src/main/c/truffleposix/Makefile
50+
src/main/c/cext-trampoline/trampoline.c
5051
src/main/c/etc/constdefs.h
5152
src/main/c/spawn-helper/spawn-helper
5253

doc/contributor/how-to-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,15 +1292,15 @@ When you modify C-files (*.c, *.h) or compilation-related Ruby files
12921292
affect the ABI or increase the ABI *check* version explicitly by modifying one of
12931293
the files:
12941294
1295-
- lib/cext/ABI_version.txt
1295+
- lib/cext/include/truffleruby/truffleruby-abi-version.h
12961296
- lib/cext/ABI_check.txt
12971297
12981298
ABI change is:
12991299
- changing headers or compilation flags
13001300
- removing/adding a non-static function
13011301
- implementing already declared non-static functions
13021302
1303-
In case of doubt, bump `ABI_version.txt`.
1303+
In case of doubt, bump `truffleruby-abi-version.h`.
13041304
13051305
## How to choose where to add new specs - in TruffleRuby or in ruby/spec repository
13061306

doc/contributor/updating-ruby.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Also update the list of `provided_executables` in `mx_truffleruby.py` if some la
142142
Update all of these:
143143

144144
* Update `.ruby-version`, `TruffleRuby.LANGUAGE_VERSION`
145-
* Reset `lib/cext/ABI_version.txt` and `lib/cext/ABI_check.txt` to `1` if `RUBY_VERSION` was updated.
145+
* Reset `truffleruby-abi-version.h` to `$RUBY_VERSION.1` and `lib/cext/ABI_check.txt` to `1` if `RUBY_VERSION` was updated.
146146
* Update `versions.json` (with gem versions provided by `cat ../ruby/gems/bundled_gems | sort`, `ls -l lib/gems/specifications/default` and `grep 'VERSION =' lib/mri/rubygems.rb`)
147147
* Also update version numbers for `debug` and `rbs` in `src/main/c/Makefile` and in `mx.truffleruby/suite.py`.
148148
* Copy and paste `-h` and `--help` output to `RubyLauncher` (instructions are in the end of the file `src/launcher/java/org/truffleruby/launcher/RubyLauncher.java`)

lib/cext/ABI_version.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/cext/include/internal/bignum.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ static inline bool BIGNUM_POSITIVE_P(VALUE b);
136136
static inline bool BIGNUM_NEGATIVE_P(VALUE b);
137137
static inline void BIGNUM_SET_SIGN(VALUE b, bool sign);
138138
static inline void BIGNUM_NEGATE(VALUE b);
139+
#ifndef TRUFFLERUBY
139140
static inline size_t BIGNUM_LEN(VALUE b);
141+
#endif
140142
static inline BDIGIT *BIGNUM_DIGITS(VALUE b);
143+
#ifndef TRUFFLERUBY
141144
static inline int BIGNUM_LENINT(VALUE b);
145+
#endif
142146
static inline bool BIGNUM_EMBED_P(VALUE b);
143147

144148
RUBY_SYMBOL_EXPORT_BEGIN
@@ -205,6 +209,7 @@ BIGNUM_NEGATE(VALUE b)
205209
FL_REVERSE_RAW(b, BIGNUM_SIGN_BIT);
206210
}
207211

212+
#ifndef TRUFFLERUBY
208213
static inline size_t
209214
BIGNUM_LEN(VALUE b)
210215
{
@@ -224,6 +229,7 @@ BIGNUM_LENINT(VALUE b)
224229
{
225230
return rb_long2int(BIGNUM_LEN(b));
226231
}
232+
#endif
227233

228234
/* LSB:BIGNUM_DIGITS(b)[0], MSB:BIGNUM_DIGITS(b)[BIGNUM_LEN(b)-1] */
229235
static inline BDIGIT *

lib/cext/include/internal/compile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ st_index_t rb_iseq_cdhash_hash(VALUE a);
2525
/* iseq.c */
2626
int rb_vm_insn_addr2insn(const void *);
2727
int rb_vm_insn_decode(const VALUE encoded);
28+
29+
#ifdef TRUFFLERUBY
30+
#define ruby_vm_keep_script_lines false
31+
#else
2832
extern bool ruby_vm_keep_script_lines;
33+
#endif
2934

3035
MJIT_SYMBOL_EXPORT_BEGIN
3136
/* iseq.c (export) */

lib/cext/include/internal/imemo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ VALUE rb_imemo_new(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0)
160160
const char *rb_imemo_name(enum imemo_type type);
161161
RUBY_SYMBOL_EXPORT_END
162162

163+
#ifndef TRUFFLERUBY
163164
static inline enum imemo_type
164165
imemo_type(VALUE imemo)
165166
{
@@ -182,6 +183,7 @@ imemo_type_p(VALUE imemo, enum imemo_type imemo_type)
182183
}
183184

184185
#define IMEMO_TYPE_P(v, t) imemo_type_p((VALUE)v, t)
186+
#endif
185187

186188
static inline bool
187189
imemo_throw_data_p(VALUE imemo)

lib/cext/include/ruby/internal/arithmetic/long.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,7 @@ rb_ulong2num_inline(unsigned long v)
337337
if (RB_POSFIXABLE(v))
338338
return RB_LONG2FIX(v);
339339
else
340-
#ifdef TRUFFLERUBY
341-
return rb_tr_wrap(polyglot_invoke(RUBY_CEXT, "rb_ulong2num", (long) v));
342-
#else
343340
return rb_uint2big(v);
344-
#endif
345341
}
346342

347343
/**

lib/cext/include/ruby/internal/core/rarray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ VALUE rb_tr_rarray_aref(VALUE array, long index);
283283
#endif
284284
RBIMPL_SYMBOL_EXPORT_END()
285285

286+
#ifndef TRUFFLERUBY
286287
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
287288
RBIMPL_ATTR_ARTIFICIAL()
288289
/**
@@ -312,7 +313,6 @@ RARRAY_EMBED_LEN(VALUE ary)
312313
return RBIMPL_CAST((long)f);
313314
}
314315

315-
#ifndef TRUFFLERUBY
316316
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
317317
/**
318318
* Queries the length of the array.

lib/cext/include/ruby/internal/core/rbasic.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ RBasic {
8787
* @note This is ::VALUE rather than an enum for alignment purpose. Back
8888
* in the 1990s there were no such thing like `_Alignas` in C.
8989
*/
90+
#ifndef TRUFFLERUBY
91+
// TruffleRuby: we cannot support writing to these flags, so don't expose the field
9092
VALUE flags;
93+
#endif
9194

9295
/**
9396
* Class of an object. Every object has its class. Also, everything is an
@@ -98,11 +101,7 @@ RBasic {
98101
* Also note the `const` qualifier. In ruby an object cannot "change" its
99102
* class.
100103
*/
101-
#ifdef TRUFFLERUBY
102-
VALUE klass;
103-
#else
104104
const VALUE klass;
105-
#endif
106105

107106
#ifdef __cplusplus
108107
public:
@@ -117,17 +116,15 @@ RBasic {
117116
* ourselves.
118117
*/
119118
RBasic() :
119+
#ifndef TRUFFLERUBY
120120
flags(RBIMPL_VALUE_NULL),
121+
#endif
121122
klass(RBIMPL_VALUE_NULL)
122123
{
123124
}
124125
#endif
125126
};
126127

127-
#ifdef TRUFFLERUBY
128-
POLYGLOT_DECLARE_STRUCT(RBasic)
129-
#endif
130-
131128
RBIMPL_SYMBOL_EXPORT_BEGIN()
132129
/**
133130
* Make the object invisible from Ruby code.

0 commit comments

Comments
 (0)