mwrap 2.2.0.1.g867b → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3766bf906f58529a4ddf88092f71cd4dc976e5c1dd1f147ffa30d7ebb0ddcf7
4
- data.tar.gz: 594b60075684fbedb224dfbb2632df74971cd36b52d4e991e07146af9a7106cc
3
+ metadata.gz: b967676ac9ff95d0771147fc464a06ce6a88c9a7e07c3eef97b0cf0a273ff822
4
+ data.tar.gz: f99e5f3a27adecf190e11a921a58f46c9514e28a88d83602c2421dbd8cecc90b
5
5
  SHA512:
6
- metadata.gz: a60e54ad4b1f024cd69ed7a968721c893310c5201516cc98d2023e9b61e54a20a1d8d1775fc6ca1f3638ebebc6ee32a4bb7c0ab6afc51b719203fbae4e955ba9
7
- data.tar.gz: b9e1a20b64ddf602baf3f5a43e439b3a2742a31c45faad9725fa32fdfc4895f40ccf3949980dace0e51e3ef1cecc9b6e3674c3e0a78d2725f11711e23c4bcee5
6
+ metadata.gz: 6f3a089d3bf14258b0382d13f8d4428ffd0291d6e9af8fa33331696e5b55e5a279f0dafc30fb1018e73a199d9d3b8cbe826dd814dfd80941ae059581fa6f330c
7
+ data.tar.gz: 54a2bc06918d050e161ff0c9457ca67ebc3573a5795495d5ab57637d0bb37830e442f3073cede28d672938baaba7e7057b9d0fa8f40c64b85864add6e81e53d0
data/MANIFEST CHANGED
@@ -5,10 +5,13 @@ COPYING
5
5
  MANIFEST
6
6
  README
7
7
  Rakefile
8
+ VERSION-GEN
8
9
  bin/mwrap
9
10
  ext/mwrap/extconf.rb
10
11
  ext/mwrap/jhash.h
11
12
  ext/mwrap/mwrap.c
13
+ lib/mwrap/.gitignore
12
14
  lib/mwrap_rack.rb
13
15
  mwrap.gemspec
14
16
  test/test_mwrap.rb
17
+ lib/mwrap/version.rb
data/README CHANGED
@@ -23,7 +23,7 @@ It does not require recompiling or rebuilding Ruby, but only
23
23
  supports Ruby trunk (2.6.0dev+) on a few platforms:
24
24
 
25
25
  * GNU/Linux
26
- * FreeBSD (tested 11.1)
26
+ * FreeBSD (tested 11.1 on Ruby 2.6, currently broken with Ruby 3.x)
27
27
 
28
28
  It may work on NetBSD, OpenBSD and DragonFly BSD.
29
29
 
data/VERSION-GEN ADDED
@@ -0,0 +1,36 @@
1
+ #!/bin/sh
2
+ VF=lib/mwrap/version.rb
3
+ DEF_VER=v2.3.0
4
+ VN=$(git describe HEAD 2>/dev/null)
5
+ if test $? -eq 0
6
+ then
7
+ case "$VN" in
8
+ v[0-9]*)
9
+ set -e
10
+ git update-index -q --refresh
11
+ set +e
12
+ git diff-index --quiet HEAD -- || VN="$VN-dirty"
13
+ set -e
14
+ VN=$(echo $VN | tr '-' '.')
15
+ ;;
16
+ esac
17
+ fi
18
+ set -e
19
+
20
+ case $VN in
21
+ '') VN="$DEF_VER" ;;
22
+ esac
23
+
24
+ VN=$(expr "$VN" : v*'\(.*\)')
25
+ VC=unset
26
+ if test -r $VF
27
+ then
28
+ VC="$(cat $VF)"
29
+ fi
30
+
31
+ new="module Mwrap; VERSION = '$VN'.freeze; end"
32
+ if test x"$new" != x"$VC"
33
+ then
34
+ echo "$new" >$VF
35
+ fi
36
+ echo $VN
data/bin/mwrap CHANGED
@@ -2,6 +2,25 @@
2
2
  # frozen_string_literal: true
3
3
  # Copyright (C) mwrap hackers <mwrap-public@80x24.org>
4
4
  # License: GPL-2.0+ <https://www.gnu.org/licenses/gpl-2.0.txt>
5
+ help = <<EOM
6
+ usage: mwrap COMMAND [ARGS]
7
+ see https://80x24.org/mwrap/README.html for more info
8
+ EOM
9
+ ARGV.empty? and abort help
10
+ ARGV.each do |x|
11
+ case x
12
+ when '--version', '-v'
13
+ require 'mwrap/version'
14
+ puts "mwrap #{Mwrap::VERSION} - #{RUBY_DESCRIPTION}"
15
+ exit 0
16
+ when '--help', '-h'
17
+ puts help
18
+ exit 0
19
+ else # don't intercept --version/--help intended for commands we wrap
20
+ break
21
+ end
22
+ end
23
+
5
24
  require 'mwrap'
6
25
  mwrap_so = $".grep(%r{/mwrap\.so\z})[0] or abort "mwrap.so not loaded"
7
26
  cur = ENV['LD_PRELOAD']
data/ext/mwrap/extconf.rb CHANGED
@@ -11,15 +11,15 @@ have_library 'dl'
11
11
  have_library 'c'
12
12
  have_library 'execinfo' # FreeBSD
13
13
 
14
- if try_link(<<'')
14
+ if try_link(<<EOC)
15
15
  int main(void) { return __builtin_add_overflow_p(0,0,(int)1); }
16
-
16
+ EOC
17
17
  $defs << '-DHAVE_BUILTIN_ADD_OVERFLOW_P'
18
18
  end
19
19
 
20
- if try_link(<<'')
20
+ if try_link(<<EOC)
21
21
  int main(int a) { return __builtin_add_overflow(0,0,&a); }
22
-
22
+ EOC
23
23
  $defs << '-DHAVE_BUILTIN_ADD_OVERFLOW_P'
24
24
  else
25
25
  abort 'missing __builtin_add_overflow'
data/ext/mwrap/mwrap.c CHANGED
@@ -99,9 +99,43 @@ union padded_mutex {
99
99
  /* a round-robin pool of mutexes */
100
100
  #define MUTEX_NR (1 << 6)
101
101
  #define MUTEX_MASK (MUTEX_NR - 1)
102
+ #ifdef __FreeBSD__
103
+ # define STATIC_MTX_INIT_OK (0)
104
+ #else /* only tested on Linux + glibc */
105
+ # define STATIC_MTX_INIT_OK (1)
106
+ #endif
102
107
  static size_t mutex_i;
103
108
  static union padded_mutex mutexes[MUTEX_NR] = {
109
+ #if STATIC_MTX_INIT_OK
104
110
  [0 ... (MUTEX_NR-1)].mtx = PTHREAD_MUTEX_INITIALIZER
111
+ #endif
112
+ };
113
+
114
+ #define ACC_INIT(name) { .nr=0, .min=INT64_MAX, .max=-1, .m2=0, .mean=0 }
115
+ struct acc {
116
+ uint64_t nr;
117
+ int64_t min;
118
+ int64_t max;
119
+ double m2;
120
+ double mean;
121
+ };
122
+
123
+ /* for tracking 16K-aligned heap page bodies (protected by GVL) */
124
+ struct {
125
+ pthread_mutex_t lock;
126
+ struct cds_list_head bodies;
127
+ struct cds_list_head freed;
128
+
129
+ struct acc alive;
130
+ struct acc reborn;
131
+ } hpb_stats = {
132
+ #if STATIC_MTX_INIT_OK
133
+ .lock = PTHREAD_MUTEX_INITIALIZER,
134
+ #endif
135
+ .bodies = CDS_LIST_HEAD_INIT(hpb_stats.bodies),
136
+ .freed = CDS_LIST_HEAD_INIT(hpb_stats.freed),
137
+ .alive = ACC_INIT(hpb_stats.alive),
138
+ .reborn = ACC_INIT(hpb_stats.reborn)
105
139
  };
106
140
 
107
141
  static pthread_mutex_t *mutex_assign(void)
@@ -120,12 +154,11 @@ __attribute__((constructor)) static void resolve_malloc(void)
120
154
  int err;
121
155
  ++locating;
122
156
 
123
- #ifdef __FreeBSD__
124
157
  /*
125
158
  * PTHREAD_MUTEX_INITIALIZER on FreeBSD means lazy initialization,
126
159
  * which happens at pthread_mutex_lock, and that calls calloc
127
160
  */
128
- {
161
+ if (!STATIC_MTX_INIT_OK) {
129
162
  size_t i;
130
163
 
131
164
  for (i = 0; i < MUTEX_NR; i++) {
@@ -135,22 +168,28 @@ __attribute__((constructor)) static void resolve_malloc(void)
135
168
  _exit(1);
136
169
  }
137
170
  }
171
+ err = pthread_mutex_init(&hpb_stats.lock, 0);
172
+ if (err) {
173
+ fprintf(stderr, "error: %s\n", strerror(err));
174
+ _exit(1);
175
+ }
138
176
  /* initialize mutexes used by urcu-bp */
139
177
  rcu_read_lock();
140
178
  rcu_read_unlock();
179
+ #ifndef __FreeBSD__
180
+ } else {
181
+ if (!real_malloc) {
182
+ resolving_malloc = 1;
183
+ real_malloc = dlsym(RTLD_NEXT, "malloc");
184
+ }
185
+ real_free = dlsym(RTLD_NEXT, "free");
186
+ if (!real_malloc || !real_free) {
187
+ fprintf(stderr, "missing malloc/aligned_alloc/free\n"
188
+ "\t%p %p\n", real_malloc, real_free);
189
+ _exit(1);
190
+ }
191
+ #endif /* !__FreeBSD__ */
141
192
  }
142
- #else /* !FreeBSD (tested on GNU/Linux) */
143
- if (!real_malloc) {
144
- resolving_malloc = 1;
145
- real_malloc = dlsym(RTLD_NEXT, "malloc");
146
- }
147
- real_free = dlsym(RTLD_NEXT, "free");
148
- if (!real_malloc || !real_free) {
149
- fprintf(stderr, "missing malloc/aligned_alloc/free\n"
150
- "\t%p %p\n", real_malloc, real_free);
151
- _exit(1);
152
- }
153
- #endif /* !FreeBSD */
154
193
  CMM_STORE_SHARED(totals, lfht_new());
155
194
  if (!CMM_LOAD_SHARED(totals))
156
195
  fprintf(stderr, "failed to allocate totals table\n");
@@ -237,32 +276,6 @@ static int has_ec_p(void)
237
276
  ruby_current_vm_ptr && ruby_current_ec;
238
277
  }
239
278
 
240
- struct acc {
241
- uint64_t nr;
242
- int64_t min;
243
- int64_t max;
244
- double m2;
245
- double mean;
246
- };
247
-
248
- #define ACC_INIT(name) { .nr=0, .min=INT64_MAX, .max=-1, .m2=0, .mean=0 }
249
-
250
- /* for tracking 16K-aligned heap page bodies (protected by GVL) */
251
- struct {
252
- pthread_mutex_t lock;
253
- struct cds_list_head bodies;
254
- struct cds_list_head freed;
255
-
256
- struct acc alive;
257
- struct acc reborn;
258
- } hpb_stats = {
259
- .lock = PTHREAD_MUTEX_INITIALIZER,
260
- .bodies = CDS_LIST_HEAD_INIT(hpb_stats.bodies),
261
- .freed = CDS_LIST_HEAD_INIT(hpb_stats.freed),
262
- .alive = ACC_INIT(hpb_stats.alive),
263
- .reborn = ACC_INIT(hpb_stats.reborn)
264
- };
265
-
266
279
  /* allocated via real_malloc/real_free */
267
280
  struct src_loc {
268
281
  pthread_mutex_t *mtx;
@@ -0,0 +1 @@
1
+ version.rb
@@ -0,0 +1 @@
1
+ module Mwrap; VERSION = '2.3.0'.freeze; end
data/mwrap.gemspec CHANGED
@@ -1,18 +1,21 @@
1
1
  git_manifest = `git ls-files 2>/dev/null`.split("\n")
2
+ git_ok = $?.success?
3
+ git_manifest << 'lib/mwrap/version.rb'.freeze # generated by ./VERSION-GEN
2
4
  manifest = File.exist?('MANIFEST') ?
3
5
  File.readlines('MANIFEST').map!(&:chomp).delete_if(&:empty?) : git_manifest
4
- if git_manifest[0] && manifest != git_manifest
6
+ if git_ok && manifest != git_manifest
5
7
  tmp = "MANIFEST.#$$.tmp"
6
8
  File.open(tmp, 'w') { |fp| fp.puts(git_manifest.join("\n")) }
7
9
  File.rename(tmp, 'MANIFEST')
8
10
  system('git add MANIFEST')
9
11
  end
10
12
 
11
- desc = `git describe --abbrev=4 HEAD`.strip.tr('-', '.').delete_prefix('v')
13
+ version = `./VERSION-GEN`.chomp
14
+ $?.success? or abort './VERSION-GEN failed'
12
15
 
13
16
  Gem::Specification.new do |s|
14
17
  s.name = 'mwrap'
15
- s.version = desc.empty? ? '2.2.0' : desc
18
+ s.version = version
16
19
  s.homepage = 'https://80x24.org/mwrap/'
17
20
  s.authors = ["mwrap hackers"]
18
21
  s.summary = 'LD_PRELOAD malloc wrapper for Ruby'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mwrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0.1.g867b
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mwrap hackers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-23 00:00:00.000000000 Z
11
+ date: 2022-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -55,10 +55,13 @@ files:
55
55
  - MANIFEST
56
56
  - README
57
57
  - Rakefile
58
+ - VERSION-GEN
58
59
  - bin/mwrap
59
60
  - ext/mwrap/extconf.rb
60
61
  - ext/mwrap/jhash.h
61
62
  - ext/mwrap/mwrap.c
63
+ - lib/mwrap/.gitignore
64
+ - lib/mwrap/version.rb
62
65
  - lib/mwrap_rack.rb
63
66
  - mwrap.gemspec
64
67
  - test/test_mwrap.rb
@@ -77,9 +80,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
80
  version: '0'
78
81
  required_rubygems_version: !ruby/object:Gem::Requirement
79
82
  requirements:
80
- - - ">"
83
+ - - ">="
81
84
  - !ruby/object:Gem::Version
82
- version: 1.3.1
85
+ version: '0'
83
86
  requirements: []
84
87
  rubygems_version: 3.0.2
85
88
  signing_key: