/
ruby-1.8.7.patch
462 lines (439 loc) · 12.9 KB
/
ruby-1.8.7.patch
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
diff --git a/Makefile.in b/Makefile.in
index a37bcf6..52f723c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -34,7 +34,7 @@ RIDATADIR = $(DESTDIR)$(datadir)/ri/$(MAJOR).$(MINOR)/system
empty =
OUTFLAG = @OUTFLAG@$(empty)
-CFLAGS = @CFLAGS@ @XCFLAGS@ @ARCH_FLAG@
+CFLAGS = @CFLAGS@ @XCFLAGS@ @ARCH_FLAG@ @VALGRIND_CFLAGS@
cflags = @cflags@
optflags = @optflags@
debugflags = @debugflags@
diff --git a/configure b/configure
index faf2b45..16287ca 100755
--- a/configure
+++ b/configure
@@ -724,6 +724,7 @@ cflags
optflags
debugflags
XCFLAGS
+VALGRIND_CFLAGS
XLDFLAGS
LIBRUBY_LDSHARED
LIBRUBY_DLDFLAGS
@@ -1353,6 +1354,7 @@ Optional Features:
--enable-setreuid use setreuid()/setregid() according to need even if obsolete.
--disable-rpath embed run path into extension libraries.
--enable-shared build a shared library for Ruby.
+ --enable-valgrind Use valgrind support
--enable-install-doc build and install rdoc indexes during install
Optional Packages:
@@ -13012,12 +13014,11 @@ cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <sys/types.h> /* for off_t */
- #include <stdio.h>
+#include <stdio.h>
int
main ()
{
-int (*fp) (FILE *, off_t, int) = fseeko;
- return fseeko (stdin, 0, 0) && fp (stdin, 0, 0);
+return fseeko (stdin, 0, 0) && (fseeko) (stdin, 0, 0);
;
return 0;
}
@@ -16462,6 +16463,173 @@ done
fi
fi
+# Check whether --enable-valgrind was given.
+if test "${enable_valgrind+set}" = set; then
+ enableval=$enable_valgrind; want_valgrind=$enableval
+else
+ want_valgrind=auto
+fi
+
+
+if test x"$want_valgrind" != xno; then
+
+for ac_header in valgrind/memcheck.h
+do
+as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+ { echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+ { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+else
+ # Is the header compilable?
+{ echo "$as_me:$LINENO: checking $ac_header usability" >&5
+echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+#include <$ac_header>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_compile") 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && {
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ } && test -s conftest.$ac_objext; then
+ ac_header_compiler=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_header_compiler=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
+echo "${ECHO_T}$ac_header_compiler" >&6; }
+
+# Is the header present?
+{ echo "$as_me:$LINENO: checking $ac_header presence" >&5
+echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; }
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <$ac_header>
+_ACEOF
+if { (ac_try="$ac_cpp conftest.$ac_ext"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } >/dev/null && {
+ test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ }; then
+ ac_header_preproc=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_header_preproc=no
+fi
+
+rm -f conftest.err conftest.$ac_ext
+{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
+echo "${ECHO_T}$ac_header_preproc" >&6; }
+
+# So? What about this header?
+case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
+ yes:no: )
+ { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
+echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
+ ac_header_preproc=yes
+ ;;
+ no:yes:* )
+ { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
+echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
+echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
+echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
+echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
+echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
+ { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
+echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
+
+ ;;
+esac
+{ echo "$as_me:$LINENO: checking for $ac_header" >&5
+echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; }
+if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ eval "$as_ac_Header=\$ac_header_preproc"
+fi
+ac_res=`eval echo '${'$as_ac_Header'}'`
+ { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+
+fi
+if test `eval echo '${'$as_ac_Header'}'` = yes; then
+ cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
+_ACEOF
+ have_valgrind=yes
+else
+ have_valgrind=no
+fi
+
+done
+
+ if test x"$have_valgrind" = xyes; then
+ cat >>confdefs.h <<\_ACEOF
+#define HAVE_VALGRIND 1
+_ACEOF
+
+ VALGRIND_CFLAGS="";
+ elif test x"$want_valgrind" = xyes -a x"$have_valgrind" = xno; then
+ { { echo "$as_me:$LINENO: error: valgrind support requested but valgrind not found" >&5
+echo "$as_me: error: valgrind support requested but valgrind not found" >&2;}
+ { (exit 1); exit 1; }; }
+ else
+ VALGRIND_CFLAGS="";
+ fi
+fi
+
+
DEFAULT_KCODE="KCODE_NONE"
@@ -18588,6 +18756,7 @@ cflags!$cflags$ac_delim
optflags!$optflags$ac_delim
debugflags!$debugflags$ac_delim
XCFLAGS!$XCFLAGS$ac_delim
+VALGRIND_CFLAGS!$VALGRIND_CFLAGS$ac_delim
XLDFLAGS!$XLDFLAGS$ac_delim
LIBRUBY_LDSHARED!$LIBRUBY_LDSHARED$ac_delim
LIBRUBY_DLDFLAGS!$LIBRUBY_DLDFLAGS$ac_delim
@@ -18622,7 +18791,7 @@ MANTYPE!$MANTYPE$ac_delim
LTLIBOBJS!$LTLIBOBJS$ac_delim
_ACEOF
- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 47; then
+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 48; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
diff --git a/configure.in b/configure.in
index fe63c0c..e0cdcdd 100644
--- a/configure.in
+++ b/configure.in
@@ -1043,6 +1043,23 @@ if test x"$ac_cv_header_ucontext_h" = xyes; then
fi
fi
+AC_ARG_ENABLE(valgrind,
+ [ --enable-valgrind use valgrind support],
+ [want_valgrind=$enableval], [want_valgrind=auto])
+
+if test x"$want_valgrind" != xno; then
+ AC_CHECK_HEADERS(valgrind/memcheck.h, have_valgrind=yes, have_valgrind=no)
+ if test x"$have_valgrind" = xyes; then
+ AC_DEFINE(HAVE_VALGRIND)
+ VALGRIND_CFLAGS="";
+ elif test x"$want_valgrind" = xyes -a x"$have_valgrind" = xno; then
+ AC_MSG_ERROR(valgrind support requested but valgrind not found)
+ else
+ VALGRIND_CFLAGS="";
+ fi
+fi
+
+
dnl default value for $KANJI
DEFAULT_KCODE="KCODE_NONE"
@@ -1663,6 +1680,7 @@ AC_SUBST(cflags, ['${optflags} ${debugflags}'])dnl
AC_SUBST(optflags)dnl
AC_SUBST(debugflags)dnl
AC_SUBST(XCFLAGS)dnl
+AC_SUBST(VALGRIND_CFLAGS)dnl
AC_SUBST(XLDFLAGS)dnl
AC_SUBST(LIBRUBY_LDSHARED)
AC_SUBST(LIBRUBY_DLDFLAGS)
diff --git a/eval.c b/eval.c
index 11264f7..09ec7a6 100644
--- a/eval.c
+++ b/eval.c
@@ -28,6 +28,12 @@
#define EXIT_FAILURE 1
#endif
+#ifdef HAVE_VALGRIND
+#include <valgrind/memcheck.h>
+#else
+#define VALGRIND_MAKE_MEM_DEFINED(p, n) /* empty */
+#endif
+
#include <stdio.h>
#include "st.h"
@@ -1149,7 +1149,7 @@ static VALUE trace_func = 0;
static int tracing = 0;
static void call_trace_func _((rb_event_t,NODE*,VALUE,ID,VALUE));
-#if 0
+#if 1
#define SET_CURRENT_SOURCE() (ruby_sourcefile = ruby_current_node->nd_file, \
ruby_sourceline = nd_line(ruby_current_node))
#else
@@ -5290,6 +5296,9 @@ assign(self, lhs, val, pcall)
int pcall;
{
ruby_current_node = lhs;
+
+ VALGRIND_MAKE_MEM_DEFINED(&val, sizeof(val));
+
if (val == Qundef) {
rb_warning("assigning void value");
val = Qnil;
diff --git a/gc.c b/gc.c
index 45facf0..933b76e 100644
--- a/gc.c
+++ b/gc.c
@@ -30,6 +30,12 @@
#include <sys/resource.h>
#endif
+#ifdef HAVE_VALGRIND
+#include <valgrind/memcheck.h>
+#else
+#define VALGRIND_MAKE_MEM_DEFINED(p, n) /* empty */
+#endif
+
#if defined _WIN32 || defined __CYGWIN__
#include <windows.h>
#endif
@@ -138,6 +144,9 @@ ruby_xmalloc(size)
{
void *mem;
+ VALGRIND_MAKE_MEM_DEFINED(&malloc_increase, sizeof(malloc_increase));
+ VALGRIND_MAKE_MEM_DEFINED(&malloc_limit, sizeof(malloc_limit));
+
if (size < 0) {
rb_raise(rb_eNoMemError, "negative allocation size (or too big)");
}
@@ -297,8 +306,6 @@ rb_gc_unregister_address(addr)
}
}
-#undef GC_DEBUG
-
void
rb_global_variable(var)
VALUE *var;
@@ -333,10 +340,8 @@ typedef struct RVALUE {
struct RVarmap varmap;
struct SCOPE scope;
} as;
-#ifdef GC_DEBUG
char *file;
int line;
-#endif
} RVALUE;
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__CYGWIN__)
@@ -355,6 +360,22 @@ static struct heaps_slot {
static int heaps_length = 0;
static int heaps_used = 0;
+struct heaps_slot *
+rb_gc_heap_slots()
+{
+ return heaps;
+}
+
+int
+rb_gc_heaps_used() {
+ return heaps_used;
+}
+
+int
+rb_gc_heaps_length() {
+ return heaps_length;
+}
+
#define HEAP_MIN_SLOTS 10000
static int heap_slots = HEAP_MIN_SLOTS;
@@ -442,6 +463,11 @@ rb_newobj()
RANY(obj)->file = ruby_sourcefile;
RANY(obj)->line = ruby_sourceline;
#endif
+
+ if (ruby_current_node && ruby_current_node->nd_file) {
+ RANY(obj)->file = ruby_current_node->nd_file;
+ RANY(obj)->line = nd_line(ruby_current_node);
+ }
return obj;
}
@@ -678,6 +704,9 @@ mark_locations_array(x, n)
register long n;
{
VALUE v;
+
+ VALGRIND_MAKE_MEM_DEFINED(x, sizeof(*x) * n);
+
while (n--) {
v = *x;
if (is_pointer_to_heap((void *)v)) {
@@ -768,12 +797,18 @@ gc_mark(ptr, lev)
{
register RVALUE *obj;
+ VALGRIND_MAKE_MEM_DEFINED(&ptr, sizeof(ptr));
obj = RANY(ptr);
+ VALGRIND_MAKE_MEM_DEFINED(obj, sizeof(*obj));
+
if (rb_special_const_p(ptr)) return; /* special const not marked */
if (obj->as.basic.flags == 0) return; /* free cell */
if (obj->as.basic.flags & FL_MARK) return; /* already marked */
obj->as.basic.flags |= FL_MARK;
+ /* mark our new reference point for sourcefile objects */
+ mark_source_filename(RANY(obj)->file);
+
if (lev > GC_LEVEL_MAX || (lev == 0 && ruby_stack_check())) {
if (!mark_stack_overflow) {
if (mark_stack_ptr - mark_stack < MARK_STACK_MAX) {
diff --git a/parse.c b/parse.c
index 6b3d80d..b320cf2 100644
--- a/parse.c
+++ b/parse.c
@@ -11403,6 +11403,11 @@ symbols_i(key, value, ary)
* :wait2, :$>]
*/
+struct st_table *
+rb_parse_sym_tbl() {
+ return sym_tbl;
+}
+
VALUE
rb_sym_all_symbols()
{
diff --git a/parse.y b/parse.y
index ab0b83c..3ce1dfb 100644
--- a/parse.y
+++ b/parse.y
@@ -6263,6 +6263,11 @@ symbols_i(key, value, ary)
* :wait2, :$>]
*/
+struct st_table *
+rb_parse_sym_tbl() {
+ return sym_tbl;
+}
+
VALUE
rb_sym_all_symbols()
{
diff --git a/version.h b/version.h
index 70fc28a..76aa188 100644
--- a/version.h
+++ b/version.h
@@ -5,2 +5,2 @@
-#define RUBY_PATCHLEVEL 174
+#define RUBY_PATCHLEVEL 905