Skip to content

Commit 5e87007

Browse files
committed
[GR-20670] Fix linking of always-inline C API functions with -std=gnu90 (#1837, #1879).
PullRequest: truffleruby/1271
2 parents bd6ad98 + 3bdc5d5 commit 5e87007

File tree

7 files changed

+77
-64
lines changed

7 files changed

+77
-64
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Bug fixes:
7474
* Fixed type conversion for `Numeric#step` `step` parameter.
7575
* Fixed `Kernel#Integer` conversion.
7676
* Fixed `IO.try_convert` parameter conversion.
77+
* Fixed linking of always-inline C API functions with `-std=gnu90` (#1837, #1879).
7778

7879
Compatibility:
7980

lib/cext/include/ruby/ruby.h

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,16 @@ enum ruby_special_consts {
477477
#endif
478478
#define SYMBOL_FLAG RUBY_SYMBOL_FLAG
479479

480+
#ifdef TRUFFLERUBY
481+
#define RB_NIL_P(value) ((int) polyglot_as_boolean(polyglot_invoke(RUBY_CEXT, "RB_NIL_P", value)))
480482
int RTEST(VALUE value);
481483
#define NIL_P(v) RB_NIL_P(v)
484+
#else
485+
#define RB_TEST(v) !(((VALUE)(v) & (VALUE)~RUBY_Qnil) == 0)
486+
#define RB_NIL_P(v) !((VALUE)(v) != RUBY_Qnil)
487+
#define RTEST(v) RB_TEST(v)
488+
#define NIL_P(v) RB_NIL_P(v)
489+
#endif
482490

483491
#define CLASS_OF(v) rb_class_of((VALUE)(v))
484492

@@ -550,19 +558,23 @@ enum ruby_value_type {
550558
int rb_type(VALUE value);
551559
#define TYPE(x) rb_type((VALUE)(x))
552560

553-
/* Truffle: Simplify the RB_FLOAT_TYPE_P check based on our representation of Floats.
561+
#ifdef TRUFFLERUBY
562+
/* TruffleRuby: Simplify the RB_FLOAT_TYPE_P check based on our representation of Floats. */
563+
#define RB_FLOAT_TYPE_P(obj) (\
564+
polyglot_as_boolean(polyglot_invoke(RUBY_CEXT, "RB_FLOAT_TYPE_P", rb_tr_unwrap(value))))
565+
#else
554566
#define RB_FLOAT_TYPE_P(obj) (\
555567
RB_FLONUM_P(obj) || \
556568
(!RB_SPECIAL_CONST_P(obj) && RB_BUILTIN_TYPE(obj) == RUBY_T_FLOAT))
557-
*/
558-
MUST_INLINE int RB_FLOAT_TYPE_P(VALUE obj);
569+
#endif
559570

560571
bool RB_TYPE_P(VALUE value, int type);
561572

562573
#ifdef __GNUC__
563574
#define RB_GC_GUARD(v) \
564575
(*__extension__ ({ \
565-
volatile VALUE *rb_gc_guarded_ptr = rb_tr_gc_guard(&v); \
576+
polyglot_invoke(RUBY_CEXT, "rb_tr_gc_guard", v); \
577+
volatile VALUE *rb_gc_guarded_ptr = &v; \
566578
rb_gc_guarded_ptr; \
567579
}))
568580
#elif defined _MSC_VER
@@ -586,13 +598,25 @@ void rb_check_type(VALUE,int);
586598
#define Check_Type(v,t) rb_check_type((VALUE)(v),(t))
587599

588600
VALUE rb_str_to_str(VALUE);
589-
MUST_INLINE VALUE rb_string_value(VALUE *value_pointer);
590-
MUST_INLINE char *rb_string_value_ptr(VALUE *value_pointer);
591-
MUST_INLINE char *rb_string_value_cstr(VALUE *value_pointer);
601+
#ifdef TRUFFLERUBY
602+
VALUE rb_string_value(VALUE *value_pointer);
603+
char *rb_string_value_ptr(VALUE *value_pointer);
604+
char *rb_string_value_cstr(VALUE *value_pointer);
605+
#else
606+
VALUE rb_string_value(volatile VALUE*);
607+
char *rb_string_value_ptr(volatile VALUE*);
608+
char *rb_string_value_cstr(volatile VALUE*);
609+
#endif
592610

611+
#ifdef TRUFFLERUBY
612+
#define StringValue(v) rb_tr_string_value(&(v))
613+
#define StringValuePtr(v) rb_tr_string_value_ptr(&(v))
614+
#define StringValueCStr(v) rb_tr_string_value_cstr(&(v))
615+
#else
593616
#define StringValue(v) rb_string_value(&(v))
594617
#define StringValuePtr(v) rb_string_value_ptr(&(v))
595618
#define StringValueCStr(v) rb_string_value_cstr(&(v))
619+
#endif
596620

597621
void rb_check_safe_obj(VALUE);
598622
#define SafeStringValue(v) do {\
@@ -1147,7 +1171,11 @@ struct rb_data_type_struct {
11471171
struct RTypedData {
11481172
struct RBasic basic;
11491173
const rb_data_type_t *type;
1174+
#ifdef TRUFFLERUBY
1175+
int typed_flag; /* 1 or not */
1176+
#else
11501177
VALUE typed_flag; /* 1 or not */
1178+
#endif
11511179
void *data;
11521180
};
11531181

lib/cext/include/ruby/thread_native.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ RUBY_SYMBOL_EXPORT_BEGIN
4747

4848
rb_nativethread_id_t rb_nativethread_self();
4949

50-
MUST_INLINE int rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock);
51-
MUST_INLINE int rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock);
52-
MUST_INLINE int rb_nativethread_lock_lock(rb_nativethread_lock_t *lock);
53-
MUST_INLINE int rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock);
50+
void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock);
51+
void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock);
52+
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock);
53+
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock);
5454

5555
RUBY_SYMBOL_EXPORT_END
5656

lib/cext/include/truffleruby/truffleruby-pre.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,12 @@ typedef VALUE ID;
4444
extern void* rb_tr_cext;
4545
#define RUBY_CEXT rb_tr_cext
4646

47-
#define MUST_INLINE __attribute__((always_inline)) inline
48-
4947
// Wrapping and unwrapping of values.
5048

5149
extern void* (*rb_tr_unwrap)(VALUE obj);
5250
extern VALUE (*rb_tr_wrap)(void *obj);
5351
extern VALUE (*rb_tr_longwrap)(long obj);
5452

55-
// Needed for GC guarding
56-
57-
MUST_INLINE VALUE *rb_tr_gc_guard(VALUE *ptr) {
58-
polyglot_invoke(RUBY_CEXT, "rb_tr_gc_guard", *ptr);
59-
return ptr;
60-
}
61-
62-
#define RB_NIL_P(value) ((int)polyglot_as_boolean(polyglot_invoke(rb_tr_cext, "RB_NIL_P", value)))
6353

6454
#include <ruby/thread_native.h>
6555

lib/cext/include/truffleruby/truffleruby.h

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ if (polyglot_as_boolean(polyglot_invoke(RUBY_CEXT, "warning?"))) { \
9090
} \
9191
} while (0);
9292

93-
MUST_INLINE int rb_tr_scan_args(int argc, VALUE *argv, const char *format, VALUE *v1, VALUE *v2, VALUE *v3, VALUE *v4, VALUE *v5, VALUE *v6, VALUE *v7, VALUE *v8, VALUE *v9, VALUE *v10);
94-
9593
#define rb_tr_scan_args_1(ARGC, ARGV, FORMAT, V1) rb_tr_scan_args(ARGC, ARGV, FORMAT, V1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
9694
#define rb_tr_scan_args_2(ARGC, ARGV, FORMAT, V1, V2) rb_tr_scan_args(ARGC, ARGV, FORMAT, V1, V2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
9795
#define rb_tr_scan_args_3(ARGC, ARGV, FORMAT, V1, V2, V3) rb_tr_scan_args(ARGC, ARGV, FORMAT, V1, V2, V3, NULL, NULL, NULL, NULL, NULL, NULL, NULL)
@@ -164,51 +162,31 @@ VALUE rb_ivar_lookup(VALUE object, const char *name, VALUE default_value);
164162

165163
// Inline implementations
166164

167-
MUST_INLINE int rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock) {
168-
*lock = RUBY_CEXT_INVOKE("rb_nativethread_lock_initialize");
169-
return 0;
170-
}
171-
172-
MUST_INLINE int rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock) {
173-
*lock = RUBY_CEXT_INVOKE("rb_nativethread_lock_destroy", *lock);
174-
return 0;
175-
}
176-
177-
MUST_INLINE int rb_nativethread_lock_lock(rb_nativethread_lock_t *lock) {
178-
RUBY_INVOKE_NO_WRAP(*lock, "lock");
179-
return 0;
180-
}
181-
182-
MUST_INLINE int rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock) {
183-
RUBY_INVOKE_NO_WRAP(*lock, "unlock");
184-
return 0;
185-
}
186-
187-
MUST_INLINE VALUE rb_string_value(VALUE *value_pointer) {
165+
ALWAYS_INLINE(static VALUE rb_tr_string_value(VALUE *value_pointer));
166+
static inline VALUE rb_tr_string_value(VALUE *value_pointer) {
188167
VALUE value = *value_pointer;
189-
190168
if (!RB_TYPE_P(value, T_STRING)) {
191169
value = rb_str_to_str(value);
192170
*value_pointer = value;
193171
}
194-
195172
return value;
196173
}
197174

198-
MUST_INLINE char *rb_string_value_ptr(VALUE *value_pointer) {
175+
ALWAYS_INLINE(static char *rb_tr_string_value_ptr(VALUE *value_pointer));
176+
static inline char *rb_tr_string_value_ptr(VALUE *value_pointer) {
199177
VALUE string = rb_string_value(value_pointer);
200178
return RSTRING_PTR(string);
201179
}
202180

203-
MUST_INLINE char *rb_string_value_cstr(VALUE *value_pointer) {
181+
ALWAYS_INLINE(static char *rb_tr_string_value_cstr(VALUE *value_pointer));
182+
static inline char *rb_tr_string_value_cstr(VALUE *value_pointer) {
204183
VALUE string = rb_string_value(value_pointer);
205-
206184
RUBY_CEXT_INVOKE("rb_string_value_cstr_check", string);
207-
208185
return RSTRING_PTR(string);
209186
}
210187

211-
MUST_INLINE int rb_tr_scan_args(int argc, VALUE *argv, const char *format, VALUE *v1, VALUE *v2, VALUE *v3, VALUE *v4, VALUE *v5, VALUE *v6, VALUE *v7, VALUE *v8, VALUE *v9, VALUE *v10) {
188+
ALWAYS_INLINE(static int rb_tr_scan_args(int argc, VALUE *argv, const char *format, VALUE *v1, VALUE *v2, VALUE *v3, VALUE *v4, VALUE *v5, VALUE *v6, VALUE *v7, VALUE *v8, VALUE *v9, VALUE *v10));
189+
static inline int rb_tr_scan_args(int argc, VALUE *argv, const char *format, VALUE *v1, VALUE *v2, VALUE *v3, VALUE *v4, VALUE *v5, VALUE *v6, VALUE *v7, VALUE *v8, VALUE *v9, VALUE *v10) {
212190
// Parse the format string
213191

214192
// TODO CS 7-Feb-17 maybe we could inline cache this part?

src/main/c/cext/ruby.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,6 @@ int RB_FIXNUM_P(VALUE value) {
419419
return polyglot_as_boolean(RUBY_CEXT_INVOKE_NO_WRAP("RB_FIXNUM_P", value));
420420
}
421421

422-
int RB_FLOAT_TYPE_P(VALUE value) {
423-
return polyglot_as_boolean(RUBY_CEXT_INVOKE_NO_WRAP("RB_FLOAT_TYPE_P", value));
424-
}
425-
426422
int RTEST(VALUE value) {
427423
return value != NULL && polyglot_as_boolean(RUBY_CEXT_INVOKE_NO_WRAP("RTEST", value));
428424
}
@@ -803,6 +799,18 @@ double rb_float_value(VALUE value) {
803799

804800
// String
805801

802+
VALUE rb_string_value(VALUE *value_pointer) {
803+
return rb_tr_string_value(value_pointer);
804+
}
805+
806+
char *rb_string_value_ptr(VALUE *value_pointer) {
807+
return rb_tr_string_value_ptr(value_pointer);
808+
}
809+
810+
char *rb_string_value_cstr(VALUE *value_pointer) {
811+
return rb_tr_string_value_cstr(value_pointer);
812+
}
813+
806814
char *RSTRING_PTR_IMPL(VALUE string) {
807815
return (char *)polyglot_as_i8_array(RUBY_CEXT_INVOKE_NO_WRAP("RSTRING_PTR", string));
808816
}
@@ -2637,6 +2645,22 @@ rb_nativethread_id_t rb_nativethread_self() {
26372645
return RUBY_CEXT_INVOKE("rb_nativethread_self");
26382646
}
26392647

2648+
void rb_nativethread_lock_initialize(rb_nativethread_lock_t *lock) {
2649+
*lock = RUBY_CEXT_INVOKE("rb_nativethread_lock_initialize");
2650+
}
2651+
2652+
void rb_nativethread_lock_destroy(rb_nativethread_lock_t *lock) {
2653+
*lock = RUBY_CEXT_INVOKE("rb_nativethread_lock_destroy", *lock);
2654+
}
2655+
2656+
void rb_nativethread_lock_lock(rb_nativethread_lock_t *lock) {
2657+
RUBY_INVOKE_NO_WRAP(*lock, "lock");
2658+
}
2659+
2660+
void rb_nativethread_lock_unlock(rb_nativethread_lock_t *lock) {
2661+
RUBY_INVOKE_NO_WRAP(*lock, "unlock");
2662+
}
2663+
26402664
// IO
26412665

26422666
void rb_io_check_writable(rb_io_t *io) {
@@ -2794,7 +2818,6 @@ int rb_tr_writable(int mode) {
27942818
return polyglot_as_boolean(polyglot_invoke(RUBY_CEXT, "rb_tr_writable", mode));
27952819
}
27962820

2797-
MUST_INLINE
27982821
int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p) {
27992822
// TODO (pitr-ch 12-Jun-2017): review, just approximate implementation
28002823
VALUE encoding = rb_cEncoding;

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,6 @@ public abstract static class AddToMarkList extends CoreMethodArrayArgumentsNode
14261426

14271427
@Specialization
14281428
protected DynamicObject addToMarkList(Object markedObject,
1429-
@Cached BranchProfile exceptionProfile,
14301429
@Cached BranchProfile noExceptionProfile,
14311430
@Cached UnwrapNode.ToWrapperNode toWrapperNode) {
14321431
ValueWrapper wrappedValue = toWrapperNode.execute(markedObject);
@@ -1440,16 +1439,13 @@ protected DynamicObject addToMarkList(Object markedObject,
14401439
return nil();
14411440
}
14421441

1443-
protected UnwrapNode createUnwrapNode() {
1444-
return UnwrapNodeGen.create();
1445-
}
14461442
}
14471443

14481444
@CoreMethod(names = "rb_tr_gc_guard", onSingleton = true, required = 1)
14491445
public abstract static class GCGuardNode extends CoreMethodArrayArgumentsNode {
14501446

14511447
@Specialization
1452-
protected DynamicObject addToMarkList(VirtualFrame frame, Object guardedObject,
1448+
protected DynamicObject addToMarkList(Object guardedObject,
14531449
@Cached MarkingServiceNodes.KeepAliveNode keepAliveNode,
14541450
@Cached BranchProfile noExceptionProfile,
14551451
@Cached UnwrapNode.ToWrapperNode toWrapperNode) {
@@ -1461,9 +1457,6 @@ protected DynamicObject addToMarkList(VirtualFrame frame, Object guardedObject,
14611457
return nil();
14621458
}
14631459

1464-
protected UnwrapNode createUnwrapNode() {
1465-
return UnwrapNodeGen.create();
1466-
}
14671460
}
14681461

14691462
@CoreMethod(names = "set_mark_list_on_object", onSingleton = true, required = 1)

0 commit comments

Comments
 (0)