Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'iij' of https://github.com/iij/mruby into iij

  • Loading branch information...
commit 9038f40e51dda5f74dc2eeda15c803eef2f1328a 2 parents 173c53d + 5e3a809
@sogabe sogabe authored
View
41 app/mrbdump/README.md
@@ -0,0 +1,41 @@
+mrbdump は mrbc コマンドが出力する .mrb ファイルの内容を可読形式で出力するツールです。
+
+```
+% cat a.rb
+p true
+
+% bin/mrbc a.rb
+
+% ./app/mrbdump/mrbdump.rb a.mrb
+Rite Binary File Identify: RITE
+Rite Binary File Format Version: "00090000"
+Rite Instruction Specification Version: "00090000"
+Rite Compiler Type: "MATZ "
+Rite Compiler Version: "00090000"
+Rite Binary Data Size: 91
+Number of ireps: 1
+Start index: 0
+Reserved: " "
+Header CRC: 0x8914
+irep0:
+ len=91
+ record identifier="S"
+ class or module="C"
+ number of local variable=1
+ number of register variable=3
+ offset of isec block=4
+ header CRC=0x469f
+ class or module name(?)=""
+ ireq lenngth=4
+ OP_LOADSELF R1
+ OP_LOADT R2
+ OP_SEND R1 :0 1
+ OP_STOP
+ ireq CRC=0x36e1
+ pool length=0
+ pool CRC=0x0000
+ syms length=1
+ 000: p
+ syms CRC=0x3241
+dummy record len=0 (must be 0)
+```
View
92 ext/assert.rb
@@ -0,0 +1,92 @@
+$ok_test = 0
+$ko_test = 0
+$kill_test = 0
+$asserts = []
+$test_start = Time.now if Object.const_defined?(:Time)
+
+##
+# Print the assertion in a readable way
+def print_assertion_string(str, iso)
+ print(str)
+ if(iso != '')
+ print(' [')
+ print(iso)
+ print(']')
+ end
+end
+
+##
+# Verify a code block.
+#
+# str : A remark which will be printed in case
+# this assertion fails
+# iso : The ISO reference code of the feature
+# which will be tested by this
+# assertion
+def assert(str = 'Assertion failed', iso = '')
+ begin
+ if(!yield)
+ $asserts.push(['Fail: ', str, iso])
+ $ko_test += 1
+ print('F')
+ else
+ $ok_test += 1
+ print('.')
+ end
+ rescue Exception => e
+ $asserts.push(['Error: ', str, iso, e])
+ $kill_test += 1
+ print('X')
+ end
+end
+
+##
+# Report the test result and print all assertions
+# which were reported broken.
+def report()
+ print "\n"
+ $asserts.each do |err, str, iso, e|
+ print(err);
+ print_assertion_string(str, iso)
+ if e
+ print(" => ")
+ print(e.message)
+ end
+ print("\n")
+ end
+
+ $total_test = $ok_test.+($ko_test)
+ print('Total: ')
+ print($total_test)
+ print("\n")
+
+ print(' OK: ')
+ print($ok_test)
+ print("\n")
+ print(' KO: ')
+ print($ko_test)
+ print("\n")
+ print('Crash: ')
+ print($kill_test)
+ print("\n")
+
+ if Object.const_defined?(:Time)
+ print(' Time: ')
+ print(Time.now - $test_start)
+ print(" seconds\n")
+ end
+end
+
+##
+# Performs fuzzy check for equality on methods returning floats
+# on the basis of the Math::TOLERANCE constant.
+def check_float(a, b)
+ tolerance = Math::TOLERANCE
+ a = a.to_f
+ b = b.to_f
+ if a.finite? and b.finite?
+ (a-b).abs < tolerance
+ else
+ true
+ end
+end
View
13 ext/simple_http_test.rb
@@ -1,6 +1,13 @@
##
# SimpleHttp Test
+begin
+ require 'assert'
+ require 'simple_http'
+rescue
+ # nothing todo.
+end
+
if Object.const_defined?(:SimpleHttp)
SEP = SimpleHttp::SEP
@@ -45,4 +52,10 @@
rep.content_length == nil and
rep['content-type'] == 'text/plain'
end
+
+ report
+
+ if $ko_test > 0 or $kill_test > 0
+ raise "simple_http test failed. (KO:#{$ko_test}, Crash:#{$kill_test})"
+ end
end
View
14 ext/simple_oauth_test.rb
@@ -1,6 +1,15 @@
##
# SimpleOAuth Test
+begin
+ require 'assert'
+ require 'simple_http'
+ require 'simple_uri'
+ require 'simple_oauth'
+rescue
+ # nothing todo.
+end
+
TESTAPI_URL = "http://term.ie/oauth/example/echo_api.php"
CONSUMER_KEY = "key"
CONSUMER_SECRET = "secret"
@@ -34,5 +43,10 @@
response.code == 200
end
+ report
+
+ if $ko_test > 0 or $kill_test > 0
+ raise "simple_oauth test failed. (KO:#{$ko_test}, Crash:#{$kill_test})"
+ end
end
View
13 ext/simple_uri_test.rb
@@ -1,6 +1,13 @@
##
# SimpleURI Test
+begin
+ require 'assert'
+ require 'simple_uri'
+rescue
+ # nothing todo.
+end
+
if Object.const_defined?(:SimpleURI)
assert('SimpleURI') do
@@ -130,4 +137,10 @@
SimpleURI.escape("!@#^&*()=", reg) == "%21%40%23%5E%26%2A%28%29%3D" and
SimpleURI.escape("http://", reg) == "http%3A%2F%2F"
end
+
+ report
+
+ if $ko_test > 0 or $kill_test > 0
+ raise "simple_uri test failed. (KO:#{$ko_test}, Crash:#{$kill_test})"
+ end
end
View
30 ext/test.sh
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-RUBY=../bin/mruby
-#RUBY="ruby -rsocket"
-
-D=`dirname $0`
-
-retval=0
-files="simple_http*.rb simple_uri*.rb simple_oauth*.rb"
-
-assertrb="../test/assert.rb"
-
-cat $assertrb $files - <<EOF | grep -v require | $RUBY
-report
-
-if \$ko_test > 0 or \$kill_test > 0
- exit false
-end
-exit true
-EOF
-retval=$?
-echo
-
-if [ $retval -eq 0 ]; then
- echo "Simple Library test result: OK"
-else
- echo "Simple Library test result: NG"
-fi
-
-exit $retval
View
5 src/ext/digest/digest.c 100755 → 100644
@@ -9,6 +9,7 @@
#if defined(USE_DIGEST_OPENSSL)
#include <openssl/evp.h>
#include <openssl/hmac.h>
+#include <openssl/sha.h>
#elif defined(USE_DIGEST_OSX_COMMONCRYPTO)
#include <CommonCrypto/CommonDigest.h>
#include <CommonCrypto/CommonHMAC.h>
@@ -70,10 +71,10 @@ static void lib_hmac_update(struct mrb_hmac *, unsigned char *, int);
#define HAVE_MD5
#define HAVE_RMD160
#define HAVE_SHA1
-#ifndef OPENSSL_NO_SHA256
+#ifdef SHA256_DIGEST_LENGTH
#define HAVE_SHA256
#endif
-#ifndef OPENSSL_NO_SHA512
+#ifdef SHA512_DIGEST_LENGTH
#define HAVE_SHA384
#define HAVE_SHA512
#endif
View
4 src/ext/errno/errno.c
@@ -82,7 +82,7 @@ mrb_sce_init(mrb_state *mrb, mrb_value self)
if (!no_errno) {
c = e2c_lookup(n);
if (c) {
- mrb_obj_ptr(self)->c = c;
+ mrb_basic(self)->c = c;
str = mrb_str_new2(mrb, strerror(n));
} else {
mrb_iv_set(mrb, self, mrb_intern(mrb, "errno"), mrb_fixnum_value(n));
@@ -160,7 +160,7 @@ mrb_sys_fail(mrb_state *mrb, const char *msg)
snprintf(name, sizeof(name), "E%03d", no);
cl = mrb_define_class_under(mrb, mrb_class_get(mrb, "Errno"), name, sce);
mrb_define_const(mrb, cl, "Errno", mrb_fixnum_value(no));
- mrb_obj_ptr(e)->c = cl;
+ mrb_basic(e)->c = cl;
}
mrb_exc_raise(mrb, e);
}
View
2  src/ext/io/io.c
@@ -1543,7 +1543,7 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass)
return mrb_nil_value();
}
- mrb_obj_ptr(port)->c = mrb_class_ptr(klass);
+ mrb_basic(port)->c = mrb_class_ptr(klass);
/* XXX: NOT SUPPORTED yet */
/*
if (rb_block_given_p()) {
View
10 src/ext/socket/socket.c
@@ -224,7 +224,7 @@ mrb_tcpsocket_open(mrb_state *mrb, mrb_value klass)
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(host, serv, &hints, &res0);
- if (error == -1)
+ if (error != 0)
mrb_raise(mrb, E_RUNTIME_ERROR, "getaddrinfo(2) failed");
res = res0;
@@ -238,7 +238,7 @@ mrb_tcpsocket_open(mrb_state *mrb, mrb_value klass)
memset(&hints, 0, sizeof(hints));
hints.ai_socktype = SOCK_STREAM;
error = getaddrinfo(lhost, lserv, &hints, &lres0);
- if (error == -1) {
+ if (error != 0) {
freeaddrinfo(res0);
close(s);
mrb_raise(mrb, E_RUNTIME_ERROR, "getaddrinfo(2) failed");
@@ -322,7 +322,7 @@ mrb_udpsocket_bind(mrb_state *mrb, mrb_value self)
hints.ai_flags = AI_NUMERICSERV|AI_PASSIVE;
snprintf(portbuf, sizeof(portbuf), "%d", port);
error = getaddrinfo(hostbuf, portbuf, &hints, &res);
- if (error == -1)
+ if (error != 0)
mrb_raise(mrb, E_RUNTIME_ERROR, "getaddrinfo(2) failed");
if (bind(s, res->ai_addr, res->ai_addrlen) == -1) {
freeaddrinfo(res);
@@ -352,7 +352,7 @@ mrb_udpsocket_connect(mrb_state *mrb, mrb_value self)
hints.ai_flags = AI_NUMERICSERV;
snprintf(portbuf, sizeof(portbuf), "%d", port);
error = getaddrinfo(hostbuf, portbuf, &hints, &res);
- if (error == -1)
+ if (error != 0)
mrb_raise(mrb, E_RUNTIME_ERROR, "getaddrinfo(2) failed");
if (connect(s, res->ai_addr, res->ai_addrlen) == -1) {
freeaddrinfo(res);
@@ -384,7 +384,7 @@ mrb_udpsocket_send(mrb_state *mrb, mrb_value self)
memcpy(hostbuf, RSTRING_PTR(host), RSTRING_LEN(host));
hostbuf[RSTRING_LEN(host)] = '\0';
snprintf(portbuf, sizeof(portbuf), "%u", mrb_fixnum(port));
- if (getaddrinfo(hostbuf, portbuf, &hints, &res) == -1)
+ if (getaddrinfo(hostbuf, portbuf, &hints, &res) != 0)
mrb_sys_fail(mrb, "getaddrinfo");
// XXX: try all addresses
n = sendto(s, msg, hlen, flags, res->ai_addr, res->ai_addrlen);
Please sign in to comment.
Something went wrong with that request. Please try again.