gemstone_ruby 0.1.2
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.
- data/.gitignore +20 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/Rakefile +8 -0
- data/bin/gemstone_ruby +3 -0
- data/bin/libgcirpc-3.1.0.4-64.dylib +0 -0
- data/bin/libssl-3.1.0.4-64.dylib +0 -0
- data/gemstone_ruby.gemspec +19 -0
- data/lib/gemstone_ruby.rb +2 -0
- data/lib/gemstone_ruby/base.rb +134 -0
- data/lib/gemstone_ruby/version.rb +3 -0
- data/test/test_gemstone_ruby.rb +69 -0
- metadata +78 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 GemTalk Systems, LLC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/gemstone_ruby
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "gemstone_ruby/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'gemstone_ruby'
|
7
|
+
s.version = GemStone::VERSION
|
8
|
+
s.summary = "GemStone/S FFI"
|
9
|
+
s.description = "FFI for GemStone/S 64 Bit 3.1.0.4"
|
10
|
+
s.authors = ["James Foster"]
|
11
|
+
s.email = 'github@jgfoster.net'
|
12
|
+
s.homepage = 'https://github.com/jgfoster/gemstone_ruby'
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.license = 'MIT'
|
18
|
+
s.add_runtime_dependency "ffi", [">= 1.9.0"]
|
19
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
|
2
|
+
require 'ffi' # Foreign Function Interface
|
3
|
+
|
4
|
+
module GemStone
|
5
|
+
extend FFI::Library
|
6
|
+
gciVersion = "3.1.0.4"
|
7
|
+
ffi_lib [
|
8
|
+
"gcirpc-#{ gciVersion }-64", # this must be in LD_LIBRARY_PATH
|
9
|
+
File.expand_path("../../../bin/libgcirpc-#{ gciVersion }-64.so", __FILE__),
|
10
|
+
File.expand_path("../../../bin/libgcirpc-#{ gciVersion }-64.dylib", __FILE__)
|
11
|
+
]
|
12
|
+
|
13
|
+
OOP_NIL = 20
|
14
|
+
OOP_CLASS_STRING = 74753
|
15
|
+
|
16
|
+
typedef :uint64, :OopType
|
17
|
+
typedef :int32, :GciSessionIdType
|
18
|
+
|
19
|
+
attach_function :GciErr, [:pointer ], :bool
|
20
|
+
attach_function :GciExecuteStr, [:string, :OopType ], :OopType, :blocking => true
|
21
|
+
attach_function :GciFetchChars_, [:OopType, :uint64, :pointer, :uint64 ], :uint64
|
22
|
+
attach_function :GciFetchClass, [:OopType ], :OopType
|
23
|
+
attach_function :GciFetchObjImpl, [:OopType ], :uint8
|
24
|
+
attach_function :GciFetchSize_, [:OopType ], :uint64
|
25
|
+
attach_function :GciGetSessionId, [ ], :GciSessionIdType
|
26
|
+
attach_function :GciHardBreak, [ ], :void
|
27
|
+
attach_function :GciInit, [ ], :bool
|
28
|
+
attach_function :GciLogin, [:string, :string ], :bool, :blocking => true
|
29
|
+
attach_function :GciLogout, [ ], :void
|
30
|
+
attach_function :GciOopToBool, [:OopType ], :bool
|
31
|
+
attach_function :GciOopToChar32, [:OopType ], :uint32
|
32
|
+
attach_function :GciOopToFlt, [:OopType ], :double
|
33
|
+
attach_function :GciOopToI64, [:OopType ], :int64
|
34
|
+
attach_function :GciSetNet, [:string, :string, :string, :string ], :void
|
35
|
+
attach_function :GciSetSessionId, [:GciSessionIdType ], :void
|
36
|
+
attach_function :GciShutdown, [ ], :void
|
37
|
+
attach_function :GciSoftBreak, [ ], :void
|
38
|
+
attach_function :GciVersion, [ ], :string
|
39
|
+
|
40
|
+
def GemStone.login(options={})
|
41
|
+
options[:stone] ||= "gs64stone"
|
42
|
+
options[:gemnet] ||= "!tcp@localhost#netldi:gs64ldi#task!gemnetobject"
|
43
|
+
options[:user] ||= "DataCurator"
|
44
|
+
options[:password] ||= "swordfish"
|
45
|
+
GemStone.GciSetNet(options[:stone], nil, nil, options[:gemnet])
|
46
|
+
if (!GemStone.GciLogin(options[:user], options[:password]))
|
47
|
+
raise GemStone.gciError()[:message]
|
48
|
+
end
|
49
|
+
return GciGetSessionId()
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def GemStone.executeString(string)
|
54
|
+
oopValue = GemStone.GciExecuteStr(string, OOP_NIL)
|
55
|
+
oop = OopType.new(oopValue)
|
56
|
+
if oop.isNil; return nil; end
|
57
|
+
if oop.isTrue; return true; end
|
58
|
+
if oop.isFalse; return false; end
|
59
|
+
if oop.isCharacter; return oop.to_s; end
|
60
|
+
if oop.isSmallDouble; return oop.to_f; end
|
61
|
+
if oop.isSmallInteger; return oop.to_i; end
|
62
|
+
if oop.isString; return oop.to_s; end
|
63
|
+
return oop
|
64
|
+
end
|
65
|
+
|
66
|
+
def GemStone.gciError()
|
67
|
+
gciError = GemStone::GciErrSType.new
|
68
|
+
haveErrorFlag = GemStone.GciErr(gciError)
|
69
|
+
return haveErrorFlag ? gciError : nil
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
class GciErrSType < FFI::Struct
|
74
|
+
layout :category, :OopType,
|
75
|
+
:context, :OopType,
|
76
|
+
:exceptionObj, :OopType,
|
77
|
+
:args, [:OopType, 10],
|
78
|
+
:number, :uint32,
|
79
|
+
:argCount, :uint32,
|
80
|
+
:fatal, :uint8,
|
81
|
+
:message, [:char, 1025],
|
82
|
+
:reason, [:char, 1025]
|
83
|
+
end
|
84
|
+
|
85
|
+
class OopType
|
86
|
+
def initialize(value)
|
87
|
+
@value = value
|
88
|
+
end
|
89
|
+
|
90
|
+
def isBoolean; return isFalse | isTrue; end
|
91
|
+
def isBytes; return GemStone.GciFetchObjImpl(@value) === 1; end
|
92
|
+
def isCharacter; return @value & 255 === 28; end
|
93
|
+
def isFalse; return @value === 12; end
|
94
|
+
def isIllegal; return @value === 2; end
|
95
|
+
def isImmediate; return 0 < @value & 6; end
|
96
|
+
def isNil; return @value === 20; end
|
97
|
+
def isSmallDouble; return @value & 7 === 6; end
|
98
|
+
def isSmallInteger; return @value & 7 === 2; end
|
99
|
+
def isString; return GemStone.GciFetchClass(@value) === OOP_CLASS_STRING; end
|
100
|
+
def isTrue; return @value === 268; end
|
101
|
+
|
102
|
+
def to_f
|
103
|
+
if !isSmallDouble; return nil; end
|
104
|
+
return GemStone.GciOopToFlt(@value)
|
105
|
+
end
|
106
|
+
|
107
|
+
def to_i
|
108
|
+
if !isSmallInteger; return nil; end
|
109
|
+
return GemStone.GciOopToI64(@value)
|
110
|
+
end
|
111
|
+
|
112
|
+
def to_s
|
113
|
+
if isNil; return "nil"; end
|
114
|
+
if isTrue; return "true"; end
|
115
|
+
if isFalse; return "false"; end
|
116
|
+
if isSmallDouble; return to_f.to_s; end
|
117
|
+
if isCharacter
|
118
|
+
return GemStone.GciOopToChar32(@value).chr
|
119
|
+
end
|
120
|
+
if isString
|
121
|
+
expectedSize = GemStone.GciFetchSize_(@value)
|
122
|
+
memory = FFI::MemoryPointer.new(expectedSize + 1)
|
123
|
+
actualSize = GemStone.GciFetchChars_(@value, 1, memory, expectedSize + 1)
|
124
|
+
if (expectedSize != actualSize)
|
125
|
+
raise "expected = #{ expectedSize }; actual = #{ actualSize }"
|
126
|
+
end
|
127
|
+
return memory.get_string(0)
|
128
|
+
end
|
129
|
+
return "OOP(#{ @value.to_s })"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
GemStone.GciInit
|
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
require "gemstone_ruby"
|
3
|
+
require "test/unit"
|
4
|
+
|
5
|
+
class TC_GciLibrary < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_character
|
8
|
+
assert_equal("a", GemStone.executeString("$a"))
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_failLogin
|
12
|
+
assert_equal(1, GemStone.GciGetSessionId());
|
13
|
+
assert(!GemStone.GciLogin("badUser", "swordfish"))
|
14
|
+
assert(!GemStone.GciLogin("DataCurator", "badPassword"))
|
15
|
+
GemStone.GciSetSessionId(1)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_false
|
19
|
+
assert_equal(false, GemStone.executeString("false"))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_hardBreak # this also tests non-blocking
|
23
|
+
Thread.new do
|
24
|
+
sleep 0.01
|
25
|
+
GemStone.GciHardBreak
|
26
|
+
end
|
27
|
+
object = GemStone.executeString("(Delay forSeconds: 1) wait. true")
|
28
|
+
assert_equal(nil, object)
|
29
|
+
gciError = GemStone.gciError()
|
30
|
+
assert_equal(6004, gciError[:number])
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_nil
|
34
|
+
assert_equal(nil, GemStone.executeString("nil"))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_smallDouble
|
38
|
+
assert_equal(2.5, GemStone.executeString("2.5"))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_softBreak # this also tests non-blocking
|
42
|
+
Thread.new do
|
43
|
+
sleep 0.01
|
44
|
+
GemStone.GciSoftBreak
|
45
|
+
end
|
46
|
+
object = GemStone.executeString("(Delay forSeconds: 1) wait. true")
|
47
|
+
assert_equal(nil, object)
|
48
|
+
gciError = GemStone.gciError()
|
49
|
+
assert_equal(6003, gciError[:number])
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_smallInteger
|
53
|
+
assert_equal(5, GemStone.executeString("2 + 3"))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_string
|
57
|
+
assert_equal("720", GemStone.executeString("6 factorial printString"))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_true
|
61
|
+
assert_equal(true, GemStone.executeString("true"))
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_version
|
65
|
+
assert_equal(String, GemStone.GciVersion().class)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
GemStone.login()
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gemstone_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Foster
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: ffi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.9.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.9.0
|
30
|
+
description: FFI for GemStone/S 64 Bit 3.1.0.4
|
31
|
+
email: github@jgfoster.net
|
32
|
+
executables:
|
33
|
+
- gemstone_ruby
|
34
|
+
- libgcirpc-3.1.0.4-64.dylib
|
35
|
+
- libssl-3.1.0.4-64.dylib
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- .gitignore
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/gemstone_ruby
|
45
|
+
- bin/libgcirpc-3.1.0.4-64.dylib
|
46
|
+
- bin/libssl-3.1.0.4-64.dylib
|
47
|
+
- gemstone_ruby.gemspec
|
48
|
+
- lib/gemstone_ruby.rb
|
49
|
+
- lib/gemstone_ruby/base.rb
|
50
|
+
- lib/gemstone_ruby/version.rb
|
51
|
+
- test/test_gemstone_ruby.rb
|
52
|
+
homepage: https://github.com/jgfoster/gemstone_ruby
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.8.23
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: GemStone/S FFI
|
77
|
+
test_files:
|
78
|
+
- test/test_gemstone_ruby.rb
|