hacks 0.0.3 → 0.0.5

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: 9d864adfb10ffe7141efe44a825a6691a50564bb5762a81d0ab970afe264eb34
4
- data.tar.gz: a653799f9f87b99e9d83c893aa793da7f8152dbddabc9be987be45faac2cb527
3
+ metadata.gz: ba3476e1fe18d372391bc6a122ef0d45744f784c135d40faa8cb264e2df3e905
4
+ data.tar.gz: 4c9e1c6d2ed0b1c60a13fe75e03b75774fe1f517c73f5aa2c3e5710f230f9602
5
5
  SHA512:
6
- metadata.gz: 94a16bcccc2be2fe57c52f55e4b8370d1a4a056c42fd8ceeefc7e9d8a8992d0a5ae8021abd0d7a78278c094b56485b61817ba9ae46f3e98a7a6a23b187ce27d8
7
- data.tar.gz: 537c8567c67ccc38f9df2f0e4eacaa5ea1ed7a5ddf3c95990ed9bb619e5db0657905f72cfccf9dd275ec1aaa7105e7edf03f068326c865147706340a6082ebc3
6
+ metadata.gz: 7666b5394fecf21bbc25a3e8d9bfdc1356d5a25f41e8b40984820d29d8b71bde04fb0c3b82d5d9031fd9245b6b440f11400b1e491e66e4834a3ec562f622c4f0
7
+ data.tar.gz: 9cd8b84ee5133710d2cd1328238d2adb046698105dd2cf5e444108e4f3671e66a68c872cd8c4bd268c2e4988d94f97ae92c948e7e85a2c03a2f1046eed9a322f
data/ext/hacks/extconf.rb CHANGED
@@ -3,8 +3,9 @@ require "erb"
3
3
 
4
4
  require File.join File.dirname(__FILE__), "constants.rb"
5
5
  require File.join File.dirname(__FILE__), "structs.rb"
6
+ require File.join File.dirname(__FILE__), "function_pointers.rb"
6
7
 
7
- def make_c constants, structs
8
+ def make_c constants, structs, fps
8
9
  erb_file = File.join File.dirname(__FILE__), "hacks.c.erb"
9
10
  erb = ERB.new(File.binread(erb_file), trim_mode: "-")
10
11
  c = erb.result(binding)
@@ -12,6 +13,12 @@ def make_c constants, structs
12
13
  File.binwrite c_file, c
13
14
  end
14
15
 
15
- make_c Hacks::CONSTANTS.find_all { have_const(_1) }.map { [_1.sub(/^RUBY_/, ''), _1] }, Hacks::STRUCTS
16
+ constants = Hacks::CONSTANTS.find_all {
17
+ have_const(_1)
18
+ }.map {
19
+ [_1.sub(/^RUBY_/, ''), _1]
20
+ }
21
+
22
+ make_c constants, Hacks::STRUCTS, Hacks::FPs
16
23
 
17
24
  create_makefile "hacks"
@@ -0,0 +1,6 @@
1
+ module Hacks
2
+ FPs = %w{
3
+ rb_funcallv
4
+ rb_ary_new
5
+ }
6
+ end
@@ -3,7 +3,7 @@
3
3
  static VALUE
4
4
  hacks_rb_intern_str(VALUE mod, VALUE x)
5
5
  {
6
- return rb_intern_str(x);
6
+ return LONG2NUM(rb_intern_str(x));
7
7
  }
8
8
 
9
9
  static VALUE
@@ -31,6 +31,14 @@ hacks_rb_id2sym(VALUE mod, VALUE x)
31
31
  return rb_id2sym((ID)NUM2INT(x));
32
32
  }
33
33
 
34
+ <%- fps.each do |name| -%>
35
+ static VALUE
36
+ hacks_fp_<%= name %>(VALUE mod)
37
+ {
38
+ return SIZET2NUM((size_t)<%= name %>);
39
+ }
40
+ <%- end -%>
41
+
34
42
  void Init_hacks(void)
35
43
  {
36
44
  VALUE rb_mHacks = rb_define_module("Hacks");
@@ -60,4 +68,9 @@ void Init_hacks(void)
60
68
  rb_define_singleton_method(rb_mHacks, "rb_obj_class", hacks_rb_obj_class, 1);
61
69
  rb_define_singleton_method(rb_mHacks, "rb_gc_writebarrier", hacks_rb_gc_writebarrier, 2);
62
70
  rb_define_singleton_method(rb_mHacks, "rb_intern_str", hacks_rb_intern_str, 1);
71
+
72
+ VALUE rb_mFPs = rb_define_module_under(rb_mHacks, "FunctionPointers");
73
+ <%- fps.each do |name| -%>
74
+ rb_define_singleton_method(rb_mFPs, "<%= name %>", hacks_fp_<%= name %>, 0);
75
+ <%- end -%>
63
76
  }
data/hacks.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "hacks"
5
- s.version = "0.0.3"
5
+ s.version = "0.0.5"
6
6
  s.summary = "Ruby C internals exposed as Ruby"
7
7
  s.description = "These are some hacks I use. This gem exposes some Ruby C internals as Ruby functions and constants"
8
8
  s.authors = ["Aaron Patterson"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hacks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-15 00:00:00.000000000 Z
11
+ date: 2023-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,6 +52,7 @@ files:
52
52
  - Rakefile
53
53
  - ext/hacks/constants.rb
54
54
  - ext/hacks/extconf.rb
55
+ - ext/hacks/function_pointers.rb
55
56
  - ext/hacks/hacks.c.erb
56
57
  - ext/hacks/structs.rb
57
58
  - hacks.gemspec
@@ -60,7 +61,7 @@ homepage: https://github.com/tenderlove/hacks
60
61
  licenses:
61
62
  - Apache-2.0
62
63
  metadata: {}
63
- post_install_message:
64
+ post_install_message:
64
65
  rdoc_options: []
65
66
  require_paths:
66
67
  - lib
@@ -75,8 +76,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  - !ruby/object:Gem::Version
76
77
  version: '0'
77
78
  requirements: []
78
- rubygems_version: 3.5.0.dev
79
- signing_key:
79
+ rubygems_version: 3.0.3.1
80
+ signing_key:
80
81
  specification_version: 4
81
82
  summary: Ruby C internals exposed as Ruby
82
83
  test_files: []