sqreen-backport 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +3 -0
- data/lib/sqreen-backport.rb +8 -0
- data/lib/sqreen/backport.rb +10 -0
- data/lib/sqreen/backport/clock_gettime.rb +73 -0
- data/lib/sqreen/backport/mutex_owned.rb +26 -0
- data/lib/sqreen/backport/original_name.rb +90 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5eb6c9f010afbe49d2a2eb9b48a6269938d54fef43fe1b06c39c6b138b6dfcc3
|
4
|
+
data.tar.gz: d9fd4fa56b7f8fac04def7cefb9cb72919e2d2337050c9c682728b8e3c85846f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1972d3bab5633ad8ad6f395c9b739f3f19745ba9b5bbfd3487c97175f0143be481267e974594aa3a75aafa141a786d35da7671d0ded731f830e7ef5944f821e6
|
7
|
+
data.tar.gz: 8d3f8aa1cead045afa6421b4b12046cf730e41483a5eafaeabfeda19602bfe12c14b702f9b6aba692294dc96e4351a0efeebadd81723d24d9d7e33596f6ce024
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# typed: ignore
|
2
|
+
|
3
|
+
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
4
|
+
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
5
|
+
|
6
|
+
require 'sqreen/backport'
|
7
|
+
|
8
|
+
module Sqreen::Backport::ClockGettime
|
9
|
+
class << self
|
10
|
+
def supported?
|
11
|
+
Process.respond_to?(:clock_gettime)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
unless supported?
|
16
|
+
require 'ffi'
|
17
|
+
|
18
|
+
class Timespec < FFI::Struct
|
19
|
+
layout :tv_sec => :time_t, :tv_nsec => :long
|
20
|
+
end
|
21
|
+
|
22
|
+
module LibC
|
23
|
+
extend FFI::Library
|
24
|
+
ffi_lib FFI::Library::LIBC
|
25
|
+
|
26
|
+
# TODO: FFI::NotFoundError
|
27
|
+
|
28
|
+
if RUBY_PLATFORM =~ /darwin/
|
29
|
+
attach_function :mach_absolute_time, [], :uint64
|
30
|
+
end
|
31
|
+
|
32
|
+
attach_function :clock_gettime, [:int, :pointer], :int
|
33
|
+
end
|
34
|
+
|
35
|
+
module Constants
|
36
|
+
case RUBY_PLATFORM
|
37
|
+
when /darwin/
|
38
|
+
CLOCK_REALTIME = 0
|
39
|
+
CLOCK_MONOTONIC = 6
|
40
|
+
CLOCK_PROCESS_CPUTIME_ID = 12
|
41
|
+
CLOCK_THERAD_CPUTIME_ID = 16
|
42
|
+
when /linux/
|
43
|
+
CLOCK_REALTIME = 0
|
44
|
+
CLOCK_MONOTONIC = 1
|
45
|
+
CLOCK_PROCESS_CPUTIME_ID = 2
|
46
|
+
CLOCK_THREAD_CPUTIME_ID = 3
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def clock_gettime(clock_id, unit = :float_second)
|
51
|
+
unless unit == :float_second
|
52
|
+
raise "Process.clock_gettime: unsupported unit #{unit.inspect}"
|
53
|
+
end
|
54
|
+
|
55
|
+
t = Sqreen::Backport::ClockGettime::Timespec.new
|
56
|
+
ret = Sqreen::Backport::ClockGettime::LibC.clock_gettime(
|
57
|
+
clock_id,
|
58
|
+
t.pointer,
|
59
|
+
)
|
60
|
+
|
61
|
+
raise SystemCallError, "Errno #{FFI.errno}" if ret == -1
|
62
|
+
|
63
|
+
t[:tv_sec].to_f + t[:tv_nsec].to_f / 1_000_000_000
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
unless Sqreen::Backport::ClockGettime.supported?
|
69
|
+
Process.instance_eval do
|
70
|
+
extend Sqreen::Backport::ClockGettime
|
71
|
+
include Sqreen::Backport::ClockGettime::Constants
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# typed: ignore
|
2
|
+
|
3
|
+
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
4
|
+
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
5
|
+
|
6
|
+
require 'sqreen/backport'
|
7
|
+
|
8
|
+
module Sqreen::Backport::MutexOwned
|
9
|
+
class << self
|
10
|
+
def supported?
|
11
|
+
Mutex.new.respond_to?(:owned?)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def owned?
|
16
|
+
locked? && synchronize { return false }
|
17
|
+
rescue ThreadError
|
18
|
+
return true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
unless Sqreen::Backport::MutexOwned.supported?
|
23
|
+
Mutex.instance_eval do
|
24
|
+
include Sqreen::Backport::MutexOwned
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# typed: ignore
|
2
|
+
|
3
|
+
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
4
|
+
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
5
|
+
|
6
|
+
require 'sqreen/backport'
|
7
|
+
|
8
|
+
module Sqreen::Backport
|
9
|
+
module OriginalName
|
10
|
+
HAS_UNBOUND_METHOD_ORIGINAL_NAME = ::UnboundMethod.instance_methods(false).include?(:original_name)
|
11
|
+
HAS_METHOD_ORIGINAL_NAME = ::Method.instance_methods(false).include?(:original_name)
|
12
|
+
|
13
|
+
def original_name
|
14
|
+
self.class.get_original_name(owner, original_name_key) || self.original_name = name
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def original_name=(name)
|
20
|
+
self.class.set_original_name(owner, original_name_key, name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def original_name_key
|
24
|
+
return hash if is_a?(::UnboundMethod)
|
25
|
+
|
26
|
+
owner.instance_method(name).hash
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
def supported?
|
31
|
+
!::Kernel.const_defined?(:JRUBY_VERSION) &&
|
32
|
+
HAS_UNBOUND_METHOD_ORIGINAL_NAME &&
|
33
|
+
HAS_METHOD_ORIGINAL_NAME
|
34
|
+
end
|
35
|
+
|
36
|
+
def included(klass)
|
37
|
+
klass.extend(ClassMethods)
|
38
|
+
end
|
39
|
+
|
40
|
+
def prepended(klass)
|
41
|
+
klass.extend(ClassMethods)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Store < ::Hash; end
|
46
|
+
|
47
|
+
module ClassMethods
|
48
|
+
def original_names(owner)
|
49
|
+
owner.instance_eval { @__sqreen_backport_original_names ||= Store.new }
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_original_name(owner, key)
|
53
|
+
original_names(owner)[key]
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_original_name(owner, key, name)
|
57
|
+
original_names(owner)[key] ||= name
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class UnboundMethod
|
64
|
+
if Sqreen::Backport::OriginalName::HAS_UNBOUND_METHOD_ORIGINAL_NAME
|
65
|
+
prepend Sqreen::Backport::OriginalName
|
66
|
+
else
|
67
|
+
include Sqreen::Backport::OriginalName
|
68
|
+
end
|
69
|
+
end unless Sqreen::Backport::OriginalName.supported?
|
70
|
+
|
71
|
+
class Method
|
72
|
+
if Sqreen::Backport::OriginalName::HAS_METHOD_ORIGINAL_NAME
|
73
|
+
prepend Sqreen::Backport::OriginalName
|
74
|
+
else
|
75
|
+
include Sqreen::Backport::OriginalName
|
76
|
+
end
|
77
|
+
end unless Sqreen::Backport::OriginalName.supported?
|
78
|
+
|
79
|
+
class Module
|
80
|
+
alias_method(:alias_method_without_original_name, :alias_method)
|
81
|
+
|
82
|
+
def alias_method_with_original_name(newname, oldname)
|
83
|
+
alias_method_without_original_name(newname, oldname).tap do
|
84
|
+
instance_method(newname).send(:original_name=, :"#{oldname}")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
alias_method_with_original_name(:alias_method_without_original_name, :alias_method)
|
89
|
+
alias_method_with_original_name(:alias_method, :alias_method_with_original_name)
|
90
|
+
end unless Sqreen::Backport::OriginalName.supported?
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sqreen-backport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Loic Nageleisen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- CHANGELOG.md
|
20
|
+
- LICENSE
|
21
|
+
- lib/sqreen-backport.rb
|
22
|
+
- lib/sqreen/backport.rb
|
23
|
+
- lib/sqreen/backport/clock_gettime.rb
|
24
|
+
- lib/sqreen/backport/mutex_owned.rb
|
25
|
+
- lib/sqreen/backport/original_name.rb
|
26
|
+
homepage: https://sqreen.com
|
27
|
+
licenses:
|
28
|
+
- Sqreen
|
29
|
+
metadata:
|
30
|
+
source_code_uri: https://github.com/sqreen/ruby-backport
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 1.9.3
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubygems_version: 3.0.3
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Backports to keep supporting old rubies
|
50
|
+
test_files: []
|