Skip to content

Commit 30a1b86

Browse files
committed
merge revision(s) 44568: [Backport ruby#9399]
* iseq.c (iseq_load): keep type_map to get rid of memory leak. based on a patch by Eric Wong at [ruby-core:59699]. [Bug ruby#9399] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@44946 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 73176ef commit 30a1b86

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Fri Feb 14 15:40:32 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* iseq.c (iseq_load): keep type_map to get rid of memory leak.
4+
based on a patch by Eric Wong at [ruby-core:59699]. [Bug #9399]
5+
16
Fri Feb 14 15:25:23 2014 Tanaka Akira <akr@fsij.org>
27

38
* lib/resolv.rb (Resolv::DNS::Resource::TXT#data): Return concatenated

iseq.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
450450
VALUE type, body, locals, args, exception;
451451

452452
st_data_t iseq_type;
453+
static struct st_table *type_map_cache = 0;
453454
struct st_table *type_map = 0;
454455
rb_iseq_t *iseq;
455456
rb_compile_option_t option;
@@ -488,7 +489,9 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
488489
GetISeqPtr(iseqval, iseq);
489490
iseq->self = iseqval;
490491

492+
type_map = type_map_cache;
491493
if (type_map == 0) {
494+
struct st_table *cached_map;
492495
type_map = st_init_numtable();
493496
st_insert(type_map, ID2SYM(rb_intern("top")), ISEQ_TYPE_TOP);
494497
st_insert(type_map, ID2SYM(rb_intern("method")), ISEQ_TYPE_METHOD);
@@ -499,6 +502,11 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
499502
st_insert(type_map, ID2SYM(rb_intern("eval")), ISEQ_TYPE_EVAL);
500503
st_insert(type_map, ID2SYM(rb_intern("main")), ISEQ_TYPE_MAIN);
501504
st_insert(type_map, ID2SYM(rb_intern("defined_guard")), ISEQ_TYPE_DEFINED_GUARD);
505+
cached_map = ATOMIC_PTR_CAS(type_map_cache, (struct st_table *)0, type_map);
506+
if (cached_map) {
507+
st_free_table(type_map);
508+
type_map = cached_map;
509+
}
502510
}
503511

504512
if (st_lookup(type_map, type, &iseq_type) == 0) {

ruby_atomic.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ rb_w32_atomic_or(volatile rb_atomic_t *var, rb_atomic_t val)
5656
# define ATOMIC_SIZE_INC(var) InterlockedIncrement64(&(var))
5757
# define ATOMIC_SIZE_DEC(var) InterlockedDecrement64(&(var))
5858
# define ATOMIC_SIZE_EXCHANGE(var, val) InterlockedExchange64(&(var), (val))
59+
# define ATOMIC_SIZE_CAS(var, oldval, val) InterlockedCompareExchange64(&(var), (oldval), (val))
5960
# else
6061
# define ATOMIC_SIZE_ADD(var, val) InterlockedExchangeAdd((LONG *)&(var), (val))
6162
# define ATOMIC_SIZE_SUB(var, val) InterlockedExchangeAdd((LONG *)&(var), -(val))
@@ -80,7 +81,7 @@ typedef unsigned int rb_atomic_t;
8081
# define ATOMIC_SIZE_INC(var) atomic_inc_ulong(&(var))
8182
# define ATOMIC_SIZE_DEC(var) atomic_dec_ulong(&(var))
8283
# define ATOMIC_SIZE_EXCHANGE(var, val) atomic_swap_ulong(&(var), (val))
83-
# else
84+
# define ATOMIC_SIZE_CAS(var, oldval, val) atomic_cas_ulong(&(var), (oldval), (# else
8485
# define ATOMIC_SIZE_ADD(var, val) atomic_add_int(&(var), (val))
8586
# define ATOMIC_SIZE_SUB(var, val) atomic_add_int(&(var), -(val))
8687
# define ATOMIC_SIZE_INC(var) atomic_inc_uint(&(var))
@@ -113,10 +114,19 @@ atomic_size_exchange(size_t *ptr, size_t val)
113114
}
114115
#endif
115116

117+
#ifndef ATOMIC_SIZE_CAS
118+
# define ATOMIC_SIZE_CAS(var, oldval, val) ATOMIC_CAS(var, oldval, val)
119+
#endif
120+
116121
#ifndef ATOMIC_PTR_EXCHANGE
117122
# if SIZEOF_VOIDP == SIZEOF_SIZE_T
118123
# define ATOMIC_PTR_EXCHANGE(var, val) (void *)ATOMIC_SIZE_EXCHANGE(*(size_t *)&(var), (size_t)(val))
119124
# endif
120125
#endif
126+
#ifndef ATOMIC_PTR_CAS
127+
# if SIZEOF_VOIDP == SIZEOF_SIZE_T
128+
# define ATOMIC_PTR_CAS(var, oldval, val) (void *)ATOMIC_SIZE_CAS(*(size_t *)&(var), (size_t)(oldval), (size_t)(val))
129+
# endif
130+
#endif
121131

122132
#endif /* RUBY_ATOMIC_H */

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define RUBY_VERSION "1.9.3"
2-
#define RUBY_PATCHLEVEL 526
2+
#define RUBY_PATCHLEVEL 527
33

44
#define RUBY_RELEASE_DATE "2014-02-14"
55
#define RUBY_RELEASE_YEAR 2014

0 commit comments

Comments
 (0)