discount 1.2.6 → 1.2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/ext/rbstrio.c +21 -4
- data/ext/rbstrio.h +0 -1
- metadata +1 -1
data/Rakefile
CHANGED
data/ext/rbstrio.c
CHANGED
@@ -1,26 +1,43 @@
|
|
1
|
+
#define _GNU_SOURCE
|
2
|
+
|
3
|
+
#include <stdlib.h>
|
1
4
|
#include "rbstrio.h"
|
2
|
-
#include "ruby.h"
|
3
5
|
|
4
6
|
#define INCREMENT 1024
|
5
7
|
|
6
8
|
/* called when data is written to the stream. */
|
7
9
|
static int rb_str_io_write(void *cookie, const char *data, int len) {
|
8
|
-
VALUE buf = cookie;
|
10
|
+
VALUE buf = (VALUE)cookie;
|
9
11
|
rb_str_cat(buf, data, len);
|
10
12
|
return len;
|
11
13
|
}
|
12
14
|
|
13
15
|
/* called when the stream is closed */
|
14
16
|
static int rb_str_io_close(void *cookie) {
|
15
|
-
|
17
|
+
VALUE buf = (VALUE)cookie;
|
18
|
+
rb_gc_unregister_address(&buf);
|
16
19
|
return 0;
|
17
20
|
}
|
18
21
|
|
22
|
+
#ifdef __GLIBC__
|
23
|
+
cookie_io_functions_t rb_str_io_functions =
|
24
|
+
{
|
25
|
+
(cookie_read_function_t*)NULL,
|
26
|
+
(cookie_write_function_t*)rb_str_io_write,
|
27
|
+
(cookie_seek_function_t*)NULL,
|
28
|
+
(cookie_close_function_t*)rb_str_io_close
|
29
|
+
};
|
30
|
+
#endif
|
31
|
+
|
19
32
|
/* create a stream backed by a Ruby string. */
|
20
33
|
FILE *rb_str_io_new(VALUE buf) {
|
21
34
|
FILE *rv;
|
22
35
|
Check_Type(buf, T_STRING);
|
23
|
-
|
36
|
+
#ifdef __GLIBC__
|
37
|
+
rv = fopencookie((void*)buf, "w", rb_str_io_functions);
|
38
|
+
#else
|
39
|
+
rv = funopen((void*)buf, NULL, rb_str_io_write, NULL, rb_str_io_close);
|
40
|
+
#endif
|
24
41
|
/* TODO if (rv == NULL) */
|
25
42
|
rb_gc_register_address(&buf);
|
26
43
|
return rv;
|
data/ext/rbstrio.h
CHANGED