Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- UV: fixed compiling issue on linux

- UV: fixed timer.
  • Loading branch information...
commit d7745f8f26bc003b487aa68ad8ed88f19667da2c 1 parent 3864304
Tokuhiro Matsuno authored
3  .gitmodules
View
@@ -0,0 +1,3 @@
+[submodule "vendor/libuv"]
+ path = vendor/libuv
+ url = git://github.com/joyent/libuv.git
10 ext/UV/SConstruct
View
@@ -9,12 +9,13 @@ conf = json.loads(open('../../config.json').read())
if os.name == 'nt':
libs = conf['LIBS'] + ['uv', 'psapi', 'iphlpapi', 'pthread']
else:
- libs = conf['LIBS']
+ libs = conf['LIBS'] + ['m', 'rt', 'pthread']
env = Environment(
CXXFLAGS=conf['CXXFLAGS'],
CCFLAGS=conf['CCFLAGS'],
LINKFLAGS=conf['LINKFLAGS'],
+ CPPPATH=conf['CPPPATH']+['../../vendor/libuv/include/'],
CC=conf['CC'],
CXX=conf['CXX'],
SHLIBPREFIX=conf['SHLIBPREFIX'],
@@ -22,7 +23,12 @@ env = Environment(
tools=conf['TOOLS'],
)
-shlib = env.SharedLibrary("lib/UV_" + conf['TORA_EXTSUFFIX'], ['uv.cc'], SHLIBPREFIX='', LIBPATH=['../..'], LIBS=libs)
+# see http://stackoverflow.com/questions/2246399/scons-to-make-a-shared-library-so-with-a-static-libarary-a
+env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME']=1
+
+libuv = env.Command('../../vendor/libuv/uv' + env.get('LIBSUFFIX'), [], 'cd ../../vendor/libuv/ && make CFLAGS+=-fPIC');
+
+shlib = env.SharedLibrary("lib/UV_" + conf['TORA_EXTSUFFIX'], ['uv.cc', libuv], SHLIBPREFIX='', LIBPATH=['../..'], LIBS=libs)
Default(shlib)
env.Command('test', shlib, '../../bin/tora -I lib -I ../../lib/ t/uv.tra')
7 ext/UV/eg/timer.tra
View
@@ -0,0 +1,7 @@
+use UV;
+
+my $timer = UV::Timer.new;
+$timer.start(sub () {
+ say("timer!");
+}, 1, 1);
+UV.run();
18 ext/UV/uv.cc
View
@@ -23,7 +23,7 @@ struct _uv_data {
};
static SharedPtr<Value> _uv_default_loop(VM * vm, Value* self) {
- return new ObjectValue(vm, vm->symbol_table->get_id("UV::Loop"), new IntValue((int) uv_default_loop()));
+ return new ObjectValue(vm, vm->symbol_table->get_id("UV::Loop"), new PointerValue(uv_default_loop()));
}
static SharedPtr<Value> _uv_run(VM * vm, Value* self) {
@@ -58,12 +58,13 @@ static SharedPtr<Value> _uv_timer_new(VM * vm, const std::vector<SharedPtr<Value
if (args.size() == 1) {
loop = uv_default_loop();
} else {
+ // uv.cc:61:48: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
loop = (uv_loop_t*) args.at(2)->to_int();
}
uv_timer_t* timer = new uv_timer_t;
if (uv_timer_init(loop, timer) == 0) {
timer->data = new _uv_data(vm, loop, NULL);
- return new ObjectValue(vm, vm->symbol_table->get_id("UV::Timer"), new IntValue((int) timer));
+ return new ObjectValue(vm, vm->symbol_table->get_id("UV::Timer"), new PointerValue(timer));
} else {
delete timer;
throw new ExceptionValue(uv_strerror(uv_last_error(loop)));
@@ -71,15 +72,16 @@ static SharedPtr<Value> _uv_timer_new(VM * vm, const std::vector<SharedPtr<Value
}
void __uv_timer_cb(uv_timer_t* timer, int status) {
- ((_uv_data*) timer->data)->vm->VM::function_call_ex(
- 1, ((_uv_data*) timer->data)->callback, new IntValue(status));
+ VM *vm = ((_uv_data*) timer->data)->vm;
+ vm->function_call_ex(
+ 0, ((_uv_data*) timer->data)->callback, new IntValue(status));
}
static SharedPtr<Value> _uv_timer_start(VM * vm, Value* self, Value* callback_v, Value* timeout_v, Value* repeat_v) {
assert(self->value_type == VALUE_TYPE_OBJECT);
SharedPtr<Value> timer_ = self->upcast<ObjectValue>()->data();
- assert(timer_->value_type == VALUE_TYPE_INT);
- uv_timer_t *timer = (uv_timer_t*) timer_->upcast<IntValue>()->int_value();
+ assert(timer_->value_type == VALUE_TYPE_POINTER);
+ uv_timer_t *timer = (uv_timer_t*) timer_->upcast<PointerValue>()->ptr();
assert(callback_v->value_type == VALUE_TYPE_CODE);
((_uv_data*) timer->data)->callback = callback_v->upcast<CodeValue>();
@@ -88,7 +90,7 @@ static SharedPtr<Value> _uv_timer_start(VM * vm, Value* self, Value* callback_v,
if (uv_timer_start(timer, __uv_timer_cb, timeout_v->to_int(), repeat_v->to_int()) != 0) {
throw new ExceptionValue(uv_strerror(uv_last_error(((_uv_data*) timer->data)->loop)));
}
- return NULL;
+ return UndefValue::instance();
}
static SharedPtr<Value> _uv_timer_DESTROY(VM *vm, Value *self) {
@@ -99,7 +101,7 @@ static SharedPtr<Value> _uv_timer_DESTROY(VM *vm, Value *self) {
uv_close((uv_handle_t*) timer, NULL);
if (timer->data) delete ((_uv_data*) timer->data);
delete timer;
- return NULL;
+ return UndefValue::instance();
}
extern "C" {
1  vendor/libuv
@@ -0,0 +1 @@
+Subproject commit f09f7bc6a8b64585cd74d1fca712c6d0cab2f737
Please sign in to comment.
Something went wrong with that request. Please try again.