summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/ext/string_spec.c
blob: 270412673eab6dfe712e41e895f588302069ed83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
#include "ruby.h"
#include "rubyspec.h"

#include <string.h>
#include <stdarg.h>

#include "ruby/encoding.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Make sure the RSTRING_PTR and the bytes are in native memory.
 * On TruffleRuby RSTRING_PTR and the bytes remain in managed memory
 * until they must be written to native memory.
 * In some specs we want to test using the native memory. */
#ifndef NATIVE_RSTRING_PTR
#define NATIVE_RSTRING_PTR(str) RSTRING_PTR(str)
#endif

VALUE string_spec_rb_cstr2inum(VALUE self, VALUE str, VALUE inum) {
  int num = FIX2INT(inum);
  return rb_cstr2inum(RSTRING_PTR(str), num);
}

static VALUE string_spec_rb_cstr_to_inum(VALUE self, VALUE str, VALUE inum, VALUE badcheck) {
  int num = FIX2INT(inum);
  return rb_cstr_to_inum(RSTRING_PTR(str), num, RTEST(badcheck));
}

VALUE string_spec_rb_str2inum(VALUE self, VALUE str, VALUE inum) {
  int num = FIX2INT(inum);
  return rb_str2inum(str, num);
}

VALUE string_spec_rb_str_append(VALUE self, VALUE str, VALUE str2) {
  return rb_str_append(str, str2);
}

VALUE string_spec_rb_str_set_len(VALUE self, VALUE str, VALUE len) {
  rb_str_set_len(str, NUM2LONG(len));

  return str;
}

VALUE string_spec_rb_str_set_len_RSTRING_LEN(VALUE self, VALUE str, VALUE len) {
  rb_str_set_len(str, NUM2LONG(len));

  return INT2FIX(RSTRING_LEN(str));
}

VALUE string_spec_rb_str_buf_new(VALUE self, VALUE len, VALUE str) {
  VALUE buf;

  buf = rb_str_buf_new(NUM2LONG(len));

  if(RTEST(str)) {
    snprintf(RSTRING_PTR(buf), NUM2LONG(len), "%s", RSTRING_PTR(str));
  }

  return buf;
}

VALUE string_spec_rb_str_capacity(VALUE self, VALUE str) {
  return SIZET2NUM(rb_str_capacity(str));
}

VALUE string_spec_rb_str_buf_new2(VALUE self) {
  return rb_str_buf_new2("hello\0invisible");
}

VALUE string_spec_rb_str_tmp_new(VALUE self, VALUE len) {
  VALUE str = rb_str_tmp_new(NUM2LONG(len));
  rb_obj_reveal(str, rb_cString);
  return str;
}

VALUE string_spec_rb_str_tmp_new_klass(VALUE self, VALUE len) {
  return RBASIC_CLASS(rb_str_tmp_new(NUM2LONG(len)));
}

VALUE string_spec_rb_str_buf_cat(VALUE self, VALUE str) {
  const char *question_mark = "?";
  rb_str_buf_cat(str, question_mark, strlen(question_mark));
  return str;
}

VALUE string_spec_rb_str_cat(VALUE self, VALUE str) {
  return rb_str_cat(str, "?", 1);
}

VALUE string_spec_rb_str_cat2(VALUE self, VALUE str) {
  return rb_str_cat2(str, "?");
}

VALUE string_spec_rb_str_cmp(VALUE self, VALUE str1, VALUE str2) {
  return INT2NUM(rb_str_cmp(str1, str2));
}

VALUE string_spec_rb_str_conv_enc(VALUE self, VALUE str, VALUE from, VALUE to) {
  rb_encoding* from_enc;
  rb_encoding* to_enc;

  from_enc = rb_to_encoding(from);

  if(NIL_P(to)) {
    to_enc = 0;
  } else {
    to_enc = rb_to_encoding(to);
  }

  return rb_str_conv_enc(str, from_enc, to_enc);
}

VALUE string_spec_rb_str_conv_enc_opts(VALUE self, VALUE str, VALUE from, VALUE to,
                                       VALUE ecflags, VALUE ecopts)
{
  rb_encoding* from_enc;
  rb_encoding* to_enc;

  from_enc = rb_to_encoding(from);

  if(NIL_P(to)) {
    to_enc = 0;
  } else {
    to_enc = rb_to_encoding(to);
  }

  return rb_str_conv_enc_opts(str, from_enc, to_enc, FIX2INT(ecflags), ecopts);
}

VALUE string_spec_rb_str_drop_bytes(VALUE self, VALUE str, VALUE len) {
  return rb_str_drop_bytes(str, NUM2LONG(len));
}

VALUE string_spec_rb_str_export(VALUE self, VALUE str) {
  return rb_str_export(str);
}

VALUE string_spec_rb_str_export_locale(VALUE self, VALUE str) {
  return rb_str_export_locale(str);
}

VALUE string_spec_rb_str_dup(VALUE self, VALUE str) {
  return rb_str_dup(str);
}

VALUE string_spec_rb_str_freeze(VALUE self, VALUE str) {
  return rb_str_freeze(str);
}

VALUE string_spec_rb_str_inspect(VALUE self, VALUE str) {
  return rb_str_inspect(str);
}

VALUE string_spec_rb_str_intern(VALUE self, VALUE str) {
  return rb_str_intern(str);
}

VALUE string_spec_rb_str_length(VALUE self, VALUE str) {
  return rb_str_length(str);
}

VALUE string_spec_rb_str_new(VALUE self, VALUE str, VALUE len) {
  return rb_str_new(RSTRING_PTR(str), FIX2INT(len));
}

VALUE string_spec_rb_str_new_native(VALUE self, VALUE str, VALUE len) {
  return rb_str_new(NATIVE_RSTRING_PTR(str), FIX2INT(len));
}

VALUE string_spec_rb_str_new_offset(VALUE self, VALUE str, VALUE offset, VALUE len) {
  return rb_str_new(RSTRING_PTR(str) + FIX2INT(offset), FIX2INT(len));
}

VALUE string_spec_rb_str_new2(VALUE self, VALUE str) {
  if(NIL_P(str)) {
    return rb_str_new2("");
  } else {
    return rb_str_new2(RSTRING_PTR(str));
  }
}

VALUE string_spec_rb_str_encode(VALUE self, VALUE str, VALUE enc, VALUE flags, VALUE opts) {
  return rb_str_encode(str, enc, FIX2INT(flags), opts);
}

VALUE string_spec_rb_str_export_to_enc(VALUE self, VALUE str, VALUE enc) {
  return rb_str_export_to_enc(str, rb_to_encoding(enc));
}

VALUE string_spec_rb_str_new_cstr(VALUE self, VALUE str) {
  if(NIL_P(str)) {
    return rb_str_new_cstr("");
  } else {
    return rb_str_new_cstr(RSTRING_PTR(str));
  }
}

VALUE string_spec_rb_external_str_new(VALUE self, VALUE str) {
  return rb_external_str_new(RSTRING_PTR(str), RSTRING_LEN(str));
}

VALUE string_spec_rb_external_str_new_cstr(VALUE self, VALUE str) {
  return rb_external_str_new_cstr(RSTRING_PTR(str));
}

VALUE string_spec_rb_external_str_new_with_enc(VALUE self, VALUE str, VALUE len, VALUE encoding) {
  return rb_external_str_new_with_enc(RSTRING_PTR(str), FIX2LONG(len), rb_to_encoding(encoding));
}

VALUE string_spec_rb_locale_str_new(VALUE self, VALUE str, VALUE len) {
  return rb_locale_str_new(RSTRING_PTR(str), FIX2INT(len));
}

VALUE string_spec_rb_locale_str_new_cstr(VALUE self, VALUE str) {
  return rb_locale_str_new_cstr(RSTRING_PTR(str));
}

VALUE string_spec_rb_str_new3(VALUE self, VALUE str) {
  return rb_str_new3(str);
}

VALUE string_spec_rb_str_new4(VALUE self, VALUE str) {
  return rb_str_new4(str);
}

VALUE string_spec_rb_str_new5(VALUE self, VALUE str, VALUE ptr, VALUE len) {
  return rb_str_new5(str, RSTRING_PTR(ptr), FIX2INT(len));
}

VALUE string_spec_rb_tainted_str_new(VALUE self, VALUE str, VALUE len) {
  return rb_tainted_str_new(RSTRING_PTR(str), FIX2INT(len));
}

VALUE string_spec_rb_tainted_str_new2(VALUE self, VALUE str) {
  return rb_tainted_str_new2(RSTRING_PTR(str));
}

VALUE string_spec_rb_str_plus(VALUE self, VALUE str1, VALUE str2) {
  return rb_str_plus(str1, str2);
}

VALUE string_spec_rb_str_times(VALUE self, VALUE str, VALUE times) {
  return rb_str_times(str, times);
}

VALUE string_spec_rb_str_modify_expand(VALUE self, VALUE str, VALUE size) {
  rb_str_modify_expand(str, FIX2LONG(size));
  return str;
}

VALUE string_spec_rb_str_resize(VALUE self, VALUE str, VALUE size) {
  return rb_str_resize(str, FIX2INT(size));
}

VALUE string_spec_rb_str_resize_RSTRING_LEN(VALUE self, VALUE str, VALUE size) {
  VALUE modified = rb_str_resize(str, FIX2INT(size));
  return INT2FIX(RSTRING_LEN(modified));
}

VALUE string_spec_rb_str_split(VALUE self, VALUE str) {
  return rb_str_split(str, ",");
}

VALUE string_spec_rb_str_subseq(VALUE self, VALUE str, VALUE beg, VALUE len) {
  return rb_str_subseq(str, FIX2INT(beg), FIX2INT(len));
}

VALUE string_spec_rb_str_substr(VALUE self, VALUE str, VALUE beg, VALUE len) {
  return rb_str_substr(str, FIX2INT(beg), FIX2INT(len));
}

VALUE string_spec_rb_str_to_str(VALUE self, VALUE arg) {
  return rb_str_to_str(arg);
}

VALUE string_spec_RSTRING_LEN(VALUE self, VALUE str) {
  return INT2FIX(RSTRING_LEN(str));
}

VALUE string_spec_RSTRING_LENINT(VALUE self, VALUE str) {
  return INT2FIX(RSTRING_LENINT(str));
}

VALUE string_spec_RSTRING_PTR_iterate(VALUE self, VALUE str) {
  int i;
  char* ptr;

  ptr = RSTRING_PTR(str);
  for(i = 0; i < RSTRING_LEN(str); i++) {
    rb_yield(CHR2FIX(ptr[i]));
  }
  return Qnil;
}

VALUE string_spec_RSTRING_PTR_iterate_uint32(VALUE self, VALUE str) {
  uint32_t* ptr;
  long i, l = RSTRING_LEN(str) / sizeof(uint32_t);

  ptr = (uint32_t *)RSTRING_PTR(str);
  for(i = 0; i < l; i++) {
    rb_yield(UINT2NUM(ptr[i]));
  }
  return Qnil;
}

VALUE string_spec_RSTRING_PTR_short_memcpy(VALUE self, VALUE str) {
  /* Short memcpy operations may be optimised by the compiler to a single write. */
  if (RSTRING_LEN(str) >= 8) {
    memcpy(RSTRING_PTR(str), "Infinity", 8);
  }
  return str;
}

VALUE string_spec_RSTRING_PTR_assign(VALUE self, VALUE str, VALUE chr) {
  int i;
  char c;
  char* ptr;

  ptr = RSTRING_PTR(str);
  c = FIX2INT(chr);

  for(i = 0; i < RSTRING_LEN(str); i++) {
    ptr[i] = c;
  }
  return Qnil;
}

VALUE string_spec_RSTRING_PTR_set(VALUE self, VALUE str, VALUE i, VALUE chr) {
  RSTRING_PTR(str)[FIX2INT(i)] = (char) FIX2INT(chr);
  return str;
}

VALUE string_spec_RSTRING_PTR_after_funcall(VALUE self, VALUE str, VALUE cb) {
  /* Silence gcc 4.3.2 warning about computed value not used */
  if(RSTRING_PTR(str)) { /* force it out */
    rb_funcall(cb, rb_intern("call"), 1, str);
  }

  return rb_str_new2(RSTRING_PTR(str));
}

VALUE string_spec_RSTRING_PTR_after_yield(VALUE self, VALUE str) {
  char* ptr = NATIVE_RSTRING_PTR(str);
  long len = RSTRING_LEN(str);
  VALUE from_rstring_ptr;

  ptr[0] = '1';
  rb_yield(str);
  ptr[2] = '2';

  from_rstring_ptr = rb_str_new(ptr, len);
  return from_rstring_ptr;
}

VALUE string_spec_StringValue(VALUE self, VALUE str) {
  return StringValue(str);
}

static VALUE string_spec_SafeStringValue(VALUE self, VALUE str) {
  SafeStringValue(str);
  return str;
}

static VALUE string_spec_rb_str_hash(VALUE self, VALUE str) {
  st_index_t val = rb_str_hash(str);

  return ST2FIX(val);
}

static VALUE string_spec_rb_str_update(VALUE self, VALUE str, VALUE beg, VALUE end, VALUE replacement) {
  rb_str_update(str, FIX2LONG(beg), FIX2LONG(end), replacement);
  return str;
}

static VALUE string_spec_rb_str_free(VALUE self, VALUE str) {
  rb_str_free(str);
  return Qnil;
}

static VALUE string_spec_rb_sprintf1(VALUE self, VALUE str, VALUE repl) {
  return rb_sprintf(RSTRING_PTR(str), RSTRING_PTR(repl));
}
static VALUE string_spec_rb_sprintf2(VALUE self, VALUE str, VALUE repl1, VALUE repl2) {
  return rb_sprintf(RSTRING_PTR(str), RSTRING_PTR(repl1), RSTRING_PTR(repl2));
}

static VALUE string_spec_rb_sprintf3(VALUE self, VALUE str) {
  return rb_sprintf("Result: %" PRIsVALUE ".", str);
}

static VALUE string_spec_rb_sprintf4(VALUE self, VALUE str) {
  return rb_sprintf("Result: %+" PRIsVALUE ".", str);
}

static VALUE string_spec_rb_vsprintf_worker(char* fmt, ...) {
  va_list varargs;
  VALUE str;

  va_start(varargs, fmt);
  str = rb_vsprintf(fmt, varargs);
  va_end(varargs);

  return str;
}

static VALUE string_spec_rb_vsprintf(VALUE self, VALUE fmt, VALUE str, VALUE i, VALUE f) {
  return string_spec_rb_vsprintf_worker(RSTRING_PTR(fmt), RSTRING_PTR(str),
      FIX2INT(i), RFLOAT_VALUE(f));
}

VALUE string_spec_rb_str_equal(VALUE self, VALUE str1, VALUE str2) {
  return rb_str_equal(str1, str2);
}

static VALUE string_spec_rb_usascii_str_new(VALUE self, VALUE str, VALUE len) {
  return rb_usascii_str_new(RSTRING_PTR(str), NUM2INT(len));
}

static VALUE string_spec_rb_usascii_str_new_cstr(VALUE self, VALUE str) {
  return rb_usascii_str_new_cstr(RSTRING_PTR(str));
}

static VALUE string_spec_rb_String(VALUE self, VALUE val) {
  return rb_String(val);
}

static VALUE string_spec_rb_string_value_cstr(VALUE self, VALUE str) {
  char *c_str = rb_string_value_cstr(&str);
  return c_str ? Qtrue : Qfalse;
}

static VALUE string_spec_rb_str_modify(VALUE self, VALUE str) {
  rb_str_modify(str);
  return str;
}

static VALUE string_spec_rb_utf8_str_new_static(VALUE self) {
  return rb_utf8_str_new_static("nokogiri", 8);
}

static VALUE string_spec_rb_utf8_str_new(VALUE self) {
  return rb_utf8_str_new("nokogiri", 8);
}

static VALUE string_spec_rb_utf8_str_new_cstr(VALUE self) {
  return rb_utf8_str_new_cstr("nokogiri");
}

void Init_string_spec(void) {
  VALUE cls = rb_define_class("CApiStringSpecs", rb_cObject);
  rb_define_method(cls, "rb_cstr2inum", string_spec_rb_cstr2inum, 2);
  rb_define_method(cls, "rb_cstr_to_inum", string_spec_rb_cstr_to_inum, 3);
  rb_define_method(cls, "rb_str2inum", string_spec_rb_str2inum, 2);
  rb_define_method(cls, "rb_str_append", string_spec_rb_str_append, 2);
  rb_define_method(cls, "rb_str_buf_new", string_spec_rb_str_buf_new, 2);
  rb_define_method(cls, "rb_str_capacity", string_spec_rb_str_capacity, 1);
  rb_define_method(cls, "rb_str_buf_new2", string_spec_rb_str_buf_new2, 0);
  rb_define_method(cls, "rb_str_tmp_new", string_spec_rb_str_tmp_new, 1);
  rb_define_method(cls, "rb_str_tmp_new_klass", string_spec_rb_str_tmp_new_klass, 1);
  rb_define_method(cls, "rb_str_buf_cat", string_spec_rb_str_buf_cat, 1);
  rb_define_method(cls, "rb_str_cat", string_spec_rb_str_cat, 1);
  rb_define_method(cls, "rb_str_cat2", string_spec_rb_str_cat2, 1);
  rb_define_method(cls, "rb_str_cmp", string_spec_rb_str_cmp, 2);
  rb_define_method(cls, "rb_str_conv_enc", string_spec_rb_str_conv_enc, 3);
  rb_define_method(cls, "rb_str_conv_enc_opts", string_spec_rb_str_conv_enc_opts, 5);
  rb_define_method(cls, "rb_str_drop_bytes", string_spec_rb_str_drop_bytes, 2);
  rb_define_method(cls, "rb_str_export", string_spec_rb_str_export, 1);
  rb_define_method(cls, "rb_str_export_locale", string_spec_rb_str_export_locale, 1);
  rb_define_method(cls, "rb_str_dup", string_spec_rb_str_dup, 1);
  rb_define_method(cls, "rb_str_freeze", string_spec_rb_str_freeze, 1);
  rb_define_method(cls, "rb_str_inspect", string_spec_rb_str_inspect, 1);
  rb_define_method(cls, "rb_str_intern", string_spec_rb_str_intern, 1);
  rb_define_method(cls, "rb_str_length", string_spec_rb_str_length, 1);
  rb_define_method(cls, "rb_str_new", string_spec_rb_str_new, 2);
  rb_define_method(cls, "rb_str_new_native", string_spec_rb_str_new_native, 2);
  rb_define_method(cls, "rb_str_new_offset", string_spec_rb_str_new_offset, 3);
  rb_define_method(cls, "rb_str_new2", string_spec_rb_str_new2, 1);
  rb_define_method(cls, "rb_str_encode", string_spec_rb_str_encode, 4);
  rb_define_method(cls, "rb_str_export_to_enc", string_spec_rb_str_export_to_enc, 2);
  rb_define_method(cls, "rb_str_new_cstr", string_spec_rb_str_new_cstr, 1);
  rb_define_method(cls, "rb_external_str_new", string_spec_rb_external_str_new, 1);
  rb_define_method(cls, "rb_external_str_new_cstr", string_spec_rb_external_str_new_cstr, 1);
  rb_define_method(cls, "rb_external_str_new_with_enc", string_spec_rb_external_str_new_with_enc, 3);
  rb_define_method(cls, "rb_locale_str_new", string_spec_rb_locale_str_new, 2);
  rb_define_method(cls, "rb_locale_str_new_cstr", string_spec_rb_locale_str_new_cstr, 1);
  rb_define_method(cls, "rb_str_new3", string_spec_rb_str_new3, 1);
  rb_define_method(cls, "rb_str_new4", string_spec_rb_str_new4, 1);
  rb_define_method(cls, "rb_str_new5", string_spec_rb_str_new5, 3);
  rb_define_method(cls, "rb_tainted_str_new", string_spec_rb_tainted_str_new, 2);
  rb_define_method(cls, "rb_tainted_str_new2", string_spec_rb_tainted_str_new2, 1);
  rb_define_method(cls, "rb_str_plus", string_spec_rb_str_plus, 2);
  rb_define_method(cls, "rb_str_times", string_spec_rb_str_times, 2);
  rb_define_method(cls, "rb_str_modify_expand", string_spec_rb_str_modify_expand, 2);
  rb_define_method(cls, "rb_str_resize", string_spec_rb_str_resize, 2);
  rb_define_method(cls, "rb_str_resize_RSTRING_LEN", string_spec_rb_str_resize_RSTRING_LEN, 2);
  rb_define_method(cls, "rb_str_set_len", string_spec_rb_str_set_len, 2);
  rb_define_method(cls, "rb_str_set_len_RSTRING_LEN", string_spec_rb_str_set_len_RSTRING_LEN, 2);
  rb_define_method(cls, "rb_str_split", string_spec_rb_str_split, 1);
  rb_define_method(cls, "rb_str_subseq", string_spec_rb_str_subseq, 3);
  rb_define_method(cls, "rb_str_substr", string_spec_rb_str_substr, 3);
  rb_define_method(cls, "rb_str_to_str", string_spec_rb_str_to_str, 1);
  rb_define_method(cls, "RSTRING_LEN", string_spec_RSTRING_LEN, 1);
  rb_define_method(cls, "RSTRING_LENINT", string_spec_RSTRING_LENINT, 1);
  rb_define_method(cls, "RSTRING_PTR_iterate", string_spec_RSTRING_PTR_iterate, 1);
  rb_define_method(cls, "RSTRING_PTR_iterate_uint32", string_spec_RSTRING_PTR_iterate_uint32, 1);
  rb_define_method(cls, "RSTRING_PTR_short_memcpy", string_spec_RSTRING_PTR_short_memcpy, 1);
  rb_define_method(cls, "RSTRING_PTR_assign", string_spec_RSTRING_PTR_assign, 2);
  rb_define_method(cls, "RSTRING_PTR_set", string_spec_RSTRING_PTR_set, 3);
  rb_define_method(cls, "RSTRING_PTR_after_funcall", string_spec_RSTRING_PTR_after_funcall, 2);
  rb_define_method(cls, "RSTRING_PTR_after_yield", string_spec_RSTRING_PTR_after_yield, 1);
  rb_define_method(cls, "StringValue", string_spec_StringValue, 1);
  rb_define_method(cls, "SafeStringValue", string_spec_SafeStringValue, 1);
  rb_define_method(cls, "rb_str_hash", string_spec_rb_str_hash, 1);
  rb_define_method(cls, "rb_str_update", string_spec_rb_str_update, 4);
  rb_define_method(cls, "rb_str_free", string_spec_rb_str_free, 1);
  rb_define_method(cls, "rb_sprintf1", string_spec_rb_sprintf1, 2);
  rb_define_method(cls, "rb_sprintf2", string_spec_rb_sprintf2, 3);
  rb_define_method(cls, "rb_sprintf3", string_spec_rb_sprintf3, 1);
  rb_define_method(cls, "rb_sprintf4", string_spec_rb_sprintf4, 1);
  rb_define_method(cls, "rb_vsprintf", string_spec_rb_vsprintf, 4);
  rb_define_method(cls, "rb_str_equal", string_spec_rb_str_equal, 2);
  rb_define_method(cls, "rb_usascii_str_new", string_spec_rb_usascii_str_new, 2);
  rb_define_method(cls, "rb_usascii_str_new_cstr", string_spec_rb_usascii_str_new_cstr, 1);
  rb_define_method(cls, "rb_String", string_spec_rb_String, 1);
  rb_define_method(cls, "rb_string_value_cstr", string_spec_rb_string_value_cstr, 1);
  rb_define_method(cls, "rb_str_modify", string_spec_rb_str_modify, 1);
  rb_define_method(cls, "rb_utf8_str_new_static", string_spec_rb_utf8_str_new_static, 0);
  rb_define_method(cls, "rb_utf8_str_new", string_spec_rb_utf8_str_new, 0);
  rb_define_method(cls, "rb_utf8_str_new_cstr", string_spec_rb_utf8_str_new_cstr, 0);
}

#ifdef __cplusplus
}
#endif