Skip to content

Commit

Permalink
Merge pull request #29 from seanchas116/update-libqmlbind
Browse files Browse the repository at this point in the history
Update libqmlbind
  • Loading branch information
seanchas116 committed Apr 5, 2016
2 parents 43e1887 + f7ba07a commit 2bd3754
Show file tree
Hide file tree
Showing 22 changed files with 140 additions and 134 deletions.
8 changes: 4 additions & 4 deletions ext/qml/application.c
Expand Up @@ -4,7 +4,7 @@
VALUE rbqml_cApplication = Qnil;

typedef struct {
qmlbind_application application;
qmlbind_application *application;
} application_t;

static void application_free(void *p) {
Expand All @@ -19,7 +19,7 @@ static const rb_data_type_t data_type = {
{ NULL, &application_free }
};

qmlbind_application rbqml_get_application(VALUE self) {
qmlbind_application *rbqml_get_application(VALUE self) {
application_t *data;
TypedData_Get_Struct(self, application_t, &data_type, data);
return data->application;
Expand All @@ -46,7 +46,7 @@ static VALUE application_initialize(VALUE self, VALUE args) {
args = rb_ary_concat(rb_ary_new_from_args(1, rb_argv0), args);

int argc = RARRAY_LEN(args);
char **argv = malloc(argc * sizeof(char *));
const char **argv = malloc(argc * sizeof(char *));

for (int i = 0; i < argc; ++i) {
VALUE arg = RARRAY_AREF(args, i);
Expand All @@ -63,7 +63,7 @@ static VALUE application_initialize(VALUE self, VALUE args) {
* This method never returns until the application quits.
*/
static VALUE application_exec(VALUE self) {
qmlbind_application app = rbqml_get_application(self);
qmlbind_application *app = rbqml_get_application(self);
int ret = (int)rb_thread_call_without_gvl((void *(*)(void *))&qmlbind_application_exec, app, RUBY_UBF_IO, NULL);
return INT2NUM(ret);
}
Expand Down
2 changes: 1 addition & 1 deletion ext/qml/application.h
Expand Up @@ -4,6 +4,6 @@

extern VALUE rbqml_cApplication;

qmlbind_application rbqml_get_application(VALUE self);
qmlbind_application *rbqml_get_application(VALUE self);

void rbqml_init_application(void);
14 changes: 7 additions & 7 deletions ext/qml/component.c
Expand Up @@ -6,7 +6,7 @@
VALUE rbqml_cComponent;

typedef struct {
qmlbind_component component;
qmlbind_component *component;
} component_t;

static void component_free(void *p) {
Expand All @@ -20,7 +20,7 @@ static const rb_data_type_t data_type = {
{ NULL, &component_free }
};

qmlbind_component rbqml_get_component(VALUE self) {
qmlbind_component *rbqml_get_component(VALUE self) {
component_t *data;
TypedData_Get_Struct(self, component_t, &data_type, data);
return data->component;
Expand All @@ -41,22 +41,22 @@ static VALUE component_initialize(VALUE self) {
}

static VALUE component_load_path(VALUE self, VALUE path) {
qmlbind_component component = rbqml_get_component(self);
qmlbind_component *component = rbqml_get_component(self);
qmlbind_component_load_path(component, rb_string_value_cstr(&path));

return self;
}

static VALUE component_load_data(VALUE self, VALUE data, VALUE path) {
qmlbind_component component = rbqml_get_component(self);
qmlbind_component *component = rbqml_get_component(self);
qmlbind_component_set_data(component, rb_string_value_cstr(&data), rb_string_value_cstr(&path));

return self;
}

static VALUE component_error_string(VALUE self) {
qmlbind_component component = rbqml_get_component(self);
qmlbind_string error = qmlbind_component_get_error_string(component);
qmlbind_component *component = rbqml_get_component(self);
qmlbind_string *error = qmlbind_component_get_error_string(component);
if (error) {
VALUE str = rb_enc_str_new(qmlbind_string_get_chars(error), qmlbind_string_get_length(error), rb_utf8_encoding());
qmlbind_string_release(error);
Expand All @@ -70,7 +70,7 @@ static VALUE component_create(VALUE self) {
component_t *data;
TypedData_Get_Struct(self, component_t, &data_type, data);

qmlbind_value obj = rb_thread_call_without_gvl((void *(*)(void *))&qmlbind_component_create, data->component, RUBY_UBF_IO, NULL);
qmlbind_value *obj = rb_thread_call_without_gvl((void *(*)(void *))&qmlbind_component_create, data->component, RUBY_UBF_IO, NULL);
VALUE result = rbqml_to_ruby(obj);
qmlbind_value_release(obj);

Expand Down
2 changes: 1 addition & 1 deletion ext/qml/component.h
Expand Up @@ -5,6 +5,6 @@

extern VALUE rbqml_cComponent;

qmlbind_component rbqml_get_component(VALUE value);
qmlbind_component *rbqml_get_component(VALUE value);

void rbqml_init_component(void);
12 changes: 7 additions & 5 deletions ext/qml/conversion.c
Expand Up @@ -5,7 +5,7 @@
#include "js_function.h"
#include "js_wrapper.h"

VALUE rbqml_to_ruby(qmlbind_value value)
VALUE rbqml_to_ruby(const qmlbind_value *value)
{
if (qmlbind_value_is_undefined(value) || qmlbind_value_is_null(value)) {
return Qnil;
Expand All @@ -18,8 +18,10 @@ VALUE rbqml_to_ruby(qmlbind_value value)
return rb_float_new(num);
}
if (qmlbind_value_is_string(value)) {
qmlbind_string str = qmlbind_value_get_string(value);
return rb_enc_str_new(qmlbind_string_get_chars(str), qmlbind_string_get_length(str), rb_utf8_encoding());
qmlbind_string *str = qmlbind_value_get_string(value);
VALUE ruby_str = rb_enc_str_new(qmlbind_string_get_chars(str), qmlbind_string_get_length(str), rb_utf8_encoding());
qmlbind_string_release(str);
return ruby_str;
}

VALUE klass;
Expand All @@ -34,10 +36,10 @@ VALUE rbqml_to_ruby(qmlbind_value value)
klass = rbqml_cJSObject;
}

return rbqml_js_object_new(klass, value);
return rbqml_js_object_new(klass, qmlbind_value_clone(value));
}

qmlbind_value rbqml_to_qml(VALUE value)
qmlbind_value *rbqml_to_qml(VALUE value)
{
value = rb_funcall(value, rb_intern("to_qml"), 0);

Expand Down
4 changes: 2 additions & 2 deletions ext/qml/conversion.h
Expand Up @@ -4,5 +4,5 @@
#include <qmlbind.h>
#include <stdbool.h>

VALUE rbqml_to_ruby(qmlbind_value value);
qmlbind_value rbqml_to_qml(VALUE value);
VALUE rbqml_to_ruby(const qmlbind_value *value);
qmlbind_value *rbqml_to_qml(VALUE value);
22 changes: 11 additions & 11 deletions ext/qml/engine.c
Expand Up @@ -7,7 +7,7 @@
VALUE rbqml_cEngine;

typedef struct {
qmlbind_engine engine;
qmlbind_engine *engine;
} engine_t;

static void engine_free(void *p) {
Expand All @@ -22,7 +22,7 @@ static const rb_data_type_t data_type = {
{ NULL, &engine_free }
};

qmlbind_engine rbqml_get_engine(VALUE self) {
qmlbind_engine *rbqml_get_engine(VALUE self) {
engine_t *data;
TypedData_Get_Struct(self, engine_t, &data_type, data);
return data->engine;
Expand All @@ -47,14 +47,14 @@ static VALUE engine_initialize(VALUE self) {
* @see http://doc.qt.io/qt-5/qtqml-syntax-imports.html#qml-import-path
*/
static VALUE engine_add_import_path(VALUE self, VALUE path) {
qmlbind_engine engine = rbqml_get_engine(self);
qmlbind_engine *engine = rbqml_get_engine(self);
path = rb_funcall(path, rb_intern("to_s"), 0);
qmlbind_engine_add_import_path(engine, rb_string_value_cstr(&path));
return self;
}

typedef struct {
qmlbind_engine engine;
qmlbind_engine *engine;
const char *str;
const char *file;
int lineNum;
Expand All @@ -66,15 +66,15 @@ static void *evaluate_impl(void *p) {
}

static VALUE engine_evaluate(VALUE self, VALUE str, VALUE file, VALUE lineNum) {
qmlbind_engine engine = rbqml_get_engine(self);
qmlbind_engine *engine = rbqml_get_engine(self);

evaluate_data data;
data.engine = engine;
data.str = rb_string_value_cstr(&str);
data.file = rb_string_value_cstr(&file);
data.lineNum = NUM2INT(lineNum);

qmlbind_value value = rb_thread_call_without_gvl(&evaluate_impl, &data, RUBY_UBF_IO, NULL);
qmlbind_value *value = rb_thread_call_without_gvl(&evaluate_impl, &data, RUBY_UBF_IO, NULL);

VALUE result = rbqml_to_ruby(value);
qmlbind_value_release(value);
Expand All @@ -87,9 +87,9 @@ static VALUE engine_evaluate(VALUE self, VALUE str, VALUE file, VALUE lineNum) {
* @return [QML::JSArray]
*/
static VALUE engine_new_array(VALUE self, VALUE len) {
qmlbind_engine engine = rbqml_get_engine(self);
qmlbind_engine *engine = rbqml_get_engine(self);

qmlbind_value array = qmlbind_engine_new_array(engine, NUM2INT(len));
qmlbind_value *array = qmlbind_engine_new_array(engine, NUM2INT(len));
VALUE value = rbqml_js_object_new(rbqml_cJSArray, array);
qmlbind_value_release(array);

Expand All @@ -100,9 +100,9 @@ static VALUE engine_new_array(VALUE self, VALUE len) {
* @return [QML::JSObject]
*/
static VALUE engine_new_object(VALUE self) {
qmlbind_engine engine = rbqml_get_engine(self);
qmlbind_engine *engine = rbqml_get_engine(self);

qmlbind_value obj = qmlbind_engine_new_object(engine);
qmlbind_value *obj = qmlbind_engine_new_object(engine);
VALUE value = rbqml_js_object_new(rbqml_cJSObject, obj);
qmlbind_value_release(obj);

Expand All @@ -113,7 +113,7 @@ static VALUE engine_new_object(VALUE self) {
* Starts garbage collection on the {Engine}.
*/
static VALUE engine_collect_garbage(VALUE self) {
qmlbind_engine engine = rbqml_get_engine(self);
qmlbind_engine *engine = rbqml_get_engine(self);
qmlbind_engine_collect_garbage(engine);
return self;
}
Expand Down
2 changes: 1 addition & 1 deletion ext/qml/engine.h
Expand Up @@ -5,6 +5,6 @@

extern VALUE rbqml_cEngine;

qmlbind_engine rbqml_get_engine(VALUE value);
qmlbind_engine *rbqml_get_engine(VALUE value);

void rbqml_init_engine(void);
16 changes: 8 additions & 8 deletions ext/qml/exporter.c
Expand Up @@ -10,7 +10,7 @@ VALUE rbqml_cExporter;


typedef struct {
qmlbind_exporter exporter;
qmlbind_exporter *exporter;
} exporter;

static void exporter_free(void *p) {
Expand All @@ -25,7 +25,7 @@ static const rb_data_type_t data_type = {
{ NULL, &exporter_free }
};

qmlbind_exporter rbqml_get_exporter(VALUE self) {
qmlbind_exporter *rbqml_get_exporter(VALUE self) {
exporter *data;
TypedData_Get_Struct(self, exporter, &data_type, data);
return data->exporter;
Expand All @@ -42,19 +42,19 @@ static VALUE exporter_alloc(VALUE klass) {
static VALUE exporter_initialize(VALUE self, VALUE klass, VALUE name) {
exporter *data;
TypedData_Get_Struct(self, exporter, &data_type, data);
data->exporter = qmlbind_exporter_new((qmlbind_backref)klass, rb_string_value_cstr(&name), rbqml_get_interface());
data->exporter = qmlbind_exporter_new((qmlbind_backref *)klass, rb_string_value_cstr(&name), rbqml_get_interface());

return self;
}

static VALUE exporter_add_method(VALUE self, VALUE name, VALUE arity) {
qmlbind_exporter exporter = rbqml_get_exporter(self);
qmlbind_exporter *exporter = rbqml_get_exporter(self);
qmlbind_exporter_add_method(exporter, rb_id2name(SYM2ID(name)), NUM2INT(arity));
return Qnil;
}

static VALUE exporter_add_signal(VALUE self, VALUE name, VALUE params) {
qmlbind_exporter exporter = rbqml_get_exporter(self);
qmlbind_exporter *exporter = rbqml_get_exporter(self);

int arity = RARRAY_LEN(params);

Expand All @@ -68,14 +68,14 @@ static VALUE exporter_add_signal(VALUE self, VALUE name, VALUE params) {
}

static VALUE exporter_add_property(VALUE self, VALUE name, VALUE notifier) {
qmlbind_exporter exporter = rbqml_get_exporter(self);
qmlbind_exporter *exporter = rbqml_get_exporter(self);
qmlbind_exporter_add_property(exporter, rb_id2name(SYM2ID(name)), rb_id2name(SYM2ID(notifier)));
return Qnil;
}

static VALUE exporter_to_metaobject(VALUE self) {
qmlbind_exporter exporter = rbqml_get_exporter(self);
qmlbind_metaobject metaobj = qmlbind_metaobject_new(exporter);
qmlbind_exporter *exporter = rbqml_get_exporter(self);
qmlbind_metaobject *metaobj = qmlbind_metaobject_new(exporter);
return rbqml_metaobject_new(metaobj);
}

Expand Down

0 comments on commit 2bd3754

Please sign in to comment.