crystalruby 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/crystalruby/reactor.rb +14 -11
- data/lib/crystalruby/templates/index.cr +4 -1
- data/lib/crystalruby/version.rb +1 -1
- metadata +10 -5
- data/crystalruby.gemspec +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cccd1a9a08608d1973ec2cca190828d8475652337dbe6ec16b9d7cac1646cdab
|
4
|
+
data.tar.gz: 441bf39c0a3627d6df202c54c3440bb69e47c91473c1974b3caa330e0defa7a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fafb4fecf18aa7e5221642fbb956457987b286d50600f0ced48a91eaf10a4e2ccc83546d2632058b765256fc3510ce17cc5a6aa37455583279fb101a0c56fe70
|
7
|
+
data.tar.gz: 77fdc7ebdd02dab88243aec94eb6e06fc0bf2b65685b2eeb0b0304ad3087903879759823045c4ee07c9453715800237c1a230a1fdc7fb0e8eb2bc3636fb90e18
|
data/CHANGELOG.md
CHANGED
data/lib/crystalruby/reactor.rb
CHANGED
@@ -10,8 +10,10 @@ module CrystalRuby
|
|
10
10
|
module_function
|
11
11
|
|
12
12
|
class SingleThreadViolation < StandardError; end
|
13
|
+
|
13
14
|
class StopReactor < StandardError; end
|
14
15
|
|
16
|
+
@op_count = 0
|
15
17
|
@single_thread_mode = false
|
16
18
|
|
17
19
|
REACTOR_QUEUE = Queue.new
|
@@ -44,7 +46,7 @@ module CrystalRuby
|
|
44
46
|
|
45
47
|
# We memoize callbacks, once per return type
|
46
48
|
CALLBACKS_MAP = Hash.new do |h, rt|
|
47
|
-
h[rt] = FFI::Function.new(:void, [:int, *(rt == :void ? [] : [rt])]) do |tid, ret|
|
49
|
+
h[rt] = FFI::Function.new(:void, [:int, *((rt == :void) ? [] : [rt])]) do |tid, ret|
|
48
50
|
THREAD_MAP[tid][:error] = nil
|
49
51
|
THREAD_MAP[tid][:result] = ret
|
50
52
|
THREAD_MAP[tid][:cond].signal
|
@@ -108,8 +110,8 @@ module CrystalRuby
|
|
108
110
|
@op_count += 1
|
109
111
|
invoke_gc_if_due!(lib)
|
110
112
|
end
|
111
|
-
rescue StopReactor
|
112
|
-
rescue
|
113
|
+
rescue StopReactor
|
114
|
+
rescue => e
|
113
115
|
CrystalRuby.log_error "Error: #{e}"
|
114
116
|
CrystalRuby.log_error e.backtrace
|
115
117
|
end
|
@@ -123,12 +125,13 @@ module CrystalRuby
|
|
123
125
|
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
124
126
|
|
125
127
|
# Initialize state variables if not already set.
|
126
|
-
@last_gc_time
|
127
|
-
@
|
128
|
+
@last_gc_time ||= now
|
129
|
+
@op_count ||= 0
|
130
|
+
@last_gc_op_count ||= @op_count
|
128
131
|
@last_mem_check_time ||= now
|
129
132
|
|
130
133
|
# Calculate differences based on ops and time.
|
131
|
-
ops_since_last_gc
|
134
|
+
ops_since_last_gc = @op_count - @last_gc_op_count
|
132
135
|
time_since_last_gc = now - @last_gc_time
|
133
136
|
|
134
137
|
# Start with our two “cheap” conditions.
|
@@ -136,7 +139,7 @@ module CrystalRuby
|
|
136
139
|
|
137
140
|
if due
|
138
141
|
# Update the baseline values after GC is scheduled.
|
139
|
-
@last_gc_time
|
142
|
+
@last_gc_time = now
|
140
143
|
# If we just did a memory check, use that value; otherwise, fetch one now.
|
141
144
|
@last_gc_op_count = @op_count
|
142
145
|
Types::Allocator.gc_hint_reset!
|
@@ -173,10 +176,10 @@ module CrystalRuby
|
|
173
176
|
tvars[:error] = nil
|
174
177
|
begin
|
175
178
|
tvars[:result] = receiver.send(op_name, *args)
|
176
|
-
rescue StopReactor
|
179
|
+
rescue StopReactor
|
177
180
|
tvars[:cond].signal
|
178
181
|
raise
|
179
|
-
rescue
|
182
|
+
rescue => e
|
180
183
|
tvars[:error] = e
|
181
184
|
end
|
182
185
|
tvars[:cond].signal
|
@@ -191,8 +194,8 @@ module CrystalRuby
|
|
191
194
|
if @single_thread_mode || (Thread.current.object_id == @main_thread_id && op_name != :yield)
|
192
195
|
unless Thread.current.object_id == @main_thread_id
|
193
196
|
raise SingleThreadViolation,
|
194
|
-
|
195
|
-
|
197
|
+
"Single thread mode is enabled, cannot run in multi-threaded mode. " \
|
198
|
+
"Reactor was started from: #{@main_thread_id}, then called from #{Thread.current.object_id}"
|
196
199
|
end
|
197
200
|
invoke_gc_if_due!(lib)
|
198
201
|
return receiver.send(op_name, *args)
|
@@ -25,6 +25,9 @@ module CrystalRuby
|
|
25
25
|
return if self.initialized
|
26
26
|
self.initialized = true
|
27
27
|
argv_ptr = ARGV1.to_unsafe
|
28
|
+
{%% if compare_versions(Crystal::VERSION, "1.16.0") >= 0 %%}
|
29
|
+
Crystal.init_runtime
|
30
|
+
{%% end %%}
|
28
31
|
Crystal.main_user_code(0, pointerof(argv_ptr))
|
29
32
|
self.libname = String.new(libname)
|
30
33
|
GC.init
|
@@ -57,7 +60,7 @@ module CrystalRuby
|
|
57
60
|
self.callbacks.send(callback)
|
58
61
|
end
|
59
62
|
|
60
|
-
def self.synchronize
|
63
|
+
def self.synchronize(&)
|
61
64
|
LibC.pthread_mutex_lock(self.rc_mux)
|
62
65
|
yield
|
63
66
|
LibC.pthread_mutex_unlock(self.rc_mux)
|
data/lib/crystalruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crystalruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wouter Coppieters
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: digest
|
@@ -56,16 +56,22 @@ dependencies:
|
|
56
56
|
name: prism
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.3.0
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.5.0
|
62
65
|
type: :runtime
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
|
-
- - "
|
69
|
+
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
71
|
version: 1.3.0
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.5.0
|
69
75
|
description: Embed Crystal code directly in Ruby.
|
70
76
|
email:
|
71
77
|
- wc@pico.net.nz
|
@@ -82,7 +88,6 @@ files:
|
|
82
88
|
- LICENSE.txt
|
83
89
|
- README.md
|
84
90
|
- Rakefile
|
85
|
-
- crystalruby.gemspec
|
86
91
|
- examples/adder/adder.rb
|
87
92
|
- exe/crystalruby
|
88
93
|
- lib/crystalruby.rb
|
data/crystalruby.gemspec
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/crystalruby/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "crystalruby"
|
7
|
-
spec.version = CrystalRuby::VERSION
|
8
|
-
spec.authors = ["Wouter Coppieters"]
|
9
|
-
spec.email = ["wc@pico.net.nz"]
|
10
|
-
|
11
|
-
spec.summary = "Embed Crystal code directly in Ruby."
|
12
|
-
spec.description = "Embed Crystal code directly in Ruby."
|
13
|
-
spec.homepage = "https://github.com/wouterken/crystalruby"
|
14
|
-
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 2.7.2"
|
16
|
-
|
17
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
-
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
-
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
|
20
|
-
|
21
|
-
# Specify which files should be added to the gem when it is released.
|
22
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files = Dir.chdir(__dir__) do
|
24
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
-
(File.expand_path(f) == __FILE__) ||
|
26
|
-
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
27
|
-
end
|
28
|
-
end
|
29
|
-
spec.bindir = "exe"
|
30
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ["lib"]
|
32
|
-
|
33
|
-
# Uncomment to register a new dependency of your gem
|
34
|
-
# spec.add_dependency "example-gem", "~> 1.0"
|
35
|
-
spec.add_dependency "digest"
|
36
|
-
spec.add_dependency "ffi"
|
37
|
-
spec.add_dependency "fileutils", "~> 1.7"
|
38
|
-
spec.add_dependency "prism", "~> 1.3.0"
|
39
|
-
# For more information and examples about making a new gem, check out our
|
40
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
41
|
-
end
|