staf4ruby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/ext/extconf.rb +14 -3
- data/ext/staf4ruby_ext.c +27 -9
- data/test/test.rb +1 -1
- metadata +2 -2
data/Rakefile
CHANGED
@@ -32,8 +32,8 @@ CLOBBER.include('lib/*.{o,so}')
|
|
32
32
|
|
33
33
|
gem_spec = Gem::Specification.new do |s|
|
34
34
|
s.name=%q{staf4ruby}
|
35
|
-
s.version="0.1.
|
36
|
-
s.date=%q{2014-
|
35
|
+
s.version="0.1.2"
|
36
|
+
s.date=%q{2014-04-29}
|
37
37
|
s.authors=["Alan Somers"]
|
38
38
|
s.email=%q{asomers@gmail.com}
|
39
39
|
s.extensions="ext/extconf.rb"
|
data/ext/extconf.rb
CHANGED
@@ -8,10 +8,21 @@
|
|
8
8
|
|
9
9
|
require 'mkmf'
|
10
10
|
|
11
|
+
# 2.0-only
|
12
|
+
have_header('ruby/thread.h') && have_func('rb_thread_call_without_gvl', 'ruby/thread.h')
|
13
|
+
|
14
|
+
# 1.9-only
|
15
|
+
have_func('rb_thread_blocking_region')
|
16
|
+
|
17
|
+
unless find_header("STAF.h", "/usr/staf/include", "/usr/local/staf/include",
|
18
|
+
"C:/STAF/include")
|
19
|
+
abort "Cannot find STAF.h"
|
20
|
+
end
|
21
|
+
unless find_library('STAF', 'STAFRegister', "/usr/staf/lib",
|
22
|
+
"/usr/local/staf/lib", "C:/STAF/lib")
|
23
|
+
abort "Cannot find libSTAF"
|
24
|
+
end
|
11
25
|
$CFLAGS += " -g3 -O0 -Wall -Werror"
|
12
|
-
$INCFLAGS << " " <<
|
13
|
-
"-I/usr/local/staf/include"
|
14
|
-
$LDFLAGS += " -L/usr/local/staf/lib -lSTAF"
|
15
26
|
|
16
27
|
puts "Using INCFLAGS='#{$INCFLAGS}'"
|
17
28
|
|
data/ext/staf4ruby_ext.c
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* vim: ts=8
|
1
|
+
/* vim: set ts=8 sw=8 noexpandtab */
|
2
2
|
/*****************************************************************************
|
3
3
|
* Copyright (c) 2013 Spectra Logic corp
|
4
4
|
* All rights reserved. This program and the accompanying materials
|
@@ -16,10 +16,30 @@
|
|
16
16
|
#include <stdbool.h>
|
17
17
|
#include <stdlib.h>
|
18
18
|
#include <errno.h>
|
19
|
+
|
20
|
+
#include <ruby.h>
|
21
|
+
|
22
|
+
#ifdef HAVE_RUBY_THREAD_H
|
23
|
+
#include <ruby/thread.h>
|
24
|
+
#endif
|
25
|
+
|
26
|
+
/*
|
27
|
+
* STAF must be included after Ruby to prevent this error on Windows7:
|
28
|
+
* #error "ws2tcpip.h is not compatible with winsock.h. Include winsock2.h
|
29
|
+
* instead"
|
30
|
+
*/
|
19
31
|
#include <STAF.h>
|
20
32
|
#include <STAFString.h>
|
21
33
|
|
22
|
-
#
|
34
|
+
#ifndef HAVE_RB_THREAD_CALL_WITHOUT_GVL
|
35
|
+
#ifdef HAVE_RB_THREAD_BLOCKING_REGION
|
36
|
+
|
37
|
+
/* emulate rb_thread_call_without_gvl with rb_thread_blocking_region */
|
38
|
+
#define rb_thread_call_without_gvl(func, data1, ubf, data2) \
|
39
|
+
rb_thread_blocking_region((rb_blocking_function_t *)func, data1, ubf, data2)
|
40
|
+
|
41
|
+
#endif /* ! HAVE_RB_THREAD_BLOCKING_REGION */
|
42
|
+
#endif /* ! HAVE_RB_THREAD_CALL_WITHOUT_GVL */
|
23
43
|
|
24
44
|
/* Global data */
|
25
45
|
VALUE rb_mStaf;
|
@@ -38,7 +58,7 @@ typedef struct {
|
|
38
58
|
|
39
59
|
/***************************** Private C Methods *****************************/
|
40
60
|
|
41
|
-
static
|
61
|
+
static void*
|
42
62
|
rb_STAFSubmit_blocking(void* data)
|
43
63
|
{
|
44
64
|
staf_submit_args_t* args = (staf_submit_args_t*)data;
|
@@ -46,10 +66,8 @@ rb_STAFSubmit_blocking(void* data)
|
|
46
66
|
*(args->rc) = STAFSubmit2(args->handle, args->syncOption,
|
47
67
|
args->machine, args->service, args->request,
|
48
68
|
args->requestLength, args->result, args->resultLen);
|
49
|
-
if (*(args->result) == NULL)
|
50
|
-
*(args->result) = "";
|
51
69
|
|
52
|
-
return (Qnil);
|
70
|
+
return (void*)(Qnil);
|
53
71
|
}
|
54
72
|
|
55
73
|
static void
|
@@ -127,12 +145,12 @@ rb_STAFSubmit(VALUE rb_self, VALUE rb_handle, VALUE rb_syncOption, VALUE rb_mach
|
|
127
145
|
args.result = &result;
|
128
146
|
args.resultLen = &resultLen;
|
129
147
|
|
130
|
-
|
131
|
-
|
148
|
+
rb_thread_call_without_gvl(rb_STAFSubmit_blocking, (void*) &args,
|
149
|
+
rb_STAFCancel, (void*) NULL);
|
132
150
|
|
133
151
|
rb_result = rb_ary_new3(3, UINT2NUM(rc), rb_str_new(result, resultLen),
|
134
152
|
UINT2NUM(resultLen));
|
135
|
-
if (result != NULL
|
153
|
+
if (result != NULL)
|
136
154
|
STAFFree(args.handle, result);
|
137
155
|
return (rb_result);
|
138
156
|
}
|
data/test/test.rb
CHANGED
@@ -77,7 +77,7 @@ module Staf
|
|
77
77
|
def test_os_name
|
78
78
|
result = @handle.submit("local", "var", "resolve string {STAF/Config/OS/Name}")
|
79
79
|
assert_equal(STAFResult::Ok, result.rc)
|
80
|
-
known_os_names = ["FreeBSD", "Linux"]
|
80
|
+
known_os_names = ["FreeBSD", "Linux", "Win7"]
|
81
81
|
assert known_os_names.include?(result.result)
|
82
82
|
end
|
83
83
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: staf4ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-29 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby interface to the STAF C APIs.
|
15
15
|
email: asomers@gmail.com
|