ruby-magic 0.4.0 → 0.5.4

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: 5ec6d5053457e958f459236e45b56c3e4f85dd16e8c09f119208619db7332982
4
- data.tar.gz: 01bd34ae0c013438354e440ab533f2b8bce0bd693df874043181a365b1980fe3
3
+ metadata.gz: 62a636b8ebb83354f9cd8ae8f25a97c9b451765687f5c4289bd44e6f1b729035
4
+ data.tar.gz: 79509714217a030267ae86277fbff57eceb8466a51b89514a6ba7b996d18f94b
5
5
  SHA512:
6
- metadata.gz: d41cbbfec82e392dfe5db7d30d51814f852def72c09f766c4cf9f007272fb256fb4669db02963a8c7fc185c4ecbb83d22873e70fadc89fd63ed0098e5a7397f2
7
- data.tar.gz: 8537e862c2b421ccf2d301d0a8811f02112f35c53061d3565d15601264e082e61184af80f866dc37a186101268c99684ada8b6949ab7feea81baf02e97f2dee3
6
+ metadata.gz: 2ba1b598ffbe702fa9467598fd44d9e9ae66beef318120092a597fe8ad08bec10a912c0f0b40609f3b08c8ec266f414048db0befa6c348eda1eab2c17af5bb41
7
+ data.tar.gz: bea167c85a64f0463e46987a690ee4aa0d00424eaa41f815898f57652d61c52455867b3df39d5ea5d35e529bc3a8176f8ed10021c9112f856d3b556ed4191767
checksums.yaml.gz.sig ADDED
Binary file
data/CHANGELOG.md CHANGED
@@ -7,6 +7,44 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.3] - 2021-12-22
11
+
12
+ ### Fixed
13
+
14
+ - ext: load C extension files from non-native gems via "require"
15
+
16
+ ## [0.5.2] - 2021-11-20
17
+
18
+ - No changes
19
+
20
+ ## [0.5.1] - 2021-11-20
21
+
22
+ ### Fixed
23
+
24
+ - Check for pkg-config when building static libraries.
25
+
26
+ ## [0.5.0] - 2021-09-30
27
+
28
+ ### Added
29
+
30
+ - Introduce support for building native gems.
31
+
32
+ ### Changed
33
+
34
+ - Relax mini_portile2 dependency.
35
+ - Use RB_ALLOC() over calling ruby_xmalloc() directly
36
+ - Address warnings reported by cppcheck.
37
+ - Address code style that checkpatch.pl script reported.
38
+ - Fix how flags are set for the open() function.
39
+ - Clean up type definitions.
40
+ - Add alias Magic::mime_type for Magic::mime.
41
+ - Make magic_set_flags() return void as its return value was never used.
42
+
43
+ ### Fixed
44
+
45
+ - Fix truffleruby test failure
46
+ - Fix --use-system-libraries not working with Rake install
47
+
10
48
  ## [0.2.0] - 2015-03-25
11
49
  ### Added
12
50
 
data/CONTRIBUTORS.md CHANGED
@@ -7,10 +7,9 @@ of Ruby Magic. They are hereby acknowledged and collectively identified as "The
7
7
  Ruby Magic Authors". Copyright is held by the original contributor according to
8
8
  the versioning history; see [LICENSE](LICENSE) file.
9
9
 
10
-
11
- - Mike Dalessio ([@flavorjones](https://github.com/flavorjones))
12
10
  - Igor Victor ([@gogainda](https://github.com/gogainda))
13
11
  - John Hawthorn ([@jhawthorn](https://github.com/jhawthorn))
12
+ - Mike Dalessio ([@flavorjones](https://github.com/flavorjones))
14
13
  - Shinya Maeda ([@dosuken123](https://github.com/dosuken123))
15
14
  - Stan Hu ([@stanhu](https://github.com/stanhu))
16
15
 
data/dependencies.yml CHANGED
@@ -14,80 +14,9 @@ libmagic:
14
14
  #
15
15
  # Using this PGP signature:
16
16
  #
17
- # -----BEGIN PGP PUBLIC KEY BLOCK-----
18
- # mQGiBEg60Q8RBAC89+Oyi+iU1dMftAqXKh9Ml2PDCRk+Q6gwSY2BwmnKrPYvLSx9/YApjDp4
19
- # BzhjaMCiDtDkbVDO3JuLQqUsCUWRJr9UxgfkQPMx3obkgoyCCvUcG5eK9CHeztjz5UK3jOzD
20
- # 939UtupUXs+5z4dK1oAFFEL3sV6m5O4cuHyeWpjLCwCg9LYwmG2wIB65/2619W2kRMShDwkD
21
- # /1KweB5mmXdQCDpzSg02Q4kGOzWmN2Dpv5kvKd9Lj/q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s8+EPXqRYYbdu6ROINhExMkwCgpupi6uEG+b4yo6M+VlcQY7gl2DE=
92
- # =XrDo
93
- # -----END PGP PUBLIC KEY BLOCK-----
17
+ # -----BEGIN PGP SIGNATURE-----
18
+ #
19
+ # iEYEABECAAYFAl7mu3AACgkQcREqsWyzOzppXACgoqokKabq7bwN9aKvd/H/yhF+
20
+ # 9PUAoOPrAtxFkfNUvtqK/trY+v/Gk5JM
21
+ # =tA6a
22
+ # -----END PGP SIGNATURE-----
data/ext/magic/common.h CHANGED
@@ -87,11 +87,13 @@ extern "C" {
87
87
  #define ARRAY_P(x) (RB_TYPE_P((x), T_ARRAY))
88
88
  #define FILE_P(x) (RB_TYPE_P((x), T_FILE))
89
89
 
90
- #define RVAL2CBOOL(x) (RTEST(x))
91
- #define CBOOL2RVAL(x) ((x) ? Qtrue : Qfalse)
90
+ #define RVAL2CBOOL(b) (RTEST(b))
91
+ #define CBOOL2RVAL(b) ((b) ? Qtrue : Qfalse)
92
92
 
93
- #define RVAL2CSTR(x) (NIL_P(x) ? NULL : StringValueCStr(x))
94
- #define CSTR2RVAL(x) ((x) == NULL ? Qnil : rb_str_new2(x))
93
+ #define RVAL2CSTR(s) (NIL_P(s) ? NULL : StringValueCStr(s))
94
+ #define CSTR2RVAL(s) ((s) == NULL ? Qnil : rb_str_new2((const char *)s))
95
+
96
+ #define RSTRING_EMPTY_P(s) (RSTRING_LEN(s) == 0)
95
97
 
96
98
  #define RARRAY_EMPTY rb_ary_new()
97
99
  #define RARRAY_EMPTY_P(a) (RARRAY_LEN(a) == 0)
@@ -126,7 +128,7 @@ extern "C" {
126
128
  # define FPTR_TO_FD(p) (fileno(GetReadFile(p)))
127
129
  #endif /* GetReadFile */
128
130
 
129
- #define NOGVL_FUNCTION (VALUE (*)(void *))
131
+ #define NOGVL_FUNCTION (VALUE(*)(void *))
130
132
 
131
133
  #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL) && \
132
134
  defined(HAVE_RUBY_THREAD_H) && HAVE_RUBY_THREAD_H
@@ -151,8 +153,10 @@ fake_blocking_region(VALUE (*f)(ANYARGS), void *data)
151
153
  }
152
154
  # define NOGVL(f, d) \
153
155
  fake_blocking_region(NOGVL_FUNCTION(f), (d))
154
- #endif /* HAVE_RB_THREAD_CALL_WITHOUT_GVL
155
- HAVE_RUBY_THREAD_H */
156
+ #endif /*
157
+ * HAVE_RB_THREAD_CALL_WITHOUT_GVL
158
+ * HAVE_RUBY_THREAD_H
159
+ */
156
160
 
157
161
  #if defined(__cplusplus)
158
162
  }
data/ext/magic/extconf.rb CHANGED
@@ -9,7 +9,7 @@ PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'
9
9
 
10
10
  # The gem version constraint in the Rakefile is not respected at install time.
11
11
  # Keep this version in sync with the one in the Rakefile !
12
- REQUIRED_MINI_PORTILE_VERSION = "~> 2.5.0"
12
+ REQUIRED_MINI_PORTILE_VERSION = "~> 2.6"
13
13
 
14
14
  MAGIC_HELP_MESSAGE = <<~HELP
15
15
  USAGE: ruby #{$0} [options]
@@ -298,9 +298,21 @@ else
298
298
  if static_p
299
299
  ENV['PKG_CONFIG_PATH'] = "#{libmagic_recipe.path}/lib/pkgconfig"
300
300
  # mkmf appends -- to the first option
301
- $LIBS += " " + pkg_config('libmagic', 'libs --static')
301
+ pkg_config_flags = pkg_config('libmagic', 'libs --static')
302
+
303
+ raise 'Please install the `pkg-config` utility' unless pkg_config_flags
304
+
305
+ $LIBS += " " + pkg_config_flags
302
306
  $LIBS += " " + File.join(libmagic_recipe.path, 'lib', "libmagic.#{$LIBEXT}")
303
307
  end
308
+
309
+ if cross_build_p
310
+ # database files will be packaged up by the cross-compiling callback in the ExtensionTask
311
+ to_path = File.join(PACKAGE_ROOT_DIR, "ext/magic/share")
312
+ FileUtils.rm_rf(to_path, secure: true)
313
+ FileUtils.mkdir(to_path)
314
+ FileUtils.cp_r(Dir[File.join(libmagic_recipe.path, 'share/misc/*.mgc')], to_path)
315
+ end
304
316
  end
305
317
 
306
318
  $CFLAGS += ' -std=c99'
@@ -371,6 +383,13 @@ unless have_header('ruby.h')
371
383
  EOS
372
384
  end
373
385
 
386
+ # these are needed for `rb_thread_call_without_gvl` to be properly detected on some linux systems.
387
+ # specifically, rake-compiler-dock's redhat-based image needs these.
388
+ have_library('pthread')
389
+ have_library('rt')
390
+ have_library('dl')
391
+ have_library('crypt')
392
+
374
393
  have_func('rb_thread_call_without_gvl')
375
394
  have_func('rb_thread_blocking_region')
376
395
 
@@ -4,14 +4,14 @@ extern "C" {
4
4
 
5
5
  #include "functions.h"
6
6
 
7
- int check_fd(int fd);
7
+ static int check_fd(int fd);
8
8
  static int safe_dup(int fd);
9
9
  static int safe_close(int fd);
10
10
  static int safe_cloexec(int fd);
11
- int override_error_output(void *data);
12
- int restore_error_output(void *data);
11
+ static int override_error_output(void *data);
12
+ static int restore_error_output(void *data);
13
13
 
14
- inline int
14
+ static inline int
15
15
  check_fd(int fd)
16
16
  {
17
17
  errno = 0;
@@ -42,6 +42,7 @@ safe_dup(int fd)
42
42
  goto error;
43
43
  }
44
44
  }
45
+
45
46
  if (safe_cloexec(new_fd) < 0) {
46
47
  local_errno = errno;
47
48
  goto error;
@@ -78,6 +79,7 @@ safe_cloexec(int fd)
78
79
  local_errno = errno;
79
80
  goto error;
80
81
  }
82
+
81
83
  if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
82
84
  local_errno = errno;
83
85
  goto error;
@@ -89,18 +91,18 @@ error:
89
91
  return -1;
90
92
  }
91
93
 
92
- int
94
+ static int
93
95
  override_error_output(void *data)
94
96
  {
95
97
  int local_errno;
96
- mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
98
+ int flags = O_WRONLY | O_APPEND;
97
99
  save_t *s = data;
98
100
 
99
101
  #if defined(HAVE_O_CLOEXEC)
100
- mode |= O_CLOEXEC;
102
+ flags |= O_CLOEXEC;
101
103
  #endif
102
104
 
103
- assert(s != NULL && \
105
+ assert(s != NULL &&
104
106
  "Must be a valid pointer to `save_t' type");
105
107
 
106
108
  s->file.old_fd = -1;
@@ -116,7 +118,7 @@ override_error_output(void *data)
116
118
  goto error;
117
119
  }
118
120
 
119
- s->file.new_fd = open("/dev/null", O_WRONLY | O_APPEND, mode);
121
+ s->file.new_fd = open("/dev/null", flags, 0222);
120
122
  if (s->file.new_fd < 0) {
121
123
  local_errno = errno;
122
124
 
@@ -128,10 +130,12 @@ override_error_output(void *data)
128
130
  safe_close(s->file.old_fd);
129
131
  goto error;
130
132
  }
133
+
131
134
  if (safe_cloexec(s->file.new_fd) < 0) {
132
135
  local_errno = errno;
133
136
  goto error;
134
137
  }
138
+
135
139
  if (dup2(s->file.new_fd, fileno(stderr)) < 0) {
136
140
  local_errno = errno;
137
141
  goto error;
@@ -146,13 +150,13 @@ error:
146
150
  return -1;
147
151
  }
148
152
 
149
- int
153
+ static int
150
154
  restore_error_output(void *data)
151
155
  {
152
156
  int local_errno;
153
157
  save_t *s = data;
154
158
 
155
- assert(s != NULL && \
159
+ assert(s != NULL &&
156
160
  "Must be a valid pointer to `save_t' type");
157
161
 
158
162
  if (s->file.old_fd < 0 && s->status != 0)
@@ -278,15 +282,21 @@ inline int
278
282
  magic_load_wrapper(magic_t magic, const char *magic_file, int flags)
279
283
  {
280
284
  int rv;
285
+
281
286
  MAGIC_FUNCTION(magic_load, rv, flags, magic, magic_file);
287
+
282
288
  return rv;
283
289
  }
284
290
 
285
291
  inline int
286
- magic_load_buffers_wrapper(magic_t magic, void **buffers, size_t *sizes, size_t count, int flags)
292
+ magic_load_buffers_wrapper(magic_t magic, void **buffers, size_t *sizes,
293
+ size_t count, int flags)
287
294
  {
288
295
  int rv;
289
- MAGIC_FUNCTION(magic_load_buffers, rv, flags, magic, buffers, sizes, count);
296
+
297
+ MAGIC_FUNCTION(magic_load_buffers, rv, flags, magic, buffers, sizes,
298
+ count);
299
+
290
300
  return rv;
291
301
  }
292
302
 
@@ -294,7 +304,9 @@ inline int
294
304
  magic_compile_wrapper(magic_t magic, const char *magic_file, int flags)
295
305
  {
296
306
  int rv;
307
+
297
308
  MAGIC_FUNCTION(magic_compile, rv, flags, magic, magic_file);
309
+
298
310
  return rv;
299
311
  }
300
312
 
@@ -302,15 +314,19 @@ inline int
302
314
  magic_check_wrapper(magic_t magic, const char *magic_file, int flags)
303
315
  {
304
316
  int rv;
317
+
305
318
  MAGIC_FUNCTION(magic_check, rv, flags, magic, magic_file);
319
+
306
320
  return rv;
307
321
  }
308
322
 
309
323
  inline const char*
310
- magic_file_wrapper(magic_t magic, const char* filename, int flags)
324
+ magic_file_wrapper(magic_t magic, const char *filename, int flags)
311
325
  {
312
326
  const char *cstring;
327
+
313
328
  MAGIC_FUNCTION(magic_file, cstring, flags, magic, filename);
329
+
314
330
  return cstring;
315
331
  }
316
332
 
@@ -318,7 +334,9 @@ inline const char*
318
334
  magic_buffer_wrapper(magic_t magic, const void *buffer, size_t size, int flags)
319
335
  {
320
336
  const char *cstring;
337
+
321
338
  MAGIC_FUNCTION(magic_buffer, cstring, flags, magic, buffer, size);
339
+
322
340
  return cstring;
323
341
  }
324
342
 
@@ -9,7 +9,7 @@ extern "C" {
9
9
 
10
10
  #define MAGIC_FUNCTION(f, r, x, ...) \
11
11
  do { \
12
- if ((x) & MAGIC_DEBUG) \
12
+ if ((x) & (MAGIC_DEBUG | MAGIC_CHECK)) \
13
13
  r = f(__VA_ARGS__); \
14
14
  else { \
15
15
  save_t __##f; \
@@ -17,7 +17,7 @@ extern "C" {
17
17
  r = f(__VA_ARGS__); \
18
18
  restore_error_output(&(__##f)); \
19
19
  } \
20
- } while(0)
20
+ } while (0)
21
21
 
22
22
  typedef struct file_data {
23
23
  fpos_t position;
@@ -33,30 +33,36 @@ typedef struct save {
33
33
  extern magic_t magic_open_wrapper(int flags);
34
34
  extern void magic_close_wrapper(magic_t magic);
35
35
 
36
- extern const char* magic_error_wrapper(magic_t magic);
36
+ extern const char *magic_error_wrapper(magic_t magic);
37
37
  extern int magic_errno_wrapper(magic_t magic);
38
38
 
39
- extern const char* magic_getpath_wrapper(void);
39
+ extern const char *magic_getpath_wrapper(void);
40
40
 
41
- extern int magic_getparam_wrapper(magic_t magic, int parameter, void *value);
41
+ extern int magic_getparam_wrapper(magic_t magic, int parameter,
42
+ void *value);
42
43
  extern int magic_setparam_wrapper(magic_t magic, int parameter,
43
44
  const void *value);
44
45
 
45
46
  extern int magic_getflags_wrapper(magic_t magic);
46
47
  extern int magic_setflags_wrapper(magic_t magic, int flags);
47
48
 
48
- extern int magic_load_wrapper(magic_t magic, const char *magic_file, int flags);
49
+ extern int magic_load_wrapper(magic_t magic, const char *magic_file,
50
+ int flags);
49
51
  extern int magic_load_buffers_wrapper(magic_t magic, void **buffers,
50
- size_t *sizes, size_t count, int flags);
52
+ size_t *sizes, size_t count,
53
+ int flags);
51
54
 
52
- extern int magic_compile_wrapper(magic_t magic, const char *magic_file, int flags);
53
- extern int magic_check_wrapper(magic_t magic, const char *magic_file, int flags);
55
+ extern int magic_compile_wrapper(magic_t magic, const char *magic_file,
56
+ int flags);
57
+ extern int magic_check_wrapper(magic_t magic, const char *magic_file,
58
+ int flags);
54
59
 
55
- extern const char* magic_file_wrapper(magic_t magic, const char *filename,
60
+ extern const char *magic_file_wrapper(magic_t magic, const char *filename,
56
61
  int flags);
57
- extern const char* magic_buffer_wrapper(magic_t magic, const void *buffer,
62
+ extern const char *magic_buffer_wrapper(magic_t magic, const void *buffer,
58
63
  size_t size, int flags);
59
- extern const char* magic_descriptor_wrapper(magic_t magic, int fd, int flags);
64
+ extern const char *magic_descriptor_wrapper(magic_t magic, int fd,
65
+ int flags);
60
66
 
61
67
  extern int magic_version_wrapper(void);
62
68