89
89
# endif
90
90
#endif
91
91
92
- #define LONG_LONG long long
92
+ #if SIZEOF_LONG_LONG > 0
93
+ # define LONG_LONG long long
94
+ #endif
95
+
96
+ #if SIZEOF_LONG == SIZEOF_VOIDP
97
+ # define SIGNED_VALUE long
98
+ # define SIZEOF_VALUE SIZEOF_LONG
99
+ # define PRI_VALUE_PREFIX "l"
100
+ #elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
101
+ # define SIGNED_VALUE LONG_LONG
102
+ # define LONG_LONG_VALUE 1
103
+ # define SIZEOF_VALUE SIZEOF_LONG_LONG
104
+ # define PRI_VALUE_PREFIX "ll"
105
+ #else
106
+ # error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
107
+ #endif
108
+
109
+ #ifndef PRI_INT_PREFIX
110
+ #define PRI_INT_PREFIX ""
111
+ #endif
112
+ #ifndef PRI_LONG_PREFIX
113
+ #define PRI_LONG_PREFIX "l"
114
+ #endif
115
+
116
+ #if SIZEOF_LONG == 8
117
+ #define PRI_64_PREFIX PRI_LONG_PREFIX
118
+ #elif SIZEOF_LONG_LONG == 8
119
+ #define PRI_64_PREFIX PRI_LL_PREFIX
120
+ #endif
121
+
122
+ #define RUBY_PRI_VALUE_MARK "\v"
123
+ #if defined PRIdPTR && !defined PRI_VALUE_PREFIX
124
+ #define PRIdVALUE PRIdPTR
125
+ #define PRIoVALUE PRIoPTR
126
+ #define PRIuVALUE PRIuPTR
127
+ #define PRIxVALUE PRIxPTR
128
+ #define PRIXVALUE PRIXPTR
129
+ #define PRIsVALUE PRIiPTR"" RUBY_PRI_VALUE_MARK
130
+ #else
131
+ #define PRIdVALUE PRI_VALUE_PREFIX"d"
132
+ #define PRIoVALUE PRI_VALUE_PREFIX"o"
133
+ #define PRIuVALUE PRI_VALUE_PREFIX"u"
134
+ #define PRIxVALUE PRI_VALUE_PREFIX"x"
135
+ #define PRIXVALUE PRI_VALUE_PREFIX"X"
136
+ #define PRIsVALUE PRI_VALUE_PREFIX"i" RUBY_PRI_VALUE_MARK
137
+ #endif
138
+ #ifndef PRI_VALUE_PREFIX
139
+ # define PRI_VALUE_PREFIX ""
140
+ #endif
141
+
142
+ #ifndef PRI_TIMET_PREFIX
143
+ # if SIZEOF_TIME_T == SIZEOF_INT
144
+ # define PRI_TIMET_PREFIX
145
+ # elif SIZEOF_TIME_T == SIZEOF_LONG
146
+ # define PRI_TIMET_PREFIX "l"
147
+ # elif SIZEOF_TIME_T == SIZEOF_LONG_LONG
148
+ # define PRI_TIMET_PREFIX PRI_LL_PREFIX
149
+ # endif
150
+ #endif
151
+
152
+ #if defined PRI_PTRDIFF_PREFIX
153
+ #elif SIZEOF_PTRDIFF_T == SIZEOF_INT
154
+ # define PRI_PTRDIFF_PREFIX ""
155
+ #elif SIZEOF_PTRDIFF_T == SIZEOF_LONG
156
+ # define PRI_PTRDIFF_PREFIX "l"
157
+ #elif SIZEOF_PTRDIFF_T == SIZEOF_LONG_LONG
158
+ # define PRI_PTRDIFF_PREFIX PRI_LL_PREFIX
159
+ #endif
160
+ #define PRIdPTRDIFF PRI_PTRDIFF_PREFIX"d"
161
+ #define PRIiPTRDIFF PRI_PTRDIFF_PREFIX"i"
162
+ #define PRIoPTRDIFF PRI_PTRDIFF_PREFIX"o"
163
+ #define PRIuPTRDIFF PRI_PTRDIFF_PREFIX"u"
164
+ #define PRIxPTRDIFF PRI_PTRDIFF_PREFIX"x"
165
+ #define PRIXPTRDIFF PRI_PTRDIFF_PREFIX"X"
166
+
167
+ #if defined PRI_SIZE_PREFIX
168
+ #elif SIZEOF_SIZE_T == SIZEOF_INT
169
+ # define PRI_SIZE_PREFIX ""
170
+ #elif SIZEOF_SIZE_T == SIZEOF_LONG
171
+ # define PRI_SIZE_PREFIX "l"
172
+ #elif SIZEOF_SIZE_T == SIZEOF_LONG_LONG
173
+ # define PRI_SIZE_PREFIX PRI_LL_PREFIX
174
+ #endif
175
+ #define PRIdSIZE PRI_SIZE_PREFIX"d"
176
+ #define PRIiSIZE PRI_SIZE_PREFIX"i"
177
+ #define PRIoSIZE PRI_SIZE_PREFIX"o"
178
+ #define PRIuSIZE PRI_SIZE_PREFIX"u"
179
+ #define PRIxSIZE PRI_SIZE_PREFIX"x"
180
+ #define PRIXSIZE PRI_SIZE_PREFIX"X"
181
+
182
+ #ifdef __GNUC__
183
+ #define RB_UNUSED_VAR (x ) x __attribute__ ((unused))
184
+ #else
185
+ #define RB_UNUSED_VAR (x ) x
186
+ #endif
93
187
94
188
#ifndef RUBY_EXTERN
95
189
#define RUBY_EXTERN extern
@@ -219,6 +313,9 @@ struct RString {
219
313
#define RSTRING (str ) capi_rstring_struct(str, RSTRING_CACHE_UNSAFE)
220
314
#endif
221
315
316
+ #define RSTRING_GETMEM (rb_str , c_str , c_str_len ) \
317
+ ((c_str) = RSTRING_PTR(rb_str), (c_str_len) = RSTRING_LEN(rb_str))
318
+
222
319
struct RArray {
223
320
ssize_t len ;
224
321
struct {
@@ -238,6 +335,7 @@ struct RData {
238
335
};
239
336
240
337
#define RDATA (d ) capi_rdata_struct(d)
338
+ #define RTYPEDDATA (d ) capi_rtypeddata_struct(d)
241
339
242
340
struct RFloat {
243
341
double value ;
@@ -250,6 +348,8 @@ struct RFloat {
250
348
#define RHASH (obj ) ({ C_API_RHASH_is_not_supported_in_Rubinius })
251
349
#define RHASH_TBL (obj ) ({ C_API_RHASH_TBL_is_not_supported_in_Rubinius })
252
350
351
+ #define RHASH_SET_IFNONE (hash , def ) rb_hash_set_ifnone(hash, def)
352
+
253
353
typedef struct rb_io_t {
254
354
VALUE handle ;
255
355
int fd ;
@@ -381,9 +481,19 @@ struct RFile {
381
481
/** Reallocate memory allocated with ALLOC or ALLOC_N. */
382
482
#define REALLOC_N (ptr , type , n ) (ptr)=(type*)realloc(ptr, sizeof(type) * (n));
383
483
484
+ #define ZALLOC_N (type ,n ) ((type*)xcalloc((n),sizeof(type)))
485
+ #define ZALLOC (type ) (ZALLOC_N(type,1))
486
+
487
+ #define ALLOCV (v , n ) rb_alloc_tmp_buffer(&(v), (n))
488
+ #define ALLOCV_N (type , v , n ) ((type*)ALLOCV((v), sizeof(type)*(n)))
489
+ #define ALLOCV_END (v ) rb_free_tmp_buffer(&(v))
490
+
384
491
/** Interrupt checking (no-op). */
385
492
#define CHECK_INTS /* No-op */
386
493
494
+ #define RB_BLOCK_CALL_FUNC_ARGLIST (yielded_arg , callback_arg ) \
495
+ VALUE yielded_arg, VALUE callback_arg, int argc, const VALUE *argv, VALUE blockarg
496
+
387
497
/** Rubinius doesn't need gc guards */
388
498
#define RB_GC_GUARD /* No-op */
389
499
@@ -482,6 +592,7 @@ VALUE rb_uint2big(unsigned long number);
482
592
483
593
/** The length of string str. */
484
594
#define RSTRING_LEN (str ) rb_str_len(str)
595
+ #define RSTRING_LENINT (str ) rb_str_len(str)
485
596
486
597
/** The pointer to the string str's data. */
487
598
#ifdef RUBY_READONLY_STRING
@@ -513,11 +624,15 @@ VALUE rb_uint2big(unsigned long number);
513
624
514
625
#define Check_SafeStr (x )
515
626
627
+ #define FilePathValue (v ) rb_file_path_value(&(v))
628
+
516
629
/** Retrieve the ID given a Symbol handle. */
517
630
#define SYM2ID (sym ) (sym)
518
631
519
632
/** Return an integer type id for the object. @see rb_type() */
520
633
#define TYPE (handle ) rb_type(handle)
634
+ #define rb_type_p (obj , type ) (rb_type(obj) == (type))
635
+ #define RB_TYPE_P (obj , type ) rb_type_p(obj, type)
521
636
522
637
/** Alias to rb_type. This is not exactly the same as in MRI, but it makes sure
523
638
+ * that it won't segfault if you give BUILTIN_TYPE an immediate such as a Fixnum
@@ -592,6 +707,7 @@ VALUE rb_uint2big(unsigned long number);
592
707
593
708
struct RArray * capi_rarray_struct (VALUE array );
594
709
struct RData * capi_rdata_struct (VALUE data );
710
+ struct RTypedData * capi_rtypeddata_struct (VALUE data );
595
711
struct RString * capi_rstring_struct (VALUE string , int cache_level );
596
712
struct RFloat * capi_rfloat_struct (VALUE data );
597
713
struct RIO * capi_rio_struct (VALUE handle );
@@ -625,19 +741,78 @@ VALUE rb_uint2big(unsigned long number);
625
741
VALUE rb_equal (VALUE a , VALUE b );
626
742
VALUE rb_class_inherited_p (VALUE mod , VALUE arg );
627
743
628
- #define Data_Make_Struct (klass , type , mark , free , sval ) (\
629
- sval = ALLOC(type), \
630
- memset(sval, 0, sizeof(type)), \
631
- Data_Wrap_Struct(klass, mark, free, sval)\
632
- )
744
+ typedef struct rb_data_type_struct rb_data_type_t ;
745
+
746
+ struct rb_data_type_struct {
747
+ const char * wrap_struct_name ;
748
+ struct {
749
+ void (* dmark )(void * );
750
+ void (* dfree )(void * );
751
+ size_t (* dsize )(const void * );
752
+ void * reserved [2 ]; /* For future extension.
753
+ This array *must* be filled with ZERO. */
754
+ } function ;
755
+ const rb_data_type_t * parent ;
756
+ void * data ; /* This area can be used for any purpose
757
+ by a programmer who define the type. */
758
+ VALUE flags ; /* FL_WB_PROTECTED */
759
+ };
760
+
761
+ #define HAVE_TYPE_RB_DATA_TYPE_T 1
762
+ #define HAVE_RB_DATA_TYPE_T_FUNCTION 1
763
+ #define HAVE_RB_DATA_TYPE_T_PARENT 1
764
+
765
+ struct RTypedData {
766
+ const rb_data_type_t * type ;
767
+ VALUE typed_flag ; /* 1 or not */
768
+ void * data ;
769
+ };
633
770
634
- #define Data_Wrap_Struct (klass , mark , free , sval ) \
635
- rb_data_object_alloc(klass, (void*)sval, (RUBY_DATA_FUNC)mark, \
636
- (RUBY_DATA_FUNC)free)
771
+ #define RTYPEDDATA_P (v ) (RTYPEDDATA(v)->typed_flag == 1)
772
+ #define RTYPEDDATA_TYPE (v ) (RTYPEDDATA(v)->type)
773
+ #define RTYPEDDATA_DATA (v ) (RTYPEDDATA(v)->data)
774
+
775
+ VALUE rb_data_object_alloc (VALUE ,void * ,RUBY_DATA_FUNC ,RUBY_DATA_FUNC );
776
+ VALUE rb_data_typed_object_alloc (VALUE klass , void * datap , const rb_data_type_t * );
777
+ int rb_typeddata_inherited_p (const rb_data_type_t * child , const rb_data_type_t * parent );
778
+ int rb_typeddata_is_kind_of (VALUE , const rb_data_type_t * );
779
+ void * rb_check_typeddata (VALUE , const rb_data_type_t * );
780
+
781
+ #define Check_TypedStruct (v ,t ) rb_check_typeddata((VALUE)(v),(t))
782
+ #define RUBY_DEFAULT_FREE ((RUBY_DATA_FUNC)-1)
783
+ #define RUBY_NEVER_FREE ((RUBY_DATA_FUNC)0)
784
+ #define RUBY_TYPED_DEFAULT_FREE RUBY_DEFAULT_FREE
785
+ #define RUBY_TYPED_NEVER_FREE RUBY_NEVER_FREE
786
+
787
+ /* bits for rb_data_type_struct::flags */
788
+ #define RUBY_TYPED_FREE_IMMEDIATELY 0xcafebeef
789
+ #define RUBY_TYPED_WB_PROTECTED 0xbeefcafe
790
+
791
+ #define Data_Wrap_Struct (klass ,mark ,free ,sval )\
792
+ rb_data_object_alloc((klass),(sval),(RUBY_DATA_FUNC)(mark),(RUBY_DATA_FUNC)(free))
793
+
794
+ #define Data_Make_Struct (klass ,type ,mark ,free ,sval ) (\
795
+ (sval) = ALLOC(type),\
796
+ memset((sval), 0, sizeof(type)),\
797
+ Data_Wrap_Struct((klass),(mark),(free),(sval))\
798
+ )
799
+
800
+ #define TypedData_Wrap_Struct (klass ,data_type ,sval )\
801
+ rb_data_typed_object_alloc((klass),(sval),(data_type))
802
+
803
+ #define TypedData_Make_Struct (klass , type , data_type , sval ) (\
804
+ (sval) = ALLOC(type),\
805
+ memset((sval), 0, sizeof(type)),\
806
+ TypedData_Wrap_Struct((klass),(data_type),(sval))\
807
+ )
808
+
809
+ #define Data_Get_Struct (obj ,type ,sval ) do {\
810
+ Check_Type((obj), T_DATA); \
811
+ (sval) = (type*)DATA_PTR(obj);\
812
+ } while (0)
637
813
638
- #define Data_Get_Struct (obj ,type ,sval ) do {\
639
- Check_Type(obj, T_DATA); \
640
- sval = (type*)DATA_PTR(obj);\
814
+ #define TypedData_Get_Struct (obj ,type ,data_type ,sval ) do {\
815
+ (sval) = (type*)rb_check_typeddata((obj), (data_type)); \
641
816
} while (0)
642
817
643
818
/** Return Qtrue if obj is an immediate, Qfalse or Qnil. */
@@ -859,6 +1034,7 @@ VALUE rb_uint2big(unsigned long number);
859
1034
860
1035
/** Returns String representation of the class' name. */
861
1036
VALUE rb_class_name (VALUE klass );
1037
+ #define rb_class_path (k ) rb_class_name(k)
862
1038
863
1039
/** Calls the class method 'inherited' on super passing the class.
864
1040
* If super is NULL, calls Object.inherited. */
@@ -874,6 +1050,9 @@ VALUE rb_uint2big(unsigned long number);
874
1050
/** Returns the Class object this object is an instance of. */
875
1051
VALUE rb_class_of (VALUE object );
876
1052
1053
+ /** Returns the superclass of a class. */
1054
+ VALUE rb_class_superclass (VALUE klass );
1055
+
877
1056
/** Returns the first superclass of an object that isn't a singleton or
878
1057
* intermediate.
879
1058
*/
@@ -1061,6 +1240,9 @@ VALUE rb_uint2big(unsigned long number);
1061
1240
1062
1241
VALUE rb_vsprintf (const char * format , va_list varargs );
1063
1242
1243
+ /** Returns a duplicate file discriptor with close-on-exec flag set. */
1244
+ int rb_cloexec_dup (int fd );
1245
+
1064
1246
/** Returns a File opened with the specified mode. */
1065
1247
VALUE rb_file_open (const char * name , const char * mode );
1066
1248
@@ -1115,6 +1297,8 @@ VALUE rb_uint2big(unsigned long number);
1115
1297
/** Return the value associated with the key, excluding default values. */
1116
1298
VALUE rb_hash_lookup (VALUE self , VALUE key );
1117
1299
1300
+ VALUE rb_hash_lookup2 (VALUE hash , VALUE key , VALUE def );
1301
+
1118
1302
/** Set the value associated with the key. */
1119
1303
VALUE rb_hash_aset (VALUE self , VALUE key , VALUE value );
1120
1304
@@ -1136,6 +1320,8 @@ VALUE rb_uint2big(unsigned long number);
1136
1320
int (* func )(ANYARGS ),
1137
1321
VALUE farg );
1138
1322
1323
+ VALUE rb_hash_set_ifnone (VALUE hash , VALUE def );
1324
+
1139
1325
void rb_eof_error ();
1140
1326
1141
1327
VALUE rb_io_addstr (VALUE , VALUE );
@@ -1233,6 +1419,8 @@ VALUE rb_uint2big(unsigned long number);
1233
1419
ID rb_intern (const char * string );
1234
1420
ID rb_intern2 (const char * string , long len );
1235
1421
1422
+ VALUE rb_sym2str (VALUE sym );
1423
+
1236
1424
/** Coerce x and y and perform 'x func y' */
1237
1425
VALUE rb_num_coerce_bin (VALUE x , VALUE y , ID func );
1238
1426
@@ -1572,6 +1760,9 @@ VALUE rb_uint2big(unsigned long number);
1572
1760
* to check that length is greater than 0 properly */
1573
1761
VALUE rb_str_new (const char * string , long length );
1574
1762
1763
+ /** Create a String from a C string. Alias of rb_str_new2. */
1764
+ VALUE rb_str_new_cstr (const char * string );
1765
+
1575
1766
/** Create a String from a C string. */
1576
1767
VALUE rb_str_new2 (const char * string );
1577
1768
@@ -1760,6 +1951,8 @@ VALUE rb_uint2big(unsigned long number);
1760
1951
1761
1952
NORETURN (void rb_notimplement ());
1762
1953
1954
+ NORETURN (VALUE rb_f_notimplement (int argc , VALUE * argv , VALUE obj ));
1955
+
1763
1956
/** Raises an ArgumentError exception. */
1764
1957
NORETURN (void rb_invalid_str (const char * str , const char * type ));
1765
1958
0 commit comments