[seed] new style rules based on clang-format
- From: Alan Knowles <alank src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seed] new style rules based on clang-format
- Date: Thu, 11 Feb 2016 01:34:02 +0000 (UTC)
commit bea6140cc0e678244a701c6c9effffefab7095d6
Author: Danilo Cesar Lemes de Paula <danilo cesar collabora co uk>
Date: Wed Feb 3 11:53:09 2016 -0200
new style rules based on clang-format
By using clang-format, we're now able to enforce a single set
of rules for coyding style.
There's no functionality change in this commit.
.clang-format | 9 +
DEVELOPERS | 20 +
libseed/seed-api.c | 496 ++--
libseed/seed-builtins.c | 982 ++++----
libseed/seed-builtins.h | 7 +-
libseed/seed-closure.c | 747 +++---
libseed/seed-closure.h | 83 +-
libseed/seed-debug.h | 54 +-
libseed/seed-engine.c | 2935 +++++++++----------
libseed/seed-engine.h | 60 +-
libseed/seed-exceptions.c | 207 +-
libseed/seed-exceptions.h | 27 +-
libseed/seed-gtype.c | 1658 +++++------
libseed/seed-gtype.h | 2 +-
libseed/seed-importer.c | 1609 +++++------
libseed/seed-importer.h | 7 +-
libseed/seed-module.h | 27 +-
libseed/seed-private.h | 8 +-
libseed/seed-signals.c | 631 ++---
libseed/seed-signals.h | 52 +-
libseed/seed-structs.c | 1181 ++++----
libseed/seed-structs.h | 63 +-
libseed/seed-types.c | 3666 +++++++++++-------------
libseed/seed-types.h | 327 ++-
libseed/seed.h | 823 +++---
modules/DynamicObject/seed-DynamicObject.c | 180 +-
modules/cairo/seed-cairo-enums.c | 231 +-
modules/cairo/seed-cairo-enums.h | 2 +-
modules/cairo/seed-cairo-image-surface.c | 204 +-
modules/cairo/seed-cairo-image-surface.h | 2 +-
modules/cairo/seed-cairo-matrix.c | 401 ++--
modules/cairo/seed-cairo-matrix.h | 13 +-
modules/cairo/seed-cairo-pattern.c | 269 +-
modules/cairo/seed-cairo-pattern.h | 17 +-
modules/cairo/seed-cairo-pdf-surface.c | 166 +-
modules/cairo/seed-cairo-pdf-surface.h | 2 +-
modules/cairo/seed-cairo-surface.c | 569 ++--
modules/cairo/seed-cairo-surface.h | 11 +-
modules/cairo/seed-cairo.c | 2581 +++++++++---------
modules/cairo/seed-cairo.h | 11 +-
modules/canvas/seed-canvas.c | 1505 +++++-----
modules/dbus/dbus-exports.c | 714 +++---
modules/dbus/dbus-exports.h | 6 +-
modules/dbus/dbus-values.c | 1450 +++++-----
modules/dbus/dbus-values.h | 49 +-
modules/dbus/module.c | 1745 ++++++------
modules/dbus/util/dbus-private.h | 53 +-
modules/dbus/util/dbus-proxy.c | 471 ++--
modules/dbus/util/dbus-proxy.h | 95 +-
modules/dbus/util/dbus-signals.c | 747 ++---
modules/dbus/util/dbus.c | 1707 +++++------
modules/dbus/util/dbus.h | 274 +-
modules/dbus/util/log.h | 2 +-
modules/example/seed-example.c | 6 +-
modules/ffi/seed-ffi.c | 825 +++---
modules/gettext/seed-gettext.c | 427 ++--
modules/gjs/system/seed-system.c | 174 +-
modules/gtkbuilder/seed-gtkbuilder.c | 117 +-
modules/libxml/seed-libxml.c | 772 +++---
modules/mpfr/seed-mpfr-arithmetic.c | 817 +++---
modules/mpfr/seed-mpfr-cmp.c | 274 +-
modules/mpfr/seed-mpfr-trig.c | 840 +++---
modules/mpfr/seed-mpfr.c | 952 ++++---
modules/mpfr/seed-mpfr.h | 36 +-
modules/multiprocessing/seed-multiprocessing.c | 271 +-
modules/os/seed-os.c | 1442 +++++-----
modules/readline/seed-readline.c | 216 +-
modules/sandbox/seed-sandbox.c | 167 +-
modules/sqlite/seed-sqlite.c | 285 +-
modules/xorg/seed-xorg.c | 72 +-
src/args.c | 71 +-
src/main.c | 168 +-
tests/c/api-closure.c | 66 +-
tests/c/api-js-signal-from-c.c | 70 +-
tests/c/api-types.c | 205 +-
tests/c/basic.c | 5 +-
tests/c/main.c | 59 +-
tests/c/test-common.h | 14 +-
78 files changed, 18193 insertions(+), 19316 deletions(-)
---
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..bea77f6
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,9 @@
+BasedOnStyle: Mozilla
+IndentWidth: 4
+BinPackParameters: false
+BinPackArguments: true
+AlignAfterOpenBracket: true
+PenaltyBreakBeforeFirstCallParameter: 100
+PointerAlignment: Left
+SpaceAfterCStyleCast: true
+BreakBeforeBinaryOperators: All
diff --git a/DEVELOPERS b/DEVELOPERS
new file mode 100644
index 0000000..e59f621
--- /dev/null
+++ b/DEVELOPERS
@@ -0,0 +1,20 @@
+=== DEVELOPERS ===
+
+==== Coding Style ====
+
+To contribute to seed, the developers needs to be aware of some coding style rules.
+
+It's basically based on the coding style from Mozilla
[https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style] with
+a few differences.
+
+So, tl:dl:
+ * Use four spaces to indent.
+ * Indent after brakets
+ * Pointers always on left of var name, glues to the type.
+
+
+To ease the developer's life, there's a .clang-format to autoformat the source code. Developers are invited
to used that tool
+before submitting a patch.
+
+To use that tool, call:
+ clang-format -i filename.c
diff --git a/libseed/seed-api.c b/libseed/seed-api.c
index 37fa1d1..ed0aaa2 100644
--- a/libseed/seed-api.c
+++ b/libseed/seed-api.c
@@ -34,9 +34,9 @@
*
*/
void
-seed_value_protect (JSContextRef ctx, JSValueRef value)
+seed_value_protect(JSContextRef ctx, JSValueRef value)
{
- JSValueProtect (ctx, value);
+ JSValueProtect(ctx, value);
}
/**
@@ -49,9 +49,9 @@ seed_value_protect (JSContextRef ctx, JSValueRef value)
*
*/
void
-seed_value_unprotect (JSContextRef ctx, JSValueRef value)
+seed_value_unprotect(JSContextRef ctx, JSValueRef value)
{
- JSValueUnprotect (ctx, value);
+ JSValueUnprotect(ctx, value);
}
/**
@@ -69,9 +69,9 @@ seed_value_unprotect (JSContextRef ctx, JSValueRef value)
*
*/
JSGlobalContextRef
-seed_context_create (JSContextGroupRef group, JSClassRef global_class)
+seed_context_create(JSContextGroupRef group, JSClassRef global_class)
{
- return JSGlobalContextCreateInGroup (group, global_class);
+ return JSGlobalContextCreateInGroup(group, global_class);
}
/**
@@ -84,9 +84,9 @@ seed_context_create (JSContextGroupRef group, JSClassRef global_class)
*
*/
JSGlobalContextRef
-seed_context_ref (JSGlobalContextRef ctx)
+seed_context_ref(JSGlobalContextRef ctx)
{
- return JSGlobalContextRetain (ctx);
+ return JSGlobalContextRetain(ctx);
}
/**
@@ -97,9 +97,9 @@ seed_context_ref (JSGlobalContextRef ctx)
*
*/
void
-seed_context_unref (JSGlobalContextRef ctx)
+seed_context_unref(JSGlobalContextRef ctx)
{
- JSGlobalContextRelease (ctx);
+ JSGlobalContextRelease(ctx);
}
/**
@@ -112,9 +112,9 @@ seed_context_unref (JSGlobalContextRef ctx)
*
*/
void
-seed_context_collect (JSGlobalContextRef ctx)
+seed_context_collect(JSGlobalContextRef ctx)
{
- JSGarbageCollect(ctx);
+ JSGarbageCollect(ctx);
}
/**
@@ -128,9 +128,9 @@ seed_context_collect (JSGlobalContextRef ctx)
*
*/
JSObjectRef
-seed_make_object (JSContextRef ctx, JSClassRef class, gpointer private)
+seed_make_object(JSContextRef ctx, JSClassRef class, gpointer private)
{
- return JSObjectMake (ctx, class, private);
+ return JSObjectMake(ctx, class, private);
}
/**
@@ -146,27 +146,30 @@ seed_make_object (JSContextRef ctx, JSClassRef class, gpointer private)
*
*/
void
-seed_object_set_property_at_index (JSContextRef ctx,
- JSObjectRef object,
- gint index,
- JSValueRef value, JSValueRef * exception)
+seed_object_set_property_at_index(JSContextRef ctx,
+ JSObjectRef object,
+ gint index,
+ JSValueRef value,
+ JSValueRef* exception)
{
- JSObjectSetPropertyAtIndex (ctx, object, index, value, exception);
+ JSObjectSetPropertyAtIndex(ctx, object, index, value, exception);
}
JSValueRef
-seed_object_get_property_at_index (JSContextRef ctx,
- JSObjectRef object,
- gint index, JSValueRef * exception)
+seed_object_get_property_at_index(JSContextRef ctx,
+ JSObjectRef object,
+ gint index,
+ JSValueRef* exception)
{
- return JSObjectGetPropertyAtIndex (ctx, object, index, exception);
+ return JSObjectGetPropertyAtIndex(ctx, object, index, exception);
}
/**
* seed_object_call
* @ctx: A #SeedContext.
* @object: A #SeedObject to call.
- * @this: The #SeedObject to use as the 'this' object inside the called function.
+ * @this: The #SeedObject to use as the 'this' object inside the called
+ * function.
* @argument_count: The number of arguments in the @arguments array.
* @arguments: An array (@argument_count long) of #SeedValues to pass in as the
* function's arguments.
@@ -180,14 +183,15 @@ seed_object_get_property_at_index (JSContextRef ctx,
*
*/
JSValueRef
-seed_object_call (JSContextRef ctx,
- JSObjectRef object,
- JSObjectRef this,
- size_t argument_count,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_object_call(JSContextRef ctx,
+ JSObjectRef object,
+ JSObjectRef this,
+ size_t argument_count,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- return JSObjectCallAsFunction (ctx, object, this,
- argument_count, arguments, exception);
+ return JSObjectCallAsFunction(ctx, object, this, argument_count, arguments,
+ exception);
}
/**
@@ -207,28 +211,28 @@ seed_object_call (JSContextRef ctx,
* Return value: The newly created #SeedScript.
*
*/
-SeedScript *
-seed_make_script (JSContextRef ctx,
- const gchar * js,
- const gchar * source_url, gint line_number)
+SeedScript*
+seed_make_script(JSContextRef ctx,
+ const gchar* js,
+ const gchar* source_url,
+ gint line_number)
{
- SeedScript *ret = g_new0 (SeedScript, 1);
+ SeedScript* ret = g_new0(SeedScript, 1);
- if (js)
- ret->script = JSStringCreateWithUTF8CString (js);
- else
- ret->script = JSStringCreateWithUTF8CString ("");
+ if (js)
+ ret->script = JSStringCreateWithUTF8CString(js);
+ else
+ ret->script = JSStringCreateWithUTF8CString("");
- if (source_url)
- {
- ret->source_url = JSStringCreateWithUTF8CString (source_url);
+ if (source_url) {
+ ret->source_url = JSStringCreateWithUTF8CString(source_url);
}
- ret->line_number = line_number;
+ ret->line_number = line_number;
- JSCheckScriptSyntax (ctx, ret->script,
- ret->source_url, ret->line_number, &ret->exception);
+ JSCheckScriptSyntax(ctx, ret->script, ret->source_url, ret->line_number,
+ &ret->exception);
- return ret;
+ return ret;
}
/**
@@ -241,22 +245,21 @@ seed_make_script (JSContextRef ctx,
* Return value: The newly created #SeedScript.
*
*/
-SeedScript *
-seed_script_new_from_file (JSContextRef ctx, gchar * file)
+SeedScript*
+seed_script_new_from_file(JSContextRef ctx, gchar* file)
{
- SeedScript *script;
- GError *e = NULL;
- gchar *contents = NULL;
+ SeedScript* script;
+ GError* e = NULL;
+ gchar* contents = NULL;
- g_file_get_contents (file, &contents, NULL, &e);
- script = seed_make_script (ctx, contents, file, 0);
- if (e)
- {
- seed_make_exception_from_gerror (ctx, &script->exception, e);
- g_error_free (e);
+ g_file_get_contents(file, &contents, NULL, &e);
+ script = seed_make_script(ctx, contents, file, 0);
+ if (e) {
+ seed_make_exception_from_gerror(ctx, &script->exception, e);
+ g_error_free(e);
}
- return script;
+ return script;
}
/**
@@ -271,16 +274,15 @@ seed_script_new_from_file (JSContextRef ctx, gchar * file)
*
*/
JSValueRef
-seed_evaluate (JSContextRef ctx, SeedScript * s, JSObjectRef this)
+seed_evaluate(JSContextRef ctx, SeedScript* s, JSObjectRef this)
{
- JSValueRef ret;
+ JSValueRef ret;
- s->exception = 0;
- ret = JSEvaluateScript (ctx,
- s->script, this, s->source_url,
- s->line_number, &s->exception);
+ s->exception = 0;
+ ret = JSEvaluateScript(ctx, s->script, this, s->source_url, s->line_number,
+ &s->exception);
- return ret;
+ return ret;
}
/**
@@ -296,16 +298,17 @@ seed_evaluate (JSContextRef ctx, SeedScript * s, JSObjectRef this)
*
*/
JSValueRef
-seed_simple_evaluate (JSContextRef ctx,
- const gchar * source, JSValueRef * exception)
+seed_simple_evaluate(JSContextRef ctx,
+ const gchar* source,
+ JSValueRef* exception)
{
- JSValueRef ret;
- JSStringRef script = JSStringCreateWithUTF8CString (source);
+ JSValueRef ret;
+ JSStringRef script = JSStringCreateWithUTF8CString(source);
- ret = JSEvaluateScript (ctx, script, NULL, NULL, 0, exception);
+ ret = JSEvaluateScript(ctx, script, NULL, NULL, 0, exception);
- JSStringRelease (script);
- return ret;
+ JSStringRelease(script);
+ return ret;
}
/**
@@ -318,9 +321,9 @@ seed_simple_evaluate (JSContextRef ctx,
*
*/
JSValueRef
-seed_script_exception (SeedScript * s)
+seed_script_exception(SeedScript* s)
{
- return s->exception;
+ return s->exception;
}
/**
@@ -332,9 +335,9 @@ seed_script_exception (SeedScript * s)
*
*/
gsize
-seed_string_get_maximum_size (JSStringRef string)
+seed_string_get_maximum_size(JSStringRef string)
{
- return JSStringGetMaximumUTF8CStringSize (string);
+ return JSStringGetMaximumUTF8CStringSize(string);
}
/**
@@ -347,10 +350,11 @@ seed_string_get_maximum_size (JSStringRef string)
*
*/
gsize
-seed_string_to_utf8_buffer (JSStringRef string, gchar * buffer,
- size_t buffer_size)
+seed_string_to_utf8_buffer(JSStringRef string,
+ gchar* buffer,
+ size_t buffer_size)
{
- return JSStringGetUTF8CString (string, buffer, buffer_size);
+ return JSStringGetUTF8CString(string, buffer, buffer_size);
}
/**
@@ -362,9 +366,9 @@ seed_string_to_utf8_buffer (JSStringRef string, gchar * buffer,
*
*/
gboolean
-seed_string_is_equal (JSStringRef a, JSStringRef b)
+seed_string_is_equal(JSStringRef a, JSStringRef b)
{
- return JSStringIsEqual (a, b);
+ return JSStringIsEqual(a, b);
}
/**
@@ -378,9 +382,9 @@ seed_string_is_equal (JSStringRef a, JSStringRef b)
*
*/
gboolean
-seed_string_is_equal_utf8 (JSStringRef a, const gchar * b)
+seed_string_is_equal_utf8(JSStringRef a, const gchar* b)
{
- return JSStringIsEqualToUTF8CString (a, b);
+ return JSStringIsEqualToUTF8CString(a, b);
}
/**
@@ -393,9 +397,9 @@ seed_string_is_equal_utf8 (JSStringRef a, const gchar * b)
*
*/
JSStringRef
-seed_string_ref (JSStringRef string)
+seed_string_ref(JSStringRef string)
{
- return JSStringRetain (string);
+ return JSStringRetain(string);
}
/**
@@ -406,19 +410,19 @@ seed_string_ref (JSStringRef string)
*
*/
void
-seed_string_unref (JSStringRef string)
+seed_string_unref(JSStringRef string)
{
- JSStringRelease (string);
+ JSStringRelease(string);
}
void
-seed_script_destroy (SeedScript * s)
+seed_script_destroy(SeedScript* s)
{
- seed_string_unref (s->script);
- if (s->source_url)
- seed_string_unref (s->source_url);
+ seed_string_unref(s->script);
+ if (s->source_url)
+ seed_string_unref(s->source_url);
- g_free (s);
+ g_free(s);
}
// TODO:FIXME: Do we have an external typedef or anything for JSClassDefinition?
@@ -431,9 +435,9 @@ seed_script_destroy (SeedScript * s)
*
*/
JSClassRef
-seed_create_class (JSClassDefinition * def)
+seed_create_class(JSClassDefinition* def)
{
- return JSClassCreate (def);
+ return JSClassCreate(def);
}
/* TODO:FIXME: GtkDoc is choking on JSObjectCallAsConstructorCallback, and
@@ -450,11 +454,11 @@ seed_create_class (JSClassDefinition * def)
*
*/
JSObjectRef
-seed_make_constructor (JSContextRef ctx,
- JSClassRef class,
- JSObjectCallAsConstructorCallback constructor)
+seed_make_constructor(JSContextRef ctx,
+ JSClassRef class,
+ JSObjectCallAsConstructorCallback constructor)
{
- return JSObjectMakeConstructor (ctx, class, constructor);
+ return JSObjectMakeConstructor(ctx, class, constructor);
}
/**
@@ -467,9 +471,9 @@ seed_make_constructor (JSContextRef ctx,
*
*/
gpointer
-seed_object_get_private (JSObjectRef object)
+seed_object_get_private(JSObjectRef object)
{
- return (gpointer) JSObjectGetPrivate (object);
+ return (gpointer) JSObjectGetPrivate(object);
}
/**
@@ -481,9 +485,9 @@ seed_object_get_private (JSObjectRef object)
*
*/
void
-seed_object_set_private (JSObjectRef object, gpointer value)
+seed_object_set_private(JSObjectRef object, gpointer value)
{
- JSObjectSetPrivate (object, value);
+ JSObjectSetPrivate(object, value);
}
/**
@@ -497,9 +501,9 @@ seed_object_set_private (JSObjectRef object, gpointer value)
*
*/
gboolean
-seed_value_is_null (JSContextRef ctx, JSValueRef value)
+seed_value_is_null(JSContextRef ctx, JSValueRef value)
{
- return JSValueIsNull (ctx, value);
+ return JSValueIsNull(ctx, value);
}
/**
@@ -513,9 +517,9 @@ seed_value_is_null (JSContextRef ctx, JSValueRef value)
*
*/
gboolean
-seed_value_is_undefined (JSContextRef ctx, JSValueRef value)
+seed_value_is_undefined(JSContextRef ctx, JSValueRef value)
{
- return JSValueIsUndefined (ctx, value);
+ return JSValueIsUndefined(ctx, value);
}
/**
@@ -529,9 +533,9 @@ seed_value_is_undefined (JSContextRef ctx, JSValueRef value)
*
*/
gboolean
-seed_value_is_object (JSContextRef ctx, JSValueRef value)
+seed_value_is_object(JSContextRef ctx, JSValueRef value)
{
- return !seed_value_is_null (ctx, value) && JSValueIsObject (ctx, value);
+ return !seed_value_is_null(ctx, value) && JSValueIsObject(ctx, value);
}
/**
@@ -546,11 +550,12 @@ seed_value_is_object (JSContextRef ctx, JSValueRef value)
*
*/
gboolean
-seed_value_is_object_of_class (JSContextRef ctx, JSValueRef value,
- JSClassRef klass)
+seed_value_is_object_of_class(JSContextRef ctx,
+ JSValueRef value,
+ JSClassRef klass)
{
- return !seed_value_is_null (ctx, value)
- && JSValueIsObjectOfClass (ctx, value, klass);
+ return !seed_value_is_null(ctx, value)
+ && JSValueIsObjectOfClass(ctx, value, klass);
}
/**
@@ -565,9 +570,9 @@ seed_value_is_object_of_class (JSContextRef ctx, JSValueRef value,
*
*/
gboolean
-seed_value_is_function (JSContextRef ctx, JSObjectRef value)
+seed_value_is_function(JSContextRef ctx, JSObjectRef value)
{
- return seed_value_is_object (ctx, value) && JSObjectIsFunction (ctx, value);
+ return seed_value_is_object(ctx, value) && JSObjectIsFunction(ctx, value);
}
/**
@@ -581,9 +586,9 @@ seed_value_is_function (JSContextRef ctx, JSObjectRef value)
*
*/
gboolean
-seed_value_is_string (JSContextRef ctx, JSValueRef value)
+seed_value_is_string(JSContextRef ctx, JSValueRef value)
{
- return JSValueIsString (ctx, value);
+ return JSValueIsString(ctx, value);
}
/**
@@ -597,9 +602,9 @@ seed_value_is_string (JSContextRef ctx, JSValueRef value)
*
*/
gboolean
-seed_value_is_number (JSContextRef ctx, JSValueRef value)
+seed_value_is_number(JSContextRef ctx, JSValueRef value)
{
- return JSValueIsNumber (ctx, value);
+ return JSValueIsNumber(ctx, value);
}
/**
@@ -611,12 +616,12 @@ seed_value_is_number (JSContextRef ctx, JSValueRef value)
*
*/
void
-seed_engine_set_search_path (SeedEngine * eng, const gchar * path)
+seed_engine_set_search_path(SeedEngine* eng, const gchar* path)
{
- /* this should be null from seed_init unless there's already a path set. */
+ /* this should be null from seed_init unless there's already a path set. */
- g_strfreev (eng->search_path);
- eng->search_path = g_strsplit (path, ":", -1);
+ g_strfreev(eng->search_path);
+ eng->search_path = g_strsplit(path, ":", -1);
}
/**
@@ -629,10 +634,10 @@ seed_engine_set_search_path (SeedEngine * eng, const gchar * path)
* Return value: A null-terminated array of strings containing the paths.
*
*/
-gchar **
-seed_engine_get_search_path (SeedEngine * eng)
+gchar**
+seed_engine_get_search_path(SeedEngine* eng)
{
- return eng->search_path;
+ return eng->search_path;
}
/**
@@ -648,13 +653,13 @@ seed_engine_get_search_path (SeedEngine * eng)
*
*/
void
-seed_signal_connect_full (JSContextRef ctx,
- GObject * object,
- const gchar * signal,
- JSObjectRef function, JSObjectRef user_data)
+seed_signal_connect_full(JSContextRef ctx,
+ GObject* object,
+ const gchar* signal,
+ JSObjectRef function,
+ JSObjectRef user_data)
{
- seed_gobject_signal_connect (ctx, signal, object, function,
- NULL, user_data);
+ seed_gobject_signal_connect(ctx, signal, object, function, NULL, user_data);
}
/**
@@ -670,14 +675,15 @@ seed_signal_connect_full (JSContextRef ctx,
*
*/
void
-seed_signal_connect (JSContextRef ctx,
- GObject * object,
- const gchar * signal, const gchar * script)
+seed_signal_connect(JSContextRef ctx,
+ GObject* object,
+ const gchar* signal,
+ const gchar* script)
{
- JSValueRef func;
+ JSValueRef func;
- func = seed_simple_evaluate (ctx, script, NULL);
- seed_signal_connect_full (ctx, object, signal, (JSObjectRef) func, NULL);
+ func = seed_simple_evaluate(ctx, script, NULL);
+ seed_signal_connect_full(ctx, object, signal, (JSObjectRef) func, NULL);
}
/**
@@ -687,12 +693,11 @@ seed_signal_connect (JSContextRef ctx,
* Return value: The global object for @ctx.
*/
JSObjectRef
-seed_context_get_global_object (JSGlobalContextRef ctx)
+seed_context_get_global_object(JSGlobalContextRef ctx)
{
- return JSContextGetGlobalObject (ctx);
+ return JSContextGetGlobalObject(ctx);
}
-
/**
* seed_make_array:
* @ctx: A valid #SeedContext
@@ -708,11 +713,12 @@ seed_context_get_global_object (JSGlobalContextRef ctx)
*/
JSObjectRef
-seed_make_array (JSContextRef ctx,
- const JSValueRef elements[],
- gsize num_elements, JSValueRef * exception)
+seed_make_array(JSContextRef ctx,
+ const JSValueRef elements[],
+ gsize num_elements,
+ JSValueRef* exception)
{
- return JSObjectMakeArray (ctx, num_elements, elements, exception);
+ return JSObjectMakeArray(ctx, num_elements, elements, exception);
}
/**
@@ -727,9 +733,9 @@ seed_make_array (JSContextRef ctx,
*
*/
JSValueRef
-seed_make_null (JSContextRef ctx)
+seed_make_null(JSContextRef ctx)
{
- return JSValueMakeNull (ctx);
+ return JSValueMakeNull(ctx);
}
/**
@@ -743,9 +749,9 @@ seed_make_null (JSContextRef ctx)
* Return value: A #SeedValue of the 'undefined' type.
*/
JSValueRef
-seed_make_undefined (JSContextRef ctx)
+seed_make_undefined(JSContextRef ctx)
{
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
/**
@@ -756,9 +762,9 @@ seed_make_undefined (JSContextRef ctx)
* Return value: The type of @value
*/
JSType
-seed_value_get_type (JSContextRef ctx, JSValueRef value)
+seed_value_get_type(JSContextRef ctx, JSValueRef value)
{
- return JSValueGetType (ctx, value);
+ return JSValueGetType(ctx, value);
}
/**
@@ -766,34 +772,33 @@ seed_value_get_type (JSContextRef ctx, JSValueRef value)
* @ctx: A valid #SeedContext
* @object: An object from which to copy property names.
*
- * Return value: A %NULL terminated array containing the property names of @object
- */
-gchar **
-seed_object_copy_property_names (JSContextRef ctx, JSObjectRef object)
-{
- JSPropertyNameArrayRef names;
- JSStringRef name;
- guint i, length;
- gsize max_length;
- gchar *c_name;
- gchar **ret;
-
- names = JSObjectCopyPropertyNames (ctx, object);
- length = JSPropertyNameArrayGetCount (names);
- ret = (gchar **) g_malloc ((length + 1) * sizeof (gchar *));
- for (i = 0; i < length; i++)
- {
- name = JSPropertyNameArrayGetNameAtIndex (names, i);
- max_length = JSStringGetMaximumUTF8CStringSize (name);
- c_name = (gchar *) g_malloc (max_length * sizeof (gchar));
- JSStringGetUTF8CString (name, c_name, max_length);
- ret[i] = c_name;
-
+ * Return value: A %NULL terminated array containing the property names of
+ * @object
+ */
+gchar**
+seed_object_copy_property_names(JSContextRef ctx, JSObjectRef object)
+{
+ JSPropertyNameArrayRef names;
+ JSStringRef name;
+ guint i, length;
+ gsize max_length;
+ gchar* c_name;
+ gchar** ret;
+
+ names = JSObjectCopyPropertyNames(ctx, object);
+ length = JSPropertyNameArrayGetCount(names);
+ ret = (gchar**) g_malloc((length + 1) * sizeof(gchar*));
+ for (i = 0; i < length; i++) {
+ name = JSPropertyNameArrayGetNameAtIndex(names, i);
+ max_length = JSStringGetMaximumUTF8CStringSize(name);
+ c_name = (gchar*) g_malloc(max_length * sizeof(gchar));
+ JSStringGetUTF8CString(name, c_name, max_length);
+ ret[i] = c_name;
}
- ret[length] = NULL;
- JSPropertyNameArrayRelease (names);
+ ret[length] = NULL;
+ JSPropertyNameArrayRelease(names);
- return ret;
+ return ret;
}
/**
@@ -804,15 +809,15 @@ seed_object_copy_property_names (JSContextRef ctx, JSObjectRef object)
* Return value: The prototype of @obj.
*/
JSObjectRef
-seed_object_get_prototype (JSContextRef ctx, JSObjectRef obj)
+seed_object_get_prototype(JSContextRef ctx, JSObjectRef obj)
{
- return (JSObjectRef) JSObjectGetPrototype (ctx, obj);
+ return (JSObjectRef) JSObjectGetPrototype(ctx, obj);
}
gboolean
-seed_object_is_of_class (JSContextRef ctx, JSObjectRef obj, JSClassRef class)
+seed_object_is_of_class(JSContextRef ctx, JSObjectRef obj, JSClassRef class)
{
- return JSValueIsObjectOfClass (ctx, obj, class);
+ return JSValueIsObjectOfClass(ctx, obj, class);
}
/**
@@ -827,18 +832,18 @@ seed_object_is_of_class (JSContextRef ctx, JSObjectRef obj, JSClassRef class)
* Return value: A #SeedObject representing the function
*/
JSObjectRef
-seed_make_function (JSContextRef ctx, gpointer func, gchar * name)
+seed_make_function(JSContextRef ctx, gpointer func, gchar* name)
{
- JSObjectRef oref;
- JSStringRef jsname = NULL;
- if (name)
- jsname = JSStringCreateWithUTF8CString (name);
- oref = JSObjectMakeFunctionWithCallback (ctx, NULL, func);
+ JSObjectRef oref;
+ JSStringRef jsname = NULL;
+ if (name)
+ jsname = JSStringCreateWithUTF8CString(name);
+ oref = JSObjectMakeFunctionWithCallback(ctx, NULL, func);
- if (jsname)
- JSStringRelease (jsname);
+ if (jsname)
+ JSStringRelease(jsname);
- return oref;
+ return oref;
}
/**
@@ -847,7 +852,8 @@ seed_make_function (JSContextRef ctx, gpointer func, gchar * name)
* @format: Format string to use.
* @exception: Location to store an exception.
* @values: The values to convert.
- * @Varargs: A %NULL-terminated list of locations to store the results of conversion.
+ * @Varargs: A %NULL-terminated list of locations to store the results of
+ * conversion.
*
* A convenience API for converting multiple values at once, the format string
* is composed of single characters specifying types, for example:
@@ -865,64 +871,57 @@ seed_make_function (JSContextRef ctx, gpointer func, gchar * name)
* Return value: Whether conversion was successful.
*/
gboolean
-seed_value_to_format (JSContextRef ctx,
- const gchar * format,
- JSValueRef * values, JSValueRef * exception, ...)
-{
- va_list argp;
- const gchar *c;
- guint i = 0;
-
- va_start (argp, exception);
-
- for (c = format; *c; c++)
- {
- JSValueRef val = values[i];
- gpointer p = va_arg (argp, gpointer);
-
- if (!val || !p)
- {
- va_end (argp);
- return FALSE;
- }
- switch (*c)
- {
- case 'i':
- {
- *((gint *) p) = seed_value_to_int (ctx, val, exception);
- break;
- }
- case 'u':
- {
- *((guint *) p) = seed_value_to_uint (ctx, val, exception);
- break;
- }
- case 's':
- {
- *((gchar **) p) = seed_value_to_string (ctx, val, exception);
- break;
- }
- case 'f':
- {
- *((gdouble *) p) = seed_value_to_int (ctx, val, exception);
- break;
- }
- case 'o':
- {
- *((GObject **) p) = seed_value_to_object (ctx, val, exception);
- break;
- }
- case 'c':
- {
- *((gchar *) c) = seed_value_to_char (ctx, val, exception);
- break;
- }
- }
- i++;
+seed_value_to_format(JSContextRef ctx,
+ const gchar* format,
+ JSValueRef* values,
+ JSValueRef* exception,
+ ...)
+{
+ va_list argp;
+ const gchar* c;
+ guint i = 0;
+
+ va_start(argp, exception);
+
+ for (c = format; *c; c++) {
+ JSValueRef val = values[i];
+ gpointer p = va_arg(argp, gpointer);
+
+ if (!val || !p) {
+ va_end(argp);
+ return FALSE;
+ }
+ switch (*c) {
+ case 'i': {
+ *((gint*) p) = seed_value_to_int(ctx, val, exception);
+ break;
+ }
+ case 'u': {
+ *((guint*) p) = seed_value_to_uint(ctx, val, exception);
+ break;
+ }
+ case 's': {
+ *((gchar**) p) = seed_value_to_string(ctx, val, exception);
+ break;
+ }
+ case 'f': {
+ *((gdouble*) p) = seed_value_to_int(ctx, val, exception);
+ break;
+ }
+ case 'o': {
+ *((GObject**) p) = seed_value_to_object(ctx, val, exception);
+ break;
+ }
+ case 'c': {
+ *((gchar*) c) = seed_value_to_char(ctx, val, exception);
+ break;
+ }
+ }
+ i++;
}
- va_end (argp);
- return TRUE;
+ va_end(argp);
+ return TRUE;
}
/*************************** CALLBACK DOCUMENTATION **************************/
@@ -934,7 +933,8 @@ seed_value_to_format (JSContextRef ctx,
* @this_object: The #SeedObject representing the "this" object in the caller
* @argument_count: The number of arguments passed into the callback
* @arguments: An array of #SeedValues; the value of the arguments passed in
- * @exception: A reference to a #SeedException; use seed_make_exception() in order
+ * @exception: A reference to a #SeedException; use seed_make_exception() in
+ * order
* to throw a JavaScript exception from the callback.
*
* All native C function callbacks should use the prototype of
diff --git a/libseed/seed-builtins.c b/libseed/seed-builtins.c
index 6821ba6..08caf08 100644
--- a/libseed/seed-builtins.c
+++ b/libseed/seed-builtins.c
@@ -28,636 +28,620 @@ JSValueRef seed_printerr_ref;
JSValueRef seed_log_error_ref;
static JSValueRef
-seed_include (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_include(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSStringRef file_contents, file_name;
+ JSStringRef file_contents, file_name;
+
+ GDir* dir;
+ gchar *import_file, *abs_path;
+ gchar *walk, *buffer = NULL;
+ guint i, len;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.include expected 1 argument, "
+ "got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
+ }
- GDir *dir;
- gchar *import_file, *abs_path;
- gchar *walk, *buffer = NULL;
- guint i, len;
+ import_file = seed_value_to_string(ctx, arguments[0], exception);
- if (argumentCount != 1)
+ /* just try current dir if no path set, or use the absolute path */
+ if (!eng->search_path || g_path_is_absolute(import_file))
+ g_file_get_contents(import_file, &buffer, 0, NULL);
+ else /* A search path is set and path given is not absolute. */
{
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.include expected 1 argument, "
- "got %zd", argumentCount);
- return JSValueMakeNull (ctx);
- }
+ len = g_strv_length(eng->search_path);
+ for (i = 0; i < len; ++i) {
+ dir = g_dir_open(eng->search_path[i], 0, NULL);
- import_file = seed_value_to_string (ctx, arguments[0], exception);
+ if (!dir) /* skip bad path entries */
+ continue;
- /* just try current dir if no path set, or use the absolute path */
- if (!eng->search_path || g_path_is_absolute (import_file))
- g_file_get_contents (import_file, &buffer, 0, NULL);
- else /* A search path is set and path given is not absolute. */
- {
- len = g_strv_length (eng->search_path);
- for (i = 0; i < len; ++i)
- {
- dir = g_dir_open (eng->search_path[i], 0, NULL);
-
- if (!dir) /* skip bad path entries */
- continue;
-
- abs_path =
- g_build_filename (eng->search_path[i], import_file, NULL);
-
- if (g_file_get_contents (abs_path, &buffer, 0, NULL))
- {
- g_free (abs_path);
- g_dir_close (dir);
- break;
- }
-
- g_dir_close (dir);
- g_free (abs_path);
- }
+ abs_path = g_build_filename(eng->search_path[i], import_file, NULL);
+
+ if (g_file_get_contents(abs_path, &buffer, 0, NULL)) {
+ g_free(abs_path);
+ g_dir_close(dir);
+ break;
+ }
+
+ g_dir_close(dir);
+ g_free(abs_path);
+ }
}
- if (!buffer)
- {
- seed_make_exception (ctx, exception, "FileNotFound",
- "File not found: %s", import_file);
+ if (!buffer) {
+ seed_make_exception(ctx, exception, "FileNotFound",
+ "File not found: %s", import_file);
- g_free (import_file);
- g_free (buffer);
- return JSValueMakeNull (ctx);
+ g_free(import_file);
+ g_free(buffer);
+ return JSValueMakeNull(ctx);
}
- walk = buffer;
+ walk = buffer;
- if (*walk == '#')
- {
- while (*walk != '\n')
- walk++;
- walk++;
+ if (*walk == '#') {
+ while (*walk != '\n')
+ walk++;
+ walk++;
}
- walk = g_strdup (walk);
- g_free (buffer);
+ walk = g_strdup(walk);
+ g_free(buffer);
- file_contents = JSStringCreateWithUTF8CString (walk);
- file_name = JSStringCreateWithUTF8CString (import_file);
+ file_contents = JSStringCreateWithUTF8CString(walk);
+ file_name = JSStringCreateWithUTF8CString(import_file);
- JSEvaluateScript (ctx, file_contents, NULL, file_name, 0, exception);
+ JSEvaluateScript(ctx, file_contents, NULL, file_name, 0, exception);
- JSStringRelease (file_contents);
- JSStringRelease (file_name);
- g_free (import_file);
- g_free (walk);
+ JSStringRelease(file_contents);
+ JSStringRelease(file_name);
+ g_free(import_file);
+ g_free(walk);
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
static JSValueRef
-seed_scoped_include (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_scoped_include(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSContextRef nctx;
- JSObjectRef global;
- JSStringRef file_contents, file_name;
- GDir *dir;
- gchar *import_file, *abs_path;
- gchar *walk, *buffer = NULL;
- guint i;
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.include expected 1 argument, "
- "got %zd", argumentCount);
- return JSValueMakeNull (ctx);
+ JSContextRef nctx;
+ JSObjectRef global;
+ JSStringRef file_contents, file_name;
+ GDir* dir;
+ gchar *import_file, *abs_path;
+ gchar *walk, *buffer = NULL;
+ guint i;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.include expected 1 argument, "
+ "got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- import_file = seed_value_to_string (ctx, arguments[0], exception);
+ import_file = seed_value_to_string(ctx, arguments[0], exception);
- /* just try current dir if no path set, or use the absolute path */
- if (!eng->search_path || g_path_is_absolute (import_file))
- g_file_get_contents (import_file, &buffer, 0, NULL);
- else /* A search path is set and path given is not absolute. */
+ /* just try current dir if no path set, or use the absolute path */
+ if (!eng->search_path || g_path_is_absolute(import_file))
+ g_file_get_contents(import_file, &buffer, 0, NULL);
+ else /* A search path is set and path given is not absolute. */
{
- for (i = 0; i < g_strv_length (eng->search_path); ++i)
- {
- dir = g_dir_open (eng->search_path[i], 0, NULL);
+ for (i = 0; i < g_strv_length(eng->search_path); ++i) {
+ dir = g_dir_open(eng->search_path[i], 0, NULL);
- if (!dir) /* skip bad path entries */
- continue;
+ if (!dir) /* skip bad path entries */
+ continue;
- abs_path =
- g_build_filename (eng->search_path[i], import_file, NULL);
+ abs_path = g_build_filename(eng->search_path[i], import_file, NULL);
- if (g_file_get_contents (abs_path, &buffer, 0, NULL))
- {
- g_free (abs_path);
- break;
- }
+ if (g_file_get_contents(abs_path, &buffer, 0, NULL)) {
+ g_free(abs_path);
+ break;
+ }
- g_dir_close (dir);
- g_free (abs_path);
- }
+ g_dir_close(dir);
+ g_free(abs_path);
+ }
}
- if (!buffer)
- {
- seed_make_exception (ctx, exception, "FileNotFound",
- "File not found: %s", import_file);
+ if (!buffer) {
+ seed_make_exception(ctx, exception, "FileNotFound",
+ "File not found: %s", import_file);
- g_free (import_file);
- g_free (buffer);
- return JSValueMakeNull (ctx);
+ g_free(import_file);
+ g_free(buffer);
+ return JSValueMakeNull(ctx);
}
- walk = buffer;
+ walk = buffer;
- if (*walk == '#')
- {
- while (*walk != '\n')
- walk++;
- walk++;
+ if (*walk == '#') {
+ while (*walk != '\n')
+ walk++;
+ walk++;
}
- walk = g_strdup (walk);
- g_free (buffer);
-
- file_contents = JSStringCreateWithUTF8CString (walk);
- file_name = JSStringCreateWithUTF8CString (import_file);
+ walk = g_strdup(walk);
+ g_free(buffer);
+ file_contents = JSStringCreateWithUTF8CString(walk);
+ file_name = JSStringCreateWithUTF8CString(import_file);
- nctx = JSGlobalContextCreateInGroup (context_group, 0);
- seed_prepare_global_context (nctx);
+ nctx = JSGlobalContextCreateInGroup(context_group, 0);
+ seed_prepare_global_context(nctx);
- JSEvaluateScript (nctx, file_contents, NULL, file_name, 0, exception);
+ JSEvaluateScript(nctx, file_contents, NULL, file_name, 0, exception);
- global = JSContextGetGlobalObject (nctx);
+ global = JSContextGetGlobalObject(nctx);
- JSGlobalContextRelease ((JSGlobalContextRef) nctx);
+ JSGlobalContextRelease((JSGlobalContextRef) nctx);
- JSStringRelease (file_contents);
- JSStringRelease (file_name);
- g_free (import_file);
- g_free (walk);
+ JSStringRelease(file_contents);
+ JSStringRelease(file_name);
+ g_free(import_file);
+ g_free(walk);
- return global;
+ return global;
}
static JSValueRef
-seed_print (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_print(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gchar *buf;
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "print expected 1 argument, got %zd",
- argumentCount);
- return JSValueMakeNull (ctx);
+ gchar* buf;
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "print expected 1 argument, got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- buf = seed_value_to_string (ctx, arguments[0], exception);
+ buf = seed_value_to_string(ctx, arguments[0], exception);
- g_print ("%s\n", buf);
- g_free (buf);
+ g_print("%s\n", buf);
+ g_free(buf);
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
static JSValueRef
-seed_log_error (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_log_error(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gchar *buf1;
- gchar *buf2 = NULL;
- if (argumentCount != 1 && argumentCount != 2)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "logError expected 1 or 2 argument, got %zd",
- argumentCount);
- return JSValueMakeNull (ctx);
+ gchar* buf1;
+ gchar* buf2 = NULL;
+ if (argumentCount != 1 && argumentCount != 2) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "logError expected 1 or 2 argument, got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
+ }
+
+ buf1 = seed_value_to_string(ctx, arguments[0], exception);
+ if (argumentCount == 2) {
+ buf2 = seed_value_to_string(ctx, arguments[1], exception);
+ g_print("%s - %s\n", buf1, buf2);
+ } else {
+ g_print("%s\n", buf1);
}
+ g_free(buf1);
+ g_free(buf2);
- buf1 = seed_value_to_string (ctx, arguments[0], exception);
- if (argumentCount == 2) {
- buf2 = seed_value_to_string (ctx, arguments[1], exception);
- g_print ("%s - %s\n", buf1, buf2);
- } else {
- g_print ("%s\n", buf1);
- }
- g_free (buf1);
- g_free (buf2);
-
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
static JSValueRef
-seed_printerr (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef *exception)
+seed_printerr(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gchar *buf;
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "printerr expected 1 argument, got %zd",
- argumentCount);
- return JSValueMakeNull (ctx);
+ gchar* buf;
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "printerr expected 1 argument, got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- buf = seed_value_to_string (ctx, arguments[0], exception);
+ buf = seed_value_to_string(ctx, arguments[0], exception);
- g_printerr ("%s\n", buf);
- g_free (buf);
+ g_printerr("%s\n", buf);
+ g_free(buf);
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
-const gchar *
-seed_g_type_name_to_string (GITypeInfo * type)
+const gchar*
+seed_g_type_name_to_string(GITypeInfo* type)
{
- GITypeTag type_tag = g_type_info_get_tag (type);
+ GITypeTag type_tag = g_type_info_get_tag(type);
- const gchar *type_name;
- GIBaseInfo *interface;
+ const gchar* type_name;
+ GIBaseInfo* interface;
- if (type_tag == GI_TYPE_TAG_INTERFACE)
- {
- interface = g_type_info_get_interface (type);
+ if (type_tag == GI_TYPE_TAG_INTERFACE) {
+ interface = g_type_info_get_interface(type);
- type_name = g_base_info_get_name (interface);
- g_base_info_unref (interface);
- }
- else
- {
- type_name = g_type_tag_to_string (type_tag);
+ type_name = g_base_info_get_name(interface);
+ g_base_info_unref(interface);
+ } else {
+ type_name = g_type_tag_to_string(type_tag);
}
- return type_name;
+ return type_name;
}
static JSValueRef
-seed_introspect (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_introspect(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- // TODO: LEAKY!
-
- GICallableInfo *info;
- JSObjectRef data_obj, args_obj, argument;
- guint i, nargs;
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.introspect expected 1 argument, "
- "got %zd", argumentCount);
- return JSValueMakeNull (ctx);
+ // TODO: LEAKY!
+
+ GICallableInfo* info;
+ JSObjectRef data_obj, args_obj, argument;
+ guint i, nargs;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.introspect expected 1 argument, "
+ "got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- if (!JSValueIsObject (ctx, arguments[0]))
- return JSValueMakeNull (ctx);
- if (!JSValueIsObjectOfClass (ctx, arguments[0], gobject_method_class))
- return JSValueMakeNull (ctx);
-
- info = (GICallableInfo *) JSObjectGetPrivate ((JSObjectRef) arguments[0]);
- data_obj = JSObjectMake (ctx, NULL, NULL);
-
- seed_object_set_property (ctx, data_obj, "name", (JSValueRef)
- seed_value_from_string (ctx, g_base_info_get_name
- ((GIBaseInfo *) info),
- exception));
-
- seed_object_set_property (ctx, data_obj, "return_type",
- seed_value_from_string
- (ctx, seed_g_type_name_to_string
- (g_callable_info_get_return_type (info)),
- exception));
-
- args_obj = JSObjectMake (ctx, NULL, NULL);
-
- seed_object_set_property (ctx, data_obj, "args", args_obj);
-
- nargs = g_callable_info_get_n_args (info);
- for (i = 0; i < nargs; ++i)
- {
- argument = JSObjectMake (ctx, NULL, NULL);
- GIArgInfo* arg_info = g_callable_info_get_arg (info, i);
- const gchar *arg_type = seed_g_type_name_to_string (
- g_arg_info_get_type(arg_info));
- const gchar *arg_name = g_base_info_get_name((GIBaseInfo*) arg_info);
- GIDirection dir = g_arg_info_get_direction (arg_info);
-
-
- seed_object_set_property (ctx, argument, "type",
- seed_value_from_string (ctx,
- arg_type, exception));
- seed_object_set_property (ctx, argument, "name",
- seed_value_from_string (ctx,
- arg_name, exception));
-
- seed_object_set_property (ctx, argument, "allow_none",
- seed_value_from_boolean (ctx,
- g_arg_info_may_be_null (arg_info) ? 1 : 0, exception));
-
-
- seed_object_set_property (ctx, argument, "direction",
- seed_value_from_string (ctx,
- dir == GI_DIRECTION_OUT ? "out" :
- (dir == GI_DIRECTION_IN ? "in" : "inout")
- , exception));
-
- JSObjectSetPropertyAtIndex (ctx, args_obj, i, argument, NULL);
+ if (!JSValueIsObject(ctx, arguments[0]))
+ return JSValueMakeNull(ctx);
+ if (!JSValueIsObjectOfClass(ctx, arguments[0], gobject_method_class))
+ return JSValueMakeNull(ctx);
+
+ info = (GICallableInfo*) JSObjectGetPrivate((JSObjectRef) arguments[0]);
+ data_obj = JSObjectMake(ctx, NULL, NULL);
+
+ seed_object_set_property(ctx, data_obj, "name",
+ (JSValueRef) seed_value_from_string(
+ ctx, g_base_info_get_name((GIBaseInfo*) info),
+ exception));
+
+ seed_object_set_property(
+ ctx, data_obj, "return_type",
+ seed_value_from_string(ctx, seed_g_type_name_to_string(
+ g_callable_info_get_return_type(info)),
+ exception));
+
+ args_obj = JSObjectMake(ctx, NULL, NULL);
+
+ seed_object_set_property(ctx, data_obj, "args", args_obj);
+
+ nargs = g_callable_info_get_n_args(info);
+ for (i = 0; i < nargs; ++i) {
+ argument = JSObjectMake(ctx, NULL, NULL);
+ GIArgInfo* arg_info = g_callable_info_get_arg(info, i);
+ const gchar* arg_type
+ = seed_g_type_name_to_string(g_arg_info_get_type(arg_info));
+ const gchar* arg_name = g_base_info_get_name((GIBaseInfo*) arg_info);
+ GIDirection dir = g_arg_info_get_direction(arg_info);
+
+ seed_object_set_property(ctx, argument, "type",
+ seed_value_from_string(ctx, arg_type,
+ exception));
+ seed_object_set_property(ctx, argument, "name",
+ seed_value_from_string(ctx, arg_name,
+ exception));
+
+ seed_object_set_property(
+ ctx, argument, "allow_none",
+ seed_value_from_boolean(ctx, g_arg_info_may_be_null(arg_info) ? 1 : 0,
+ exception));
+
+ seed_object_set_property(
+ ctx, argument, "direction",
+ seed_value_from_string(ctx,
+ dir == GI_DIRECTION_OUT
+ ? "out"
+ : (dir == GI_DIRECTION_IN ? "in" : "inout"),
+ exception));
+
+ JSObjectSetPropertyAtIndex(ctx, args_obj, i, argument, NULL);
}
- return data_obj;
+ return data_obj;
}
static JSValueRef
-seed_check_syntax (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_check_syntax(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSStringRef jsstr;
- if (argumentCount == 1)
- {
- jsstr = JSValueToStringCopy (ctx, arguments[0], exception);
-
- JSCheckScriptSyntax (ctx, jsstr, 0, 0, exception);
- if (jsstr)
- JSStringRelease (jsstr);
+ JSStringRef jsstr;
+ if (argumentCount == 1) {
+ jsstr = JSValueToStringCopy(ctx, arguments[0], exception);
+
+ JSCheckScriptSyntax(ctx, jsstr, 0, 0, exception);
+ if (jsstr)
+ JSStringRelease(jsstr);
+ } else {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.check_syntax expected "
+ "1 argument, got %zd",
+ argumentCount);
}
- else
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.check_syntax expected "
- "1 argument, got %zd", argumentCount);
- }
- return JSValueMakeNull (ctx);
+ return JSValueMakeNull(ctx);
}
static JSValueRef
-seed_spawn (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_spawn(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gchar *line, *stdoutstr, *stderrstr;
- JSObjectRef ret;
- GError *error = NULL;
-
- if (argumentCount != 1)
- {
- // I am so lazy
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.spawn expected 1 argument");
- return JSValueMakeNull (ctx);
+ gchar *line, *stdoutstr, *stderrstr;
+ JSObjectRef ret;
+ GError* error = NULL;
+
+ if (argumentCount != 1) {
+ // I am so lazy
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.spawn expected 1 argument");
+ return JSValueMakeNull(ctx);
}
- line = seed_value_to_string (ctx, arguments[0], exception);
- g_spawn_command_line_sync (line, &stdoutstr, &stderrstr, NULL, &error);
- if (error)
- {
- seed_make_exception_from_gerror (ctx, exception, error);
+ line = seed_value_to_string(ctx, arguments[0], exception);
+ g_spawn_command_line_sync(line, &stdoutstr, &stderrstr, NULL, &error);
+ if (error) {
+ seed_make_exception_from_gerror(ctx, exception, error);
- g_free (line);
- g_error_free (error);
- return JSValueMakeNull (ctx);
+ g_free(line);
+ g_error_free(error);
+ return JSValueMakeNull(ctx);
}
- ret = JSObjectMake (ctx, NULL, NULL);
- seed_object_set_property (ctx, ret, "stdout",
- seed_value_from_string (ctx, stdoutstr,
- exception));
- seed_object_set_property (ctx, ret, "stderr",
- seed_value_from_string (ctx, stderrstr,
- exception));
+ ret = JSObjectMake(ctx, NULL, NULL);
+ seed_object_set_property(ctx, ret, "stdout",
+ seed_value_from_string(ctx, stdoutstr, exception));
+ seed_object_set_property(ctx, ret, "stderr",
+ seed_value_from_string(ctx, stderrstr, exception));
- g_free (line);
- g_free (stdoutstr);
- g_free (stderrstr);
+ g_free(line);
+ g_free(stdoutstr);
+ g_free(stderrstr);
- return ret;
+ return ret;
}
static JSValueRef
-seed_quit (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_quit(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- if (argumentCount == 1)
- {
- exit (seed_value_to_int (ctx, arguments[0], NULL));
- }
- else if (argumentCount > 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Seed.quit expected " "1 argument, got %zd",
- argumentCount);
+ if (argumentCount == 1) {
+ exit(seed_value_to_int(ctx, arguments[0], NULL));
+ } else if (argumentCount > 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Seed.quit expected "
+ "1 argument, got %zd",
+ argumentCount);
}
- exit (EXIT_SUCCESS);
+ exit(EXIT_SUCCESS);
}
static JSValueRef
-seed_breakpoint (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_breakpoint(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- G_BREAKPOINT ();
- return JSValueMakeUndefined (ctx);
+ G_BREAKPOINT();
+ return JSValueMakeUndefined(ctx);
}
-
static JSValueRef
-seed_argv_get_property (JSContextRef ctx,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_argv_get_property(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- SeedArgvPrivates *priv;
- gchar *cproperty_name;
- gsize length;
- gint index;
-
- priv = JSObjectGetPrivate (object);
- if (!priv->argc)
- return JSValueMakeUndefined (ctx);
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- if (!g_strcmp0 (cproperty_name, "length"))
- {
- return seed_value_from_int (ctx, priv->argc, exception);
+ SeedArgvPrivates* priv;
+ gchar* cproperty_name;
+ gsize length;
+ gint index;
+
+ priv = JSObjectGetPrivate(object);
+ if (!priv->argc)
+ return JSValueMakeUndefined(ctx);
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ if (!g_strcmp0(cproperty_name, "length")) {
+ return seed_value_from_int(ctx, priv->argc, exception);
+ }
+ index = atoi(cproperty_name);
+ if (index >= 0 && index < priv->argc) {
+ return seed_value_from_string(ctx, priv->argv[index], exception);
+ } else {
+ seed_make_exception(ctx, exception, "ArgumentError", "ArgumentCount "
+ "%d, got %d",
+ priv->argc, index);
+ return JSValueMakeNull(ctx);
}
- index = atoi (cproperty_name);
- if (index >= 0 && index < priv->argc) {
- return seed_value_from_string (ctx, priv->argv[index], exception);
- } else {
- seed_make_exception (ctx, exception, "ArgumentError",
- "ArgumentCount "
- "%d, got %d", priv->argc, index);
- return JSValueMakeNull (ctx);
- }
}
JSClassDefinition seed_argv_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
- "argv_array", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL,
- NULL,
- NULL,
- NULL, /* Has Property */
- seed_argv_get_property, /* Get Property */
- NULL,
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
+ "argv_array", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* Has Property */
+ seed_argv_get_property, /* Get Property */
+ NULL,
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassRef seed_argv_class;
static JSValueRef
-seed_ARGV_get_property (JSContextRef ctx,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_ARGV_get_property(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- SeedArgvPrivates *priv;
- gchar *cproperty_name;
- gsize length;
- gint index;
-
- priv = JSObjectGetPrivate (object);
- if (!priv->argc)
- return JSValueMakeUndefined (ctx);
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- if (!g_strcmp0 (cproperty_name, "length"))
- {
- return seed_value_from_int (ctx, priv->argc-2, exception);
+ SeedArgvPrivates* priv;
+ gchar* cproperty_name;
+ gsize length;
+ gint index;
+
+ priv = JSObjectGetPrivate(object);
+ if (!priv->argc)
+ return JSValueMakeUndefined(ctx);
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ if (!g_strcmp0(cproperty_name, "length")) {
+ return seed_value_from_int(ctx, priv->argc - 2, exception);
+ }
+ index = atoi(cproperty_name);
+ if (index >= 0 && index < priv->argc - 2) {
+ return seed_value_from_string(ctx, priv->argv[index + 2], exception);
+ } else {
+ seed_make_exception(ctx, exception, "ArgumentError", "ArgumentCount "
+ "%d, got %d",
+ priv->argc - 2, index);
+ return JSValueMakeNull(ctx);
}
- index = atoi (cproperty_name);
- if (index >= 0 && index < priv->argc-2) {
- return seed_value_from_string (ctx, priv->argv[index+2], exception);
- } else {
- seed_make_exception (ctx, exception, "ArgumentError",
- "ArgumentCount "
- "%d, got %d", priv->argc-2, index);
- return JSValueMakeNull (ctx);
- }
}
JSClassDefinition seed_ARGV_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
- "argv_array", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL,
- NULL,
- NULL,
- NULL, /* Has Property */
- seed_ARGV_get_property, /* Get Property */
- NULL,
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
+ "argv_array", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL,
+ NULL,
+ NULL,
+ NULL, /* Has Property */
+ seed_ARGV_get_property, /* Get Property */
+ NULL,
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassRef seed_ARGV_class;
void
-seed_init_builtins (SeedEngine * local_eng, gint * argc, gchar *** argv)
+seed_init_builtins(SeedEngine* local_eng, gint* argc, gchar*** argv)
{
- SeedArgvPrivates *priv;
- JSObjectRef argvArrayObj;
- JSObjectRef ARGVArrayObj;
- JSObjectRef obj =
- (JSObjectRef) seed_object_get_property (local_eng->context,
- local_eng->global,
- "Seed");
-
- seed_create_function (local_eng->context, "include", &seed_include, obj);
- seed_create_function (local_eng->context, "scoped_include",
- &seed_scoped_include, obj);
-
- seed_print_ref =
- JSObjectMakeFunctionWithCallback (local_eng->context, NULL, &seed_print);
- seed_object_set_property (local_eng->context, obj, "print", seed_print_ref);
- seed_object_set_property (local_eng->context, local_eng->global, "print",
- seed_print_ref);
- seed_object_set_property (local_eng->context, local_eng->global, "log",
- seed_print_ref);
- JSValueProtect (local_eng->context, seed_print_ref);
-
- seed_printerr_ref =
- JSObjectMakeFunctionWithCallback (local_eng->context, NULL, &seed_printerr);
- seed_object_set_property (local_eng->context, obj, "printerr", seed_printerr_ref);
- seed_object_set_property (local_eng->context, local_eng->global, "printerr",
- seed_printerr_ref);
- JSValueProtect (local_eng->context, seed_printerr_ref);
-
- seed_log_error_ref =
- JSObjectMakeFunctionWithCallback (local_eng->context, NULL, &seed_log_error);
- seed_object_set_property (local_eng->context, local_eng->global, "logError",
- seed_log_error_ref);
- JSValueProtect (local_eng->context, seed_log_error_ref);
-
- seed_create_function (local_eng->context,
- "check_syntax", &seed_check_syntax, obj);
- seed_create_function (local_eng->context,
- "introspect", &seed_introspect, obj);
- seed_create_function (local_eng->context, "spawn", &seed_spawn, obj);
- seed_create_function (local_eng->context, "quit", &seed_quit, obj);
- seed_create_function (local_eng->context, "breakpoint",
- &seed_breakpoint, obj);
-
- priv = g_new0 (SeedArgvPrivates, 1);
- priv->argv = argv ? *argv : 0;
- priv->argc = argc ? *argc : 0;
-
- seed_argv_class = JSClassCreate (&seed_argv_def);
- argvArrayObj = JSObjectMake (local_eng->context, seed_argv_class, priv);
-
- seed_object_set_property (local_eng->context, obj, "argv", argvArrayObj);
-
- seed_ARGV_class = JSClassCreate (&seed_ARGV_def);
- ARGVArrayObj = JSObjectMake (local_eng->context, seed_ARGV_class, priv);
-
- seed_object_set_property (local_eng->context, local_eng->global, "ARGV", ARGVArrayObj);
-
+ SeedArgvPrivates* priv;
+ JSObjectRef argvArrayObj;
+ JSObjectRef ARGVArrayObj;
+ JSObjectRef obj
+ = (JSObjectRef) seed_object_get_property(local_eng->context,
+ local_eng->global, "Seed");
+
+ seed_create_function(local_eng->context, "include", &seed_include, obj);
+ seed_create_function(local_eng->context, "scoped_include",
+ &seed_scoped_include, obj);
+
+ seed_print_ref
+ = JSObjectMakeFunctionWithCallback(local_eng->context, NULL, &seed_print);
+ seed_object_set_property(local_eng->context, obj, "print", seed_print_ref);
+ seed_object_set_property(local_eng->context, local_eng->global, "print",
+ seed_print_ref);
+ seed_object_set_property(local_eng->context, local_eng->global, "log",
+ seed_print_ref);
+ JSValueProtect(local_eng->context, seed_print_ref);
+
+ seed_printerr_ref = JSObjectMakeFunctionWithCallback(local_eng->context,
+ NULL, &seed_printerr);
+ seed_object_set_property(local_eng->context, obj, "printerr",
+ seed_printerr_ref);
+ seed_object_set_property(local_eng->context, local_eng->global, "printerr",
+ seed_printerr_ref);
+ JSValueProtect(local_eng->context, seed_printerr_ref);
+
+ seed_log_error_ref
+ = JSObjectMakeFunctionWithCallback(local_eng->context, NULL,
+ &seed_log_error);
+ seed_object_set_property(local_eng->context, local_eng->global, "logError",
+ seed_log_error_ref);
+ JSValueProtect(local_eng->context, seed_log_error_ref);
+
+ seed_create_function(local_eng->context, "check_syntax", &seed_check_syntax,
+ obj);
+ seed_create_function(local_eng->context, "introspect", &seed_introspect,
+ obj);
+ seed_create_function(local_eng->context, "spawn", &seed_spawn, obj);
+ seed_create_function(local_eng->context, "quit", &seed_quit, obj);
+ seed_create_function(local_eng->context, "breakpoint", &seed_breakpoint,
+ obj);
+
+ priv = g_new0(SeedArgvPrivates, 1);
+ priv->argv = argv ? *argv : 0;
+ priv->argc = argc ? *argc : 0;
+
+ seed_argv_class = JSClassCreate(&seed_argv_def);
+ argvArrayObj = JSObjectMake(local_eng->context, seed_argv_class, priv);
+
+ seed_object_set_property(local_eng->context, obj, "argv", argvArrayObj);
+
+ seed_ARGV_class = JSClassCreate(&seed_ARGV_def);
+ ARGVArrayObj = JSObjectMake(local_eng->context, seed_ARGV_class, priv);
+
+ seed_object_set_property(local_eng->context, local_eng->global, "ARGV",
+ ARGVArrayObj);
}
diff --git a/libseed/seed-builtins.h b/libseed/seed-builtins.h
index 762ecc9..4386de4 100644
--- a/libseed/seed-builtins.h
+++ b/libseed/seed-builtins.h
@@ -25,14 +25,13 @@
extern JSValueRef seed_print_ref;
extern JSValueRef seed_printerr_ref;
-void seed_init_builtins (SeedEngine * local_eng, gint * argc, gchar *** argv);
+void seed_init_builtins(SeedEngine* local_eng, gint* argc, gchar*** argv);
extern JSClassRef seed_argv_class;
typedef struct _SeedArgvPrivates
{
- gchar **argv;
- gint argc;
+ gchar** argv;
+ gint argc;
} SeedArgvPrivates;
-
#endif
diff --git a/libseed/seed-closure.c b/libseed/seed-closure.c
index 0205c39..953c720 100644
--- a/libseed/seed-closure.c
+++ b/libseed/seed-closure.c
@@ -24,457 +24,438 @@
JSClassRef seed_native_callback_class;
static void
-seed_closure_finalize (JSObjectRef object)
+seed_closure_finalize(JSObjectRef object)
{
- SeedNativeClosure *privates =
- (SeedNativeClosure *) JSObjectGetPrivate (object);
+ SeedNativeClosure* privates
+ = (SeedNativeClosure*) JSObjectGetPrivate(object);
- SEED_NOTE (FINALIZATION, "Finalizing closure object %p with "
- "GIBaseInfo: %s \n", object,
- g_base_info_get_name ((GIBaseInfo *) privates->info));
+ SEED_NOTE(FINALIZATION, "Finalizing closure object %p with "
+ "GIBaseInfo: %s \n",
+ object, g_base_info_get_name((GIBaseInfo*) privates->info));
- g_free (privates->cif->arg_types);
- g_free (privates->cif);
- g_callable_info_free_closure (privates->info, privates->closure);
- g_base_info_unref ((GIBaseInfo *) privates->info);
+ g_free(privates->cif->arg_types);
+ g_free(privates->cif);
+ g_callable_info_free_closure(privates->info, privates->closure);
+ g_base_info_unref((GIBaseInfo*) privates->info);
}
static void
-seed_handle_closure (ffi_cif * cif, void *result, void **args, gpointer userdata)
+seed_handle_closure(ffi_cif* cif, void* result, void** args, gpointer userdata)
{
- SeedNativeClosure *privates = userdata;
- gint num_args, i;
- JSValueRef *jsargs;
- JSValueRef return_value, exception = 0;
- GITypeTag return_tag;
- GIArgInfo *arg_info;
- GITypeInfo *return_type;
- GITypeInfo *arg_type;
- GITypeTag tag;
- GArgument rarg, return_arg;
- JSContextRef ctx = JSGlobalContextCreateInGroup (
- context_group, 0);
- GArgument *arg = &rarg;
- gchar *mes;
-
- seed_prepare_global_context (ctx);
-
- SEED_NOTE (INVOCATION, "Invoking closure of type: %s \n",
- g_base_info_get_name ((GIBaseInfo *) privates->info));
-
- num_args = g_callable_info_get_n_args (privates->info);
- return_type = g_callable_info_get_return_type (privates->info);
- return_tag = g_type_info_get_tag (return_type);
- jsargs = (JSValueRef *) g_newa (JSValueRef, num_args);
-
- for (i = 0; i < num_args; i++)
- {
-
- arg_info = g_callable_info_get_arg (privates->info, i);
- arg_type = g_arg_info_get_type (arg_info);
- tag = g_type_info_get_tag (arg_type);
-
- switch (tag)
- {
+ SeedNativeClosure* privates = userdata;
+ gint num_args, i;
+ JSValueRef* jsargs;
+ JSValueRef return_value, exception = 0;
+ GITypeTag return_tag;
+ GIArgInfo* arg_info;
+ GITypeInfo* return_type;
+ GITypeInfo* arg_type;
+ GITypeTag tag;
+ GArgument rarg, return_arg;
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
+ GArgument* arg = &rarg;
+ gchar* mes;
+
+ seed_prepare_global_context(ctx);
+
+ SEED_NOTE(INVOCATION, "Invoking closure of type: %s \n",
+ g_base_info_get_name((GIBaseInfo*) privates->info));
+
+ num_args = g_callable_info_get_n_args(privates->info);
+ return_type = g_callable_info_get_return_type(privates->info);
+ return_tag = g_type_info_get_tag(return_type);
+ jsargs = (JSValueRef*) g_newa(JSValueRef, num_args);
+
+ for (i = 0; i < num_args; i++) {
+
+ arg_info = g_callable_info_get_arg(privates->info, i);
+ arg_type = g_arg_info_get_type(arg_info);
+ tag = g_type_info_get_tag(arg_type);
+
+ switch (tag) {
#if GOBJECT_INTROSPECTION_VERSION < 0x000900
- case GI_TYPE_TAG_LONG:
- arg->v_long = *(glong *) args[i];
- break;
- case GI_TYPE_TAG_ULONG:
- arg->v_ulong = *(gulong *) args[i];
- break;
- case GI_TYPE_TAG_INT:
- arg->v_int = *(gint *) args[i];
- break;
- case GI_TYPE_TAG_SSIZE:
- arg->v_ssize = *(gssize *) args[i];
- break;
- case GI_TYPE_TAG_SIZE:
- arg->v_size = *(gsize *) args[i];
- break;
- case GI_TYPE_TAG_UINT:
- arg->v_uint = *(guint *) args[i];
- break;
+ case GI_TYPE_TAG_LONG:
+ arg->v_long = *(glong*) args[i];
+ break;
+ case GI_TYPE_TAG_ULONG:
+ arg->v_ulong = *(gulong*) args[i];
+ break;
+ case GI_TYPE_TAG_INT:
+ arg->v_int = *(gint*) args[i];
+ break;
+ case GI_TYPE_TAG_SSIZE:
+ arg->v_ssize = *(gssize*) args[i];
+ break;
+ case GI_TYPE_TAG_SIZE:
+ arg->v_size = *(gsize*) args[i];
+ break;
+ case GI_TYPE_TAG_UINT:
+ arg->v_uint = *(guint*) args[i];
+ break;
#endif
- case GI_TYPE_TAG_BOOLEAN:
- arg->v_boolean = *(gboolean *) args[i];
- break;
- case GI_TYPE_TAG_INT8:
- arg->v_int8 = *(gint8 *) args[i];
- break;
- case GI_TYPE_TAG_UINT8:
- arg->v_uint8 = *(guint8 *) args[i];
- break;
- case GI_TYPE_TAG_INT16:
- arg->v_int16 = *(gint16 *) args[i];
- break;
- case GI_TYPE_TAG_UINT16:
- arg->v_uint16 = *(guint16 *) args[i];
- break;
- case GI_TYPE_TAG_INT32:
- arg->v_int32 = *(gint32 *) args[i];
- break;
- case GI_TYPE_TAG_UINT32:
- arg->v_uint32 = *(guint32 *) args[i];
- break;
- case GI_TYPE_TAG_INT64:
- arg->v_int64 = *(gint64 *) args[i];
- break;
- case GI_TYPE_TAG_UINT64:
- arg->v_uint64 = *(guint64 *) args[i];
- break;
- case GI_TYPE_TAG_FLOAT:
- arg->v_float = *(gfloat *) args[i];
- break;
- case GI_TYPE_TAG_DOUBLE:
- arg->v_double = *(gdouble *) args[i];
- break;
- case GI_TYPE_TAG_UTF8:
- arg->v_string = *(gchar **) args[i];
- break;
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo *interface;
- GIInfoType interface_type;
-
- interface = g_type_info_get_interface (arg_type);
- interface_type = g_base_info_get_type (interface);
-
- if (interface_type == GI_INFO_TYPE_OBJECT ||
- interface_type == GI_INFO_TYPE_INTERFACE)
- {
- arg->v_pointer = *(gpointer *) args[i];
- g_base_info_unref (interface);
- break;
- }
-
- else if (interface_type == GI_INFO_TYPE_ENUM ||
- interface_type == GI_INFO_TYPE_FLAGS)
- {
- arg->v_double = *(double *) args[i];
- g_base_info_unref (interface);
- break;
- }
- else if (interface_type == GI_INFO_TYPE_STRUCT)
- {
- arg->v_pointer = *(gpointer *) args[i];
- g_base_info_unref (interface);
- break;
- }
-
- g_base_info_unref (interface);
- }
- case GI_TYPE_TAG_GLIST:
- case GI_TYPE_TAG_GSLIST:
- case GI_TYPE_TAG_GHASH:
- arg->v_pointer = *(gpointer *) args[i];
- break;
- default:
- arg->v_pointer = 0;
- }
- jsargs[i] = seed_value_from_gi_argument (ctx, arg, arg_type, 0);
- seed_gi_release_arg (g_arg_info_get_ownership_transfer (arg_info),
- arg_type, arg);
- g_base_info_unref ((GIBaseInfo *) arg_info);
- g_base_info_unref ((GIBaseInfo *) arg_type);
+ case GI_TYPE_TAG_BOOLEAN:
+ arg->v_boolean = *(gboolean*) args[i];
+ break;
+ case GI_TYPE_TAG_INT8:
+ arg->v_int8 = *(gint8*) args[i];
+ break;
+ case GI_TYPE_TAG_UINT8:
+ arg->v_uint8 = *(guint8*) args[i];
+ break;
+ case GI_TYPE_TAG_INT16:
+ arg->v_int16 = *(gint16*) args[i];
+ break;
+ case GI_TYPE_TAG_UINT16:
+ arg->v_uint16 = *(guint16*) args[i];
+ break;
+ case GI_TYPE_TAG_INT32:
+ arg->v_int32 = *(gint32*) args[i];
+ break;
+ case GI_TYPE_TAG_UINT32:
+ arg->v_uint32 = *(guint32*) args[i];
+ break;
+ case GI_TYPE_TAG_INT64:
+ arg->v_int64 = *(gint64*) args[i];
+ break;
+ case GI_TYPE_TAG_UINT64:
+ arg->v_uint64 = *(guint64*) args[i];
+ break;
+ case GI_TYPE_TAG_FLOAT:
+ arg->v_float = *(gfloat*) args[i];
+ break;
+ case GI_TYPE_TAG_DOUBLE:
+ arg->v_double = *(gdouble*) args[i];
+ break;
+ case GI_TYPE_TAG_UTF8:
+ arg->v_string = *(gchar**) args[i];
+ break;
+ case GI_TYPE_TAG_INTERFACE: {
+ GIBaseInfo* interface;
+ GIInfoType interface_type;
+
+ interface = g_type_info_get_interface(arg_type);
+ interface_type = g_base_info_get_type(interface);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE) {
+ arg->v_pointer = *(gpointer*) args[i];
+ g_base_info_unref(interface);
+ break;
+ }
+
+ else if (interface_type == GI_INFO_TYPE_ENUM
+ || interface_type == GI_INFO_TYPE_FLAGS) {
+ arg->v_double = *(double*) args[i];
+ g_base_info_unref(interface);
+ break;
+ } else if (interface_type == GI_INFO_TYPE_STRUCT) {
+ arg->v_pointer = *(gpointer*) args[i];
+ g_base_info_unref(interface);
+ break;
+ }
+
+ g_base_info_unref(interface);
+ }
+ case GI_TYPE_TAG_GLIST:
+ case GI_TYPE_TAG_GSLIST:
+ case GI_TYPE_TAG_GHASH:
+ arg->v_pointer = *(gpointer*) args[i];
+ break;
+ default:
+ arg->v_pointer = 0;
+ }
+ jsargs[i] = seed_value_from_gi_argument(ctx, arg, arg_type, 0);
+ seed_gi_release_arg(g_arg_info_get_ownership_transfer(arg_info),
+ arg_type, arg);
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ g_base_info_unref((GIBaseInfo*) arg_type);
}
- return_value = (JSValueRef)
- JSObjectCallAsFunction (ctx,
- (JSObjectRef) privates->function, 0,
- num_args, jsargs, &exception);
-
- if (exception)
- {
- mes = seed_exception_to_string (ctx, exception);
- g_warning ("Exception in closure marshal. %s \n", mes);
- g_free (mes);
- exception = 0;
+ return_value
+ = (JSValueRef) JSObjectCallAsFunction(ctx,
+ (JSObjectRef) privates->function, 0,
+ num_args, jsargs, &exception);
+
+ if (exception) {
+ mes = seed_exception_to_string(ctx, exception);
+ g_warning("Exception in closure marshal. %s \n", mes);
+ g_free(mes);
+ exception = 0;
}
- seed_value_to_gi_argument (ctx, (JSValueRef) return_value, return_type, GI_TRANSFER_NOTHING,
- &return_arg, 0);
- switch (return_tag)
- {
+ seed_value_to_gi_argument(ctx, (JSValueRef) return_value, return_type,
+ GI_TRANSFER_NOTHING, &return_arg, 0);
+ switch (return_tag) {
#if GOBJECT_INTROSPECTION_VERSION < 0x000900
- case GI_TYPE_TAG_LONG:
- *(glong *) result = return_arg.v_long;
- break;
- case GI_TYPE_TAG_ULONG:
- *(gulong *) result = return_arg.v_ulong;
- break;
- case GI_TYPE_TAG_INT:
- *(gint *) result = return_arg.v_int;
- break;
- case GI_TYPE_TAG_SSIZE:
- *(gssize *) result = return_arg.v_ssize;
- break;
- case GI_TYPE_TAG_SIZE:
- *(gsize *) result = return_arg.v_size;
- break;
- case GI_TYPE_TAG_UINT:
- *(guint *) result = return_arg.v_uint;
- break;
+ case GI_TYPE_TAG_LONG:
+ *(glong*) result = return_arg.v_long;
+ break;
+ case GI_TYPE_TAG_ULONG:
+ *(gulong*) result = return_arg.v_ulong;
+ break;
+ case GI_TYPE_TAG_INT:
+ *(gint*) result = return_arg.v_int;
+ break;
+ case GI_TYPE_TAG_SSIZE:
+ *(gssize*) result = return_arg.v_ssize;
+ break;
+ case GI_TYPE_TAG_SIZE:
+ *(gsize*) result = return_arg.v_size;
+ break;
+ case GI_TYPE_TAG_UINT:
+ *(guint*) result = return_arg.v_uint;
+ break;
#endif
- case GI_TYPE_TAG_BOOLEAN:
- *(gboolean *) result = return_arg.v_boolean;
- break;
- case GI_TYPE_TAG_INT8:
- *(gint8 *) result = return_arg.v_int8;
- break;
- case GI_TYPE_TAG_UINT8:
- *(guint8 *) result = return_arg.v_uint8;
- break;
- case GI_TYPE_TAG_INT16:
- *(gint16 *) result = return_arg.v_int16;
- break;
- case GI_TYPE_TAG_UINT16:
- *(guint16 *) result = return_arg.v_uint16;
- break;
- case GI_TYPE_TAG_INT32:
- *(gint32 *) result = return_arg.v_int32;
- break;
- case GI_TYPE_TAG_UINT32:
- *(guint32 *) result = return_arg.v_uint32;
- break;
- case GI_TYPE_TAG_INT64:
- *(gint64 *) result = return_arg.v_int64;
- break;
- case GI_TYPE_TAG_UINT64:
- *(guint64 *) result = return_arg.v_uint64;
- break;
- case GI_TYPE_TAG_FLOAT:
- *(gfloat *) result = return_arg.v_float;
- break;
- case GI_TYPE_TAG_DOUBLE:
- *(gdouble *) result = return_arg.v_double;
- break;
- case GI_TYPE_TAG_UTF8:
- *(gchar **) result = return_arg.v_string;
- break;
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo *interface;
- GIInfoType interface_type;
-
- interface = g_type_info_get_interface (return_type);
- interface_type = g_base_info_get_type (interface);
-
- if (interface_type == GI_INFO_TYPE_OBJECT ||
- interface_type == GI_INFO_TYPE_INTERFACE)
- {
- *(gpointer *) result = return_arg.v_pointer;
- break;
- }
-
- else if (interface_type == GI_INFO_TYPE_ENUM ||
- interface_type == GI_INFO_TYPE_FLAGS)
- {
- *(double *) result = return_arg.v_double;
- break;
- }
- else if (interface_type == GI_INFO_TYPE_STRUCT)
- {
- *(gpointer *) result = return_arg.v_pointer;
- break;
- }
- }
- case GI_TYPE_TAG_GLIST:
- case GI_TYPE_TAG_GSLIST:
- case GI_TYPE_TAG_GHASH:
- *(gpointer *) result = return_arg.v_pointer;
- break;
- default:
- *(gpointer *) result = 0;
+ case GI_TYPE_TAG_BOOLEAN:
+ *(gboolean*) result = return_arg.v_boolean;
+ break;
+ case GI_TYPE_TAG_INT8:
+ *(gint8*) result = return_arg.v_int8;
+ break;
+ case GI_TYPE_TAG_UINT8:
+ *(guint8*) result = return_arg.v_uint8;
+ break;
+ case GI_TYPE_TAG_INT16:
+ *(gint16*) result = return_arg.v_int16;
+ break;
+ case GI_TYPE_TAG_UINT16:
+ *(guint16*) result = return_arg.v_uint16;
+ break;
+ case GI_TYPE_TAG_INT32:
+ *(gint32*) result = return_arg.v_int32;
+ break;
+ case GI_TYPE_TAG_UINT32:
+ *(guint32*) result = return_arg.v_uint32;
+ break;
+ case GI_TYPE_TAG_INT64:
+ *(gint64*) result = return_arg.v_int64;
+ break;
+ case GI_TYPE_TAG_UINT64:
+ *(guint64*) result = return_arg.v_uint64;
+ break;
+ case GI_TYPE_TAG_FLOAT:
+ *(gfloat*) result = return_arg.v_float;
+ break;
+ case GI_TYPE_TAG_DOUBLE:
+ *(gdouble*) result = return_arg.v_double;
+ break;
+ case GI_TYPE_TAG_UTF8:
+ *(gchar**) result = return_arg.v_string;
+ break;
+ case GI_TYPE_TAG_INTERFACE: {
+ GIBaseInfo* interface;
+ GIInfoType interface_type;
+
+ interface = g_type_info_get_interface(return_type);
+ interface_type = g_base_info_get_type(interface);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE) {
+ *(gpointer*) result = return_arg.v_pointer;
+ break;
+ }
+
+ else if (interface_type == GI_INFO_TYPE_ENUM
+ || interface_type == GI_INFO_TYPE_FLAGS) {
+ *(double*) result = return_arg.v_double;
+ break;
+ } else if (interface_type == GI_INFO_TYPE_STRUCT) {
+ *(gpointer*) result = return_arg.v_pointer;
+ break;
+ }
+ }
+ case GI_TYPE_TAG_GLIST:
+ case GI_TYPE_TAG_GSLIST:
+ case GI_TYPE_TAG_GHASH:
+ *(gpointer*) result = return_arg.v_pointer;
+ break;
+ default:
+ *(gpointer*) result = 0;
}
- g_base_info_unref ((GIBaseInfo *) return_type);
-
- JSGarbageCollect(ctx);
+ g_base_info_unref((GIBaseInfo*) return_type);
+
+ JSGarbageCollect(ctx);
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
}
-SeedNativeClosure *
-seed_make_native_closure (JSContextRef ctx,
- GICallableInfo * info,
- JSValueRef function)
+SeedNativeClosure*
+seed_make_native_closure(JSContextRef ctx,
+ GICallableInfo* info,
+ JSValueRef function)
{
- ffi_cif *cif;
- ffi_closure *closure;
- GITypeInfo *return_type;
- SeedNativeClosure *privates;
- JSObjectRef cached;
-
- cached =
- (JSObjectRef) seed_object_get_property (ctx, (JSObjectRef) function,
- "__seed_native_closure");
- if (cached
- && JSValueIsObjectOfClass (ctx, cached, seed_native_callback_class))
- {
- return (SeedNativeClosure *) JSObjectGetPrivate (cached);
+ ffi_cif* cif;
+ ffi_closure* closure;
+ GITypeInfo* return_type;
+ SeedNativeClosure* privates;
+ JSObjectRef cached;
+
+ cached = (JSObjectRef) seed_object_get_property(ctx, (JSObjectRef) function,
+ "__seed_native_closure");
+ if (cached
+ && JSValueIsObjectOfClass(ctx, cached, seed_native_callback_class)) {
+ return (SeedNativeClosure*) JSObjectGetPrivate(cached);
}
- return_type = g_callable_info_get_return_type (info);
- cif = g_new0 (ffi_cif, 1);
+ return_type = g_callable_info_get_return_type(info);
+ cif = g_new0(ffi_cif, 1);
- privates = g_new0 (SeedNativeClosure, 1);
- privates->ctx = ctx;
- privates->info = (GICallableInfo *) g_base_info_ref ((GIBaseInfo *) info);
- privates->function = function;
- privates->cif = cif;
+ privates = g_new0(SeedNativeClosure, 1);
+ privates->ctx = ctx;
+ privates->info = (GICallableInfo*) g_base_info_ref((GIBaseInfo*) info);
+ privates->function = function;
+ privates->cif = cif;
- closure =
- g_callable_info_prepare_closure (info, cif, seed_handle_closure,
- privates);
- privates->closure = closure;
+ closure = g_callable_info_prepare_closure(info, cif, seed_handle_closure,
+ privates);
+ privates->closure = closure;
- JSValueProtect (ctx, function);
+ JSValueProtect(ctx, function);
- seed_object_set_property (ctx, (JSObjectRef) function,
- "__seed_native_closure",
- (JSValueRef) JSObjectMake (ctx,
- seed_native_callback_class,
- privates));
+ seed_object_set_property(
+ ctx, (JSObjectRef) function, "__seed_native_closure",
+ (JSValueRef) JSObjectMake(ctx, seed_native_callback_class, privates));
- g_base_info_unref ((GIBaseInfo *) return_type);
+ g_base_info_unref((GIBaseInfo*) return_type);
- return privates;
+ return privates;
}
static void
-closure_invalidated (gpointer data, GClosure * c)
+closure_invalidated(gpointer data, GClosure* c)
{
- SeedClosure *closure = (SeedClosure *) c;
-
- SEED_NOTE (FINALIZATION, "Finalizing closure.");
- if (closure->user_data
- && !JSValueIsUndefined (eng->context, closure->user_data))
- JSValueUnprotect (eng->context, closure->user_data);
- if (!JSValueIsUndefined (eng->context, closure->function))
- JSValueUnprotect (eng->context, closure->function);
+ SeedClosure* closure = (SeedClosure*) c;
- g_free (closure->description);
+ SEED_NOTE(FINALIZATION, "Finalizing closure.");
+ if (closure->user_data
+ && !JSValueIsUndefined(eng->context, closure->user_data))
+ JSValueUnprotect(eng->context, closure->user_data);
+ if (!JSValueIsUndefined(eng->context, closure->function))
+ JSValueUnprotect(eng->context, closure->function);
+ g_free(closure->description);
}
JSObjectRef
-seed_closure_get_callable (GClosure * c)
+seed_closure_get_callable(GClosure* c)
{
- return ((SeedClosure *) c)->function;
+ return ((SeedClosure*) c)->function;
}
JSValueRef
-seed_closure_invoke (GClosure * closure, JSValueRef * args, guint argc,
- JSValueRef * exception)
+seed_closure_invoke(GClosure* closure,
+ JSValueRef* args,
+ guint argc,
+ JSValueRef* exception)
{
- JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
- JSValueRef ret;
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
+ JSValueRef ret;
- seed_prepare_global_context (ctx);
+ seed_prepare_global_context(ctx);
- ret =
- seed_closure_invoke_with_context (ctx, closure, args, argc, exception);
+ ret = seed_closure_invoke_with_context(ctx, closure, args, argc, exception);
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
- return ret;
+ return ret;
}
JSValueRef
-seed_closure_invoke_with_context (JSContextRef ctx, GClosure * closure,
- JSValueRef * args, guint argc,
- JSValueRef * exception)
+seed_closure_invoke_with_context(JSContextRef ctx,
+ GClosure* closure,
+ JSValueRef* args,
+ guint argc,
+ JSValueRef* exception)
{
- JSValueRef *real_args = g_newa (JSValueRef, argc + 1);
- guint i;
-
- for (i = 0; i < argc; i++)
- real_args[i] = args[i];
- real_args[argc] =
- ((SeedClosure *) closure)->user_data ? ((SeedClosure *) closure)->
- user_data : JSValueMakeNull (ctx);
-
- return
- JSObjectCallAsFunction (ctx, ((SeedClosure *) closure)->function, NULL,
- argc + 1, real_args, exception);
+ JSValueRef* real_args = g_newa(JSValueRef, argc + 1);
+ guint i;
+
+ for (i = 0; i < argc; i++)
+ real_args[i] = args[i];
+ real_args[argc] = ((SeedClosure*) closure)->user_data
+ ? ((SeedClosure*) closure)->user_data
+ : JSValueMakeNull(ctx);
+
+ return JSObjectCallAsFunction(ctx, ((SeedClosure*) closure)->function, NULL,
+ argc + 1, real_args, exception);
}
-GClosure *
-seed_closure_new_for_signal (JSContextRef ctx, JSObjectRef function,
- JSObjectRef user_data, const gchar * description,
- guint signal_id)
+GClosure*
+seed_closure_new_for_signal(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef user_data,
+ const gchar* description,
+ guint signal_id)
{
- GClosure *closure;
-
- closure = g_closure_new_simple (sizeof (SeedClosure), 0);
- g_closure_add_finalize_notifier (closure, 0, closure_invalidated);
- g_closure_set_meta_marshal (closure, GUINT_TO_POINTER (signal_id),
- seed_signal_marshal_func);
-
- JSValueProtect (ctx, function);
- ((SeedClosure *) closure)->function = function;
- if (user_data && !JSValueIsNull (ctx, user_data))
- {
- ((SeedClosure *) closure)->user_data = user_data;
- JSValueProtect (ctx, user_data);
+ GClosure* closure;
+
+ closure = g_closure_new_simple(sizeof(SeedClosure), 0);
+ g_closure_add_finalize_notifier(closure, 0, closure_invalidated);
+ g_closure_set_meta_marshal(closure, GUINT_TO_POINTER(signal_id),
+ seed_signal_marshal_func);
+
+ JSValueProtect(ctx, function);
+ ((SeedClosure*) closure)->function = function;
+ if (user_data && !JSValueIsNull(ctx, user_data)) {
+ ((SeedClosure*) closure)->user_data = user_data;
+ JSValueProtect(ctx, user_data);
}
- if (description)
- ((SeedClosure *) closure)->description = g_strdup (description);
+ if (description)
+ ((SeedClosure*) closure)->description = g_strdup(description);
- return closure;
+ return closure;
}
-GClosure *
-seed_closure_new (JSContextRef ctx, JSObjectRef function,
- JSObjectRef user_data, const gchar * description)
+GClosure*
+seed_closure_new(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef user_data,
+ const gchar* description)
{
- return seed_closure_new_for_signal (ctx, function, user_data, description,
- 0);
+ return seed_closure_new_for_signal(ctx, function, user_data, description,
+ 0);
}
void
-seed_closure_warn_exception (GClosure * c,
- JSContextRef ctx, JSValueRef exception)
+seed_closure_warn_exception(GClosure* c, JSContextRef ctx, JSValueRef exception)
{
- JSObjectRef callable = seed_closure_get_callable (c);
- gchar *name = seed_value_to_string (ctx,
- seed_object_get_property (ctx, callable,
- "name"),
- NULL);
- gchar *mes = seed_exception_to_string (ctx, exception);
-
- g_warning ("Exception in closure (%p) for %s (handler %s). %s", c,
- ((SeedClosure *) c)->description,
- *name == '\0' ? "[anonymous]" : name, mes);
-
- g_free (name);
- g_free (mes);
+ JSObjectRef callable = seed_closure_get_callable(c);
+ gchar* name
+ = seed_value_to_string(ctx,
+ seed_object_get_property(ctx, callable, "name"),
+ NULL);
+ gchar* mes = seed_exception_to_string(ctx, exception);
+
+ g_warning("Exception in closure (%p) for %s (handler %s). %s", c,
+ ((SeedClosure*) c)->description,
+ *name == '\0' ? "[anonymous]" : name, mes);
+
+ g_free(name);
+ g_free(mes);
}
JSClassDefinition seed_native_callback_def = {
- 0, /* Version, always 0 */
- 0,
- "seed_native_callback", /* Class Name */
- 0, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- seed_closure_finalize, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0, "seed_native_callback", /* Class Name */
+ 0, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, seed_closure_finalize, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
void
-seed_closures_init (void)
+seed_closures_init(void)
{
- seed_native_callback_class = JSClassCreate (&seed_native_callback_def);
- JSClassRetain (seed_native_callback_class);
+ seed_native_callback_class = JSClassCreate(&seed_native_callback_def);
+ JSClassRetain(seed_native_callback_class);
}
diff --git a/libseed/seed-closure.h b/libseed/seed-closure.h
index 49246f1..03590a1 100644
--- a/libseed/seed-closure.h
+++ b/libseed/seed-closure.h
@@ -24,58 +24,57 @@
typedef struct _SeedClosure
{
- GClosure closure;
+ GClosure closure;
- JSObjectRef function;
- JSValueRef user_data;
+ JSObjectRef function;
+ JSValueRef user_data;
- GType return_type;
- gchar *description;
+ GType return_type;
+ gchar* description;
} SeedClosure;
typedef struct _SeedNativeClosure
{
- JSContextRef ctx;
- GICallableInfo *info;
- JSValueRef function;
+ JSContextRef ctx;
+ GICallableInfo* info;
+ JSValueRef function;
- ffi_closure *closure;
- ffi_cif *cif;
+ ffi_closure* closure;
+ ffi_cif* cif;
} SeedNativeClosure;
extern JSClassRef seed_native_callback_class;
-SeedNativeClosure *seed_make_native_closure (JSContextRef ctx,
- GICallableInfo * info,
- JSValueRef function);
-GClosure *seed_closure_new (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef user_data, const gchar * description);
-
-
-GClosure *seed_closure_new_for_signal (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef user_data,
- const gchar *description,
- guint signal_id);
-
-
-JSObjectRef seed_closure_get_callable (GClosure * c);
-
-JSValueRef
-seed_closure_invoke (GClosure * closure, JSValueRef * args, guint argc,
- JSValueRef * exception);
-JSValueRef seed_closure_invoke_with_context (JSContextRef ctx,
- GClosure * closure,
- JSValueRef * args, guint argc,
- JSValueRef * exception);
-
-void
-seed_closure_warn_exception (GClosure * c,
- JSContextRef ctx, JSValueRef exception);
-
-
-
-void seed_closures_init ();
+SeedNativeClosure* seed_make_native_closure(JSContextRef ctx,
+ GICallableInfo* info,
+ JSValueRef function);
+GClosure* seed_closure_new(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef user_data,
+ const gchar* description);
+
+GClosure* seed_closure_new_for_signal(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef user_data,
+ const gchar* description,
+ guint signal_id);
+
+JSObjectRef seed_closure_get_callable(GClosure* c);
+
+JSValueRef seed_closure_invoke(GClosure* closure,
+ JSValueRef* args,
+ guint argc,
+ JSValueRef* exception);
+JSValueRef seed_closure_invoke_with_context(JSContextRef ctx,
+ GClosure* closure,
+ JSValueRef* args,
+ guint argc,
+ JSValueRef* exception);
+
+void seed_closure_warn_exception(GClosure* c,
+ JSContextRef ctx,
+ JSValueRef exception);
+
+void seed_closures_init();
#endif
diff --git a/libseed/seed-debug.h b/libseed/seed-debug.h
index 32bd87d..11a099f 100644
--- a/libseed/seed-debug.h
+++ b/libseed/seed-debug.h
@@ -24,39 +24,43 @@
#include <glib.h>
-typedef enum
-{
- SEED_DEBUG_ALL = 1 << 0,
- SEED_DEBUG_MISC = 1 << 1,
- SEED_DEBUG_FINALIZATION = 1 << 2,
- SEED_DEBUG_INITIALIZATION = 1 << 3,
- SEED_DEBUG_CONSTRUCTION = 1 << 4,
- SEED_DEBUG_INVOCATION = 1 << 5,
- SEED_DEBUG_SIGNAL = 1 << 6,
- SEED_DEBUG_STRUCTS = 1 << 7,
- SEED_DEBUG_GTYPE = 1 << 8,
- SEED_DEBUG_IMPORTER = 1 << 9,
- SEED_DEBUG_MODULE = 1 << 10
+typedef enum {
+ SEED_DEBUG_ALL = 1 << 0,
+ SEED_DEBUG_MISC = 1 << 1,
+ SEED_DEBUG_FINALIZATION = 1 << 2,
+ SEED_DEBUG_INITIALIZATION = 1 << 3,
+ SEED_DEBUG_CONSTRUCTION = 1 << 4,
+ SEED_DEBUG_INVOCATION = 1 << 5,
+ SEED_DEBUG_SIGNAL = 1 << 6,
+ SEED_DEBUG_STRUCTS = 1 << 7,
+ SEED_DEBUG_GTYPE = 1 << 8,
+ SEED_DEBUG_IMPORTER = 1 << 9,
+ SEED_DEBUG_MODULE = 1 << 10
} SeedDebugFlag;
#ifdef SEED_ENABLE_DEBUG
-#define SEED_NOTE(type,...) G_STMT_START { \
- if ((seed_debug_flags & SEED_DEBUG_##type) || \
- seed_debug_flags & SEED_DEBUG_ALL) \
- { \
- gchar * _fmt = g_strdup_printf (__VA_ARGS__); \
- g_message ("[" #type "] " G_STRLOC ": %s",_fmt); \
- g_free (_fmt); \
- } \
-} G_STMT_END
+#define SEED_NOTE(type, ...) \
+ G_STMT_START \
+ { \
+ if ((seed_debug_flags & SEED_DEBUG_##type) \
+ || seed_debug_flags & SEED_DEBUG_ALL) { \
+ gchar* _fmt = g_strdup_printf(__VA_ARGS__); \
+ g_message("[" #type "] " G_STRLOC ": %s", _fmt); \
+ g_free(_fmt); \
+ } \
+ } \
+ G_STMT_END
-#define SEED_MARK() SEED_NOTE(MISC, "== mark ==")
-#define SEED_DBG(x) { a }
+#define SEED_MARK() SEED_NOTE(MISC, "== mark ==")
+#define SEED_DBG(x) \
+ { \
+ a \
+ }
#else /* !SEED_ENABLE_DEBUG */
-#define SEED_NOTE(type,...)
+#define SEED_NOTE(type, ...)
#define SEED_MARK()
#define SEED_DBG(x)
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index b010938..c024308 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -48,13 +48,13 @@ JSContextGroupRef context_group;
JSStringRef defaults_script;
-gchar *glib_message = 0;
+gchar* glib_message = 0;
-GIBaseInfo *base_info_info = 0;
+GIBaseInfo* base_info_info = 0;
GQuark js_ref_quark;
-guint seed_debug_flags = 0; /* global seed debug flag */
+guint seed_debug_flags = 0; /* global seed debug flag */
gboolean seed_arg_print_version = FALSE; // Flag to print version and quit
#ifdef SEED_ENABLE_GJSCOMPAT
gboolean seed_arg_gjs_compatiblity = FALSE;
@@ -63,38 +63,38 @@ gboolean seed_arg_gjs_compatiblity = FALSE;
pthread_key_t seed_next_gobject_wrapper_key;
#ifdef SEED_ENABLE_DEBUG
-static const GDebugKey seed_debug_keys[] = {
- {"misc", SEED_DEBUG_MISC},
- {"finalization", SEED_DEBUG_FINALIZATION},
- {"initialization", SEED_DEBUG_INITIALIZATION},
- {"signal", SEED_DEBUG_SIGNAL},
- {"invocation", SEED_DEBUG_INVOCATION},
- {"structs", SEED_DEBUG_STRUCTS},
- {"construction", SEED_DEBUG_CONSTRUCTION},
- {"gtype", SEED_DEBUG_GTYPE},
- {"importer", SEED_DEBUG_IMPORTER},
- {"module", SEED_DEBUG_MODULE}
-};
+static const GDebugKey seed_debug_keys[]
+ = { { "misc", SEED_DEBUG_MISC },
+ { "finalization", SEED_DEBUG_FINALIZATION },
+ { "initialization", SEED_DEBUG_INITIALIZATION },
+ { "signal", SEED_DEBUG_SIGNAL },
+ { "invocation", SEED_DEBUG_INVOCATION },
+ { "structs", SEED_DEBUG_STRUCTS },
+ { "construction", SEED_DEBUG_CONSTRUCTION },
+ { "gtype", SEED_DEBUG_GTYPE },
+ { "importer", SEED_DEBUG_IMPORTER },
+ { "module", SEED_DEBUG_MODULE } };
#endif /* SEED_ENABLE_DEBUG */
static bool
-seed_gobject_has_instance (JSContextRef ctx, JSObjectRef constructor,
- JSValueRef possible_instance, JSValueRef* exception)
+seed_gobject_has_instance(JSContextRef ctx,
+ JSObjectRef constructor,
+ JSValueRef possible_instance,
+ JSValueRef* exception)
{
- GType constructor_type, value_type;
- if (JSValueIsNull (ctx, possible_instance) ||
- !JSValueIsObject (ctx, possible_instance) ||
- !JSValueIsObjectOfClass (ctx, possible_instance, gobject_class))
- return FALSE;
+ GType constructor_type, value_type;
+ if (JSValueIsNull(ctx, possible_instance)
+ || !JSValueIsObject(ctx, possible_instance)
+ || !JSValueIsObjectOfClass(ctx, possible_instance, gobject_class))
+ return FALSE;
- constructor_type = (GType) JSObjectGetPrivate (constructor);
- value_type = G_OBJECT_TYPE ((GObject *)
- JSObjectGetPrivate ((JSObjectRef) possible_instance));
+ constructor_type = (GType) JSObjectGetPrivate(constructor);
+ value_type = G_OBJECT_TYPE(
+ (GObject*) JSObjectGetPrivate((JSObjectRef) possible_instance));
- return g_type_is_a (value_type, constructor_type);
+ return g_type_is_a(value_type, constructor_type);
}
-
/**
* seed_prepare_global_context:
* @ctx: A #SeedContext on which to add the default set of global objects.
@@ -104,1469 +104,1385 @@ seed_gobject_has_instance (JSContextRef ctx, JSObjectRef constructor,
*
*/
void
-seed_prepare_global_context (JSContextRef ctx)
+seed_prepare_global_context(JSContextRef ctx)
{
- JSObjectRef global = JSContextGetGlobalObject (ctx);
- JSStringRef check_sprintf = JSStringCreateWithUTF8CString ("sprintf");
+ JSObjectRef global = JSContextGetGlobalObject(ctx);
+ JSStringRef check_sprintf = JSStringCreateWithUTF8CString("sprintf");
- seed_object_set_property (ctx, global, "imports", importer);
- seed_object_set_property (ctx, global, "GType", seed_gtype_constructor);
- seed_object_set_property (ctx, global, "Seed", seed_obj_ref);
+ seed_object_set_property(ctx, global, "imports", importer);
+ seed_object_set_property(ctx, global, "GType", seed_gtype_constructor);
+ seed_object_set_property(ctx, global, "Seed", seed_obj_ref);
#ifdef SEED_ENABLE_GJSCOMPAT
- seed_object_set_property (ctx, global, "ARGV", ARGV_obj_ref);
- seed_object_set_property (ctx, global, "window", window_obj_ref);
+ seed_object_set_property(ctx, global, "ARGV", ARGV_obj_ref);
+ seed_object_set_property(ctx, global, "window", window_obj_ref);
#endif
- seed_object_set_property (ctx, global, "print", seed_print_ref);
- seed_object_set_property (ctx, global, "printerr", seed_printerr_ref);
-
- /* No need to re-import Seed.js if not needed. */
- if (!JSObjectHasProperty( ctx, seed_obj_ref, check_sprintf)) {
- JSEvaluateScript (ctx, defaults_script, NULL, NULL, 0, NULL);
- }
- JSStringRelease (check_sprintf);
+ seed_object_set_property(ctx, global, "print", seed_print_ref);
+ seed_object_set_property(ctx, global, "printerr", seed_printerr_ref);
+
+ /* No need to re-import Seed.js if not needed. */
+ if (!JSObjectHasProperty(ctx, seed_obj_ref, check_sprintf)) {
+ JSEvaluateScript(ctx, defaults_script, NULL, NULL, 0, NULL);
+ }
+ JSStringRelease(check_sprintf);
}
static JSObjectRef
-seed_struct_constructor_invoked (JSContextRef ctx,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_struct_constructor_invoked(JSContextRef ctx,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GIBaseInfo *info = JSObjectGetPrivate (constructor);
- JSValueRef ret;
- JSObjectRef parameters = 0;
-
- if (argumentCount == 1)
- {
- if (!JSValueIsObject (ctx, arguments[0]))
- {
-
- // new GObject.GValue() can accept anything as a argument...
- GType gtype = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) info);
- if (!g_type_is_a (gtype, G_TYPE_VALUE)) {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Constructor expects object as argument");
- return (JSObjectRef) JSValueMakeNull (ctx);
- }
- }
- parameters = (JSObjectRef) arguments[0];
+ GIBaseInfo* info = JSObjectGetPrivate(constructor);
+ JSValueRef ret;
+ JSObjectRef parameters = 0;
+
+ if (argumentCount == 1) {
+ if (!JSValueIsObject(ctx, arguments[0])) {
+
+ // new GObject.GValue() can accept anything as a argument...
+ GType gtype
+ = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) info);
+ if (!g_type_is_a(gtype, G_TYPE_VALUE)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Constructor expects object as argument");
+ return (JSObjectRef) JSValueMakeNull(ctx);
+ }
+ }
+ parameters = (JSObjectRef) arguments[0];
}
- ret = seed_construct_struct_type_with_parameters (ctx, info,
- parameters, exception);
+ ret = seed_construct_struct_type_with_parameters(ctx, info, parameters,
+ exception);
- return (JSObjectRef) ret;
+ return (JSObjectRef) ret;
}
static JSObjectRef
-seed_gobject_constructor_invoked (JSContextRef ctx,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_constructor_invoked(JSContextRef ctx,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GType type;
- GParameter *params;
- GObjectClass *oclass;
- GObject *gobject;
- GParamSpec *param_spec;
- gchar *prop_name;
- gint i, nparams = 0, length, ri;
- JSObjectRef ret;
- JSPropertyNameArrayRef jsprops = 0;
- JSStringRef jsprop_name;
- JSValueRef jsprop_value;
-
- type = (GType) JSObjectGetPrivate (constructor);
- if (!type)
- return 0;
-
- oclass = g_type_class_ref (type);
-
- // Check for an exception in class init (which may have just been called
- // by g_type_class_ref, if this is the first construction of this class).
- // Bubble up the exception, and clear it from the class's qdata so that
- // this doesn't happen on subsequent construction.
- GQuark class_init_exception_q =
- g_quark_from_static_string("type-class-init-exception");
- JSValueRef class_init_exception =
- (JSValueRef)g_type_get_qdata(type, class_init_exception_q);
- if(class_init_exception)
- {
- *exception = class_init_exception;
- g_type_set_qdata(type, class_init_exception_q, NULL);
- return (JSObjectRef) JSValueMakeNull (ctx);
+ GType type;
+ GParameter* params;
+ GObjectClass* oclass;
+ GObject* gobject;
+ GParamSpec* param_spec;
+ gchar* prop_name;
+ gint i, nparams = 0, length, ri;
+ JSObjectRef ret;
+ JSPropertyNameArrayRef jsprops = 0;
+ JSStringRef jsprop_name;
+ JSValueRef jsprop_value;
+
+ type = (GType) JSObjectGetPrivate(constructor);
+ if (!type)
+ return 0;
+
+ oclass = g_type_class_ref(type);
+
+ // Check for an exception in class init (which may have just been called
+ // by g_type_class_ref, if this is the first construction of this class).
+ // Bubble up the exception, and clear it from the class's qdata so that
+ // this doesn't happen on subsequent construction.
+ GQuark class_init_exception_q
+ = g_quark_from_static_string("type-class-init-exception");
+ JSValueRef class_init_exception
+ = (JSValueRef) g_type_get_qdata(type, class_init_exception_q);
+ if (class_init_exception) {
+ *exception = class_init_exception;
+ g_type_set_qdata(type, class_init_exception_q, NULL);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- if (argumentCount > 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Constructor expects"
- " 1 argument, got %zd", argumentCount);
+ if (argumentCount > 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Constructor expects"
+ " 1 argument, got %zd",
+ argumentCount);
- return (JSObjectRef) JSValueMakeNull (ctx);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- if (argumentCount == 1)
- {
- if (!JSValueIsObject (ctx, arguments[0]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Constructor expects object as argument");
- g_type_class_unref (oclass);
- return (JSObjectRef) JSValueMakeNull (ctx);
- }
-
- jsprops = JSObjectCopyPropertyNames (ctx, (JSObjectRef) arguments[0]);
- nparams = JSPropertyNameArrayGetCount (jsprops);
+ if (argumentCount == 1) {
+ if (!JSValueIsObject(ctx, arguments[0])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Constructor expects object as argument");
+ g_type_class_unref(oclass);
+ return (JSObjectRef) JSValueMakeNull(ctx);
+ }
+
+ jsprops = JSObjectCopyPropertyNames(ctx, (JSObjectRef) arguments[0]);
+ nparams = JSPropertyNameArrayGetCount(jsprops);
}
- ri = i = 0;
+ ri = i = 0;
- params = g_new0 (GParameter, nparams + 1);
- SEED_NOTE (INITIALIZATION, "Constructing object of type %s",
- g_type_name (type));
+ params = g_new0(GParameter, nparams + 1);
+ SEED_NOTE(INITIALIZATION, "Constructing object of type %s",
+ g_type_name(type));
+ pthread_setspecific(seed_next_gobject_wrapper_key,
+ seed_make_wrapper_for_type(ctx, type));
- pthread_setspecific (seed_next_gobject_wrapper_key,
- seed_make_wrapper_for_type (ctx, type));
+ while (i < nparams) {
+ GType type;
+ jsprop_name = JSPropertyNameArrayGetNameAtIndex(jsprops, i);
- while (i < nparams)
- {
- GType type;
- jsprop_name = JSPropertyNameArrayGetNameAtIndex (jsprops, i);
-
- length = JSStringGetMaximumUTF8CStringSize (jsprop_name);
- prop_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (jsprop_name, prop_name, length);
-
- param_spec = g_object_class_find_property (oclass, prop_name);
-
- jsprop_value = JSObjectGetProperty (ctx,
- (JSObjectRef) arguments[0],
- jsprop_name, NULL);
-
- if (param_spec == NULL)
- {
- JSObjectSetProperty (ctx, pthread_getspecific(seed_next_gobject_wrapper_key), jsprop_name,
- jsprop_value, 0, NULL);
- ++i;
- continue;
- }
- // TODO: exception handling
-
- if (g_type_is_a (param_spec->value_type, G_TYPE_ENUM))
- type = G_TYPE_INT;
- else
- type = param_spec->value_type;
-
- seed_value_to_gvalue (ctx, jsprop_value,
- type, ¶ms[ri].value, exception);
-
- if (*exception)
- {
- g_free (params);
- JSPropertyNameArrayRelease (jsprops);
- pthread_setspecific(seed_next_gobject_wrapper_key, NULL);
- return 0;
- }
- params[ri].name = prop_name;
-
- ++i;
- ++ri;
- }
+ length = JSStringGetMaximumUTF8CStringSize(jsprop_name);
+ prop_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(jsprop_name, prop_name, length);
- if (jsprops)
- JSPropertyNameArrayRelease (jsprops);
+ param_spec = g_object_class_find_property(oclass, prop_name);
- SEED_NOTE (INITIALIZATION, "G_TYPE_IS_INSTANTIATABLE = %d G_TYPE_IS_ABSTRACT = %d",
- G_TYPE_IS_INSTANTIATABLE(type) , G_TYPE_IS_ABSTRACT(type));
+ jsprop_value = JSObjectGetProperty(ctx, (JSObjectRef) arguments[0],
+ jsprop_name, NULL);
+ if (param_spec == NULL) {
+ JSObjectSetProperty(ctx, pthread_getspecific(
+ seed_next_gobject_wrapper_key),
+ jsprop_name, jsprop_value, 0, NULL);
+ ++i;
+ continue;
+ }
+ // TODO: exception handling
-
- if (! G_TYPE_IS_INSTANTIATABLE(type) || G_TYPE_IS_ABSTRACT(type) ) {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Type can not be created - not INSTANTIATABLE");
+ if (g_type_is_a(param_spec->value_type, G_TYPE_ENUM))
+ type = G_TYPE_INT;
+ else
+ type = param_spec->value_type;
- return (JSObjectRef) JSValueMakeNull (ctx);
+ seed_value_to_gvalue(ctx, jsprop_value, type, ¶ms[ri].value,
+ exception);
+
+ if (*exception) {
+ g_free(params);
+ JSPropertyNameArrayRelease(jsprops);
+ pthread_setspecific(seed_next_gobject_wrapper_key, NULL);
+ return 0;
+ }
+ params[ri].name = prop_name;
+
+ ++i;
+ ++ri;
}
-
-
- gobject = g_object_newv (type, ri, params);
+ if (jsprops)
+ JSPropertyNameArrayRelease(jsprops);
- if (G_IS_INITIALLY_UNOWNED (gobject) && !g_object_is_floating (gobject))
- g_object_ref (gobject);
- else if (g_object_is_floating (gobject))
- g_object_ref_sink (gobject);
+ SEED_NOTE(INITIALIZATION,
+ "G_TYPE_IS_INSTANTIATABLE = %d G_TYPE_IS_ABSTRACT = %d",
+ G_TYPE_IS_INSTANTIATABLE(type), G_TYPE_IS_ABSTRACT(type));
- if (!gobject)
- ret = (JSObjectRef) JSValueMakeNull (ctx);
- else
- ret = (JSObjectRef) seed_value_from_object (ctx, gobject, exception);
+ if (!G_TYPE_IS_INSTANTIATABLE(type) || G_TYPE_IS_ABSTRACT(type)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Type can not be created - not INSTANTIATABLE");
- for (i = 0; i < ri; i++)
- {
- g_value_unset (¶ms[i].value);
+ return (JSObjectRef) JSValueMakeNull(ctx);
+ }
+
+ gobject = g_object_newv(type, ri, params);
+
+ if (G_IS_INITIALLY_UNOWNED(gobject) && !g_object_is_floating(gobject))
+ g_object_ref(gobject);
+ else if (g_object_is_floating(gobject))
+ g_object_ref_sink(gobject);
+
+ if (!gobject)
+ ret = (JSObjectRef) JSValueMakeNull(ctx);
+ else
+ ret = (JSObjectRef) seed_value_from_object(ctx, gobject, exception);
+
+ for (i = 0; i < ri; i++) {
+ g_value_unset(¶ms[i].value);
}
- g_object_unref (gobject);
+ g_object_unref(gobject);
- g_type_class_unref (oclass);
+ g_type_class_unref(oclass);
- g_free (params);
+ g_free(params);
- return ret;
+ return ret;
}
static JSValueRef
-seed_gobject_property_type (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_property_type(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GParamSpec *spec;
- gchar *name;
- GObject *this;
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "__property_type expects 1 argument"
- "got %zd", argumentCount);
- return JSValueMakeNull (ctx);
+ GParamSpec* spec;
+ gchar* name;
+ GObject* this;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "__property_type expects 1 argument"
+ "got %zd",
+ argumentCount);
+ return JSValueMakeNull(ctx);
}
- this = seed_value_to_object (ctx, this_object, exception);
- name = seed_value_to_string (ctx, arguments[0], exception);
+ this = seed_value_to_object(ctx, this_object, exception);
+ name = seed_value_to_string(ctx, arguments[0], exception);
- spec = g_object_class_find_property (G_OBJECT_GET_CLASS (this), name);
- g_free (name);
+ spec = g_object_class_find_property(G_OBJECT_GET_CLASS(this), name);
+ g_free(name);
- return seed_value_from_long (ctx, spec->value_type, exception);
+ return seed_value_from_long(ctx, spec->value_type, exception);
}
static JSValueRef
-seed_gobject_ref_count (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[], JSValueRef * exception)
+seed_gobject_ref_count(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GObject *this;
+ GObject* this;
- this = seed_value_to_object (ctx, (JSValueRef) this_object, exception);
+ this = seed_value_to_object(ctx, (JSValueRef) this_object, exception);
- return seed_value_from_int (ctx, this->ref_count, exception);
+ return seed_value_from_int(ctx, this->ref_count, exception);
}
static void
-seed_gobject_method_finalize (JSObjectRef method)
+seed_gobject_method_finalize(JSObjectRef method)
{
- GIBaseInfo *info = (GIBaseInfo *) JSObjectGetPrivate (method);
- if (info)
- g_base_info_unref (info);
+ GIBaseInfo* info = (GIBaseInfo*) JSObjectGetPrivate(method);
+ if (info)
+ g_base_info_unref(info);
}
-typedef void (*InitMethodCallback) (gint * argc, gchar *** argv);
+typedef void (*InitMethodCallback)(gint* argc, gchar*** argv);
static gboolean
-seed_gobject_init_build_argv (JSContextRef ctx,
- JSObjectRef array,
- SeedArgvPrivates * priv, JSValueRef * exception)
+seed_gobject_init_build_argv(JSContextRef ctx,
+ JSObjectRef array,
+ SeedArgvPrivates* priv,
+ JSValueRef* exception)
{
- guint i, length;
- JSValueRef jsl;
+ guint i, length;
+ JSValueRef jsl;
- jsl = seed_object_get_property (ctx, array, "length");
- if (JSValueIsNull (ctx, jsl) || JSValueIsUndefined (ctx, jsl))
- return FALSE;
+ jsl = seed_object_get_property(ctx, array, "length");
+ if (JSValueIsNull(ctx, jsl) || JSValueIsUndefined(ctx, jsl))
+ return FALSE;
- length = seed_value_to_uint (ctx, jsl, exception);
- priv->argv = g_new (gchar *, length);
- priv->argc = length;
+ length = seed_value_to_uint(ctx, jsl, exception);
+ priv->argv = g_new(gchar*, length);
+ priv->argc = length;
- for (i = 0; i < length; i++)
- {
- priv->argv[i] = seed_value_to_string (ctx,
- JSObjectGetPropertyAtIndex (ctx,
- array,
- i,
- exception),
- exception);
+ for (i = 0; i < length; i++) {
+ priv->argv[i] = seed_value_to_string(
+ ctx, JSObjectGetPropertyAtIndex(ctx, array, i, exception), exception);
}
- return TRUE;
-
+ return TRUE;
}
static JSValueRef
-seed_gobject_init_method_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_init_method_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GIBaseInfo *info;
- GTypelib *typelib;
- InitMethodCallback c;
- SeedArgvPrivates *priv = NULL;
- gboolean allocated = FALSE;
-
- if (argumentCount != 1 && argumentCount != 2)
- {
- seed_make_exception (ctx, exception,
- "ArgumentError",
- "init method expects 1 argument, got %zd",
- argumentCount);
- return JSValueMakeUndefined (ctx);
+ GIBaseInfo* info;
+ GTypelib* typelib;
+ InitMethodCallback c;
+ SeedArgvPrivates* priv = NULL;
+ gboolean allocated = FALSE;
+
+ if (argumentCount != 1 && argumentCount != 2) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "init method expects 1 argument, got %zd",
+ argumentCount);
+ return JSValueMakeUndefined(ctx);
}
- if (argumentCount == 1)
- {
- if (!JSValueIsNull (ctx, arguments[0])
- && !JSValueIsObject (ctx, arguments[0]))
-
- {
- seed_make_exception (ctx, exception,
- "ArgumentError",
- "init method expects an array object as argument");
- return JSValueMakeUndefined (ctx);
- }
- if (JSValueIsNull (ctx, arguments[0]))
- {
- priv = NULL;
- } else
- if (JSValueIsObjectOfClass (ctx, arguments[0], seed_argv_class))
- {
- priv = JSObjectGetPrivate ((JSObjectRef) arguments[0]);
- }
- else
- {
- priv = g_newa (SeedArgvPrivates, 1);
- if (!seed_gobject_init_build_argv (ctx,
- (JSObjectRef) arguments[0],
- priv, exception))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Init method expects an array as argument");
- return JSValueMakeUndefined (ctx);
-
- }
- allocated = TRUE;
- }
+ if (argumentCount == 1) {
+ if (!JSValueIsNull(ctx, arguments[0])
+ && !JSValueIsObject(ctx, arguments[0]))
+
+ {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "init method expects an array object as argument");
+ return JSValueMakeUndefined(ctx);
+ }
+ if (JSValueIsNull(ctx, arguments[0])) {
+ priv = NULL;
+ } else if (JSValueIsObjectOfClass(ctx, arguments[0], seed_argv_class)) {
+ priv = JSObjectGetPrivate((JSObjectRef) arguments[0]);
+ } else {
+ priv = g_newa(SeedArgvPrivates, 1);
+ if (!seed_gobject_init_build_argv(ctx, (JSObjectRef) arguments[0],
+ priv, exception)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Init method expects an array as argument");
+ return JSValueMakeUndefined(ctx);
+ }
+ allocated = TRUE;
+ }
}
- info = JSObjectGetPrivate (function);
- typelib = g_base_info_get_typelib (info);
- g_typelib_symbol (typelib,
- g_function_info_get_symbol ((GIFunctionInfo *) info),
- (gpointer *) & c);
- // Backwards compatibility
- if (!priv)
- {
- c (NULL, NULL);
- return JSValueMakeUndefined (ctx);
+ info = JSObjectGetPrivate(function);
+ typelib = g_base_info_get_typelib(info);
+ g_typelib_symbol(typelib,
+ g_function_info_get_symbol((GIFunctionInfo*) info),
+ (gpointer*) &c);
+ // Backwards compatibility
+ if (!priv) {
+ c(NULL, NULL);
+ return JSValueMakeUndefined(ctx);
}
- c (&priv->argc, &priv->argv);
+ c(&priv->argc, &priv->argv);
- if (allocated)
- g_free (priv->argv);
+ if (allocated)
+ g_free(priv->argv);
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
static JSValueRef
-seed_gobject_method_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef this_object,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_method_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef this_object,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GIBaseInfo *info;
- GObject *object = NULL;
- gboolean instance_method = TRUE;
- gboolean is_caller_allocates = FALSE;
- gboolean *caller_allocated;
- GIBaseInfo *iface_info = NULL;
- GArgument retval;
- GArgument *in_args;
- GArgument *out_args;
- GArgument *out_values;
- gint *out_pos;
- gint first_out = -1;
- guint use_return_as_out = 0;
- guint n_args, n_in_args, n_out_args, i;
- guint in_args_pos, out_args_pos;
- GIArgInfo *arg_info = NULL;
- GITypeInfo *type_info = NULL;
- GITypeTag tag;
- GIDirection dir;
- GITransfer transfer;
- JSValueRef retval_ref;
- GError *error = 0;
- gint length_arg_pos = 0;
- guint64 array_len = 0;
-
- info = JSObjectGetPrivate (function);
-
- // We just want to check if there IS an object, not actually throw an
- // exception if we don't get it.
- if (!this_object || !
- ((object = seed_value_to_object (ctx, this_object, 0)) ||
- (object = seed_pointer_get_pointer (ctx, this_object))))
- instance_method = FALSE;
-
- n_args = g_callable_info_get_n_args ((GICallableInfo *) info);
-
- out_pos = g_new0 (gint, n_args + 1);
- in_args = g_new0 (GArgument, n_args + 1);
- out_args = g_new0 (GArgument, n_args + 1);
- out_values = g_new0 (GArgument, n_args + 1);
- n_in_args = n_out_args = 0;
- caller_allocated = g_new0 (gboolean, n_args + 1);
-
- // start buy pushing the object onto the call stack.
-
- if (instance_method)
- in_args[n_in_args++].v_pointer = object;
-
-
- // now loop through all the other args.
- for (i = 0; (i < (n_args)); i++)
- {
- out_pos[i] = -1;
- arg_info = g_callable_info_get_arg ((GICallableInfo *) info, i);
- dir = g_arg_info_get_direction (arg_info);
- type_info = g_arg_info_get_type (arg_info);
- transfer = g_arg_info_get_ownership_transfer (arg_info);
- is_caller_allocates = FALSE;
-
+ GIBaseInfo* info;
+ GObject* object = NULL;
+ gboolean instance_method = TRUE;
+ gboolean is_caller_allocates = FALSE;
+ gboolean* caller_allocated;
+ GIBaseInfo* iface_info = NULL;
+ GArgument retval;
+ GArgument* in_args;
+ GArgument* out_args;
+ GArgument* out_values;
+ gint* out_pos;
+ gint first_out = -1;
+ guint use_return_as_out = 0;
+ guint n_args, n_in_args, n_out_args, i;
+ guint in_args_pos, out_args_pos;
+ GIArgInfo* arg_info = NULL;
+ GITypeInfo* type_info = NULL;
+ GITypeTag tag;
+ GIDirection dir;
+ GITransfer transfer;
+ JSValueRef retval_ref;
+ GError* error = 0;
+ gint length_arg_pos = 0;
+ guint64 array_len = 0;
+
+ info = JSObjectGetPrivate(function);
+
+ // We just want to check if there IS an object, not actually throw an
+ // exception if we don't get it.
+ if (!this_object
+ || !((object = seed_value_to_object(ctx, this_object, 0))
+ || (object = seed_pointer_get_pointer(ctx, this_object))))
+ instance_method = FALSE;
+
+ n_args = g_callable_info_get_n_args((GICallableInfo*) info);
+
+ out_pos = g_new0(gint, n_args + 1);
+ in_args = g_new0(GArgument, n_args + 1);
+ out_args = g_new0(GArgument, n_args + 1);
+ out_values = g_new0(GArgument, n_args + 1);
+ n_in_args = n_out_args = 0;
+ caller_allocated = g_new0(gboolean, n_args + 1);
+
+ // start buy pushing the object onto the call stack.
+
+ if (instance_method)
+ in_args[n_in_args++].v_pointer = object;
+
+ // now loop through all the other args.
+ for (i = 0; (i < (n_args)); i++) {
+ out_pos[i] = -1;
+ arg_info = g_callable_info_get_arg((GICallableInfo*) info, i);
+ dir = g_arg_info_get_direction(arg_info);
+ type_info = g_arg_info_get_type(arg_info);
+ transfer = g_arg_info_get_ownership_transfer(arg_info);
+ is_caller_allocates = FALSE;
+
#if GOBJECT_INTROSPECTION_VERSION > 0x000613
- is_caller_allocates = (dir == GI_DIRECTION_OUT) && g_arg_info_is_caller_allocates (arg_info);
-
- /* caller allocates only applies to structures but GI has
- * no way to denote that yet, so we only use caller allocates
- * if we see a structure
- */
- if (is_caller_allocates)
- {
- GITypeTag type_tag = g_type_info_get_tag (type_info);
+ is_caller_allocates = (dir == GI_DIRECTION_OUT)
+ && g_arg_info_is_caller_allocates(arg_info);
- is_caller_allocates = FALSE;
+ /* caller allocates only applies to structures but GI has
+ * no way to denote that yet, so we only use caller allocates
+ * if we see a structure
+ */
+ if (is_caller_allocates) {
+ GITypeTag type_tag = g_type_info_get_tag(type_info);
+ is_caller_allocates = FALSE;
- if (type_tag == GI_TYPE_TAG_INTERFACE)
- {
- GIInfoType info_type;
+ if (type_tag == GI_TYPE_TAG_INTERFACE) {
+ GIInfoType info_type;
- iface_info = g_type_info_get_interface (type_info);
- g_assert (info != NULL);
- info_type = g_base_info_get_type (iface_info);
+ iface_info = g_type_info_get_interface(type_info);
+ g_assert(info != NULL);
+ info_type = g_base_info_get_type(iface_info);
- if (info_type == GI_INFO_TYPE_STRUCT)
- is_caller_allocates = TRUE;
+ if (info_type == GI_INFO_TYPE_STRUCT)
+ is_caller_allocates = TRUE;
}
- }
+ }
#endif
+ SEED_NOTE(INVOCATION,
+ "Converting arg: %s (%d) of function %s, exception is %p",
+ g_base_info_get_name((GIBaseInfo*) arg_info), i,
+ g_base_info_get_name(info), exception);
- SEED_NOTE (INVOCATION,
- "Converting arg: %s (%d) of function %s, exception is %p",
- g_base_info_get_name ((GIBaseInfo *)arg_info), i,
- g_base_info_get_name (info), exception);
-
+ if (i + 1 > argumentCount) {
+ if (dir == GI_DIRECTION_OUT) {
+ GArgument* out_value = &out_values[n_out_args];
+ out_values[n_out_args].v_pointer = NULL;
+ out_args[n_out_args].v_pointer = out_value;
- if (i + 1 > argumentCount)
- {
-
- if (dir == GI_DIRECTION_OUT)
- {
- GArgument *out_value = &out_values[n_out_args];
- out_values[n_out_args].v_pointer = NULL;
- out_args[n_out_args].v_pointer = out_value;
-
- out_pos[ i ] = n_out_args;
-
- if (is_caller_allocates)
- {
- gsize size = g_struct_info_get_size ( (GIStructInfo *) iface_info) ;
- out_args[n_out_args].v_pointer = g_malloc0 (size);
- out_values[n_out_args].v_pointer = out_args[n_out_args].v_pointer;
- caller_allocated[i] = TRUE;
+ out_pos[i] = n_out_args;
+ if (is_caller_allocates) {
+ gsize size
+ = g_struct_info_get_size((GIStructInfo*) iface_info);
+ out_args[n_out_args].v_pointer = g_malloc0(size);
+ out_values[n_out_args].v_pointer
+ = out_args[n_out_args].v_pointer;
+ caller_allocated[i] = TRUE;
}
- n_out_args++;
- }
- else
- in_args[n_in_args++].v_pointer = 0;
-
- }
- else if (dir == GI_DIRECTION_IN || dir == GI_DIRECTION_INOUT)
- {
-
- if ( !g_arg_info_may_be_null (arg_info) )
- {
- gboolean is_null = ( !arguments[i] || JSValueIsNull (ctx, arguments[i]) );
-
- if (!is_null && (g_type_info_get_tag (type_info) == GI_TYPE_TAG_INTERFACE))
- {
- /* see if the pointer is null for struct/unions. */
- GIBaseInfo *interface = g_type_info_get_interface (type_info);
- GIInfoType interface_type = g_base_info_get_type (interface);
-
- gboolean arg_is_object = JSValueIsObject (ctx, arguments[i]);
-
- gboolean is_gvalue = (interface_type == GI_INFO_TYPE_STRUCT) &&
- !g_strcmp0(g_base_info_get_name((GIBaseInfo *)interface), "Value") &&
- !g_strcmp0(g_base_info_get_namespace((GIBaseInfo *)interface), "GObject");
-
-
- gboolean is_struct_or_union = (
- interface_type == GI_INFO_TYPE_STRUCT ||
- interface_type == GI_INFO_TYPE_UNION
- );
-
- /* this test ignores non-objects being sent where interfaces are expected
- hopefully our type manipluation code will pick that up.
- The only exception to this is GObject.GValues which are arrays.
- */
- if (!is_gvalue && is_struct_or_union && arg_is_object &&
- (seed_pointer_get_pointer (ctx, arguments[i]) == 0)) {
- is_null = TRUE;
- }
- g_base_info_unref (interface);
+ n_out_args++;
+ } else
+ in_args[n_in_args++].v_pointer = 0;
+
+ } else if (dir == GI_DIRECTION_IN || dir == GI_DIRECTION_INOUT) {
+
+ if (!g_arg_info_may_be_null(arg_info)) {
+ gboolean is_null
+ = (!arguments[i] || JSValueIsNull(ctx, arguments[i]));
+
+ if (!is_null && (g_type_info_get_tag(type_info)
+ == GI_TYPE_TAG_INTERFACE)) {
+ /* see if the pointer is null for struct/unions. */
+ GIBaseInfo* interface = g_type_info_get_interface(
+ type_info);
+ GIInfoType interface_type = g_base_info_get_type(interface);
+
+ gboolean arg_is_object = JSValueIsObject(ctx, arguments[i]);
+
+ gboolean is_gvalue
+ = (interface_type == GI_INFO_TYPE_STRUCT)
+ && !g_strcmp0(g_base_info_get_name(
+ (GIBaseInfo*) interface),
+ "Value")
+ && !g_strcmp0(g_base_info_get_namespace(
+ (GIBaseInfo*) interface),
+ "GObject");
+
+ gboolean is_struct_or_union
+ = (interface_type == GI_INFO_TYPE_STRUCT
+ || interface_type == GI_INFO_TYPE_UNION);
+
+ /* this test ignores non-objects being sent where interfaces
+ are expected
+ hopefully our type manipluation code will pick that up.
+ The only exception to this is GObject.GValues which are
+ arrays.
+ */
+ if (!is_gvalue && is_struct_or_union && arg_is_object
+ && (seed_pointer_get_pointer(ctx, arguments[i]) == 0)) {
+ is_null = TRUE;
+ }
+ g_base_info_unref(interface);
}
- if (is_null)
- {
- GIBaseInfo *ctr = g_base_info_get_container((GIBaseInfo *) info);
- // note - ctr does not need unref'ing (see ginfo.c source for why)
-
- // RE-INSTATE THIS CODE LATER.. - when gtk etc. has be release with fixes
- //seed_make_exception (ctx, exception,
- // "ArgumentError",
- g_warning( "ArgumentError - probably due to incorrect gir file (which may be fixed
upstream)"
- " argument %d must not be null for"
- " function: %s%s%s \n",
- i + 1,
- ctr ? g_base_info_get_name ((GIBaseInfo *) ctr) : "",
- ctr ? "." : "",
- g_base_info_get_name ((GIBaseInfo *)
- info));
- //goto arg_error;
+ if (is_null) {
+ GIBaseInfo* ctr
+ = g_base_info_get_container((GIBaseInfo*) info);
+ // note - ctr does not need unref'ing (see ginfo.c source
+ // for why)
+
+ // RE-INSTATE THIS CODE LATER.. - when gtk etc. has be
+ // release with fixes
+ // seed_make_exception (ctx, exception,
+ // "ArgumentError",
+ g_warning("ArgumentError - probably due to incorrect gir "
+ "file (which may be fixed upstream)"
+ " argument %d must not be null for"
+ " function: %s%s%s \n",
+ i + 1,
+ ctr ? g_base_info_get_name((GIBaseInfo*) ctr)
+ : "",
+ ctr ? "." : "",
+ g_base_info_get_name((GIBaseInfo*) info));
+ // goto arg_error;
}
}
- if (!seed_value_to_gi_argument (ctx, arguments[i], type_info, transfer,
- &in_args[n_in_args++], exception))
- {
- seed_make_exception (ctx, exception,
- "ArgumentError",
- "Unable to make argument %d for"
- " function: %s. \n",
- i + 1,
- g_base_info_get_name ((GIBaseInfo *)
- info));
-
-
- retval_ref = JSValueMakeNull (ctx);
- goto invoke_return;
-
- }
- if (dir == GI_DIRECTION_INOUT)
- {
- GArgument *out_value = &out_values[n_out_args];
- out_args[n_out_args++].v_pointer = out_value;
- out_pos[ i ] = n_out_args;
- }
-
- }
- else if (dir == GI_DIRECTION_OUT)
- {
- GArgument *out_value = &out_values[n_out_args];
- out_values[n_out_args].v_pointer = NULL;
- out_args[n_out_args].v_pointer = out_value;
- out_pos[ i ] = n_out_args;
- if (is_caller_allocates)
- {
- gsize size = g_struct_info_get_size ( (GIStructInfo *) iface_info) ;
- out_args[n_out_args].v_pointer = g_malloc0 (size);
- out_values[n_out_args].v_pointer = out_args[n_out_args].v_pointer;
- caller_allocated[i] = TRUE;
-
- }
- n_out_args++;
- first_out = first_out > -1 ? first_out : i;
-
- }
-
- g_base_info_unref ((GIBaseInfo *) type_info);
- g_base_info_unref ((GIBaseInfo *) arg_info);
- if (iface_info) g_base_info_unref (iface_info);
- iface_info = NULL;
- type_info = NULL;
- arg_info = NULL;
+ if (!seed_value_to_gi_argument(ctx, arguments[i], type_info,
+ transfer, &in_args[n_in_args++],
+ exception)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Unable to make argument %d for"
+ " function: %s. \n",
+ i + 1,
+ g_base_info_get_name((GIBaseInfo*) info));
+
+ retval_ref = JSValueMakeNull(ctx);
+ goto invoke_return;
+ }
+ if (dir == GI_DIRECTION_INOUT) {
+ GArgument* out_value = &out_values[n_out_args];
+ out_args[n_out_args++].v_pointer = out_value;
+ out_pos[i] = n_out_args;
+ }
+
+ } else if (dir == GI_DIRECTION_OUT) {
+ GArgument* out_value = &out_values[n_out_args];
+ out_values[n_out_args].v_pointer = NULL;
+ out_args[n_out_args].v_pointer = out_value;
+ out_pos[i] = n_out_args;
+ if (is_caller_allocates) {
+ gsize size = g_struct_info_get_size((GIStructInfo*) iface_info);
+ out_args[n_out_args].v_pointer = g_malloc0(size);
+ out_values[n_out_args].v_pointer
+ = out_args[n_out_args].v_pointer;
+ caller_allocated[i] = TRUE;
+ }
+ n_out_args++;
+ first_out = first_out > -1 ? first_out : i;
+ }
+
+ g_base_info_unref((GIBaseInfo*) type_info);
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ if (iface_info)
+ g_base_info_unref(iface_info);
+ iface_info = NULL;
+ type_info = NULL;
+ arg_info = NULL;
}
-
-
- // --- Finished building the args, now call the method / function.
-
-
- SEED_NOTE (INVOCATION, "Invoking method: %s with %d 'in' arguments"
- " and %d 'out' arguments",
- g_base_info_get_name (info), n_in_args, n_out_args);
- if (!g_function_info_invoke ((GIFunctionInfo *) info,
- in_args,
- n_in_args,
- out_args, n_out_args, &retval, &error))
- {
-
- // failed...
- seed_make_exception_from_gerror (ctx, exception, error);
- g_error_free (error);
- retval_ref = JSValueMakeNull (ctx);
- goto invoke_return;
-
+
+ // --- Finished building the args, now call the method / function.
+
+ SEED_NOTE(INVOCATION, "Invoking method: %s with %d 'in' arguments"
+ " and %d 'out' arguments",
+ g_base_info_get_name(info), n_in_args, n_out_args);
+ if (!g_function_info_invoke((GIFunctionInfo*) info, in_args, n_in_args,
+ out_args, n_out_args, &retval, &error)) {
+
+ // failed...
+ seed_make_exception_from_gerror(ctx, exception, error);
+ g_error_free(error);
+ retval_ref = JSValueMakeNull(ctx);
+ goto invoke_return;
}
-
- // -- returned OK..
-
- type_info = g_callable_info_get_return_type ((GICallableInfo *) info);
- tag = g_type_info_get_tag (type_info);
+
+ // -- returned OK..
+
+ type_info = g_callable_info_get_return_type((GICallableInfo*) info);
+ tag = g_type_info_get_tag(type_info);
// might need to add g_type_info_is_pointer (type_info) check here..
-
- if (tag == GI_TYPE_TAG_VOID)
- {
- // if we have no out args - returns undefined
- // otherwise we return an object, and put the return values into that
- // along with supporting the old object.value way
- if (n_out_args < 1)
- retval_ref = JSValueMakeUndefined (ctx);
- else
- {
- retval_ref = JSObjectMake (ctx, NULL, NULL);
- use_return_as_out = 1;
- }
- }
- else
- {
-
- // not a void return.
-
- GIBaseInfo *interface;
- gboolean sunk = FALSE;
-
- // for most returns we just pump it though our type convert calls.
- // however gobjects are different, if they are not owned by anybody,
- // then we add a ref so that it can not be destroyed during this process.
- // this ref is removed after we have converted it to a JSObject.
-
- if (tag == GI_TYPE_TAG_INTERFACE)
- {
- GIInfoType interface_type;
-
- interface = g_type_info_get_interface (type_info);
- interface_type = g_base_info_get_type (interface);
- g_base_info_unref (interface);
-
- if (interface_type == GI_INFO_TYPE_OBJECT ||
- interface_type == GI_INFO_TYPE_INTERFACE)
- {
- if (G_IS_OBJECT (retval.v_pointer))
- {
- sunk =
- G_IS_INITIALLY_UNOWNED (G_OBJECT (retval.v_pointer));
- if (sunk)
- g_object_ref_sink (G_OBJECT (retval.v_pointer));
- }
- }
-
- }
-
- length_arg_pos = g_type_info_get_array_length(type_info);
- SEED_NOTE (INVOCATION, "length_arg_pos=%d\n", length_arg_pos);
- if (length_arg_pos < 0)
- {
- array_len = 0;
- }
- else
- {
- array_len = (&out_values[ out_pos[length_arg_pos] ])->v_uint32;
- }
- SEED_NOTE (INVOCATION, "array_len=%" G_GUINT64_FORMAT "\n", array_len);
- retval_ref =
- seed_value_from_gi_argument_full (ctx, &retval, type_info, exception,
- array_len, tag);
-
- if (sunk)
- g_object_unref (G_OBJECT (retval.v_pointer));
- else
- seed_gi_release_arg (g_callable_info_get_caller_owns
- ((GICallableInfo *) info),
- type_info, &retval);
- }
- if (type_info) g_base_info_unref ((GIBaseInfo *) type_info);
- type_info = NULL;
-
-
- // finished with return.. now go thorugh the args and handle any out/inout etc..
-
- in_args_pos = out_args_pos = 0;
- for (i = 0; (i < n_args); i++)
- {
- JSValueRef jsout_val;
- arg_info = g_callable_info_get_arg ((GICallableInfo *) info, i);
- dir = g_arg_info_get_direction (arg_info);
- type_info = g_arg_info_get_type (arg_info);
- // since we succesfully called, we can presume that
-
- if (dir == GI_DIRECTION_IN || dir == GI_DIRECTION_INOUT)
- {
- seed_gi_release_in_arg (g_arg_info_get_ownership_transfer
- (arg_info), type_info,
- &in_args[in_args_pos +
- (instance_method ? 1 : 0)]);
- in_args_pos++;
-
- g_base_info_unref ((GIBaseInfo *) type_info);
- g_base_info_unref ((GIBaseInfo *) arg_info);
- type_info = NULL;
- arg_info = NULL;
-
- continue;
- }
-
- // we are now only dealing with OUT arguments.
-
- // if the type_info is an array with a length position, we
- // need to send that as well, so it can be used to build the seed value.
- {
- length_arg_pos = g_type_info_get_array_length(type_info);
- array_len = 0;
- if (length_arg_pos > -1) {
- GIArgInfo *array_arg_info;
- GITypeInfo *array_type_info;
- GArgument *array_len_arg;
-
- g_assert (out_pos[length_arg_pos] > -1);
-
-
- array_arg_info = g_callable_info_get_arg ((GICallableInfo *) info, length_arg_pos);
- array_type_info = g_arg_info_get_type (array_arg_info);
-
- array_len_arg = &out_values[ out_pos[length_arg_pos] ] ;
-
+
+ if (tag == GI_TYPE_TAG_VOID) {
+ // if we have no out args - returns undefined
+ // otherwise we return an object, and put the return values into that
+ // along with supporting the old object.value way
+ if (n_out_args < 1)
+ retval_ref = JSValueMakeUndefined(ctx);
+ else {
+ retval_ref = JSObjectMake(ctx, NULL, NULL);
+ use_return_as_out = 1;
+ }
+ } else {
+
+ // not a void return.
+
+ GIBaseInfo* interface;
+ gboolean sunk = FALSE;
+
+ // for most returns we just pump it though our type convert calls.
+ // however gobjects are different, if they are not owned by anybody,
+ // then we add a ref so that it can not be destroyed during this
+ // process.
+ // this ref is removed after we have converted it to a JSObject.
+
+ if (tag == GI_TYPE_TAG_INTERFACE) {
+ GIInfoType interface_type;
+
+ interface = g_type_info_get_interface(type_info);
+ interface_type = g_base_info_get_type(interface);
+ g_base_info_unref(interface);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE) {
+ if (G_IS_OBJECT(retval.v_pointer)) {
+ sunk = G_IS_INITIALLY_UNOWNED(G_OBJECT(retval.v_pointer));
+ if (sunk)
+ g_object_ref_sink(G_OBJECT(retval.v_pointer));
+ }
+ }
+ }
+
+ length_arg_pos = g_type_info_get_array_length(type_info);
+ SEED_NOTE(INVOCATION, "length_arg_pos=%d\n", length_arg_pos);
+ if (length_arg_pos < 0) {
array_len = 0;
- switch( g_type_info_get_tag (array_type_info) )
- {
- // not sure if the non-unsigned versions are need as length should not be -ve..
- case GI_TYPE_TAG_INT8: array_len = (guint64) array_len_arg->v_int8; break;
- case GI_TYPE_TAG_UINT8:array_len = (guint64) array_len_arg->v_uint8; break;
- case GI_TYPE_TAG_INT16: array_len =(guint64) array_len_arg->v_int16; break;
- case GI_TYPE_TAG_UINT16: array_len =(guint64) array_len_arg->v_uint16; break;
- case GI_TYPE_TAG_INT32: array_len =(guint64) array_len_arg->v_int32; break;
- case GI_TYPE_TAG_UINT32: array_len =(guint64) array_len_arg->v_uint32; break;
- case GI_TYPE_TAG_INT64: array_len = (guint64) array_len_arg->v_int64; break;
- case GI_TYPE_TAG_UINT64: array_len = (guint64) array_len_arg->v_uint64; break;
- default: g_assert(1==0); break;
-
- }
-
- // this may work, but the above should be more accurate..
- //array_len = (&out_values[ out_pos[length_arg_pos] ])->v_uint32;
-
- SEED_NOTE (INVOCATION, "Getting length from OUTPOS=%d, ORIGPOS=%d : result = %"
G_GUINT64_FORMAT,
- out_pos[length_arg_pos], length_arg_pos, array_len);
- // free stuff.
-
- g_base_info_unref ((GIBaseInfo *) array_type_info);
- g_base_info_unref ((GIBaseInfo *) array_arg_info);
-
- }
-
-
- jsout_val = seed_value_from_gi_argument_full (ctx, &out_values[out_args_pos],
- type_info, exception, array_len, g_type_info_get_tag
(type_info) );
-
- }
- /* caller allocates only applies to structures but GI has
- * no way to denote that yet, so we only use caller allocates
- * if we see a structure
- */
-
- if (caller_allocated[i]) {
-
- // this is the old python code..
- // if we are going to do this, the caching the iface_info at the top would be a better idea.
-
- //if (g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *) iface_info) == G_TYPE_VALUE)
- // g_value_unset ( (GValue *) state->args[i]);
-
-
- // clear the caller allocated flag so it's not free'd at the end..
- caller_allocated[i] = FALSE;
- }
-
-
- // old ? depreciated ? way to handle out args -> set 'value' on object that was send through.
- out_args_pos++;
-
- if ( (i < argumentCount) &&
- !JSValueIsNull (ctx, arguments[i]) &&
- JSValueIsObject (ctx, arguments[i]))
- {
- seed_object_set_property (ctx, (JSObjectRef) arguments[i],
- "value", jsout_val);
+ } else {
+ array_len = (&out_values[out_pos[length_arg_pos]])->v_uint32;
}
+ SEED_NOTE(INVOCATION, "array_len=%" G_GUINT64_FORMAT "\n", array_len);
+ retval_ref
+ = seed_value_from_gi_argument_full(ctx, &retval, type_info, exception,
+ array_len, tag);
+
+ if (sunk)
+ g_object_unref(G_OBJECT(retval.v_pointer));
+ else
+ seed_gi_release_arg(g_callable_info_get_caller_owns(
+ (GICallableInfo*) info),
+ type_info, &retval);
+ }
+ if (type_info)
+ g_base_info_unref((GIBaseInfo*) type_info);
+ type_info = NULL;
+ // finished with return.. now go thorugh the args and handle any out/inout
+ // etc..
+
+ in_args_pos = out_args_pos = 0;
+ for (i = 0; (i < n_args); i++) {
+ JSValueRef jsout_val;
+ arg_info = g_callable_info_get_arg((GICallableInfo*) info, i);
+ dir = g_arg_info_get_direction(arg_info);
+ type_info = g_arg_info_get_type(arg_info);
+ // since we succesfully called, we can presume that
+
+ if (dir == GI_DIRECTION_IN || dir == GI_DIRECTION_INOUT) {
+ seed_gi_release_in_arg(
+ g_arg_info_get_ownership_transfer(arg_info), type_info,
+ &in_args[in_args_pos + (instance_method ? 1 : 0)]);
+ in_args_pos++;
+
+ g_base_info_unref((GIBaseInfo*) type_info);
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ type_info = NULL;
+ arg_info = NULL;
+
+ continue;
+ }
- // if we add it to the return argument and/or the first out arguement
+ // we are now only dealing with OUT arguments.
- if (use_return_as_out)
+ // if the type_info is an array with a length position, we
+ // need to send that as well, so it can be used to build the seed value.
{
- seed_object_set_property (ctx, (JSObjectRef) retval_ref,
- g_base_info_get_name((GIBaseInfo*) arg_info) , jsout_val);
+ length_arg_pos = g_type_info_get_array_length(type_info);
+ array_len = 0;
+ if (length_arg_pos > -1) {
+ GIArgInfo* array_arg_info;
+ GITypeInfo* array_type_info;
+ GArgument* array_len_arg;
+
+ g_assert(out_pos[length_arg_pos] > -1);
+
+ array_arg_info = g_callable_info_get_arg((GICallableInfo*) info,
+ length_arg_pos);
+ array_type_info = g_arg_info_get_type(array_arg_info);
+
+ array_len_arg = &out_values[out_pos[length_arg_pos]];
+
+ array_len = 0;
+ switch (g_type_info_get_tag(array_type_info)) {
+ // not sure if the non-unsigned versions are need as length
+ // should not be -ve..
+ case GI_TYPE_TAG_INT8:
+ array_len = (guint64) array_len_arg->v_int8;
+ break;
+ case GI_TYPE_TAG_UINT8:
+ array_len = (guint64) array_len_arg->v_uint8;
+ break;
+ case GI_TYPE_TAG_INT16:
+ array_len = (guint64) array_len_arg->v_int16;
+ break;
+ case GI_TYPE_TAG_UINT16:
+ array_len = (guint64) array_len_arg->v_uint16;
+ break;
+ case GI_TYPE_TAG_INT32:
+ array_len = (guint64) array_len_arg->v_int32;
+ break;
+ case GI_TYPE_TAG_UINT32:
+ array_len = (guint64) array_len_arg->v_uint32;
+ break;
+ case GI_TYPE_TAG_INT64:
+ array_len = (guint64) array_len_arg->v_int64;
+ break;
+ case GI_TYPE_TAG_UINT64:
+ array_len = (guint64) array_len_arg->v_uint64;
+ break;
+ default:
+ g_assert(1 == 0);
+ break;
+ }
+
+ // this may work, but the above should be more accurate..
+ // array_len = (&out_values[ out_pos[length_arg_pos]
+ // ])->v_uint32;
+
+ SEED_NOTE(INVOCATION,
+ "Getting length from OUTPOS=%d, ORIGPOS=%d : "
+ "result = %" G_GUINT64_FORMAT,
+ out_pos[length_arg_pos], length_arg_pos, array_len);
+ // free stuff.
+
+ g_base_info_unref((GIBaseInfo*) array_type_info);
+ g_base_info_unref((GIBaseInfo*) array_arg_info);
+ }
+
+ jsout_val = seed_value_from_gi_argument_full(
+ ctx, &out_values[out_args_pos], type_info, exception, array_len,
+ g_type_info_get_tag(type_info));
}
-
+ /* caller allocates only applies to structures but GI has
+ * no way to denote that yet, so we only use caller allocates
+ * if we see a structure
+ */
- if ( (first_out > -1) &&
- !JSValueIsNull (ctx, arguments[first_out]) &&
- JSValueIsObject (ctx, arguments[first_out]) )
-
- {
- seed_object_set_property (ctx, (JSObjectRef) arguments[first_out],
- g_base_info_get_name((GIBaseInfo*) arg_info) , jsout_val);
+ if (caller_allocated[i]) {
+
+ // this is the old python code..
+ // if we are going to do this, the caching the iface_info at the top
+ // would be a better idea.
+
+ // if (g_registered_type_info_get_g_type ( (GIRegisteredTypeInfo *)
+ // iface_info) == G_TYPE_VALUE)
+ // g_value_unset ( (GValue *) state->args[i]);
+
+ // clear the caller allocated flag so it's not free'd at the end..
+ caller_allocated[i] = FALSE;
+ }
+
+ // old ? depreciated ? way to handle out args -> set 'value' on object
+ // that was send through.
+ out_args_pos++;
+
+ if ((i < argumentCount) && !JSValueIsNull(ctx, arguments[i])
+ && JSValueIsObject(ctx, arguments[i])) {
+ seed_object_set_property(ctx, (JSObjectRef) arguments[i], "value",
+ jsout_val);
}
+ // if we add it to the return argument and/or the first out arguement
+
+ if (use_return_as_out) {
+ seed_object_set_property(ctx, (JSObjectRef) retval_ref,
+ g_base_info_get_name(
+ (GIBaseInfo*) arg_info),
+ jsout_val);
+ }
+
+ if ((first_out > -1) && !JSValueIsNull(ctx, arguments[first_out])
+ && JSValueIsObject(ctx, arguments[first_out]))
+
+ {
+ seed_object_set_property(ctx, (JSObjectRef) arguments[first_out],
+ g_base_info_get_name(
+ (GIBaseInfo*) arg_info),
+ jsout_val);
+ }
- g_base_info_unref ((GIBaseInfo *) arg_info);
- g_base_info_unref ((GIBaseInfo *) type_info);
- type_info = NULL;
- arg_info = NULL;
-
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ g_base_info_unref((GIBaseInfo*) type_info);
+ type_info = NULL;
+ arg_info = NULL;
}
invoke_return:
-// clean up everything..
- for (i = 0; (i < (n_args)); i++)
- if (caller_allocated[i])
- g_free(out_args[out_pos[i]].v_pointer);
-
- g_free(caller_allocated);
-
- if (type_info) g_base_info_unref ((GIBaseInfo *) type_info);
- if (arg_info) g_base_info_unref ((GIBaseInfo *) arg_info);
- if (iface_info) g_base_info_unref (iface_info);
-
- g_free (in_args);
- g_free (out_args);
- g_free (out_pos);
- g_free (out_values);
- return retval_ref;
-
-
-
-
+ // clean up everything..
+ for (i = 0; (i < (n_args)); i++)
+ if (caller_allocated[i])
+ g_free(out_args[out_pos[i]].v_pointer);
+
+ g_free(caller_allocated);
+
+ if (type_info)
+ g_base_info_unref((GIBaseInfo*) type_info);
+ if (arg_info)
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ if (iface_info)
+ g_base_info_unref(iface_info);
+
+ g_free(in_args);
+ g_free(out_args);
+ g_free(out_pos);
+ g_free(out_values);
+ return retval_ref;
}
static JSObjectRef
-seed_gobject_named_constructor_invoked (JSContextRef ctx,
- JSObjectRef constructor,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_named_constructor_invoked(JSContextRef ctx,
+ JSObjectRef constructor,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- return (JSObjectRef) seed_gobject_method_invoked (ctx, constructor,
- NULL, argumentCount,
- arguments, exception);
+ return (JSObjectRef) seed_gobject_method_invoked(ctx, constructor, NULL,
+ argumentCount, arguments,
+ exception);
}
void
-seed_gobject_define_property_from_function_info (JSContextRef ctx,
- GIFunctionInfo * info,
- JSObjectRef object,
- gboolean instance)
+seed_gobject_define_property_from_function_info(JSContextRef ctx,
+ GIFunctionInfo* info,
+ JSObjectRef object,
+ gboolean instance)
{
- GIFunctionInfoFlags flags;
- JSObjectRef method_ref;
- const gchar *name;
+ GIFunctionInfoFlags flags;
+ JSObjectRef method_ref;
+ const gchar* name;
- //if (g_base_info_is_deprecated ((GIBaseInfo *) info))
- //g_printf("Not defining deprecated symbol: %s \n",
- //g_base_info_get_name((GIBaseInfo *)info));
+ // if (g_base_info_is_deprecated ((GIBaseInfo *) info))
+ // g_printf("Not defining deprecated symbol: %s \n",
+ // g_base_info_get_name((GIBaseInfo *)info));
- flags = g_function_info_get_flags (info);
+ flags = g_function_info_get_flags(info);
- if (instance && (flags & GI_FUNCTION_IS_CONSTRUCTOR))
- {
- return;
+ if (instance && (flags & GI_FUNCTION_IS_CONSTRUCTOR)) {
+ return;
}
- method_ref = JSObjectMake (ctx, gobject_method_class,
- g_base_info_ref ((GIBaseInfo *) info));
-
- JSObjectSetPrototype (ctx, method_ref, function_proto);
-
- name = g_base_info_get_name ((GIBaseInfo *) info);
- if (!g_strcmp0 (name, "new")) {
- // To be compatible with gjs, we need to have new as function, too.
- seed_object_set_property (ctx, object, name, method_ref);
- name = "c_new";
- }
- seed_object_set_property (ctx, object, name, method_ref);
- /*
- // Disabled as this crashes in a recursive loop now
- seed_object_set_property (ctx, method_ref, "info",
- seed_make_struct (ctx,
- g_base_info_ref ((GIBaseInfo *)
- info),
- base_info_info));
- */
+ method_ref = JSObjectMake(ctx, gobject_method_class,
+ g_base_info_ref((GIBaseInfo*) info));
+
+ JSObjectSetPrototype(ctx, method_ref, function_proto);
+
+ name = g_base_info_get_name((GIBaseInfo*) info);
+ if (!g_strcmp0(name, "new")) {
+ // To be compatible with gjs, we need to have new as function, too.
+ seed_object_set_property(ctx, object, name, method_ref);
+ name = "c_new";
+ }
+ seed_object_set_property(ctx, object, name, method_ref);
+ /*
+ // Disabled as this crashes in a recursive loop now
+ seed_object_set_property (ctx, method_ref, "info",
+ seed_make_struct (ctx,
+ g_base_info_ref ((GIBaseInfo *)
+ info),
+ base_info_info));
+ */
}
static void
-seed_gobject_add_methods_for_interfaces (JSContextRef ctx,
- GIObjectInfo * oinfo,
- JSObjectRef object)
+seed_gobject_add_methods_for_interfaces(JSContextRef ctx,
+ GIObjectInfo* oinfo,
+ JSObjectRef object)
{
- GIInterfaceInfo *interface;
- GIFunctionInfo *function;
- gint n_interfaces, i, n_functions, k;
+ GIInterfaceInfo* interface;
+ GIFunctionInfo* function;
+ gint n_interfaces, i, n_functions, k;
- n_interfaces = g_object_info_get_n_interfaces (oinfo);
+ n_interfaces = g_object_info_get_n_interfaces(oinfo);
- for (i = 0; i < n_interfaces; i++)
- {
- interface = g_object_info_get_interface (oinfo, i);
-
- n_functions = g_interface_info_get_n_methods (interface);
- for (k = 0; k < n_functions; k++)
- {
- function = g_interface_info_get_method (interface, k);
- seed_gobject_define_property_from_function_info
- (ctx, function, object, TRUE);
- }
- g_base_info_unref((GIBaseInfo*)interface);
+ for (i = 0; i < n_interfaces; i++) {
+ interface = g_object_info_get_interface(oinfo, i);
+
+ n_functions = g_interface_info_get_n_methods(interface);
+ for (k = 0; k < n_functions; k++) {
+ function = g_interface_info_get_method(interface, k);
+ seed_gobject_define_property_from_function_info(ctx, function,
+ object, TRUE);
+ }
+ g_base_info_unref((GIBaseInfo*) interface);
}
}
static void
-seed_gobject_add_methods_for_type (JSContextRef ctx,
- GIObjectInfo * oinfo, JSObjectRef object)
+seed_gobject_add_methods_for_type(JSContextRef ctx,
+ GIObjectInfo* oinfo,
+ JSObjectRef object)
{
- gint n_methods;
- gint i;
- GIFunctionInfo *info;
+ gint n_methods;
+ gint i;
+ GIFunctionInfo* info;
- n_methods = g_object_info_get_n_methods (oinfo);
+ n_methods = g_object_info_get_n_methods(oinfo);
- for (i = 0; i < n_methods; i++)
- {
- info = g_object_info_get_method (oinfo, i);
- seed_gobject_define_property_from_function_info (ctx,
- info, object, TRUE);
- g_base_info_unref ((GIBaseInfo *) info);
+ for (i = 0; i < n_methods; i++) {
+ info = g_object_info_get_method(oinfo, i);
+ seed_gobject_define_property_from_function_info(ctx, info, object,
+ TRUE);
+ g_base_info_unref((GIBaseInfo*) info);
}
}
JSClassRef
-seed_gobject_get_class_for_gtype (JSContextRef ctx, GType type)
+seed_gobject_get_class_for_gtype(JSContextRef ctx, GType type)
{
- JSClassDefinition def;
- GType parent;
- JSClassRef ref;
- JSClassRef parent_class = 0;
- GIBaseInfo *info;
- JSObjectRef prototype_obj;
- JSObjectRef parent_prototype;
-
- if ((ref = g_type_get_qdata (type, qname)) != NULL)
- {
- return ref;
+ JSClassDefinition def;
+ GType parent;
+ JSClassRef ref;
+ JSClassRef parent_class = 0;
+ GIBaseInfo* info;
+ JSObjectRef prototype_obj;
+ JSObjectRef parent_prototype;
+
+ if ((ref = g_type_get_qdata(type, qname)) != NULL) {
+ return ref;
}
- info = g_irepository_find_by_gtype (g_irepository_get_default (), type);
+ info = g_irepository_find_by_gtype(g_irepository_get_default(), type);
- memset (&def, 0, sizeof (JSClassDefinition));
+ memset(&def, 0, sizeof(JSClassDefinition));
- def.className = g_type_name (type);
- if ((parent = g_type_parent (type)))
- parent_class = seed_gobject_get_class_for_gtype (ctx, parent);
- def.parentClass = parent_class;
- def.attributes = kJSClassAttributeNoAutomaticPrototype;
+ def.className = g_type_name(type);
+ if ((parent = g_type_parent(type)))
+ parent_class = seed_gobject_get_class_for_gtype(ctx, parent);
+ def.parentClass = parent_class;
+ def.attributes = kJSClassAttributeNoAutomaticPrototype;
- prototype_obj = JSObjectMake (ctx, 0, 0);
- if (parent)
- {
- parent_prototype = seed_gobject_get_prototype_for_gtype (parent);
- if (parent_prototype)
- JSObjectSetPrototype (ctx, prototype_obj, parent_prototype);
+ prototype_obj = JSObjectMake(ctx, 0, 0);
+ if (parent) {
+ parent_prototype = seed_gobject_get_prototype_for_gtype(parent);
+ if (parent_prototype)
+ JSObjectSetPrototype(ctx, prototype_obj, parent_prototype);
}
- ref = JSClassCreate (&def);
- JSClassRetain (ref);
-
- JSValueProtect (ctx, prototype_obj);
-
- g_type_set_qdata (type, qname, ref);
- g_type_set_qdata (type, qprototype, prototype_obj);
-
- if (info && (g_base_info_get_type (info) == GI_INFO_TYPE_OBJECT))
- {
- seed_gobject_add_methods_for_interfaces (ctx, (GIObjectInfo *) info,
- prototype_obj);
- seed_gobject_add_methods_for_type (ctx,
- (GIObjectInfo *) info,
- prototype_obj);
- g_base_info_unref (info);
- }
- else
- {
- GType *interfaces;
- GIFunctionInfo *function;
- GIBaseInfo *interface;
- gint n_functions, k;
- guint i, n;
-
- interfaces = g_type_interfaces (type, &n);
- for (i = 0; i < n; i++)
- {
- interface = g_irepository_find_by_gtype (0, interfaces[i]);
- if (!interface)
- break;
- n_functions =
- g_interface_info_get_n_methods ((GIInterfaceInfo *) interface);
- for (k = 0; k < n_functions; k++)
- {
- function =
- g_interface_info_get_method ((GIInterfaceInfo
- *) interface, k);
- seed_gobject_define_property_from_function_info
- (ctx, function, prototype_obj, TRUE);
- }
- }
+ ref = JSClassCreate(&def);
+ JSClassRetain(ref);
+
+ JSValueProtect(ctx, prototype_obj);
+
+ g_type_set_qdata(type, qname, ref);
+ g_type_set_qdata(type, qprototype, prototype_obj);
+
+ if (info && (g_base_info_get_type(info) == GI_INFO_TYPE_OBJECT)) {
+ seed_gobject_add_methods_for_interfaces(ctx, (GIObjectInfo*) info,
+ prototype_obj);
+ seed_gobject_add_methods_for_type(ctx, (GIObjectInfo*) info,
+ prototype_obj);
+ g_base_info_unref(info);
+ } else {
+ GType* interfaces;
+ GIFunctionInfo* function;
+ GIBaseInfo* interface;
+ gint n_functions, k;
+ guint i, n;
+
+ interfaces = g_type_interfaces(type, &n);
+ for (i = 0; i < n; i++) {
+ interface = g_irepository_find_by_gtype(0, interfaces[i]);
+ if (!interface)
+ break;
+ n_functions
+ = g_interface_info_get_n_methods((GIInterfaceInfo*) interface);
+ for (k = 0; k < n_functions; k++) {
+ function
+ = g_interface_info_get_method((GIInterfaceInfo*) interface,
+ k);
+ seed_gobject_define_property_from_function_info(ctx, function,
+ prototype_obj,
+ TRUE);
+ }
+ }
}
- return ref;
+ return ref;
}
JSObjectRef
-seed_gobject_get_prototype_for_gtype (GType type)
+seed_gobject_get_prototype_for_gtype(GType type)
{
- JSObjectRef prototype = 0;
- while (type && !prototype)
- {
- prototype = g_type_get_qdata (type, qprototype);
- type = g_type_parent (type);
+ JSObjectRef prototype = 0;
+ while (type && !prototype) {
+ prototype = g_type_get_qdata(type, qprototype);
+ type = g_type_parent(type);
}
- return prototype;
+ return prototype;
}
static void
-seed_gobject_finalize (JSObjectRef object)
+seed_gobject_finalize(JSObjectRef object)
{
- GObject *gobject;
- JSObjectRef js_ref;
-
- gobject = (GObject *) JSObjectGetPrivate ((JSObjectRef) object);
- if (!gobject)
- {
- SEED_NOTE (FINALIZATION,
- "Attempting to finalize already destroyed object.");
- return;
+ GObject* gobject;
+ JSObjectRef js_ref;
+
+ gobject = (GObject*) JSObjectGetPrivate((JSObjectRef) object);
+ if (!gobject) {
+ SEED_NOTE(FINALIZATION,
+ "Attempting to finalize already destroyed object.");
+ return;
}
- SEED_NOTE (FINALIZATION, "%s at %p (%d refs)",
- g_type_name (G_OBJECT_TYPE (gobject)), gobject,
- gobject->ref_count);
-
- js_ref = g_object_get_qdata (gobject, js_ref_quark);
- if (js_ref)
- {
- /* Steal the qdata here as otherwise we will call
- * JSValueUnprotect() from the destroy notify of
- * the qdata, which is not allowed to be called
- * from a finalizer!
- */
- g_object_steal_qdata (gobject, js_ref_quark);
-
- g_object_remove_toggle_ref (gobject, seed_toggle_ref, js_ref);
- }
- else
- {
- g_object_run_dispose (gobject);
+ SEED_NOTE(FINALIZATION, "%s at %p (%d refs)",
+ g_type_name(G_OBJECT_TYPE(gobject)), gobject, gobject->ref_count);
+
+ js_ref = g_object_get_qdata(gobject, js_ref_quark);
+ if (js_ref) {
+ /* Steal the qdata here as otherwise we will call
+ * JSValueUnprotect() from the destroy notify of
+ * the qdata, which is not allowed to be called
+ * from a finalizer!
+ */
+ g_object_steal_qdata(gobject, js_ref_quark);
+
+ g_object_remove_toggle_ref(gobject, seed_toggle_ref, js_ref);
+ } else {
+ g_object_run_dispose(gobject);
}
}
static JSValueRef
-seed_gobject_get_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_gobject_get_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- GParamSpec *spec;
- GObject *b;
- GValue gval = { 0 };
- char *cproperty_name;
- gint length;
- JSValueRef ret;
- guint i;
- gsize len;
-
- b = seed_value_to_object (context, (JSValueRef) object, exception);
- if (!b)
- return 0;
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- spec =
- g_object_class_find_property (G_OBJECT_GET_CLASS (b), cproperty_name);
-
- if (!spec)
- {
- len = strlen (cproperty_name) - 1;
- for (i = 0; i < len; i++)
- {
- if (cproperty_name[i] == '_')
- cproperty_name[i] = '-';
- }
- spec = g_object_class_find_property (G_OBJECT_GET_CLASS (b),
- cproperty_name);
- if (spec)
- goto found;
- else
- {
- GIFieldInfo *field = NULL;
- GIBaseInfo *info = (GIBaseInfo *)
- g_irepository_find_by_gtype (0, G_OBJECT_TYPE (b));
- gint n;
- const gchar *name;
-
- for (i = 0; i < len; i++)
- {
- if (cproperty_name[i] == '-')
- cproperty_name[i] = '_';
- }
-
- if (!info)
- {
- return NULL;
- }
-
- n = g_object_info_get_n_fields ((GIObjectInfo *) info);
- for (i = 0; i < n; i++)
- {
- field = g_object_info_get_field ((GIObjectInfo *) info, i);
- name = g_base_info_get_name ((GIBaseInfo *) field);
-
- if (!g_strcmp0 (name, cproperty_name))
- goto found_field;
- else
- {
- g_base_info_unref ((GIBaseInfo *) field);
- field = 0;
- }
- }
- found_field:
- if (field)
- {
- ret = seed_field_get_value (context, b, field, exception);
- g_base_info_unref ((GIBaseInfo *) info);
- return ret;
- }
- g_base_info_unref ((GIBaseInfo *) info);
- }
- return NULL;
+ GParamSpec* spec;
+ GObject* b;
+ GValue gval = { 0 };
+ char* cproperty_name;
+ gint length;
+ JSValueRef ret;
+ guint i;
+ gsize len;
+
+ b = seed_value_to_object(context, (JSValueRef) object, exception);
+ if (!b)
+ return 0;
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ spec = g_object_class_find_property(G_OBJECT_GET_CLASS(b), cproperty_name);
+
+ if (!spec) {
+ len = strlen(cproperty_name) - 1;
+ for (i = 0; i < len; i++) {
+ if (cproperty_name[i] == '_')
+ cproperty_name[i] = '-';
+ }
+ spec
+ = g_object_class_find_property(G_OBJECT_GET_CLASS(b), cproperty_name);
+ if (spec)
+ goto found;
+ else {
+ GIFieldInfo* field = NULL;
+ GIBaseInfo* info
+ = (GIBaseInfo*) g_irepository_find_by_gtype(0, G_OBJECT_TYPE(b));
+ gint n;
+ const gchar* name;
+
+ for (i = 0; i < len; i++) {
+ if (cproperty_name[i] == '-')
+ cproperty_name[i] = '_';
+ }
+
+ if (!info) {
+ return NULL;
+ }
+
+ n = g_object_info_get_n_fields((GIObjectInfo*) info);
+ for (i = 0; i < n; i++) {
+ field = g_object_info_get_field((GIObjectInfo*) info, i);
+ name = g_base_info_get_name((GIBaseInfo*) field);
+
+ if (!g_strcmp0(name, cproperty_name))
+ goto found_field;
+ else {
+ g_base_info_unref((GIBaseInfo*) field);
+ field = 0;
+ }
+ }
+ found_field:
+ if (field) {
+ ret = seed_field_get_value(context, b, field, exception);
+ g_base_info_unref((GIBaseInfo*) info);
+ return ret;
+ }
+ g_base_info_unref((GIBaseInfo*) info);
+ }
+ return NULL;
}
found:
- g_value_init (&gval, spec->value_type);
- g_object_get_property (b, cproperty_name, &gval);
- ret = seed_value_from_gvalue (context, &gval, exception);
- g_value_unset (&gval);
+ g_value_init(&gval, spec->value_type);
+ g_object_get_property(b, cproperty_name, &gval);
+ ret = seed_value_from_gvalue(context, &gval, exception);
+ g_value_unset(&gval);
- return (JSValueRef) ret;
+ return (JSValueRef) ret;
}
static bool
-seed_gobject_set_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name,
- JSValueRef value, JSValueRef * exception)
+seed_gobject_set_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef value,
+ JSValueRef* exception)
{
- GParamSpec *spec = 0;
- GObject *obj;
- GValue gval = { 0 };
- GType type;
- gchar *cproperty_name;
- gsize length;
- gsize i, len;
-
- if (pthread_getspecific(seed_next_gobject_wrapper_key) ||
- JSValueIsNull (context, value))
- return 0;
-
-
- obj = seed_value_to_object (context, object, 0);
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- spec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj),
- cproperty_name);
-
- if (!spec)
- {
- len = strlen (cproperty_name);
- for (i = 0; i < len; i++)
- {
- if (cproperty_name[i] == '_')
- cproperty_name[i] = '-';
- }
- spec = g_object_class_find_property (G_OBJECT_GET_CLASS (obj),
- cproperty_name);
- if (!spec)
- {
- return FALSE;
- }
+ GParamSpec* spec = 0;
+ GObject* obj;
+ GValue gval = { 0 };
+ GType type;
+ gchar* cproperty_name;
+ gsize length;
+ gsize i, len;
+
+ if (pthread_getspecific(seed_next_gobject_wrapper_key)
+ || JSValueIsNull(context, value))
+ return 0;
+
+ obj = seed_value_to_object(context, object, 0);
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ spec
+ = g_object_class_find_property(G_OBJECT_GET_CLASS(obj), cproperty_name);
+
+ if (!spec) {
+ len = strlen(cproperty_name);
+ for (i = 0; i < len; i++) {
+ if (cproperty_name[i] == '_')
+ cproperty_name[i] = '-';
+ }
+ spec = g_object_class_find_property(G_OBJECT_GET_CLASS(obj),
+ cproperty_name);
+ if (!spec) {
+ return FALSE;
+ }
}
- if (g_type_is_a (spec->value_type, G_TYPE_ENUM))
- type = G_TYPE_LONG;
- else
- type = spec->value_type;
+ if (g_type_is_a(spec->value_type, G_TYPE_ENUM))
+ type = G_TYPE_LONG;
+ else
+ type = spec->value_type;
- seed_value_to_gvalue (context, value, type, &gval, exception);
- if (*exception)
- {
- return FALSE;
+ seed_value_to_gvalue(context, value, type, &gval, exception);
+ if (*exception) {
+ return FALSE;
}
- if (glib_message)
- {
- g_free (glib_message);
- glib_message = 0;
+ if (glib_message) {
+ g_free(glib_message);
+ glib_message = 0;
}
- g_object_set_property (obj, cproperty_name, &gval);
- if (glib_message != 0)
- {
- seed_make_exception (context, exception, "PropertyError",
- glib_message, NULL);
+ g_object_set_property(obj, cproperty_name, &gval);
+ if (glib_message != 0) {
+ seed_make_exception(context, exception, "PropertyError", glib_message,
+ NULL);
- return FALSE;
+ return FALSE;
}
- g_value_unset (&gval);
+ g_value_unset(&gval);
- return TRUE;
+ return TRUE;
}
static JSValueRef
-seed_gobject_convert_to_type (JSContextRef ctx,
- JSObjectRef object,
- JSType type, JSValueRef * exception)
+seed_gobject_convert_to_type(JSContextRef ctx,
+ JSObjectRef object,
+ JSType type,
+ JSValueRef* exception)
{
- GObject *obj;
- gchar *as_string;
+ GObject* obj;
+ gchar* as_string;
- if (type == kJSTypeString)
- {
- JSValueRef ret;
- obj = (GObject *) JSObjectGetPrivate (object);
+ if (type == kJSTypeString) {
+ JSValueRef ret;
+ obj = (GObject*) JSObjectGetPrivate(object);
- as_string =
- g_strdup_printf ("[gobject %s %p]", G_OBJECT_TYPE_NAME (obj), obj);
- ret = seed_value_from_string (ctx, as_string, exception);
- g_free (as_string);
+ as_string
+ = g_strdup_printf("[gobject %s %p]", G_OBJECT_TYPE_NAME(obj), obj);
+ ret = seed_value_from_string(ctx, as_string, exception);
+ g_free(as_string);
- return ret;
+ return ret;
}
- return FALSE;
+ return FALSE;
}
static JSValueRef
-seed_gobject_constructor_convert_to_type (JSContextRef ctx,
- JSObjectRef object,
- JSType type, JSValueRef * exception)
+seed_gobject_constructor_convert_to_type(JSContextRef ctx,
+ JSObjectRef object,
+ JSType type,
+ JSValueRef* exception)
{
- GType gtype;
- gchar *as_string;
+ GType gtype;
+ gchar* as_string;
- if (type == kJSTypeString)
- {
- JSValueRef ret;
- gtype = (GType) JSObjectGetPrivate (object);
+ if (type == kJSTypeString) {
+ JSValueRef ret;
+ gtype = (GType) JSObjectGetPrivate(object);
- as_string =
- g_strdup_printf ("[gobject_constructor %s]", g_type_name (gtype));
- ret = seed_value_from_string (ctx, as_string, exception);
- g_free (as_string);
+ as_string
+ = g_strdup_printf("[gobject_constructor %s]", g_type_name(gtype));
+ ret = seed_value_from_string(ctx, as_string, exception);
+ g_free(as_string);
- return ret;
+ return ret;
}
- return FALSE;
+ return FALSE;
}
-JSStaticFunction gobject_static_funcs[] = {
- {"__debug_ref_count", seed_gobject_ref_count, 0}
- ,
- {"__property_type", seed_gobject_property_type, 0}
- ,
- {"connect", seed_gobject_signal_connect_by_name, 0}
- ,
- {0, 0, 0}
-};
+JSStaticFunction gobject_static_funcs[]
+ = { { "__debug_ref_count", seed_gobject_ref_count, 0 },
+ { "__property_type", seed_gobject_property_type, 0 },
+ { "connect", seed_gobject_signal_connect_by_name, 0 },
+ { 0, 0, 0 } };
JSClassDefinition gobject_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
- "gobject", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- gobject_static_funcs, /* Static Functions */
- NULL,
- seed_gobject_finalize, /* Finalize */
- NULL, /* Has Property */
- seed_gobject_get_property, /* Get Property */
- seed_gobject_set_property, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- seed_gobject_convert_to_type /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype, /* JSClassAttributes */
+ "gobject", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ gobject_static_funcs, /* Static Functions */
+ NULL,
+ seed_gobject_finalize, /* Finalize */
+ NULL, /* Has Property */
+ seed_gobject_get_property, /* Get Property */
+ seed_gobject_set_property, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ seed_gobject_convert_to_type /* Convert To Type */
};
JSClassDefinition gobject_method_def = {
- 0, /* Version, always 0 */
- 0,
- "gobject_method", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- seed_gobject_method_finalize, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- seed_gobject_method_invoked, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0,
+ "gobject_method", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ seed_gobject_method_finalize, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ seed_gobject_method_invoked, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition gobject_init_method_def = {
- 0, /* Version, always 0 */
- 0,
- "init_method", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- seed_gobject_method_finalize, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- seed_gobject_init_method_invoked, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0,
+ "init_method", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ seed_gobject_method_finalize, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ seed_gobject_init_method_invoked, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition seed_callback_def = {
- 0, /* Version, always 0 */
- 0,
- "seed_callback", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- NULL, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0, "seed_callback", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, NULL, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
-JSClassDefinition gobject_constructor_def = {
- 0, /* Version, always 0 */
- 0,
- "gobject_constructor", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- NULL, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- seed_gobject_constructor_invoked, /* Call As Constructor */
- seed_gobject_has_instance, /* Has Instance */
- seed_gobject_constructor_convert_to_type
-};
-
-JSClassDefinition gobject_named_constructor_def = {
- 0, /* Version, always 0 */
- 0,
- "gobject_named_constructor", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- NULL, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- // To be compatible with gjs you need to be able to call named
- // constructors without the new in front
- seed_gobject_method_invoked, /* Call As Function */
- seed_gobject_named_constructor_invoked, /* Call As Constructor */
- seed_gobject_has_instance, /* Has Instance */
- seed_gobject_constructor_convert_to_type
-};
+JSClassDefinition gobject_constructor_def
+ = { 0, /* Version, always 0 */
+ 0,
+ "gobject_constructor", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ NULL, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ seed_gobject_constructor_invoked, /* Call As Constructor */
+ seed_gobject_has_instance, /* Has Instance */
+ seed_gobject_constructor_convert_to_type };
+
+JSClassDefinition gobject_named_constructor_def
+ = { 0, /* Version, always 0 */
+ 0, "gobject_named_constructor", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, NULL, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ // To be compatible with gjs you need to be able to call named
+ // constructors without the new in front
+ seed_gobject_method_invoked, /* Call As Function */
+ seed_gobject_named_constructor_invoked, /* Call As Constructor */
+ seed_gobject_has_instance, /* Has Instance */
+ seed_gobject_constructor_convert_to_type };
JSClassDefinition struct_constructor_def = {
- 0, /* Version, always 0 */
- 0,
- "struct_constructor", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- NULL, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- seed_struct_constructor_invoked, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0,
+ "struct_constructor", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ NULL, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ seed_struct_constructor_invoked, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
/**
@@ -1574,7 +1490,7 @@ JSClassDefinition struct_constructor_def = {
* @ctx: A valid #SeedContext
* @name: The name of the function (used in exceptions).
* @func: A #SeedFunctionCallback to implement the function.
- * @obj: The #SeedObject on which to put the function.
+ * @obj: The #SeedObject on which to put the function.
*
* Creates a JavaScript object representing a first-class function; when
* the function is called from JavaScript, @func will be called. Places
@@ -1582,156 +1498,159 @@ JSClassDefinition struct_constructor_def = {
*
*/
void
-seed_create_function (JSContextRef ctx,
- gchar * name, gpointer func, JSObjectRef obj)
+seed_create_function(JSContextRef ctx,
+ gchar* name,
+ gpointer func,
+ JSObjectRef obj)
{
- JSObjectRef oref;
+ JSObjectRef oref;
- oref = JSObjectMakeFunctionWithCallback (ctx, NULL, func);
- seed_object_set_property (ctx, obj, name, oref);
+ oref = JSObjectMakeFunctionWithCallback(ctx, NULL, func);
+ seed_object_set_property(ctx, obj, name, oref);
}
void
-seed_repl_expose (JSContextRef ctx, ...)
+seed_repl_expose(JSContextRef ctx, ...)
{
- va_list argp;
- void *expose;
- JSObjectRef arrayObj;
- guint i = 0;
- JSStringRef script;
- JSObjectRef seed = (JSObjectRef) seed_object_get_property (ctx,
- JSContextGetGlobalObject
- (ctx),
- "Seed");
- va_start (argp, ctx);
-
- arrayObj = JSObjectMake (ctx, NULL, NULL);
-
- g_print ("Seed Debug REPL\n\nExposing:\n");
-
- while ((expose = va_arg (argp, void *)))
- {
- g_print (" Seed.debug_argv[%u] = %p\n", i, expose);
- JSObjectSetPropertyAtIndex (ctx, arrayObj, i++, expose, NULL);
+ va_list argp;
+ void* expose;
+ JSObjectRef arrayObj;
+ guint i = 0;
+ JSStringRef script;
+ JSObjectRef seed
+ = (JSObjectRef) seed_object_get_property(ctx,
+ JSContextGetGlobalObject(ctx),
+ "Seed");
+ va_start(argp, ctx);
+
+ arrayObj = JSObjectMake(ctx, NULL, NULL);
+
+ g_print("Seed Debug REPL\n\nExposing:\n");
+
+ while ((expose = va_arg(argp, void*) )) {
+ g_print(" Seed.debug_argv[%u] = %p\n", i, expose);
+ JSObjectSetPropertyAtIndex(ctx, arrayObj, i++, expose, NULL);
}
- g_print ("\n");
+ g_print("\n");
- seed_object_set_property (ctx, seed, "debug_argv", arrayObj);
+ seed_object_set_property(ctx, seed, "debug_argv", arrayObj);
- script = JSStringCreateWithUTF8CString ("readline = imports.readline;"
- "while(1) { try { print(eval("
- "readline.readline(\"> \"))); } catch(e) {"
- "print(e.name + \" \" + e.message);}}");
+ script = JSStringCreateWithUTF8CString(
+ "readline = imports.readline;"
+ "while(1) { try { print(eval("
+ "readline.readline(\"> \"))); } catch(e) {"
+ "print(e.name + \" \" + e.message);}}");
- JSEvaluateScript (ctx, script, NULL, NULL, 0, NULL);
+ JSEvaluateScript(ctx, script, NULL, NULL, 0, NULL);
- JSStringRelease (script);
+ JSStringRelease(script);
- va_end (argp);
+ va_end(argp);
}
static void
-seed_log_handler (const gchar * domain,
- GLogLevelFlags log_level,
- const gchar * message, gpointer user_data)
+seed_log_handler(const gchar* domain,
+ GLogLevelFlags log_level,
+ const gchar* message,
+ gpointer user_data)
{
- if (glib_message)
- g_free (glib_message);
- glib_message = g_strdup (message);
+ if (glib_message)
+ g_free(glib_message);
+ glib_message = g_strdup(message);
}
#ifdef SEED_ENABLE_DEBUG
static gboolean
-seed_arg_debug_cb (const char *key, const char *value, gpointer user_data)
+seed_arg_debug_cb(const char* key, const char* value, gpointer user_data)
{
- seed_debug_flags |=
- g_parse_debug_string (value,
- seed_debug_keys, G_N_ELEMENTS (seed_debug_keys));
- return TRUE;
+ seed_debug_flags |= g_parse_debug_string(value, seed_debug_keys,
+ G_N_ELEMENTS(seed_debug_keys));
+ return TRUE;
}
static gboolean
-seed_arg_no_debug_cb (const char *key, const char *value, gpointer user_data)
+seed_arg_no_debug_cb(const char* key, const char* value, gpointer user_data)
{
- seed_debug_flags &=
- ~g_parse_debug_string (value,
- seed_debug_keys, G_N_ELEMENTS (seed_debug_keys));
- return TRUE;
+ seed_debug_flags &= ~g_parse_debug_string(value, seed_debug_keys,
+ G_N_ELEMENTS(seed_debug_keys));
+ return TRUE;
}
#endif /* SEED_ENABLE_DEBUG */
static GOptionEntry seed_args[] = {
#ifdef SEED_ENABLE_DEBUG
- {"seed-debug", 0, 0, G_OPTION_ARG_CALLBACK, seed_arg_debug_cb,
- "Seed debugging messages to show. Comma separated list of: all, misc, finalization, initialization,
construction, invocation, signal, structs, gtype.",
- "FLAGS"},
- {"seed-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, seed_arg_no_debug_cb,
- "Disable Seed debugging", "FLAGS"},
+ { "seed-debug", 0, 0, G_OPTION_ARG_CALLBACK, seed_arg_debug_cb,
+ "Seed debugging messages to show. Comma separated list of: all, misc, "
+ "finalization, initialization, construction, invocation, signal, "
+ "structs, gtype.",
+ "FLAGS" },
+ { "seed-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, seed_arg_no_debug_cb,
+ "Disable Seed debugging", "FLAGS" },
#endif /* SEED_ENABLE_DEBUG */
#ifdef SEED_ENABLE_GJSCOMPAT
- {"seed-gjs-compatibility", 0, 0, G_OPTION_ARG_NONE, &seed_arg_gjs_compatiblity,
- "Enable gjs compatibility", 0},
+ { "seed-gjs-compatibility", 0, 0, G_OPTION_ARG_NONE,
+ &seed_arg_gjs_compatiblity, "Enable gjs compatibility", 0 },
#endif /* SEED_ENABLE_GJSCOMPAT */
- {"seed-version", 0, 0, G_OPTION_ARG_NONE, &seed_arg_print_version,
- "Print libseed version", 0},
- {NULL,},
+ { "seed-version", 0, 0, G_OPTION_ARG_NONE, &seed_arg_print_version,
+ "Print libseed version", 0 },
+ {
+ NULL,
+ },
};
-GOptionGroup *
-seed_get_option_group (void)
+GOptionGroup*
+seed_get_option_group(void)
{
- GOptionGroup *group;
+ GOptionGroup* group;
- group = g_option_group_new ("seed", "Seed Options",
- "Show Seed Options", NULL, NULL);
- g_option_group_add_entries (group, seed_args);
+ group = g_option_group_new("seed", "Seed Options", "Show Seed Options",
+ NULL, NULL);
+ g_option_group_add_entries(group, seed_args);
- return group;
+ return group;
}
static gboolean
-seed_parse_args (int *argc, char ***argv)
+seed_parse_args(int* argc, char*** argv)
{
- GOptionContext *option_context;
- GOptionGroup *seed_group;
+ GOptionContext* option_context;
+ GOptionGroup* seed_group;
- GError *error = NULL;
- gboolean ret = TRUE;
+ GError* error = NULL;
+ gboolean ret = TRUE;
- option_context = g_option_context_new (NULL);
- g_option_context_set_ignore_unknown_options (option_context, TRUE);
- g_option_context_set_help_enabled (option_context, TRUE);
+ option_context = g_option_context_new(NULL);
+ g_option_context_set_ignore_unknown_options(option_context, TRUE);
+ g_option_context_set_help_enabled(option_context, TRUE);
- /* Initiate any command line options from the backend */
+ /* Initiate any command line options from the backend */
- seed_group = seed_get_option_group ();
- g_option_context_add_group (option_context, seed_group);
+ seed_group = seed_get_option_group();
+ g_option_context_add_group(option_context, seed_group);
- if (!g_option_context_parse (option_context, argc, argv, &error))
- {
- if (error)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
+ if (!g_option_context_parse(option_context, argc, argv, &error)) {
+ if (error) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ }
- ret = FALSE;
+ ret = FALSE;
}
- g_option_context_free (option_context);
+ g_option_context_free(option_context);
- return ret;
+ return ret;
}
void
-seed_engine_destroy (SeedEngine *eng)
+seed_engine_destroy(SeedEngine* eng)
{
- JSValueUnprotect (eng->context, eng->global);
- JSGlobalContextRelease (eng->context);
- JSContextGroupRelease (eng->group);
+ JSValueUnprotect(eng->context, eng->global);
+ JSGlobalContextRelease(eng->context);
+ JSContextGroupRelease(eng->group);
- g_free (eng);
+ g_free(eng);
}
/**
@@ -1741,15 +1660,18 @@ seed_engine_destroy (SeedEngine *eng)
* @context A reference to an existing JavascriptCore context
* @group: A #SeedContextGroup within which to create the initial context.
*
- * Initializes an empty new #SeedEngine. The Javascript context of this engine is
+ * Initializes an empty new #SeedEngine. The Javascript context of this engine
+ * is
* *not* filled with any builtins functions and the import system.
*
* The javascript code executed with this engine can't import arbitrary
* GObject introspected librairies.
*
- * Use this when control over what is exposed in the Javascript context is required,
+ * Use this when control over what is exposed in the Javascript context is
+ * required,
* for security concerns for example.
- * GObject instances can be selectively exposed by calling @seed_engine_expose_gobject.
+ * GObject instances can be selectively exposed by calling
+ * @seed_engine_expose_gobject.
* Namespaces can be selectively exposed by calling
*
* This function should only be called once within a single Seed application.
@@ -1757,84 +1679,84 @@ seed_engine_destroy (SeedEngine *eng)
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init_constrained_with_context_and_group (gint * argc,
- gchar *** argv,
- JSGlobalContextRef context,
- JSContextGroupRef group)
+SeedEngine*
+seed_init_constrained_with_context_and_group(gint* argc,
+ gchar*** argv,
+ JSGlobalContextRef context,
+ JSContextGroupRef group)
{
#if !GLIB_CHECK_VERSION(2, 36, 0)
- g_type_init ();
+ g_type_init();
#endif
- g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_WARNING, seed_log_handler, 0);
+ g_log_set_handler("GLib-GObject", G_LOG_LEVEL_WARNING, seed_log_handler, 0);
- if ((argc != 0) && seed_parse_args (argc, argv) == FALSE)
- {
- SEED_NOTE (MISC, "failed to parse arguments.");
- return FALSE;
+ if ((argc != 0) && seed_parse_args(argc, argv) == FALSE) {
+ SEED_NOTE(MISC, "failed to parse arguments.");
+ return FALSE;
}
- if (seed_arg_print_version)
- {
- g_print("%s\n", "Seed " VERSION);
- exit(EXIT_SUCCESS);
+ if (seed_arg_print_version) {
+ g_print("%s\n", "Seed " VERSION);
+ exit(EXIT_SUCCESS);
}
- qname = g_quark_from_static_string ("js-type");
- qprototype = g_quark_from_static_string ("js-prototype");
- js_ref_quark = g_quark_from_static_string ("js-ref");
-
- pthread_key_create(&seed_next_gobject_wrapper_key, NULL);
-
- eng = (SeedEngine *) g_malloc (sizeof (SeedEngine));
-
- context_group = group;
-
- eng->context = context;
- eng->global = JSContextGetGlobalObject (eng->context);
- eng->group = context_group;
- eng->search_path = NULL;
-
- function_proto = (JSObjectRef)
- seed_simple_evaluate (eng->context, "Function.prototype", NULL);
-
- gobject_class = JSClassCreate (&gobject_def);
- JSClassRetain (gobject_class);
- gobject_method_class = JSClassCreate (&gobject_method_def);
- JSClassRetain (gobject_method_class);
- gobject_constructor_class = JSClassCreate (&gobject_constructor_def);
- JSClassRetain (gobject_constructor_class);
- gobject_named_constructor_class =
- JSClassCreate (&gobject_named_constructor_def);
- JSClassRetain (gobject_named_constructor_class);
- gobject_signal_class = JSClassCreate (seed_get_signal_class ());
- JSClassRetain (gobject_signal_class);
- seed_callback_class = JSClassCreate (&seed_callback_def);
- JSClassRetain (seed_callback_class);
- seed_struct_constructor_class = JSClassCreate (&struct_constructor_def);
- JSClassRetain (seed_struct_constructor_class);
- gobject_init_method_class = JSClassCreate (&gobject_init_method_def);
- JSClassRetain (gobject_init_method_class);
-
- g_type_set_qdata (G_TYPE_OBJECT, qname, gobject_class);
-
- seed_obj_ref = JSObjectMake (eng->context, NULL, NULL);
- seed_object_set_property (eng->context, eng->global, "Seed", seed_obj_ref);
- JSValueProtect (eng->context, seed_obj_ref);
+ qname = g_quark_from_static_string("js-type");
+ qprototype = g_quark_from_static_string("js-prototype");
+ js_ref_quark = g_quark_from_static_string("js-ref");
+
+ pthread_key_create(&seed_next_gobject_wrapper_key, NULL);
+
+ eng = (SeedEngine*) g_malloc(sizeof(SeedEngine));
+
+ context_group = group;
+
+ eng->context = context;
+ eng->global = JSContextGetGlobalObject(eng->context);
+ eng->group = context_group;
+ eng->search_path = NULL;
+
+ function_proto
+ = (JSObjectRef) seed_simple_evaluate(eng->context, "Function.prototype",
+ NULL);
+
+ gobject_class = JSClassCreate(&gobject_def);
+ JSClassRetain(gobject_class);
+ gobject_method_class = JSClassCreate(&gobject_method_def);
+ JSClassRetain(gobject_method_class);
+ gobject_constructor_class = JSClassCreate(&gobject_constructor_def);
+ JSClassRetain(gobject_constructor_class);
+ gobject_named_constructor_class
+ = JSClassCreate(&gobject_named_constructor_def);
+ JSClassRetain(gobject_named_constructor_class);
+ gobject_signal_class = JSClassCreate(seed_get_signal_class());
+ JSClassRetain(gobject_signal_class);
+ seed_callback_class = JSClassCreate(&seed_callback_def);
+ JSClassRetain(seed_callback_class);
+ seed_struct_constructor_class = JSClassCreate(&struct_constructor_def);
+ JSClassRetain(seed_struct_constructor_class);
+ gobject_init_method_class = JSClassCreate(&gobject_init_method_def);
+ JSClassRetain(gobject_init_method_class);
+
+ g_type_set_qdata(G_TYPE_OBJECT, qname, gobject_class);
+
+ seed_obj_ref = JSObjectMake(eng->context, NULL, NULL);
+ seed_object_set_property(eng->context, eng->global, "Seed", seed_obj_ref);
+ JSValueProtect(eng->context, seed_obj_ref);
#ifdef SEED_ENABLE_GJSCOMPAT
- window_obj_ref = JSObjectMake (eng->context, NULL, NULL);
- seed_object_set_property (eng->context, eng->global, "window", window_obj_ref);
- JSValueProtect (eng->context, window_obj_ref);
+ window_obj_ref = JSObjectMake(eng->context, NULL, NULL);
+ seed_object_set_property(eng->context, eng->global, "window",
+ window_obj_ref);
+ JSValueProtect(eng->context, window_obj_ref);
#endif
- g_irepository_require (g_irepository_get_default (), "GObject", NULL, 0, 0);
- g_irepository_require (g_irepository_get_default (), "GIRepository",
- NULL, 0, 0);
+ g_irepository_require(g_irepository_get_default(), "GObject", NULL, 0, 0);
+ g_irepository_require(g_irepository_get_default(), "GIRepository", NULL, 0,
+ 0);
- seed_structs_init ();
- seed_closures_init ();
+ seed_structs_init();
+ seed_closures_init();
- return eng;
+ return eng;
}
/**
@@ -1854,30 +1776,29 @@ seed_init_constrained_with_context_and_group (gint * argc,
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init_with_context_and_group (gint * argc,
- gchar *** argv, JSGlobalContextRef context, JSContextGroupRef group)
+SeedEngine*
+seed_init_with_context_and_group(gint* argc,
+ gchar*** argv,
+ JSGlobalContextRef context,
+ JSContextGroupRef group)
{
- eng = seed_init_constrained_with_context_and_group (argc, argv, context, group);
- seed_init_builtins (eng, argc, argv);
- seed_initialize_importer (eng->context, eng->global);
- seed_gtype_init (eng);
+ eng = seed_init_constrained_with_context_and_group(argc, argv, context,
+ group);
+ seed_init_builtins(eng, argc, argv);
+ seed_initialize_importer(eng->context, eng->global);
+ seed_gtype_init(eng);
- defaults_script =
- JSStringCreateWithUTF8CString ("Seed.include(\"" SEED_PREFIX_PATH
- "extensions/Seed.js\");");
+ defaults_script = JSStringCreateWithUTF8CString(
+ "Seed.include(\"" SEED_PREFIX_PATH "extensions/Seed.js\");");
- JSEvaluateScript (eng->context, defaults_script, NULL, NULL, 0, NULL);
+ JSEvaluateScript(eng->context, defaults_script, NULL, NULL, 0, NULL);
- base_info_info =
- g_irepository_find_by_name (0, "GIRepository", "BaseInfo");
+ base_info_info = g_irepository_find_by_name(0, "GIRepository", "BaseInfo");
- return eng;
+ return eng;
}
-
-
/**
* seed_init_with_context_group:
* @argc: A reference to the number of arguments remaining to parse.
@@ -1893,11 +1814,11 @@ seed_init_with_context_and_group (gint * argc,
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init_with_context_group (gint * argc,
- gchar *** argv, JSContextGroupRef group)
+SeedEngine*
+seed_init_with_context_group(gint* argc, gchar*** argv, JSContextGroupRef group)
{
- return seed_init_with_context_and_group (argc, argv, JSGlobalContextCreateInGroup (group, NULL), group);
+ return seed_init_with_context_and_group(
+ argc, argv, JSGlobalContextCreateInGroup(group, NULL), group);
}
/**
@@ -1914,12 +1835,12 @@ seed_init_with_context_group (gint * argc,
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init (gint * argc, gchar *** argv)
+SeedEngine*
+seed_init(gint* argc, gchar*** argv)
{
- context_group = JSContextGroupCreate ();
+ context_group = JSContextGroupCreate();
- return seed_init_with_context_group (argc, argv, context_group);
+ return seed_init_with_context_group(argc, argv, context_group);
}
/**
@@ -1928,7 +1849,7 @@ seed_init (gint * argc, gchar *** argv)
* @argv: A reference to an array of string arguments remaining to parse.
* @context A reference to an existing JavascriptCore context
- * Initializes a new #SeedEngine using an existing JavascriptCore context.
+ * Initializes a new #SeedEngine using an existing JavascriptCore context.
* This involves initializing GLib, adding the default globals to the provided
* @context and initializing various internal parts of Seed.
*
@@ -1937,12 +1858,12 @@ seed_init (gint * argc, gchar *** argv)
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init_with_context (gint * argc, gchar *** argv, JSGlobalContextRef context)
+SeedEngine*
+seed_init_with_context(gint* argc, gchar*** argv, JSGlobalContextRef context)
{
- context_group = JSContextGetGroup (context);
+ context_group = JSContextGetGroup(context);
- return seed_init_with_context_and_group (argc, argv, context, context_group);
+ return seed_init_with_context_and_group(argc, argv, context, context_group);
}
/**
@@ -1950,15 +1871,18 @@ seed_init_with_context (gint * argc, gchar *** argv, JSGlobalContextRef context)
* @argc: A reference to the number of arguments remaining to parse.
* @argv: A reference to an array of string arguments remaining to parse.
*
- * Initializes an empty new #SeedEngine. The Javascript context of this engine is
+ * Initializes an empty new #SeedEngine. The Javascript context of this engine
+ * is
* *not* filled with any builtins functions and the import system.
*
* The javascript code executed with this engine can't import arbitrary
* GObject introspected librairies.
*
- * Use this when control over what is exposed in the Javascript context is required,
+ * Use this when control over what is exposed in the Javascript context is
+ * required,
* for security concerns for example.
- * GObject instances can be selectively exposed by calling @seed_engine_expose_gobject.
+ * GObject instances can be selectively exposed by calling
+ * @seed_engine_expose_gobject.
* Namespaces can be selectively exposed by calling
*
* This function should only be called once within a single Seed application.
@@ -1966,88 +1890,93 @@ seed_init_with_context (gint * argc, gchar *** argv, JSGlobalContextRef context)
* Return value: The newly created and initialized #SeedEngine.
*
*/
-SeedEngine *
-seed_init_constrained (gint * argc, gchar *** argv)
+SeedEngine*
+seed_init_constrained(gint* argc, gchar*** argv)
{
- context_group = JSContextGroupCreate ();
+ context_group = JSContextGroupCreate();
- return seed_init_constrained_with_context_and_group(argc, argv,
- JSGlobalContextCreateInGroup (context_group,
NULL),
- context_group);
+ return seed_init_constrained_with_context_and_group(
+ argc, argv, JSGlobalContextCreateInGroup(context_group, NULL),
+ context_group);
}
/*
* seed_engine_expose_gobject:
* @engine:
* @name: The name of the global javascript variable pointing to @object
- * @object: The #GObject instance that will be exposed in the the javascript context
- * @gir_namespace: The Introspection namespace containing the type of the provided
+ * @object: The #GObject instance that will be exposed in the the javascript
+ * context
+ * @gir_namespace: The Introspection namespace containing the type of the
+ * provided
* object.
*
- * Expose a GObject instance to the global Javascript context and makes it accessible
+ * Expose a GObject instance to the global Javascript context and makes it
+ * accessible
* under the provided @js_name
*
* return: the SeedValue representing @object, NULL in case of error
*/
JSValueRef
-seed_engine_expose_gobject (SeedEngine *engine,
- gchar *js_name,
- GObject *object,
- gchar *gir_namespace,
- JSValueRef * exception)
+seed_engine_expose_gobject(SeedEngine* engine,
+ gchar* js_name,
+ GObject* object,
+ gchar* gir_namespace,
+ JSValueRef* exception)
{
- GError *error = NULL;
+ GError* error = NULL;
- g_assert (engine != NULL && gir_namespace != NULL && js_name != NULL);
+ g_assert(engine != NULL && gir_namespace != NULL && js_name != NULL);
- GITypelib *type_lib = g_irepository_require (g_irepository_get_default(),
- gir_namespace, NULL, 0, &error);
- if (type_lib == NULL)
- {
- seed_make_exception_from_gerror (engine->context, exception, error);
- g_error_free (error);
- return NULL;
- }
+ GITypelib* type_lib = g_irepository_require(g_irepository_get_default(),
+ gir_namespace, NULL, 0, &error);
+ if (type_lib == NULL) {
+ seed_make_exception_from_gerror(engine->context, exception, error);
+ g_error_free(error);
+ return NULL;
+ }
- JSValueRef obj_js_value = seed_value_from_object (engine->context,
- G_OBJECT(object),
- exception);
- g_return_val_if_fail (obj_js_value != NULL, NULL);
+ JSValueRef obj_js_value
+ = seed_value_from_object(engine->context, G_OBJECT(object), exception);
+ g_return_val_if_fail(obj_js_value != NULL, NULL);
- g_return_val_if_fail (engine->global != NULL, NULL);
+ g_return_val_if_fail(engine->global != NULL, NULL);
- gboolean ok = seed_object_set_property (engine->context,
- engine->global, js_name, obj_js_value);
- g_return_val_if_fail (ok == TRUE, NULL);
+ gboolean ok = seed_object_set_property(engine->context, engine->global,
+ js_name, obj_js_value);
+ g_return_val_if_fail(ok == TRUE, NULL);
- return obj_js_value;
+ return obj_js_value;
}
/*
* seed_engine_expose_namespace:
* @engine:
- * @namespace: Name of the GIR Namespace that should be exposed in the JS context.
+ * @namespace: Name of the GIR Namespace that should be exposed in the JS
+ * context.
*
- * Expose a GIR namespace in the global Javascript context and makes it accessible
- * under a variable named after the namespace (ex: the namespace 'Notify' is held
+ * Expose a GIR namespace in the global Javascript context and makes it
+ * accessible
+ * under a variable named after the namespace (ex: the namespace 'Notify' is
+ * held
* by the 'Notify' javascript variable.
*
* return: the SeedValue representing @namespace in the javascript context,
* NULL in case of error
*/
JSValueRef
-seed_engine_expose_namespace (SeedEngine *engine,
- gchar *namespace_name,
- JSValueRef *exception)
+seed_engine_expose_namespace(SeedEngine* engine,
+ gchar* namespace_name,
+ JSValueRef* exception)
{
- g_assert (engine != NULL && namespace_name != NULL);
+ g_assert(engine != NULL && namespace_name != NULL);
- JSValueRef namespace = seed_gi_importer_do_namespace (engine->context,
- namespace_name, exception);
- g_return_val_if_fail (namespace != NULL, NULL);
- gboolean ok = seed_object_set_property (engine->context,
- engine->global, namespace_name, namespace);
- g_return_val_if_fail (ok == TRUE, FALSE);
+ JSValueRef namespace
+ = seed_gi_importer_do_namespace(engine->context, namespace_name,
+ exception);
+ g_return_val_if_fail(namespace != NULL, NULL);
+ gboolean ok = seed_object_set_property(engine->context, engine->global,
+ namespace_name, namespace);
+ g_return_val_if_fail(ok == TRUE, FALSE);
- return namespace;
+ return namespace;
}
diff --git a/libseed/seed-engine.h b/libseed/seed-engine.h
index 4adcde5..9652344 100644
--- a/libseed/seed-engine.h
+++ b/libseed/seed-engine.h
@@ -32,7 +32,7 @@ extern JSClassRef gobject_init_method_class;
extern pthread_key_t seed_next_gobject_wrapper_key;
extern JSClassRef seed_callback_class;
-extern SeedEngine *eng;
+extern SeedEngine* eng;
extern JSObjectRef seed_obj_ref;
@@ -42,44 +42,48 @@ extern JSStringRef defaults_script;
typedef struct _SeedScript
{
- JSStringRef script;
- JSValueRef exception;
+ JSStringRef script;
+ JSValueRef exception;
- JSStringRef source_url;
- gint line_number;
+ JSStringRef source_url;
+ gint line_number;
} SeedScript;
-JSObjectRef seed_gobject_get_prototype_for_gtype (GType type);
-JSClassRef seed_gobject_get_class_for_gtype (JSContextRef ctx, GType type);
+JSObjectRef seed_gobject_get_prototype_for_gtype(GType type);
+JSClassRef seed_gobject_get_class_for_gtype(JSContextRef ctx, GType type);
-void
-seed_gobject_define_property_from_function_info (JSContextRef ctx,
- GIFunctionInfo * info,
- JSObjectRef object,
- gboolean instance);
-void seed_create_function (JSContextRef ctx, gchar * name,
- gpointer func, JSObjectRef obj);
+void seed_gobject_define_property_from_function_info(JSContextRef ctx,
+ GIFunctionInfo* info,
+ JSObjectRef object,
+ gboolean instance);
+void seed_create_function(JSContextRef ctx,
+ gchar* name,
+ gpointer func,
+ JSObjectRef obj);
-void seed_repl_expose (JSContextRef ctx, ...);
+void seed_repl_expose(JSContextRef ctx, ...);
-typedef JSObjectRef (*SeedModuleInitCallback) (SeedEngine * eng);
+typedef JSObjectRef (*SeedModuleInitCallback)(SeedEngine* eng);
-void seed_prepare_global_context (JSContextRef ctx);
+void seed_prepare_global_context(JSContextRef ctx);
-SeedScript *seed_make_script (JSContextRef ctx,
- const gchar * js,
- const gchar * source_url, gint line_number);
-SeedScript *seed_script_new_from_file (JSContextRef ctx, gchar * file);
-JSValueRef seed_script_exception (SeedScript * s);
+SeedScript* seed_make_script(JSContextRef ctx,
+ const gchar* js,
+ const gchar* source_url,
+ gint line_number);
+SeedScript* seed_script_new_from_file(JSContextRef ctx, gchar* file);
+JSValueRef seed_script_exception(SeedScript* s);
-JSValueRef seed_evaluate (JSContextRef ctx, SeedScript * script,
- JSObjectRef this);
+JSValueRef seed_evaluate(JSContextRef ctx,
+ SeedScript* script,
+ JSObjectRef this);
-void seed_script_destroy (SeedScript * s);
+void seed_script_destroy(SeedScript* s);
-JSValueRef seed_simple_evaluate (JSContextRef ctx, const gchar * script,
- JSValueRef * exception);
+JSValueRef seed_simple_evaluate(JSContextRef ctx,
+ const gchar* script,
+ JSValueRef* exception);
-GOptionGroup * seed_get_option_group (void);
+GOptionGroup* seed_get_option_group(void);
#endif
diff --git a/libseed/seed-exceptions.c b/libseed/seed-exceptions.c
index ed37054..6336b21 100644
--- a/libseed/seed-exceptions.c
+++ b/libseed/seed-exceptions.c
@@ -35,48 +35,48 @@
*
*/
void
-seed_make_exception (JSContextRef ctx,
- JSValueRef * exception,
- const gchar * name, const gchar * message, ...)
+seed_make_exception(JSContextRef ctx,
+ JSValueRef* exception,
+ const gchar* name,
+ const gchar* message,
+ ...)
{
- JSStringRef js_name = 0;
- JSStringRef js_message = 0;
- JSValueRef js_name_ref = 0, js_message_ref = 0;
- JSObjectRef exception_obj;
- gchar *mes;
- va_list args;
+ JSStringRef js_name = 0;
+ JSStringRef js_message = 0;
+ JSValueRef js_name_ref = 0, js_message_ref = 0;
+ JSObjectRef exception_obj;
+ gchar* mes;
+ va_list args;
- if (!exception)
- return;
+ if (!exception)
+ return;
- va_start (args, message);
+ va_start(args, message);
- if (name)
- {
- js_name = JSStringCreateWithUTF8CString (name);
- js_name_ref = JSValueMakeString (ctx, js_name);
+ if (name) {
+ js_name = JSStringCreateWithUTF8CString(name);
+ js_name_ref = JSValueMakeString(ctx, js_name);
}
- if (message)
- {
- mes = g_strdup_vprintf (message, args);
- js_message = JSStringCreateWithUTF8CString (mes);
- js_message_ref = JSValueMakeString (ctx, js_message);
- g_free (mes);
+ if (message) {
+ mes = g_strdup_vprintf(message, args);
+ js_message = JSStringCreateWithUTF8CString(mes);
+ js_message_ref = JSValueMakeString(ctx, js_message);
+ g_free(mes);
}
- // TODO: needs to create a global class named 'name', and this needs to
- // be an instance of it, for integration with normal JS!
+ // TODO: needs to create a global class named 'name', and this needs to
+ // be an instance of it, for integration with normal JS!
- exception_obj = JSObjectMake (ctx, 0, NULL);
- seed_object_set_property (ctx, exception_obj, "message", js_message_ref);
- seed_object_set_property (ctx, exception_obj, "name", js_name_ref);
+ exception_obj = JSObjectMake(ctx, 0, NULL);
+ seed_object_set_property(ctx, exception_obj, "message", js_message_ref);
+ seed_object_set_property(ctx, exception_obj, "name", js_name_ref);
- *exception = exception_obj;
+ *exception = exception_obj;
- JSStringRelease (js_name);
- JSStringRelease (js_message);
+ JSStringRelease(js_name);
+ JSStringRelease(js_message);
- va_end (args);
+ va_end(args);
}
/**
@@ -89,29 +89,26 @@ seed_make_exception (JSContextRef ctx,
*
*/
void
-seed_make_exception_from_gerror (JSContextRef ctx,
- JSValueRef * exception, GError * error)
+seed_make_exception_from_gerror(JSContextRef ctx,
+ JSValueRef* exception,
+ GError* error)
{
- const gchar *domain = g_quark_to_string (error->domain);
- GString *string = g_string_new (domain);
- guint i;
- gsize len = string->len;
-
- *(string->str) = g_unichar_toupper (*(string->str));
- for (i = 0; i < len; i++)
- {
- if (*(string->str + i) == '-')
- {
- *(string->str + i + 1) = g_unichar_toupper (*(string->str + i + 1));
- g_string_erase (string, i, 1);
- }
- else if (!g_strcmp0 (string->str + i - 1, "Quark"))
- g_string_truncate (string, i - 1);
+ const gchar* domain = g_quark_to_string(error->domain);
+ GString* string = g_string_new(domain);
+ guint i;
+ gsize len = string->len;
+ *(string->str) = g_unichar_toupper(*(string->str));
+ for (i = 0; i < len; i++) {
+ if (*(string->str + i) == '-') {
+ *(string->str + i + 1) = g_unichar_toupper(*(string->str + i + 1));
+ g_string_erase(string, i, 1);
+ } else if (!g_strcmp0(string->str + i - 1, "Quark"))
+ g_string_truncate(string, i - 1);
}
- seed_make_exception (ctx, exception, string->str, error->message, NULL);
+ seed_make_exception(ctx, exception, string->str, error->message, NULL);
- g_string_free (string, TRUE);
+ g_string_free(string, TRUE);
}
/**
@@ -126,16 +123,16 @@ seed_make_exception_from_gerror (JSContextRef ctx,
* Return value: A #gchar* representing the name of @exception.
*
*/
-gchar *
-seed_exception_get_name (JSContextRef ctx, JSValueRef e)
+gchar*
+seed_exception_get_name(JSContextRef ctx, JSValueRef e)
{
- JSValueRef name;
- g_assert ((e));
- if (!JSValueIsObject (ctx, e))
- return NULL;
+ JSValueRef name;
+ g_assert((e));
+ if (!JSValueIsObject(ctx, e))
+ return NULL;
- name = seed_object_get_property (ctx, (JSObjectRef) e, "name");
- return seed_value_to_string (ctx, name, NULL);
+ name = seed_object_get_property(ctx, (JSObjectRef) e, "name");
+ return seed_value_to_string(ctx, name, NULL);
}
/**
@@ -151,16 +148,16 @@ seed_exception_get_name (JSContextRef ctx, JSValueRef e)
* Return value: A #gchar* representing the detailed message of @exception.
*
*/
-gchar *
-seed_exception_get_message (JSContextRef ctx, JSValueRef e)
+gchar*
+seed_exception_get_message(JSContextRef ctx, JSValueRef e)
{
- JSValueRef name;
- g_assert ((e));
- if (!JSValueIsObject (ctx, e))
- return 0;
+ JSValueRef name;
+ g_assert((e));
+ if (!JSValueIsObject(ctx, e))
+ return 0;
- name = seed_object_get_property (ctx, (JSObjectRef) e, "message");
- return seed_value_to_string (ctx, name, NULL);
+ name = seed_object_get_property(ctx, (JSObjectRef) e, "message");
+ return seed_value_to_string(ctx, name, NULL);
}
/**
@@ -176,14 +173,14 @@ seed_exception_get_message (JSContextRef ctx, JSValueRef e)
*
*/
guint
-seed_exception_get_line (JSContextRef ctx, JSValueRef e)
+seed_exception_get_line(JSContextRef ctx, JSValueRef e)
{
- JSValueRef line;
- g_assert ((e));
- if (!JSValueIsObject (ctx, e))
- return 0;
- line = seed_object_get_property (ctx, (JSObjectRef) e, "line");
- return seed_value_to_uint (ctx, line, NULL);
+ JSValueRef line;
+ g_assert((e));
+ if (!JSValueIsObject(ctx, e))
+ return 0;
+ line = seed_object_get_property(ctx, (JSObjectRef) e, "line");
+ return seed_value_to_uint(ctx, line, NULL);
}
/**
@@ -198,15 +195,15 @@ seed_exception_get_line (JSContextRef ctx, JSValueRef e)
* @exception was thrown.
*
*/
-gchar *
-seed_exception_get_file (JSContextRef ctx, JSValueRef e)
+gchar*
+seed_exception_get_file(JSContextRef ctx, JSValueRef e)
{
- JSValueRef line;
- g_assert ((e));
- if (!JSValueIsObject (ctx, e))
- return 0;
- line = seed_object_get_property (ctx, (JSObjectRef) e, "sourceURL");
- return seed_value_to_string (ctx, line, 0);
+ JSValueRef line;
+ g_assert((e));
+ if (!JSValueIsObject(ctx, e))
+ return 0;
+ line = seed_object_get_property(ctx, (JSObjectRef) e, "sourceURL");
+ return seed_value_to_string(ctx, line, 0);
}
/**
* seed_exception_get_stack:
@@ -219,18 +216,17 @@ seed_exception_get_file (JSContextRef ctx, JSValueRef e)
* @exception was thrown.
*
*/
-gchar *
-seed_exception_get_stack (JSContextRef ctx, JSValueRef e)
+gchar*
+seed_exception_get_stack(JSContextRef ctx, JSValueRef e)
{
- JSValueRef stack ;
- g_assert ((e));
- if (!JSValueIsObject (ctx, e))
- return 0;
- stack = seed_object_get_property (ctx, (JSObjectRef) e, "stack");
- return seed_value_to_string (ctx, stack , 0);
+ JSValueRef stack;
+ g_assert((e));
+ if (!JSValueIsObject(ctx, e))
+ return 0;
+ stack = seed_object_get_property(ctx, (JSObjectRef) e, "stack");
+ return seed_value_to_string(ctx, stack, 0);
}
-
/**
* seed_exception_to_string:
* @ctx: A #SeedContext.
@@ -244,24 +240,25 @@ seed_exception_get_stack (JSContextRef ctx, JSValueRef e)
* Return value: A #gchar* representing the @exception.
*
*/
-gchar *
-seed_exception_to_string (JSContextRef ctx, JSValueRef e)
+gchar*
+seed_exception_to_string(JSContextRef ctx, JSValueRef e)
{
- guint line;
- gchar *mes, *name, *file, *ret, *stack;
+ guint line;
+ gchar *mes, *name, *file, *ret, *stack;
- line = seed_exception_get_line (ctx, e);
- mes = seed_exception_get_message (ctx, e);
- file = seed_exception_get_file (ctx, e);
- name = seed_exception_get_name (ctx, e);
- stack = seed_exception_get_stack (ctx, e);
+ line = seed_exception_get_line(ctx, e);
+ mes = seed_exception_get_message(ctx, e);
+ file = seed_exception_get_file(ctx, e);
+ name = seed_exception_get_name(ctx, e);
+ stack = seed_exception_get_stack(ctx, e);
- ret = g_strdup_printf ("Line %d in %s: %s %s\n\nStack:\n%s", line, file, name, mes, stack);
+ ret = g_strdup_printf("Line %d in %s: %s %s\n\nStack:\n%s", line, file,
+ name, mes, stack);
- g_free (mes);
- g_free (file);
- g_free (name);
- g_free (stack);
+ g_free(mes);
+ g_free(file);
+ g_free(name);
+ g_free(stack);
- return ret;
+ return ret;
}
diff --git a/libseed/seed-exceptions.h b/libseed/seed-exceptions.h
index cc1a261..db4b35c 100644
--- a/libseed/seed-exceptions.h
+++ b/libseed/seed-exceptions.h
@@ -22,20 +22,21 @@
#include "seed-private.h"
-void
-seed_make_exception (JSContextRef ctx, JSValueRef * exception,
- const gchar * name, const gchar * message, ...)
-G_GNUC_PRINTF (4, 5);
+void seed_make_exception(JSContextRef ctx,
+ JSValueRef* exception,
+ const gchar* name,
+ const gchar* message,
+ ...) G_GNUC_PRINTF(4, 5);
- void seed_make_exception_from_gerror (JSContextRef ctx,
- JSValueRef * exception,
- GError * e);
+void seed_make_exception_from_gerror(JSContextRef ctx,
+ JSValueRef* exception,
+ GError* e);
- gchar *seed_exception_get_name (JSContextRef ctx, JSValueRef e);
- gchar *seed_exception_get_message (JSContextRef ctx, JSValueRef e);
- guint seed_exception_get_line (JSContextRef ctx, JSValueRef e);
- gchar *seed_exception_get_file (JSContextRef ctx, JSValueRef e);
- gchar *seed_exception_get_stack (JSContextRef ctx, JSValueRef e);
- gchar *seed_exception_to_string (JSContextRef ctx, JSValueRef e);
+gchar* seed_exception_get_name(JSContextRef ctx, JSValueRef e);
+gchar* seed_exception_get_message(JSContextRef ctx, JSValueRef e);
+guint seed_exception_get_line(JSContextRef ctx, JSValueRef e);
+gchar* seed_exception_get_file(JSContextRef ctx, JSValueRef e);
+gchar* seed_exception_get_stack(JSContextRef ctx, JSValueRef e);
+gchar* seed_exception_to_string(JSContextRef ctx, JSValueRef e);
#endif
diff --git a/libseed/seed-gtype.c b/libseed/seed-gtype.c
index 1121326..55f9e62 100644
--- a/libseed/seed-gtype.c
+++ b/libseed/seed-gtype.c
@@ -20,12 +20,13 @@
#include "seed-private.h"
#include <sys/mman.h>
-typedef GObject *(*GObjectConstructCallback) (GType, guint,
- GObjectConstructParam *);
+typedef GObject* (*GObjectConstructCallback)(GType,
+ guint,
+ GObjectConstructParam*);
JSClassRef seed_gtype_class;
-GIBaseInfo *objectclass_info = NULL;
-GIBaseInfo *paramspec_info = NULL;
+GIBaseInfo* objectclass_info = NULL;
+GIBaseInfo* paramspec_info = NULL;
JSObjectRef seed_gtype_constructor;
@@ -35,1033 +36,926 @@ GQuark qsetter;
GQuark qiinit;
GQuark qcinit;
-typedef struct _SeedGClassPrivates {
- JSObjectRef constructor;
- JSObjectRef func;
+typedef struct _SeedGClassPrivates
+{
+ JSObjectRef constructor;
+ JSObjectRef func;
- JSObjectRef definition;
+ JSObjectRef definition;
} SeedGClassPrivates;
static JSValueRef
-seed_property_method_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_property_method_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GParamSpec *spec;
- GObjectClass *class;
- guint property_count;
- JSValueRef newcount, oldcount;
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Property installation expected 1 argument"
- " got %zd \n", argumentCount);
-
- return JSValueMakeNull (ctx);
+ GParamSpec* spec;
+ GObjectClass* class;
+ guint property_count;
+ JSValueRef newcount, oldcount;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Property installation expected 1 argument"
+ " got %zd \n",
+ argumentCount);
+
+ return JSValueMakeNull(ctx);
}
- if (JSValueIsNull (ctx, arguments[0]) ||
- // Might need to check if JSValueIsObject? Who knows with WebKit.
- !JSValueIsObjectOfClass (ctx, arguments[0], seed_struct_class))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Property installation expected a "
- "GParamSpec as argument");
- return JSValueMakeNull (ctx);
+ if (JSValueIsNull(ctx, arguments[0]) ||
+ // Might need to check if JSValueIsObject? Who knows with WebKit.
+ !JSValueIsObjectOfClass(ctx, arguments[0], seed_struct_class)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Property installation expected a "
+ "GParamSpec as argument");
+ return JSValueMakeNull(ctx);
}
- spec = (GParamSpec *) seed_pointer_get_pointer (ctx, arguments[0]);
+ spec = (GParamSpec*) seed_pointer_get_pointer(ctx, arguments[0]);
- oldcount = seed_object_get_property (ctx, thisObject, "property_count");
- property_count = seed_value_to_int (ctx, oldcount, exception);
+ oldcount = seed_object_get_property(ctx, thisObject, "property_count");
+ property_count = seed_value_to_int(ctx, oldcount, exception);
- class = seed_pointer_get_pointer (ctx, thisObject);
- g_object_class_install_property (class, property_count, spec);
+ class = seed_pointer_get_pointer(ctx, thisObject);
+ g_object_class_install_property(class, property_count, spec);
- newcount = seed_value_from_int (ctx, property_count + 1, exception);
- seed_object_set_property (ctx, thisObject, "property_count", newcount);
+ newcount = seed_value_from_int(ctx, property_count + 1, exception);
+ seed_object_set_property(ctx, thisObject, "property_count", newcount);
- return oldcount;
+ return oldcount;
}
static JSValueRef
-seed_gsignal_method_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gsignal_method_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- // TODO: class_closure, and accumlator. Not useful until we have structs.
- JSValueRef jsname, jstype, jsflags, jsreturn_type, jsparams;
- GType itype, return_type;
- guint n_params = 0;
- GType *param_types = 0;
- gchar *name;
- guint signal_id;
- GSignalFlags flags;
-
- /* Sanity check */
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal constructor expected 1 argument"
- " got %zd \n", argumentCount);
- return (JSObjectRef) JSValueMakeNull (ctx);
+ // TODO: class_closure, and accumlator. Not useful until we have structs.
+ JSValueRef jsname, jstype, jsflags, jsreturn_type, jsparams;
+ GType itype, return_type;
+ guint n_params = 0;
+ GType* param_types = 0;
+ gchar* name;
+ guint signal_id;
+ GSignalFlags flags;
+
+ /* Sanity check */
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal constructor expected 1 argument"
+ " got %zd \n",
+ argumentCount);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- if (JSValueIsNull (ctx, arguments[0])
- || !JSValueIsObject (ctx, arguments[0]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal constructor expected object"
- " as first argument");
- return (JSObjectRef) JSValueMakeNull (ctx);
+ if (JSValueIsNull(ctx, arguments[0])
+ || !JSValueIsObject(ctx, arguments[0])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal constructor expected object"
+ " as first argument");
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- /* Signal name */
- jsname = seed_object_get_property (ctx, (JSObjectRef) arguments[0], "name");
- /* seed_value_to_string can handle non strings, however the kind
- * of strings we want as a signal name are rather small, so make sure
- * we have an actual string */
- if (JSValueIsNull (ctx, jsname) || !JSValueIsString (ctx, jsname))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal definition needs name property");
- return (JSObjectRef) JSValueMakeNull (ctx);
+ /* Signal name */
+ jsname = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "name");
+ /* seed_value_to_string can handle non strings, however the kind
+ * of strings we want as a signal name are rather small, so make sure
+ * we have an actual string */
+ if (JSValueIsNull(ctx, jsname) || !JSValueIsString(ctx, jsname)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal definition needs name property");
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- name = seed_value_to_string (ctx, jsname, exception);
-
- /* Type to install on. Comes from class. */
- jstype = seed_object_get_property (ctx, thisObject, "type");
- itype = seed_value_to_int (ctx, jstype, exception);
-
- SEED_NOTE (GTYPE, "Installing signal with name: %s on type: %s",
- name, g_type_name (itype));
-
- /* Signal flags */
- jsflags = seed_object_get_property (ctx,
- (JSObjectRef) arguments[0], "flags");
- if (JSValueIsNull (ctx, jsflags) || !JSValueIsNumber (ctx, jsflags))
- flags = G_SIGNAL_RUN_LAST;
- else
- flags = seed_value_to_long (ctx, jsflags, exception);
-
- /* Return type */
- jsreturn_type = seed_object_get_property (ctx, (JSObjectRef) arguments[0],
- "return_type");
- if (JSValueIsNull (ctx, jsreturn_type) ||
- !JSValueIsNumber (ctx, jsreturn_type))
- return_type = G_TYPE_NONE;
- else
- return_type = seed_value_to_int (ctx, jsreturn_type, exception);
-
- /* Number of params and types */
- jsparams = seed_object_get_property (ctx, (JSObjectRef) arguments[0],
- "parameters");
- if (!JSValueIsNull (ctx, jsparams) && JSValueIsObject (ctx, jsparams))
- {
- n_params = seed_value_to_int
- (ctx,
- seed_object_get_property (ctx, (JSObjectRef) jsparams, "length"),
- exception);
- if (n_params > 0)
- {
- guint i;
- JSValueRef ptype;
-
- param_types = g_new0 (GType, n_params);
- for (i = 0; i < n_params; i++)
- {
- ptype = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- jsparams, i, exception);
-
- param_types[i] = seed_value_to_int (ctx, ptype, exception);
- }
- }
+ name = seed_value_to_string(ctx, jsname, exception);
+
+ /* Type to install on. Comes from class. */
+ jstype = seed_object_get_property(ctx, thisObject, "type");
+ itype = seed_value_to_int(ctx, jstype, exception);
+
+ SEED_NOTE(GTYPE, "Installing signal with name: %s on type: %s", name,
+ g_type_name(itype));
+
+ /* Signal flags */
+ jsflags
+ = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "flags");
+ if (JSValueIsNull(ctx, jsflags) || !JSValueIsNumber(ctx, jsflags))
+ flags = G_SIGNAL_RUN_LAST;
+ else
+ flags = seed_value_to_long(ctx, jsflags, exception);
+
+ /* Return type */
+ jsreturn_type = seed_object_get_property(ctx, (JSObjectRef) arguments[0],
+ "return_type");
+ if (JSValueIsNull(ctx, jsreturn_type)
+ || !JSValueIsNumber(ctx, jsreturn_type))
+ return_type = G_TYPE_NONE;
+ else
+ return_type = seed_value_to_int(ctx, jsreturn_type, exception);
+
+ /* Number of params and types */
+ jsparams
+ = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "parameters");
+ if (!JSValueIsNull(ctx, jsparams) && JSValueIsObject(ctx, jsparams)) {
+ n_params = seed_value_to_int(
+ ctx, seed_object_get_property(ctx, (JSObjectRef) jsparams, "length"),
+ exception);
+ if (n_params > 0) {
+ guint i;
+ JSValueRef ptype;
+
+ param_types = g_new0(GType, n_params);
+ for (i = 0; i < n_params; i++) {
+ ptype = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) jsparams,
+ i, exception);
+
+ param_types[i] = seed_value_to_int(ctx, ptype, exception);
+ }
+ }
}
- signal_id = g_signal_newv (name, itype,
- flags, 0, 0, 0,
- gi_cclosure_marshal_generic,
- return_type, n_params, param_types);
+ signal_id
+ = g_signal_newv(name, itype, flags, 0, 0, 0, gi_cclosure_marshal_generic,
+ return_type, n_params, param_types);
- g_free (name);
- g_free (param_types);
+ g_free(name);
+ g_free(param_types);
- return (JSValueRef) seed_value_from_uint (ctx, signal_id, exception);
+ return (JSValueRef) seed_value_from_uint(ctx, signal_id, exception);
}
static void
-seed_gtype_builtin_set_property (GObject * object,
- guint property_id,
- const GValue * value, GParamSpec * spec)
+seed_gtype_builtin_set_property(GObject* object,
+ guint property_id,
+ const GValue* value,
+ GParamSpec* spec)
{
- JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
- gchar *name = g_strjoin (NULL, "_", spec->name, NULL);
- JSObjectRef jsobj = (JSObjectRef) seed_value_from_object (ctx, object, 0);
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
+ gchar* name = g_strjoin(NULL, "_", spec->name, NULL);
+ JSObjectRef jsobj = (JSObjectRef) seed_value_from_object(ctx, object, 0);
- seed_prepare_global_context (ctx);
+ seed_prepare_global_context(ctx);
- seed_object_set_property (ctx,
- jsobj,
- name,
- seed_value_from_gvalue (ctx, (GValue *) value,
- 0));
+ seed_object_set_property(ctx, jsobj, name,
+ seed_value_from_gvalue(ctx, (GValue*) value, 0));
- g_free (name);
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ g_free(name);
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
}
static void
-seed_gtype_builtin_get_property (GObject * object,
- guint property_id,
- GValue * value, GParamSpec * spec)
+seed_gtype_builtin_get_property(GObject* object,
+ guint property_id,
+ GValue* value,
+ GParamSpec* spec)
{
- // TODO: Exceptions
- JSContextRef ctx = JSGlobalContextCreateInGroup (context_group, 0);
- gchar *name = g_strjoin (NULL, "_", spec->name, NULL);
- JSObjectRef jsobj = (JSObjectRef) seed_value_from_object (ctx, object, 0);
- JSValueRef jsval = seed_object_get_property (ctx, jsobj,
- name);
+ // TODO: Exceptions
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
+ gchar* name = g_strjoin(NULL, "_", spec->name, NULL);
+ JSObjectRef jsobj = (JSObjectRef) seed_value_from_object(ctx, object, 0);
+ JSValueRef jsval = seed_object_get_property(ctx, jsobj, name);
- seed_prepare_global_context (ctx);
+ seed_prepare_global_context(ctx);
- seed_value_to_gvalue (ctx, jsval, spec->value_type, value, 0);
+ seed_value_to_gvalue(ctx, jsval, spec->value_type, value, 0);
- g_free (name);
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ g_free(name);
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
}
static void
-seed_gtype_set_property (GObject * object,
- guint property_id,
- const GValue * value, GParamSpec * spec)
+seed_gtype_set_property(GObject* object,
+ guint property_id,
+ const GValue* value,
+ GParamSpec* spec)
{
- gpointer data = g_param_spec_get_qdata (spec, qsetter);
+ gpointer data = g_param_spec_get_qdata(spec, qsetter);
- if (!data)
- {
- seed_gtype_builtin_set_property (object, property_id, value, spec);
- return;
+ if (!data) {
+ seed_gtype_builtin_set_property(object, property_id, value, spec);
+ return;
}
}
static void
-seed_gtype_get_property (GObject * object,
- guint property_id, GValue * value, GParamSpec * spec)
+seed_gtype_get_property(GObject* object,
+ guint property_id,
+ GValue* value,
+ GParamSpec* spec)
{
- gpointer data = g_param_spec_get_qdata (spec, qgetter);
+ gpointer data = g_param_spec_get_qdata(spec, qgetter);
- if (!data)
- {
- seed_gtype_builtin_get_property (object, property_id, value, spec);
- return;
+ if (!data) {
+ seed_gtype_builtin_get_property(object, property_id, value, spec);
+ return;
}
}
-static GIBaseInfo *
-seed_get_class_info_for_type (GType type)
+static GIBaseInfo*
+seed_get_class_info_for_type(GType type)
{
- GIBaseInfo *object_info;
-
- // Note to self: Investigate the entire premise of this function.
- while ((type = g_type_parent (type)))
- {
- GIBaseInfo *ret;
-
- object_info = g_irepository_find_by_gtype (NULL, type);
- if (object_info)
- {
- ret = g_object_info_get_class_struct ((GIObjectInfo *)object_info);
- g_base_info_unref (object_info);
-
- return ret;
- }
+ GIBaseInfo* object_info;
+
+ // Note to self: Investigate the entire premise of this function.
+ while ((type = g_type_parent(type))) {
+ GIBaseInfo* ret;
+
+ object_info = g_irepository_find_by_gtype(NULL, type);
+ if (object_info) {
+ ret = g_object_info_get_class_struct((GIObjectInfo*) object_info);
+ g_base_info_unref(object_info);
+
+ return ret;
+ }
}
-
- return NULL;
+
+ return NULL;
}
static void
-seed_attach_methods_to_class_object (JSContextRef ctx,
- JSObjectRef object,
- JSValueRef * exception)
+seed_attach_methods_to_class_object(JSContextRef ctx,
+ JSObjectRef object,
+ JSValueRef* exception)
{
- seed_create_function (ctx, "c_install_property",
- &seed_property_method_invoked, object);
- seed_create_function (ctx, "install_signal",
- &seed_gsignal_method_invoked, object);
+ seed_create_function(ctx, "c_install_property",
+ &seed_property_method_invoked, object);
+ seed_create_function(ctx, "install_signal", &seed_gsignal_method_invoked,
+ object);
}
static void
-seed_gtype_call_construct (GType type, GObject * object)
+seed_gtype_call_construct(GType type, GObject* object)
{
- JSContextRef ctx;
- JSObjectRef func, this_object;
- JSValueRef exception = NULL, args[1];
- gchar *mes;
-
- func = g_type_get_qdata (type, qiinit);
-
- if (func)
- {
- ctx = JSGlobalContextCreateInGroup (context_group, 0);
- seed_prepare_global_context (ctx);
-
- SEED_NOTE (GTYPE, "Handling constructor for: %p with type: %s",
- object, g_type_name (type));
- this_object = (JSObjectRef) seed_value_from_object (ctx, object, NULL);
- args[0] = this_object;
-
- JSObjectCallAsFunction (ctx, func, this_object, 1, args, &exception);
- if (exception)
- {
- mes = seed_exception_to_string (ctx, exception);
- g_warning ("Exception in instance construction. %s \n", mes);
- g_free (mes);
- }
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ JSContextRef ctx;
+ JSObjectRef func, this_object;
+ JSValueRef exception = NULL, args[1];
+ gchar* mes;
+
+ func = g_type_get_qdata(type, qiinit);
+
+ if (func) {
+ ctx = JSGlobalContextCreateInGroup(context_group, 0);
+ seed_prepare_global_context(ctx);
+
+ SEED_NOTE(GTYPE, "Handling constructor for: %p with type: %s", object,
+ g_type_name(type));
+ this_object = (JSObjectRef) seed_value_from_object(ctx, object, NULL);
+ args[0] = this_object;
+
+ JSObjectCallAsFunction(ctx, func, this_object, 1, args, &exception);
+ if (exception) {
+ mes = seed_exception_to_string(ctx, exception);
+ g_warning("Exception in instance construction. %s \n", mes);
+ g_free(mes);
+ }
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
}
-
-
}
-static GObject *
-seed_gtype_construct (GType type,
- guint n_construct_params,
- GObjectConstructParam * construct_params)
+static GObject*
+seed_gtype_construct(GType type,
+ guint n_construct_params,
+ GObjectConstructParam* construct_params)
{
- GObject *object;
- GType parent;
- GObjectClass *parent_class;
+ GObject* object;
+ GType parent;
+ GObjectClass* parent_class;
- parent = g_type_parent (type);
- parent_class = g_type_class_ref (parent);
+ parent = g_type_parent(type);
+ parent_class = g_type_class_ref(parent);
- if (parent_class->constructor == seed_gtype_construct)
- {
- GType t = parent;
- parent = g_type_parent (parent);
+ if (parent_class->constructor == seed_gtype_construct) {
+ GType t = parent;
+ parent = g_type_parent(parent);
- g_type_class_unref (parent_class);
- parent_class = g_type_class_ref (parent);
+ g_type_class_unref(parent_class);
+ parent_class = g_type_class_ref(parent);
- object =
- parent_class->constructor (type, n_construct_params,
- construct_params);
-
- seed_gtype_call_construct (t, object);
+ object = parent_class->constructor(type, n_construct_params,
+ construct_params);
- g_type_class_unref (parent_class);
- }
- else
- object =
- parent_class->constructor (type, n_construct_params, construct_params);
+ seed_gtype_call_construct(t, object);
+
+ g_type_class_unref(parent_class);
+ } else
+ object = parent_class->constructor(type, n_construct_params,
+ construct_params);
- seed_gtype_call_construct (type, object);
+ seed_gtype_call_construct(type, object);
- g_type_class_unref (parent_class);
+ g_type_class_unref(parent_class);
- return object;
+ return object;
}
static void
-seed_gtype_install_signals (JSContextRef ctx,
- JSObjectRef definition, GType type,
- JSValueRef * exception)
+seed_gtype_install_signals(JSContextRef ctx,
+ JSObjectRef definition,
+ GType type,
+ JSValueRef* exception)
{
- JSObjectRef signals, signal_def;
- JSValueRef jslength;
- guint i, j, length;
- GType return_type;
- GType *param_types = NULL;
- guint n_params = 0;
- GSignalFlags flags;
- JSValueRef jsname, jsflags, jsreturn_type, jsparams;
- gchar *name;
-
- signals =
- (JSObjectRef) seed_object_get_property (ctx, definition, "signals");
- if (JSValueIsNull (ctx, signals) || !JSValueIsObject (ctx, signals))
- return;
-
- jslength = seed_object_get_property (ctx, signals, "length");
- if (JSValueIsNull (ctx, jslength))
- return;
-
- length = seed_value_to_uint (ctx, jslength, exception);
- for (i = 0; i < length; i++)
- {
- signal_def = (JSObjectRef) JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- signals, i,
- exception);
-
- if (JSValueIsNull (ctx, signal_def)
- || !JSValueIsObject (ctx, signal_def))
- continue;
-
- // TODO: Error checking
- jsname = seed_object_get_property (ctx, signal_def, "name");
- name = seed_value_to_string (ctx, jsname, exception);
-
- SEED_NOTE (GTYPE, "Installing signal with name: %s on type: %s",
- name, g_type_name (type));
-
- jsflags =
- seed_object_get_property (ctx, (JSObjectRef) signal_def, "flags");
- if (JSValueIsNull (ctx, jsflags) || !JSValueIsNumber (ctx, jsflags))
- flags = G_SIGNAL_RUN_LAST;
- else
- flags = seed_value_to_long (ctx, jsflags, exception);
-
- jsreturn_type =
- seed_object_get_property (ctx, signal_def, "return_type");
- if (JSValueIsNull (ctx, jsreturn_type)
- || !JSValueIsNumber (ctx, jsreturn_type))
- return_type = G_TYPE_NONE;
- else
- return_type = seed_value_to_long (ctx, jsreturn_type, exception);
-
- jsparams = seed_object_get_property (ctx, signal_def, "parameters");
-
- // reset params..
- param_types = NULL;
- n_params = 0;
-
- if (!JSValueIsNull (ctx, jsparams) && JSValueIsObject (ctx, jsparams))
- {
- n_params =
- seed_value_to_int (ctx,
- seed_object_get_property (ctx,
- (JSObjectRef)
- jsparams, "length"),
- exception);
- if (n_params > 0)
- {
- param_types = g_alloca (sizeof (GType) * n_params);
- for (j = 0; j < n_params; j++)
- {
- JSValueRef ptype = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- jsparams,
- j,
- exception);
- param_types[j] =
- (GType) seed_value_to_long (ctx, ptype, exception);
- }
- }
- }
-
- g_signal_newv (name, type,
- flags, 0, 0, 0,
- gi_cclosure_marshal_generic,
- return_type, n_params, param_types);
- g_free (name);
-
+ JSObjectRef signals, signal_def;
+ JSValueRef jslength;
+ guint i, j, length;
+ GType return_type;
+ GType* param_types = NULL;
+ guint n_params = 0;
+ GSignalFlags flags;
+ JSValueRef jsname, jsflags, jsreturn_type, jsparams;
+ gchar* name;
+
+ signals
+ = (JSObjectRef) seed_object_get_property(ctx, definition, "signals");
+ if (JSValueIsNull(ctx, signals) || !JSValueIsObject(ctx, signals))
+ return;
+
+ jslength = seed_object_get_property(ctx, signals, "length");
+ if (JSValueIsNull(ctx, jslength))
+ return;
+
+ length = seed_value_to_uint(ctx, jslength, exception);
+ for (i = 0; i < length; i++) {
+ signal_def
+ = (JSObjectRef) JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) signals,
+ i, exception);
+
+ if (JSValueIsNull(ctx, signal_def) || !JSValueIsObject(ctx, signal_def))
+ continue;
+
+ // TODO: Error checking
+ jsname = seed_object_get_property(ctx, signal_def, "name");
+ name = seed_value_to_string(ctx, jsname, exception);
+
+ SEED_NOTE(GTYPE, "Installing signal with name: %s on type: %s", name,
+ g_type_name(type));
+
+ jsflags
+ = seed_object_get_property(ctx, (JSObjectRef) signal_def, "flags");
+ if (JSValueIsNull(ctx, jsflags) || !JSValueIsNumber(ctx, jsflags))
+ flags = G_SIGNAL_RUN_LAST;
+ else
+ flags = seed_value_to_long(ctx, jsflags, exception);
+
+ jsreturn_type
+ = seed_object_get_property(ctx, signal_def, "return_type");
+ if (JSValueIsNull(ctx, jsreturn_type)
+ || !JSValueIsNumber(ctx, jsreturn_type))
+ return_type = G_TYPE_NONE;
+ else
+ return_type = seed_value_to_long(ctx, jsreturn_type, exception);
+
+ jsparams = seed_object_get_property(ctx, signal_def, "parameters");
+
+ // reset params..
+ param_types = NULL;
+ n_params = 0;
+
+ if (!JSValueIsNull(ctx, jsparams) && JSValueIsObject(ctx, jsparams)) {
+ n_params = seed_value_to_int(
+ ctx,
+ seed_object_get_property(ctx, (JSObjectRef) jsparams, "length"),
+ exception);
+ if (n_params > 0) {
+ param_types = g_alloca(sizeof(GType) * n_params);
+ for (j = 0; j < n_params; j++) {
+ JSValueRef ptype
+ = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) jsparams,
+ j, exception);
+ param_types[j]
+ = (GType) seed_value_to_long(ctx, ptype, exception);
+ }
+ }
+ }
+
+ g_signal_newv(name, type, flags, 0, 0, 0, gi_cclosure_marshal_generic,
+ return_type, n_params, param_types);
+ g_free(name);
}
}
static unsigned int
-seed_gtype_install_properties (JSContextRef ctx,
- JSObjectRef definition,
- GType type, GObjectClass *g_class,
- JSValueRef * exception)
+seed_gtype_install_properties(JSContextRef ctx,
+ JSObjectRef definition,
+ GType type,
+ GObjectClass* g_class,
+ JSValueRef* exception)
{
- JSObjectRef properties, property_def;
- JSValueRef jslength;
- guint i, length;
- GType property_type, object_type;
- GParamFlags flags;
- JSValueRef jsname, jsflags, jsproperty_type, jsdefault_value, jsobject_type;
- JSValueRef jsnick, jsblurb, jsmin_value, jsmax_value;
- gchar *name , *nick, *blurb;
- GParamSpec *pspec;
- guint property_count = 0;
-
- properties = (JSObjectRef) seed_object_get_property (ctx, definition,
- "properties");
- if (JSValueIsNull (ctx, properties) || !JSValueIsObject (ctx, properties))
- return 0;
-
- jslength = seed_object_get_property (ctx, properties, "length");
- if (JSValueIsNull (ctx, jslength))
- return 0;
-
- length = seed_value_to_uint (ctx, jslength, exception);
- for (i = 0; i < length; i++)
- {
- property_def = (JSObjectRef) JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- properties, i,
- NULL);
-
- if (JSValueIsNull (ctx, property_def)
- || !JSValueIsObject (ctx, property_def))
- continue;
-
- jsname = seed_object_get_property (ctx, property_def, "name");
- if (!JSValueIsString(ctx, jsname))
- {
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property requires name attribute");
- return property_count;
- }
- name = seed_value_to_string (ctx, jsname, exception);
-
- // Check for "nick" property; set to name if nonexistent
- jsnick = seed_object_get_property (ctx, property_def, "nick");
- if (!JSValueIsString(ctx, jsnick))
- nick = name;
- else
- nick = seed_value_to_string (ctx, jsnick, exception);
-
- // Check for "blurb" property; set to name if nonexistent
- jsblurb = seed_object_get_property (ctx, property_def, "blurb");
- if (!JSValueIsString(ctx, jsblurb))
- blurb = name;
- else
- blurb = seed_value_to_string (ctx, jsblurb, exception);
-
- SEED_NOTE (GTYPE, "Installing property with name: %s on type: %s",
- name, g_type_name (type));
-
- // Flags default to read/write, non-construct
- jsflags =
- seed_object_get_property (ctx, (JSObjectRef) property_def, "flags");
- if (JSValueIsNull (ctx, jsflags) || !JSValueIsNumber (ctx, jsflags))
- flags = G_PARAM_READABLE | G_PARAM_WRITABLE;
- else
- flags = seed_value_to_long (ctx, jsflags, exception);
-
- jsproperty_type = seed_object_get_property (ctx, property_def, "type");
-
- if (JSValueIsNull (ctx, jsproperty_type) ||
- !JSValueIsNumber (ctx, jsproperty_type))
- property_type = G_TYPE_NONE;
- else
- property_type = seed_value_to_long (ctx, jsproperty_type, exception);
-
- jsdefault_value = seed_object_get_property (ctx, property_def,
- "default_value");
-
- if (JSValueIsNull (ctx, jsdefault_value) ||
- JSValueIsUndefined (ctx, jsdefault_value))
- {
- if(property_type == G_TYPE_OBJECT)
- continue;
-
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property of type %s requires default_value attribute",
- g_type_name(property_type));
- return property_count;
- }
-
- jsmin_value = seed_object_get_property (ctx, property_def,
- "minimum_value");
- jsmax_value = seed_object_get_property (ctx, property_def,
- "maximum_value");
-
- // Make sure min/max properties are defined, based on type
- if(property_type == G_TYPE_CHAR ||
- property_type == G_TYPE_UCHAR ||
- property_type == G_TYPE_INT ||
- property_type == G_TYPE_UINT ||
- property_type == G_TYPE_INT64 ||
- property_type == G_TYPE_UINT64 ||
- property_type == G_TYPE_FLOAT ||
- property_type == G_TYPE_DOUBLE)
- {
- if (JSValueIsNull (ctx, jsmin_value) ||
- !JSValueIsNumber (ctx, jsmin_value))
- {
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property of type %s requires minimum_value attribute",
- g_type_name(property_type));
- return property_count;
- }
- if (JSValueIsNull (ctx, jsmax_value) ||
- !JSValueIsNumber (ctx, jsmax_value))
- {
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property of type %s requires maximum_value attribute",
- g_type_name(property_type));
- return property_count;
- }
- }
-
-
- switch(property_type)
- {
- case G_TYPE_BOOLEAN:
- pspec = g_param_spec_boolean(name, nick, blurb,
- seed_value_to_boolean(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_CHAR:
- pspec = g_param_spec_char(name, nick, blurb,
- seed_value_to_char(ctx,
- jsmin_value,
- exception),
- seed_value_to_char(ctx,
- jsmax_value,
- exception),
- seed_value_to_char(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_UCHAR:
- pspec = g_param_spec_uchar(name, nick, blurb,
- seed_value_to_uchar(ctx,
- jsmin_value,
- exception),
- seed_value_to_uchar(ctx,
- jsmax_value,
- exception),
- seed_value_to_uchar(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_INT:
- pspec = g_param_spec_int(name, nick, blurb,
- seed_value_to_int(ctx,
- jsmin_value,
- exception),
- seed_value_to_int(ctx,
- jsmax_value,
- exception),
- seed_value_to_int(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_UINT:
- pspec = g_param_spec_uint(name, nick, blurb,
- seed_value_to_uint(ctx,
- jsmin_value,
- exception),
- seed_value_to_uint(ctx,
- jsmax_value,
- exception),
- seed_value_to_uint(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_LONG:
- pspec = g_param_spec_long(name, nick, blurb,
- seed_value_to_long(ctx,
- jsmin_value,
- exception),
- seed_value_to_long(ctx,
- jsmax_value,
- exception),
- seed_value_to_long(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_ULONG:
- pspec = g_param_spec_ulong(name, nick, blurb,
- seed_value_to_ulong(ctx,
- jsmin_value,
- exception),
- seed_value_to_ulong(ctx,
- jsmax_value,
- exception),
- seed_value_to_ulong(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_INT64:
- pspec = g_param_spec_int64(name, nick, blurb,
- seed_value_to_int64(ctx,
- jsmin_value,
- exception),
- seed_value_to_int64(ctx,
- jsmax_value,
- exception),
- seed_value_to_int64(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_UINT64:
- pspec = g_param_spec_uint64(name, nick, blurb,
- seed_value_to_uint64(ctx,
- jsmin_value,
- exception),
- seed_value_to_uint64(ctx,
- jsmax_value,
- exception),
- seed_value_to_uint64(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_FLOAT:
- pspec = g_param_spec_float(name, nick, blurb,
- seed_value_to_float(ctx,
- jsmin_value,
- exception),
- seed_value_to_float(ctx,
- jsmax_value,
- exception),
- seed_value_to_float(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_DOUBLE:
- pspec = g_param_spec_double(name, nick, blurb,
- seed_value_to_double(ctx,
- jsmin_value,
- exception),
- seed_value_to_double(ctx,
- jsmax_value,
- exception),
- seed_value_to_double(ctx,
- jsdefault_value,
- exception), flags);
- break;
- // TODO: support enums/flags/params
- case G_TYPE_STRING:
- // TODO: leaky?
- pspec = g_param_spec_string(name, nick, blurb,
- seed_value_to_string(ctx,
- jsdefault_value,
- exception), flags);
- break;
- case G_TYPE_OBJECT:
- jsobject_type = seed_object_get_property (ctx, property_def,
- "object_type");
-
- if (JSValueIsNull (ctx, jsobject_type) ||
- !JSValueIsNumber (ctx, jsobject_type))
- object_type = G_TYPE_NONE;
- else
- object_type = seed_value_to_long (ctx, jsobject_type, exception);
-
- if(object_type == G_TYPE_NONE)
- {
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property of type %s requires object_type attribute",
- g_type_name(property_type));
- return property_count;
- }
-
- pspec = g_param_spec_object(name, nick, blurb,
- object_type, flags);
- break;
- case G_TYPE_BOXED: // Boxed types TODO: this is almost certainly wrong
- pspec = g_param_spec_boxed(name, nick, blurb, type, flags);
- break;
- default:
- case G_TYPE_NONE:
- seed_make_exception (ctx, exception, "PropertyInstallationError",
- "Property requires type attribute");
- return property_count;
- break;
- }
-
- g_object_class_install_property (g_class, ++property_count, pspec);
-
- if (nick != name)
- g_free (nick);
-
- if (blurb != name)
- g_free (blurb);
-
- g_free (name);
+ JSObjectRef properties, property_def;
+ JSValueRef jslength;
+ guint i, length;
+ GType property_type, object_type;
+ GParamFlags flags;
+ JSValueRef jsname, jsflags, jsproperty_type, jsdefault_value, jsobject_type;
+ JSValueRef jsnick, jsblurb, jsmin_value, jsmax_value;
+ gchar *name, *nick, *blurb;
+ GParamSpec* pspec;
+ guint property_count = 0;
+
+ properties
+ = (JSObjectRef) seed_object_get_property(ctx, definition, "properties");
+ if (JSValueIsNull(ctx, properties) || !JSValueIsObject(ctx, properties))
+ return 0;
+
+ jslength = seed_object_get_property(ctx, properties, "length");
+ if (JSValueIsNull(ctx, jslength))
+ return 0;
+
+ length = seed_value_to_uint(ctx, jslength, exception);
+ for (i = 0; i < length; i++) {
+ property_def
+ = (JSObjectRef) JSObjectGetPropertyAtIndex(ctx,
+ (JSObjectRef) properties,
+ i, NULL);
+
+ if (JSValueIsNull(ctx, property_def)
+ || !JSValueIsObject(ctx, property_def))
+ continue;
+
+ jsname = seed_object_get_property(ctx, property_def, "name");
+ if (!JSValueIsString(ctx, jsname)) {
+ seed_make_exception(ctx, exception, "PropertyInstallationError",
+ "Property requires name attribute");
+ return property_count;
+ }
+ name = seed_value_to_string(ctx, jsname, exception);
+
+ // Check for "nick" property; set to name if nonexistent
+ jsnick = seed_object_get_property(ctx, property_def, "nick");
+ if (!JSValueIsString(ctx, jsnick))
+ nick = name;
+ else
+ nick = seed_value_to_string(ctx, jsnick, exception);
+
+ // Check for "blurb" property; set to name if nonexistent
+ jsblurb = seed_object_get_property(ctx, property_def, "blurb");
+ if (!JSValueIsString(ctx, jsblurb))
+ blurb = name;
+ else
+ blurb = seed_value_to_string(ctx, jsblurb, exception);
+
+ SEED_NOTE(GTYPE, "Installing property with name: %s on type: %s", name,
+ g_type_name(type));
+
+ // Flags default to read/write, non-construct
+ jsflags
+ = seed_object_get_property(ctx, (JSObjectRef) property_def, "flags");
+ if (JSValueIsNull(ctx, jsflags) || !JSValueIsNumber(ctx, jsflags))
+ flags = G_PARAM_READABLE | G_PARAM_WRITABLE;
+ else
+ flags = seed_value_to_long(ctx, jsflags, exception);
+
+ jsproperty_type = seed_object_get_property(ctx, property_def, "type");
+
+ if (JSValueIsNull(ctx, jsproperty_type)
+ || !JSValueIsNumber(ctx, jsproperty_type))
+ property_type = G_TYPE_NONE;
+ else
+ property_type = seed_value_to_long(ctx, jsproperty_type, exception);
+
+ jsdefault_value
+ = seed_object_get_property(ctx, property_def, "default_value");
+
+ if (JSValueIsNull(ctx, jsdefault_value)
+ || JSValueIsUndefined(ctx, jsdefault_value)) {
+ if (property_type == G_TYPE_OBJECT)
+ continue;
+
+ seed_make_exception(
+ ctx, exception, "PropertyInstallationError",
+ "Property of type %s requires default_value attribute",
+ g_type_name(property_type));
+ return property_count;
+ }
+
+ jsmin_value
+ = seed_object_get_property(ctx, property_def, "minimum_value");
+ jsmax_value
+ = seed_object_get_property(ctx, property_def, "maximum_value");
+
+ // Make sure min/max properties are defined, based on type
+ if (property_type == G_TYPE_CHAR || property_type == G_TYPE_UCHAR
+ || property_type == G_TYPE_INT || property_type == G_TYPE_UINT
+ || property_type == G_TYPE_INT64 || property_type == G_TYPE_UINT64
+ || property_type == G_TYPE_FLOAT
+ || property_type == G_TYPE_DOUBLE) {
+ if (JSValueIsNull(ctx, jsmin_value)
+ || !JSValueIsNumber(ctx, jsmin_value)) {
+ seed_make_exception(
+ ctx, exception, "PropertyInstallationError",
+ "Property of type %s requires minimum_value attribute",
+ g_type_name(property_type));
+ return property_count;
+ }
+ if (JSValueIsNull(ctx, jsmax_value)
+ || !JSValueIsNumber(ctx, jsmax_value)) {
+ seed_make_exception(
+ ctx, exception, "PropertyInstallationError",
+ "Property of type %s requires maximum_value attribute",
+ g_type_name(property_type));
+ return property_count;
+ }
+ }
+
+ switch (property_type) {
+ case G_TYPE_BOOLEAN:
+ pspec = g_param_spec_boolean(
+ name, nick, blurb,
+ seed_value_to_boolean(ctx, jsdefault_value, exception),
+ flags);
+ break;
+ case G_TYPE_CHAR:
+ pspec = g_param_spec_char(
+ name, nick, blurb,
+ seed_value_to_char(ctx, jsmin_value, exception),
+ seed_value_to_char(ctx, jsmax_value, exception),
+ seed_value_to_char(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_UCHAR:
+ pspec = g_param_spec_uchar(
+ name, nick, blurb,
+ seed_value_to_uchar(ctx, jsmin_value, exception),
+ seed_value_to_uchar(ctx, jsmax_value, exception),
+ seed_value_to_uchar(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_INT:
+ pspec = g_param_spec_int(
+ name, nick, blurb,
+ seed_value_to_int(ctx, jsmin_value, exception),
+ seed_value_to_int(ctx, jsmax_value, exception),
+ seed_value_to_int(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_UINT:
+ pspec = g_param_spec_uint(
+ name, nick, blurb,
+ seed_value_to_uint(ctx, jsmin_value, exception),
+ seed_value_to_uint(ctx, jsmax_value, exception),
+ seed_value_to_uint(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_LONG:
+ pspec = g_param_spec_long(
+ name, nick, blurb,
+ seed_value_to_long(ctx, jsmin_value, exception),
+ seed_value_to_long(ctx, jsmax_value, exception),
+ seed_value_to_long(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_ULONG:
+ pspec = g_param_spec_ulong(
+ name, nick, blurb,
+ seed_value_to_ulong(ctx, jsmin_value, exception),
+ seed_value_to_ulong(ctx, jsmax_value, exception),
+ seed_value_to_ulong(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_INT64:
+ pspec = g_param_spec_int64(
+ name, nick, blurb,
+ seed_value_to_int64(ctx, jsmin_value, exception),
+ seed_value_to_int64(ctx, jsmax_value, exception),
+ seed_value_to_int64(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_UINT64:
+ pspec = g_param_spec_uint64(
+ name, nick, blurb,
+ seed_value_to_uint64(ctx, jsmin_value, exception),
+ seed_value_to_uint64(ctx, jsmax_value, exception),
+ seed_value_to_uint64(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_FLOAT:
+ pspec = g_param_spec_float(
+ name, nick, blurb,
+ seed_value_to_float(ctx, jsmin_value, exception),
+ seed_value_to_float(ctx, jsmax_value, exception),
+ seed_value_to_float(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_DOUBLE:
+ pspec = g_param_spec_double(
+ name, nick, blurb,
+ seed_value_to_double(ctx, jsmin_value, exception),
+ seed_value_to_double(ctx, jsmax_value, exception),
+ seed_value_to_double(ctx, jsdefault_value, exception), flags);
+ break;
+ // TODO: support enums/flags/params
+ case G_TYPE_STRING:
+ // TODO: leaky?
+ pspec = g_param_spec_string(
+ name, nick, blurb,
+ seed_value_to_string(ctx, jsdefault_value, exception), flags);
+ break;
+ case G_TYPE_OBJECT:
+ jsobject_type
+ = seed_object_get_property(ctx, property_def, "object_type");
+
+ if (JSValueIsNull(ctx, jsobject_type)
+ || !JSValueIsNumber(ctx, jsobject_type))
+ object_type = G_TYPE_NONE;
+ else
+ object_type
+ = seed_value_to_long(ctx, jsobject_type, exception);
+
+ if (object_type == G_TYPE_NONE) {
+ seed_make_exception(
+ ctx, exception, "PropertyInstallationError",
+ "Property of type %s requires object_type attribute",
+ g_type_name(property_type));
+ return property_count;
+ }
+
+ pspec
+ = g_param_spec_object(name, nick, blurb, object_type, flags);
+ break;
+ case G_TYPE_BOXED: // Boxed types TODO: this is almost certainly
+ // wrong
+ pspec = g_param_spec_boxed(name, nick, blurb, type, flags);
+ break;
+ default:
+ case G_TYPE_NONE:
+ seed_make_exception(ctx, exception, "PropertyInstallationError",
+ "Property requires type attribute");
+ return property_count;
+ break;
+ }
+
+ g_object_class_install_property(g_class, ++property_count, pspec);
+
+ if (nick != name)
+ g_free(nick);
+
+ if (blurb != name)
+ g_free(blurb);
+
+ g_free(name);
}
- return property_count;
+ return property_count;
}
static void
-seed_gtype_class_init (gpointer g_class, gpointer class_data)
+seed_gtype_class_init(gpointer g_class, gpointer class_data)
{
- SeedGClassPrivates *priv;
- GIBaseInfo *class_info;
- JSContextRef ctx;
- JSValueRef jsargs[2];
- GType type;
- JSValueRef exception = NULL;
- int initial_prop_count = 1;
- GQuark class_init_exception_q =
- g_quark_from_static_string("type-class-init-exception");
-
- priv = (SeedGClassPrivates *) class_data;
-
- ((GObjectClass *)g_class)->get_property = seed_gtype_get_property;
- ((GObjectClass *)g_class)->set_property = seed_gtype_set_property;
- ((GObjectClass *)g_class)->constructor = seed_gtype_construct;
-
- ctx = JSGlobalContextCreateInGroup (context_group, 0);
-
- type = (GType) JSObjectGetPrivate (priv->constructor);
- seed_gtype_install_signals (ctx, priv->definition, type, &exception);
- initial_prop_count = seed_gtype_install_properties (ctx,
- priv->definition,
- type,
- (GObjectClass *) g_class,
- &exception);
-
- if (!priv->func)
- {
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
- if (exception)
- {
- g_type_set_qdata(type, class_init_exception_q, (gpointer)exception);
- }
- return;
+ SeedGClassPrivates* priv;
+ GIBaseInfo* class_info;
+ JSContextRef ctx;
+ JSValueRef jsargs[2];
+ GType type;
+ JSValueRef exception = NULL;
+ int initial_prop_count = 1;
+ GQuark class_init_exception_q
+ = g_quark_from_static_string("type-class-init-exception");
+
+ priv = (SeedGClassPrivates*) class_data;
+
+ ((GObjectClass*) g_class)->get_property = seed_gtype_get_property;
+ ((GObjectClass*) g_class)->set_property = seed_gtype_set_property;
+ ((GObjectClass*) g_class)->constructor = seed_gtype_construct;
+
+ ctx = JSGlobalContextCreateInGroup(context_group, 0);
+
+ type = (GType) JSObjectGetPrivate(priv->constructor);
+ seed_gtype_install_signals(ctx, priv->definition, type, &exception);
+ initial_prop_count
+ = seed_gtype_install_properties(ctx, priv->definition, type,
+ (GObjectClass*) g_class, &exception);
+
+ if (!priv->func) {
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
+ if (exception) {
+ g_type_set_qdata(type, class_init_exception_q,
+ (gpointer) exception);
+ }
+ return;
}
- seed_prepare_global_context (ctx);
+ seed_prepare_global_context(ctx);
- class_info = seed_get_class_info_for_type (type);
+ class_info = seed_get_class_info_for_type(type);
- jsargs[0] = seed_make_struct (ctx, g_class, class_info);
- jsargs[1] = seed_gobject_get_prototype_for_gtype (type);
+ jsargs[0] = seed_make_struct(ctx, g_class, class_info);
+ jsargs[1] = seed_gobject_get_prototype_for_gtype(type);
- seed_attach_methods_to_class_object (ctx, (JSObjectRef) jsargs[0],
- &exception);
+ seed_attach_methods_to_class_object(ctx, (JSObjectRef) jsargs[0],
+ &exception);
- g_base_info_unref ((GIBaseInfo *) class_info);
+ g_base_info_unref((GIBaseInfo*) class_info);
- SEED_NOTE (GTYPE, "Marshalling class init for type: %s",
- g_type_name (type));
+ SEED_NOTE(GTYPE, "Marshalling class init for type: %s", g_type_name(type));
- seed_object_set_property (ctx, (JSObjectRef) jsargs[0],
- "type", seed_value_from_int (ctx, type, 0));
- seed_object_set_property (ctx, (JSObjectRef) jsargs[0],
- "property_count",
- seed_value_from_int (ctx, initial_prop_count + 1,
- 0));
+ seed_object_set_property(ctx, (JSObjectRef) jsargs[0], "type",
+ seed_value_from_int(ctx, type, 0));
+ seed_object_set_property(ctx, (JSObjectRef) jsargs[0], "property_count",
+ seed_value_from_int(ctx, initial_prop_count + 1,
+ 0));
- JSObjectCallAsFunction (ctx, priv->func, 0, 2, jsargs, &exception);
- if (exception)
- {
- g_type_set_qdata(type, class_init_exception_q, (gpointer)exception);
+ JSObjectCallAsFunction(ctx, priv->func, 0, 2, jsargs, &exception);
+ if (exception) {
+ g_type_set_qdata(type, class_init_exception_q, (gpointer) exception);
}
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
}
static JSObjectRef
-seed_gtype_constructor_invoked (JSContextRef ctx,
- JSObjectRef constructor,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gtype_constructor_invoked(JSContextRef ctx,
+ JSObjectRef constructor,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSValueRef class_init, instance_init, name, parent_ref;
- GType parent_type, new_type;
- gchar *new_name;
- GTypeInfo type_info = {
- 0,
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) NULL,
- (GClassFinalizeFunc) NULL,
- NULL,
- 0,
- 0,
- NULL
- };
- GTypeQuery query;
- JSObjectRef constructor_ref;
- SeedGClassPrivates *priv;
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "GType constructor expected 1 "
- "argument, got %zd \n", argumentCount);
- return (JSObjectRef) JSValueMakeNull (ctx);
+ JSValueRef class_init, instance_init, name, parent_ref;
+ GType parent_type, new_type;
+ gchar* new_name;
+ GTypeInfo type_info = { 0,
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) NULL,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ 0,
+ 0,
+ NULL };
+ GTypeQuery query;
+ JSObjectRef constructor_ref;
+ SeedGClassPrivates* priv;
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "GType constructor expected 1 "
+ "argument, got %zd \n",
+ argumentCount);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- if (!JSValueIsObject (ctx, arguments[0]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "GType constructor expected a"
- "class definition object. Got a nonobject");
+ if (!JSValueIsObject(ctx, arguments[0])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "GType constructor expected a"
+ "class definition object. Got a nonobject");
- return (JSObjectRef) JSValueMakeNull (ctx);
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- parent_ref = seed_object_get_property (ctx,
- (JSObjectRef) arguments[0],
- "parent");
- class_init =
- seed_object_get_property (ctx, (JSObjectRef) arguments[0], "class_init");
- instance_init =
- seed_object_get_property (ctx, (JSObjectRef) arguments[0], "init");
- name = seed_object_get_property (ctx, (JSObjectRef) arguments[0], "name");
-
- new_name = seed_value_to_string (ctx, name, exception);
- if (!JSValueIsNumber (ctx, parent_ref))
- {
- seed_make_exception (ctx, exception, "TypeError",
- "GType constructor expected GType for parent");
-
- return (JSObjectRef) JSValueMakeNull (ctx);
+ parent_ref
+ = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "parent");
+ class_init
+ = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "class_init");
+ instance_init
+ = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "init");
+ name = seed_object_get_property(ctx, (JSObjectRef) arguments[0], "name");
+
+ new_name = seed_value_to_string(ctx, name, exception);
+ if (!JSValueIsNumber(ctx, parent_ref)) {
+ seed_make_exception(ctx, exception, "TypeError",
+ "GType constructor expected GType for parent");
+
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
+ // TODO: GType is of variable length, so this is an incorrect fix
+ parent_type = (GType) seed_value_to_long(ctx, parent_ref, exception);
- // TODO: GType is of variable length, so this is an incorrect fix
- parent_type = (GType) seed_value_to_long (ctx, parent_ref, exception);
-
- SEED_NOTE (GTYPE, "Registering new GType with name: %s as child of %s.",
- new_name, g_type_name (parent_type));
+ SEED_NOTE(GTYPE, "Registering new GType with name: %s as child of %s.",
+ new_name, g_type_name(parent_type));
- g_type_query (parent_type, &query);
- type_info.class_size = query.class_size;
- type_info.instance_size = query.instance_size;
- type_info.class_init = seed_gtype_class_init;
+ g_type_query(parent_type, &query);
+ type_info.class_size = query.class_size;
+ type_info.instance_size = query.instance_size;
+ type_info.class_init = seed_gtype_class_init;
- priv = g_slice_alloc (sizeof (SeedGClassPrivates));
+ priv = g_slice_alloc(sizeof(SeedGClassPrivates));
- if (!JSValueIsNull (ctx, class_init) &&
- JSValueIsObject (ctx, class_init) &&
- JSObjectIsFunction (ctx, (JSObjectRef) class_init))
- {
- priv->func = (gpointer) class_init;
- JSValueProtect (ctx, class_init);
+ if (!JSValueIsNull(ctx, class_init) && JSValueIsObject(ctx, class_init)
+ && JSObjectIsFunction(ctx, (JSObjectRef) class_init)) {
+ priv->func = (gpointer) class_init;
+ JSValueProtect(ctx, class_init);
}
+ constructor_ref
+ = JSObjectMake(ctx, gobject_constructor_class, (gpointer) 0);
+ JSValueProtect(ctx, constructor_ref);
- constructor_ref = JSObjectMake (ctx, gobject_constructor_class,
- (gpointer) 0);
- JSValueProtect (ctx, constructor_ref);
+ priv->constructor = constructor_ref;
- priv->constructor = constructor_ref;
+ JSValueProtect(ctx, arguments[0]);
+ priv->definition = (JSObjectRef) arguments[0];
- JSValueProtect (ctx, arguments[0]);
- priv->definition = (JSObjectRef) arguments[0];
+ type_info.class_data = priv;
- type_info.class_data = priv;
+ new_type = g_type_register_static(parent_type, new_name, &type_info, 0);
+ seed_gobject_get_class_for_gtype(ctx, new_type);
+ JSObjectSetPrivate(constructor_ref, (gpointer) new_type);
- new_type = g_type_register_static (parent_type, new_name, &type_info, 0);
- seed_gobject_get_class_for_gtype (ctx, new_type);
- JSObjectSetPrivate (constructor_ref, (gpointer) new_type);
+ seed_object_set_property(ctx, constructor_ref, "type",
+ seed_value_from_int(ctx, new_type, exception));
- seed_object_set_property (ctx, constructor_ref,
- "type", seed_value_from_int (ctx, new_type,
- exception));
-
- if (!JSValueIsNull (ctx, instance_init) &&
- JSValueIsObject (ctx, instance_init) &&
- JSObjectIsFunction (ctx, (JSObjectRef) instance_init))
- {
- g_type_set_qdata (new_type, qiinit, (gpointer) instance_init);
- JSValueProtect (ctx, instance_init);
+ if (!JSValueIsNull(ctx, instance_init)
+ && JSValueIsObject(ctx, instance_init)
+ && JSObjectIsFunction(ctx, (JSObjectRef) instance_init)) {
+ g_type_set_qdata(new_type, qiinit, (gpointer) instance_init);
+ JSValueProtect(ctx, instance_init);
}
- g_free (new_name);
- return constructor_ref;
+ g_free(new_name);
+ return constructor_ref;
}
static JSValueRef
-seed_param_getter_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_param_getter_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GParamSpec *pspec = seed_pointer_get_pointer (ctx, thisObject);
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "ParamSpec.get expected "
- "1 argument, got %zd", argumentCount);
-
- return JSValueMakeNull (ctx);
- }
- else if (JSValueIsNull (ctx, arguments[0]) ||
- !JSValueIsObject (ctx, arguments[0]) ||
- !JSObjectIsFunction (ctx, (JSObjectRef) arguments[0]))
- {
- // Maybe should accept C functions
- seed_make_exception (ctx, exception, "ArgumentError",
- "ParamSpec.get expected a function");
- return JSValueMakeNull (ctx);
+ GParamSpec* pspec = seed_pointer_get_pointer(ctx, thisObject);
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "ParamSpec.get expected "
+ "1 argument, got %zd",
+ argumentCount);
+
+ return JSValueMakeNull(ctx);
+ } else if (JSValueIsNull(ctx, arguments[0])
+ || !JSValueIsObject(ctx, arguments[0])
+ || !JSObjectIsFunction(ctx, (JSObjectRef) arguments[0])) {
+ // Maybe should accept C functions
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "ParamSpec.get expected a function");
+ return JSValueMakeNull(ctx);
}
- g_param_spec_set_qdata (pspec, qgetter, (gpointer) arguments[0]);
+ g_param_spec_set_qdata(pspec, qgetter, (gpointer) arguments[0]);
- return seed_value_from_boolean (ctx, TRUE, exception);
+ return seed_value_from_boolean(ctx, TRUE, exception);
}
static JSValueRef
-seed_param_setter_invoked (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_param_setter_invoked(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- GParamSpec *pspec = seed_pointer_get_pointer (ctx, thisObject);
-
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "ParamSpec.set expected "
- "1 argument, got %zd", argumentCount);
-
- return JSValueMakeNull (ctx);
- }
- else if (JSValueIsNull (ctx, arguments[0]) ||
- !JSValueIsObject (ctx, arguments[0]) ||
- !JSObjectIsFunction (ctx, (JSObjectRef) arguments[0]))
- {
- // Maybe should accept C functions
- seed_make_exception (ctx, exception, "ArgumentError",
- "ParamSpec.set expected a function");
- return JSValueMakeNull (ctx);
+ GParamSpec* pspec = seed_pointer_get_pointer(ctx, thisObject);
+
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "ParamSpec.set expected "
+ "1 argument, got %zd",
+ argumentCount);
+
+ return JSValueMakeNull(ctx);
+ } else if (JSValueIsNull(ctx, arguments[0])
+ || !JSValueIsObject(ctx, arguments[0])
+ || !JSObjectIsFunction(ctx, (JSObjectRef) arguments[0])) {
+ // Maybe should accept C functions
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "ParamSpec.set expected a function");
+ return JSValueMakeNull(ctx);
}
- g_param_spec_set_qdata (pspec, qsetter, (gpointer) arguments[0]);
+ g_param_spec_set_qdata(pspec, qsetter, (gpointer) arguments[0]);
- return seed_value_from_boolean (ctx, TRUE, exception);
+ return seed_value_from_boolean(ctx, TRUE, exception);
}
void
-seed_define_gtype_functions (JSContextRef ctx)
+seed_define_gtype_functions(JSContextRef ctx)
{
- JSObjectRef proto;
-
- objectclass_info = g_irepository_find_by_name (NULL,
- "GObject", "ObjectClass");
-
- proto = seed_struct_prototype (ctx, objectclass_info);
-/*
- // paramspec is remove in newer versions of introspeciton - removing
- // until we can work out how to replace this.
- paramspec_info = g_irepository_find_by_name (NULL, "GObject", "ParamSpec");
- proto = seed_struct_prototype (ctx, paramspec_info);
-*/
- seed_create_function (ctx, "get", &seed_param_getter_invoked, proto);
- seed_create_function (ctx, "set", &seed_param_setter_invoked, proto);
+ JSObjectRef proto;
+
+ objectclass_info
+ = g_irepository_find_by_name(NULL, "GObject", "ObjectClass");
+
+ proto = seed_struct_prototype(ctx, objectclass_info);
+ /*
+ // paramspec is remove in newer versions of introspeciton - removing
+ // until we can work out how to replace this.
+ paramspec_info = g_irepository_find_by_name (NULL, "GObject",
+ "ParamSpec");
+ proto = seed_struct_prototype (ctx, paramspec_info);
+ */
+ seed_create_function(ctx, "get", &seed_param_getter_invoked, proto);
+ seed_create_function(ctx, "set", &seed_param_setter_invoked, proto);
}
void
-seed_gtype_init (SeedEngine * local_eng)
+seed_gtype_init(SeedEngine* local_eng)
{
- JSClassDefinition gtype_def = kJSClassDefinitionEmpty;
+ JSClassDefinition gtype_def = kJSClassDefinitionEmpty;
- gtype_def.callAsConstructor = seed_gtype_constructor_invoked;
- seed_gtype_class = JSClassCreate (>ype_def);
- JSClassRetain (seed_gtype_class);
+ gtype_def.callAsConstructor = seed_gtype_constructor_invoked;
+ seed_gtype_class = JSClassCreate(>ype_def);
+ JSClassRetain(seed_gtype_class);
- seed_gtype_constructor =
- JSObjectMake (local_eng->context, seed_gtype_class, 0);
+ seed_gtype_constructor
+ = JSObjectMake(local_eng->context, seed_gtype_class, 0);
- seed_object_set_property (local_eng->context,
- local_eng->global, "GType",
- seed_gtype_constructor);
+ seed_object_set_property(local_eng->context, local_eng->global, "GType",
+ seed_gtype_constructor);
- qiinit = g_quark_from_static_string("js-instance-init");
+ qiinit = g_quark_from_static_string("js-instance-init");
- seed_define_gtype_functions (local_eng->context);
+ seed_define_gtype_functions(local_eng->context);
}
diff --git a/libseed/seed-gtype.h b/libseed/seed-gtype.h
index b16fc58..466eaa0 100644
--- a/libseed/seed-gtype.h
+++ b/libseed/seed-gtype.h
@@ -22,7 +22,7 @@
#include "seed-private.h"
-void seed_gtype_init (SeedEngine * eng);
+void seed_gtype_init(SeedEngine* eng);
extern JSObjectRef seed_gtype_constructor;
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index 5d4c161..7c83691 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -35,8 +35,8 @@ JSObjectRef importer_search_path;
JSClassRef importer_dir_class;
-GHashTable *gi_imports;
-GHashTable *file_imports;
+GHashTable* gi_imports;
+GHashTable* file_imports;
/*
* Some high level documentation of the importer object.
@@ -78,35 +78,33 @@ GHashTable *file_imports;
*/
static gboolean
-seed_gi_importer_is_init (GIFunctionInfo * info)
+seed_gi_importer_is_init(GIFunctionInfo* info)
{
- if (g_strcmp0 (g_base_info_get_name ((GIBaseInfo *) info), "init"))
- {
- return FALSE;
+ if (g_strcmp0(g_base_info_get_name((GIBaseInfo*) info), "init")) {
+ return FALSE;
}
- if (g_callable_info_get_n_args ((GICallableInfo *) info) != 2)
- return FALSE;
+ if (g_callable_info_get_n_args((GICallableInfo*) info) != 2)
+ return FALSE;
- return TRUE;
+ return TRUE;
}
static void
-seed_gi_importer_handle_function (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIFunctionInfo * info,
- JSValueRef * exception)
+seed_gi_importer_handle_function(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIFunctionInfo* info,
+ JSValueRef* exception)
{
- if (!seed_gi_importer_is_init (info))
- seed_gobject_define_property_from_function_info (ctx,
- (GIFunctionInfo *) info,
- namespace_ref, FALSE);
- else
- {
- JSObjectRef init_method;
-
- init_method = JSObjectMake (ctx, gobject_init_method_class,
- g_base_info_ref ((GIBaseInfo *) info));
- seed_object_set_property (ctx, namespace_ref, "init", init_method);
+ if (!seed_gi_importer_is_init(info))
+ seed_gobject_define_property_from_function_info(ctx,
+ (GIFunctionInfo*) info,
+ namespace_ref, FALSE);
+ else {
+ JSObjectRef init_method;
+
+ init_method = JSObjectMake(ctx, gobject_init_method_class,
+ g_base_info_ref((GIBaseInfo*) info));
+ seed_object_set_property(ctx, namespace_ref, "init", init_method);
}
}
@@ -117,46 +115,44 @@ seed_gi_importer_handle_function (JSContextRef ctx,
* i.e. Gtk.WindowType.NORMAL
*/
static void
-seed_gi_importer_handle_enum (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIEnumInfo * info, JSValueRef * exception)
+seed_gi_importer_handle_enum(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIEnumInfo* info,
+ JSValueRef* exception)
{
- JSObjectRef enum_class;
- guint num_vals, i, j;
- gsize name_len;
- gint value; // TODO: investigate what's up with the glong/gint mystery here
- gchar *name;
- GIValueInfo *val;
-
- enum_class = JSObjectMake (ctx, 0, 0);
- num_vals = g_enum_info_get_n_values (info);
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- enum_class);
-
- for (i = 0; i < num_vals; i++)
- {
- val = g_enum_info_get_value ((GIEnumInfo *) info, i);
- value = g_value_info_get_value (val);
- name = g_strdup (g_base_info_get_name ((GIBaseInfo *) val));
- name_len = strlen (name);
- JSValueRef value_ref;
-
- value_ref = JSValueMakeNumber (ctx, value);
- JSValueProtect (ctx, (JSValueRef) value_ref);
-
- for (j = 0; j < name_len; j++)
- {
- if (name[j] == '-')
- name[j] = '_';
- name[j] = g_ascii_toupper (name[j]);
- }
-
- seed_object_set_property (ctx, enum_class, name, value_ref);
-
- g_free (name);
- g_base_info_unref ((GIBaseInfo *) val);
-
+ JSObjectRef enum_class;
+ guint num_vals, i, j;
+ gsize name_len;
+ gint value; // TODO: investigate what's up with the glong/gint mystery here
+ gchar* name;
+ GIValueInfo* val;
+
+ enum_class = JSObjectMake(ctx, 0, 0);
+ num_vals = g_enum_info_get_n_values(info);
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ enum_class);
+
+ for (i = 0; i < num_vals; i++) {
+ val = g_enum_info_get_value((GIEnumInfo*) info, i);
+ value = g_value_info_get_value(val);
+ name = g_strdup(g_base_info_get_name((GIBaseInfo*) val));
+ name_len = strlen(name);
+ JSValueRef value_ref;
+
+ value_ref = JSValueMakeNumber(ctx, value);
+ JSValueProtect(ctx, (JSValueRef) value_ref);
+
+ for (j = 0; j < name_len; j++) {
+ if (name[j] == '-')
+ name[j] = '_';
+ name[j] = g_ascii_toupper(name[j]);
+ }
+
+ seed_object_set_property(ctx, enum_class, name, value_ref);
+
+ g_free(name);
+ g_base_info_unref((GIBaseInfo*) val);
}
}
@@ -166,1024 +162,995 @@ seed_gi_importer_handle_enum (JSContextRef ctx,
* the prototype object. Namespace.Type.type will be the GType.
*/
static void
-seed_gi_importer_handle_object (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIObjectInfo * info, JSValueRef * exception)
+seed_gi_importer_handle_object(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIObjectInfo* info,
+ JSValueRef* exception)
{
- GType type;
- JSClassRef class_ref;
-
- type = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) info);
-
- if (type != 0)
- {
- GIFunctionInfo *finfo;
- GIFunctionInfoFlags flags;
- JSObjectRef constructor_ref;
- guint i, n_methods;
-
- class_ref = seed_gobject_get_class_for_gtype (ctx, type);
-
- constructor_ref =
- JSObjectMake (ctx, gobject_constructor_class, (gpointer) type);
-
- seed_object_set_property (ctx, constructor_ref,
- "type",
- seed_value_from_long (ctx, type, exception));
- n_methods = g_object_info_get_n_methods (info);
- for (i = 0; i < n_methods; i++)
- {
- finfo = g_object_info_get_method (info, i);
- flags = g_function_info_get_flags (finfo);
- if (flags & GI_FUNCTION_IS_CONSTRUCTOR)
- {
- JSObjectRef constructor = JSObjectMake (ctx,
- gobject_named_constructor_class,
- finfo);
- const gchar *fname =
- g_base_info_get_name ((GIBaseInfo *) finfo);
- if (g_strrstr (fname, "new_") == fname) {
- // To be compatible with gjs, we need to have a method with new_, too.
- seed_object_set_property (ctx,
- constructor_ref, fname, constructor);
- fname += 4;
- }
-
- else if (!g_strcmp0 (fname, "new")) {
- // To be compatible with gjs, we need to have new as function, too.
- seed_object_set_property (ctx,
- constructor_ref, fname, constructor);
- fname = "c_new";
- }
-
- seed_object_set_property (ctx,
- constructor_ref, fname, constructor);
- }
- else if (!(flags & GI_FUNCTION_IS_METHOD))
- {
- seed_gobject_define_property_from_function_info
- (ctx, finfo, constructor_ref, FALSE);
- }
- else
- {
- g_base_info_unref ((GIBaseInfo *) finfo);
- }
- }
-
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- constructor_ref);
- seed_object_set_property (ctx, constructor_ref,
- "prototype",
- seed_gobject_get_prototype_for_gtype (type));
+ GType type;
+ JSClassRef class_ref;
+
+ type = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) info);
+
+ if (type != 0) {
+ GIFunctionInfo* finfo;
+ GIFunctionInfoFlags flags;
+ JSObjectRef constructor_ref;
+ guint i, n_methods;
+
+ class_ref = seed_gobject_get_class_for_gtype(ctx, type);
+
+ constructor_ref
+ = JSObjectMake(ctx, gobject_constructor_class, (gpointer) type);
+
+ seed_object_set_property(ctx, constructor_ref, "type",
+ seed_value_from_long(ctx, type, exception));
+ n_methods = g_object_info_get_n_methods(info);
+ for (i = 0; i < n_methods; i++) {
+ finfo = g_object_info_get_method(info, i);
+ flags = g_function_info_get_flags(finfo);
+ if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
+ JSObjectRef constructor
+ = JSObjectMake(ctx, gobject_named_constructor_class, finfo);
+ const gchar* fname = g_base_info_get_name((GIBaseInfo*) finfo);
+ if (g_strrstr(fname, "new_") == fname) {
+ // To be compatible with gjs, we need to have a method with
+ // new_, too.
+ seed_object_set_property(ctx, constructor_ref, fname,
+ constructor);
+ fname += 4;
+ }
+
+ else if (!g_strcmp0(fname, "new")) {
+ // To be compatible with gjs, we need to have new as
+ // function, too.
+ seed_object_set_property(ctx, constructor_ref, fname,
+ constructor);
+ fname = "c_new";
+ }
+
+ seed_object_set_property(ctx, constructor_ref, fname,
+ constructor);
+ } else if (!(flags & GI_FUNCTION_IS_METHOD)) {
+ seed_gobject_define_property_from_function_info(ctx, finfo,
+ constructor_ref,
+ FALSE);
+ } else {
+ g_base_info_unref((GIBaseInfo*) finfo);
+ }
+ }
+
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ constructor_ref);
+ seed_object_set_property(ctx, constructor_ref, "prototype",
+ seed_gobject_get_prototype_for_gtype(type));
}
}
static void
-seed_gi_importer_handle_iface (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIObjectInfo * info, JSValueRef * exception)
+seed_gi_importer_handle_iface(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIObjectInfo* info,
+ JSValueRef* exception)
{
- GType type;
-
- type = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) info);
-
- if (type != 0)
- {
- GIFunctionInfo *finfo;
- GIFunctionInfoFlags flags;
- JSObjectRef constructor_ref;
- guint i, n_methods;
-
- constructor_ref =
- JSObjectMake (ctx, gobject_constructor_class, (gpointer) type);
-
- seed_object_set_property (ctx, constructor_ref,
- "type",
- seed_value_from_long (ctx, type, exception));
- n_methods = g_interface_info_get_n_methods (info);
- for (i = 0; i < n_methods; i++)
- {
- finfo = g_interface_info_get_method (info, i);
- flags = g_function_info_get_flags (finfo);
- if (!(flags & GI_FUNCTION_IS_METHOD))
- {
- seed_gobject_define_property_from_function_info
- (ctx, finfo, constructor_ref, FALSE);
- }
- else
- {
- g_base_info_unref ((GIBaseInfo *) finfo);
- }
- }
-
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- constructor_ref);
- seed_object_set_property (ctx, constructor_ref,
- "prototype",
- seed_gobject_get_prototype_for_gtype (type));
+ GType type;
+
+ type = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) info);
+
+ if (type != 0) {
+ GIFunctionInfo* finfo;
+ GIFunctionInfoFlags flags;
+ JSObjectRef constructor_ref;
+ guint i, n_methods;
+
+ constructor_ref
+ = JSObjectMake(ctx, gobject_constructor_class, (gpointer) type);
+
+ seed_object_set_property(ctx, constructor_ref, "type",
+ seed_value_from_long(ctx, type, exception));
+ n_methods = g_interface_info_get_n_methods(info);
+ for (i = 0; i < n_methods; i++) {
+ finfo = g_interface_info_get_method(info, i);
+ flags = g_function_info_get_flags(finfo);
+ if (!(flags & GI_FUNCTION_IS_METHOD)) {
+ seed_gobject_define_property_from_function_info(ctx, finfo,
+ constructor_ref,
+ FALSE);
+ } else {
+ g_base_info_unref((GIBaseInfo*) finfo);
+ }
+ }
+
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ constructor_ref);
+ seed_object_set_property(ctx, constructor_ref, "prototype",
+ seed_gobject_get_prototype_for_gtype(type));
}
}
/*
- * Set up prototype and constructor for structs. Same semantics as objects except
+ * Set up prototype and constructor for structs. Same semantics as objects
+ * except
* for the type.
*/
static void
-seed_gi_importer_handle_struct (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIStructInfo * info, JSValueRef * exception)
+seed_gi_importer_handle_struct(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIStructInfo* info,
+ JSValueRef* exception)
{
- JSObjectRef struct_ref;
- JSObjectRef proto;
- gint i, n_methods;
- GIFunctionInfo *finfo;
-
- struct_ref = JSObjectMake (ctx, seed_struct_constructor_class, info);
- g_base_info_ref (info);
-
- n_methods = g_struct_info_get_n_methods (info);
-
- for (i = 0; i < n_methods; i++)
- {
- GIFunctionInfoFlags flags;
- finfo = g_struct_info_get_method (info, i);
-
- flags = g_function_info_get_flags (finfo);
-
- if (flags & GI_FUNCTION_IS_CONSTRUCTOR)
- {
- JSObjectRef constructor = JSObjectMake (ctx,
- gobject_named_constructor_class,
- finfo);
- const gchar *fname = g_base_info_get_name ((GIBaseInfo *) finfo);
- if (g_strrstr (fname, "new_") == fname) {
- // To be compatible with gjs, we need to have a method with new_, too.
- seed_object_set_property (ctx, struct_ref, fname, constructor);
- fname += 4;
- }
-
- else if (!g_strcmp0 (fname, "new")) {
- // To be compatible with gjs, we need to have new as function, too.
- seed_object_set_property (ctx, struct_ref, fname, constructor);
- fname = "c_new";
- }
-
- seed_object_set_property (ctx, struct_ref, fname, constructor);
- }
- else if (flags & GI_FUNCTION_IS_METHOD)
- g_base_info_unref ((GIBaseInfo *) finfo);
- else
- seed_gobject_define_property_from_function_info
- (ctx, finfo, struct_ref, FALSE);
+ JSObjectRef struct_ref;
+ JSObjectRef proto;
+ gint i, n_methods;
+ GIFunctionInfo* finfo;
+
+ struct_ref = JSObjectMake(ctx, seed_struct_constructor_class, info);
+ g_base_info_ref(info);
+
+ n_methods = g_struct_info_get_n_methods(info);
+
+ for (i = 0; i < n_methods; i++) {
+ GIFunctionInfoFlags flags;
+ finfo = g_struct_info_get_method(info, i);
+
+ flags = g_function_info_get_flags(finfo);
+
+ if (flags & GI_FUNCTION_IS_CONSTRUCTOR) {
+ JSObjectRef constructor
+ = JSObjectMake(ctx, gobject_named_constructor_class, finfo);
+ const gchar* fname = g_base_info_get_name((GIBaseInfo*) finfo);
+ if (g_strrstr(fname, "new_") == fname) {
+ // To be compatible with gjs, we need to have a method with
+ // new_, too.
+ seed_object_set_property(ctx, struct_ref, fname, constructor);
+ fname += 4;
+ }
+
+ else if (!g_strcmp0(fname, "new")) {
+ // To be compatible with gjs, we need to have new as function,
+ // too.
+ seed_object_set_property(ctx, struct_ref, fname, constructor);
+ fname = "c_new";
+ }
+
+ seed_object_set_property(ctx, struct_ref, fname, constructor);
+ } else if (flags & GI_FUNCTION_IS_METHOD)
+ g_base_info_unref((GIBaseInfo*) finfo);
+ else
+ seed_gobject_define_property_from_function_info(ctx, finfo,
+ struct_ref, FALSE);
}
- proto = seed_struct_prototype (ctx, (GIBaseInfo *) info);
- seed_object_set_property (ctx, struct_ref, "prototype", proto);
+ proto = seed_struct_prototype(ctx, (GIBaseInfo*) info);
+ seed_object_set_property(ctx, struct_ref, "prototype", proto);
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- struct_ref);
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ struct_ref);
}
static void
-seed_gi_importer_handle_union (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIUnionInfo * info, JSValueRef * exception)
+seed_gi_importer_handle_union(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIUnionInfo* info,
+ JSValueRef* exception)
{
- JSObjectRef union_ref;
- JSObjectRef proto;
- guint i, n_methods;
- GIFunctionInfo *finfo;
+ JSObjectRef union_ref;
+ JSObjectRef proto;
+ guint i, n_methods;
+ GIFunctionInfo* finfo;
- union_ref = JSObjectMake (ctx, seed_struct_constructor_class, info);
- g_base_info_ref (info);
+ union_ref = JSObjectMake(ctx, seed_struct_constructor_class, info);
+ g_base_info_ref(info);
- n_methods = g_union_info_get_n_methods (info);
+ n_methods = g_union_info_get_n_methods(info);
- for (i = 0; i < n_methods; i++)
- {
- GIFunctionInfoFlags flags;
- finfo = g_union_info_get_method (info, i);
+ for (i = 0; i < n_methods; i++) {
+ GIFunctionInfoFlags flags;
+ finfo = g_union_info_get_method(info, i);
- flags = g_function_info_get_flags (finfo);
+ flags = g_function_info_get_flags(finfo);
- if (flags & GI_FUNCTION_IS_METHOD)
- g_base_info_unref ((GIBaseInfo *) finfo);
- else
- seed_gobject_define_property_from_function_info
- (ctx, finfo, union_ref, FALSE);
+ if (flags & GI_FUNCTION_IS_METHOD)
+ g_base_info_unref((GIBaseInfo*) finfo);
+ else
+ seed_gobject_define_property_from_function_info(ctx, finfo,
+ union_ref, FALSE);
}
- proto = seed_union_prototype (ctx, (GIBaseInfo *) info);
- seed_object_set_property (ctx, union_ref, "prototype", proto);
+ proto = seed_union_prototype(ctx, (GIBaseInfo*) info);
+ seed_object_set_property(ctx, union_ref, "prototype", proto);
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- union_ref);
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ union_ref);
}
static void
-seed_gi_importer_handle_callback (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GICallbackInfo * info,
- JSValueRef * exception)
+seed_gi_importer_handle_callback(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GICallbackInfo* info,
+ JSValueRef* exception)
{
- JSObjectRef callback_ref = JSObjectMake (ctx,
- seed_callback_class,
- info);
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- (JSValueRef) callback_ref);
+ JSObjectRef callback_ref = JSObjectMake(ctx, seed_callback_class, info);
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ (JSValueRef) callback_ref);
}
/*
* Define constants toplevel. Uses the casing as in the typelib
*/
static void
-seed_gi_importer_handle_constant (JSContextRef ctx,
- JSObjectRef namespace_ref,
- GIConstantInfo * info,
- JSValueRef * exception)
+seed_gi_importer_handle_constant(JSContextRef ctx,
+ JSObjectRef namespace_ref,
+ GIConstantInfo* info,
+ JSValueRef* exception)
{
- GArgument argument;
- GITypeInfo *constant_type = g_constant_info_get_type (info);
- JSValueRef constant_value;
-
- g_constant_info_get_value (info, &argument);
- constant_value =
- seed_value_from_gi_argument (ctx, &argument, constant_type, exception);
- seed_object_set_property (ctx, namespace_ref,
- g_base_info_get_name ((GIBaseInfo *) info),
- constant_value);
-
- g_base_info_unref ((GIBaseInfo *) constant_type);
- g_constant_info_free_value(info, &argument);
+ GArgument argument;
+ GITypeInfo* constant_type = g_constant_info_get_type(info);
+ JSValueRef constant_value;
+
+ g_constant_info_get_value(info, &argument);
+ constant_value
+ = seed_value_from_gi_argument(ctx, &argument, constant_type, exception);
+ seed_object_set_property(ctx, namespace_ref,
+ g_base_info_get_name((GIBaseInfo*) info),
+ constant_value);
+
+ g_base_info_unref((GIBaseInfo*) constant_type);
+ g_constant_info_free_value(info, &argument);
}
-static gchar *
-seed_gi_importer_get_version (JSContextRef ctx,
- gchar * namespace, JSValueRef * exception)
+static gchar*
+seed_gi_importer_get_version(JSContextRef ctx,
+ gchar* namespace,
+ JSValueRef* exception)
{
- JSValueRef version_ref;
- gchar *version = NULL;
+ JSValueRef version_ref;
+ gchar* version = NULL;
- version_ref =
- seed_object_get_property (ctx, gi_importer_versions, namespace);
- if (!JSValueIsUndefined (ctx, version_ref))
- version = seed_value_to_string (ctx, version_ref, exception);
+ version_ref
+ = seed_object_get_property(ctx, gi_importer_versions, namespace);
+ if (!JSValueIsUndefined(ctx, version_ref))
+ version = seed_value_to_string(ctx, version_ref, exception);
- return version;
+ return version;
}
JSObjectRef
-seed_gi_importer_do_namespace (JSContextRef ctx,
- gchar * namespace, JSValueRef * exception)
+seed_gi_importer_do_namespace(JSContextRef ctx,
+ gchar* namespace,
+ JSValueRef* exception)
{
- GIBaseInfo *info;
- JSObjectRef namespace_ref;
- GError *e = NULL;
- guint n, i;
- gchar *version = NULL;
- gchar *jsextension;
- JSStringRef extension_script;
-
- if (gi_imports == NULL)
- gi_imports = g_hash_table_new (g_str_hash, g_str_equal);
-
- if ((namespace_ref = g_hash_table_lookup (gi_imports, namespace)))
- {
- SEED_NOTE (IMPORTER, "Using existing namespace ref (%p) for %s",
- namespace_ref, namespace);
- return namespace_ref;
+ GIBaseInfo* info;
+ JSObjectRef namespace_ref;
+ GError* e = NULL;
+ guint n, i;
+ gchar* version = NULL;
+ gchar* jsextension;
+ JSStringRef extension_script;
+
+ if (gi_imports == NULL)
+ gi_imports = g_hash_table_new(g_str_hash, g_str_equal);
+
+ if ((namespace_ref = g_hash_table_lookup(gi_imports, namespace))) {
+ SEED_NOTE(IMPORTER, "Using existing namespace ref (%p) for %s",
+ namespace_ref, namespace);
+ return namespace_ref;
}
- if (gi_importer_versions != NULL)
- version = seed_gi_importer_get_version (ctx, namespace, exception);
- if (!g_irepository_require (NULL, namespace, version, 0, &e))
- {
- seed_make_exception_from_gerror (ctx, exception, e);
- g_error_free (e);
- g_free (version);
- return NULL;
+ if (gi_importer_versions != NULL)
+ version = seed_gi_importer_get_version(ctx, namespace, exception);
+ if (!g_irepository_require(NULL, namespace, version, 0, &e)) {
+ seed_make_exception_from_gerror(ctx, exception, e);
+ g_error_free(e);
+ g_free(version);
+ return NULL;
}
- if (version != NULL)
- g_free (version);
-
- n = g_irepository_get_n_infos (NULL, namespace);
-
- namespace_ref = JSObjectMake (ctx, NULL, NULL);
- SEED_NOTE (IMPORTER, "Constructing namespace ref (%p) for %s",
- namespace_ref, namespace);
-
- JSValueProtect (ctx, namespace_ref);
-
- for (i = 0; i < n; i++)
- {
- GIInfoType info_type;
-
- info = g_irepository_get_info (NULL, namespace, i);
- info_type = g_base_info_get_type (info);
-
- switch (info_type)
- {
- case GI_INFO_TYPE_FUNCTION:
- seed_gi_importer_handle_function (ctx, namespace_ref,
- (GIFunctionInfo *) info,
- exception);
- break;
- case GI_INFO_TYPE_ENUM:
- case GI_INFO_TYPE_FLAGS:
- seed_gi_importer_handle_enum (ctx, namespace_ref,
- (GIEnumInfo *) info, exception);
- break;
- case GI_INFO_TYPE_OBJECT:
- seed_gi_importer_handle_object (ctx, namespace_ref,
- (GIObjectInfo *) info, exception);
- break;
- case GI_INFO_TYPE_INTERFACE:
- seed_gi_importer_handle_iface (ctx, namespace_ref,
- (GIObjectInfo *) info, exception);
- break;
- case GI_INFO_TYPE_STRUCT:
- seed_gi_importer_handle_struct (ctx, namespace_ref,
- (GIStructInfo *) info, exception);
- break;
- case GI_INFO_TYPE_UNION:
- seed_gi_importer_handle_union (ctx, namespace_ref,
- (GIUnionInfo *) info, exception);
- break;
- case GI_INFO_TYPE_CALLBACK:
- seed_gi_importer_handle_callback (ctx, namespace_ref,
- (GICallbackInfo *) info,
- exception);
- break;
- case GI_INFO_TYPE_CONSTANT:
- seed_gi_importer_handle_constant (ctx, namespace_ref,
- (GIConstantInfo *) info,
- exception);
- break;
- default:
- SEED_NOTE (IMPORTER, "Unhandled type %s for %s",
- g_info_type_to_string (info_type),
- g_base_info_get_name (info));
- break;
- }
- g_base_info_unref (info);
+ if (version != NULL)
+ g_free(version);
+
+ n = g_irepository_get_n_infos(NULL, namespace);
+
+ namespace_ref = JSObjectMake(ctx, NULL, NULL);
+ SEED_NOTE(IMPORTER, "Constructing namespace ref (%p) for %s", namespace_ref,
+ namespace);
+
+ JSValueProtect(ctx, namespace_ref);
+
+ for (i = 0; i < n; i++) {
+ GIInfoType info_type;
+
+ info = g_irepository_get_info(NULL, namespace, i);
+ info_type = g_base_info_get_type(info);
+
+ switch (info_type) {
+ case GI_INFO_TYPE_FUNCTION:
+ seed_gi_importer_handle_function(ctx, namespace_ref,
+ (GIFunctionInfo*) info,
+ exception);
+ break;
+ case GI_INFO_TYPE_ENUM:
+ case GI_INFO_TYPE_FLAGS:
+ seed_gi_importer_handle_enum(ctx, namespace_ref,
+ (GIEnumInfo*) info, exception);
+ break;
+ case GI_INFO_TYPE_OBJECT:
+ seed_gi_importer_handle_object(ctx, namespace_ref,
+ (GIObjectInfo*) info, exception);
+ break;
+ case GI_INFO_TYPE_INTERFACE:
+ seed_gi_importer_handle_iface(ctx, namespace_ref,
+ (GIObjectInfo*) info, exception);
+ break;
+ case GI_INFO_TYPE_STRUCT:
+ seed_gi_importer_handle_struct(ctx, namespace_ref,
+ (GIStructInfo*) info, exception);
+ break;
+ case GI_INFO_TYPE_UNION:
+ seed_gi_importer_handle_union(ctx, namespace_ref,
+ (GIUnionInfo*) info, exception);
+ break;
+ case GI_INFO_TYPE_CALLBACK:
+ seed_gi_importer_handle_callback(ctx, namespace_ref,
+ (GICallbackInfo*) info,
+ exception);
+ break;
+ case GI_INFO_TYPE_CONSTANT:
+ seed_gi_importer_handle_constant(ctx, namespace_ref,
+ (GIConstantInfo*) info,
+ exception);
+ break;
+ default:
+ SEED_NOTE(IMPORTER, "Unhandled type %s for %s",
+ g_info_type_to_string(info_type),
+ g_base_info_get_name(info));
+ break;
+ }
+ g_base_info_unref(info);
}
- g_hash_table_insert (gi_imports, g_strdup (namespace), namespace_ref);
-
- jsextension = g_strdup_printf ("imports.extensions.%s", namespace);
- extension_script = JSStringCreateWithUTF8CString (jsextension);
- JSEvaluateScript (ctx, extension_script, NULL, NULL, 0, exception);
- JSStringRelease (extension_script);
- g_free (jsextension);
-
+ g_hash_table_insert(gi_imports, g_strdup(namespace), namespace_ref);
- return namespace_ref;
+ jsextension = g_strdup_printf("imports.extensions.%s", namespace);
+ extension_script = JSStringCreateWithUTF8CString(jsextension);
+ JSEvaluateScript(ctx, extension_script, NULL, NULL, 0, exception);
+ JSStringRelease(extension_script);
+ g_free(jsextension);
+ return namespace_ref;
}
static JSValueRef
-seed_gi_importer_get_property (JSContextRef ctx,
- JSObjectRef object,
- JSStringRef property_name,
- JSValueRef * exception)
+seed_gi_importer_get_property(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- JSObjectRef ret;
- guint len;
- gchar *prop;
-
- len = JSStringGetMaximumUTF8CStringSize (property_name);
- prop = g_alloca (len * sizeof (gchar));
- JSStringGetUTF8CString (property_name, prop, len);
+ JSObjectRef ret;
+ guint len;
+ gchar* prop;
- SEED_NOTE (IMPORTER, "seed_gi_importer_get_property with %s", prop);
+ len = JSStringGetMaximumUTF8CStringSize(property_name);
+ prop = g_alloca(len * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, prop, len);
- if (!g_strcmp0 (prop, "versions"))
- return gi_importer_versions;
- // Nasty hack
- else if (!g_strcmp0 (prop, "toString"))
- return 0;
- if (!g_strcmp0 (prop, "valueOf")) // HACK
- return NULL;
+ SEED_NOTE(IMPORTER, "seed_gi_importer_get_property with %s", prop);
+ if (!g_strcmp0(prop, "versions"))
+ return gi_importer_versions;
+ // Nasty hack
+ else if (!g_strcmp0(prop, "toString"))
+ return 0;
+ if (!g_strcmp0(prop, "valueOf")) // HACK
+ return NULL;
- ret = seed_gi_importer_do_namespace (ctx, prop, exception);
- SEED_NOTE (IMPORTER, "Result (%p) from attempting to import %s: %s",
- ret, prop, seed_value_to_string (ctx, ret, exception));
+ ret = seed_gi_importer_do_namespace(ctx, prop, exception);
+ SEED_NOTE(IMPORTER, "Result (%p) from attempting to import %s: %s", ret,
+ prop, seed_value_to_string(ctx, ret, exception));
- return ret;
+ return ret;
}
static JSObjectRef
-seed_make_importer_dir (JSContextRef ctx, gchar * path)
+seed_make_importer_dir(JSContextRef ctx, gchar* path)
{
- gchar *init;
- JSObjectRef dir;
+ gchar* init;
+ JSObjectRef dir;
- dir = JSObjectMake (ctx, importer_dir_class, path);
+ dir = JSObjectMake(ctx, importer_dir_class, path);
- init = g_build_filename (path, "__init__.js", NULL);
- if (g_file_test (init, G_FILE_TEST_IS_REGULAR))
- {
- SeedScript *s;
- SEED_NOTE (IMPORTER, "Found __init__.js (%s)", path);
+ init = g_build_filename(path, "__init__.js", NULL);
+ if (g_file_test(init, G_FILE_TEST_IS_REGULAR)) {
+ SeedScript* s;
+ SEED_NOTE(IMPORTER, "Found __init__.js (%s)", path);
- s = seed_script_new_from_file (ctx, init);
- seed_evaluate (ctx, s, dir);
- seed_script_destroy (s);
+ s = seed_script_new_from_file(ctx, init);
+ seed_evaluate(ctx, s, dir);
+ seed_script_destroy(s);
}
- g_free (init);
- return dir;
+ g_free(init);
+ return dir;
}
static void
-seed_importer_free_search_path (GSList * path)
+seed_importer_free_search_path(GSList* path)
{
- GSList *walk = path;
+ GSList* walk = path;
- while (walk)
- {
- g_free (walk->data);
- walk = walk->next;
+ while (walk) {
+ g_free(walk->data);
+ walk = walk->next;
}
- g_slist_free (path);
+ g_slist_free(path);
}
-
-GSList *
-seed_importer_get_search_path (JSContextRef ctx, JSValueRef * exception)
+GSList*
+seed_importer_get_search_path(JSContextRef ctx, JSValueRef* exception)
{
- GSList *path = NULL;
- gchar *entry;
- JSValueRef search_path_ref, length_ref;
- guint length, i;
-
- search_path_ref = seed_object_get_property (ctx, importer, "searchPath");
- if (!JSValueIsObject (ctx, search_path_ref))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Importer searchPath object is not an array");
- return NULL;
+ GSList* path = NULL;
+ gchar* entry;
+ JSValueRef search_path_ref, length_ref;
+ guint length, i;
+
+ search_path_ref = seed_object_get_property(ctx, importer, "searchPath");
+ if (!JSValueIsObject(ctx, search_path_ref)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Importer searchPath object is not an array");
+ return NULL;
}
- length_ref =
- seed_object_get_property (ctx, (JSObjectRef) search_path_ref, "length");
- length = seed_value_to_uint (ctx, length_ref, exception);
+ length_ref
+ = seed_object_get_property(ctx, (JSObjectRef) search_path_ref, "length");
+ length = seed_value_to_uint(ctx, length_ref, exception);
- for (i = 0; i < length; i++)
- {
- JSValueRef entry_ref;
+ for (i = 0; i < length; i++) {
+ JSValueRef entry_ref;
- entry_ref =
- JSObjectGetPropertyAtIndex (ctx, (JSObjectRef) search_path_ref, i,
- exception);
- entry = seed_value_to_string (ctx, entry_ref, exception);
+ entry_ref
+ = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) search_path_ref, i,
+ exception);
+ entry = seed_value_to_string(ctx, entry_ref, exception);
- if (g_file_test (entry, G_FILE_TEST_EXISTS) == TRUE)
- path = g_slist_append (path, entry);
- else
- g_free(entry);
+ if (g_file_test(entry, G_FILE_TEST_EXISTS) == TRUE)
+ path = g_slist_append(path, entry);
+ else
+ g_free(entry);
}
- return path;
+ return path;
}
/* forward reference */
-static JSObjectRef
-seed_importer_handle_file (JSContextRef ctx,
- const gchar * dir,
- const gchar * file,
- JSValueRef * exception);
-
-
+static JSObjectRef seed_importer_handle_file(JSContextRef ctx,
+ const gchar* dir,
+ const gchar* file,
+ JSValueRef* exception);
static JSObjectRef
-seed_importer_handle_native_module (JSContextRef ctx,
- const gchar * dir,
- const gchar * prop,
- JSValueRef * exception)
+seed_importer_handle_native_module(JSContextRef ctx,
+ const gchar* dir,
+ const gchar* prop,
+ JSValueRef* exception)
{
- GModule *module;
- JSObjectRef module_obj;
- SeedModuleInitCallback init;
- gchar *file_path = g_strconcat (dir, "/libseed_", prop, ".", G_MODULE_SUFFIX, NULL);
-
- SEED_NOTE (IMPORTER, "Trying native module: %s", file_path);
-
- if ((module_obj = g_hash_table_lookup (file_imports, file_path)))
- {
- SEED_NOTE (IMPORTER, "Using existing global");
- g_free (file_path);
- return module_obj;
+ GModule* module;
+ JSObjectRef module_obj;
+ SeedModuleInitCallback init;
+ gchar* file_path
+ = g_strconcat(dir, "/libseed_", prop, ".", G_MODULE_SUFFIX, NULL);
+
+ SEED_NOTE(IMPORTER, "Trying native module: %s", file_path);
+
+ if ((module_obj = g_hash_table_lookup(file_imports, file_path))) {
+ SEED_NOTE(IMPORTER, "Using existing global");
+ g_free(file_path);
+ return module_obj;
}
- module = g_module_open (file_path, 0);
+ module = g_module_open(file_path, 0);
- if (!module)
- {
- // Could be a better exception
- seed_make_exception (ctx, exception, "ModuleError",
- "Error loading native module at %s: %s",
- file_path, g_module_error ());
- g_free (file_path);
+ if (!module) {
+ // Could be a better exception
+ seed_make_exception(ctx, exception, "ModuleError",
+ "Error loading native module at %s: %s", file_path,
+ g_module_error());
+ g_free(file_path);
- return NULL;
+ return NULL;
}
- g_module_symbol (module, "seed_module_init", (gpointer *) & init);
- module_obj = (*init) (eng);
- g_hash_table_insert (file_imports, file_path, module_obj);
- SEED_NOTE (IMPORTER, "Loaded native module");
-
- //protect module_obj since the GC won't find the module in our file_imports cache
- JSValueProtect (ctx, module_obj);
-
- file_path = g_strconcat ("libseed_", prop, ".js", NULL);
- seed_importer_handle_file (ctx, dir, file_path, exception);
- g_free (file_path);
-
- return module_obj;
+ g_module_symbol(module, "seed_module_init", (gpointer*) &init);
+ module_obj = (*init)(eng);
+ g_hash_table_insert(file_imports, file_path, module_obj);
+ SEED_NOTE(IMPORTER, "Loaded native module");
+
+ // protect module_obj since the GC won't find the module in our file_imports
+ // cache
+ JSValueProtect(ctx, module_obj);
+
+ file_path = g_strconcat("libseed_", prop, ".js", NULL);
+ seed_importer_handle_file(ctx, dir, file_path, exception);
+ g_free(file_path);
+
+ return module_obj;
}
-static gchar *
-seed_importer_canonicalize_path (gchar * path)
+static gchar*
+seed_importer_canonicalize_path(gchar* path)
{
- GFile *file;
- gchar *absolute_path;
+ GFile* file;
+ gchar* absolute_path;
- file = g_file_new_for_path (path);
- absolute_path = g_file_get_path (file);
- g_object_unref (file);
+ file = g_file_new_for_path(path);
+ absolute_path = g_file_get_path(file);
+ g_object_unref(file);
- return absolute_path;
+ return absolute_path;
}
static JSObjectRef
-seed_importer_handle_file (JSContextRef ctx,
- const gchar * dir,
- const gchar * file, JSValueRef * exception)
+seed_importer_handle_file(JSContextRef ctx,
+ const gchar* dir,
+ const gchar* file,
+ JSValueRef* exception)
{
- JSContextRef nctx;
- JSValueRef js_file_dirname;
- JSObjectRef global, c_global;
- JSStringRef file_contents, file_name;
- gchar *contents, *walk, *file_path, *canonical, *absolute_path;
- char *normalized_path;
-
- file_path = g_build_filename (dir, file, NULL);
- canonical = seed_importer_canonicalize_path (file_path);
- SEED_NOTE (IMPORTER, "Trying to import file: %s", file_path);
-
- if ((global = g_hash_table_lookup (file_imports, canonical)))
- {
- SEED_NOTE (IMPORTER, "Using existing global");
-
- g_free (file_path);
- g_free (canonical);
- return global;
+ JSContextRef nctx;
+ JSValueRef js_file_dirname;
+ JSObjectRef global, c_global;
+ JSStringRef file_contents, file_name;
+ gchar *contents, *walk, *file_path, *canonical, *absolute_path;
+ char* normalized_path;
+
+ file_path = g_build_filename(dir, file, NULL);
+ canonical = seed_importer_canonicalize_path(file_path);
+ SEED_NOTE(IMPORTER, "Trying to import file: %s", file_path);
+
+ if ((global = g_hash_table_lookup(file_imports, canonical))) {
+ SEED_NOTE(IMPORTER, "Using existing global");
+
+ g_free(file_path);
+ g_free(canonical);
+ return global;
}
- if (!g_file_test (file_path, G_FILE_TEST_IS_REGULAR))
- {
- if (g_file_test (file_path, G_FILE_TEST_IS_DIR))
- {
- SEED_NOTE (IMPORTER, "File is directory");
- return seed_make_importer_dir (ctx, file_path);
- }
- return NULL;
+ if (!g_file_test(file_path, G_FILE_TEST_IS_REGULAR)) {
+ if (g_file_test(file_path, G_FILE_TEST_IS_DIR)) {
+ SEED_NOTE(IMPORTER, "File is directory");
+ return seed_make_importer_dir(ctx, file_path);
+ }
+ return NULL;
}
- g_file_get_contents (file_path, &contents, 0, NULL);
- walk = contents;
- if (*walk == '#')
- {
- while (*walk != '\n')
- walk++;
- walk++;
+ g_file_get_contents(file_path, &contents, 0, NULL);
+ walk = contents;
+ if (*walk == '#') {
+ while (*walk != '\n')
+ walk++;
+ walk++;
}
- walk = g_strdup (walk);
- g_free (contents);
+ walk = g_strdup(walk);
+ g_free(contents);
- file_contents = JSStringCreateWithUTF8CString (walk);
- file_name = JSStringCreateWithUTF8CString (canonical);
+ file_contents = JSStringCreateWithUTF8CString(walk);
+ file_name = JSStringCreateWithUTF8CString(canonical);
- nctx = JSGlobalContextCreateInGroup (context_group, 0);
- seed_prepare_global_context (nctx);
+ nctx = JSGlobalContextCreateInGroup(context_group, 0);
+ seed_prepare_global_context(nctx);
- global = JSContextGetGlobalObject (nctx);
- c_global = JSContextGetGlobalObject (ctx);
- JSValueProtect (eng->context, global);
+ global = JSContextGetGlobalObject(nctx);
+ c_global = JSContextGetGlobalObject(ctx);
+ JSValueProtect(eng->context, global);
- absolute_path = g_path_get_dirname (file_path);
- if (!g_path_is_absolute (absolute_path))
- {
- g_free (absolute_path);
- absolute_path = g_build_filename (g_get_current_dir (),
- g_path_get_dirname (file_path), NULL);
+ absolute_path = g_path_get_dirname(file_path);
+ if (!g_path_is_absolute(absolute_path)) {
+ g_free(absolute_path);
+ absolute_path = g_build_filename(g_get_current_dir(),
+ g_path_get_dirname(file_path), NULL);
}
- normalized_path = realpath (absolute_path, NULL);
+ normalized_path = realpath(absolute_path, NULL);
- js_file_dirname = seed_value_from_string (ctx, normalized_path, NULL);
+ js_file_dirname = seed_value_from_string(ctx, normalized_path, NULL);
- seed_object_set_property (nctx, global, "__script_path__", js_file_dirname);
+ seed_object_set_property(nctx, global, "__script_path__", js_file_dirname);
- g_hash_table_insert (file_imports, canonical, global);
- g_free (file_path);
- g_free (absolute_path);
- g_free (normalized_path);
+ g_hash_table_insert(file_imports, canonical, global);
+ g_free(file_path);
+ g_free(absolute_path);
+ g_free(normalized_path);
- JSEvaluateScript (nctx, file_contents, NULL, file_name, 0, exception);
+ JSEvaluateScript(nctx, file_contents, NULL, file_name, 0, exception);
- // Does leak...but it's a debug statement.
- SEED_NOTE (IMPORTER, "Evaluated file, exception: %s",
- *exception ? seed_exception_to_string (ctx,
- *exception) : "(null)");
+ // Does leak...but it's a debug statement.
+ SEED_NOTE(IMPORTER, "Evaluated file, exception: %s",
+ *exception ? seed_exception_to_string(ctx, *exception)
+ : "(null)");
- JSGlobalContextRelease ((JSGlobalContextRef) nctx);
+ JSGlobalContextRelease((JSGlobalContextRef) nctx);
- JSStringRelease (file_contents);
- JSStringRelease (file_name);
- g_free (walk);
+ JSStringRelease(file_contents);
+ JSStringRelease(file_name);
+ g_free(walk);
- return global;
+ return global;
}
-static JSObjectRef seed_importer_try_load (JSContextRef ctx,
- const gchar *test_path,
- const gchar *script_path,
- const gchar *prop,
- const gchar *prop_as_js,
- const gchar *prop_as_lib,
- JSValueRef *exception)
+static JSObjectRef
+seed_importer_try_load(JSContextRef ctx,
+ const gchar* test_path,
+ const gchar* script_path,
+ const gchar* prop,
+ const gchar* prop_as_js,
+ const gchar* prop_as_lib,
+ JSValueRef* exception)
{
- gchar *file_path = NULL;
+ gchar* file_path = NULL;
JSObjectRef ret = NULL;
// replace '.' with current script_path if not null
- if(script_path && !g_strcmp0(".",test_path))
+ if (script_path && !g_strcmp0(".", test_path))
test_path = script_path;
// check if prop is a file or dir (imports['foo.js'] or imports.mydir)
- file_path = g_build_filename (test_path, prop, NULL);
- if (g_file_test (file_path, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_DIR)) {
- ret = seed_importer_handle_file (ctx, test_path, prop, exception);
- g_free (file_path);
+ file_path = g_build_filename(test_path, prop, NULL);
+ if (g_file_test(file_path, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_DIR)) {
+ ret = seed_importer_handle_file(ctx, test_path, prop, exception);
+ g_free(file_path);
return ret;
}
- g_free (file_path);
+ g_free(file_path);
// check if prop is file ending with '.js'
- file_path = g_build_filename (test_path, prop_as_js, NULL);
- if (g_file_test (file_path, G_FILE_TEST_IS_REGULAR)) {
- ret = seed_importer_handle_file (ctx, test_path, prop_as_js, exception);
- g_free (file_path);
+ file_path = g_build_filename(test_path, prop_as_js, NULL);
+ if (g_file_test(file_path, G_FILE_TEST_IS_REGULAR)) {
+ ret = seed_importer_handle_file(ctx, test_path, prop_as_js, exception);
+ g_free(file_path);
return ret;
}
- g_free (file_path);
+ g_free(file_path);
// check if file is native module
- file_path = g_build_filename (test_path, prop_as_lib, NULL);
- if (g_file_test (file_path, G_FILE_TEST_IS_REGULAR)) {
- ret = seed_importer_handle_native_module (ctx, test_path, prop, exception);
- g_free (file_path);
+ file_path = g_build_filename(test_path, prop_as_lib, NULL);
+ if (g_file_test(file_path, G_FILE_TEST_IS_REGULAR)) {
+ ret
+ = seed_importer_handle_native_module(ctx, test_path, prop, exception);
+ g_free(file_path);
return ret;
}
- g_free (file_path);
+ g_free(file_path);
return ret;
}
static JSObjectRef
-seed_importer_search_dirs (JSContextRef ctx, GSList *path, gchar *prop, JSValueRef *exception)
+seed_importer_search_dirs(JSContextRef ctx,
+ GSList* path,
+ gchar* prop,
+ JSValueRef* exception)
{
- GSList *walk;
+ GSList* walk;
JSObjectRef ret, global;
JSValueRef script_path_prop;
gchar *prop_as_lib, *prop_as_js, *script_path;
- prop_as_lib = g_strconcat ("libseed_", prop, ".", G_MODULE_SUFFIX, NULL);
- prop_as_js = g_strconcat (prop, ".js", NULL);
+ prop_as_lib = g_strconcat("libseed_", prop, ".", G_MODULE_SUFFIX, NULL);
+ prop_as_js = g_strconcat(prop, ".js", NULL);
- // get the current script_path
- global = JSContextGetGlobalObject (ctx);
- script_path_prop = seed_object_get_property (ctx, global, "__script_path__");
- if (script_path_prop==NULL || JSValueIsUndefined (ctx, script_path_prop))
+ // get the current script_path
+ global = JSContextGetGlobalObject(ctx);
+ script_path_prop = seed_object_get_property(ctx, global, "__script_path__");
+ if (script_path_prop == NULL || JSValueIsUndefined(ctx, script_path_prop))
script_path = NULL;
else
- script_path = seed_value_to_string (ctx, script_path_prop, exception);
+ script_path = seed_value_to_string(ctx, script_path_prop, exception);
ret = NULL;
walk = path;
#ifdef SEED_ENABLE_GJSCOMPAT
if (seed_arg_gjs_compatiblity) {
- while (walk) {
- gchar *test_path = g_strconcat(walk->data, "/gjs", NULL);
+ while (walk) {
+ gchar* test_path = g_strconcat(walk->data, "/gjs", NULL);
- ret = seed_importer_try_load (ctx, test_path, script_path, prop, prop_as_js,
- prop_as_lib, exception);
- g_free (test_path);
- walk = walk->next;
+ ret = seed_importer_try_load(ctx, test_path, script_path, prop,
+ prop_as_js, prop_as_lib, exception);
+ g_free(test_path);
+ walk = walk->next;
- if (ret)
- break;
- }
+ if (ret)
+ break;
+ }
}
#endif
if (!ret) {
- walk = path;
- while (walk) {
- gchar *test_path = walk->data;
-
- ret = seed_importer_try_load (ctx, test_path, script_path, prop, prop_as_js,
- prop_as_lib, exception);
- walk = walk->next;
-
- if (ret)
- break;
- }
- }
-
- g_free (prop_as_lib);
- g_free (prop_as_js);
- g_free (script_path);
-
+ walk = path;
+ while (walk) {
+ gchar* test_path = walk->data;
+
+ ret = seed_importer_try_load(ctx, test_path, script_path, prop,
+ prop_as_js, prop_as_lib, exception);
+ walk = walk->next;
+
+ if (ret)
+ break;
+ }
+ }
+
+ g_free(prop_as_lib);
+ g_free(prop_as_js);
+ g_free(script_path);
+
return ret;
}
static JSObjectRef
-seed_importer_search (JSContextRef ctx, gchar *prop, JSValueRef *exception)
+seed_importer_search(JSContextRef ctx, gchar* prop, JSValueRef* exception)
{
JSObjectRef ret = NULL;
- GSList *path = seed_importer_get_search_path (ctx, exception);
- ret = seed_importer_search_dirs (ctx, path, prop, exception);
- seed_importer_free_search_path (path);
+ GSList* path = seed_importer_get_search_path(ctx, exception);
+ ret = seed_importer_search_dirs(ctx, path, prop, exception);
+ seed_importer_free_search_path(path);
return ret;
}
static JSValueRef
-seed_importer_get_property (JSContextRef ctx,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_importer_get_property(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- JSValueRef ret;
- guint len;
- gchar *prop;
+ JSValueRef ret;
+ guint len;
+ gchar* prop;
- len = JSStringGetMaximumUTF8CStringSize (property_name);
- prop = g_alloca (len * sizeof (gchar));
- JSStringGetUTF8CString (property_name, prop, len);
+ len = JSStringGetMaximumUTF8CStringSize(property_name);
+ prop = g_alloca(len * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, prop, len);
- if (!g_strcmp0 (prop, "gi"))
- return gi_importer;
- if (!g_strcmp0 (prop, "searchPath"))
- return NULL;
- if (!g_strcmp0 (prop, "toString")) // HACK
- return NULL;
+ if (!g_strcmp0(prop, "gi"))
+ return gi_importer;
+ if (!g_strcmp0(prop, "searchPath"))
+ return NULL;
+ if (!g_strcmp0(prop, "toString")) // HACK
+ return NULL;
- ret = seed_importer_search (ctx, prop, exception);
+ ret = seed_importer_search(ctx, prop, exception);
- return ret;
+ return ret;
}
static JSValueRef
-seed_importer_dir_get_property (JSContextRef ctx,
+seed_importer_dir_get_property(JSContextRef ctx,
JSObjectRef object,
JSStringRef property_name,
- JSValueRef * exception)
+ JSValueRef* exception)
{
guint len;
- gchar *prop;
+ gchar* prop;
GSList path;
- path.data = JSObjectGetPrivate (object);
+ path.data = JSObjectGetPrivate(object);
path.next = NULL;
- len = JSStringGetMaximumUTF8CStringSize (property_name);
- prop = g_alloca (len * sizeof (gchar));
- JSStringGetUTF8CString (property_name, prop, len);
+ len = JSStringGetMaximumUTF8CStringSize(property_name);
+ prop = g_alloca(len * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, prop, len);
- /* These prevent print(imports.somefile) running "somefile/toString.js"
+ /* These prevent print(imports.somefile) running "somefile/toString.js"
Which is more than a little unexpected.. */
- if (!g_strcmp0 (prop, "toString"))
+ if (!g_strcmp0(prop, "toString"))
return NULL;
- if (!g_strcmp0 (prop, "valueOf"))
+ if (!g_strcmp0(prop, "valueOf"))
return NULL;
-
+
return seed_importer_search_dirs(ctx, &path, prop, exception);
}
static void
-seed_importer_dir_finalize (JSObjectRef dir)
+seed_importer_dir_finalize(JSObjectRef dir)
{
- gchar *dir_path = (gchar *) JSObjectGetPrivate (dir);
- g_free (dir_path);
+ gchar* dir_path = (gchar*) JSObjectGetPrivate(dir);
+ g_free(dir_path);
}
void
-seed_importer_add_global (JSObjectRef global, gchar * name)
+seed_importer_add_global(JSObjectRef global, gchar* name)
{
- JSValueProtect (eng->context, global);
- g_hash_table_insert (file_imports, seed_importer_canonicalize_path (name),
- global);
+ JSValueProtect(eng->context, global);
+ g_hash_table_insert(file_imports, seed_importer_canonicalize_path(name),
+ global);
}
static void
-seed_importer_dir_enumerate_properties (JSContextRef ctx,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef
- propertyNames)
+seed_importer_dir_enumerate_properties(
+ JSContextRef ctx,
+ JSObjectRef object,
+ JSPropertyNameAccumulatorRef propertyNames)
{
- const gchar *entry;
- GDir *dir;
- GError *e = NULL;
- gchar *path = JSObjectGetPrivate (object);
-
-
- dir = g_dir_open (path, 0, &e);
- if (e)
- {
- SEED_NOTE (IMPORTER,
- "Error in g_dir_open in seed_importer_enumerate_dir_properties: %s",
- e->message);
- g_error_free (e);
- // Not much we can do here.
- return;
+ const gchar* entry;
+ GDir* dir;
+ GError* e = NULL;
+ gchar* path = JSObjectGetPrivate(object);
+
+ dir = g_dir_open(path, 0, &e);
+ if (e) {
+ SEED_NOTE(
+ IMPORTER,
+ "Error in g_dir_open in seed_importer_enumerate_dir_properties: %s",
+ e->message);
+ g_error_free(e);
+ // Not much we can do here.
+ return;
}
- while ((entry = g_dir_read_name (dir)))
- {
- JSStringRef jname;
+ while ((entry = g_dir_read_name(dir))) {
+ JSStringRef jname;
- jname = JSStringCreateWithUTF8CString (entry);
- JSPropertyNameAccumulatorAddName (propertyNames, jname);
- JSStringRelease (jname);
+ jname = JSStringCreateWithUTF8CString(entry);
+ JSPropertyNameAccumulatorAddName(propertyNames, jname);
+ JSStringRelease(jname);
}
- g_dir_close (dir);
+ g_dir_close(dir);
}
JSObjectRef
-seed_importer_construct_dir (JSContextRef ctx,
- JSObjectRef constructor,
- gsize argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_importer_construct_dir(JSContextRef ctx,
+ JSObjectRef constructor,
+ gsize argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gchar *path;
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Directory constructor expects 1 argument");
- return (JSObjectRef) JSValueMakeUndefined (ctx);
+ gchar* path;
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Directory constructor expects 1 argument");
+ return (JSObjectRef) JSValueMakeUndefined(ctx);
}
- path = seed_value_to_string (ctx, arguments[0], exception);
-
- if (!g_file_test (path, G_FILE_TEST_IS_DIR))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Path (%s) is not a directory", path);
- g_free (path);
- return (JSObjectRef) JSValueMakeUndefined (ctx);
+ path = seed_value_to_string(ctx, arguments[0], exception);
+
+ if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Path (%s) is not a directory", path);
+ g_free(path);
+ return (JSObjectRef) JSValueMakeUndefined(ctx);
}
- return seed_make_importer_dir (ctx, path);
+ return seed_make_importer_dir(ctx, path);
}
void
-seed_importer_set_search_path (JSContextRef ctx, gchar ** search_path)
+seed_importer_set_search_path(JSContextRef ctx, gchar** search_path)
{
- JSObjectRef imports, array;
- JSValueRef *array_elem;
- guint length = g_strv_length (search_path), i;
-
- array_elem = g_alloca (length * sizeof (array_elem));
- imports =
- (JSObjectRef) seed_object_get_property (ctx,
- JSContextGetGlobalObject (ctx),
- "imports");
-
- for (i = 0; i < length; i++)
- {
- array_elem[i] = seed_value_from_string (ctx, search_path[i], NULL);
+ JSObjectRef imports, array;
+ JSValueRef* array_elem;
+ guint length = g_strv_length(search_path), i;
+
+ array_elem = g_alloca(length * sizeof(array_elem));
+ imports
+ = (JSObjectRef) seed_object_get_property(ctx,
+ JSContextGetGlobalObject(ctx),
+ "imports");
+
+ for (i = 0; i < length; i++) {
+ array_elem[i] = seed_value_from_string(ctx, search_path[i], NULL);
}
- array = JSObjectMakeArray (ctx, length, array_elem, NULL);
- seed_object_set_property (ctx, imports, "searchPath", array);
+ array = JSObjectMakeArray(ctx, length, array_elem, NULL);
+ seed_object_set_property(ctx, imports, "searchPath", array);
}
void
-seed_importer_add_search_path (JSContextRef ctx, gchar *search_path)
+seed_importer_add_search_path(JSContextRef ctx, gchar* search_path)
{
- GSList *paths, *l;
- GPtrArray *tmp;
+ GSList *paths, *l;
+ GPtrArray* tmp;
- tmp = g_ptr_array_new ();
+ tmp = g_ptr_array_new();
- paths = seed_importer_get_search_path (ctx, NULL);
- for (l = paths; l != NULL; l = g_slist_next (l))
- {
- g_ptr_array_add (tmp, l->data);
+ paths = seed_importer_get_search_path(ctx, NULL);
+ for (l = paths; l != NULL; l = g_slist_next(l)) {
+ g_ptr_array_add(tmp, l->data);
}
- g_ptr_array_add (tmp, search_path);
- g_ptr_array_add (tmp, NULL);
+ g_ptr_array_add(tmp, search_path);
+ g_ptr_array_add(tmp, NULL);
- seed_importer_set_search_path (ctx, (gchar **) tmp->pdata);
+ seed_importer_set_search_path(ctx, (gchar**) tmp->pdata);
- g_ptr_array_unref (tmp);
- seed_importer_free_search_path (paths);
+ g_ptr_array_unref(tmp);
+ seed_importer_free_search_path(paths);
}
JSClassDefinition importer_class_def = {
- 0, /* Version, always 0 */
- 0,
- "importer", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL, /* Initialize */
- NULL, /* Finalize */
- NULL, /* Has Property */
- seed_importer_get_property, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0,
+ "importer", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, /* Initialize */
+ NULL, /* Finalize */
+ NULL, /* Has Property */
+ seed_importer_get_property, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition gi_importer_class_def = {
- 0, /* Version, always 0 */
- 0,
- "gi_importer", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL, /* Initialize */
- NULL, /* Finalize */
- NULL, /* Has Property */
- seed_gi_importer_get_property, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0,
+ "gi_importer", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, /* Initialize */
+ NULL, /* Finalize */
+ NULL, /* Has Property */
+ seed_gi_importer_get_property, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition importer_dir_class_def = {
- 0, /* Version, always 0 */
- 0,
- "importer_dir", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL, /* Initialize */
- seed_importer_dir_finalize, /* Finalize */
- NULL, /* Has Property */
- seed_importer_dir_get_property, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- seed_importer_dir_enumerate_properties, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0,
+ "importer_dir", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, /* Initialize */
+ seed_importer_dir_finalize, /* Finalize */
+ NULL, /* Has Property */
+ seed_importer_dir_get_property, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ seed_importer_dir_enumerate_properties, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
void
-seed_initialize_importer (JSContextRef ctx, JSObjectRef global)
+seed_initialize_importer(JSContextRef ctx, JSObjectRef global)
{
- JSObjectRef dir_constructor;
+ JSObjectRef dir_constructor;
- importer_class = JSClassCreate (&importer_class_def);
- importer = JSObjectMake (ctx, importer_class, NULL);
+ importer_class = JSClassCreate(&importer_class_def);
+ importer = JSObjectMake(ctx, importer_class, NULL);
- gi_importer_class = JSClassCreate (&gi_importer_class_def);
- gi_importer = JSObjectMake (ctx, gi_importer_class, NULL);
- gi_importer_versions = JSObjectMake (ctx, NULL, NULL);
+ gi_importer_class = JSClassCreate(&gi_importer_class_def);
+ gi_importer = JSObjectMake(ctx, gi_importer_class, NULL);
+ gi_importer_versions = JSObjectMake(ctx, NULL, NULL);
- JSValueProtect (ctx, gi_importer);
- JSValueProtect (ctx, gi_importer_versions);
+ JSValueProtect(ctx, gi_importer);
+ JSValueProtect(ctx, gi_importer_versions);
- importer_dir_class = JSClassCreate (&importer_dir_class_def);
+ importer_dir_class = JSClassCreate(&importer_dir_class_def);
- gi_imports = g_hash_table_new (g_str_hash, g_str_equal);
- file_imports = g_hash_table_new (g_str_hash, g_str_equal);
+ gi_imports = g_hash_table_new(g_str_hash, g_str_equal);
+ file_imports = g_hash_table_new(g_str_hash, g_str_equal);
- /* Passing nonnull for class requires a webkit fix that most people wont have yet. It also has minimal
benefit */
- // dir_constructor = JSObjectMakeConstructor (ctx, importer_dir_class, seed_importer_construct_dir);
- dir_constructor =
- JSObjectMakeConstructor (ctx, NULL, seed_importer_construct_dir);
- seed_object_set_property (ctx, importer, "Directory", dir_constructor);
+ /* Passing nonnull for class requires a webkit fix that most people wont
+ * have yet. It also has minimal benefit */
+ // dir_constructor = JSObjectMakeConstructor (ctx, importer_dir_class,
+ // seed_importer_construct_dir);
+ dir_constructor
+ = JSObjectMakeConstructor(ctx, NULL, seed_importer_construct_dir);
+ seed_object_set_property(ctx, importer, "Directory", dir_constructor);
- seed_object_set_property (ctx, global, "imports", importer);
+ seed_object_set_property(ctx, global, "imports", importer);
}
diff --git a/libseed/seed-importer.h b/libseed/seed-importer.h
index 8fb2e7a..11c59b5 100644
--- a/libseed/seed-importer.h
+++ b/libseed/seed-importer.h
@@ -24,8 +24,9 @@
extern JSObjectRef importer;
-void seed_initialize_importer (JSContextRef ctx, JSObjectRef global);
-JSObjectRef seed_gi_importer_do_namespace (JSContextRef ctx,
- gchar * namespace, JSValueRef * exception);
+void seed_initialize_importer(JSContextRef ctx, JSObjectRef global);
+JSObjectRef seed_gi_importer_do_namespace(JSContextRef ctx,
+ gchar* namespace,
+ JSValueRef* exception);
#endif
diff --git a/libseed/seed-module.h b/libseed/seed-module.h
index f7e99fb..e704fb6 100644
--- a/libseed/seed-module.h
+++ b/libseed/seed-module.h
@@ -43,14 +43,13 @@
*
*/
-#define CHECK_ARG_COUNT(name, argnum) \
- if ( argument_count != argnum ) \
- { \
- seed_make_exception (ctx, exception, "ArgumentError", \
- "wrong number of arguments; expected %s, got %zd", \
- #argnum, argument_count); \
- return seed_make_undefined (ctx); \
- }
+#define CHECK_ARG_COUNT(name, argnum) \
+ if (argument_count != argnum) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "wrong number of arguments; expected %s, got %zd", \
+ #argnum, argument_count); \
+ return seed_make_undefined(ctx); \
+ }
/**
* DEFINE_ENUM_MEMBER:
@@ -64,9 +63,9 @@
* #defines as well.
*
*/
-#define DEFINE_ENUM_MEMBER(holder, member) \
- seed_object_set_property(ctx, holder, #member, \
- seed_value_from_long(ctx, member, NULL))
+#define DEFINE_ENUM_MEMBER(holder, member) \
+ seed_object_set_property(ctx, holder, #member, \
+ seed_value_from_long(ctx, member, NULL))
/**
* DEFINE_ENUM_MEMBER_EXT:
@@ -85,8 +84,8 @@
* </programlisting>
*
*/
-#define DEFINE_ENUM_MEMBER_EXT(holder, name, val) \
- seed_object_set_property(ctx, holder, name, \
- seed_value_from_long(ctx, val, NULL))
+#define DEFINE_ENUM_MEMBER_EXT(holder, name, val) \
+ seed_object_set_property(ctx, holder, name, \
+ seed_value_from_long(ctx, val, NULL))
#endif
diff --git a/libseed/seed-private.h b/libseed/seed-private.h
index 1dd6275..17627b7 100644
--- a/libseed/seed-private.h
+++ b/libseed/seed-private.h
@@ -36,11 +36,11 @@ typedef struct _SeedEngine SeedEngine;
struct _SeedEngine
{
- JSGlobalContextRef context;
- JSObjectRef global;
- gchar **search_path;
+ JSGlobalContextRef context;
+ JSObjectRef global;
+ gchar** search_path;
- JSContextGroupRef group;
+ JSContextGroupRef group;
};
#include "seed-debug.h"
diff --git a/libseed/seed-signals.c b/libseed/seed-signals.c
index 98c893f..4e31275 100644
--- a/libseed/seed-signals.c
+++ b/libseed/seed-signals.c
@@ -22,439 +22,420 @@
typedef struct _signal_privates
{
- GObject *object;
- gchar *signal_name;
+ GObject* object;
+ gchar* signal_name;
} signal_privates;
JSClassRef signal_holder_class;
static void
-seed_signal_finalize (JSObjectRef object)
+seed_signal_finalize(JSObjectRef object)
{
- signal_privates *sig_priv = JSObjectGetPrivate (object);
+ signal_privates* sig_priv = JSObjectGetPrivate(object);
- g_free (sig_priv->signal_name);
- g_slice_free1 (sizeof (signal_privates), sig_priv);
+ g_free(sig_priv->signal_name);
+ g_slice_free1(sizeof(signal_privates), sig_priv);
}
-
gulong
-seed_gobject_signal_connect (JSContextRef ctx,
- const gchar * signal_name,
- GObject * on_obj,
- JSObjectRef func,
- JSObjectRef this_obj, JSObjectRef user_data)
+seed_gobject_signal_connect(JSContextRef ctx,
+ const gchar* signal_name,
+ GObject* on_obj,
+ JSObjectRef func,
+ JSObjectRef this_obj,
+ JSObjectRef user_data)
{
- GSignalQuery query;
- GClosure *closure;
+ GSignalQuery query;
+ GClosure* closure;
- if (g_str_has_prefix (signal_name, "notify::"))
- g_signal_query (g_signal_lookup ("notify", G_OBJECT_TYPE (on_obj)),
- &query);
- else
- g_signal_query (g_signal_lookup (signal_name, G_OBJECT_TYPE (on_obj)),
- &query);
+ if (g_str_has_prefix(signal_name, "notify::"))
+ g_signal_query(g_signal_lookup("notify", G_OBJECT_TYPE(on_obj)),
+ &query);
+ else
+ g_signal_query(g_signal_lookup(signal_name, G_OBJECT_TYPE(on_obj)),
+ &query);
#ifdef SEED_ENABLE_DEBUG
- {
- guint function_arity = seed_value_to_uint (ctx,
- seed_object_get_property (ctx,
- func,
- "length"),
- NULL);
- if (function_arity != query.n_params)
- {
- SEED_MARK ();
- SEED_NOTE (SIGNAL,
- "Connecting signal: %s. Function has arity %d, signal expects %d",
- query.signal_name, function_arity, query.n_params);
- SEED_MARK ();
- }
- }
+ {
+ guint function_arity
+ = seed_value_to_uint(ctx,
+ seed_object_get_property(ctx, func, "length"),
+ NULL);
+ if (function_arity != query.n_params) {
+ SEED_MARK();
+ SEED_NOTE(
+ SIGNAL,
+ "Connecting signal: %s. Function has arity %d, signal expects %d",
+ query.signal_name, function_arity, query.n_params);
+ SEED_MARK();
+ }
+ }
#endif
- closure = seed_closure_new_for_signal (ctx, func, user_data, "signal handler", query.signal_id);
+ closure = seed_closure_new_for_signal(ctx, func, user_data,
+ "signal handler", query.signal_id);
- // This seems wrong...
- ((SeedClosure *) closure)->return_type = query.return_type;
- return g_signal_connect_closure (on_obj, signal_name, closure, FALSE);
+ // This seems wrong...
+ ((SeedClosure*) closure)->return_type = query.return_type;
+ return g_signal_connect_closure(on_obj, signal_name, closure, FALSE);
}
JSValueRef
-seed_gobject_signal_connect_by_name (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_signal_connect_by_name(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSObjectRef user_data = NULL;
- gchar *signal_name;
- GObject *obj;
- gulong id;
-
- if (argumentCount < 2 || argumentCount > 3)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal connection expected"
- " 2 or 3 arguments. Got " "%zd", argumentCount);
-
- return JSValueMakeNull (ctx);
+ JSObjectRef user_data = NULL;
+ gchar* signal_name;
+ GObject* obj;
+ gulong id;
+
+ if (argumentCount < 2 || argumentCount > 3) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal connection expected"
+ " 2 or 3 arguments. Got "
+ "%zd",
+ argumentCount);
+
+ return JSValueMakeNull(ctx);
}
- if (JSValueIsNull (ctx, arguments[1]) ||
- !JSValueIsObject (ctx, arguments[1]) ||
- !JSObjectIsFunction (ctx, (JSObjectRef) arguments[1]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal connection by name "
- "requires a function" " as second argument");
- return JSValueMakeNull (ctx);
+ if (JSValueIsNull(ctx, arguments[1]) || !JSValueIsObject(ctx, arguments[1])
+ || !JSObjectIsFunction(ctx, (JSObjectRef) arguments[1])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal connection by name "
+ "requires a function"
+ " as second argument");
+ return JSValueMakeNull(ctx);
}
- if (argumentCount == 3)
- {
- user_data = (JSObjectRef) arguments[2];
+ if (argumentCount == 3) {
+ user_data = (JSObjectRef) arguments[2];
}
- signal_name = seed_value_to_string (ctx, arguments[0], exception);
- obj = (GObject *) JSObjectGetPrivate (thisObject);
+ signal_name = seed_value_to_string(ctx, arguments[0], exception);
+ obj = (GObject*) JSObjectGetPrivate(thisObject);
- id = seed_gobject_signal_connect (ctx, signal_name, obj,
- (JSObjectRef) arguments[1], NULL,
- user_data);
+ id = seed_gobject_signal_connect(ctx, signal_name, obj,
+ (JSObjectRef) arguments[1], NULL,
+ user_data);
- g_free (signal_name);
+ g_free(signal_name);
- return seed_value_from_ulong (ctx, id, exception);
+ return seed_value_from_ulong(ctx, id, exception);
}
void
-seed_add_signals_to_object (JSContextRef ctx,
- JSObjectRef object_ref, GObject * obj)
+seed_add_signals_to_object(JSContextRef ctx,
+ JSObjectRef object_ref,
+ GObject* obj)
{
- g_assert (obj);
+ g_assert(obj);
- JSObjectRef signals_ref;
+ JSObjectRef signals_ref;
- signals_ref = JSObjectMake (ctx, signal_holder_class, obj);
+ signals_ref = JSObjectMake(ctx, signal_holder_class, obj);
- seed_object_set_property (ctx, object_ref, "signal", signals_ref);
+ seed_object_set_property(ctx, object_ref, "signal", signals_ref);
}
void
-seed_signal_marshal_func (GClosure * closure,
- GValue * return_value,
- guint n_param_values,
- const GValue * param_values,
- gpointer invocation_hint, gpointer marshal_data)
+seed_signal_marshal_func(GClosure* closure,
+ GValue* return_value,
+ guint n_param_values,
+ const GValue* param_values,
+ gpointer invocation_hint,
+ gpointer marshal_data)
{
- SeedClosure *seed_closure = (SeedClosure *) closure;
- JSValueRef *args, exception = 0;
- JSValueRef ret = 0;
- guint i;
- gchar *mes;
- GSignalQuery signal_query = { 0, };
-
- if (marshal_data)
- {
- /* Inspired from gjs/gi/value.c:closure_marshal() */
- /* we are used for a signal handler */
- guint signal_id;
-
- signal_id = GPOINTER_TO_UINT(marshal_data);
-
- g_signal_query(signal_id, &signal_query);
-
- if (!signal_query.signal_id)
- g_error("Signal handler being called on invalid signal");
-
- if (signal_query.n_params + 1 != n_param_values)
- g_error("Signal handler being called with wrong number of parameters");
- }
-
- JSContextRef ctx = JSGlobalContextCreateInGroup (context_group,
- 0);
+ SeedClosure* seed_closure = (SeedClosure*) closure;
+ JSValueRef *args, exception = 0;
+ JSValueRef ret = 0;
+ guint i;
+ gchar* mes;
+ GSignalQuery signal_query = {
+ 0,
+ };
+
+ if (marshal_data) {
+ /* Inspired from gjs/gi/value.c:closure_marshal() */
+ /* we are used for a signal handler */
+ guint signal_id;
+
+ signal_id = GPOINTER_TO_UINT(marshal_data);
+
+ g_signal_query(signal_id, &signal_query);
+
+ if (!signal_query.signal_id)
+ g_error("Signal handler being called on invalid signal");
+
+ if (signal_query.n_params + 1 != n_param_values)
+ g_error(
+ "Signal handler being called with wrong number of parameters");
+ }
- seed_prepare_global_context (ctx);
- SEED_NOTE (INVOCATION, "Signal Marshal: ");
+ JSContextRef ctx = JSGlobalContextCreateInGroup(context_group, 0);
- args = g_newa (JSValueRef, n_param_values + 1);
+ seed_prepare_global_context(ctx);
+ SEED_NOTE(INVOCATION, "Signal Marshal: ");
- for (i = 0; i < n_param_values; i++)
- {
- args[i] = seed_value_from_gvalue_for_signal (ctx,
- (GValue *) & param_values[i], 0, &signal_query, i);
+ args = g_newa(JSValueRef, n_param_values + 1);
- if (!args[i])
- g_error ("Error in signal marshal. "
- "Unable to convert argument of type: %s \n",
- g_type_name (param_values[i].g_type));
+ for (i = 0; i < n_param_values; i++) {
+ args[i]
+ = seed_value_from_gvalue_for_signal(ctx, (GValue*) ¶m_values[i],
+ 0, &signal_query, i);
+ if (!args[i])
+ g_error("Error in signal marshal. "
+ "Unable to convert argument of type: %s \n",
+ g_type_name(param_values[i].g_type));
}
- if (seed_closure->user_data)
- args[i] = seed_closure->user_data;
- else
- args[i] = JSValueMakeNull (ctx);
+ if (seed_closure->user_data)
+ args[i] = seed_closure->user_data;
+ else
+ args[i] = JSValueMakeNull(ctx);
- ret = JSObjectCallAsFunction (ctx, seed_closure->function,
- NULL, n_param_values + 1, args, &exception);
+ ret = JSObjectCallAsFunction(ctx, seed_closure->function, NULL,
+ n_param_values + 1, args, &exception);
- if (exception)
- {
- seed_closure_warn_exception (closure, ctx, exception);
- exception = NULL;
+ if (exception) {
+ seed_closure_warn_exception(closure, ctx, exception);
+ exception = NULL;
}
- if (ret && !JSValueIsNull (ctx, ret)
- && (seed_closure->return_type != G_TYPE_NONE))
- {
- seed_value_to_gvalue (ctx, ret, seed_closure->return_type,
- return_value, &exception);
+ if (ret && !JSValueIsNull(ctx, ret)
+ && (seed_closure->return_type != G_TYPE_NONE)) {
+ seed_value_to_gvalue(ctx, ret, seed_closure->return_type, return_value,
+ &exception);
}
- if (exception)
- {
- mes = seed_exception_to_string (ctx, exception);
- g_warning ("Exception in signal handler return value. %s \n", mes);
- g_free (mes);
+ if (exception) {
+ mes = seed_exception_to_string(ctx, exception);
+ g_warning("Exception in signal handler return value. %s \n", mes);
+ g_free(mes);
}
- JSGlobalContextRelease ((JSGlobalContextRef) ctx);
- JSGarbageCollect(ctx);
-
+ JSGlobalContextRelease((JSGlobalContextRef) ctx);
+ JSGarbageCollect(ctx);
}
static JSValueRef
-seed_gobject_signal_emit (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_signal_emit(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- JSValueRef ret;
- GValue *params;
- GValue ret_value = { 0 };
- GSignalQuery query;
+ JSValueRef ret;
+ GValue* params;
+ GValue ret_value = { 0 };
+ GSignalQuery query;
- signal_privates *privates;
- guint i, signal_id;
+ signal_privates* privates;
+ guint i, signal_id;
- privates = JSObjectGetPrivate (thisObject);
+ privates = JSObjectGetPrivate(thisObject);
- signal_id = g_signal_lookup (privates->signal_name,
- G_OBJECT_TYPE (privates->object));
+ signal_id
+ = g_signal_lookup(privates->signal_name, G_OBJECT_TYPE(privates->object));
- g_signal_query (signal_id, &query);
+ g_signal_query(signal_id, &query);
- if (argumentCount != query.n_params)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal: %s for type %s expected %u "
- "arguments, got %zd",
- query.signal_name,
- g_type_name (query.itype),
- query.n_params, argumentCount);
-
- return JSValueMakeNull (ctx);
- }
+ if (argumentCount != query.n_params) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal: %s for type %s expected %u "
+ "arguments, got %zd",
+ query.signal_name, g_type_name(query.itype),
+ query.n_params, argumentCount);
- params = g_new0 (GValue, argumentCount + 1);
+ return JSValueMakeNull(ctx);
+ }
- g_value_init (¶ms[0], G_TYPE_OBJECT);
- g_value_set_object (¶ms[0], privates->object);
- for (i = 0; i < argumentCount; i++)
- seed_value_to_gvalue (ctx, arguments[i],
- query.param_types[i],
- ¶ms[i + 1], exception);
+ params = g_new0(GValue, argumentCount + 1);
+ g_value_init(¶ms[0], G_TYPE_OBJECT);
+ g_value_set_object(¶ms[0], privates->object);
+ for (i = 0; i < argumentCount; i++)
+ seed_value_to_gvalue(ctx, arguments[i], query.param_types[i],
+ ¶ms[i + 1], exception);
- if (query.return_type != G_TYPE_NONE)
- g_value_init (&ret_value, query.return_type);
- g_signal_emitv (params, signal_id, 0, &ret_value);
+ if (query.return_type != G_TYPE_NONE)
+ g_value_init(&ret_value, query.return_type);
+ g_signal_emitv(params, signal_id, 0, &ret_value);
- for (i = 0; i < argumentCount; i++)
- g_value_unset (¶ms[i]);
- g_free (params);
+ for (i = 0; i < argumentCount; i++)
+ g_value_unset(¶ms[i]);
+ g_free(params);
- ret = seed_value_from_gvalue (ctx, &ret_value, exception);
+ ret = seed_value_from_gvalue(ctx, &ret_value, exception);
- if (query.return_type != G_TYPE_NONE)
- g_value_unset (&ret_value);
+ if (query.return_type != G_TYPE_NONE)
+ g_value_unset(&ret_value);
- return ret;
+ return ret;
}
static JSValueRef
-seed_gobject_signal_disconnect (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_signal_disconnect(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gulong id;
- if (argumentCount != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal disconnection expects 1 argument"
- " got %zd", argumentCount);
- return JSValueMakeUndefined (ctx);
+ gulong id;
+ if (argumentCount != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal disconnection expects 1 argument"
+ " got %zd",
+ argumentCount);
+ return JSValueMakeUndefined(ctx);
}
- id = seed_value_to_ulong (ctx, arguments[0], exception);
- g_signal_handler_disconnect (JSObjectGetPrivate (thisObject), id);
+ id = seed_value_to_ulong(ctx, arguments[0], exception);
+ g_signal_handler_disconnect(JSObjectGetPrivate(thisObject), id);
- return JSValueMakeUndefined (ctx);
+ return JSValueMakeUndefined(ctx);
}
static JSValueRef
-seed_gobject_signal_connect_on_property (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception)
+seed_gobject_signal_connect_on_property(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception)
{
- gulong id = 0;
- JSObjectRef this_obj;
- signal_privates *privates;
-
- privates = (signal_privates *) JSObjectGetPrivate (thisObject);
- if (!privates)
- g_error ("Signal constructed with invalid parameters"
- "in namespace import \n");
-
- this_obj =
- (JSObjectRef) seed_value_from_object (ctx, privates->object, exception);
-
- if ((argumentCount > 2) || (argumentCount == 0))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal connection expected"
- " 1, or 2 arguments. Got " "%zd", argumentCount);
-
- return JSValueMakeNull (ctx);
+ gulong id = 0;
+ JSObjectRef this_obj;
+ signal_privates* privates;
+
+ privates = (signal_privates*) JSObjectGetPrivate(thisObject);
+ if (!privates)
+ g_error("Signal constructed with invalid parameters"
+ "in namespace import \n");
+
+ this_obj
+ = (JSObjectRef) seed_value_from_object(ctx, privates->object, exception);
+
+ if ((argumentCount > 2) || (argumentCount == 0)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal connection expected"
+ " 1, or 2 arguments. Got "
+ "%zd",
+ argumentCount);
+
+ return JSValueMakeNull(ctx);
}
- if (JSValueIsNull (ctx, arguments[0]) ||
- !JSValueIsObject (ctx, arguments[0]) ||
- !JSObjectIsFunction (ctx, (JSObjectRef) arguments[0]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Signal connection requires a function"
- " as first argument");
- return JSValueMakeNull (ctx);
+ if (JSValueIsNull(ctx, arguments[0]) || !JSValueIsObject(ctx, arguments[0])
+ || !JSObjectIsFunction(ctx, (JSObjectRef) arguments[0])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Signal connection requires a function"
+ " as first argument");
+ return JSValueMakeNull(ctx);
}
- if (argumentCount == 1)
- {
- id = seed_gobject_signal_connect (ctx, privates->signal_name,
- privates->object,
- (JSObjectRef) arguments[0], this_obj,
- NULL);
-
- }
- else if (argumentCount == 2)
- {
- id = seed_gobject_signal_connect (ctx, privates->signal_name,
- privates->object,
- (JSObjectRef) arguments[0],
- this_obj, (JSObjectRef) arguments[1]);
+ if (argumentCount == 1) {
+ id = seed_gobject_signal_connect(ctx, privates->signal_name,
+ privates->object,
+ (JSObjectRef) arguments[0], this_obj,
+ NULL);
+
+ } else if (argumentCount == 2) {
+ id = seed_gobject_signal_connect(ctx, privates->signal_name,
+ privates->object,
+ (JSObjectRef) arguments[0], this_obj,
+ (JSObjectRef) arguments[1]);
}
- return seed_value_from_ulong (ctx, id, exception);
+ return seed_value_from_ulong(ctx, id, exception);
}
-JSStaticFunction signal_static_functions[] = {
- {"connect", seed_gobject_signal_connect_on_property, 0}
- ,
- {"emit", seed_gobject_signal_emit, 0}
- ,
- {0, 0, 0}
-};
+JSStaticFunction signal_static_functions[]
+ = { { "connect", seed_gobject_signal_connect_on_property, 0 },
+ { "emit", seed_gobject_signal_emit, 0 },
+ { 0, 0, 0 } };
-JSStaticFunction signal_holder_static_functions[] = {
- {"connect", seed_gobject_signal_connect_by_name, 0}
- ,
- {"disconnect", seed_gobject_signal_disconnect, 0}
- ,
- {0, 0, 0}
-};
+JSStaticFunction signal_holder_static_functions[]
+ = { { "connect", seed_gobject_signal_connect_by_name, 0 },
+ { "disconnect", seed_gobject_signal_disconnect, 0 },
+ { 0, 0, 0 } };
JSClassDefinition gobject_signal_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype,
- "gobject_signal", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- signal_static_functions, /* Static Functions */
- NULL,
- seed_signal_finalize, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype,
+ "gobject_signal", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ signal_static_functions, /* Static Functions */
+ NULL,
+ seed_signal_finalize, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
static JSValueRef
-seed_signal_holder_get_property (JSContextRef ctx,
- JSObjectRef object,
- JSStringRef property_name,
- JSValueRef * exception)
+seed_signal_holder_get_property(JSContextRef ctx,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- GObject *gobj = JSObjectGetPrivate (object);
- signal_privates *priv;
- guint length = JSStringGetMaximumUTF8CStringSize (property_name);
- gchar *signal_name = g_malloc (length * sizeof (gchar));
- JSObjectRef signal_ref;
-
- JSStringGetUTF8CString (property_name, signal_name, length);
-
- if (!
- (g_strcmp0 (signal_name, "connect")
- && g_strcmp0 (signal_name, "disconnect")))
- {
- g_free (signal_name);
- return NULL;
+ GObject* gobj = JSObjectGetPrivate(object);
+ signal_privates* priv;
+ guint length = JSStringGetMaximumUTF8CStringSize(property_name);
+ gchar* signal_name = g_malloc(length * sizeof(gchar));
+ JSObjectRef signal_ref;
+
+ JSStringGetUTF8CString(property_name, signal_name, length);
+
+ if (!(g_strcmp0(signal_name, "connect")
+ && g_strcmp0(signal_name, "disconnect"))) {
+ g_free(signal_name);
+ return NULL;
}
- if (!g_str_has_prefix (signal_name, "notify::") &&
- !g_signal_lookup (signal_name, G_OBJECT_TYPE (gobj)))
- {
- seed_make_exception (ctx, exception, "InvalidSignalName",
- "Failed to connect to %s. "
- "Invalid signal name.", signal_name);
- g_free (signal_name);
- return NULL;
+ if (!g_str_has_prefix(signal_name, "notify::")
+ && !g_signal_lookup(signal_name, G_OBJECT_TYPE(gobj))) {
+ seed_make_exception(ctx, exception, "InvalidSignalName",
+ "Failed to connect to %s. "
+ "Invalid signal name.",
+ signal_name);
+ g_free(signal_name);
+ return NULL;
}
- priv = g_slice_alloc (sizeof (signal_privates));
+ priv = g_slice_alloc(sizeof(signal_privates));
- priv->object = gobj;
- priv->signal_name = signal_name;
+ priv->object = gobj;
+ priv->signal_name = signal_name;
- signal_ref = JSObjectMake (ctx, gobject_signal_class, priv);
+ signal_ref = JSObjectMake(ctx, gobject_signal_class, priv);
- return signal_ref;
+ return signal_ref;
}
-JSClassDefinition *
-seed_get_signal_class (void)
+JSClassDefinition*
+seed_get_signal_class(void)
{
- JSClassDefinition signal_holder = kJSClassDefinitionEmpty;
+ JSClassDefinition signal_holder = kJSClassDefinitionEmpty;
- signal_holder.className = "gobject_signals";
- signal_holder.getProperty = seed_signal_holder_get_property;
- signal_holder.staticFunctions = signal_holder_static_functions;
- signal_holder_class = JSClassCreate (&signal_holder);
- JSClassRetain (signal_holder_class);
+ signal_holder.className = "gobject_signals";
+ signal_holder.getProperty = seed_signal_holder_get_property;
+ signal_holder.staticFunctions = signal_holder_static_functions;
+ signal_holder_class = JSClassCreate(&signal_holder);
+ JSClassRetain(signal_holder_class);
- return &gobject_signal_def;
+ return &gobject_signal_def;
}
diff --git a/libseed/seed-signals.h b/libseed/seed-signals.h
index 387aa88..1ce4e04 100644
--- a/libseed/seed-signals.h
+++ b/libseed/seed-signals.h
@@ -22,32 +22,32 @@
#include "seed-private.h"
-void seed_signal_marshal_func (GClosure * closure,
- GValue * return_value,
- guint n_param_values,
- const GValue * param_values,
- gpointer invocation_hint,
- gpointer marshall_data);
-
-void seed_add_signals_to_object (JSContextRef ctx,
- JSObjectRef object_ref, GObject * obj);
-
-gulong seed_gobject_signal_connect (JSContextRef ctx,
- const gchar * signal_name,
- GObject * on_obj,
- JSObjectRef func,
- JSObjectRef this_obj,
- JSObjectRef user_data);
-
-JSValueRef
-seed_gobject_signal_connect_by_name (JSContextRef ctx,
- JSObjectRef function,
- JSObjectRef thisObject,
- size_t argumentCount,
- const JSValueRef arguments[],
- JSValueRef * exception);
-
-JSClassDefinition *seed_get_signal_class (void);
+void seed_signal_marshal_func(GClosure* closure,
+ GValue* return_value,
+ guint n_param_values,
+ const GValue* param_values,
+ gpointer invocation_hint,
+ gpointer marshall_data);
+
+void seed_add_signals_to_object(JSContextRef ctx,
+ JSObjectRef object_ref,
+ GObject* obj);
+
+gulong seed_gobject_signal_connect(JSContextRef ctx,
+ const gchar* signal_name,
+ GObject* on_obj,
+ JSObjectRef func,
+ JSObjectRef this_obj,
+ JSObjectRef user_data);
+
+JSValueRef seed_gobject_signal_connect_by_name(JSContextRef ctx,
+ JSObjectRef function,
+ JSObjectRef thisObject,
+ size_t argumentCount,
+ const JSValueRef arguments[],
+ JSValueRef* exception);
+
+JSClassDefinition* seed_get_signal_class(void);
extern JSClassRef gobject_signal_class;
#endif
diff --git a/libseed/seed-structs.c b/libseed/seed-structs.c
index 2e9600d..7d70d68 100644
--- a/libseed/seed-structs.c
+++ b/libseed/seed-structs.c
@@ -25,785 +25,750 @@ JSClassRef seed_boxed_class = 0;
typedef struct _seed_struct_privates
{
- gpointer pointer;
- GIBaseInfo *info;
+ gpointer pointer;
+ GIBaseInfo* info;
- gboolean free_pointer;
- gboolean slice_alloc;
- gsize size;
+ gboolean free_pointer;
+ gboolean slice_alloc;
+ gsize size;
} seed_struct_privates;
-GHashTable *struct_prototype_hash = NULL;
-GHashTable *union_prototype_hash = NULL;
+GHashTable* struct_prototype_hash = NULL;
+GHashTable* union_prototype_hash = NULL;
static void
-seed_pointer_finalize (JSObjectRef object)
+seed_pointer_finalize(JSObjectRef object)
{
- seed_struct_privates *priv =
- (seed_struct_privates *) JSObjectGetPrivate (object);
-
- SEED_NOTE (STRUCTS, "Finalizing seed_pointer object %p. with "
- "priv->free_pointer = %d with type: %s, size: %zu",
- priv->pointer,
- priv->free_pointer,
- priv->info ? g_base_info_get_name (priv->info) : "[generic]",
- priv->size);
-
- if (priv->free_pointer)
- {
- if (priv->slice_alloc)
- g_slice_free1 (priv->size, priv->pointer);
- else
- g_free (priv->pointer);
+ seed_struct_privates* priv
+ = (seed_struct_privates*) JSObjectGetPrivate(object);
+
+ SEED_NOTE(STRUCTS, "Finalizing seed_pointer object %p. with "
+ "priv->free_pointer = %d with type: %s, size: %zu",
+ priv->pointer, priv->free_pointer,
+ priv->info ? g_base_info_get_name(priv->info) : "[generic]",
+ priv->size);
+
+ if (priv->free_pointer) {
+ if (priv->slice_alloc)
+ g_slice_free1(priv->size, priv->pointer);
+ else
+ g_free(priv->pointer);
}
- if (priv->info)
- g_base_info_unref (priv->info);
+ if (priv->info)
+ g_base_info_unref(priv->info);
- g_slice_free1 (sizeof (seed_struct_privates), priv);
+ g_slice_free1(sizeof(seed_struct_privates), priv);
}
static void
-seed_boxed_finalize (JSObjectRef object)
+seed_boxed_finalize(JSObjectRef object)
{
- seed_struct_privates *priv =
- (seed_struct_privates *) JSObjectGetPrivate (object);
- GType type;
- GIRegisteredTypeInfo *info =
- (GIRegisteredTypeInfo *) g_base_info_get_type (priv->info);
+ seed_struct_privates* priv
+ = (seed_struct_privates*) JSObjectGetPrivate(object);
+ GType type;
+ GIRegisteredTypeInfo* info
+ = (GIRegisteredTypeInfo*) g_base_info_get_type(priv->info);
- SEED_NOTE (STRUCTS, "Finalizing boxed object of type %s \n",
- g_base_info_get_name (priv->info));
+ SEED_NOTE(STRUCTS, "Finalizing boxed object of type %s \n",
+ g_base_info_get_name(priv->info));
- type = g_registered_type_info_get_g_type (info);
- g_base_info_unref ((GIBaseInfo *) info);
-
- g_boxed_free (type, priv->pointer);
+ type = g_registered_type_info_get_g_type(info);
+ g_base_info_unref((GIBaseInfo*) info);
+ g_boxed_free(type, priv->pointer);
}
-GIFieldInfo *
-seed_union_find_field (GIUnionInfo * info, gchar * field_name)
+GIFieldInfo*
+seed_union_find_field(GIUnionInfo* info, gchar* field_name)
{
- gint n, i;
- GIFieldInfo *field;
-
- n = g_union_info_get_n_fields (info);
- for (i = 0; i < n; i++)
- {
- const gchar *name;
-
- field = g_union_info_get_field (info, i);
- name = g_base_info_get_name ((GIBaseInfo *) field);
- if (!g_strcmp0 (name, field_name))
- return field;
- else
- g_base_info_unref ((GIBaseInfo *) field);
+ gint n, i;
+ GIFieldInfo* field;
+
+ n = g_union_info_get_n_fields(info);
+ for (i = 0; i < n; i++) {
+ const gchar* name;
+
+ field = g_union_info_get_field(info, i);
+ name = g_base_info_get_name((GIBaseInfo*) field);
+ if (!g_strcmp0(name, field_name))
+ return field;
+ else
+ g_base_info_unref((GIBaseInfo*) field);
}
- return NULL;
+ return NULL;
}
-GIFieldInfo *
-seed_struct_find_field (GIStructInfo * info, gchar * field_name)
+GIFieldInfo*
+seed_struct_find_field(GIStructInfo* info, gchar* field_name)
{
- gint n, i;
- const gchar *name;
- GIFieldInfo *field;
-
- n = g_struct_info_get_n_fields (info);
- for (i = 0; i < n; i++)
- {
-
- field = g_struct_info_get_field (info, i);
- name = g_base_info_get_name ((GIBaseInfo *) field);
- if (!g_strcmp0 (name, field_name))
- return field;
- else
- g_base_info_unref ((GIBaseInfo *) field);
+ gint n, i;
+ const gchar* name;
+ GIFieldInfo* field;
+
+ n = g_struct_info_get_n_fields(info);
+ for (i = 0; i < n; i++) {
+
+ field = g_struct_info_get_field(info, i);
+ name = g_base_info_get_name((GIBaseInfo*) field);
+ if (!g_strcmp0(name, field_name))
+ return field;
+ else
+ g_base_info_unref((GIBaseInfo*) field);
}
- return NULL;
+ return NULL;
}
JSValueRef
-seed_field_get_value (JSContextRef ctx,
- gpointer object,
- GIFieldInfo * field, JSValueRef * exception)
+seed_field_get_value(JSContextRef ctx,
+ gpointer object,
+ GIFieldInfo* field,
+ JSValueRef* exception)
{
- GITypeInfo *field_type;
- GIBaseInfo *interface;
- GArgument field_value;
- JSValueRef ret = JSValueMakeNull (ctx);
- gint offset;
-
- field_type = g_field_info_get_type (field);
- if (!g_field_info_get_field (field, object, &field_value))
- {
- GITypeTag tag;
-
- tag = g_type_info_get_tag (field_type);
- if (tag == GI_TYPE_TAG_INTERFACE)
- {
- interface = g_type_info_get_interface (field_type);
- offset = g_field_info_get_offset (field);
-
- g_base_info_unref ((GIBaseInfo *) field_type);
- switch (g_base_info_get_type (interface))
- {
- case GI_INFO_TYPE_STRUCT:
- ret = seed_make_struct (ctx, (object + offset), interface);
- break;
- case GI_INFO_TYPE_UNION:
- ret = seed_make_union (ctx, (object + offset), interface);
- break;
- case GI_INFO_TYPE_BOXED:
- ret = seed_make_boxed (ctx, (object + offset), interface);
- break;
- default:
- break;
- }
- g_base_info_unref (interface);
-
- return ret;
- }
-
- return JSValueMakeNull (ctx);
+ GITypeInfo* field_type;
+ GIBaseInfo* interface;
+ GArgument field_value;
+ JSValueRef ret = JSValueMakeNull(ctx);
+ gint offset;
+
+ field_type = g_field_info_get_type(field);
+ if (!g_field_info_get_field(field, object, &field_value)) {
+ GITypeTag tag;
+
+ tag = g_type_info_get_tag(field_type);
+ if (tag == GI_TYPE_TAG_INTERFACE) {
+ interface = g_type_info_get_interface(field_type);
+ offset = g_field_info_get_offset(field);
+
+ g_base_info_unref((GIBaseInfo*) field_type);
+ switch (g_base_info_get_type(interface)) {
+ case GI_INFO_TYPE_STRUCT:
+ ret = seed_make_struct(ctx, (object + offset), interface);
+ break;
+ case GI_INFO_TYPE_UNION:
+ ret = seed_make_union(ctx, (object + offset), interface);
+ break;
+ case GI_INFO_TYPE_BOXED:
+ ret = seed_make_boxed(ctx, (object + offset), interface);
+ break;
+ default:
+ break;
+ }
+ g_base_info_unref(interface);
+
+ return ret;
+ }
+
+ return JSValueMakeNull(ctx);
}
- // Maybe need to release argument.
- ret = seed_value_from_gi_argument (ctx, &field_value, field_type, exception);
- if (field_type)
- g_base_info_unref ((GIBaseInfo *) field_type);
- return ret;
+ // Maybe need to release argument.
+ ret = seed_value_from_gi_argument(ctx, &field_value, field_type, exception);
+ if (field_type)
+ g_base_info_unref((GIBaseInfo*) field_type);
+ return ret;
}
static JSValueRef
-seed_union_get_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_union_get_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- gchar *cproperty_name;
- gsize length;
- seed_struct_privates *priv = JSObjectGetPrivate (object);
- GIFieldInfo *field = 0;
- JSValueRef ret;
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- SEED_NOTE (STRUCTS, "Getting property on union of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
-
- field = seed_union_find_field ((GIUnionInfo *) priv->info, cproperty_name);
- if (!field)
- {
- return 0;
+ gchar* cproperty_name;
+ gsize length;
+ seed_struct_privates* priv = JSObjectGetPrivate(object);
+ GIFieldInfo* field = 0;
+ JSValueRef ret;
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ SEED_NOTE(STRUCTS, "Getting property on union of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
+
+ field = seed_union_find_field((GIUnionInfo*) priv->info, cproperty_name);
+ if (!field) {
+ return 0;
}
- ret = seed_field_get_value (context, priv->pointer, field, exception);
+ ret = seed_field_get_value(context, priv->pointer, field, exception);
- g_base_info_unref ((GIBaseInfo *) field);
+ g_base_info_unref((GIBaseInfo*) field);
- return ret;
+ return ret;
}
static bool
-seed_union_set_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name,
- JSValueRef value, JSValueRef * exception)
+seed_union_set_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef value,
+ JSValueRef* exception)
{
- gsize length;
- GArgument field_value;
- GIFieldInfo *field;
- gchar *cproperty_name;
- GITypeInfo *field_type;
- seed_struct_privates *priv =
- (seed_struct_privates *) JSObjectGetPrivate (object);
- gboolean ret;
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- SEED_NOTE (STRUCTS, "Setting property on union of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
-
- field = seed_union_find_field ((GIUnionInfo *) priv->info, cproperty_name);
-
- if (!field)
- {
- return FALSE;
+ gsize length;
+ GArgument field_value;
+ GIFieldInfo* field;
+ gchar* cproperty_name;
+ GITypeInfo* field_type;
+ seed_struct_privates* priv
+ = (seed_struct_privates*) JSObjectGetPrivate(object);
+ gboolean ret;
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ SEED_NOTE(STRUCTS, "Setting property on union of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
+
+ field = seed_union_find_field((GIUnionInfo*) priv->info, cproperty_name);
+
+ if (!field) {
+ return FALSE;
}
- field_type = g_field_info_get_type (field);
+ field_type = g_field_info_get_type(field);
- seed_value_to_gi_argument (context, value, field_type, GI_TRANSFER_NOTHING, &field_value, exception);
- ret = g_field_info_set_field (field, priv->pointer, &field_value);
- if (!ret)
- g_warning("Setting property failed on union of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
+ seed_value_to_gi_argument(context, value, field_type, GI_TRANSFER_NOTHING,
+ &field_value, exception);
+ ret = g_field_info_set_field(field, priv->pointer, &field_value);
+ if (!ret)
+ g_warning("Setting property failed on union of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
- g_base_info_unref ((GIBaseInfo *) field_type);
- g_base_info_unref ((GIBaseInfo *) field);
+ g_base_info_unref((GIBaseInfo*) field_type);
+ g_base_info_unref((GIBaseInfo*) field);
- return TRUE;
+ return TRUE;
}
static bool
-seed_struct_set_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name,
- JSValueRef value, JSValueRef * exception)
+seed_struct_set_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef value,
+ JSValueRef* exception)
{
- gsize length;
- GArgument field_value;
- GIFieldInfo *field;
- gchar *cproperty_name;
- GITypeInfo *field_type;
- seed_struct_privates *priv =
- (seed_struct_privates *) JSObjectGetPrivate (object);
- gboolean ret;
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- SEED_NOTE (STRUCTS, "Setting property on struct of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
-
- field =
- seed_struct_find_field ((GIStructInfo *) priv->info, cproperty_name);
-
- if (!field)
- {
- return FALSE;
+ gsize length;
+ GArgument field_value;
+ GIFieldInfo* field;
+ gchar* cproperty_name;
+ GITypeInfo* field_type;
+ seed_struct_privates* priv
+ = (seed_struct_privates*) JSObjectGetPrivate(object);
+ gboolean ret;
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ SEED_NOTE(STRUCTS, "Setting property on struct of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
+
+ field = seed_struct_find_field((GIStructInfo*) priv->info, cproperty_name);
+
+ if (!field) {
+ return FALSE;
}
- field_type = g_field_info_get_type (field);
+ field_type = g_field_info_get_type(field);
+
+ seed_value_to_gi_argument(context, value, field_type, GI_TRANSFER_NOTHING,
+ &field_value, exception);
+ ret = g_field_info_set_field(field, priv->pointer, &field_value);
- seed_value_to_gi_argument (context, value, field_type, GI_TRANSFER_NOTHING, &field_value, exception);
- ret = g_field_info_set_field (field, priv->pointer, &field_value);
+ if (!ret)
+ g_warning("Setting property failed on struct of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
- if (!ret)
- g_warning("Setting property failed on struct of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
-
- g_base_info_unref ((GIBaseInfo *) field_type);
- g_base_info_unref ((GIBaseInfo *) field);
+ g_base_info_unref((GIBaseInfo*) field_type);
+ g_base_info_unref((GIBaseInfo*) field);
- return TRUE;
+ return TRUE;
}
static JSValueRef
-seed_struct_get_property (JSContextRef context,
- JSObjectRef object,
- JSStringRef property_name, JSValueRef * exception)
+seed_struct_get_property(JSContextRef context,
+ JSObjectRef object,
+ JSStringRef property_name,
+ JSValueRef* exception)
{
- gchar *cproperty_name;
- gsize length;
- seed_struct_privates *priv = JSObjectGetPrivate (object);
- GIFieldInfo *field = NULL;
- JSValueRef ret;
-
- length = JSStringGetMaximumUTF8CStringSize (property_name);
- cproperty_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (property_name, cproperty_name, length);
-
- SEED_NOTE (STRUCTS, "Getting property on struct of type: %s "
- "with name %s \n",
- g_base_info_get_name (priv->info), cproperty_name);
-
- // for a gvalue, it has a special property 'value' (read-only)
- GType gtype = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) priv->info);
-
- if (g_type_is_a (gtype, G_TYPE_VALUE) && !g_strcmp0 (cproperty_name, "value"))
- {
- return seed_value_from_gvalue ( context, ( GValue *) priv->pointer, exception);
-
+ gchar* cproperty_name;
+ gsize length;
+ seed_struct_privates* priv = JSObjectGetPrivate(object);
+ GIFieldInfo* field = NULL;
+ JSValueRef ret;
+
+ length = JSStringGetMaximumUTF8CStringSize(property_name);
+ cproperty_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+ SEED_NOTE(STRUCTS, "Getting property on struct of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(priv->info), cproperty_name);
+
+ // for a gvalue, it has a special property 'value' (read-only)
+ GType gtype
+ = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) priv->info);
+
+ if (g_type_is_a(gtype, G_TYPE_VALUE)
+ && !g_strcmp0(cproperty_name, "value")) {
+ return seed_value_from_gvalue(context, (GValue*) priv->pointer,
+ exception);
}
- field =
- seed_struct_find_field ((GIStructInfo *) priv->info, cproperty_name);
+ field = seed_struct_find_field((GIStructInfo*) priv->info, cproperty_name);
- if (!field)
- {
- return NULL;
+ if (!field) {
+ return NULL;
}
- ret = seed_field_get_value (context, priv->pointer, field, exception);
+ ret = seed_field_get_value(context, priv->pointer, field, exception);
- g_base_info_unref ((GIBaseInfo *) field);
+ g_base_info_unref((GIBaseInfo*) field);
- return ret;
+ return ret;
}
static void
-seed_enumerate_structlike_properties (JSContextRef ctx,
- JSObjectRef object,
- JSPropertyNameAccumulatorRef
- propertyNames)
+seed_enumerate_structlike_properties(JSContextRef ctx,
+ JSObjectRef object,
+ JSPropertyNameAccumulatorRef propertyNames)
{
- GIFieldInfo *field;
- gint i, n;
- guchar type = 0;
- seed_struct_privates *priv =
- (seed_struct_privates *) JSObjectGetPrivate (object);
- GIBaseInfo *info = priv->info;
-
- if (!info)
- return;
-
- if (JSValueIsObjectOfClass (ctx, object, seed_struct_class))
- type = 1;
- else if (JSValueIsObjectOfClass (ctx, object, seed_union_class))
- type = 2;
- else
- g_assert_not_reached ();
-
- (type == 1) ?
- (n = g_struct_info_get_n_fields ((GIStructInfo *) info)) :
- (n = g_union_info_get_n_fields ((GIUnionInfo *) info));
-
- for (i = 0; i < n; i++)
- {
- JSStringRef jname;
-
- (type == 1) ?
- (field = g_struct_info_get_field ((GIStructInfo *) info, i)) :
- (field = g_union_info_get_field ((GIUnionInfo *) info, i));
-
- jname =
- JSStringCreateWithUTF8CString (g_base_info_get_name
- ((GIBaseInfo *) field));
-
- g_base_info_unref ((GIBaseInfo *) field);
- JSPropertyNameAccumulatorAddName (propertyNames, jname);
-
- JSStringRelease (jname);
+ GIFieldInfo* field;
+ gint i, n;
+ guchar type = 0;
+ seed_struct_privates* priv
+ = (seed_struct_privates*) JSObjectGetPrivate(object);
+ GIBaseInfo* info = priv->info;
+
+ if (!info)
+ return;
+
+ if (JSValueIsObjectOfClass(ctx, object, seed_struct_class))
+ type = 1;
+ else if (JSValueIsObjectOfClass(ctx, object, seed_union_class))
+ type = 2;
+ else
+ g_assert_not_reached();
+
+ (type == 1) ? (n = g_struct_info_get_n_fields((GIStructInfo*) info))
+ : (n = g_union_info_get_n_fields((GIUnionInfo*) info));
+
+ for (i = 0; i < n; i++) {
+ JSStringRef jname;
+
+ (type == 1) ? (field = g_struct_info_get_field((GIStructInfo*) info, i))
+ : (field = g_union_info_get_field((GIUnionInfo*) info, i));
+
+ jname = JSStringCreateWithUTF8CString(
+ g_base_info_get_name((GIBaseInfo*) field));
+
+ g_base_info_unref((GIBaseInfo*) field);
+ JSPropertyNameAccumulatorAddName(propertyNames, jname);
+
+ JSStringRelease(jname);
}
}
JSClassDefinition seed_pointer_def = {
- 0, /* Version, always 0 */
- 0,
- "seed_pointer", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- seed_pointer_finalize,
- NULL, /* Has Property */
- 0,
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL,
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ 0, "seed_pointer", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL, seed_pointer_finalize,
+ NULL, /* Has Property */
+ 0, NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition seed_struct_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype,
- "seed_struct", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- NULL,
- NULL, /* Has Property */
- seed_struct_get_property,
- seed_struct_set_property, /* Set Property */
- NULL, /* Delete Property */
- seed_enumerate_structlike_properties, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype,
+ "seed_struct", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ NULL,
+ NULL, /* Has Property */
+ seed_struct_get_property,
+ seed_struct_set_property, /* Set Property */
+ NULL, /* Delete Property */
+ seed_enumerate_structlike_properties, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition seed_union_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype,
- "seed_union", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- NULL,
- NULL, /* Has Property */
- seed_union_get_property,
- seed_union_set_property, /* Set Property */
- NULL, /* Delete Property */
- seed_enumerate_structlike_properties, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype,
+ "seed_union", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ NULL,
+ NULL, /* Has Property */
+ seed_union_get_property,
+ seed_union_set_property, /* Set Property */
+ NULL, /* Delete Property */
+ seed_enumerate_structlike_properties, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
JSClassDefinition seed_boxed_def = {
- 0, /* Version, always 0 */
- kJSClassAttributeNoAutomaticPrototype,
- "seed_boxed", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- NULL, /* Static Functions */
- NULL,
- seed_boxed_finalize,
- NULL, /* Has Property */
- NULL,
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ kJSClassAttributeNoAutomaticPrototype,
+ "seed_boxed", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ NULL, /* Static Functions */
+ NULL,
+ seed_boxed_finalize,
+ NULL, /* Has Property */
+ NULL,
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
gpointer
-seed_pointer_get_pointer (JSContextRef ctx, JSValueRef pointer)
+seed_pointer_get_pointer(JSContextRef ctx, JSValueRef pointer)
{
- if (JSValueIsObjectOfClass (ctx, pointer, seed_pointer_class))
- {
- seed_struct_privates *priv = JSObjectGetPrivate ((JSObjectRef) pointer);
- return priv->pointer;
+ if (JSValueIsObjectOfClass(ctx, pointer, seed_pointer_class)) {
+ seed_struct_privates* priv = JSObjectGetPrivate((JSObjectRef) pointer);
+ return priv->pointer;
}
- return NULL;
+ return NULL;
}
void
-seed_pointer_set_free (JSContextRef ctx,
- JSValueRef pointer, gboolean free_pointer)
+seed_pointer_set_free(JSContextRef ctx,
+ JSValueRef pointer,
+ gboolean free_pointer)
{
- if (JSValueIsObjectOfClass (ctx, pointer, seed_pointer_class))
- {
- seed_struct_privates *priv = JSObjectGetPrivate ((JSObjectRef) pointer);
- priv->free_pointer = free_pointer;
+ if (JSValueIsObjectOfClass(ctx, pointer, seed_pointer_class)) {
+ seed_struct_privates* priv = JSObjectGetPrivate((JSObjectRef) pointer);
+ priv->free_pointer = free_pointer;
}
}
static void
-seed_pointer_set_slice (JSContextRef ctx,
- JSValueRef pointer, gboolean free_pointer, gsize size)
+seed_pointer_set_slice(JSContextRef ctx,
+ JSValueRef pointer,
+ gboolean free_pointer,
+ gsize size)
{
- seed_struct_privates *priv = JSObjectGetPrivate ((JSObjectRef) pointer);
- priv->slice_alloc = free_pointer;
- priv->size = size;
+ seed_struct_privates* priv = JSObjectGetPrivate((JSObjectRef) pointer);
+ priv->slice_alloc = free_pointer;
+ priv->size = size;
}
JSObjectRef
-seed_make_pointer (JSContextRef ctx, gpointer pointer)
+seed_make_pointer(JSContextRef ctx, gpointer pointer)
{
- seed_struct_privates *priv = g_slice_alloc (sizeof (seed_struct_privates));
- priv->pointer = pointer;
- priv->info = 0;
- priv->free_pointer = FALSE;
+ seed_struct_privates* priv = g_slice_alloc(sizeof(seed_struct_privates));
+ priv->pointer = pointer;
+ priv->info = 0;
+ priv->free_pointer = FALSE;
- return JSObjectMake (ctx, seed_pointer_class, priv);
+ return JSObjectMake(ctx, seed_pointer_class, priv);
}
JSObjectRef
-seed_union_prototype (JSContextRef ctx, GIBaseInfo * info)
+seed_union_prototype(JSContextRef ctx, GIBaseInfo* info)
{
- JSObjectRef proto;
- const gchar *namespace, *name;
- gchar *key;
- gint n_methods, i;
- GIFunctionInfo *finfo;
-
- name = g_base_info_get_name (info);
- namespace = g_base_info_get_namespace (info);
- key = g_strjoin (NULL, namespace, name, NULL);
-
- proto = (JSObjectRef) g_hash_table_lookup (union_prototype_hash, key);
-
- if (!proto)
- {
- proto = JSObjectMake (ctx, 0, 0);
- JSValueProtect (eng->context, proto);
-
- n_methods = g_union_info_get_n_methods ((GIUnionInfo *) info);
- for (i = 0; i < n_methods; i++)
- {
- finfo = g_union_info_get_method ((GIUnionInfo *) info, i);
-
- seed_gobject_define_property_from_function_info (ctx,
- (GIFunctionInfo *)
- finfo, proto,
- TRUE);
-
- g_base_info_unref ((GIBaseInfo *) finfo);
- }
-
- g_hash_table_insert (union_prototype_hash, key, proto);
- }
- else
- {
- g_free (key);
+ JSObjectRef proto;
+ const gchar* namespace, *name;
+ gchar* key;
+ gint n_methods, i;
+ GIFunctionInfo* finfo;
+
+ name = g_base_info_get_name(info);
+ namespace = g_base_info_get_namespace(info);
+ key = g_strjoin(NULL, namespace, name, NULL);
+
+ proto = (JSObjectRef) g_hash_table_lookup(union_prototype_hash, key);
+
+ if (!proto) {
+ proto = JSObjectMake(ctx, 0, 0);
+ JSValueProtect(eng->context, proto);
+
+ n_methods = g_union_info_get_n_methods((GIUnionInfo*) info);
+ for (i = 0; i < n_methods; i++) {
+ finfo = g_union_info_get_method((GIUnionInfo*) info, i);
+
+ seed_gobject_define_property_from_function_info(
+ ctx, (GIFunctionInfo*) finfo, proto, TRUE);
+
+ g_base_info_unref((GIBaseInfo*) finfo);
+ }
+
+ g_hash_table_insert(union_prototype_hash, key, proto);
+ } else {
+ g_free(key);
}
- return proto;
+ return proto;
}
JSObjectRef
-seed_make_union (JSContextRef ctx, gpointer younion, GIBaseInfo * info)
+seed_make_union(JSContextRef ctx, gpointer younion, GIBaseInfo* info)
{
- JSObjectRef object;
+ JSObjectRef object;
- if (younion == NULL)
- {
- return (JSObjectRef) JSValueMakeNull (ctx);
+ if (younion == NULL) {
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- seed_struct_privates *priv = g_slice_alloc (sizeof (seed_struct_privates));
+ seed_struct_privates* priv = g_slice_alloc(sizeof(seed_struct_privates));
- priv->pointer = younion;
- priv->info = info ? g_base_info_ref (info) : 0;
- priv->free_pointer = FALSE;
+ priv->pointer = younion;
+ priv->info = info ? g_base_info_ref(info) : 0;
+ priv->free_pointer = FALSE;
- object = JSObjectMake (ctx, seed_union_class, priv);
+ object = JSObjectMake(ctx, seed_union_class, priv);
- if (info)
- {
- JSObjectRef proto = seed_union_prototype (ctx, info);
- if (proto)
- JSObjectSetPrototype (ctx, object, proto);
- else
- g_assert_not_reached ();
+ if (info) {
+ JSObjectRef proto = seed_union_prototype(ctx, info);
+ if (proto)
+ JSObjectSetPrototype(ctx, object, proto);
+ else
+ g_assert_not_reached();
}
- return object;
+ return object;
}
JSObjectRef
-seed_make_boxed (JSContextRef ctx, gpointer boxed, GIBaseInfo * info)
+seed_make_boxed(JSContextRef ctx, gpointer boxed, GIBaseInfo* info)
{
- JSObjectRef object;
- seed_struct_privates *priv = g_slice_alloc (sizeof (seed_struct_privates));
+ JSObjectRef object;
+ seed_struct_privates* priv = g_slice_alloc(sizeof(seed_struct_privates));
- priv->info = info ? g_base_info_ref (info) : 0;
- priv->pointer = boxed;
- // Boxed finalize handler handles freeing.
- priv->free_pointer = FALSE;
+ priv->info = info ? g_base_info_ref(info) : 0;
+ priv->pointer = boxed;
+ // Boxed finalize handler handles freeing.
+ priv->free_pointer = FALSE;
- object = JSObjectMake (ctx, seed_boxed_class, priv);
+ object = JSObjectMake(ctx, seed_boxed_class, priv);
- // FIXME: Instance methods?
+ // FIXME: Instance methods?
- return object;
+ return object;
}
JSObjectRef
-seed_struct_prototype (JSContextRef ctx, GIBaseInfo * info)
+seed_struct_prototype(JSContextRef ctx, GIBaseInfo* info)
{
- JSObjectRef proto;
- const gchar *namespace, *name;
- gchar *key;
- gint n_methods, i;
+ JSObjectRef proto;
+ const gchar* namespace, *name;
+ gchar* key;
+ gint n_methods, i;
- name = g_base_info_get_name (info);
- namespace = g_base_info_get_namespace (info);
- key = g_strjoin (NULL, namespace, name, NULL);
+ name = g_base_info_get_name(info);
+ namespace = g_base_info_get_namespace(info);
+ key = g_strjoin(NULL, namespace, name, NULL);
- proto = (JSObjectRef) g_hash_table_lookup (struct_prototype_hash, key);
+ proto = (JSObjectRef) g_hash_table_lookup(struct_prototype_hash, key);
- if (!proto)
- {
- proto = JSObjectMake (ctx, 0, 0);
- JSValueProtect (eng->context, proto);
+ if (!proto) {
+ proto = JSObjectMake(ctx, 0, 0);
+ JSValueProtect(eng->context, proto);
- n_methods = g_struct_info_get_n_methods ((GIStructInfo *) info);
- for (i = 0; i < n_methods; i++)
- {
- GIFunctionInfo *finfo;
+ n_methods = g_struct_info_get_n_methods((GIStructInfo*) info);
+ for (i = 0; i < n_methods; i++) {
+ GIFunctionInfo* finfo;
- finfo = g_struct_info_get_method ((GIStructInfo *) info, i);
+ finfo = g_struct_info_get_method((GIStructInfo*) info, i);
- seed_gobject_define_property_from_function_info (ctx,
- (GIFunctionInfo *)
- finfo, proto,
- TRUE);
+ seed_gobject_define_property_from_function_info(
+ ctx, (GIFunctionInfo*) finfo, proto, TRUE);
- g_base_info_unref ((GIBaseInfo *) finfo);
- }
+ g_base_info_unref((GIBaseInfo*) finfo);
+ }
- g_hash_table_insert (struct_prototype_hash, key, proto);
- }
- else
- {
- g_free (key);
+ g_hash_table_insert(struct_prototype_hash, key, proto);
+ } else {
+ g_free(key);
}
- return proto;
+ return proto;
}
JSObjectRef
-seed_make_struct (JSContextRef ctx, gpointer strukt, GIBaseInfo * info)
+seed_make_struct(JSContextRef ctx, gpointer strukt, GIBaseInfo* info)
{
- JSObjectRef object, proto;
+ JSObjectRef object, proto;
- if (strukt == NULL)
- {
- return (JSObjectRef) JSValueMakeNull (ctx);
+ if (strukt == NULL) {
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- seed_struct_privates *priv = g_slice_alloc (sizeof (seed_struct_privates));
-
- priv->info = info ? g_base_info_ref (info) : 0;
- priv->pointer = strukt;
- priv->free_pointer = FALSE;
-
- object = JSObjectMake (ctx, seed_struct_class, priv);
- // Examine cases where struct is being used without info.
- if (info)
- {
- proto = seed_struct_prototype (ctx, info);
- if (proto)
- JSObjectSetPrototype (ctx, object, proto);
- else
- g_assert_not_reached ();
+ seed_struct_privates* priv = g_slice_alloc(sizeof(seed_struct_privates));
+
+ priv->info = info ? g_base_info_ref(info) : 0;
+ priv->pointer = strukt;
+ priv->free_pointer = FALSE;
+
+ object = JSObjectMake(ctx, seed_struct_class, priv);
+ // Examine cases where struct is being used without info.
+ if (info) {
+ proto = seed_struct_prototype(ctx, info);
+ if (proto)
+ JSObjectSetPrototype(ctx, object, proto);
+ else
+ g_assert_not_reached();
}
- return object;
+ return object;
}
void
-seed_structs_init (void)
+seed_structs_init(void)
{
- seed_pointer_class = JSClassCreate (&seed_pointer_def);
- seed_struct_def.parentClass = seed_pointer_class;
- seed_struct_class = JSClassCreate (&seed_struct_def);
- seed_union_def.parentClass = seed_pointer_class;
- seed_union_class = JSClassCreate (&seed_union_def);
- seed_boxed_def.parentClass = seed_struct_class;
- seed_boxed_class = JSClassCreate (&seed_boxed_def);
-
- struct_prototype_hash = g_hash_table_new (g_str_hash, g_str_equal);
- union_prototype_hash = g_hash_table_new (g_str_hash, g_str_equal);
+ seed_pointer_class = JSClassCreate(&seed_pointer_def);
+ seed_struct_def.parentClass = seed_pointer_class;
+ seed_struct_class = JSClassCreate(&seed_struct_def);
+ seed_union_def.parentClass = seed_pointer_class;
+ seed_union_class = JSClassCreate(&seed_union_def);
+ seed_boxed_def.parentClass = seed_struct_class;
+ seed_boxed_class = JSClassCreate(&seed_boxed_def);
+
+ struct_prototype_hash = g_hash_table_new(g_str_hash, g_str_equal);
+ union_prototype_hash = g_hash_table_new(g_str_hash, g_str_equal);
}
JSObjectRef
-seed_construct_struct_type_with_parameters (JSContextRef ctx,
- GIBaseInfo * info,
- JSObjectRef parameters,
- JSValueRef * exception)
+seed_construct_struct_type_with_parameters(JSContextRef ctx,
+ GIBaseInfo* info,
+ JSObjectRef parameters,
+ JSValueRef* exception)
{
- gsize size = 0;
- gpointer object;
- GIInfoType type = g_base_info_get_type (info);
- JSObjectRef ret;
- gboolean set_ret;
- gint nparams, i = 0;
- gsize length;
- GIFieldInfo *field = 0;
- JSPropertyNameArrayRef jsprops;
- JSStringRef jsprop_name;
- JSValueRef jsprop_value;
- GArgument field_value;
- gchar *prop_name;
- GITypeInfo *field_type;
-
- if (type == GI_INFO_TYPE_STRUCT)
- {
- GType gtype = g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *) info);
- if (g_type_is_a (gtype, G_TYPE_VALUE))
- {
- GValue *gval = g_slice_alloc0 (sizeof (GValue));
- if (!parameters)
- {
- seed_make_exception (ctx, exception, "ArgumentError", "Missing Type in GValue constructor");
- return (JSObjectRef) JSValueMakeNull (ctx);
+ gsize size = 0;
+ gpointer object;
+ GIInfoType type = g_base_info_get_type(info);
+ JSObjectRef ret;
+ gboolean set_ret;
+ gint nparams, i = 0;
+ gsize length;
+ GIFieldInfo* field = 0;
+ JSPropertyNameArrayRef jsprops;
+ JSStringRef jsprop_name;
+ JSValueRef jsprop_value;
+ GArgument field_value;
+ gchar* prop_name;
+ GITypeInfo* field_type;
+
+ if (type == GI_INFO_TYPE_STRUCT) {
+ GType gtype
+ = g_registered_type_info_get_g_type((GIRegisteredTypeInfo*) info);
+ if (g_type_is_a(gtype, G_TYPE_VALUE)) {
+ GValue* gval = g_slice_alloc0(sizeof(GValue));
+ if (!parameters) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Missing Type in GValue constructor");
+ return (JSObjectRef) JSValueMakeNull(ctx);
}
- SEED_NOTE (CONSTRUCTION, "Created a GValue struct");
- seed_value_to_gvalue (ctx, parameters , 0, gval, exception);
- ret = seed_make_struct (ctx, (gpointer)gval, info);
- return ret;
+ SEED_NOTE(CONSTRUCTION, "Created a GValue struct");
+ seed_value_to_gvalue(ctx, parameters, 0, gval, exception);
+ ret = seed_make_struct(ctx, (gpointer) gval, info);
+ return ret;
}
- size = g_struct_info_get_size ((GIStructInfo *) info);
- }
- else
- {
- size = g_union_info_get_size ((GIUnionInfo *) info);
+ size = g_struct_info_get_size((GIStructInfo*) info);
+ } else {
+ size = g_union_info_get_size((GIUnionInfo*) info);
}
- if (!size)
- {
- g_critical ("Struct/union of type: %s has size 0 in introspection data. Please check GIR",
- g_base_info_get_name (info));
- g_assert(size);
+ if (!size) {
+ g_critical("Struct/union of type: %s has size 0 in introspection data. "
+ "Please check GIR",
+ g_base_info_get_name(info));
+ g_assert(size);
}
- object = g_slice_alloc0 (size);
+ object = g_slice_alloc0(size);
- SEED_NOTE (CONSTRUCTION,
- "Constructing struct/union of type: %s. Size: %zu \n",
- g_base_info_get_name (info), size);
+ SEED_NOTE(CONSTRUCTION,
+ "Constructing struct/union of type: %s. Size: %zu \n",
+ g_base_info_get_name(info), size);
- if (type == GI_INFO_TYPE_STRUCT)
- ret = seed_make_struct (ctx, object, info);
- else
- ret = seed_make_union (ctx, object, info);
+ if (type == GI_INFO_TYPE_STRUCT)
+ ret = seed_make_struct(ctx, object, info);
+ else
+ ret = seed_make_union(ctx, object, info);
- seed_pointer_set_free (ctx, ret, TRUE);
- seed_pointer_set_slice (ctx, ret, TRUE, size);
+ seed_pointer_set_free(ctx, ret, TRUE);
+ seed_pointer_set_slice(ctx, ret, TRUE, size);
- if (!parameters)
- return ret;
+ if (!parameters)
+ return ret;
+
+ jsprops = JSObjectCopyPropertyNames(ctx, (JSObjectRef) parameters);
+ nparams = JSPropertyNameArrayGetCount(jsprops);
- jsprops = JSObjectCopyPropertyNames (ctx, (JSObjectRef) parameters);
- nparams = JSPropertyNameArrayGetCount (jsprops);
-
- while (i < nparams)
- {
- jsprop_name = JSPropertyNameArrayGetNameAtIndex (jsprops, i);
-
- length = JSStringGetMaximumUTF8CStringSize (jsprop_name);
- prop_name = g_alloca (length * sizeof (gchar));
- JSStringGetUTF8CString (jsprop_name, prop_name, length);
-
- if (type == GI_INFO_TYPE_STRUCT)
- field = seed_struct_find_field ((GIStructInfo *) info, prop_name);
- else
- field = seed_union_find_field ((GIUnionInfo *) info, prop_name);
- if (!field)
- {
- seed_make_exception (ctx, exception, "PropertyError",
- "Invalid property for construction: %s",
- prop_name);
-
- JSPropertyNameArrayRelease (jsprops);
- return (JSObjectRef) JSValueMakeNull (ctx);
- }
- field_type = g_field_info_get_type (field);
-
- jsprop_value = JSObjectGetProperty (ctx,
- (JSObjectRef) parameters,
- jsprop_name, NULL);
-
- seed_value_to_gi_argument (ctx, jsprop_value, field_type, GI_TRANSFER_NOTHING, &field_value,
- exception);
- set_ret = g_field_info_set_field (field, object, &field_value);
-
- if (!set_ret)
- g_warning("Constructor setting property failed on struct of type: %s "
- "with name %s \n",
- g_base_info_get_name (info), prop_name);
-
- g_base_info_unref ((GIBaseInfo *) field_type);
- g_base_info_unref ((GIBaseInfo *) field);
-
- i++;
+ while (i < nparams) {
+ jsprop_name = JSPropertyNameArrayGetNameAtIndex(jsprops, i);
+
+ length = JSStringGetMaximumUTF8CStringSize(jsprop_name);
+ prop_name = g_alloca(length * sizeof(gchar));
+ JSStringGetUTF8CString(jsprop_name, prop_name, length);
+
+ if (type == GI_INFO_TYPE_STRUCT)
+ field = seed_struct_find_field((GIStructInfo*) info, prop_name);
+ else
+ field = seed_union_find_field((GIUnionInfo*) info, prop_name);
+ if (!field) {
+ seed_make_exception(ctx, exception, "PropertyError",
+ "Invalid property for construction: %s",
+ prop_name);
+
+ JSPropertyNameArrayRelease(jsprops);
+ return (JSObjectRef) JSValueMakeNull(ctx);
+ }
+ field_type = g_field_info_get_type(field);
+
+ jsprop_value = JSObjectGetProperty(ctx, (JSObjectRef) parameters,
+ jsprop_name, NULL);
+
+ seed_value_to_gi_argument(ctx, jsprop_value, field_type,
+ GI_TRANSFER_NOTHING, &field_value, exception);
+ set_ret = g_field_info_set_field(field, object, &field_value);
+
+ if (!set_ret)
+ g_warning(
+ "Constructor setting property failed on struct of type: %s "
+ "with name %s \n",
+ g_base_info_get_name(info), prop_name);
+
+ g_base_info_unref((GIBaseInfo*) field_type);
+ g_base_info_unref((GIBaseInfo*) field);
+
+ i++;
}
- JSPropertyNameArrayRelease (jsprops);
+ JSPropertyNameArrayRelease(jsprops);
- return ret;
+ return ret;
}
diff --git a/libseed/seed-structs.h b/libseed/seed-structs.h
index 92f85e9..33ad639 100644
--- a/libseed/seed-structs.h
+++ b/libseed/seed-structs.h
@@ -21,36 +21,37 @@
extern JSClassRef seed_struct_class;
extern JSClassRef seed_union_class;
-JSObjectRef seed_make_union (JSContextRef ctx, gpointer younion,
- GIBaseInfo * info);
-JSObjectRef seed_make_struct (JSContextRef ctx, gpointer strukt,
- GIBaseInfo * info);
-JSObjectRef seed_make_boxed (JSContextRef ctx,
- gpointer boxed, GIBaseInfo * info);
-
-JSObjectRef seed_make_pointer (JSContextRef ctx, gpointer pointer);
-
-JSValueRef
-seed_field_get_value (JSContextRef ctx,
- gpointer object,
- GIFieldInfo * field, JSValueRef * exception);
-
-gpointer seed_pointer_get_pointer (JSContextRef ctx, JSValueRef strukt);
-void seed_pointer_set_free (JSContextRef ctx,
- JSValueRef pointer, gboolean free_pointer);
-
-GIFieldInfo *seed_struct_find_field (GIStructInfo * info, gchar * field_name);
-GIFieldInfo *seed_union_find_field (GIUnionInfo * info, gchar * field_name);
-
-JSObjectRef
-seed_construct_struct_type_with_parameters (JSContextRef ctx,
- GIBaseInfo * info,
- JSObjectRef parameters,
- JSValueRef * exception);
-
-JSObjectRef seed_union_prototype (JSContextRef ctx, GIBaseInfo * info);
-JSObjectRef seed_struct_prototype (JSContextRef ctx, GIBaseInfo * info);
-
-void seed_structs_init ();
+JSObjectRef seed_make_union(JSContextRef ctx,
+ gpointer younion,
+ GIBaseInfo* info);
+JSObjectRef seed_make_struct(JSContextRef ctx,
+ gpointer strukt,
+ GIBaseInfo* info);
+JSObjectRef seed_make_boxed(JSContextRef ctx, gpointer boxed, GIBaseInfo* info);
+
+JSObjectRef seed_make_pointer(JSContextRef ctx, gpointer pointer);
+
+JSValueRef seed_field_get_value(JSContextRef ctx,
+ gpointer object,
+ GIFieldInfo* field,
+ JSValueRef* exception);
+
+gpointer seed_pointer_get_pointer(JSContextRef ctx, JSValueRef strukt);
+void seed_pointer_set_free(JSContextRef ctx,
+ JSValueRef pointer,
+ gboolean free_pointer);
+
+GIFieldInfo* seed_struct_find_field(GIStructInfo* info, gchar* field_name);
+GIFieldInfo* seed_union_find_field(GIUnionInfo* info, gchar* field_name);
+
+JSObjectRef seed_construct_struct_type_with_parameters(JSContextRef ctx,
+ GIBaseInfo* info,
+ JSObjectRef parameters,
+ JSValueRef* exception);
+
+JSObjectRef seed_union_prototype(JSContextRef ctx, GIBaseInfo* info);
+JSObjectRef seed_struct_prototype(JSContextRef ctx, GIBaseInfo* info);
+
+void seed_structs_init();
#endif
diff --git a/libseed/seed-types.c b/libseed/seed-types.c
index 16560bd..ac9e38b 100644
--- a/libseed/seed-types.c
+++ b/libseed/seed-types.c
@@ -26,1695 +26,1499 @@ JSClassRef gobject_method_class;
JSClassRef gobject_constructor_class;
JSClassRef seed_callback_class;
JSClassRef gobject_init_method_class;
-SeedEngine *eng;
+SeedEngine* eng;
static gboolean
-seed_value_is_gobject (JSContextRef ctx, JSValueRef value)
+seed_value_is_gobject(JSContextRef ctx, JSValueRef value)
{
- if (!JSValueIsObject (ctx, value) || JSValueIsNull (ctx, value))
- return FALSE;
+ if (!JSValueIsObject(ctx, value) || JSValueIsNull(ctx, value))
+ return FALSE;
- return JSValueIsObjectOfClass (ctx, value, gobject_class);
+ return JSValueIsObjectOfClass(ctx, value, gobject_class);
}
void
-seed_toggle_ref (gpointer data, GObject * object, gboolean is_last_ref)
+seed_toggle_ref(gpointer data, GObject* object, gboolean is_last_ref)
{
- JSValueRef wrapper;
+ JSValueRef wrapper;
- if (!g_object_get_qdata (object, js_ref_quark))
- return;
+ if (!g_object_get_qdata(object, js_ref_quark))
+ return;
- wrapper = (JSValueRef) data;
+ wrapper = (JSValueRef) data;
- if (is_last_ref)
- {
- JSValueUnprotect (eng->context, wrapper);
- }
- else
- {
- JSValueProtect (eng->context, wrapper);
+ if (is_last_ref) {
+ JSValueUnprotect(eng->context, wrapper);
+ } else {
+ JSValueProtect(eng->context, wrapper);
}
}
static void
-seed_gobject_destroyed (gpointer object)
+seed_gobject_destroyed(gpointer object)
{
- JSValueUnprotect (eng->context, (JSValueRef) object);
- JSObjectSetPrivate ((JSObjectRef) object, 0);
+ JSValueUnprotect(eng->context, (JSValueRef) object);
+ JSObjectSetPrivate((JSObjectRef) object, 0);
}
JSObjectRef
-seed_make_wrapper_for_type (JSContextRef ctx, GType type)
+seed_make_wrapper_for_type(JSContextRef ctx, GType type)
{
- JSClassRef class;
- JSObjectRef ret;
- JSValueRef prototype;
+ JSClassRef class;
+ JSObjectRef ret;
+ JSValueRef prototype;
- class = seed_gobject_get_class_for_gtype (ctx, type);
+ class = seed_gobject_get_class_for_gtype(ctx, type);
- while (!class && (type = g_type_parent (type)))
- class = seed_gobject_get_class_for_gtype (ctx, type);
+ while (!class && (type = g_type_parent(type)))
+ class = seed_gobject_get_class_for_gtype(ctx, type);
- prototype = seed_gobject_get_prototype_for_gtype (type);
- ret = JSObjectMake (ctx, class, NULL);
- if (prototype)
- JSObjectSetPrototype (ctx, ret, prototype);
- else
- g_assert_not_reached ();
+ prototype = seed_gobject_get_prototype_for_gtype(type);
+ ret = JSObjectMake(ctx, class, NULL);
+ if (prototype)
+ JSObjectSetPrototype(ctx, ret, prototype);
+ else
+ g_assert_not_reached();
- return ret;
+ return ret;
}
static JSValueRef
-seed_wrap_object (JSContextRef ctx, GObject * object)
+seed_wrap_object(JSContextRef ctx, GObject* object)
{
- JSValueRef user_data;
- JSObjectRef js_ref;
- GType type;
+ JSValueRef user_data;
+ JSObjectRef js_ref;
+ GType type;
- type = G_OBJECT_TYPE (object);
+ type = G_OBJECT_TYPE(object);
- user_data = (JSValueRef) g_object_get_qdata (object, js_ref_quark);
+ user_data = (JSValueRef) g_object_get_qdata(object, js_ref_quark);
- if (user_data)
- return user_data;
+ if (user_data)
+ return user_data;
- if (pthread_getspecific(seed_next_gobject_wrapper_key))
- js_ref = pthread_getspecific(seed_next_gobject_wrapper_key);
- else
- js_ref = seed_make_wrapper_for_type (ctx, type);
+ if (pthread_getspecific(seed_next_gobject_wrapper_key))
+ js_ref = pthread_getspecific(seed_next_gobject_wrapper_key);
+ else
+ js_ref = seed_make_wrapper_for_type(ctx, type);
- JSObjectSetPrivate (js_ref, object);
+ JSObjectSetPrivate(js_ref, object);
- g_object_set_qdata_full (object, js_ref_quark, (gpointer) js_ref,
- seed_gobject_destroyed);
+ g_object_set_qdata_full(object, js_ref_quark, (gpointer) js_ref,
+ seed_gobject_destroyed);
- JSValueProtect (eng->context, js_ref);
- g_object_add_toggle_ref (object, seed_toggle_ref, (gpointer) js_ref);
+ JSValueProtect(eng->context, js_ref);
+ g_object_add_toggle_ref(object, seed_toggle_ref, (gpointer) js_ref);
- seed_add_signals_to_object (ctx, js_ref, object);
+ seed_add_signals_to_object(ctx, js_ref, object);
- pthread_setspecific(seed_next_gobject_wrapper_key, NULL);
+ pthread_setspecific(seed_next_gobject_wrapper_key, NULL);
- return js_ref;
+ return js_ref;
}
static gboolean
-seed_release_arg (GITransfer transfer,
- GITypeInfo * type_info, GITypeTag type_tag, GArgument * arg)
+seed_release_arg(GITransfer transfer,
+ GITypeInfo* type_info,
+ GITypeTag type_tag,
+ GArgument* arg)
{
- GType gtype;
- GITypeInfo *param_type;
- GIBaseInfo *interface_info;
- GValue *gval;
-
- switch (type_tag)
- {
- case GI_TYPE_TAG_UTF8:
- case GI_TYPE_TAG_FILENAME:
- g_free (arg->v_string);
- break;
- case GI_TYPE_TAG_ARRAY:
- if (arg->v_pointer)
- {
- param_type = g_type_info_get_param_type (type_info, 0);
-
- switch (g_type_info_get_tag (param_type))
- {
- case GI_TYPE_TAG_UTF8:
- if (transfer == GI_TRANSFER_EVERYTHING)
- g_strfreev (arg->v_pointer);
- else if (transfer == GI_TRANSFER_CONTAINER)
- g_free (arg->v_pointer);
- break;
- case GI_TYPE_TAG_GTYPE:
- case GI_TYPE_TAG_FLOAT:
- case GI_TYPE_TAG_UINT8:
- case GI_TYPE_TAG_UINT32:
- g_free (arg->v_pointer);
- break;
- case GI_TYPE_TAG_INTERFACE:
- break;
- default:
- g_assert_not_reached ();
- }
-
- g_base_info_unref ((GIBaseInfo *) param_type);
- }
- break;
- case GI_TYPE_TAG_GHASH:
- {
- GITypeInfo *val_param_info;
- GHashTableIter iter;
- GArgument value;
-
- val_param_info = g_type_info_get_param_type (type_info, 1);
- g_assert(val_param_info != NULL);
-
- /* release the hashtable's values */
- g_hash_table_iter_init (&iter, arg->v_pointer);
- while (g_hash_table_iter_next (&iter, NULL, &value.v_pointer))
- {
- seed_release_arg (GI_TRANSFER_EVERYTHING, val_param_info,
- g_type_info_get_tag (val_param_info), &value);
- }
-
- /* release the hashtable's keys and the hashtable itself */
- g_hash_table_destroy (arg->v_pointer);
- break;
- }
- case GI_TYPE_TAG_INTERFACE:
- {
- if (arg->v_pointer)
- {
- interface_info = g_type_info_get_interface (type_info);
-
- GIInfoType interface_type = g_base_info_get_type (interface_info);
- if (interface_type == GI_INFO_TYPE_CALLBACK)
- {
- /* FIXME: - callback returns are not handled yet */
- g_base_info_unref (interface_info);
- break;
- }
-
- gtype =
- g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *)
- interface_info);
-
- if (g_type_is_a (gtype, G_TYPE_OBJECT)
- || g_type_is_a (gtype, G_TYPE_INTERFACE))
- {
- SEED_NOTE (MISC,
- "Unreffing object of type: %s in"
- "argument release. Reference count: %d\n",
- g_type_name (G_OBJECT_TYPE
- (G_OBJECT (arg->v_pointer))),
- G_OBJECT (arg->v_pointer)->ref_count);
- g_object_unref (G_OBJECT (arg->v_pointer));
- }
- else if (g_type_is_a (gtype, G_TYPE_VALUE))
- {
- gval = (GValue *) arg->v_pointer;
- // Free/unref the GValue's contents.
- g_value_unset (gval);
- // Free the GValue.
- g_slice_free1 (sizeof (GValue), gval);
- }
- else if (g_type_is_a (gtype, G_TYPE_CLOSURE))
- {
- g_closure_unref (arg->v_pointer);
- }
-
- g_base_info_unref (interface_info);
- }
- break;
- }
- default:
- break;
-
+ GType gtype;
+ GITypeInfo* param_type;
+ GIBaseInfo* interface_info;
+ GValue* gval;
+
+ switch (type_tag) {
+ case GI_TYPE_TAG_UTF8:
+ case GI_TYPE_TAG_FILENAME:
+ g_free(arg->v_string);
+ break;
+ case GI_TYPE_TAG_ARRAY:
+ if (arg->v_pointer) {
+ param_type = g_type_info_get_param_type(type_info, 0);
+
+ switch (g_type_info_get_tag(param_type)) {
+ case GI_TYPE_TAG_UTF8:
+ if (transfer == GI_TRANSFER_EVERYTHING)
+ g_strfreev(arg->v_pointer);
+ else if (transfer == GI_TRANSFER_CONTAINER)
+ g_free(arg->v_pointer);
+ break;
+ case GI_TYPE_TAG_GTYPE:
+ case GI_TYPE_TAG_FLOAT:
+ case GI_TYPE_TAG_UINT8:
+ case GI_TYPE_TAG_UINT32:
+ g_free(arg->v_pointer);
+ break;
+ case GI_TYPE_TAG_INTERFACE:
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ g_base_info_unref((GIBaseInfo*) param_type);
+ }
+ break;
+ case GI_TYPE_TAG_GHASH: {
+ GITypeInfo* val_param_info;
+ GHashTableIter iter;
+ GArgument value;
+
+ val_param_info = g_type_info_get_param_type(type_info, 1);
+ g_assert(val_param_info != NULL);
+
+ /* release the hashtable's values */
+ g_hash_table_iter_init(&iter, arg->v_pointer);
+ while (g_hash_table_iter_next(&iter, NULL, &value.v_pointer)) {
+ seed_release_arg(GI_TRANSFER_EVERYTHING, val_param_info,
+ g_type_info_get_tag(val_param_info), &value);
+ }
+
+ /* release the hashtable's keys and the hashtable itself */
+ g_hash_table_destroy(arg->v_pointer);
+ break;
+ }
+ case GI_TYPE_TAG_INTERFACE: {
+ if (arg->v_pointer) {
+ interface_info = g_type_info_get_interface(type_info);
+
+ GIInfoType interface_type
+ = g_base_info_get_type(interface_info);
+ if (interface_type == GI_INFO_TYPE_CALLBACK) {
+ /* FIXME: - callback returns are not handled yet */
+ g_base_info_unref(interface_info);
+ break;
+ }
+
+ gtype = g_registered_type_info_get_g_type(
+ (GIRegisteredTypeInfo*) interface_info);
+
+ if (g_type_is_a(gtype, G_TYPE_OBJECT)
+ || g_type_is_a(gtype, G_TYPE_INTERFACE)) {
+ SEED_NOTE(MISC, "Unreffing object of type: %s in"
+ "argument release. Reference count: %d\n",
+ g_type_name(
+ G_OBJECT_TYPE(G_OBJECT(arg->v_pointer))),
+ G_OBJECT(arg->v_pointer)->ref_count);
+ g_object_unref(G_OBJECT(arg->v_pointer));
+ } else if (g_type_is_a(gtype, G_TYPE_VALUE)) {
+ gval = (GValue*) arg->v_pointer;
+ // Free/unref the GValue's contents.
+ g_value_unset(gval);
+ // Free the GValue.
+ g_slice_free1(sizeof(GValue), gval);
+ } else if (g_type_is_a(gtype, G_TYPE_CLOSURE)) {
+ g_closure_unref(arg->v_pointer);
+ }
+
+ g_base_info_unref(interface_info);
+ }
+ break;
+ }
+ default:
+ break;
}
- return TRUE;
+ return TRUE;
}
gboolean
-seed_gi_release_arg (GITransfer transfer,
- GITypeInfo * type_info, GArgument * arg)
+seed_gi_release_arg(GITransfer transfer, GITypeInfo* type_info, GArgument* arg)
{
- GITypeTag type_tag;
+ GITypeTag type_tag;
- if (transfer == GI_TRANSFER_NOTHING)
- return TRUE;
+ if (transfer == GI_TRANSFER_NOTHING)
+ return TRUE;
- type_tag = g_type_info_get_tag ((GITypeInfo *) type_info);
+ type_tag = g_type_info_get_tag((GITypeInfo*) type_info);
- return seed_release_arg (transfer, type_info, type_tag, arg);
+ return seed_release_arg(transfer, type_info, type_tag, arg);
}
gboolean
-seed_gi_release_in_arg (GITransfer transfer,
- GITypeInfo * type_info, GArgument * arg)
+seed_gi_release_in_arg(GITransfer transfer,
+ GITypeInfo* type_info,
+ GArgument* arg)
{
- GITypeTag type_tag;
+ GITypeTag type_tag;
- if (transfer == GI_TRANSFER_EVERYTHING)
- return TRUE;
+ if (transfer == GI_TRANSFER_EVERYTHING)
+ return TRUE;
- type_tag = g_type_info_get_tag ((GITypeInfo *) type_info);
-
- switch (type_tag)
- {
- // TODO: FIXME: Leaaaks?
- case GI_TYPE_TAG_INTERFACE:
- {
- // TODO: FIXME: Need some safe way to look for GClosure.
- break;
- }
- case GI_TYPE_TAG_UTF8:
- case GI_TYPE_TAG_FILENAME:
- case GI_TYPE_TAG_ARRAY:
- case GI_TYPE_TAG_GHASH:
- return seed_release_arg (GI_TRANSFER_EVERYTHING,
- type_info, type_tag, arg);
- default:
- break;
+ type_tag = g_type_info_get_tag((GITypeInfo*) type_info);
+
+ switch (type_tag) {
+ // TODO: FIXME: Leaaaks?
+ case GI_TYPE_TAG_INTERFACE: {
+ // TODO: FIXME: Need some safe way to look for GClosure.
+ break;
+ }
+ case GI_TYPE_TAG_UTF8:
+ case GI_TYPE_TAG_FILENAME:
+ case GI_TYPE_TAG_ARRAY:
+ case GI_TYPE_TAG_GHASH:
+ return seed_release_arg(GI_TRANSFER_EVERYTHING, type_info, type_tag,
+ arg);
+ default:
+ break;
}
- return TRUE;
+ return TRUE;
}
static JSValueRef
-seed_gi_make_jsarray (JSContextRef ctx,
- void *array,
- GITypeInfo * param_type, JSValueRef * exception)
+seed_gi_make_jsarray(JSContextRef ctx,
+ void* array,
+ GITypeInfo* param_type,
+ JSValueRef* exception)
{
- GITypeTag element_type;
- JSValueRef *elements;
- guint length, i;
- gchar **str_array = (gchar **) array;
- JSValueRef ret = JSValueMakeNull (ctx);
+ GITypeTag element_type;
+ JSValueRef* elements;
+ guint length, i;
+ gchar** str_array = (gchar**) array;
+ JSValueRef ret = JSValueMakeNull(ctx);
- element_type = g_type_info_get_tag (param_type);
+ element_type = g_type_info_get_tag(param_type);
- if (element_type == GI_TYPE_TAG_UTF8)
- {
+ if (element_type == GI_TYPE_TAG_UTF8) {
- length = g_strv_length (str_array);
- if (!length)
- return ret;
+ length = g_strv_length(str_array);
+ if (!length)
+ return ret;
- elements = g_alloca (sizeof (JSValueRef) * length);
- for (i = 0; i < length; ++i)
- {
- elements[i] = seed_value_from_string (ctx, str_array[i], exception);
- }
+ elements = g_alloca(sizeof(JSValueRef) * length);
+ for (i = 0; i < length; ++i) {
+ elements[i] = seed_value_from_string(ctx, str_array[i], exception);
+ }
- ret = (JSValueRef) JSObjectMakeArray (ctx, length, elements, exception);
+ ret = (JSValueRef) JSObjectMakeArray(ctx, length, elements, exception);
}
- if (element_type == GI_TYPE_TAG_GTYPE)
- {
- GType* ptr = (GType*)array;
- length = 0;
- while (ptr[length]) length++;
-
- elements = g_alloca (sizeof (JSValueRef) * length);
+ if (element_type == GI_TYPE_TAG_GTYPE) {
+ GType* ptr = (GType*) array;
+ length = 0;
+ while (ptr[length])
+ length++;
+
+ elements = g_alloca(sizeof(JSValueRef) * length);
- for (i = 0; i < length; ++i)
- elements[i] = seed_value_from_long (ctx, ptr[i], exception);
-
- return (JSValueRef) JSObjectMakeArray (ctx, length, elements, exception);
+ for (i = 0; i < length; ++i)
+ elements[i] = seed_value_from_long(ctx, ptr[i], exception);
+ return (JSValueRef) JSObjectMakeArray(ctx, length, elements, exception);
}
- return ret;
+ return ret;
}
static gboolean
-seed_gi_make_array_from_string (JSContextRef ctx,
- JSStringRef js_string,
- GITypeInfo *param_type,
- void **array_p,
- JSValueRef *exception)
+seed_gi_make_array_from_string(JSContextRef ctx,
+ JSStringRef js_string,
+ GITypeInfo* param_type,
+ void** array_p,
+ JSValueRef* exception)
{
GITypeTag element_type;
- element_type = g_type_info_get_tag (param_type);
+ element_type = g_type_info_get_tag(param_type);
// This could be handled by the case where the value is an object,
// however, getting length from a string crashs inside JSC. So,
// we're now proper handling strings here
- size_t length = JSStringGetMaximumUTF8CStringSize (js_string);
- gchar *buffer = g_malloc (length * sizeof (gchar));
- JSStringGetUTF8CString (js_string, buffer, length);
+ size_t length = JSStringGetMaximumUTF8CStringSize(js_string);
+ gchar* buffer = g_malloc(length * sizeof(gchar));
+ JSStringGetUTF8CString(js_string, buffer, length);
- switch (element_type)
- {
- case GI_TYPE_TAG_UINT8:
- {
+ switch (element_type) {
+ case GI_TYPE_TAG_UINT8: {
*array_p = buffer;
break;
- }
- default:
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Unhandled array element type");
- return FALSE;
- }
- }
+ }
+ default: {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Unhandled array element type");
+ return FALSE;
+ }
+ }
return TRUE;
}
static gboolean
-seed_gi_make_array (JSContextRef ctx,
- JSValueRef array,
- guint length,
- GITypeInfo * param_type,
- void **array_p, JSValueRef * exception)
+seed_gi_make_array(JSContextRef ctx,
+ JSValueRef array,
+ guint length,
+ GITypeInfo* param_type,
+ void** array_p,
+ JSValueRef* exception)
{
- GITypeTag element_type;
- JSValueRef elem;
- guint i;
-
- element_type = g_type_info_get_tag (param_type);
-
- switch (element_type)
- {
- case GI_TYPE_TAG_UTF8:
- {
- gchar **strresult = g_new0 (gchar *, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- strresult[i] = seed_value_to_string (ctx, elem, exception);
- }
-
- *array_p = strresult;
- }
- break;
- case GI_TYPE_TAG_GTYPE:
- {
- GType *typeresult;
-
- typeresult = g_new0 (GType, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- typeresult[i] = seed_value_to_int (ctx, elem, exception);
- }
-
- *array_p = typeresult;
- }
- break;
- case GI_TYPE_TAG_FLOAT:
- {
- gfloat *floatresult;
-
- floatresult = g_new0 (gfloat, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- floatresult[i] = seed_value_to_float (ctx, elem, exception);
- }
-
- *array_p = floatresult;
- }
- break;
- case GI_TYPE_TAG_DOUBLE:
- {
- gdouble *dblresult;
-
- dblresult = g_new0 (gdouble, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- dblresult[i] = seed_value_to_double (ctx, elem, exception);
- }
-
- *array_p = dblresult;
- }
- break;
+ GITypeTag element_type;
+ JSValueRef elem;
+ guint i;
+
+ element_type = g_type_info_get_tag(param_type);
+
+ switch (element_type) {
+ case GI_TYPE_TAG_UTF8: {
+ gchar** strresult = g_new0(gchar*, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ strresult[i] = seed_value_to_string(ctx, elem, exception);
+ }
+
+ *array_p = strresult;
+ } break;
+ case GI_TYPE_TAG_GTYPE: {
+ GType* typeresult;
+
+ typeresult = g_new0(GType, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ typeresult[i] = seed_value_to_int(ctx, elem, exception);
+ }
+
+ *array_p = typeresult;
+ } break;
+ case GI_TYPE_TAG_FLOAT: {
+ gfloat* floatresult;
+
+ floatresult = g_new0(gfloat, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ floatresult[i] = seed_value_to_float(ctx, elem, exception);
+ }
+
+ *array_p = floatresult;
+ } break;
+ case GI_TYPE_TAG_DOUBLE: {
+ gdouble* dblresult;
+
+ dblresult = g_new0(gdouble, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ dblresult[i] = seed_value_to_double(ctx, elem, exception);
+ }
+
+ *array_p = dblresult;
+ } break;
#if GOBJECT_INTROSPECTION_VERSION < 0x000900
- case GI_TYPE_TAG_INT:
+ case GI_TYPE_TAG_INT:
#endif
- case GI_TYPE_TAG_INT32:
- {
- gint *intresult;
-
- intresult = g_new0 (gint, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- intresult[i] = seed_value_to_int (ctx, elem, exception);
- }
-
- *array_p = intresult;
- }
- break;
- case GI_TYPE_TAG_UINT8:
- {
- guint8 *guint8result;
-
- guint8result = g_new0 (guint8, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- guint8result[i] = seed_value_to_uchar (ctx, elem, exception);
- }
-
- *array_p = guint8result;
- }
- break;
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo *interface = g_type_info_get_interface (param_type);
- GIInfoType interface_type = g_base_info_get_type (interface);
- if (interface_type == GI_INFO_TYPE_OBJECT
- || interface_type == GI_INFO_TYPE_INTERFACE
- || interface_type == GI_INFO_TYPE_STRUCT)
- {
- GType type =
- g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *)
- interface);
- if (g_type_is_a (type, G_TYPE_VALUE))
- {
- GValue *gvalresult;
-
- // TODO:FIXME: Robb. Valgrind thinks there's a leak here,
- // at least while running Same Seed.
- gvalresult = g_new0 (GValue, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- seed_value_to_gvalue (ctx, elem,
- (GType) 0,
- &gvalresult[i], exception);
- }
- *array_p = gvalresult;
-
- g_base_info_unref (interface);
- break;
- }
- }
-
- g_base_info_unref (interface);
- }
- case GI_TYPE_TAG_UINT32:
- {
- guint32 *uintresult;
-
- uintresult = g_new0 (guint32, length + 1);
-
- for (i = 0; i < length; i++)
- {
- elem = JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef) array,
- i, exception);
- uintresult[i] = seed_value_to_uint (ctx, elem, exception);
- }
- *array_p = uintresult;
- }
- break;
- default:
- seed_make_exception (ctx, exception, "ArgumentError",
- "Unhandled array element type");
- return FALSE;
+ case GI_TYPE_TAG_INT32: {
+ gint* intresult;
+
+ intresult = g_new0(gint, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ intresult[i] = seed_value_to_int(ctx, elem, exception);
+ }
+
+ *array_p = intresult;
+ } break;
+ case GI_TYPE_TAG_UINT8: {
+ guint8* guint8result;
+
+ guint8result = g_new0(guint8, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ guint8result[i] = seed_value_to_uchar(ctx, elem, exception);
+ }
+
+ *array_p = guint8result;
+ } break;
+ case GI_TYPE_TAG_INTERFACE: {
+ GIBaseInfo* interface = g_type_info_get_interface(param_type);
+ GIInfoType interface_type = g_base_info_get_type(interface);
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE
+ || interface_type == GI_INFO_TYPE_STRUCT) {
+ GType type = g_registered_type_info_get_g_type(
+ (GIRegisteredTypeInfo*) interface);
+ if (g_type_is_a(type, G_TYPE_VALUE)) {
+ GValue* gvalresult;
+
+ // TODO:FIXME: Robb. Valgrind thinks there's a leak here,
+ // at least while running Same Seed.
+ gvalresult = g_new0(GValue, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem
+ = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array,
+ i, exception);
+ seed_value_to_gvalue(ctx, elem, (GType) 0,
+ &gvalresult[i], exception);
+ }
+ *array_p = gvalresult;
+
+ g_base_info_unref(interface);
+ break;
+ }
+ }
+
+ g_base_info_unref(interface);
+ }
+ case GI_TYPE_TAG_UINT32: {
+ guint32* uintresult;
+
+ uintresult = g_new0(guint32, length + 1);
+
+ for (i = 0; i < length; i++) {
+ elem = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) array, i,
+ exception);
+ uintresult[i] = seed_value_to_uint(ctx, elem, exception);
+ }
+ *array_p = uintresult;
+ } break;
+ default:
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Unhandled array element type");
+ return FALSE;
}
- return TRUE;
+ return TRUE;
}
gboolean
-seed_value_to_gi_argument (JSContextRef ctx,
- JSValueRef value,
- GITypeInfo * type_info,
- GITransfer transfer,
- GArgument * arg,
- JSValueRef * exception)
+seed_value_to_gi_argument(JSContextRef ctx,
+ JSValueRef value,
+ GITypeInfo* type_info,
+ GITransfer transfer,
+ GArgument* arg,
+ JSValueRef* exception)
{
- GITypeTag gi_tag = g_type_info_get_tag (type_info);
-
- // FIXME: Some types are not "nullable", also need to check if argument
- // can be null before doing this.
- if (!value || JSValueIsNull (ctx, value))
- {
- arg->v_pointer = 0;
- return 1;
- }
+ GITypeTag gi_tag = g_type_info_get_tag(type_info);
- switch (gi_tag)
- {
- case GI_TYPE_TAG_VOID:
-
- if (g_type_info_is_pointer (type_info))
- {
- GObject *gobject;
- if (JSValueIsString (ctx, value))
- {
- /*
- things like gio.outputstream.write use void pointers
- might need a few other types here..
- not very well memory managed. - should be solved by bytearrays when
- introspection implements it.
- */
- arg->v_string = seed_value_to_string (ctx, value, exception);
- break;
- }
- /* gtk_statusicon_position_menu / gtk_menu_popup use the userdata for the Gobject */
- gobject = seed_value_to_object (ctx, value, exception);
- if (!gobject)
- return FALSE;
+ // FIXME: Some types are not "nullable", also need to check if argument
+ // can be null before doing this.
+ if (!value || JSValueIsNull(ctx, value)) {
+ arg->v_pointer = 0;
+ return 1;
+ }
- arg->v_pointer = gobject;
- }
- break;
+ switch (gi_tag) {
+ case GI_TYPE_TAG_VOID:
+
+ if (g_type_info_is_pointer(type_info)) {
+ GObject* gobject;
+ if (JSValueIsString(ctx, value)) {
+ /*
+ things like gio.outputstream.write use void pointers
+ might need a few other types here..
+ not very well memory managed. - should be solved by
+ bytearrays when
+ introspection implements it.
+ */
+ arg->v_string = seed_value_to_string(ctx, value, exception);
+ break;
+ }
+ /* gtk_statusicon_position_menu / gtk_menu_popup use the
+ * userdata for the Gobject */
+ gobject = seed_value_to_object(ctx, value, exception);
+ if (!gobject)
+ return FALSE;
+
+ arg->v_pointer = gobject;
+ }
+ break;
#if GOBJECT_INTROSPECTION_VERSION < 0x000900
- case GI_TYPE_TAG_LONG:
- arg->v_long = seed_value_to_long (ctx, value, exception);
- break;
- case GI_TYPE_TAG_ULONG:
- arg->v_ulong = seed_value_to_ulong (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INT:
- arg->v_int = seed_value_to_int (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UINT:
- arg->v_uint = seed_value_to_uint (ctx, value, exception);
- break;
- case GI_TYPE_TAG_SIZE:
- arg->v_size = seed_value_to_size (ctx, value, exception);
- break;
- case GI_TYPE_TAG_SSIZE:
- arg->v_ssize = seed_value_to_ssize (ctx, value, exception);
- break;
- case GI_TYPE_TAG_TIME_T:
- arg->v_long = seed_value_to_time_t (ctx, value, exception);
- break;
+ case GI_TYPE_TAG_LONG:
+ arg->v_long = seed_value_to_long(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_ULONG:
+ arg->v_ulong = seed_value_to_ulong(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INT:
+ arg->v_int = seed_value_to_int(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UINT:
+ arg->v_uint = seed_value_to_uint(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_SIZE:
+ arg->v_size = seed_value_to_size(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_SSIZE:
+ arg->v_ssize = seed_value_to_ssize(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_TIME_T:
+ arg->v_long = seed_value_to_time_t(ctx, value, exception);
+ break;
#endif
- case GI_TYPE_TAG_BOOLEAN:
- arg->v_boolean = seed_value_to_boolean (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INT8:
- arg->v_int8 = seed_value_to_char (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UINT8:
- arg->v_uint8 = seed_value_to_uchar (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INT16:
- arg->v_int16 = seed_value_to_int (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UINT16:
- arg->v_uint16 = seed_value_to_uint (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INT32:
- arg->v_int32 = seed_value_to_int (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UINT32:
- arg->v_uint32 = seed_value_to_uint (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INT64:
- arg->v_int64 = seed_value_to_int64 (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UINT64:
- arg->v_uint64 = seed_value_to_uint64 (ctx, value, exception);
- break;
- case GI_TYPE_TAG_FLOAT:
- arg->v_float = seed_value_to_float (ctx, value, exception);
- break;
- case GI_TYPE_TAG_DOUBLE:
- arg->v_double = seed_value_to_double (ctx, value, exception);
- break;
- case GI_TYPE_TAG_UTF8:
- arg->v_string = seed_value_to_string (ctx, value, exception);
- break;
- case GI_TYPE_TAG_FILENAME:
- arg->v_string = seed_value_to_filename (ctx, value, exception);
- break;
- case GI_TYPE_TAG_GTYPE:
- arg->v_int = seed_value_to_int (ctx, value, exception);
- break;
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo *interface;
- GIInfoType interface_type;
- GType required_gtype;
- GObject *gobject;
-
- interface = g_type_info_get_interface (type_info);
- interface_type = g_base_info_get_type (interface);
-
- arg->v_pointer = NULL;
-
- if (interface_type == GI_INFO_TYPE_OBJECT ||
- interface_type == GI_INFO_TYPE_INTERFACE)
- {
- gobject = seed_value_to_object (ctx, value, exception);
- required_gtype =
- g_registered_type_info_get_g_type ((GIRegisteredTypeInfo *)
- interface);
-
- // FIXME: Not clear if the g_type_is_a check is desired here.
- // Possibly 'breaks things' when we don't have introspection
- // data for some things in an interface hierarchy. Hasn't
- // provided any problems so far.
- if (!gobject
- || !g_type_is_a (G_OBJECT_TYPE (gobject), required_gtype))
- {
- g_base_info_unref (interface);
- return FALSE;
- }
-
- arg->v_pointer = gobject;
- // FIXME: This has to be done for other types too
- if (transfer == GI_TRANSFER_EVERYTHING)
- g_object_ref (gobject);
- g_base_info_unref (interface);
- break;
- }
- else if (interface_type == GI_INFO_TYPE_ENUM ||
- interface_type == GI_INFO_TYPE_FLAGS)
- {
- // this might need fixing...
- arg->v_long = seed_value_to_long (ctx, value, exception);
- if (!(interface_type == GI_INFO_TYPE_FLAGS)
- && !seed_validate_enum ((GIEnumInfo *) interface,
- arg->v_long))
- {
- seed_make_exception (ctx, exception, "EnumRange",
- "Enum value: %ld is out of range",
- arg->v_long);
- g_base_info_unref (interface);
-
- return FALSE;
- }
-
- g_base_info_unref (interface);
- break;
- }
- else if (interface_type == GI_INFO_TYPE_STRUCT ||
- interface_type == GI_INFO_TYPE_UNION)
- {
- if (JSValueIsObjectOfClass (ctx, value, seed_struct_class))
- arg->v_pointer = seed_pointer_get_pointer (ctx, value);
- else if (JSValueIsObjectOfClass (ctx, value, seed_union_class))
- arg->v_pointer = seed_pointer_get_pointer (ctx, value);
- else
- {
- GType type =
- g_registered_type_info_get_g_type ((GIRegisteredTypeInfo
- *) interface);
- if (!type)
- {
- g_base_info_unref (interface);
- return FALSE;
- }
- else if (type == G_TYPE_VALUE)
- {
- GValue *gval = g_slice_alloc0 (sizeof (GValue));
- seed_value_to_gvalue (ctx,
- value,
- (GType) NULL,
- gval, exception);
- arg->v_pointer = gval;
-
- g_base_info_unref (interface);
- break;
- }
- // Automatically convert between functions and
- // GClosures where expected.
- else if (g_type_is_a (type, G_TYPE_CLOSURE))
- {
- if (JSObjectIsFunction (ctx, (JSObjectRef) value))
- {
- arg->v_pointer =
- seed_closure_new (ctx, (JSObjectRef) value, NULL,
- NULL);
- }
- }
- else
- {
- JSObjectRef strukt =
- seed_construct_struct_type_with_parameters (ctx,
- interface,
- (JSObjectRef) value,
- exception);
- arg->v_pointer = seed_pointer_get_pointer (ctx, strukt);
- }
- }
- g_base_info_unref (interface);
- break;
- }
- else if (interface_type == GI_INFO_TYPE_CALLBACK)
- {
- if (JSValueIsNull (ctx, value))
- {
- arg->v_pointer = NULL;
- g_base_info_unref (interface);
- break;
- }
- // Someone passes in a wrapper around a method where a
- // callback is expected, i.e Clutter.sine_inc_func, as an alpha
- // Have to dlsym the symbol to be able to do this.
- // NOTE: Some cases where dlsym(NULL, symbol) doesn't work depending
- // On how libseed is loaded.
- else if (JSValueIsObjectOfClass (ctx,
- value, gobject_method_class))
- {
- GIFunctionInfo *info =
- JSObjectGetPrivate ((JSObjectRef) value);
- const gchar *symbol = g_function_info_get_symbol (info);
- gchar *error;
- void *fp;
-
- dlerror ();
- fp = (void *) dlsym (0, symbol);
- if ((error = dlerror ()) != NULL)
- {
- g_critical ("dlerror: %s \n", error);
- }
- else
- {
- arg->v_pointer = fp;
- g_base_info_unref (interface);
- break;
- }
- }
- // Somewhat deprecated from when it was necessary to manually
- // create closure objects...
- else if (JSValueIsObjectOfClass (ctx,
- value,
- seed_native_callback_class))
- {
- SeedNativeClosure *privates =
- (SeedNativeClosure *)
- JSObjectGetPrivate ((JSObjectRef) value);
- arg->v_pointer = privates->closure;
- g_base_info_unref (interface);
- break;
- }
- // Automagically create closure around function passed in as
- // callback.
- else if (JSObjectIsFunction (ctx, (JSObjectRef) value))
- {
- SeedNativeClosure *privates = seed_make_native_closure (ctx,
- (GICallableInfo *) interface,
- value);
- arg->v_pointer = privates->closure;
- g_base_info_unref (interface);
- break;
- }
-
- }
- }
- case GI_TYPE_TAG_ARRAY:
- {
- if (JSValueIsNull (ctx, value))
- {
- arg->v_pointer = NULL;
- break;
- }
- else if (JSValueIsString(ctx, value))
- {
- GITypeInfo *param_type;
- param_type = g_type_info_get_param_type (type_info, 0);
-
- JSStringRef js_string = JSValueToStringCopy(ctx, value, exception);
- if (!seed_gi_make_array_from_string (ctx, js_string, param_type,
- &arg->v_pointer, exception))
- {
- g_base_info_unref ((GIBaseInfo *) param_type);
- JSStringRelease(js_string);
- return FALSE;
- }
- JSStringRelease(js_string);
- g_base_info_unref ((GIBaseInfo *) param_type);
+ case GI_TYPE_TAG_BOOLEAN:
+ arg->v_boolean = seed_value_to_boolean(ctx, value, exception);
break;
- }
- else if (!JSValueIsObject (ctx, value))
- {
- // TODO: FIXME: Is this right?
- return FALSE;
- }
- else
- {
- GITypeInfo *param_type;
- //TODO: FIXME: Better array test like the cool one on reddit.
- guint length =
- seed_value_to_int (ctx, seed_object_get_property (ctx,
- (JSObjectRef)
- value,
- "length"),
- exception);
- if (!length)
- {
- arg->v_pointer = NULL;
- break;
- }
-
- param_type = g_type_info_get_param_type (type_info, 0);
- if (!seed_gi_make_array (ctx, value, length, param_type,
- &arg->v_pointer, exception))
- {
- g_base_info_unref ((GIBaseInfo *) param_type);
- return FALSE;
- }
- g_base_info_unref ((GIBaseInfo *) param_type);
- break;
- }
- }
- case GI_TYPE_TAG_GHASH:
- {
- GITypeInfo *key_param_info, *val_param_info;
- GHashTable *hash_table;
-
- JSPropertyNameArrayRef jsprops = 0;
- JSStringRef jsprop_name;
- JSValueRef jsprop_value;
- int i, nparams = 0;
-
- if (!JSValueIsObject (ctx, value))
- {
- return FALSE;
- }
+ case GI_TYPE_TAG_INT8:
+ arg->v_int8 = seed_value_to_char(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UINT8:
+ arg->v_uint8 = seed_value_to_uchar(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INT16:
+ arg->v_int16 = seed_value_to_int(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UINT16:
+ arg->v_uint16 = seed_value_to_uint(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INT32:
+ arg->v_int32 = seed_value_to_int(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UINT32:
+ arg->v_uint32 = seed_value_to_uint(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INT64:
+ arg->v_int64 = seed_value_to_int64(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UINT64:
+ arg->v_uint64 = seed_value_to_uint64(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_FLOAT:
+ arg->v_float = seed_value_to_float(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_DOUBLE:
+ arg->v_double = seed_value_to_double(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_UTF8:
+ arg->v_string = seed_value_to_string(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_FILENAME:
+ arg->v_string = seed_value_to_filename(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_GTYPE:
+ arg->v_int = seed_value_to_int(ctx, value, exception);
+ break;
+ case GI_TYPE_TAG_INTERFACE: {
+ GIBaseInfo* interface;
+ GIInfoType interface_type;
+ GType required_gtype;
+ GObject* gobject;
+
+ interface = g_type_info_get_interface(type_info);
+ interface_type = g_base_info_get_type(interface);
- if (JSValueIsNull (ctx, value))
- {
arg->v_pointer = NULL;
- break;
- }
-
- key_param_info = g_type_info_get_param_type (type_info, 0);
- g_assert(key_param_info != NULL);
- if (g_type_info_get_tag (key_param_info) != GI_TYPE_TAG_UTF8)
- {
- /* Functions requesting a hash table with non-string keys are
- * not supported */
- return FALSE;
- }
-
- val_param_info = g_type_info_get_param_type (type_info, 1);
- g_assert(val_param_info != NULL);
-
- jsprops = JSObjectCopyPropertyNames (ctx, (JSObjectRef) value);
- nparams = JSPropertyNameArrayGetCount (jsprops);
-
- /* keys are strings and the destructor is g_free
- * values will be freed in seed_release_arg
- */
- hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-
- for (i = 0; i < nparams; i++)
- {
- char *prop_name;
- int length;
- GArgument hash_arg;
-
- jsprop_name = JSPropertyNameArrayGetNameAtIndex (jsprops, i);
-
- length = JSStringGetMaximumUTF8CStringSize (jsprop_name);
- prop_name = g_malloc (length * sizeof (gchar));
- JSStringGetUTF8CString (jsprop_name, prop_name, length);
-
- jsprop_value = JSObjectGetProperty (ctx,
- (JSObjectRef) value,
- jsprop_name, NULL);
-
- if (!seed_value_to_gi_argument (ctx, jsprop_value,
- val_param_info,
- GI_TRANSFER_NOTHING,
- &hash_arg,
- exception))
- {
- g_hash_table_destroy (hash_table);
- g_base_info_unref ((GIBaseInfo *) val_param_info);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE) {
+ gobject = seed_value_to_object(ctx, value, exception);
+ required_gtype = g_registered_type_info_get_g_type(
+ (GIRegisteredTypeInfo*) interface);
+
+ // FIXME: Not clear if the g_type_is_a check is desired here.
+ // Possibly 'breaks things' when we don't have introspection
+ // data for some things in an interface hierarchy. Hasn't
+ // provided any problems so far.
+ if (!gobject
+ || !g_type_is_a(G_OBJECT_TYPE(gobject), required_gtype)) {
+ g_base_info_unref(interface);
+ return FALSE;
+ }
+
+ arg->v_pointer = gobject;
+ // FIXME: This has to be done for other types too
+ if (transfer == GI_TRANSFER_EVERYTHING)
+ g_object_ref(gobject);
+ g_base_info_unref(interface);
+ break;
+ } else if (interface_type == GI_INFO_TYPE_ENUM
+ || interface_type == GI_INFO_TYPE_FLAGS) {
+ // this might need fixing...
+ arg->v_long = seed_value_to_long(ctx, value, exception);
+ if (!(interface_type == GI_INFO_TYPE_FLAGS)
+ && !seed_validate_enum((GIEnumInfo*) interface,
+ arg->v_long)) {
+ seed_make_exception(ctx, exception, "EnumRange",
+ "Enum value: %ld is out of range",
+ arg->v_long);
+ g_base_info_unref(interface);
+
+ return FALSE;
+ }
+
+ g_base_info_unref(interface);
+ break;
+ } else if (interface_type == GI_INFO_TYPE_STRUCT
+ || interface_type == GI_INFO_TYPE_UNION) {
+ if (JSValueIsObjectOfClass(ctx, value, seed_struct_class))
+ arg->v_pointer = seed_pointer_get_pointer(ctx, value);
+ else if (JSValueIsObjectOfClass(ctx, value, seed_union_class))
+ arg->v_pointer = seed_pointer_get_pointer(ctx, value);
+ else {
+ GType type = g_registered_type_info_get_g_type(
+ (GIRegisteredTypeInfo*) interface);
+ if (!type) {
+ g_base_info_unref(interface);
+ return FALSE;
+ } else if (type == G_TYPE_VALUE) {
+ GValue* gval = g_slice_alloc0(sizeof(GValue));
+ seed_value_to_gvalue(ctx, value, (GType) NULL, gval,
+ exception);
+ arg->v_pointer = gval;
+
+ g_base_info_unref(interface);
+ break;
+ }
+ // Automatically convert between functions and
+ // GClosures where expected.
+ else if (g_type_is_a(type, G_TYPE_CLOSURE)) {
+ if (JSObjectIsFunction(ctx, (JSObjectRef) value)) {
+ arg->v_pointer
+ = seed_closure_new(ctx, (JSObjectRef) value, NULL,
+ NULL);
+ }
+ } else {
+ JSObjectRef strukt
+ = seed_construct_struct_type_with_parameters(
+ ctx, interface, (JSObjectRef) value, exception);
+ arg->v_pointer = seed_pointer_get_pointer(ctx, strukt);
+ }
+ }
+ g_base_info_unref(interface);
+ break;
+ } else if (interface_type == GI_INFO_TYPE_CALLBACK) {
+ if (JSValueIsNull(ctx, value)) {
+ arg->v_pointer = NULL;
+ g_base_info_unref(interface);
+ break;
+ }
+ // Someone passes in a wrapper around a method where a
+ // callback is expected, i.e Clutter.sine_inc_func, as an alpha
+ // Have to dlsym the symbol to be able to do this.
+ // NOTE: Some cases where dlsym(NULL, symbol) doesn't work
+ // depending
+ // On how libseed is loaded.
+ else if (JSValueIsObjectOfClass(ctx, value,
+ gobject_method_class)) {
+ GIFunctionInfo* info
+ = JSObjectGetPrivate((JSObjectRef) value);
+ const gchar* symbol = g_function_info_get_symbol(info);
+ gchar* error;
+ void* fp;
+
+ dlerror();
+ fp = (void*) dlsym(0, symbol);
+ if ((error = dlerror()) != NULL) {
+ g_critical("dlerror: %s \n", error);
+ } else {
+ arg->v_pointer = fp;
+ g_base_info_unref(interface);
+ break;
+ }
+ }
+ // Somewhat deprecated from when it was necessary to manually
+ // create closure objects...
+ else if (JSValueIsObjectOfClass(ctx, value,
+ seed_native_callback_class)) {
+ SeedNativeClosure* privates
+ = (SeedNativeClosure*) JSObjectGetPrivate(
+ (JSObjectRef) value);
+ arg->v_pointer = privates->closure;
+ g_base_info_unref(interface);
+ break;
+ }
+ // Automagically create closure around function passed in as
+ // callback.
+ else if (JSObjectIsFunction(ctx, (JSObjectRef) value)) {
+ SeedNativeClosure* privates
+ = seed_make_native_closure(ctx,
+ (GICallableInfo*) interface,
+ value);
+ arg->v_pointer = privates->closure;
+ g_base_info_unref(interface);
+ break;
+ }
+ }
+ }
+ case GI_TYPE_TAG_ARRAY: {
+ if (JSValueIsNull(ctx, value)) {
+ arg->v_pointer = NULL;
+ break;
+ } else if (JSValueIsString(ctx, value)) {
+ GITypeInfo* param_type;
+ param_type = g_type_info_get_param_type(type_info, 0);
+
+ JSStringRef js_string
+ = JSValueToStringCopy(ctx, value, exception);
+ if (!seed_gi_make_array_from_string(ctx, js_string, param_type,
+ &arg->v_pointer,
+ exception)) {
+ g_base_info_unref((GIBaseInfo*) param_type);
+ JSStringRelease(js_string);
+ return FALSE;
+ }
+ JSStringRelease(js_string);
+ g_base_info_unref((GIBaseInfo*) param_type);
+ break;
+ } else if (!JSValueIsObject(ctx, value)) {
+ // TODO: FIXME: Is this right?
+ return FALSE;
+ } else {
+ GITypeInfo* param_type;
+ // TODO: FIXME: Better array test like the cool one on reddit.
+ guint length = seed_value_to_int(
+ ctx,
+ seed_object_get_property(ctx, (JSObjectRef) value, "length"),
+ exception);
+ if (!length) {
+ arg->v_pointer = NULL;
+ break;
+ }
+
+ param_type = g_type_info_get_param_type(type_info, 0);
+ if (!seed_gi_make_array(ctx, value, length, param_type,
+ &arg->v_pointer, exception)) {
+ g_base_info_unref((GIBaseInfo*) param_type);
+ return FALSE;
+ }
+ g_base_info_unref((GIBaseInfo*) param_type);
+ break;
+ }
+ }
+ case GI_TYPE_TAG_GHASH: {
+ GITypeInfo *key_param_info, *val_param_info;
+ GHashTable* hash_table;
+
+ JSPropertyNameArrayRef jsprops = 0;
+ JSStringRef jsprop_name;
+ JSValueRef jsprop_value;
+ int i, nparams = 0;
+
+ if (!JSValueIsObject(ctx, value)) {
return FALSE;
- }
+ }
+
+ if (JSValueIsNull(ctx, value)) {
+ arg->v_pointer = NULL;
+ break;
+ }
+
+ key_param_info = g_type_info_get_param_type(type_info, 0);
+ g_assert(key_param_info != NULL);
+ if (g_type_info_get_tag(key_param_info) != GI_TYPE_TAG_UTF8) {
+ /* Functions requesting a hash table with non-string keys are
+ * not supported */
+ return FALSE;
+ }
- g_hash_table_insert (hash_table,
- prop_name,
- hash_arg.v_pointer);
- }
+ val_param_info = g_type_info_get_param_type(type_info, 1);
+ g_assert(val_param_info != NULL);
- arg->v_pointer = hash_table;
+ jsprops = JSObjectCopyPropertyNames(ctx, (JSObjectRef) value);
+ nparams = JSPropertyNameArrayGetCount(jsprops);
- break;
- }
- default:
- return FALSE;
+ /* keys are strings and the destructor is g_free
+ * values will be freed in seed_release_arg
+ */
+ hash_table
+ = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
- }
- return TRUE;
+ for (i = 0; i < nparams; i++) {
+ char* prop_name;
+ int length;
+ GArgument hash_arg;
+
+ jsprop_name = JSPropertyNameArrayGetNameAtIndex(jsprops, i);
+
+ length = JSStringGetMaximumUTF8CStringSize(jsprop_name);
+ prop_name = g_malloc(length * sizeof(gchar));
+ JSStringGetUTF8CString(jsprop_name, prop_name, length);
+
+ jsprop_value = JSObjectGetProperty(ctx, (JSObjectRef) value,
+ jsprop_name, NULL);
+ if (!seed_value_to_gi_argument(ctx, jsprop_value,
+ val_param_info,
+ GI_TRANSFER_NOTHING, &hash_arg,
+ exception)) {
+ g_hash_table_destroy(hash_table);
+ g_base_info_unref((GIBaseInfo*) val_param_info);
+ return FALSE;
+ }
+
+ g_hash_table_insert(hash_table, prop_name, hash_arg.v_pointer);
+ }
+
+ arg->v_pointer = hash_table;
+
+ break;
+ }
+ default:
+ return FALSE;
+ }
+ return TRUE;
}
JSValueRef
-seed_value_from_gi_argument (JSContextRef ctx,
- GArgument * arg,
- GITypeInfo * type_info,
- JSValueRef * exception)
+seed_value_from_gi_argument(JSContextRef ctx,
+ GArgument* arg,
+ GITypeInfo* type_info,
+ JSValueRef* exception)
{
-
- return seed_value_from_gi_argument_full (
- ctx,
- arg,
- type_info,
- exception,
- 0,
- g_type_info_get_tag (type_info) );
+
+ return seed_value_from_gi_argument_full(ctx, arg, type_info, exception, 0,
+ g_type_info_get_tag(type_info));
}
-
+
JSValueRef
-seed_value_from_gi_argument_full (JSContextRef ctx,
- GArgument * arg,
- GITypeInfo * type_info,
- JSValueRef * exception,
- guint64 array_len,
- GITypeTag gi_tag
- )
+seed_value_from_gi_argument_full(JSContextRef ctx,
+ GArgument* arg,
+ GITypeInfo* type_info,
+ JSValueRef* exception,
+ guint64 array_len,
+ GITypeTag gi_tag)
{
-
- //seed_value_from_gi_argument_with_length : g_type_tag_to_string(gi_tag)
- SEED_NOTE (INVOCATION,
- "seed_value_from_gi_argument_full: arg_type = %s ",
- g_type_tag_to_string(gi_tag)
- );
- switch (gi_tag)
- {
+ // seed_value_from_gi_argument_with_length : g_type_tag_to_string(gi_tag)
+ SEED_NOTE(INVOCATION, "seed_value_from_gi_argument_full: arg_type = %s ",
+ g_type_tag_to_string(gi_tag));
+
+ switch (gi_tag) {
#if GOBJECT_INTROSPECTION_VERSION < 0x000900
- case GI_TYPE_TAG_LONG:
- return seed_value_from_long (ctx, arg->v_long, exception);
- case GI_TYPE_TAG_ULONG:
- return seed_value_from_ulong (ctx, arg->v_ulong, exception);
- case GI_TYPE_TAG_INT:
- return seed_value_from_int (ctx, arg->v_int32, exception);
- case GI_TYPE_TAG_UINT:
- return seed_value_from_uint (ctx, arg->v_uint32, exception);
- case GI_TYPE_TAG_SSIZE:
- return seed_value_from_ssize (ctx, arg->v_ssize, exception);
- case GI_TYPE_TAG_SIZE:
- return seed_value_from_size (ctx, arg->v_size, exception);
- case GI_TYPE_TAG_TIME_T:
- return seed_value_from_time_t (ctx, arg->v_long, exception);
+ case GI_TYPE_TAG_LONG:
+ return seed_value_from_long(ctx, arg->v_long, exception);
+ case GI_TYPE_TAG_ULONG:
+ return seed_value_from_ulong(ctx, arg->v_ulong, exception);
+ case GI_TYPE_TAG_INT:
+ return seed_value_from_int(ctx, arg->v_int32, exception);
+ case GI_TYPE_TAG_UINT:
+ return seed_value_from_uint(ctx, arg->v_uint32, exception);
+ case GI_TYPE_TAG_SSIZE:
+ return seed_value_from_ssize(ctx, arg->v_ssize, exception);
+ case GI_TYPE_TAG_SIZE:
+ return seed_value_from_size(ctx, arg->v_size, exception);
+ case GI_TYPE_TAG_TIME_T:
+ return seed_value_from_time_t(ctx, arg->v_long, exception);
#endif
- case GI_TYPE_TAG_VOID:
- return JSValueMakeUndefined (ctx);
- case GI_TYPE_TAG_BOOLEAN:
- return seed_value_from_boolean (ctx, arg->v_boolean, exception);
- case GI_TYPE_TAG_INT8:
- return seed_value_from_char (ctx, arg->v_int8, exception);
- case GI_TYPE_TAG_UINT8:
- return seed_value_from_uchar (ctx, arg->v_uint8, exception);
- case GI_TYPE_TAG_INT16:
- return seed_value_from_int (ctx, arg->v_int16, exception);
- case GI_TYPE_TAG_UINT16:
- return seed_value_from_uint (ctx, arg->v_uint16, exception);
- case GI_TYPE_TAG_INT32:
- return seed_value_from_int (ctx, arg->v_int32, exception);
- case GI_TYPE_TAG_UINT32:
- return seed_value_from_uint (ctx, arg->v_uint32, exception);
- case GI_TYPE_TAG_INT64:
- return seed_value_from_int64 (ctx, arg->v_int64, exception);
- case GI_TYPE_TAG_UINT64:
- return seed_value_from_uint64 (ctx, arg->v_uint64, exception);
- case GI_TYPE_TAG_FLOAT:
- return seed_value_from_float (ctx, arg->v_float, exception);
- case GI_TYPE_TAG_DOUBLE:
- return seed_value_from_double (ctx, arg->v_double, exception);
- case GI_TYPE_TAG_UTF8:
- return seed_value_from_string (ctx, arg->v_string, exception);
- case GI_TYPE_TAG_FILENAME:
- return seed_value_from_filename (ctx, arg->v_string, exception);
- case GI_TYPE_TAG_GTYPE:
- return seed_value_from_int (ctx, arg->v_int, exception);
- case GI_TYPE_TAG_ARRAY:
- {
-
- GIArrayType array_type;
- GITypeInfo *array_type_info;
- JSValueRef ret;
-
- if (arg->v_pointer == NULL)
- return JSValueMakeNull (ctx);
-
- array_type = g_type_info_get_array_type (type_info);
-
- array_type_info = g_type_info_get_param_type (type_info, 0);
-
-
-
- if (array_type == GI_ARRAY_TYPE_PTR_ARRAY)
- {
- JSObjectRef ret_ptr_array;
- GPtrArray *ptr = arg->v_pointer;
- GArgument larg;
- int length = 0;
- int i;
+ case GI_TYPE_TAG_VOID:
+ return JSValueMakeUndefined(ctx);
+ case GI_TYPE_TAG_BOOLEAN:
+ return seed_value_from_boolean(ctx, arg->v_boolean, exception);
+ case GI_TYPE_TAG_INT8:
+ return seed_value_from_char(ctx, arg->v_int8, exception);
+ case GI_TYPE_TAG_UINT8:
+ return seed_value_from_uchar(ctx, arg->v_uint8, exception);
+ case GI_TYPE_TAG_INT16:
+ return seed_value_from_int(ctx, arg->v_int16, exception);
+ case GI_TYPE_TAG_UINT16:
+ return seed_value_from_uint(ctx, arg->v_uint16, exception);
+ case GI_TYPE_TAG_INT32:
+ return seed_value_from_int(ctx, arg->v_int32, exception);
+ case GI_TYPE_TAG_UINT32:
+ return seed_value_from_uint(ctx, arg->v_uint32, exception);
+ case GI_TYPE_TAG_INT64:
+ return seed_value_from_int64(ctx, arg->v_int64, exception);
+ case GI_TYPE_TAG_UINT64:
+ return seed_value_from_uint64(ctx, arg->v_uint64, exception);
+ case GI_TYPE_TAG_FLOAT:
+ return seed_value_from_float(ctx, arg->v_float, exception);
+ case GI_TYPE_TAG_DOUBLE:
+ return seed_value_from_double(ctx, arg->v_double, exception);
+ case GI_TYPE_TAG_UTF8:
+ return seed_value_from_string(ctx, arg->v_string, exception);
+ case GI_TYPE_TAG_FILENAME:
+ return seed_value_from_filename(ctx, arg->v_string, exception);
+ case GI_TYPE_TAG_GTYPE:
+ return seed_value_from_int(ctx, arg->v_int, exception);
+ case GI_TYPE_TAG_ARRAY: {
+
+ GIArrayType array_type;
+ GITypeInfo* array_type_info;
+ JSValueRef ret;
- length = ptr->len;
- ret_ptr_array = JSObjectMakeArray (ctx, 0, NULL, exception);
+ if (arg->v_pointer == NULL)
+ return JSValueMakeNull(ctx);
- for (i = 0; i < length; ++i)
- {
- JSValueRef ival;
+ array_type = g_type_info_get_array_type(type_info);
- larg.v_pointer = g_ptr_array_index(ptr, i);
- ival = (JSValueRef) seed_value_from_gi_argument (ctx, &larg,
- array_type_info, exception);
- if (!ival)
- ival = JSValueMakeNull (ctx);
-
- JSObjectSetPropertyAtIndex (ctx, ret_ptr_array, i, ival, NULL);
- }
-
- g_base_info_unref ((GIBaseInfo *) array_type_info);
-
- return ret_ptr_array;
- }
-
- // technically gir has arrays of bytes, eg.
- // <array length="2" zero-terminated="0" c:type="gchar**"><type name="guint8"/>
- // example : g_file_get_contents..
- // we can treat this as a string.. - it's a bit flakey, we should really use
- // Uint8Array - need to check the webkit API for this..
-
- if (
- !g_type_info_is_zero_terminated (type_info)
- && array_type == GI_ARRAY_TYPE_C
- && GI_TYPE_TAG_UINT8 == g_type_info_get_tag (array_type_info)
- && array_len > 0
- )
- {
- // got a stringy array..
- // we should check g_type_info_get_array_fixed_size
- // we are assuming that this is the array_len from the call..
- g_base_info_unref ((GIBaseInfo *) array_type_info);
-
- ret = seed_value_from_binary_string (ctx, arg->v_pointer, array_len, exception);
- // always free arg... what about when we do not own it...?
- //g_free(arg->v_pointer);
-
- return ret;
-
- }
-
-
- if (!g_type_info_is_zero_terminated (type_info))
- {
- g_base_info_unref ((GIBaseInfo *) array_type_info);
- break;
- }
-
- ret = seed_gi_make_jsarray (ctx, arg->v_pointer, array_type_info,
- exception);
-
- g_base_info_unref ((GIBaseInfo *) array_type_info);
-
- return ret;
- }
- case GI_TYPE_TAG_INTERFACE:
- {
- GIBaseInfo *interface;
- GIInfoType interface_type;
-
- interface = g_type_info_get_interface (type_info);
- interface_type = g_base_info_get_type (interface);
-
- if (interface_type == GI_INFO_TYPE_OBJECT ||
- interface_type == GI_INFO_TYPE_INTERFACE)
- {
- if (arg->v_pointer == 0)
- {
- g_base_info_unref (interface);
- return JSValueMakeNull (ctx);
- }
- g_base_info_unref (interface);
- return seed_value_from_object (ctx, arg->v_pointer, exception);
- }
- else if (interface_type == GI_INFO_TYPE_ENUM)
- {
- JSValueRef ret;
- GITypeTag etype = g_enum_info_get_storage_type (interface);
-
- // needs GITypeInfo - we are sending it GIBaseInfo
-
- ret = seed_value_from_gi_argument_full (
- ctx,
- arg,
- type_info,
- exception,
- 0,
- etype);
- g_base_info_unref (interface);
- return ret;
- }
- else if ( interface_type == GI_INFO_TYPE_FLAGS)
- {
-
- g_base_info_unref (interface);
- return seed_value_from_long (ctx, arg->v_long, exception);
- }
- else if (interface_type == GI_INFO_TYPE_STRUCT)
- {
- JSValueRef strukt;
-
- strukt = seed_make_struct (ctx, arg->v_pointer, interface);
- g_base_info_unref (interface);
-
- return strukt;
- }
- else if (interface_type == GI_INFO_TYPE_CALLBACK)
- {
- /* FIXME: return values of type callback are not handled yet. */
- g_base_info_unref (interface);
- return FALSE;
- }
- /* fall through - other types?? */
- g_base_info_unref (interface);
- return FALSE;
- }
-
- case GI_TYPE_TAG_GLIST:
- {
- GITypeInfo *list_type;
- JSObjectRef ret;
- GArgument larg;
- gint i = 0;
- GList *list = arg->v_pointer;
-
- ret = JSObjectMakeArray (ctx, 0, NULL, exception);
- list_type = g_type_info_get_param_type (type_info, 0);
-
- for (; list != NULL; list = list->next)
- {
- JSValueRef ival;
-
- larg.v_pointer = list->data;
- ival =
- (JSValueRef) seed_value_from_gi_argument (ctx, &larg,
- list_type, exception);
- if (!ival)
- ival = JSValueMakeNull (ctx);
- JSObjectSetPropertyAtIndex (ctx, ret, i, ival, NULL);
- i++;
- }
- return ret;
-
- }
- case GI_TYPE_TAG_GSLIST:
- {
- GITypeInfo *list_type;
- JSObjectRef ret;
- JSValueRef ival;
- GArgument larg;
- guint i = 0;
- GSList *list = arg->v_pointer;
-
- ret = JSObjectMakeArray (ctx, 0, NULL, exception);
- list_type = g_type_info_get_param_type (type_info, 0);
-
- for (; list != NULL; list = list->next)
- {
- larg.v_pointer = list->data;
- ival =
- (JSValueRef) seed_value_from_gi_argument (ctx, &larg,
- list_type, exception);
- if (!ival)
- ival = JSValueMakeNull (ctx);
- JSObjectSetPropertyAtIndex (ctx, ret, i, ival, NULL);
- i++;
- }
- return ret;
- }
- case GI_TYPE_TAG_GHASH:
- {
- GITypeInfo *key_type;
- GITypeTag key_type_tag;
- GITypeInfo *value_type;
- JSObjectRef ret;
- GHashTable *hash_table;
- GHashTableIter iter;
- gpointer key, value;
-
- key_type = g_type_info_get_param_type (type_info, 0);
- key_type_tag = g_type_info_get_tag (key_type);
-
- if ((key_type_tag != GI_TYPE_TAG_UTF8) &&
- (key_type_tag != GI_TYPE_TAG_FILENAME))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Unable to make object from hash table indexed with values of type %s",
g_type_tag_to_string (key_type_tag));
- return JSValueMakeNull (ctx);
- }
-
- hash_table = arg->v_pointer;
- if (!hash_table)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Unable to make hash table indexed with values of type %s",
g_type_tag_to_string (key_type_tag));
- return JSValueMakeNull (ctx);
- }
-
- value_type = g_type_info_get_param_type (type_info, 1);
-
- ret = JSObjectMake (ctx, NULL, NULL);
-
- g_hash_table_iter_init (&iter, hash_table);
-
- while (g_hash_table_iter_next (&iter, &key, &value))
- {
- JSStringRef js_key;
- GArgument value_arg;
- JSValueRef value_jsval;
-
- js_key = JSStringCreateWithUTF8CString ((const char*) key);
-
- value_arg.v_string = value;
- value_jsval = seed_value_from_gi_argument_full (ctx, &value_arg,
- value_type, exception, 0, key_type_tag);
-
- JSObjectSetProperty (ctx, ret, js_key, value_jsval, 0, NULL);
- }
-
- return ret;
- }
- case GI_TYPE_TAG_ERROR:
- {
- JSValueRef ret;
- seed_make_exception_from_gerror (ctx, &ret, (GError*) arg->v_pointer);
- return ret;
- }
-
- default:
- return FALSE;
+ array_type_info = g_type_info_get_param_type(type_info, 0);
- }
- return 0;
-}
+ if (array_type == GI_ARRAY_TYPE_PTR_ARRAY) {
+ JSObjectRef ret_ptr_array;
+ GPtrArray* ptr = arg->v_pointer;
+ GArgument larg;
+ int length = 0;
+ int i;
-JSValueRef
-seed_value_from_gvalue_for_signal (JSContextRef ctx, GValue * gval,
- JSValueRef * exception,
- GSignalQuery *signal_query, gint arg_n)
-{
- if (!G_IS_VALUE (gval))
- {
- return false;
- }
- switch (G_VALUE_TYPE (gval))
- {
- case G_TYPE_BOOLEAN:
- return seed_value_from_boolean (ctx,
- g_value_get_boolean (gval), exception);
- case G_TYPE_CHAR:
- return seed_value_from_char (ctx, g_value_get_schar (gval), exception);
- case G_TYPE_UCHAR:
- return seed_value_from_uchar (ctx, g_value_get_uchar (gval), exception);
- case G_TYPE_INT:
- return seed_value_from_int (ctx, g_value_get_int (gval), exception);
- case G_TYPE_UINT:
- return seed_value_from_uint (ctx, g_value_get_uint (gval), exception);
- case G_TYPE_LONG:
- return seed_value_from_long (ctx, g_value_get_long (gval), exception);
- case G_TYPE_ULONG:
- return seed_value_from_ulong (ctx, g_value_get_ulong (gval), exception);
- case G_TYPE_INT64:
- return seed_value_from_int64 (ctx, g_value_get_int64 (gval), exception);
- case G_TYPE_UINT64:
- return seed_value_from_uint64 (ctx, g_value_get_uint64 (gval),
- exception);
- case G_TYPE_FLOAT:
- return seed_value_from_float (ctx, g_value_get_float (gval), exception);
- case G_TYPE_DOUBLE:
- return seed_value_from_double (ctx, g_value_get_double (gval),
- exception);
- case G_TYPE_STRING:
- return seed_value_from_string (ctx, (gchar *)
- g_value_get_string (gval), exception);
- case G_TYPE_POINTER:
- if (signal_query)
- {
- JSValueRef res;
- GArgument arg;
- GIBaseInfo *obj;
- GISignalInfo *signal_info;
- GIArgInfo *arg_info;
- GITypeInfo type_info;
+ length = ptr->len;
+ ret_ptr_array = JSObjectMakeArray(ctx, 0, NULL, exception);
+
+ for (i = 0; i < length; ++i) {
+ JSValueRef ival;
+
+ larg.v_pointer = g_ptr_array_index(ptr, i);
+ ival = (JSValueRef) seed_value_from_gi_argument(
+ ctx, &larg, array_type_info, exception);
+ if (!ival)
+ ival = JSValueMakeNull(ctx);
- obj = g_irepository_find_by_gtype(NULL, signal_query->itype);
- if (!obj)
- return NULL;
+ JSObjectSetPropertyAtIndex(ctx, ret_ptr_array, i, ival,
+ NULL);
+ }
- signal_info = g_object_info_find_signal((GIObjectInfo *) obj,
- signal_query->signal_name);
+ g_base_info_unref((GIBaseInfo*) array_type_info);
- if (!signal_info) {
- g_base_info_unref((GIBaseInfo *) obj);
- return NULL;
- }
+ return ret_ptr_array;
+ }
- arg_info = g_callable_info_get_arg(signal_info, arg_n - 1);
- g_arg_info_load_type(arg_info, &type_info);
+ // technically gir has arrays of bytes, eg.
+ // <array length="2" zero-terminated="0" c:type="gchar**"><type
+ // name="guint8"/>
+ // example : g_file_get_contents..
+ // we can treat this as a string.. - it's a bit flakey, we should
+ // really use
+ // Uint8Array - need to check the webkit API for this..
- arg.v_pointer = g_value_get_pointer(gval);
+ if (!g_type_info_is_zero_terminated(type_info)
+ && array_type == GI_ARRAY_TYPE_C
+ && GI_TYPE_TAG_UINT8 == g_type_info_get_tag(array_type_info)
+ && array_len > 0) {
+ // got a stringy array..
+ // we should check g_type_info_get_array_fixed_size
+ // we are assuming that this is the array_len from the call..
+ g_base_info_unref((GIBaseInfo*) array_type_info);
- res = seed_value_from_gi_argument (ctx, &arg, &type_info, exception);
+ ret = seed_value_from_binary_string(ctx, arg->v_pointer,
+ array_len, exception);
+ // always free arg... what about when we do not own it...?
+ // g_free(arg->v_pointer);
- g_base_info_unref((GIBaseInfo*)arg_info);
- g_base_info_unref((GIBaseInfo*)signal_info);
- g_base_info_unref((GIBaseInfo*)obj);
+ return ret;
+ }
- return res;
+ if (!g_type_info_is_zero_terminated(type_info)) {
+ g_base_info_unref((GIBaseInfo*) array_type_info);
+ break;
+ }
+
+ ret = seed_gi_make_jsarray(ctx, arg->v_pointer, array_type_info,
+ exception);
+
+ g_base_info_unref((GIBaseInfo*) array_type_info);
+
+ return ret;
}
- else
- {
- return seed_make_pointer (ctx, g_value_get_pointer (gval));
+ case GI_TYPE_TAG_INTERFACE: {
+ GIBaseInfo* interface;
+ GIInfoType interface_type;
+
+ interface = g_type_info_get_interface(type_info);
+ interface_type = g_base_info_get_type(interface);
+
+ if (interface_type == GI_INFO_TYPE_OBJECT
+ || interface_type == GI_INFO_TYPE_INTERFACE) {
+ if (arg->v_pointer == 0) {
+ g_base_info_unref(interface);
+ return JSValueMakeNull(ctx);
+ }
+ g_base_info_unref(interface);
+ return seed_value_from_object(ctx, arg->v_pointer, exception);
+ } else if (interface_type == GI_INFO_TYPE_ENUM) {
+ JSValueRef ret;
+ GITypeTag etype = g_enum_info_get_storage_type(interface);
+
+ // needs GITypeInfo - we are sending it GIBaseInfo
+
+ ret = seed_value_from_gi_argument_full(ctx, arg, type_info,
+ exception, 0, etype);
+ g_base_info_unref(interface);
+ return ret;
+ } else if (interface_type == GI_INFO_TYPE_FLAGS) {
+
+ g_base_info_unref(interface);
+ return seed_value_from_long(ctx, arg->v_long, exception);
+ } else if (interface_type == GI_INFO_TYPE_STRUCT) {
+ JSValueRef strukt;
+
+ strukt = seed_make_struct(ctx, arg->v_pointer, interface);
+ g_base_info_unref(interface);
+
+ return strukt;
+ } else if (interface_type == GI_INFO_TYPE_CALLBACK) {
+ /* FIXME: return values of type callback are not handled yet. */
+ g_base_info_unref(interface);
+ return FALSE;
+ }
+ /* fall through - other types?? */
+ g_base_info_unref(interface);
+ return FALSE;
+ }
+
+ case GI_TYPE_TAG_GLIST: {
+ GITypeInfo* list_type;
+ JSObjectRef ret;
+ GArgument larg;
+ gint i = 0;
+ GList* list = arg->v_pointer;
+
+ ret = JSObjectMakeArray(ctx, 0, NULL, exception);
+ list_type = g_type_info_get_param_type(type_info, 0);
+
+ for (; list != NULL; list = list->next) {
+ JSValueRef ival;
+
+ larg.v_pointer = list->data;
+ ival = (JSValueRef) seed_value_from_gi_argument(ctx, &larg,
+ list_type,
+ exception);
+ if (!ival)
+ ival = JSValueMakeNull(ctx);
+ JSObjectSetPropertyAtIndex(ctx, ret, i, ival, NULL);
+ i++;
+ }
+ return ret;
+ }
+ case GI_TYPE_TAG_GSLIST: {
+ GITypeInfo* list_type;
+ JSObjectRef ret;
+ JSValueRef ival;
+ GArgument larg;
+ guint i = 0;
+ GSList* list = arg->v_pointer;
+
+ ret = JSObjectMakeArray(ctx, 0, NULL, exception);
+ list_type = g_type_info_get_param_type(type_info, 0);
+
+ for (; list != NULL; list = list->next) {
+ larg.v_pointer = list->data;
+ ival = (JSValueRef) seed_value_from_gi_argument(ctx, &larg,
+ list_type,
+ exception);
+ if (!ival)
+ ival = JSValueMakeNull(ctx);
+ JSObjectSetPropertyAtIndex(ctx, ret, i, ival, NULL);
+ i++;
+ }
+ return ret;
+ }
+ case GI_TYPE_TAG_GHASH: {
+ GITypeInfo* key_type;
+ GITypeTag key_type_tag;
+ GITypeInfo* value_type;
+ JSObjectRef ret;
+ GHashTable* hash_table;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ key_type = g_type_info_get_param_type(type_info, 0);
+ key_type_tag = g_type_info_get_tag(key_type);
+
+ if ((key_type_tag != GI_TYPE_TAG_UTF8)
+ && (key_type_tag != GI_TYPE_TAG_FILENAME)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Unable to make object from hash table "
+ "indexed with values of type %s",
+ g_type_tag_to_string(key_type_tag));
+ return JSValueMakeNull(ctx);
+ }
+
+ hash_table = arg->v_pointer;
+ if (!hash_table) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Unable to make hash table indexed with values of type %s",
+ g_type_tag_to_string(key_type_tag));
+ return JSValueMakeNull(ctx);
+ }
+
+ value_type = g_type_info_get_param_type(type_info, 1);
+
+ ret = JSObjectMake(ctx, NULL, NULL);
+
+ g_hash_table_iter_init(&iter, hash_table);
+
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ JSStringRef js_key;
+ GArgument value_arg;
+ JSValueRef value_jsval;
+
+ js_key = JSStringCreateWithUTF8CString((const char*) key);
+
+ value_arg.v_string = value;
+ value_jsval
+ = seed_value_from_gi_argument_full(ctx, &value_arg,
+ value_type, exception, 0,
+ key_type_tag);
+
+ JSObjectSetProperty(ctx, ret, js_key, value_jsval, 0, NULL);
+ }
+
+ return ret;
+ }
+ case GI_TYPE_TAG_ERROR: {
+ JSValueRef ret;
+ seed_make_exception_from_gerror(ctx, &ret,
+ (GError*) arg->v_pointer);
+ return ret;
}
- case G_TYPE_PARAM:
- // Might need to dup and make a boxed.
- return seed_make_pointer (ctx, g_value_get_param (gval));
- }
- if (g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_STRV))
- {
- return seed_value_from_strv(ctx, (GStrv *) g_value_get_boxed (gval), exception);
+ default:
+ return FALSE;
}
+ return 0;
+}
+JSValueRef
+seed_value_from_gvalue_for_signal(JSContextRef ctx,
+ GValue* gval,
+ JSValueRef* exception,
+ GSignalQuery* signal_query,
+ gint arg_n)
+{
+ if (!G_IS_VALUE(gval)) {
+ return false;
+ }
+ switch (G_VALUE_TYPE(gval)) {
+ case G_TYPE_BOOLEAN:
+ return seed_value_from_boolean(ctx, g_value_get_boolean(gval),
+ exception);
+ case G_TYPE_CHAR:
+ return seed_value_from_char(ctx, g_value_get_schar(gval),
+ exception);
+ case G_TYPE_UCHAR:
+ return seed_value_from_uchar(ctx, g_value_get_uchar(gval),
+ exception);
+ case G_TYPE_INT:
+ return seed_value_from_int(ctx, g_value_get_int(gval), exception);
+ case G_TYPE_UINT:
+ return seed_value_from_uint(ctx, g_value_get_uint(gval), exception);
+ case G_TYPE_LONG:
+ return seed_value_from_long(ctx, g_value_get_long(gval), exception);
+ case G_TYPE_ULONG:
+ return seed_value_from_ulong(ctx, g_value_get_ulong(gval),
+ exception);
+ case G_TYPE_INT64:
+ return seed_value_from_int64(ctx, g_value_get_int64(gval),
+ exception);
+ case G_TYPE_UINT64:
+ return seed_value_from_uint64(ctx, g_value_get_uint64(gval),
+ exception);
+ case G_TYPE_FLOAT:
+ return seed_value_from_float(ctx, g_value_get_float(gval),
+ exception);
+ case G_TYPE_DOUBLE:
+ return seed_value_from_double(ctx, g_value_get_double(gval),
+ exception);
+ case G_TYPE_STRING:
+ return seed_value_from_string(ctx,
+ (gchar*) g_value_get_string(gval),
+ exception);
+ case G_TYPE_POINTER:
+ if (signal_query) {
+ JSValueRef res;
+ GArgument arg;
+ GIBaseInfo* obj;
+ GISignalInfo* signal_info;
+ GIArgInfo* arg_info;
+ GITypeInfo type_info;
+
+ obj = g_irepository_find_by_gtype(NULL, signal_query->itype);
+ if (!obj)
+ return NULL;
+
+ signal_info
+ = g_object_info_find_signal((GIObjectInfo*) obj,
+ signal_query->signal_name);
+
+ if (!signal_info) {
+ g_base_info_unref((GIBaseInfo*) obj);
+ return NULL;
+ }
+
+ arg_info = g_callable_info_get_arg(signal_info, arg_n - 1);
+ g_arg_info_load_type(arg_info, &type_info);
+
+ arg.v_pointer = g_value_get_pointer(gval);
+
+ res = seed_value_from_gi_argument(ctx, &arg, &type_info,
+ exception);
+
+ g_base_info_unref((GIBaseInfo*) arg_info);
+ g_base_info_unref((GIBaseInfo*) signal_info);
+ g_base_info_unref((GIBaseInfo*) obj);
+
+ return res;
+ } else {
+ return seed_make_pointer(ctx, g_value_get_pointer(gval));
+ }
+ case G_TYPE_PARAM:
+ // Might need to dup and make a boxed.
+ return seed_make_pointer(ctx, g_value_get_param(gval));
+ }
- if (g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_ENUM) ||
- g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_FLAGS))
- return seed_value_from_long (ctx, gval->data[0].v_long, exception);
- else if (g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_ENUM))
- return seed_value_from_long (ctx, gval->data[0].v_long, exception);
- else if (g_type_is_a (G_VALUE_TYPE (gval), G_TYPE_OBJECT))
- {
- GObject *obj = g_value_get_object (gval);
- return seed_value_from_object (ctx, obj, exception);
+ if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_STRV)) {
+ return seed_value_from_strv(ctx, (GStrv*) g_value_get_boxed(gval),
+ exception);
}
- else
- {
- GIBaseInfo *info;
- GIInfoType type;
-
- info = g_irepository_find_by_gtype (0, G_VALUE_TYPE (gval));
- if (!info)
- return FALSE;
- type = g_base_info_get_type (info);
-
- if (type == GI_INFO_TYPE_UNION)
- {
- return seed_make_union (ctx, g_value_peek_pointer (gval), info);
- }
- else if (type == GI_INFO_TYPE_STRUCT)
- {
- return seed_make_struct (ctx, g_value_peek_pointer (gval), info);
- }
- else if (type == GI_INFO_TYPE_BOXED)
- {
- return seed_make_boxed (ctx, g_value_dup_boxed (gval), info);
- }
+ if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_ENUM)
+ || g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_FLAGS))
+ return seed_value_from_long(ctx, gval->data[0].v_long, exception);
+ else if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_ENUM))
+ return seed_value_from_long(ctx, gval->data[0].v_long, exception);
+ else if (g_type_is_a(G_VALUE_TYPE(gval), G_TYPE_OBJECT)) {
+ GObject* obj = g_value_get_object(gval);
+ return seed_value_from_object(ctx, obj, exception);
+ } else {
+ GIBaseInfo* info;
+ GIInfoType type;
+
+ info = g_irepository_find_by_gtype(0, G_VALUE_TYPE(gval));
+ if (!info)
+ return FALSE;
+ type = g_base_info_get_type(info);
+
+ if (type == GI_INFO_TYPE_UNION) {
+ return seed_make_union(ctx, g_value_peek_pointer(gval), info);
+ } else if (type == GI_INFO_TYPE_STRUCT) {
+ return seed_make_struct(ctx, g_value_peek_pointer(gval), info);
+ } else if (type == GI_INFO_TYPE_BOXED) {
+ return seed_make_boxed(ctx, g_value_dup_boxed(gval), info);
+ }
}
- return NULL;
+ return NULL;
}
JSValueRef
-seed_value_from_gvalue (JSContextRef ctx,
- GValue * gval, JSValueRef * exception)
+seed_value_from_gvalue(JSContextRef ctx, GValue* gval, JSValueRef* exception)
{
- return seed_value_from_gvalue_for_signal(ctx, gval, exception, NULL, 0);
+ return seed_value_from_gvalue_for_signal(ctx, gval, exception, NULL, 0);
}
gboolean
-seed_value_to_gvalue (JSContextRef ctx,
- JSValueRef val,
- GType type, GValue * ret, JSValueRef * exception)
+seed_value_to_gvalue(JSContextRef ctx,
+ JSValueRef val,
+ GType type,
+ GValue* ret,
+ JSValueRef* exception)
{
- if (G_IS_VALUE (ret))
- g_value_unset (ret);
-
- if (type == G_TYPE_STRV)
- {
- gchar **result;
- JSValueRef jslen;
- guint length, i;
-
- if (JSValueIsNull (ctx, val) || !JSValueIsObject (ctx, val))
- return FALSE;
-
- jslen = seed_object_get_property (ctx, (JSObjectRef) val, "length");
- length = seed_value_to_uint (ctx, jslen, exception);
-
- result = g_new0 (gchar *, length+1);
-
- for (i = 0; i < length; i++)
- {
- result[i] = seed_value_to_string (ctx,
- JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- val,
- i,
- exception),
- exception);
-
- }
- result[i] = 0;
-
- g_value_init (ret, G_TYPE_STRV);
- g_value_take_boxed (ret, result);
-
- return TRUE;
- }
- else if (g_type_is_a (type, G_TYPE_ENUM) && JSValueIsNumber (ctx, val))
- {
- g_value_init (ret, type);
- g_value_set_enum (ret, seed_value_to_long (ctx, val, exception));
- return TRUE;
- }
- else if (g_type_is_a (type, G_TYPE_FLAGS) && JSValueIsNumber (ctx, val))
- {
- g_value_init (ret, type);
- g_value_set_flags (ret, seed_value_to_long (ctx, val, exception));
- return TRUE;
- }
- else if (g_type_is_a (type, G_TYPE_OBJECT)
- && (JSValueIsNull (ctx, val) || seed_value_is_gobject (ctx, val)))
- {
- GObject *o = seed_value_to_object (ctx,
- val, exception);
-
- if (o == NULL || g_type_is_a (G_OBJECT_TYPE (o), type))
- {
- g_value_init (ret, type);
- g_value_set_object (ret, o);
-
- return TRUE;
- }
+ if (G_IS_VALUE(ret))
+ g_value_unset(ret);
+
+ if (type == G_TYPE_STRV) {
+ gchar** result;
+ JSValueRef jslen;
+ guint length, i;
+
+ if (JSValueIsNull(ctx, val) || !JSValueIsObject(ctx, val))
+ return FALSE;
+
+ jslen = seed_object_get_property(ctx, (JSObjectRef) val, "length");
+ length = seed_value_to_uint(ctx, jslen, exception);
+
+ result = g_new0(gchar*, length + 1);
+
+ for (i = 0; i < length; i++) {
+ result[i] = seed_value_to_string(
+ ctx,
+ JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) val, i, exception),
+ exception);
+ }
+ result[i] = 0;
+
+ g_value_init(ret, G_TYPE_STRV);
+ g_value_take_boxed(ret, result);
+
+ return TRUE;
+ } else if (g_type_is_a(type, G_TYPE_ENUM) && JSValueIsNumber(ctx, val)) {
+ g_value_init(ret, type);
+ g_value_set_enum(ret, seed_value_to_long(ctx, val, exception));
+ return TRUE;
+ } else if (g_type_is_a(type, G_TYPE_FLAGS) && JSValueIsNumber(ctx, val)) {
+ g_value_init(ret, type);
+ g_value_set_flags(ret, seed_value_to_long(ctx, val, exception));
+ return TRUE;
+ } else if (g_type_is_a(type, G_TYPE_OBJECT)
+ && (JSValueIsNull(ctx, val)
+ || seed_value_is_gobject(ctx, val))) {
+ GObject* o = seed_value_to_object(ctx, val, exception);
+
+ if (o == NULL || g_type_is_a(G_OBJECT_TYPE(o), type)) {
+ g_value_init(ret, type);
+ g_value_set_object(ret, o);
+
+ return TRUE;
+ }
}
- /* Boxed handling is broken. Will be fixed in struct overhall. */
- else if (g_type_is_a (type, G_TYPE_BOXED))
- {
- gpointer p = seed_pointer_get_pointer (ctx, val);
- if (p)
- {
- g_value_init (ret, type);
- g_value_set_boxed (ret, p);
- return TRUE;
- }
- else
- {
- if (JSValueIsObject (ctx, val))
- {
- GIBaseInfo *info = g_irepository_find_by_gtype (0, type);
- JSObjectRef new_struct;
- if (!info)
- return FALSE;
-
- new_struct =
- seed_construct_struct_type_with_parameters (ctx,
- info,
- (JSObjectRef)
- val, exception);
- p = seed_pointer_get_pointer (ctx, new_struct);
- if (p)
- {
- g_value_init (ret, type);
- g_value_set_boxed (ret, p);
- g_base_info_unref (info);
- return TRUE;
- }
- g_base_info_unref (info);
- }
- }
+ /* Boxed handling is broken. Will be fixed in struct overhall. */
+ else if (g_type_is_a(type, G_TYPE_BOXED)) {
+ gpointer p = seed_pointer_get_pointer(ctx, val);
+ if (p) {
+ g_value_init(ret, type);
+ g_value_set_boxed(ret, p);
+ return TRUE;
+ } else {
+ if (JSValueIsObject(ctx, val)) {
+ GIBaseInfo* info = g_irepository_find_by_gtype(0, type);
+ JSObjectRef new_struct;
+ if (!info)
+ return FALSE;
+
+ new_struct = seed_construct_struct_type_with_parameters(
+ ctx, info, (JSObjectRef) val, exception);
+ p = seed_pointer_get_pointer(ctx, new_struct);
+ if (p) {
+ g_value_init(ret, type);
+ g_value_set_boxed(ret, p);
+ g_base_info_unref(info);
+ return TRUE;
+ }
+ g_base_info_unref(info);
+ }
+ }
}
- switch (type)
- {
- case G_TYPE_BOOLEAN:
- {
- g_value_init (ret, G_TYPE_BOOLEAN);
- g_value_set_boolean (ret, seed_value_to_boolean (ctx,
- val, exception));
- return TRUE;
- }
- case G_TYPE_INT:
- case G_TYPE_UINT:
- {
- g_value_init (ret, type);
- if (type == G_TYPE_INT)
- g_value_set_int (ret, seed_value_to_int (ctx, val, exception));
- else
- g_value_set_uint (ret, seed_value_to_uint (ctx, val, exception));
- return TRUE;
- }
- case G_TYPE_CHAR:
- {
- g_value_init (ret, G_TYPE_CHAR);
- g_value_set_schar (ret, seed_value_to_char (ctx, val, exception));
- return TRUE;
- }
- case G_TYPE_UCHAR:
- {
- g_value_init (ret, G_TYPE_UCHAR);
- g_value_set_uchar (ret, seed_value_to_uchar (ctx, val, exception));
- return TRUE;
- }
- case G_TYPE_LONG:
- case G_TYPE_ULONG:
- case G_TYPE_INT64:
- case G_TYPE_UINT64:
- case G_TYPE_FLOAT:
- case G_TYPE_DOUBLE:
- {
- switch (type)
- {
- case G_TYPE_LONG:
- g_value_init (ret, G_TYPE_LONG);
- g_value_set_long (ret, seed_value_to_long (ctx, val, exception));
- break;
- case G_TYPE_ULONG:
- g_value_init (ret, G_TYPE_ULONG);
- g_value_set_ulong (ret, seed_value_to_ulong (ctx,
- val, exception));
- break;
- case G_TYPE_INT64:
- g_value_init (ret, G_TYPE_INT64);
- g_value_set_int64 (ret, seed_value_to_int64 (ctx,
- val, exception));
- break;
- case G_TYPE_UINT64:
- g_value_init (ret, G_TYPE_UINT64);
- g_value_set_uint64 (ret, seed_value_to_uint64 (ctx,
- val, exception));
- break;
- case G_TYPE_FLOAT:
- g_value_init (ret, G_TYPE_FLOAT);
- g_value_set_float (ret, seed_value_to_float (ctx,
- val, exception));
- break;
- case G_TYPE_DOUBLE:
- g_value_init (ret, G_TYPE_DOUBLE);
- g_value_set_double (ret, seed_value_to_double (ctx,
- val, exception));
- break;
- }
- return TRUE;
- }
- case G_TYPE_STRING:
- {
- gchar *cval = seed_value_to_string (ctx, val, exception);
-
- g_value_init (ret, G_TYPE_STRING);
- g_value_take_string (ret, cval);
-
- return TRUE;
- }
- default:
- {
- // TODO: FIXME: This whole undefined type area
- // needs some heaaavy improvement.
-
- if (type == 0 && seed_value_is_gobject(ctx, val))
- {
- GObject *o = seed_value_to_object (ctx, val, exception);
-
- g_value_init (ret, G_OBJECT_TYPE(o));
- g_value_set_object (ret, o);
- return TRUE;
- }
- // Support [GObject.TYPE_INT, 3]
- // TODO: FIXME: Might crash.
- else if (type == 0 && JSValueIsObject (ctx, val))
- {
- // TODO: FIXME: Better array test like the cool one on reddit.
- guint length = seed_value_to_int (ctx,
- seed_object_get_property (ctx,
- (JSObjectRef) val,
- "length"),
- exception);
-
- if (length)
- {
- type =
- seed_value_to_int (ctx,
- JSObjectGetPropertyAtIndex (ctx,
- (JSObjectRef)
- val, 0,
- exception),
- exception);
- val =
- JSObjectGetPropertyAtIndex (ctx, (JSObjectRef) val, 1,
- exception);
- if (type) // Prevents recursion.
- {
- return seed_value_to_gvalue (ctx, val,
- type, ret, exception);
- }
- // TODO: FIXME: Handle better?
- else
- g_assert_not_reached ();
- }
- }
- switch (JSValueGetType (ctx, val))
- {
- case kJSTypeBoolean:
- {
- g_value_init (ret, G_TYPE_BOOLEAN);
- g_value_set_boolean (ret,
- seed_value_to_boolean (ctx,
- val, exception));
- return TRUE;
- }
- case kJSTypeNumber:
- {
- g_value_init (ret, G_TYPE_DOUBLE);
- g_value_set_double (ret,
- seed_value_to_double (ctx, val, exception));
- return TRUE;
- }
- case kJSTypeString:
- {
- gchar *cv = seed_value_to_string (ctx, val,
- exception);
-
- g_value_init (ret, G_TYPE_STRING);
- g_value_take_string (ret, cv);
- return TRUE;
- }
- default:
- break;
- }
- break;
- }
+ switch (type) {
+ case G_TYPE_BOOLEAN: {
+ g_value_init(ret, G_TYPE_BOOLEAN);
+ g_value_set_boolean(ret,
+ seed_value_to_boolean(ctx, val, exception));
+ return TRUE;
+ }
+ case G_TYPE_INT:
+ case G_TYPE_UINT: {
+ g_value_init(ret, type);
+ if (type == G_TYPE_INT)
+ g_value_set_int(ret, seed_value_to_int(ctx, val, exception));
+ else
+ g_value_set_uint(ret, seed_value_to_uint(ctx, val, exception));
+ return TRUE;
+ }
+ case G_TYPE_CHAR: {
+ g_value_init(ret, G_TYPE_CHAR);
+ g_value_set_schar(ret, seed_value_to_char(ctx, val, exception));
+ return TRUE;
+ }
+ case G_TYPE_UCHAR: {
+ g_value_init(ret, G_TYPE_UCHAR);
+ g_value_set_uchar(ret, seed_value_to_uchar(ctx, val, exception));
+ return TRUE;
+ }
+ case G_TYPE_LONG:
+ case G_TYPE_ULONG:
+ case G_TYPE_INT64:
+ case G_TYPE_UINT64:
+ case G_TYPE_FLOAT:
+ case G_TYPE_DOUBLE: {
+ switch (type) {
+ case G_TYPE_LONG:
+ g_value_init(ret, G_TYPE_LONG);
+ g_value_set_long(ret,
+ seed_value_to_long(ctx, val, exception));
+ break;
+ case G_TYPE_ULONG:
+ g_value_init(ret, G_TYPE_ULONG);
+ g_value_set_ulong(ret,
+ seed_value_to_ulong(ctx, val, exception));
+ break;
+ case G_TYPE_INT64:
+ g_value_init(ret, G_TYPE_INT64);
+ g_value_set_int64(ret,
+ seed_value_to_int64(ctx, val, exception));
+ break;
+ case G_TYPE_UINT64:
+ g_value_init(ret, G_TYPE_UINT64);
+ g_value_set_uint64(ret, seed_value_to_uint64(ctx, val,
+ exception));
+ break;
+ case G_TYPE_FLOAT:
+ g_value_init(ret, G_TYPE_FLOAT);
+ g_value_set_float(ret,
+ seed_value_to_float(ctx, val, exception));
+ break;
+ case G_TYPE_DOUBLE:
+ g_value_init(ret, G_TYPE_DOUBLE);
+ g_value_set_double(ret, seed_value_to_double(ctx, val,
+ exception));
+ break;
+ }
+ return TRUE;
+ }
+ case G_TYPE_STRING: {
+ gchar* cval = seed_value_to_string(ctx, val, exception);
+
+ g_value_init(ret, G_TYPE_STRING);
+ g_value_take_string(ret, cval);
+
+ return TRUE;
+ }
+ default: {
+ // TODO: FIXME: This whole undefined type area
+ // needs some heaaavy improvement.
+
+ if (type == 0 && seed_value_is_gobject(ctx, val)) {
+ GObject* o = seed_value_to_object(ctx, val, exception);
+
+ g_value_init(ret, G_OBJECT_TYPE(o));
+ g_value_set_object(ret, o);
+ return TRUE;
+ }
+ // Support [GObject.TYPE_INT, 3]
+ // TODO: FIXME: Might crash.
+ else if (type == 0 && JSValueIsObject(ctx, val)) {
+ // TODO: FIXME: Better array test like the cool one on reddit.
+ guint length = seed_value_to_int(
+ ctx,
+ seed_object_get_property(ctx, (JSObjectRef) val, "length"),
+ exception);
+
+ if (length) {
+ type = seed_value_to_int(
+ ctx, JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) val, 0,
+ exception),
+ exception);
+ val = JSObjectGetPropertyAtIndex(ctx, (JSObjectRef) val, 1,
+ exception);
+ if (type) // Prevents recursion.
+ {
+ return seed_value_to_gvalue(ctx, val, type, ret,
+ exception);
+ }
+ // TODO: FIXME: Handle better?
+ else
+ g_assert_not_reached();
+ }
+ }
+ switch (JSValueGetType(ctx, val)) {
+ case kJSTypeBoolean: {
+ g_value_init(ret, G_TYPE_BOOLEAN);
+ g_value_set_boolean(ret, seed_value_to_boolean(ctx, val,
+ exception));
+ return TRUE;
+ }
+ case kJSTypeNumber: {
+ g_value_init(ret, G_TYPE_DOUBLE);
+ g_value_set_double(ret, seed_value_to_double(ctx, val,
+ exception));
+ return TRUE;
+ }
+ case kJSTypeString: {
+ gchar* cv = seed_value_to_string(ctx, val, exception);
+
+ g_value_init(ret, G_TYPE_STRING);
+ g_value_take_string(ret, cv);
+ return TRUE;
+ }
+ default:
+ break;
+ }
+ break;
+ }
}
- return FALSE;
+ return FALSE;
}
/**
@@ -1726,18 +1530,15 @@ seed_value_to_gvalue (JSContextRef ctx,
* Returns: The value of the property or the undefined value
*/
JSValueRef
-seed_object_get_property (JSContextRef ctx,
- JSObjectRef val, const gchar * name)
+seed_object_get_property(JSContextRef ctx, JSObjectRef val, const gchar* name)
{
- JSStringRef jname = JSStringCreateWithUTF8CString (name);
- JSValueRef ret = JSObjectGetProperty (ctx,
- (JSObjectRef) val,
- jname, NULL);
+ JSStringRef jname = JSStringCreateWithUTF8CString(name);
+ JSValueRef ret = JSObjectGetProperty(ctx, (JSObjectRef) val, jname, NULL);
- JSStringRelease (jname);
+ JSStringRelease(jname);
- return ret;
+ return ret;
}
/**
@@ -1750,21 +1551,22 @@ seed_object_get_property (JSContextRef ctx,
* Returns: %TRUE on success, %FALSE otherwise.
*/
gboolean
-seed_object_set_property (JSContextRef ctx, JSObjectRef object,
- const gchar * name, JSValueRef value)
+seed_object_set_property(JSContextRef ctx,
+ JSObjectRef object,
+ const gchar* name,
+ JSValueRef value)
{
- JSStringRef jname = JSStringCreateWithUTF8CString (name);
- JSValueRef exception = NULL;
+ JSStringRef jname = JSStringCreateWithUTF8CString(name);
+ JSValueRef exception = NULL;
- if (value)
- {
- JSObjectSetProperty (ctx, (JSObjectRef) object, jname, value, 0,
- &exception);
+ if (value) {
+ JSObjectSetProperty(ctx, (JSObjectRef) object, jname, value, 0,
+ &exception);
}
- JSStringRelease (jname);
+ JSStringRelease(jname);
- return TRUE;
+ return TRUE;
}
/* TODO: Make some macros or something for making exceptions, code is littered
@@ -1784,22 +1586,19 @@ seed_object_set_property (JSContextRef ctx, JSObjectRef object,
*
*/
gboolean
-seed_value_to_boolean (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+seed_value_to_boolean(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsBoolean (ctx, val) && !JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- {
- seed_make_exception (eng->context, exception, "ConversionError",
- "Can not convert Javascript value to boolean");
- return FALSE;
- }
-
- return FALSE;
+ if (!JSValueIsBoolean(ctx, val) && !JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val)) {
+ seed_make_exception(eng->context, exception, "ConversionError",
+ "Can not convert Javascript value to boolean");
+ return FALSE;
+ }
+
+ return FALSE;
}
- return JSValueToBoolean (ctx, val);
+ return JSValueToBoolean(ctx, val);
}
/**
@@ -1815,10 +1614,9 @@ seed_value_to_boolean (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_boolean (JSContextRef ctx,
- gboolean val, JSValueRef * exception)
+seed_value_from_boolean(JSContextRef ctx, gboolean val, JSValueRef* exception)
{
- return JSValueMakeBoolean (ctx, val);
+ return JSValueMakeBoolean(ctx, val);
}
/**
@@ -1834,20 +1632,18 @@ seed_value_from_boolean (JSContextRef ctx,
*
*/
guint
-seed_value_to_uint (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_uint(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- {
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to"
- " boolean");
- }
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val)) {
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " boolean");
+ }
+ return 0;
}
- return (guint) JSValueToNumber (ctx, val, NULL);
+ return (guint) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -1863,9 +1659,9 @@ seed_value_to_uint (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_uint (JSContextRef ctx, guint val, JSValueRef * exception)
+seed_value_from_uint(JSContextRef ctx, guint val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -1881,17 +1677,17 @@ seed_value_from_uint (JSContextRef ctx, guint val, JSValueRef * exception)
*
*/
gint
-seed_value_to_int (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_int(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " int");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " int");
+ return 0;
}
- return (gint) JSValueToNumber (ctx, val, NULL);
+ return (gint) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -1907,9 +1703,9 @@ seed_value_to_int (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_int (JSContextRef ctx, gint val, JSValueRef * exception)
+seed_value_from_int(JSContextRef ctx, gint val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -1925,28 +1721,27 @@ seed_value_from_int (JSContextRef ctx, gint val, JSValueRef * exception)
*
*/
gchar
-seed_value_to_char (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_char(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- gint cv;
-
- if (!JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " gchar");
- return 0;
+ gint cv;
+
+ if (!JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " gchar");
+ return 0;
}
- cv = JSValueToNumber (ctx, val, NULL);
+ cv = JSValueToNumber(ctx, val, NULL);
- if (cv < G_MININT8 || cv > G_MAXINT8)
- {
- seed_make_exception (ctx, exception, "ConversionError",
- "Javascript number out of range of gchar");
- return 0;
+ if (cv < G_MININT8 || cv > G_MAXINT8) {
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Javascript number out of range of gchar");
+ return 0;
}
- return (gchar) cv;
+ return (gchar) cv;
}
/**
@@ -1962,9 +1757,9 @@ seed_value_to_char (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_char (JSContextRef ctx, gchar val, JSValueRef * exception)
+seed_value_from_char(JSContextRef ctx, gchar val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -1980,28 +1775,27 @@ seed_value_from_char (JSContextRef ctx, gchar val, JSValueRef * exception)
*
*/
guchar
-seed_value_to_uchar (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_uchar(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- guint cv;
-
- if (!JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " guchar");
- return 0;
+ guint cv;
+
+ if (!JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " guchar");
+ return 0;
}
- cv = JSValueToNumber (ctx, val, NULL);
+ cv = JSValueToNumber(ctx, val, NULL);
- if (cv > G_MAXUINT8)
- {
- seed_make_exception (ctx, exception, "ConversionError",
- "Javascript number out of range of guchar");
- return 0;
+ if (cv > G_MAXUINT8) {
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Javascript number out of range of guchar");
+ return 0;
}
- return (guchar) cv;
+ return (guchar) cv;
}
/**
@@ -2017,9 +1811,9 @@ seed_value_to_uchar (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_uchar (JSContextRef ctx, guchar val, JSValueRef * exception)
+seed_value_from_uchar(JSContextRef ctx, guchar val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2035,17 +1829,17 @@ seed_value_from_uchar (JSContextRef ctx, guchar val, JSValueRef * exception)
*
*/
gshort
-seed_value_to_short (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_short(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " short");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " short");
+ return 0;
}
- return (gshort) JSValueToNumber (ctx, val, NULL);
+ return (gshort) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2061,9 +1855,9 @@ seed_value_to_short (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_short (JSContextRef ctx, gshort val, JSValueRef * exception)
+seed_value_from_short(JSContextRef ctx, gshort val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2079,18 +1873,17 @@ seed_value_from_short (JSContextRef ctx, gshort val, JSValueRef * exception)
*
*/
gushort
-seed_value_to_ushort (JSContextRef ctx, JSValueRef val,
- JSValueRef * exception)
+seed_value_to_ushort(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " ushort");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " ushort");
+ return 0;
}
- return (gushort) JSValueToNumber (ctx, val, NULL);
+ return (gushort) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2106,9 +1899,9 @@ seed_value_to_ushort (JSContextRef ctx, JSValueRef val,
*
*/
JSValueRef
-seed_value_from_ushort (JSContextRef ctx, gushort val, JSValueRef * exception)
+seed_value_from_ushort(JSContextRef ctx, gushort val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2124,35 +1917,35 @@ seed_value_from_ushort (JSContextRef ctx, gushort val, JSValueRef * exception)
*
*/
glong
-seed_value_to_long (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_long(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " long");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " long");
+ return 0;
}
- return (glong) JSValueToNumber (ctx, val, NULL);
+ return (glong) JSValueToNumber(ctx, val, NULL);
}
- /**
- * seed_value_from_long:
- * @ctx: A #SeedContext.
- * @val: The #glong to represent.
- * @exception: A reference to a #SeedValue in which to store any exceptions.
- * Pass %NULL to ignore exceptions.
- *
- * Converts the given #glong into a #SeedValue.
- *
- * Return value: A #SeedValue which represents @val.
- *
- */
+/**
+* seed_value_from_long:
+* @ctx: A #SeedContext.
+* @val: The #glong to represent.
+* @exception: A reference to a #SeedValue in which to store any exceptions.
+* Pass %NULL to ignore exceptions.
+*
+* Converts the given #glong into a #SeedValue.
+*
+* Return value: A #SeedValue which represents @val.
+*
+*/
JSValueRef
-seed_value_from_long (JSContextRef ctx, glong val, JSValueRef * exception)
+seed_value_from_long(JSContextRef ctx, glong val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2168,18 +1961,18 @@ seed_value_from_long (JSContextRef ctx, glong val, JSValueRef * exception)
*
*/
gulong
-seed_value_to_ulong (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_ulong(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " ulong");
+ if (!JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " ulong");
- return 0;
+ return 0;
}
- return (gulong) JSValueToNumber (ctx, val, NULL);
+ return (gulong) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2195,9 +1988,9 @@ seed_value_to_ulong (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_ulong (JSContextRef ctx, gulong val, JSValueRef * exception)
+seed_value_from_ulong(JSContextRef ctx, gulong val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2213,18 +2006,18 @@ seed_value_from_ulong (JSContextRef ctx, gulong val, JSValueRef * exception)
*
*/
gint64
-seed_value_to_int64 (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_int64(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " gint64");
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " gint64");
- return 0;
+ return 0;
}
- return (gint64) JSValueToNumber (ctx, val, NULL);
+ return (gint64) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2240,9 +2033,9 @@ seed_value_to_int64 (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_int64 (JSContextRef ctx, gint64 val, JSValueRef * exception)
+seed_value_from_int64(JSContextRef ctx, gint64 val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2258,20 +2051,18 @@ seed_value_from_int64 (JSContextRef ctx, gint64 val, JSValueRef * exception)
*
*/
guint64
-seed_value_to_uint64 (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+seed_value_to_uint64(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to"
- " guint64");
-
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " guint64");
+
+ return 0;
}
- return (guint64) JSValueToNumber (ctx, val, NULL);
+ return (guint64) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2287,9 +2078,9 @@ seed_value_to_uint64 (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_uint64 (JSContextRef ctx, guint64 val, JSValueRef * exception)
+seed_value_from_uint64(JSContextRef ctx, guint64 val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2305,17 +2096,17 @@ seed_value_from_uint64 (JSContextRef ctx, guint64 val, JSValueRef * exception)
*
*/
gfloat
-seed_value_to_float (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_float(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " gfloat");
- return 0;
+ if (!JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " gfloat");
+ return 0;
}
- return (gfloat) JSValueToNumber (ctx, val, NULL);
+ return (gfloat) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2331,9 +2122,9 @@ seed_value_to_float (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_float (JSContextRef ctx, gfloat val, JSValueRef * exception)
+seed_value_from_float(JSContextRef ctx, gfloat val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2349,18 +2140,17 @@ seed_value_from_float (JSContextRef ctx, gfloat val, JSValueRef * exception)
*
*/
gdouble
-seed_value_to_double (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+seed_value_to_double(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " double");
- return 0;
+ if (!JSValueIsNumber(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " double");
+ return 0;
}
- return (gdouble) JSValueToNumber (ctx, val, NULL);
+ return (gdouble) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2376,9 +2166,9 @@ seed_value_to_double (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_double (JSContextRef ctx, gdouble val, JSValueRef * exception)
+seed_value_from_double(JSContextRef ctx, gdouble val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2394,17 +2184,17 @@ seed_value_from_double (JSContextRef ctx, gdouble val, JSValueRef * exception)
*
*/
gsize
-seed_value_to_size (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_size(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " gsize");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " gsize");
+ return 0;
}
- return (gsize) JSValueToNumber (ctx, val, NULL);
+ return (gsize) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2420,9 +2210,9 @@ seed_value_to_size (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_size (JSContextRef ctx, gsize val, JSValueRef * exception)
+seed_value_from_size(JSContextRef ctx, gsize val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2438,17 +2228,17 @@ seed_value_from_size (JSContextRef ctx, gsize val, JSValueRef * exception)
*
*/
gssize
-seed_value_to_ssize (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
+seed_value_to_ssize(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- if (!JSValueIsNumber (ctx, val) && !JSValueIsBoolean (ctx, val))
- {
- if (!JSValueIsNull (ctx, val))
- seed_make_exception (ctx, exception, "ConversionError",
- "Can not convert Javascript value to" " gssize");
- return 0;
+ if (!JSValueIsNumber(ctx, val) && !JSValueIsBoolean(ctx, val)) {
+ if (!JSValueIsNull(ctx, val))
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Can not convert Javascript value to"
+ " gssize");
+ return 0;
}
- return (gssize) JSValueToNumber (ctx, val, NULL);
+ return (gssize) JSValueToNumber(ctx, val, NULL);
}
/**
@@ -2464,9 +2254,9 @@ seed_value_to_ssize (JSContextRef ctx, JSValueRef val, JSValueRef * exception)
*
*/
JSValueRef
-seed_value_from_ssize (JSContextRef ctx, gssize val, JSValueRef * exception)
+seed_value_from_ssize(JSContextRef ctx, gssize val, JSValueRef* exception)
{
- return JSValueMakeNumber (ctx, (gdouble) val);
+ return JSValueMakeNumber(ctx, (gdouble) val);
}
/**
@@ -2483,7 +2273,7 @@ seed_value_from_ssize (JSContextRef ctx, gssize val, JSValueRef * exception)
* "[undefined]"; if it represents JavaScript's null value, this returns
* "[null]".
*
- * If the #SeedValue is a number or a boolean, it is printed as a double, with
+ * If the #SeedValue is a number or a boolean, it is printed as a double, with
* the printf format string "%.15g".
*
* If the #SeedValue is an object, the string returned is that obtained by
@@ -2492,57 +2282,46 @@ seed_value_from_ssize (JSContextRef ctx, gssize val, JSValueRef * exception)
* Return value: The #gchar* represented by @val.
*
*/
-gchar *
-seed_value_to_string (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+gchar*
+seed_value_to_string(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- JSStringRef jsstr = NULL;
- JSValueRef func;
- gchar *buf = NULL;
- gint length;
+ JSStringRef jsstr = NULL;
+ JSValueRef func;
+ gchar* buf = NULL;
+ gint length;
+
+ if (val == NULL)
+ return NULL;
+ else if (JSValueIsUndefined(ctx, val)) {
+ buf = g_strdup("[undefined]");
+ } else if (JSValueIsNull(ctx, val)) {
+ buf = g_strdup("[null]");
+ } else if (JSValueIsBoolean(ctx, val) || JSValueIsNumber(ctx, val)) {
+ buf = g_strdup_printf("%.15g", JSValueToNumber(ctx, val, NULL));
+ } else {
+ if (!JSValueIsString(ctx, val)) // In this case,
+ // it's an object
+ {
+ func = seed_object_get_property(ctx, (JSObjectRef) val, "toString");
- if (val == NULL)
- return NULL;
- else if (JSValueIsUndefined (ctx, val))
- {
- buf = g_strdup ("[undefined]");
- }
- else if (JSValueIsNull (ctx, val))
- {
- buf = g_strdup ("[null]");
- }
- else if (JSValueIsBoolean (ctx, val) || JSValueIsNumber (ctx, val))
- {
- buf = g_strdup_printf ("%.15g", JSValueToNumber (ctx, val, NULL));
- }
- else
- {
- if (!JSValueIsString (ctx, val)) // In this case,
- // it's an object
- {
- func =
- seed_object_get_property (ctx, (JSObjectRef) val, "toString");
-
- if (!JSValueIsNull (ctx, func) &&
- JSValueIsObject (ctx, func) &&
- JSObjectIsFunction (ctx, (JSObjectRef) func))
- //str = ... we dump the return value!?!
- JSObjectCallAsFunction (ctx, (JSObjectRef) func,
- (JSObjectRef) val, 0, NULL, NULL);
- }
-
- jsstr = JSValueToStringCopy (ctx, val, NULL);
- length = JSStringGetMaximumUTF8CStringSize (jsstr);
- if (length > 0)
- {
- buf = g_malloc (length * sizeof (gchar));
- JSStringGetUTF8CString (jsstr, buf, length);
- }
- if (jsstr)
- JSStringRelease (jsstr);
+ if (!JSValueIsNull(ctx, func) && JSValueIsObject(ctx, func)
+ && JSObjectIsFunction(ctx, (JSObjectRef) func))
+ // str = ... we dump the return value!?!
+ JSObjectCallAsFunction(ctx, (JSObjectRef) func,
+ (JSObjectRef) val, 0, NULL, NULL);
+ }
+
+ jsstr = JSValueToStringCopy(ctx, val, NULL);
+ length = JSStringGetMaximumUTF8CStringSize(jsstr);
+ if (length > 0) {
+ buf = g_malloc(length * sizeof(gchar));
+ JSStringGetUTF8CString(jsstr, buf, length);
+ }
+ if (jsstr)
+ JSStringRelease(jsstr);
}
- return buf;
+ return buf;
}
/**
@@ -2558,18 +2337,18 @@ seed_value_to_string (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_string (JSContextRef ctx,
- const gchar * val, JSValueRef * exception)
+seed_value_from_string(JSContextRef ctx,
+ const gchar* val,
+ JSValueRef* exception)
{
- if (val == NULL)
- return JSValueMakeNull (ctx);
- else
- {
- JSStringRef jsstr = JSStringCreateWithUTF8CString (val);
- JSValueRef valstr = JSValueMakeString (ctx, jsstr);
- JSStringRelease (jsstr);
-
- return valstr;
+ if (val == NULL)
+ return JSValueMakeNull(ctx);
+ else {
+ JSStringRef jsstr = JSStringCreateWithUTF8CString(val);
+ JSValueRef valstr = JSValueMakeString(ctx, jsstr);
+ JSStringRelease(jsstr);
+
+ return valstr;
}
}
@@ -2590,37 +2369,34 @@ seed_value_from_string (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_binary_string (JSContextRef ctx,
- const gchar * bytes,
- gint n_bytes, JSValueRef * exception)
+seed_value_from_binary_string(JSContextRef ctx,
+ const gchar* bytes,
+ gint n_bytes,
+ JSValueRef* exception)
{
- JSStringRef jsstr;
- JSValueRef valstr;
- JSChar* jchar;
- gint i;
-
- SEED_NOTE (INVOCATION, "Creating binary string of length %d ",
- n_bytes);
-
- if (bytes == NULL)
- {
- return JSValueMakeNull (ctx);
+ JSStringRef jsstr;
+ JSValueRef valstr;
+ JSChar* jchar;
+ gint i;
+
+ SEED_NOTE(INVOCATION, "Creating binary string of length %d ", n_bytes);
+
+ if (bytes == NULL) {
+ return JSValueMakeNull(ctx);
}
-
- jchar = g_new0(JSChar, n_bytes);
- for(i =0;i < n_bytes; i++)
- {
- jchar[i] = bytes[i];
+
+ jchar = g_new0(JSChar, n_bytes);
+ for (i = 0; i < n_bytes; i++) {
+ jchar[i] = bytes[i];
}
- // this may leak...
-
- jsstr = JSStringCreateWithCharacters((const JSChar*)jchar, n_bytes);
- valstr = JSValueMakeString (ctx, jsstr);
- g_free(jchar);
- JSStringRelease (jsstr);
-
- return valstr;
-
+ // this may leak...
+
+ jsstr = JSStringCreateWithCharacters((const JSChar*) jchar, n_bytes);
+ valstr = JSValueMakeString(ctx, jsstr);
+ g_free(jchar);
+ JSStringRelease(jsstr);
+
+ return valstr;
}
/**
@@ -2630,31 +2406,29 @@ seed_value_from_binary_string (JSContextRef ctx,
* @exception: A reference to a #SeedValue in which to store any exceptions.
* Pass %NULL to ignore exceptions.
*
- * Converts the given #SeedValue into a #gchar*, properly converting to the
+ * Converts the given #SeedValue into a #gchar*, properly converting to the
* character set used for filenames on the local machine.
*
* Return value: The #gchar* represented by @val, or %NULL if an exception
* is raised during the conversion.
*
*/
-gchar *
-seed_value_to_filename (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+gchar*
+seed_value_to_filename(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- GError *e = NULL;
- gchar *utf8 = seed_value_to_string (ctx, val, exception);
- gchar *filename;
-
- filename = g_filename_from_utf8 (utf8, -1, NULL, NULL, &e);
- g_free (utf8);
- if (e)
- {
- seed_make_exception_from_gerror (ctx, exception, e);
- g_error_free (e);
- return NULL;
+ GError* e = NULL;
+ gchar* utf8 = seed_value_to_string(ctx, val, exception);
+ gchar* filename;
+
+ filename = g_filename_from_utf8(utf8, -1, NULL, NULL, &e);
+ g_free(utf8);
+ if (e) {
+ seed_make_exception_from_gerror(ctx, exception, e);
+ g_error_free(e);
+ return NULL;
}
- return filename;
+ return filename;
}
/**
@@ -2664,37 +2438,36 @@ seed_value_to_filename (JSContextRef ctx,
* @exception: A reference to a #SeedValue in which to store any exceptions.
* Pass %NULL to ignore exceptions.
*
- * Converts the given #gchar* filename into a #SeedValue, respecting the
+ * Converts the given #gchar* filename into a #SeedValue, respecting the
* character set used for filenames on the local machine.
*
* Return value: A #SeedValue which represents @val.
*
*/
JSValueRef
-seed_value_from_filename (JSContextRef ctx,
- const gchar * val, JSValueRef * exception)
+seed_value_from_filename(JSContextRef ctx,
+ const gchar* val,
+ JSValueRef* exception)
{
- GError *e = NULL;
- gchar *utf8;
-
- if (val == NULL)
- return JSValueMakeNull (ctx);
- else
- {
- utf8 = g_filename_to_utf8 (val, -1, NULL, NULL, &e);
-
- if (e)
- {
- seed_make_exception_from_gerror (ctx, exception, e);
- g_error_free (e);
- return JSValueMakeNull (ctx);
+ GError* e = NULL;
+ gchar* utf8;
+
+ if (val == NULL)
+ return JSValueMakeNull(ctx);
+ else {
+ utf8 = g_filename_to_utf8(val, -1, NULL, NULL, &e);
+
+ if (e) {
+ seed_make_exception_from_gerror(ctx, exception, e);
+ g_error_free(e);
+ return JSValueMakeNull(ctx);
}
- JSValueRef valstr = seed_value_from_string (ctx, utf8, exception);
+ JSValueRef valstr = seed_value_from_string(ctx, utf8, exception);
- g_free (utf8);
+ g_free(utf8);
- return valstr;
+ return valstr;
}
}
@@ -2712,33 +2485,31 @@ seed_value_from_filename (JSContextRef ctx,
* is raised during the conversion.
*
*/
-GObject *
-seed_value_to_object (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception)
+GObject*
+seed_value_to_object(JSContextRef ctx, JSValueRef val, JSValueRef* exception)
{
- GObject *gobject;
-
- /*
- * Worth investigating if this is the best way to handle null. Some of
- * the existing code depends on null Objects not throwing an exception
- * however, needs testing at higher level if value can be null
- * (through GI)
- */
-
- if (JSValueIsNull (ctx, val))
- return NULL;
- if (!seed_value_is_gobject (ctx, val))
- {
- seed_make_exception (ctx, exception, "ConversionError",
- "Attempt to convert from"
- " non GObject to GObject");
- return NULL;
+ GObject* gobject;
+
+ /*
+ * Worth investigating if this is the best way to handle null. Some of
+ * the existing code depends on null Objects not throwing an exception
+ * however, needs testing at higher level if value can be null
+ * (through GI)
+ */
+
+ if (JSValueIsNull(ctx, val))
+ return NULL;
+ if (!seed_value_is_gobject(ctx, val)) {
+ seed_make_exception(ctx, exception, "ConversionError",
+ "Attempt to convert from"
+ " non GObject to GObject");
+ return NULL;
}
- gobject = (GObject *) JSObjectGetPrivate ((JSObjectRef) val);
- g_assert (G_IS_OBJECT (gobject));
+ gobject = (GObject*) JSObjectGetPrivate((JSObjectRef) val);
+ g_assert(G_IS_OBJECT(gobject));
- return gobject;
+ return gobject;
}
/**
@@ -2754,80 +2525,71 @@ seed_value_to_object (JSContextRef ctx,
*
*/
JSValueRef
-seed_value_from_object (JSContextRef ctx,
- GObject * val, JSValueRef * exception)
+seed_value_from_object(JSContextRef ctx, GObject* val, JSValueRef* exception)
{
- if (val == NULL)
- return JSValueMakeNull (ctx);
- else
- return seed_wrap_object (ctx, val);
+ if (val == NULL)
+ return JSValueMakeNull(ctx);
+ else
+ return seed_wrap_object(ctx, val);
}
gboolean
-seed_validate_enum (GIEnumInfo * info, long val)
+seed_validate_enum(GIEnumInfo* info, long val)
{
- gint n, i;
- GIValueInfo *value_info;
- gint value; // TODO: investigate glong/gint mismatch w/ g_value_info_get_value
-
- n = g_enum_info_get_n_values (info);
- for (i = 0; i < n; i++)
- {
- value_info = g_enum_info_get_value (info, i);
- value = g_value_info_get_value (value_info);
-
- g_base_info_unref ((GIBaseInfo *) value_info);
- if (value == val)
- return TRUE;
+ gint n, i;
+ GIValueInfo* value_info;
+ gint
+ value; // TODO: investigate glong/gint mismatch w/ g_value_info_get_value
+
+ n = g_enum_info_get_n_values(info);
+ for (i = 0; i < n; i++) {
+ value_info = g_enum_info_get_value(info, i);
+ value = g_value_info_get_value(value_info);
+
+ g_base_info_unref((GIBaseInfo*) value_info);
+ if (value == val)
+ return TRUE;
}
- return FALSE;
+ return FALSE;
}
JSValueRef
-seed_value_from_time_t (JSContextRef ctx, time_t time, JSValueRef * exception)
+seed_value_from_time_t(JSContextRef ctx, time_t time, JSValueRef* exception)
{
- JSValueRef args[1];
+ JSValueRef args[1];
- args[0] = seed_value_from_double (ctx, ((gdouble) time) * 1000, exception);
- return JSObjectMakeDate (ctx, 1, args, exception);
+ args[0] = seed_value_from_double(ctx, ((gdouble) time) * 1000, exception);
+ return JSObjectMakeDate(ctx, 1, args, exception);
}
time_t
-seed_value_to_time_t (JSContextRef ctx,
- JSValueRef value, JSValueRef * exception)
+seed_value_to_time_t(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
{
- JSValueRef get_time_method;
- JSValueRef jstime;
- gdouble time;
-
-
- if (JSValueIsNumber (ctx, value))
- {
- return (unsigned long) seed_value_to_long (ctx, value, exception);
- }
- else if (JSValueIsObject (ctx, value))
- {
- get_time_method = seed_object_get_property (ctx, (JSObjectRef) value,
- "getTime");
- if (JSValueIsNull (ctx, get_time_method) ||
- !JSValueIsObject (ctx, get_time_method))
- {
- goto out;
- }
- jstime = JSObjectCallAsFunction (ctx,
- (JSObjectRef) get_time_method,
- (JSObjectRef) value,
- 0, NULL, exception);
- time = seed_value_to_double (ctx, jstime, exception);
- return (unsigned long) (time / 1000);
+ JSValueRef get_time_method;
+ JSValueRef jstime;
+ gdouble time;
+
+ if (JSValueIsNumber(ctx, value)) {
+ return (unsigned long) seed_value_to_long(ctx, value, exception);
+ } else if (JSValueIsObject(ctx, value)) {
+ get_time_method
+ = seed_object_get_property(ctx, (JSObjectRef) value, "getTime");
+ if (JSValueIsNull(ctx, get_time_method)
+ || !JSValueIsObject(ctx, get_time_method)) {
+ goto out;
+ }
+ jstime
+ = JSObjectCallAsFunction(ctx, (JSObjectRef) get_time_method,
+ (JSObjectRef) value, 0, NULL, exception);
+ time = seed_value_to_double(ctx, jstime, exception);
+ return (unsigned long) (time / 1000);
}
out:
- seed_make_exception (ctx, exception,
- "TypeError",
- "Unable to convert JavaScript value to time_t");
- return 0;
+ seed_make_exception(ctx, exception, "TypeError",
+ "Unable to convert JavaScript value to time_t");
+ return 0;
}
/**
@@ -2843,20 +2605,18 @@ out:
*
*/
JSValueRef
-seed_value_from_strv (JSContextRef ctx,
- GStrv * val, JSValueRef * exception)
+seed_value_from_strv(JSContextRef ctx, GStrv* val, JSValueRef* exception)
{
- GArray *js_string_array = g_array_new (FALSE, FALSE, sizeof(gpointer));
- for (; *val != NULL; val++)
- {
- JSValueRef js_string = seed_value_from_string (ctx, (char *)*val, exception);
- js_string_array = g_array_append_val(js_string_array, js_string);
- }
- JSValueRef res = JSObjectMakeArray (ctx,
- js_string_array->len,
- (JSValueRef*)js_string_array->data,
- exception);
- g_array_free (js_string_array, FALSE);
-
- return res;
+ GArray* js_string_array = g_array_new(FALSE, FALSE, sizeof(gpointer));
+ for (; *val != NULL; val++) {
+ JSValueRef js_string
+ = seed_value_from_string(ctx, (char*) *val, exception);
+ js_string_array = g_array_append_val(js_string_array, js_string);
+ }
+ JSValueRef res
+ = JSObjectMakeArray(ctx, js_string_array->len,
+ (JSValueRef*) js_string_array->data, exception);
+ g_array_free(js_string_array, FALSE);
+
+ return res;
}
diff --git a/libseed/seed-types.h b/libseed/seed-types.h
index bb76c5c..29be0cf 100644
--- a/libseed/seed-types.h
+++ b/libseed/seed-types.h
@@ -24,147 +24,190 @@
extern GQuark js_ref_quark;
-JSValueRef seed_value_from_gvalue (JSContextRef ctx,
- GValue * gval, JSValueRef * exception);
-
-JSValueRef seed_value_from_gvalue_for_signal (JSContextRef ctx,
- GValue * gval, JSValueRef * exception,
- GSignalQuery *signal_query, gint arg_n);
-
-gboolean seed_value_to_gvalue (JSContextRef ctx,
- JSValueRef val, GType type,
- GValue * gval, JSValueRef * exception);
-
-JSValueRef seed_object_get_property (JSContextRef ctx,
- JSObjectRef val, const gchar * name);
-
-gboolean seed_object_set_property (JSContextRef ctx, JSObjectRef object,
- const gchar * name, JSValueRef value);
-
-gboolean seed_value_to_gi_argument (JSContextRef ctx,
- JSValueRef value,
- GITypeInfo * type_info,
- GITransfer transfer,
- GArgument * arg, JSValueRef * exception);
-
-JSValueRef seed_value_from_gi_argument (JSContextRef ctx,
- GArgument * arg,
- GITypeInfo * type_info,
- JSValueRef * exception);
-
-JSValueRef seed_value_from_gi_argument_full (JSContextRef ctx,
- GArgument * arg,
- GITypeInfo * type_info,
- JSValueRef * exception,
- guint64 array_len,
- GITypeTag gi_tag);
-gboolean seed_gi_release_arg (GITransfer transfer,
- GITypeInfo * type_info, GArgument * arg);
-
-gboolean seed_gi_release_in_arg (GITransfer transfer,
- GITypeInfo * type_info, GArgument * arg);
-
-gboolean seed_value_to_boolean (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-
-JSValueRef seed_value_from_boolean (JSContextRef ctx,
- gboolean val, JSValueRef * exception);
-
-guint seed_value_to_uint (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-
-JSValueRef seed_value_from_uint (JSContextRef ctx,
- guint val, JSValueRef * exception);
-
-gint seed_value_to_int (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-
-JSValueRef seed_value_from_int (JSContextRef ctx,
- gint val, JSValueRef * exception);
-
-gchar seed_value_to_char (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_char (JSContextRef ctx,
- gchar val, JSValueRef * exception);
-
-guchar seed_value_to_uchar (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_uchar (JSContextRef ctx,
- guchar val, JSValueRef * exception);
-
-glong seed_value_to_long (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_long (JSContextRef ctx,
- glong val, JSValueRef * exception);
-
-gulong seed_value_to_ulong (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_ulong (JSContextRef ctx,
- gulong val, JSValueRef * exception);
-
-gint64 seed_value_to_int64 (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_int64 (JSContextRef ctx,
- gint64 val, JSValueRef * exception);
-
-guint64 seed_value_to_uint64 (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_uint64 (JSContextRef ctx,
- guint64 val, JSValueRef * exception);
-
-gfloat seed_value_to_float (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_float (JSContextRef ctx,
- gfloat val, JSValueRef * exception);
-
-gdouble seed_value_to_double (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_double (JSContextRef ctx,
- gdouble val, JSValueRef * exception);
-
-gsize seed_value_to_size (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_size (JSContextRef ctx,
- gsize val, JSValueRef * exception);
-
-gssize seed_value_to_ssize (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_ssize (JSContextRef ctx,
- gssize val, JSValueRef * exception);
-
-gchar *seed_value_to_filename (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_filename (JSContextRef ctx,
- const gchar * filename,
- JSValueRef * exception);
-
-gchar *seed_value_to_string (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-
-JSValueRef seed_value_from_string (JSContextRef ctx,
- const gchar * val, JSValueRef * exception);
-
-time_t seed_value_to_time_t (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-
-JSValueRef seed_value_from_time_t (JSContextRef ctx,
- time_t time, JSValueRef * exception);
-
-GObject *seed_value_to_object (JSContextRef ctx,
- JSValueRef val, JSValueRef * exception);
-JSValueRef seed_value_from_object (JSContextRef ctx,
- GObject * val, JSValueRef * exception);
-JSValueRef seed_value_from_strv (JSContextRef ctx,
- GStrv * val, JSValueRef * exception);
-void seed_toggle_ref (gpointer data, GObject * object, gboolean is_last_ref);
-
-gboolean seed_validate_enum (GIEnumInfo * info, long val);
-
-JSValueRef
-seed_value_from_binary_string (JSContextRef ctx,
- const gchar * bytes,
- gint n_bytes, JSValueRef * exception);
-
-JSObjectRef seed_make_wrapper_for_type (JSContextRef ctx, GType type);
+JSValueRef seed_value_from_gvalue(JSContextRef ctx,
+ GValue* gval,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_gvalue_for_signal(JSContextRef ctx,
+ GValue* gval,
+ JSValueRef* exception,
+ GSignalQuery* signal_query,
+ gint arg_n);
+
+gboolean seed_value_to_gvalue(JSContextRef ctx,
+ JSValueRef val,
+ GType type,
+ GValue* gval,
+ JSValueRef* exception);
+
+JSValueRef seed_object_get_property(JSContextRef ctx,
+ JSObjectRef val,
+ const gchar* name);
+
+gboolean seed_object_set_property(JSContextRef ctx,
+ JSObjectRef object,
+ const gchar* name,
+ JSValueRef value);
+
+gboolean seed_value_to_gi_argument(JSContextRef ctx,
+ JSValueRef value,
+ GITypeInfo* type_info,
+ GITransfer transfer,
+ GArgument* arg,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_gi_argument(JSContextRef ctx,
+ GArgument* arg,
+ GITypeInfo* type_info,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_gi_argument_full(JSContextRef ctx,
+ GArgument* arg,
+ GITypeInfo* type_info,
+ JSValueRef* exception,
+ guint64 array_len,
+ GITypeTag gi_tag);
+gboolean seed_gi_release_arg(GITransfer transfer,
+ GITypeInfo* type_info,
+ GArgument* arg);
+
+gboolean seed_gi_release_in_arg(GITransfer transfer,
+ GITypeInfo* type_info,
+ GArgument* arg);
+
+gboolean seed_value_to_boolean(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_boolean(JSContextRef ctx,
+ gboolean val,
+ JSValueRef* exception);
+
+guint seed_value_to_uint(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_uint(JSContextRef ctx,
+ guint val,
+ JSValueRef* exception);
+
+gint seed_value_to_int(JSContextRef ctx, JSValueRef val, JSValueRef* exception);
+
+JSValueRef seed_value_from_int(JSContextRef ctx,
+ gint val,
+ JSValueRef* exception);
+
+gchar seed_value_to_char(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_char(JSContextRef ctx,
+ gchar val,
+ JSValueRef* exception);
+
+guchar seed_value_to_uchar(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_uchar(JSContextRef ctx,
+ guchar val,
+ JSValueRef* exception);
+
+glong seed_value_to_long(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_long(JSContextRef ctx,
+ glong val,
+ JSValueRef* exception);
+
+gulong seed_value_to_ulong(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_ulong(JSContextRef ctx,
+ gulong val,
+ JSValueRef* exception);
+
+gint64 seed_value_to_int64(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_int64(JSContextRef ctx,
+ gint64 val,
+ JSValueRef* exception);
+
+guint64 seed_value_to_uint64(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_uint64(JSContextRef ctx,
+ guint64 val,
+ JSValueRef* exception);
+
+gfloat seed_value_to_float(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_float(JSContextRef ctx,
+ gfloat val,
+ JSValueRef* exception);
+
+gdouble seed_value_to_double(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_double(JSContextRef ctx,
+ gdouble val,
+ JSValueRef* exception);
+
+gsize seed_value_to_size(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_size(JSContextRef ctx,
+ gsize val,
+ JSValueRef* exception);
+
+gssize seed_value_to_ssize(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_ssize(JSContextRef ctx,
+ gssize val,
+ JSValueRef* exception);
+
+gchar* seed_value_to_filename(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_filename(JSContextRef ctx,
+ const gchar* filename,
+ JSValueRef* exception);
+
+gchar* seed_value_to_string(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_string(JSContextRef ctx,
+ const gchar* val,
+ JSValueRef* exception);
+
+time_t seed_value_to_time_t(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+
+JSValueRef seed_value_from_time_t(JSContextRef ctx,
+ time_t time,
+ JSValueRef* exception);
+
+GObject* seed_value_to_object(JSContextRef ctx,
+ JSValueRef val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_object(JSContextRef ctx,
+ GObject* val,
+ JSValueRef* exception);
+JSValueRef seed_value_from_strv(JSContextRef ctx,
+ GStrv* val,
+ JSValueRef* exception);
+void seed_toggle_ref(gpointer data, GObject* object, gboolean is_last_ref);
+
+gboolean seed_validate_enum(GIEnumInfo* info, long val);
+
+JSValueRef seed_value_from_binary_string(JSContextRef ctx,
+ const gchar* bytes,
+ gint n_bytes,
+ JSValueRef* exception);
+
+JSObjectRef seed_make_wrapper_for_type(JSContextRef ctx, GType type);
#endif
diff --git a/libseed/seed.h b/libseed/seed.h
index 591753b..5f2a724 100644
--- a/libseed/seed.h
+++ b/libseed/seed.h
@@ -36,434 +36,481 @@ typedef gpointer SeedContext;
typedef gpointer SeedGlobalContext;
typedef gpointer SeedContextGroup;
-typedef enum
-{
- SEED_TYPE_UNDEFINED,
- SEED_TYPE_NULL,
- SEED_TYPE_BOOLEAN,
- SEED_TYPE_NUMBER,
- SEED_TYPE_STRING,
- SEED_TYPE_OBJECT
+typedef enum {
+ SEED_TYPE_UNDEFINED,
+ SEED_TYPE_NULL,
+ SEED_TYPE_BOOLEAN,
+ SEED_TYPE_NUMBER,
+ SEED_TYPE_STRING,
+ SEED_TYPE_OBJECT
} SeedType;
-typedef enum
-{
- SEED_PROPERTY_ATTRIBUTE_NONE = 0,
- SEED_PROPERTY_ATTRIBUTE_READ_ONLY = 1 << 1,
- SEED_PROPERTY_ATTRIBUTE_DONT_ENUM = 1 << 2,
- SEED_PROPERTY_ATTRIBUTE_DONT_DELETE = 1 << 3
+typedef enum {
+ SEED_PROPERTY_ATTRIBUTE_NONE = 0,
+ SEED_PROPERTY_ATTRIBUTE_READ_ONLY = 1 << 1,
+ SEED_PROPERTY_ATTRIBUTE_DONT_ENUM = 1 << 2,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE = 1 << 3
} SeedPropertyAttributes;
-typedef enum
-{
- SEED_CLASS_ATTRIBUTE_NONE = 0,
- SEED_CLASS_ATTRIBUTE_NO_SHARED_PROTOTYPE = 1 << 1
+typedef enum {
+ SEED_CLASS_ATTRIBUTE_NONE = 0,
+ SEED_CLASS_ATTRIBUTE_NO_SHARED_PROTOTYPE = 1 << 1
} SeedClassAttributes;
typedef struct _SeedScript SeedScript;
typedef struct _SeedEngine
{
- SeedGlobalContext context;
- SeedValue global;
- gchar **search_path;
+ SeedGlobalContext context;
+ SeedValue global;
+ gchar** search_path;
- SeedContextGroup group;
+ SeedContextGroup group;
} SeedEngine;
/*
* seed-engine.c
*/
-SeedEngine *seed_init (gint *argc, gchar ***argv);
-SeedEngine *
-seed_init_with_context (gint * argc, gchar *** argv, SeedGlobalContext context);
-
-SeedEngine *seed_init_with_context_group (gint *argc, gchar ***argv,
- SeedContextGroup group);
-SeedEngine *seed_init_with_context_and_group (gint * argc,gchar *** argv,
- SeedGlobalContext context, SeedContextGroup group);
-SeedEngine *seed_init_constrained (gint * argc, gchar *** argv);
-SeedEngine *seed_init_constrained_with_context_and_group (gint * argc,
- gchar *** argv,
- SeedGlobalContext context,
- SeedContextGroup group);
-void seed_engine_destroy (SeedEngine *eng);
-
-SeedValue seed_simple_evaluate (SeedContext ctx,
- gchar * source,
- SeedException *exception);
-
-SeedScript *seed_make_script (SeedContext ctx,
- const gchar * js,
- const gchar * source_url,
- gint line_number);
-SeedScript *seed_script_new_from_file (SeedContext ctx, gchar * file);
-SeedException seed_script_exception (SeedScript * s);
-void seed_script_destroy (SeedScript *s);
-void seed_make_exception (SeedContext ctx, SeedException exception,
- const gchar * name, const gchar * message, ...) G_GNUC_PRINTF (4,5);
-gchar *seed_exception_get_name (SeedContext ctx, SeedException exception);
-gchar *seed_exception_get_message (SeedContext ctx, SeedException exception);
-guint seed_exception_get_line (SeedContext ctx, SeedException exception);
-gchar *seed_exception_get_file (SeedContext ctx, SeedException exception);
-gchar *seed_exception_get_stack (SeedContext ctx, SeedException exception);
-gchar *seed_exception_to_string (SeedContext ctx, SeedException exception);
-
-SeedValue seed_evaluate (SeedContext ctx, SeedScript * s, SeedObject this_object);
-
-SeedValue
-seed_engine_expose_gobject (SeedEngine *engine, gchar *js_name, GObject *object, gchar *gir_namespace,
SeedException exception);
-SeedValue
-seed_engine_expose_namespace (SeedEngine *engine, gchar *namespace_name, SeedException exception);
-GOptionGroup * seed_get_option_group (void);
+SeedEngine* seed_init(gint* argc, gchar*** argv);
+SeedEngine* seed_init_with_context(gint* argc,
+ gchar*** argv,
+ SeedGlobalContext context);
+
+SeedEngine* seed_init_with_context_group(gint* argc,
+ gchar*** argv,
+ SeedContextGroup group);
+SeedEngine* seed_init_with_context_and_group(gint* argc,
+ gchar*** argv,
+ SeedGlobalContext context,
+ SeedContextGroup group);
+SeedEngine* seed_init_constrained(gint* argc, gchar*** argv);
+SeedEngine* seed_init_constrained_with_context_and_group(
+ gint* argc,
+ gchar*** argv,
+ SeedGlobalContext context,
+ SeedContextGroup group);
+void seed_engine_destroy(SeedEngine* eng);
+
+SeedValue seed_simple_evaluate(SeedContext ctx,
+ gchar* source,
+ SeedException* exception);
+
+SeedScript* seed_make_script(SeedContext ctx,
+ const gchar* js,
+ const gchar* source_url,
+ gint line_number);
+SeedScript* seed_script_new_from_file(SeedContext ctx, gchar* file);
+SeedException seed_script_exception(SeedScript* s);
+void seed_script_destroy(SeedScript* s);
+void seed_make_exception(SeedContext ctx,
+ SeedException exception,
+ const gchar* name,
+ const gchar* message,
+ ...) G_GNUC_PRINTF(4, 5);
+gchar* seed_exception_get_name(SeedContext ctx, SeedException exception);
+gchar* seed_exception_get_message(SeedContext ctx, SeedException exception);
+guint seed_exception_get_line(SeedContext ctx, SeedException exception);
+gchar* seed_exception_get_file(SeedContext ctx, SeedException exception);
+gchar* seed_exception_get_stack(SeedContext ctx, SeedException exception);
+gchar* seed_exception_to_string(SeedContext ctx, SeedException exception);
+
+SeedValue seed_evaluate(SeedContext ctx, SeedScript* s, SeedObject this_object);
+
+SeedValue seed_engine_expose_gobject(SeedEngine* engine,
+ gchar* js_name,
+ GObject* object,
+ gchar* gir_namespace,
+ SeedException exception);
+SeedValue seed_engine_expose_namespace(SeedEngine* engine,
+ gchar* namespace_name,
+ SeedException exception);
+GOptionGroup* seed_get_option_group(void);
/*
* seed-api.c
*/
-SeedGlobalContext seed_context_create (SeedContextGroup group,
- SeedClass global_class);
-SeedGlobalContext seed_context_ref (SeedGlobalContext ctx);
-void seed_context_unref (SeedGlobalContext ctx);
-void seed_context_collect (SeedGlobalContext ctx);
-
-SeedObject seed_context_get_global_object (SeedContext ctx);
-
-void seed_importer_add_global(SeedContext ctx, gchar *name);
-void seed_importer_set_search_path (SeedContext ctx,
- gchar **search_path);
-void seed_prepare_global_context (SeedContext ctx);
-void seed_importer_add_search_path (SeedContext ctx, gchar *search_path);
-
-
-SeedValue seed_make_null (SeedContext ctx);
-SeedValue seed_make_undefined (SeedContext ctx);
-
-SeedString seed_string_ref (SeedString string);
-void seed_string_unref (SeedString string);
-
-gsize seed_string_get_maximum_size (SeedString string);
-gsize seed_string_to_utf8_buffer (SeedString string, gchar * buffer,
- size_t buffer_size);
-
-gboolean seed_string_is_equal (SeedString a, SeedString b);
-gboolean seed_string_is_equal_utf8 (SeedString a, const gchar * b);
-
-gboolean seed_value_is_null (SeedContext ctx, SeedValue value);
-gboolean seed_value_is_undefined (SeedContext ctx, SeedValue value);
-gboolean seed_value_is_object (SeedContext ctx, SeedValue value);
-gboolean seed_value_is_object_of_class (SeedContext ctx, SeedValue value, SeedClass klass);
-gboolean seed_value_is_function (SeedContext ctx, SeedObject value);
-gboolean seed_value_is_string (SeedContext ctx, SeedValue value);
-gboolean seed_value_is_number (SeedContext ctx, SeedValue value);
-
-void seed_value_unprotect (SeedContext ctx, SeedValue value);
-void seed_value_protect (SeedContext ctx, SeedValue value);
-
-gboolean seed_value_to_gvalue (SeedContext ctx,
- SeedValue val, GType type,
- GValue * gval, SeedException * exception);
-
-SeedValue seed_value_from_gvalue (SeedContext ctx,
- GValue * gval, SeedException * exception);
-
-gboolean seed_value_to_gi_argument (SeedContext ctx,
- SeedValue value,
- GITypeInfo * type_info,
- GITransfer transfer,
- GArgument * arg, SeedValue * exception);
-
-SeedValue seed_value_from_gi_argument (SeedContext ctx,
- GArgument * arg,
- GITypeInfo * type_info,
- SeedException * exception);
-
-gboolean seed_value_to_boolean (SeedContext ctx,
- SeedValue val, SeedException * exception);
-
-SeedValue seed_value_from_boolean (SeedContext ctx,
- gboolean val, SeedException * exception);
-
-guint seed_value_to_uint (SeedContext ctx,
- SeedValue val, SeedException * exception);
-
-SeedValue seed_value_from_uint (SeedContext ctx,
- guint val, SeedException * exception);
-
-gint seed_value_to_int (SeedContext ctx,
- SeedValue val, SeedException * exception);
-
-SeedValue seed_value_from_int (SeedContext ctx,
- gint val, SeedException * exception);
-
-gchar seed_value_to_char (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_char (SeedContext ctx,
- gchar val, SeedException * exception);
-
-guchar seed_value_to_uchar (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_uchar (SeedContext ctx,
- guchar val, SeedException * exception);
-
-glong seed_value_to_long (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_long (SeedContext ctx,
- glong val, SeedException * exception);
-
-gulong seed_value_to_ulong (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_ulong (SeedContext ctx,
- gulong val, SeedException * exception);
-
-gint64 seed_value_to_int64 (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_int64 (SeedContext ctx,
- gint64 val, SeedException * exception);
-
-guint64 seed_value_to_uint64 (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_uint64 (SeedContext ctx,
- guint64 val, SeedException * exception);
-
-gfloat seed_value_to_float (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_float (SeedContext ctx,
- gfloat val, SeedException * exception);
-
-gdouble seed_value_to_double (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_double (SeedContext ctx,
- gdouble val, SeedException * exception);
-
-gchar *seed_value_to_string (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_string (SeedContext ctx,
- const gchar * val, SeedException * exception);
-
-gchar *seed_value_to_filename (SeedContext ctx,
- SeedValue val, SeedValue *exception);
-SeedValue seed_value_from_filename (SeedContext ctx,
- SeedValue val, SeedValue *exception);
-
-SeedValue seed_value_from_binary_string (SeedContext ctx,
- const gchar *bytes,
- gint n_bytes,
- SeedException *exception);
-
-SeedType seed_value_get_type (SeedContext ctx, SeedValue value);
-
-gboolean
-seed_value_to_format (SeedContext ctx,
- const gchar *format,
- SeedValue *values,
- SeedValue *exception,
- ...);
-
-typedef SeedObject (*SeedModuleInitCallback) (SeedEngine * eng);
-
-gboolean seed_object_set_property (SeedContext ctx,
- SeedObject object,
- const gchar * name, SeedValue value);
-SeedValue seed_object_get_property (SeedContext ctx,
- SeedObject object, const gchar * name);
-
-void seed_object_set_property_at_index (SeedContext ctx,
- SeedObject object,
- gint index,
- SeedValue value,
- SeedException * exception);
-
-SeedValue seed_object_get_property_at_index (SeedContext ctx,
- SeedObject object,
- gint index,
- SeedException *exception);
-
-SeedValue seed_object_call (SeedContext ctx,
- SeedObject object,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception);
-
-GObject *seed_value_to_object (SeedContext ctx,
- SeedValue val, SeedException * exception);
-SeedValue seed_value_from_object (SeedContext ctx,
- GObject * val, SeedException * exception);
-
-SeedObject seed_make_object (SeedContext ctx, SeedClass klass,
- gpointer private_object);
-
-gpointer seed_object_get_private (SeedObject object);
-void seed_object_set_private (SeedObject object, gpointer value);
-
-gchar **seed_object_copy_property_names(SeedContext ctx, SeedObject object);
-
-gpointer seed_pointer_get_pointer (SeedContext ctx, SeedValue pointer);
-
-SeedObject
-seed_object_get_prototype (SeedContext ctx, SeedObject obj);
-
-gboolean
-seed_object_is_of_class (SeedContext ctx, SeedObject obj, SeedClass klass);
-
-SeedValue seed_make_pointer (SeedContext ctx, gpointer pointer);
-
-typedef SeedValue (*SeedFunctionCallback) (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception);
-
-void seed_create_function (SeedContext ctx,
- gchar * name, SeedFunctionCallback func,
- SeedObject obj);
-SeedObject seed_make_function (SeedContext ctx, SeedFunctionCallback func, const gchar *name);
-
-
-SeedObject seed_make_array (SeedContext ctx, const SeedValue elements,
- gsize num_elements, SeedException *exception);
-
-
-
-typedef void (*SeedObjectInitializeCallback) (SeedContext ctx,
- SeedObject object);
+SeedGlobalContext seed_context_create(SeedContextGroup group,
+ SeedClass global_class);
+SeedGlobalContext seed_context_ref(SeedGlobalContext ctx);
+void seed_context_unref(SeedGlobalContext ctx);
+void seed_context_collect(SeedGlobalContext ctx);
+
+SeedObject seed_context_get_global_object(SeedContext ctx);
+
+void seed_importer_add_global(SeedContext ctx, gchar* name);
+void seed_importer_set_search_path(SeedContext ctx, gchar** search_path);
+void seed_prepare_global_context(SeedContext ctx);
+void seed_importer_add_search_path(SeedContext ctx, gchar* search_path);
+
+SeedValue seed_make_null(SeedContext ctx);
+SeedValue seed_make_undefined(SeedContext ctx);
+
+SeedString seed_string_ref(SeedString string);
+void seed_string_unref(SeedString string);
+
+gsize seed_string_get_maximum_size(SeedString string);
+gsize seed_string_to_utf8_buffer(SeedString string,
+ gchar* buffer,
+ size_t buffer_size);
+
+gboolean seed_string_is_equal(SeedString a, SeedString b);
+gboolean seed_string_is_equal_utf8(SeedString a, const gchar* b);
+
+gboolean seed_value_is_null(SeedContext ctx, SeedValue value);
+gboolean seed_value_is_undefined(SeedContext ctx, SeedValue value);
+gboolean seed_value_is_object(SeedContext ctx, SeedValue value);
+gboolean seed_value_is_object_of_class(SeedContext ctx,
+ SeedValue value,
+ SeedClass klass);
+gboolean seed_value_is_function(SeedContext ctx, SeedObject value);
+gboolean seed_value_is_string(SeedContext ctx, SeedValue value);
+gboolean seed_value_is_number(SeedContext ctx, SeedValue value);
+
+void seed_value_unprotect(SeedContext ctx, SeedValue value);
+void seed_value_protect(SeedContext ctx, SeedValue value);
+
+gboolean seed_value_to_gvalue(SeedContext ctx,
+ SeedValue val,
+ GType type,
+ GValue* gval,
+ SeedException* exception);
+
+SeedValue seed_value_from_gvalue(SeedContext ctx,
+ GValue* gval,
+ SeedException* exception);
+
+gboolean seed_value_to_gi_argument(SeedContext ctx,
+ SeedValue value,
+ GITypeInfo* type_info,
+ GITransfer transfer,
+ GArgument* arg,
+ SeedValue* exception);
+
+SeedValue seed_value_from_gi_argument(SeedContext ctx,
+ GArgument* arg,
+ GITypeInfo* type_info,
+ SeedException* exception);
+
+gboolean seed_value_to_boolean(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+
+SeedValue seed_value_from_boolean(SeedContext ctx,
+ gboolean val,
+ SeedException* exception);
+
+guint seed_value_to_uint(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+
+SeedValue seed_value_from_uint(SeedContext ctx,
+ guint val,
+ SeedException* exception);
+
+gint seed_value_to_int(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+
+SeedValue seed_value_from_int(SeedContext ctx,
+ gint val,
+ SeedException* exception);
+
+gchar seed_value_to_char(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_char(SeedContext ctx,
+ gchar val,
+ SeedException* exception);
+
+guchar seed_value_to_uchar(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_uchar(SeedContext ctx,
+ guchar val,
+ SeedException* exception);
+
+glong seed_value_to_long(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_long(SeedContext ctx,
+ glong val,
+ SeedException* exception);
+
+gulong seed_value_to_ulong(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_ulong(SeedContext ctx,
+ gulong val,
+ SeedException* exception);
+
+gint64 seed_value_to_int64(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_int64(SeedContext ctx,
+ gint64 val,
+ SeedException* exception);
+
+guint64 seed_value_to_uint64(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_uint64(SeedContext ctx,
+ guint64 val,
+ SeedException* exception);
+
+gfloat seed_value_to_float(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_float(SeedContext ctx,
+ gfloat val,
+ SeedException* exception);
+
+gdouble seed_value_to_double(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_double(SeedContext ctx,
+ gdouble val,
+ SeedException* exception);
+
+gchar* seed_value_to_string(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_string(SeedContext ctx,
+ const gchar* val,
+ SeedException* exception);
+
+gchar* seed_value_to_filename(SeedContext ctx,
+ SeedValue val,
+ SeedValue* exception);
+SeedValue seed_value_from_filename(SeedContext ctx,
+ SeedValue val,
+ SeedValue* exception);
+
+SeedValue seed_value_from_binary_string(SeedContext ctx,
+ const gchar* bytes,
+ gint n_bytes,
+ SeedException* exception);
+
+SeedType seed_value_get_type(SeedContext ctx, SeedValue value);
+
+gboolean seed_value_to_format(SeedContext ctx,
+ const gchar* format,
+ SeedValue* values,
+ SeedValue* exception,
+ ...);
+
+typedef SeedObject (*SeedModuleInitCallback)(SeedEngine* eng);
+
+gboolean seed_object_set_property(SeedContext ctx,
+ SeedObject object,
+ const gchar* name,
+ SeedValue value);
+SeedValue seed_object_get_property(SeedContext ctx,
+ SeedObject object,
+ const gchar* name);
+
+void seed_object_set_property_at_index(SeedContext ctx,
+ SeedObject object,
+ gint index,
+ SeedValue value,
+ SeedException* exception);
+
+SeedValue seed_object_get_property_at_index(SeedContext ctx,
+ SeedObject object,
+ gint index,
+ SeedException* exception);
+
+SeedValue seed_object_call(SeedContext ctx,
+ SeedObject object,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception);
+
+GObject* seed_value_to_object(SeedContext ctx,
+ SeedValue val,
+ SeedException* exception);
+SeedValue seed_value_from_object(SeedContext ctx,
+ GObject* val,
+ SeedException* exception);
+
+SeedObject seed_make_object(SeedContext ctx,
+ SeedClass klass,
+ gpointer private_object);
+
+gpointer seed_object_get_private(SeedObject object);
+void seed_object_set_private(SeedObject object, gpointer value);
+
+gchar** seed_object_copy_property_names(SeedContext ctx, SeedObject object);
+
+gpointer seed_pointer_get_pointer(SeedContext ctx, SeedValue pointer);
+
+SeedObject seed_object_get_prototype(SeedContext ctx, SeedObject obj);
+
+gboolean seed_object_is_of_class(SeedContext ctx,
+ SeedObject obj,
+ SeedClass klass);
+
+SeedValue seed_make_pointer(SeedContext ctx, gpointer pointer);
+
+typedef SeedValue (*SeedFunctionCallback)(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception);
+
+void seed_create_function(SeedContext ctx,
+ gchar* name,
+ SeedFunctionCallback func,
+ SeedObject obj);
+SeedObject seed_make_function(SeedContext ctx,
+ SeedFunctionCallback func,
+ const gchar* name);
+
+SeedObject seed_make_array(SeedContext ctx,
+ const SeedValue elements,
+ gsize num_elements,
+ SeedException* exception);
+
+typedef void (*SeedObjectInitializeCallback)(SeedContext ctx,
+ SeedObject object);
/* Using any functions that require a context from
*this callback has undefined results */
-typedef void (*SeedObjectFinalizeCallback) (SeedObject object);
-
-typedef gboolean (*SeedObjectHasPropertyCallback) (SeedContext ctx,
- SeedObject object,
- SeedString string);
-typedef SeedValue (*SeedObjectGetPropertyCallback) (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException * e);
-typedef gboolean (*SeedObjectSetPropertyCallback) (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedValue value,
- SeedException * e);
-typedef gboolean (*SeedObjectDeletePropertyCallback) (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException * e);
+typedef void (*SeedObjectFinalizeCallback)(SeedObject object);
+
+typedef gboolean (*SeedObjectHasPropertyCallback)(SeedContext ctx,
+ SeedObject object,
+ SeedString string);
+typedef SeedValue (*SeedObjectGetPropertyCallback)(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* e);
+typedef gboolean (*SeedObjectSetPropertyCallback)(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* e);
+typedef gboolean (*SeedObjectDeletePropertyCallback)(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* e);
/* TODO: Have to decide on accumulator API
//typedef void (*SeedObjectGetPropertyNamesCallback) (SeedContext ctx, */
-typedef void (*SeedObjectGetPropertyNamesCallback) (void);
-
-typedef SeedValue (*SeedObjectCallAsFunctionCallback) (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue
- arguments[],
- SeedException *
- exception);
-typedef SeedValue (*SeedObjectCallAsConstructorCallback) (SeedContext ctx,
- SeedObject
- constructor,
- gsize
- argument_count,
- const SeedValue
- arguments[],
- SeedException *
- exception);
-
-typedef gboolean (*SeedObjectHasInstanceCallback) (SeedContext ctx,
- SeedObject constructor,
- SeedObject instance_p,
- SeedException * exception);
-
-typedef SeedValue (*SeedObjectConvertToTypeCallback) (SeedContext ctx,
- SeedObject object,
- SeedType type,
- SeedException *
- exception);
+typedef void (*SeedObjectGetPropertyNamesCallback)(void);
+
+typedef SeedValue (*SeedObjectCallAsFunctionCallback)(
+ SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception);
+typedef SeedValue (*SeedObjectCallAsConstructorCallback)(
+ SeedContext ctx,
+ SeedObject constructor,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception);
+
+typedef gboolean (*SeedObjectHasInstanceCallback)(SeedContext ctx,
+ SeedObject constructor,
+ SeedObject instance_p,
+ SeedException* exception);
+
+typedef SeedValue (*SeedObjectConvertToTypeCallback)(SeedContext ctx,
+ SeedObject object,
+ SeedType type,
+ SeedException* exception);
typedef struct _seed_static_value
{
- const gchar *const name;
- SeedObjectGetPropertyCallback get_property;
- SeedObjectSetPropertyCallback set_property;
- SeedPropertyAttributes attributes;
+ const gchar* const name;
+ SeedObjectGetPropertyCallback get_property;
+ SeedObjectSetPropertyCallback set_property;
+ SeedPropertyAttributes attributes;
} seed_static_value;
typedef struct _seed_static_function
{
- const gchar *const name;
- SeedObjectCallAsFunctionCallback callback;
- SeedPropertyAttributes attributes;
+ const gchar* const name;
+ SeedObjectCallAsFunctionCallback callback;
+ SeedPropertyAttributes attributes;
} seed_static_function;
typedef struct _seed_class_definition
{
- int version; /* Always 0 */
- SeedClassAttributes attributes;
-
- const gchar *class_name;
- SeedClass parent_class;
-
- const seed_static_value *static_values;
- const seed_static_function *static_functions;
-
- SeedObjectInitializeCallback initialize;
- SeedObjectFinalizeCallback finalize;
- SeedObjectHasPropertyCallback has_property;
- SeedObjectGetPropertyCallback get_property;
- SeedObjectSetPropertyCallback set_property;
- SeedObjectDeletePropertyCallback delete_property;
- SeedObjectGetPropertyNamesCallback get_property_names;
- SeedObjectCallAsFunctionCallback call_as_function;
- SeedObjectCallAsConstructorCallback call_as_constructor;
- SeedObjectHasInstanceCallback has_instance;
- SeedObjectConvertToTypeCallback convert_to_type;
+ int version; /* Always 0 */
+ SeedClassAttributes attributes;
+
+ const gchar* class_name;
+ SeedClass parent_class;
+
+ const seed_static_value* static_values;
+ const seed_static_function* static_functions;
+
+ SeedObjectInitializeCallback initialize;
+ SeedObjectFinalizeCallback finalize;
+ SeedObjectHasPropertyCallback has_property;
+ SeedObjectGetPropertyCallback get_property;
+ SeedObjectSetPropertyCallback set_property;
+ SeedObjectDeletePropertyCallback delete_property;
+ SeedObjectGetPropertyNamesCallback get_property_names;
+ SeedObjectCallAsFunctionCallback call_as_function;
+ SeedObjectCallAsConstructorCallback call_as_constructor;
+ SeedObjectHasInstanceCallback has_instance;
+ SeedObjectConvertToTypeCallback convert_to_type;
} seed_class_definition;
-#define seed_empty_class { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};
-
-SeedClass seed_create_class (seed_class_definition * def);
-
-SeedObject seed_make_constructor (SeedContext ctx,
- SeedClass klass,
- SeedObjectCallAsConstructorCallback constructor);
-
-void seed_engine_set_search_path (SeedEngine * eng, const gchar * path);
-gchar **seed_engine_get_search_path (SeedEngine * eng);
-
-void
-seed_signal_connect (SeedContext ctx,
- GObject *object,
- const gchar *signal,
- const gchar *script);
-
-void
-seed_signal_connect_value (SeedContext ctx,
- GObject *object,
- const gchar *signal,
- SeedValue function,
- SeedValue user_data);
-
-GClosure *seed_closure_new (SeedContext ctx,
- SeedObject function,
- SeedObject user_data,
- const gchar *description);
-
-
-SeedObject
-seed_closure_get_callable (GClosure *c);
-
-SeedValue
-seed_closure_invoke (GClosure *closure, SeedValue *args, guint argc, SeedException *exception);
-
-SeedValue
-seed_closure_invoke_with_context (SeedContext ctx, GClosure *closure, SeedValue *args, guint argc,
SeedException *exception);
-
-void
-seed_closure_warn_exception (GClosure *c, SeedContext ctx, SeedException exception);
+#define seed_empty_class \
+ { \
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \
+ };
+
+SeedClass seed_create_class(seed_class_definition* def);
+
+SeedObject seed_make_constructor(
+ SeedContext ctx,
+ SeedClass klass,
+ SeedObjectCallAsConstructorCallback constructor);
+
+void seed_engine_set_search_path(SeedEngine* eng, const gchar* path);
+gchar** seed_engine_get_search_path(SeedEngine* eng);
+
+void seed_signal_connect(SeedContext ctx,
+ GObject* object,
+ const gchar* signal,
+ const gchar* script);
+
+void seed_signal_connect_value(SeedContext ctx,
+ GObject* object,
+ const gchar* signal,
+ SeedValue function,
+ SeedValue user_data);
+
+GClosure* seed_closure_new(SeedContext ctx,
+ SeedObject function,
+ SeedObject user_data,
+ const gchar* description);
+
+SeedObject seed_closure_get_callable(GClosure* c);
+
+SeedValue seed_closure_invoke(GClosure* closure,
+ SeedValue* args,
+ guint argc,
+ SeedException* exception);
+
+SeedValue seed_closure_invoke_with_context(SeedContext ctx,
+ GClosure* closure,
+ SeedValue* args,
+ guint argc,
+ SeedException* exception);
+
+void seed_closure_warn_exception(GClosure* c,
+ SeedContext ctx,
+ SeedException exception);
G_END_DECLS
diff --git a/modules/DynamicObject/seed-DynamicObject.c b/modules/DynamicObject/seed-DynamicObject.c
index 3b22a12..a14b4bc 100644
--- a/modules/DynamicObject/seed-DynamicObject.c
+++ b/modules/DynamicObject/seed-DynamicObject.c
@@ -5,7 +5,7 @@ this free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 2 of
the License, or (at your option) any later version.
-
+
Copyright (C) 2010 Jonatan Liljedahl <lijon kymatica com>
--------------------------------------------------------------------------------
@@ -13,7 +13,7 @@ Copyright (C) 2010 Jonatan Liljedahl <lijon kymatica com>
Compile with:
gcc -shared -fPIC seed-DynamicObject.c -I/usr/local/include/seed \
- `pkg-config --cflags --libs glib-2.0 gmodule-2.0 gobject-introspection-1.0` \
+ `pkg-config --cflags --libs glib-2.0 gmodule-2.0 gobject-introspection-1.0`\
-o libseed_DynamicObject.so
Usage:
@@ -57,137 +57,144 @@ You can also create the object first and set the callbacks later:
static SeedClass dynamic_object_class;
static SeedValue
-seed_dynamic_object_create (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_dynamic_object_create(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedObject obj = seed_make_object (ctx, dynamic_object_class, NULL);
+ SeedObject obj = seed_make_object(ctx, dynamic_object_class, NULL);
if (argument_count > 0)
- seed_object_set_property (ctx, obj, "__proto__", arguments[0]);
+ seed_object_set_property(ctx, obj, "__proto__", arguments[0]);
- return (SeedValue)obj;
+ return (SeedValue) obj;
}
static SeedValue
-seed_dynamic_object_get_property (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_dynamic_object_get_property(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- guint len = seed_string_get_maximum_size (property_name);
- gchar *prop = g_alloca (len * sizeof (gchar));
- seed_string_to_utf8_buffer (property_name, prop, len);
+ guint len = seed_string_get_maximum_size(property_name);
+ gchar* prop = g_alloca(len * sizeof(gchar));
+ seed_string_to_utf8_buffer(property_name, prop, len);
// forward these to ordinary property lookup
- if (!g_strcmp0 (prop, "toString"))
+ if (!g_strcmp0(prop, "toString"))
return NULL;
- if (!g_strcmp0 (prop, "valueOf"))
+ if (!g_strcmp0(prop, "valueOf"))
return NULL;
- if (!g_strcmp0 (prop, "getProperty"))
+ if (!g_strcmp0(prop, "getProperty"))
return NULL;
- if (!g_strcmp0 (prop, "setProperty"))
+ if (!g_strcmp0(prop, "setProperty"))
return NULL;
- if (!g_strcmp0 (prop, "deleteProperty"))
+ if (!g_strcmp0(prop, "deleteProperty"))
return NULL;
- if (!g_strcmp0 (prop, "callAsFunction"))
+ if (!g_strcmp0(prop, "callAsFunction"))
return NULL;
- if (!g_strcmp0 (prop, "callAsConstructor"))
+ if (!g_strcmp0(prop, "callAsConstructor"))
return NULL;
- SeedValue handler = seed_object_get_property (ctx, object, "getProperty");
- if (seed_value_is_object (ctx, handler)) {
- SeedValue args[1] = { seed_value_from_string (ctx, prop, exception) };
- SeedValue ret = (SeedValue) seed_object_call (ctx, (SeedObject)handler, NULL, 1, args, exception);
- return seed_value_is_null(ctx,ret)?NULL:ret;
+ SeedValue handler = seed_object_get_property(ctx, object, "getProperty");
+ if (seed_value_is_object(ctx, handler)) {
+ SeedValue args[1] = { seed_value_from_string(ctx, prop, exception) };
+ SeedValue ret = (SeedValue) seed_object_call(ctx, (SeedObject) handler,
+ NULL, 1, args, exception);
+ return seed_value_is_null(ctx, ret) ? NULL : ret;
}
return NULL;
}
static gboolean
-seed_dynamic_object_set_property (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_dynamic_object_set_property(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- guint len = seed_string_get_maximum_size (property_name);
- gchar *prop = g_alloca (len * sizeof (gchar));
- seed_string_to_utf8_buffer (property_name, prop, len);
-
- SeedValue handler = seed_object_get_property (ctx, object, "setProperty");
- if (seed_value_is_object (ctx, handler)) {
- SeedValue args[2] = {
- seed_value_from_string (ctx, prop, exception),
- value};
- SeedValue ret = seed_object_call (ctx, (SeedObject)handler, NULL, 2, args, exception);
- return seed_value_to_boolean (ctx, ret, exception);
+ guint len = seed_string_get_maximum_size(property_name);
+ gchar* prop = g_alloca(len * sizeof(gchar));
+ seed_string_to_utf8_buffer(property_name, prop, len);
+
+ SeedValue handler = seed_object_get_property(ctx, object, "setProperty");
+ if (seed_value_is_object(ctx, handler)) {
+ SeedValue args[2]
+ = { seed_value_from_string(ctx, prop, exception), value };
+ SeedValue ret = seed_object_call(ctx, (SeedObject) handler, NULL, 2,
+ args, exception);
+ return seed_value_to_boolean(ctx, ret, exception);
}
return FALSE;
}
-static gboolean
-seed_dynamic_object_delete_property (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+static gboolean
+seed_dynamic_object_delete_property(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- guint len = seed_string_get_maximum_size (property_name);
- gchar *prop = g_alloca (len * sizeof (gchar));
- seed_string_to_utf8_buffer (property_name, prop, len);
-
- SeedValue handler = seed_object_get_property (ctx, object, "deleteProperty");
- if (seed_value_is_object (ctx, handler)) {
- SeedValue args[1] = { seed_value_from_string (ctx, prop, exception) };
- SeedValue ret = (SeedValue) seed_object_call (ctx, (SeedObject)handler, NULL, 1, args, exception);
- return seed_value_to_boolean (ctx, ret, exception);
+ guint len = seed_string_get_maximum_size(property_name);
+ gchar* prop = g_alloca(len * sizeof(gchar));
+ seed_string_to_utf8_buffer(property_name, prop, len);
+
+ SeedValue handler = seed_object_get_property(ctx, object, "deleteProperty");
+ if (seed_value_is_object(ctx, handler)) {
+ SeedValue args[1] = { seed_value_from_string(ctx, prop, exception) };
+ SeedValue ret = (SeedValue) seed_object_call(ctx, (SeedObject) handler,
+ NULL, 1, args, exception);
+ return seed_value_to_boolean(ctx, ret, exception);
}
return FALSE;
-
}
static SeedValue
-seed_dynamic_object_call_as_function (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_dynamic_object_call_as_function(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue handler = seed_object_get_property (ctx, function, "callAsFunction");
- if (seed_value_is_object (ctx, handler)) {
- return (SeedValue) seed_object_call (ctx, (SeedObject)handler, NULL, argument_count, arguments,
exception);
+ SeedValue handler
+ = seed_object_get_property(ctx, function, "callAsFunction");
+ if (seed_value_is_object(ctx, handler)) {
+ return (SeedValue) seed_object_call(ctx, (SeedObject) handler, NULL,
+ argument_count, arguments,
+ exception);
}
return NULL;
}
static SeedValue
-seed_dynamic_object_call_as_constructor (SeedContext ctx,
- SeedObject function,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_dynamic_object_call_as_constructor(SeedContext ctx,
+ SeedObject function,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue handler = seed_object_get_property (ctx, function, "callAsConstructor");
- if (seed_value_is_object (ctx, handler)) {
- return (SeedValue) seed_object_call (ctx, (SeedObject)handler, NULL, argument_count, arguments,
exception);
+ SeedValue handler
+ = seed_object_get_property(ctx, function, "callAsConstructor");
+ if (seed_value_is_object(ctx, handler)) {
+ return (SeedValue) seed_object_call(ctx, (SeedObject) handler, NULL,
+ argument_count, arguments,
+ exception);
}
return NULL;
}
-//static void
-//seed_dynamic_object_get_property_names (SeedContext ctx,
+// static void
+// seed_dynamic_object_get_property_names (SeedContext ctx,
// SeedObject object,
// /*wait for API*/ propertyNames)
SeedObject
-seed_module_init (SeedEngine * eng)
+seed_module_init(SeedEngine* eng)
{
- SeedObject namespace_ref = seed_make_object (eng->context, NULL, NULL);
+ SeedObject namespace_ref = seed_make_object(eng->context, NULL, NULL);
seed_class_definition class_def = seed_empty_class;
class_def.class_name = "DynamicObject";
@@ -196,10 +203,11 @@ seed_module_init (SeedEngine * eng)
class_def.delete_property = seed_dynamic_object_delete_property;
class_def.call_as_function = seed_dynamic_object_call_as_function;
class_def.call_as_constructor = seed_dynamic_object_call_as_constructor;
-
- dynamic_object_class = seed_create_class (&class_def);
- seed_create_function(eng->context, "create", (SeedFunctionCallback)seed_dynamic_object_create,
namespace_ref);
+ dynamic_object_class = seed_create_class(&class_def);
+
+ seed_create_function(eng->context, "create",
+ (SeedFunctionCallback) seed_dynamic_object_create,
+ namespace_ref);
return namespace_ref;
}
-
diff --git a/modules/cairo/seed-cairo-enums.c b/modules/cairo/seed-cairo-enums.c
index dbc75ff..9afb3b6 100644
--- a/modules/cairo/seed-cairo-enums.c
+++ b/modules/cairo/seed-cairo-enums.c
@@ -21,124 +21,135 @@
#include <cairo/cairo.h>
#include "seed-cairo.h"
-#define ENUM_MEMBER(holder, name, value) \
- seed_object_set_property (ctx, holder, name, seed_value_from_long (ctx, value, NULL))
+#define ENUM_MEMBER(holder, name, value) \
+ seed_object_set_property(ctx, holder, name, \
+ seed_value_from_long(ctx, value, NULL))
SeedValue
-seed_cairo_status_to_string (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_status_to_string(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_status_t status;
+ cairo_status_t status;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("status_to_string", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("status_to_string", "1 argument");
}
- status = seed_value_to_long (ctx, arguments[0], exception);
+ status = seed_value_to_long(ctx, arguments[0], exception);
- return seed_value_from_string (ctx, cairo_status_to_string (status), exception);
+ return seed_value_from_string(ctx, cairo_status_to_string(status),
+ exception);
}
void
-seed_define_cairo_enums (SeedContext ctx,
- SeedObject namespace_ref)
+seed_define_cairo_enums(SeedContext ctx, SeedObject namespace_ref)
{
- SeedObject content_holder, format_holder, antialias_holder, fillrule_holder,
- linecap_holder, linejoin_holder, operator_holder, status_holder;
-
- content_holder = seed_make_object (ctx, NULL, NULL);
- seed_object_set_property (ctx, namespace_ref, "Content", content_holder);
- ENUM_MEMBER(content_holder, "COLOR", CAIRO_CONTENT_COLOR);
- ENUM_MEMBER(content_holder, "ALPHA", CAIRO_CONTENT_ALPHA);
- ENUM_MEMBER(content_holder, "COLOR_ALPHA", CAIRO_CONTENT_COLOR_ALPHA);
-
- format_holder = seed_make_object (ctx, NULL, NULL);
- seed_object_set_property (ctx, namespace_ref, "Format", format_holder);
- ENUM_MEMBER(format_holder, "ARGB32", CAIRO_FORMAT_ARGB32);
- ENUM_MEMBER(format_holder, "RGB23", CAIRO_FORMAT_RGB24);
- ENUM_MEMBER(format_holder, "A8", CAIRO_FORMAT_A8);
- ENUM_MEMBER(format_holder, "A1", CAIRO_FORMAT_A1);
-
- antialias_holder = seed_make_object (ctx, NULL, NULL);
- seed_object_set_property (ctx, namespace_ref, "Antialias", antialias_holder);
- ENUM_MEMBER(antialias_holder, "DEFAULT", CAIRO_ANTIALIAS_DEFAULT);
- ENUM_MEMBER(antialias_holder, "NONE", CAIRO_ANTIALIAS_NONE);
- ENUM_MEMBER(antialias_holder, "GRAY", CAIRO_ANTIALIAS_GRAY);
- ENUM_MEMBER(antialias_holder, "SUBPIXEL", CAIRO_ANTIALIAS_SUBPIXEL);
-
- fillrule_holder = seed_make_object (ctx, NULL, NULL);
- seed_object_set_property (ctx, namespace_ref, "Fillrule", fillrule_holder);
- ENUM_MEMBER(fillrule_holder, "WINDING", CAIRO_FILL_RULE_WINDING);
- ENUM_MEMBER(fillrule_holder, "EVEN_ODD", CAIRO_FILL_RULE_EVEN_ODD);
-
- linecap_holder = seed_make_object (ctx, NULL, NULL);
- seed_object_set_property (ctx, namespace_ref, "Linecap", linecap_holder);
- ENUM_MEMBER(linecap_holder, "BUTT", CAIRO_LINE_CAP_BUTT);
- ENUM_MEMBER(linecap_holder, "ROUND", CAIRO_LINE_CAP_ROUND);
- ENUM_MEMBER(linecap_holder, "SQUARE", CAIRO_LINE_CAP_SQUARE);
-
- linejoin_holder = seed_make_object (ctx, NULL, NULL);
- seed_object_set_property (ctx, namespace_ref, "Linejoin", linejoin_holder);
- ENUM_MEMBER(linejoin_holder, "MITER", CAIRO_LINE_JOIN_MITER);
- ENUM_MEMBER(linejoin_holder, "ROUND", CAIRO_LINE_JOIN_ROUND);
- ENUM_MEMBER(linejoin_holder, "BEVEL", CAIRO_LINE_JOIN_BEVEL);
-
-
- operator_holder = seed_make_object (ctx, NULL, NULL);
- seed_object_set_property (ctx, namespace_ref, "Operator", operator_holder);
- ENUM_MEMBER(operator_holder, "CLEAR", CAIRO_OPERATOR_CLEAR);
- ENUM_MEMBER(operator_holder, "SOURCE", CAIRO_OPERATOR_SOURCE);
- ENUM_MEMBER(operator_holder, "OVER", CAIRO_OPERATOR_OVER);
- ENUM_MEMBER(operator_holder, "IN", CAIRO_OPERATOR_IN);
- ENUM_MEMBER(operator_holder, "OUT", CAIRO_OPERATOR_OUT);
- ENUM_MEMBER(operator_holder, "ATOP", CAIRO_OPERATOR_ATOP);
- ENUM_MEMBER(operator_holder, "DEST", CAIRO_OPERATOR_DEST);
- ENUM_MEMBER(operator_holder, "DEST_OVER", CAIRO_OPERATOR_DEST_OVER);
- ENUM_MEMBER(operator_holder, "DEST_IN", CAIRO_OPERATOR_DEST_IN);
- ENUM_MEMBER(operator_holder, "DEST_OUT", CAIRO_OPERATOR_DEST_OUT);
- ENUM_MEMBER(operator_holder, "DEST_ATOP", CAIRO_OPERATOR_DEST_ATOP);
- ENUM_MEMBER(operator_holder, "XOR", CAIRO_OPERATOR_XOR);
- ENUM_MEMBER(operator_holder, "ADD", CAIRO_OPERATOR_ADD);
- ENUM_MEMBER(operator_holder, "SATURATE", CAIRO_OPERATOR_SATURATE);
-
- status_holder = seed_make_object (ctx, NULL, NULL);
- seed_object_set_property (ctx, namespace_ref, "Status", status_holder);
- ENUM_MEMBER(status_holder, "SUCCESS", CAIRO_STATUS_SUCCESS);
- ENUM_MEMBER(status_holder, "NO_MEMORY", CAIRO_STATUS_NO_MEMORY);
- ENUM_MEMBER(status_holder, "INVALID_RESTORE", CAIRO_STATUS_INVALID_RESTORE);
- ENUM_MEMBER(status_holder, "INVALID_POP_GROUP", CAIRO_STATUS_INVALID_POP_GROUP);
- ENUM_MEMBER(status_holder, "NO_CURRENT_POINT", CAIRO_STATUS_NO_CURRENT_POINT);
- ENUM_MEMBER(status_holder, "INVALID_MATRIX", CAIRO_STATUS_INVALID_MATRIX);
- ENUM_MEMBER(status_holder, "INVALID_STATUS", CAIRO_STATUS_INVALID_STATUS);
- ENUM_MEMBER(status_holder, "NULL_POINTER", CAIRO_STATUS_NULL_POINTER);
- ENUM_MEMBER(status_holder, "INVALID_STRING", CAIRO_STATUS_INVALID_STRING);
- ENUM_MEMBER(status_holder, "INVALID_PATH_DATA", CAIRO_STATUS_INVALID_PATH_DATA);
- ENUM_MEMBER(status_holder, "READ_ERROR", CAIRO_STATUS_READ_ERROR);
- ENUM_MEMBER(status_holder, "WRITE_ERROR", CAIRO_STATUS_WRITE_ERROR);
- ENUM_MEMBER(status_holder, "SURFACE_FINISHED", CAIRO_STATUS_SURFACE_FINISHED);
- ENUM_MEMBER(status_holder, "SURFACE_TYPE_MISMATCH", CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
- ENUM_MEMBER(status_holder, "PATTERN_TYPE_MISMATCH", CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
- ENUM_MEMBER(status_holder, "INVALID_CONTENT", CAIRO_STATUS_INVALID_CONTENT);
- ENUM_MEMBER(status_holder, "INVALID_FORMAT", CAIRO_STATUS_INVALID_FORMAT);
- ENUM_MEMBER(status_holder, "INVALID_VISUAL", CAIRO_STATUS_INVALID_VISUAL);
- ENUM_MEMBER(status_holder, "FILE_NOT_FOUND", CAIRO_STATUS_FILE_NOT_FOUND);
- ENUM_MEMBER(status_holder, "INVALID_DASH", CAIRO_STATUS_INVALID_DASH);
- ENUM_MEMBER(status_holder, "INVALID_DSC_COMMENT", CAIRO_STATUS_INVALID_DSC_COMMENT);
- ENUM_MEMBER(status_holder, "INVALID_INDEX", CAIRO_STATUS_INVALID_INDEX);
- ENUM_MEMBER(status_holder, "CLIP_NOT_REPRESENTABLE", CAIRO_STATUS_CLIP_NOT_REPRESENTABLE);
- ENUM_MEMBER(status_holder, "TEMP_FILE_ERROR", CAIRO_STATUS_TEMP_FILE_ERROR);
- ENUM_MEMBER(status_holder, "INVALID_STRIDE", CAIRO_STATUS_INVALID_STRIDE);
- ENUM_MEMBER(status_holder, "FONT_TYPE_MISMATCH", CAIRO_STATUS_FONT_TYPE_MISMATCH);
- ENUM_MEMBER(status_holder, "USER_FONT_IMMUTABLE", CAIRO_STATUS_USER_FONT_IMMUTABLE);
- ENUM_MEMBER(status_holder, "USER_FONT_ERROR", CAIRO_STATUS_USER_FONT_ERROR);
- ENUM_MEMBER(status_holder, "NEGATIVE_COUNT", CAIRO_STATUS_NEGATIVE_COUNT);
- ENUM_MEMBER(status_holder, "INVALID_CLUSTERS", CAIRO_STATUS_INVALID_CLUSTERS);
- ENUM_MEMBER(status_holder, "INVALID_SLANT", CAIRO_STATUS_INVALID_SLANT);
- ENUM_MEMBER(status_holder, "INVALID_WEIGHT", CAIRO_STATUS_INVALID_WEIGHT);
-
- seed_create_function (ctx, "to_string", seed_cairo_status_to_string, status_holder);
+ SeedObject content_holder, format_holder, antialias_holder, fillrule_holder,
+ linecap_holder, linejoin_holder, operator_holder, status_holder;
+
+ content_holder = seed_make_object(ctx, NULL, NULL);
+ seed_object_set_property(ctx, namespace_ref, "Content", content_holder);
+ ENUM_MEMBER(content_holder, "COLOR", CAIRO_CONTENT_COLOR);
+ ENUM_MEMBER(content_holder, "ALPHA", CAIRO_CONTENT_ALPHA);
+ ENUM_MEMBER(content_holder, "COLOR_ALPHA", CAIRO_CONTENT_COLOR_ALPHA);
+
+ format_holder = seed_make_object(ctx, NULL, NULL);
+ seed_object_set_property(ctx, namespace_ref, "Format", format_holder);
+ ENUM_MEMBER(format_holder, "ARGB32", CAIRO_FORMAT_ARGB32);
+ ENUM_MEMBER(format_holder, "RGB23", CAIRO_FORMAT_RGB24);
+ ENUM_MEMBER(format_holder, "A8", CAIRO_FORMAT_A8);
+ ENUM_MEMBER(format_holder, "A1", CAIRO_FORMAT_A1);
+
+ antialias_holder = seed_make_object(ctx, NULL, NULL);
+ seed_object_set_property(ctx, namespace_ref, "Antialias", antialias_holder);
+ ENUM_MEMBER(antialias_holder, "DEFAULT", CAIRO_ANTIALIAS_DEFAULT);
+ ENUM_MEMBER(antialias_holder, "NONE", CAIRO_ANTIALIAS_NONE);
+ ENUM_MEMBER(antialias_holder, "GRAY", CAIRO_ANTIALIAS_GRAY);
+ ENUM_MEMBER(antialias_holder, "SUBPIXEL", CAIRO_ANTIALIAS_SUBPIXEL);
+
+ fillrule_holder = seed_make_object(ctx, NULL, NULL);
+ seed_object_set_property(ctx, namespace_ref, "Fillrule", fillrule_holder);
+ ENUM_MEMBER(fillrule_holder, "WINDING", CAIRO_FILL_RULE_WINDING);
+ ENUM_MEMBER(fillrule_holder, "EVEN_ODD", CAIRO_FILL_RULE_EVEN_ODD);
+
+ linecap_holder = seed_make_object(ctx, NULL, NULL);
+ seed_object_set_property(ctx, namespace_ref, "Linecap", linecap_holder);
+ ENUM_MEMBER(linecap_holder, "BUTT", CAIRO_LINE_CAP_BUTT);
+ ENUM_MEMBER(linecap_holder, "ROUND", CAIRO_LINE_CAP_ROUND);
+ ENUM_MEMBER(linecap_holder, "SQUARE", CAIRO_LINE_CAP_SQUARE);
+
+ linejoin_holder = seed_make_object(ctx, NULL, NULL);
+ seed_object_set_property(ctx, namespace_ref, "Linejoin", linejoin_holder);
+ ENUM_MEMBER(linejoin_holder, "MITER", CAIRO_LINE_JOIN_MITER);
+ ENUM_MEMBER(linejoin_holder, "ROUND", CAIRO_LINE_JOIN_ROUND);
+ ENUM_MEMBER(linejoin_holder, "BEVEL", CAIRO_LINE_JOIN_BEVEL);
+
+ operator_holder = seed_make_object(ctx, NULL, NULL);
+ seed_object_set_property(ctx, namespace_ref, "Operator", operator_holder);
+ ENUM_MEMBER(operator_holder, "CLEAR", CAIRO_OPERATOR_CLEAR);
+ ENUM_MEMBER(operator_holder, "SOURCE", CAIRO_OPERATOR_SOURCE);
+ ENUM_MEMBER(operator_holder, "OVER", CAIRO_OPERATOR_OVER);
+ ENUM_MEMBER(operator_holder, "IN", CAIRO_OPERATOR_IN);
+ ENUM_MEMBER(operator_holder, "OUT", CAIRO_OPERATOR_OUT);
+ ENUM_MEMBER(operator_holder, "ATOP", CAIRO_OPERATOR_ATOP);
+ ENUM_MEMBER(operator_holder, "DEST", CAIRO_OPERATOR_DEST);
+ ENUM_MEMBER(operator_holder, "DEST_OVER", CAIRO_OPERATOR_DEST_OVER);
+ ENUM_MEMBER(operator_holder, "DEST_IN", CAIRO_OPERATOR_DEST_IN);
+ ENUM_MEMBER(operator_holder, "DEST_OUT", CAIRO_OPERATOR_DEST_OUT);
+ ENUM_MEMBER(operator_holder, "DEST_ATOP", CAIRO_OPERATOR_DEST_ATOP);
+ ENUM_MEMBER(operator_holder, "XOR", CAIRO_OPERATOR_XOR);
+ ENUM_MEMBER(operator_holder, "ADD", CAIRO_OPERATOR_ADD);
+ ENUM_MEMBER(operator_holder, "SATURATE", CAIRO_OPERATOR_SATURATE);
+
+ status_holder = seed_make_object(ctx, NULL, NULL);
+ seed_object_set_property(ctx, namespace_ref, "Status", status_holder);
+ ENUM_MEMBER(status_holder, "SUCCESS", CAIRO_STATUS_SUCCESS);
+ ENUM_MEMBER(status_holder, "NO_MEMORY", CAIRO_STATUS_NO_MEMORY);
+ ENUM_MEMBER(status_holder, "INVALID_RESTORE", CAIRO_STATUS_INVALID_RESTORE);
+ ENUM_MEMBER(status_holder, "INVALID_POP_GROUP",
+ CAIRO_STATUS_INVALID_POP_GROUP);
+ ENUM_MEMBER(status_holder, "NO_CURRENT_POINT",
+ CAIRO_STATUS_NO_CURRENT_POINT);
+ ENUM_MEMBER(status_holder, "INVALID_MATRIX", CAIRO_STATUS_INVALID_MATRIX);
+ ENUM_MEMBER(status_holder, "INVALID_STATUS", CAIRO_STATUS_INVALID_STATUS);
+ ENUM_MEMBER(status_holder, "NULL_POINTER", CAIRO_STATUS_NULL_POINTER);
+ ENUM_MEMBER(status_holder, "INVALID_STRING", CAIRO_STATUS_INVALID_STRING);
+ ENUM_MEMBER(status_holder, "INVALID_PATH_DATA",
+ CAIRO_STATUS_INVALID_PATH_DATA);
+ ENUM_MEMBER(status_holder, "READ_ERROR", CAIRO_STATUS_READ_ERROR);
+ ENUM_MEMBER(status_holder, "WRITE_ERROR", CAIRO_STATUS_WRITE_ERROR);
+ ENUM_MEMBER(status_holder, "SURFACE_FINISHED",
+ CAIRO_STATUS_SURFACE_FINISHED);
+ ENUM_MEMBER(status_holder, "SURFACE_TYPE_MISMATCH",
+ CAIRO_STATUS_SURFACE_TYPE_MISMATCH);
+ ENUM_MEMBER(status_holder, "PATTERN_TYPE_MISMATCH",
+ CAIRO_STATUS_PATTERN_TYPE_MISMATCH);
+ ENUM_MEMBER(status_holder, "INVALID_CONTENT", CAIRO_STATUS_INVALID_CONTENT);
+ ENUM_MEMBER(status_holder, "INVALID_FORMAT", CAIRO_STATUS_INVALID_FORMAT);
+ ENUM_MEMBER(status_holder, "INVALID_VISUAL", CAIRO_STATUS_INVALID_VISUAL);
+ ENUM_MEMBER(status_holder, "FILE_NOT_FOUND", CAIRO_STATUS_FILE_NOT_FOUND);
+ ENUM_MEMBER(status_holder, "INVALID_DASH", CAIRO_STATUS_INVALID_DASH);
+ ENUM_MEMBER(status_holder, "INVALID_DSC_COMMENT",
+ CAIRO_STATUS_INVALID_DSC_COMMENT);
+ ENUM_MEMBER(status_holder, "INVALID_INDEX", CAIRO_STATUS_INVALID_INDEX);
+ ENUM_MEMBER(status_holder, "CLIP_NOT_REPRESENTABLE",
+ CAIRO_STATUS_CLIP_NOT_REPRESENTABLE);
+ ENUM_MEMBER(status_holder, "TEMP_FILE_ERROR", CAIRO_STATUS_TEMP_FILE_ERROR);
+ ENUM_MEMBER(status_holder, "INVALID_STRIDE", CAIRO_STATUS_INVALID_STRIDE);
+ ENUM_MEMBER(status_holder, "FONT_TYPE_MISMATCH",
+ CAIRO_STATUS_FONT_TYPE_MISMATCH);
+ ENUM_MEMBER(status_holder, "USER_FONT_IMMUTABLE",
+ CAIRO_STATUS_USER_FONT_IMMUTABLE);
+ ENUM_MEMBER(status_holder, "USER_FONT_ERROR", CAIRO_STATUS_USER_FONT_ERROR);
+ ENUM_MEMBER(status_holder, "NEGATIVE_COUNT", CAIRO_STATUS_NEGATIVE_COUNT);
+ ENUM_MEMBER(status_holder, "INVALID_CLUSTERS",
+ CAIRO_STATUS_INVALID_CLUSTERS);
+ ENUM_MEMBER(status_holder, "INVALID_SLANT", CAIRO_STATUS_INVALID_SLANT);
+ ENUM_MEMBER(status_holder, "INVALID_WEIGHT", CAIRO_STATUS_INVALID_WEIGHT);
+
+ seed_create_function(ctx, "to_string", seed_cairo_status_to_string,
+ status_holder);
}
diff --git a/modules/cairo/seed-cairo-enums.h b/modules/cairo/seed-cairo-enums.h
index 4ae0b59..24c6943 100644
--- a/modules/cairo/seed-cairo-enums.h
+++ b/modules/cairo/seed-cairo-enums.h
@@ -1,5 +1,5 @@
#ifndef _SEED_CAIRO_ENUMS_H
#define _SEED_CAIRO_ENUMS_H
-void seed_define_cairo_enums (SeedContext ctx, SeedObject namespace_ref);
+void seed_define_cairo_enums(SeedContext ctx, SeedObject namespace_ref);
#endif
diff --git a/modules/cairo/seed-cairo-image-surface.c b/modules/cairo/seed-cairo-image-surface.c
index 1c68abf..ccc871a 100644
--- a/modules/cairo/seed-cairo-image-surface.c
+++ b/modules/cairo/seed-cairo-image-surface.c
@@ -23,131 +23,157 @@
#include "seed-cairo.h"
#include "seed-cairo-surface.h"
-#define CAIRO_SURFACE_PRIV(obj) ((cairo_surface_t *)seed_object_get_private(obj))
-
-#define CHECK_SURFACE(obj) ({ \
- if (!seed_object_is_of_class (ctx, obj, seed_cairo_image_surface_class)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Surface"); \
- return seed_make_undefined (ctx); \
- } \
- if (!seed_object_get_private (obj)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); \
- return seed_make_undefined (ctx);}})
-
-#define CHECK_THIS() if (!seed_object_get_private (this_object)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); \
- return seed_make_undefined (ctx);}
+#define CAIRO_SURFACE_PRIV(obj) \
+ ((cairo_surface_t*) seed_object_get_private(obj))
+
+#define CHECK_SURFACE(obj) \
+ ({ \
+ if (!seed_object_is_of_class(ctx, obj, \
+ seed_cairo_image_surface_class)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Object is not a Cairo Surface"); \
+ return seed_make_undefined(ctx); \
+ } \
+ if (!seed_object_get_private(obj)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo surface has been destroyed"); \
+ return seed_make_undefined(ctx); \
+ } \
+ })
+
+#define CHECK_THIS() \
+ if (!seed_object_get_private(this_object)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo surface has been destroyed"); \
+ return seed_make_undefined(ctx); \
+ }
SeedClass seed_cairo_image_surface_class;
SeedObject image_surface_constructor_ref;
-
static SeedObject
-seed_object_from_cairo_image_surface (SeedContext ctx, cairo_surface_t *surf)
+seed_object_from_cairo_image_surface(SeedContext ctx, cairo_surface_t* surf)
{
- SeedObject jsobj;
+ SeedObject jsobj;
- jsobj = cairo_surface_get_user_data (surf, seed_get_cairo_key());
- if (jsobj)
- return jsobj;
+ jsobj = cairo_surface_get_user_data(surf, seed_get_cairo_key());
+ if (jsobj)
+ return jsobj;
- jsobj = seed_make_object (ctx, seed_cairo_image_surface_class, surf);
- cairo_surface_set_user_data (surf, seed_get_cairo_key(), jsobj, seed_cairo_destroy_func);
- return jsobj;
+ jsobj = seed_make_object(ctx, seed_cairo_image_surface_class, surf);
+ cairo_surface_set_user_data(surf, seed_get_cairo_key(), jsobj,
+ seed_cairo_destroy_func);
+ return jsobj;
}
static SeedValue
-seed_cairo_image_surface_get_format (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_image_surface_get_format(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- CHECK_THIS();
- return seed_value_from_long (ctx, cairo_image_surface_get_format (seed_object_to_cairo_surface(ctx,
this_object, exception)), exception);
+ CHECK_THIS();
+ return seed_value_from_long(ctx,
+ cairo_image_surface_get_format(
+ seed_object_to_cairo_surface(ctx, this_object,
+ exception)),
+ exception);
}
static SeedValue
-seed_cairo_image_surface_get_width (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_image_surface_get_width(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- CHECK_THIS();
- return seed_value_from_int (ctx, cairo_image_surface_get_width (seed_object_to_cairo_surface(ctx,
this_object, exception)), exception);
+ CHECK_THIS();
+ return seed_value_from_int(ctx,
+ cairo_image_surface_get_width(
+ seed_object_to_cairo_surface(ctx, this_object,
+ exception)),
+ exception);
}
static SeedValue
-seed_cairo_image_surface_get_height (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_image_surface_get_height(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- CHECK_THIS();
- return seed_value_from_int (ctx, cairo_image_surface_get_height (seed_object_to_cairo_surface(ctx,
this_object, exception)), exception);
+ CHECK_THIS();
+ return seed_value_from_int(ctx,
+ cairo_image_surface_get_height(
+ seed_object_to_cairo_surface(ctx, this_object,
+ exception)),
+ exception);
}
static SeedValue
-seed_cairo_image_surface_get_stride (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_image_surface_get_stride(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- CHECK_THIS();
- return seed_value_from_int (ctx, cairo_image_surface_get_stride (seed_object_to_cairo_surface(ctx,
this_object, exception)), exception);
+ CHECK_THIS();
+ return seed_value_from_int(ctx,
+ cairo_image_surface_get_stride(
+ seed_object_to_cairo_surface(ctx, this_object,
+ exception)),
+ exception);
}
static SeedObject
-seed_cairo_construct_image_surface (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_cairo_construct_image_surface(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_surface_t *ret;
- gint width, height;
- cairo_format_t format;
- if (argument_count != 3)
- {
- EXPECTED_EXCEPTION("ImageSurface", "3 arguments");
+ cairo_surface_t* ret;
+ gint width, height;
+ cairo_format_t format;
+ if (argument_count != 3) {
+ EXPECTED_EXCEPTION("ImageSurface", "3 arguments");
}
- format = seed_value_to_long (ctx, arguments[0], exception);
- width = seed_value_to_int (ctx, arguments[1], exception);
- height = seed_value_to_int (ctx, arguments[2], exception);
- ret = cairo_image_surface_create (format, width, height);
+ format = seed_value_to_long(ctx, arguments[0], exception);
+ width = seed_value_to_int(ctx, arguments[1], exception);
+ height = seed_value_to_int(ctx, arguments[2], exception);
+ ret = cairo_image_surface_create(format, width, height);
- return seed_object_from_cairo_image_surface (ctx, ret);
+ return seed_object_from_cairo_image_surface(ctx, ret);
}
seed_static_value image_surface_values[] = {
- {"format", seed_cairo_image_surface_get_format, 0, SEED_PROPERTY_ATTRIBUTE_READ_ONLY |
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"width", seed_cairo_image_surface_get_width, 0, SEED_PROPERTY_ATTRIBUTE_READ_ONLY |
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"height", seed_cairo_image_surface_get_height, 0, SEED_PROPERTY_ATTRIBUTE_READ_ONLY |
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"stride", seed_cairo_image_surface_get_stride, 0, SEED_PROPERTY_ATTRIBUTE_READ_ONLY |
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {0, 0, 0, 0}
+ { "format", seed_cairo_image_surface_get_format, 0,
+ SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "width", seed_cairo_image_surface_get_width, 0,
+ SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "height", seed_cairo_image_surface_get_height, 0,
+ SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "stride", seed_cairo_image_surface_get_stride, 0,
+ SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { 0, 0, 0, 0 }
};
-
-
-
void
-seed_define_cairo_image_surface (SeedContext ctx,
- SeedObject namespace_ref)
+seed_define_cairo_image_surface(SeedContext ctx, SeedObject namespace_ref)
{
- seed_class_definition image_def = seed_empty_class;
- // TODO: FIX
- seed_static_function webkit_fail = {0,0,0};
-
- image_def.class_name = "ImageSurface";
- image_def.static_values = image_surface_values;
- image_def.parent_class = seed_get_cairo_surface_class ();
- // FAIL
- image_def.static_functions = &webkit_fail;
- seed_cairo_image_surface_class = seed_create_class (&image_def);
-
- image_surface_constructor_ref = seed_make_constructor (ctx,
- NULL,
- //seed_cairo_image_surface_class,
- seed_cairo_construct_image_surface);
- seed_object_set_property (ctx, namespace_ref, "ImageSurface", image_surface_constructor_ref);
+ seed_class_definition image_def = seed_empty_class;
+ // TODO: FIX
+ seed_static_function webkit_fail = { 0, 0, 0 };
+
+ image_def.class_name = "ImageSurface";
+ image_def.static_values = image_surface_values;
+ image_def.parent_class = seed_get_cairo_surface_class();
+ // FAIL
+ image_def.static_functions = &webkit_fail;
+ seed_cairo_image_surface_class = seed_create_class(&image_def);
+
+ image_surface_constructor_ref
+ = seed_make_constructor(ctx, NULL,
+ // seed_cairo_image_surface_class,
+ seed_cairo_construct_image_surface);
+ seed_object_set_property(ctx, namespace_ref, "ImageSurface",
+ image_surface_constructor_ref);
}
diff --git a/modules/cairo/seed-cairo-image-surface.h b/modules/cairo/seed-cairo-image-surface.h
index f0d2691..9e54bcc 100644
--- a/modules/cairo/seed-cairo-image-surface.h
+++ b/modules/cairo/seed-cairo-image-surface.h
@@ -4,6 +4,6 @@
#include <seed.h>
#include <cairo/cairo.h>
-void seed_define_cairo_image_surface (SeedContext ctx, SeedObject namespace_ref);
+void seed_define_cairo_image_surface(SeedContext ctx, SeedObject namespace_ref);
#endif
diff --git a/modules/cairo/seed-cairo-matrix.c b/modules/cairo/seed-cairo-matrix.c
index af12285..7ff0af1 100644
--- a/modules/cairo/seed-cairo-matrix.c
+++ b/modules/cairo/seed-cairo-matrix.c
@@ -16,7 +16,7 @@
*
* Copyright (C) Robert Carr 2009 <carrr rpi edu>
*/
-
+
#include <seed.h>
#include <cairo/cairo.h>
@@ -24,296 +24,307 @@
SeedClass seed_matrix_class;
SeedValue
-seed_value_from_cairo_matrix (SeedContext ctx,
- const cairo_matrix_t *matrix,
- SeedException *exception)
+seed_value_from_cairo_matrix(SeedContext ctx,
+ const cairo_matrix_t* matrix,
+ SeedException* exception)
{
- SeedValue elems[6];
+ SeedValue elems[6];
- elems[0] = seed_value_from_double(ctx, matrix->xx, exception);
- elems[1] = seed_value_from_double(ctx, matrix->yx, exception);
- elems[2] = seed_value_from_double(ctx, matrix->xy, exception);
- elems[3] = seed_value_from_double(ctx, matrix->yy, exception);
- elems[4] = seed_value_from_double(ctx, matrix->x0, exception);
- elems[5] = seed_value_from_double(ctx, matrix->y0, exception);
+ elems[0] = seed_value_from_double(ctx, matrix->xx, exception);
+ elems[1] = seed_value_from_double(ctx, matrix->yx, exception);
+ elems[2] = seed_value_from_double(ctx, matrix->xy, exception);
+ elems[3] = seed_value_from_double(ctx, matrix->yy, exception);
+ elems[4] = seed_value_from_double(ctx, matrix->x0, exception);
+ elems[5] = seed_value_from_double(ctx, matrix->y0, exception);
- return seed_make_array (ctx, elems, 6, exception);
+ return seed_make_array(ctx, elems, 6, exception);
}
gboolean
-seed_value_to_cairo_matrix (SeedContext ctx,
- SeedValue value,
- cairo_matrix_t *matrix,
- SeedException *exception)
+seed_value_to_cairo_matrix(SeedContext ctx,
+ SeedValue value,
+ cairo_matrix_t* matrix,
+ SeedException* exception)
{
- if (!seed_value_is_object (ctx, value))
- return FALSE;
-
- matrix->xx = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 0,
exception), exception);
- matrix->yx = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 1,
exception), exception);
- matrix->xy = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 2,
exception), exception);
- matrix->yy = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 3,
exception), exception);
- matrix->x0 = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 4,
exception), exception);
- matrix->y0 = seed_value_to_double (ctx, seed_object_get_property_at_index (ctx, (SeedObject) value, 5,
exception), exception);
-
- return TRUE;
+ if (!seed_value_is_object(ctx, value))
+ return FALSE;
+
+ matrix->xx = seed_value_to_double(
+ ctx,
+ seed_object_get_property_at_index(ctx, (SeedObject) value, 0, exception),
+ exception);
+ matrix->yx = seed_value_to_double(
+ ctx,
+ seed_object_get_property_at_index(ctx, (SeedObject) value, 1, exception),
+ exception);
+ matrix->xy = seed_value_to_double(
+ ctx,
+ seed_object_get_property_at_index(ctx, (SeedObject) value, 2, exception),
+ exception);
+ matrix->yy = seed_value_to_double(
+ ctx,
+ seed_object_get_property_at_index(ctx, (SeedObject) value, 3, exception),
+ exception);
+ matrix->x0 = seed_value_to_double(
+ ctx,
+ seed_object_get_property_at_index(ctx, (SeedObject) value, 4, exception),
+ exception);
+ matrix->y0 = seed_value_to_double(
+ ctx,
+ seed_object_get_property_at_index(ctx, (SeedObject) value, 5, exception),
+ exception);
+
+ return TRUE;
}
// Should probably be a property?
static SeedValue
-seed_cairo_matrix_init_identity (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_matrix_init_identity(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_matrix_t m;
+ cairo_matrix_t m;
- cairo_matrix_init_identity (&m);
- return seed_value_from_cairo_matrix (ctx, &m, exception);
+ cairo_matrix_init_identity(&m);
+ return seed_value_from_cairo_matrix(ctx, &m, exception);
}
static SeedValue
-seed_cairo_matrix_init_translate (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_matrix_init_translate(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x, y;
- cairo_matrix_t m;
+ gdouble x, y;
+ cairo_matrix_t m;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("init_translate", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("init_translate", "2 arguments");
}
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
- cairo_matrix_init_translate (&m, x, y);
+ cairo_matrix_init_translate(&m, x, y);
- return seed_value_from_cairo_matrix (ctx, &m, exception);
+ return seed_value_from_cairo_matrix(ctx, &m, exception);
}
static SeedValue
-seed_cairo_matrix_translate (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_matrix_translate(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x, y;
- cairo_matrix_t m;
+ gdouble x, y;
+ cairo_matrix_t m;
- if (argument_count != 3)
- {
- EXPECTED_EXCEPTION("translate", "3 arguments");
+ if (argument_count != 3) {
+ EXPECTED_EXCEPTION("translate", "3 arguments");
}
- if (!seed_value_to_cairo_matrix (ctx, arguments[0], &m, exception))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "translate needs an array [xx, yx, xy, yy, x0,
y0]");
+ if (!seed_value_to_cairo_matrix(ctx, arguments[0], &m, exception)) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "translate needs an array [xx, yx, xy, yy, x0, y0]");
}
- x = seed_value_to_double (ctx, arguments[1], exception);
- y = seed_value_to_double (ctx, arguments[2], exception);
+ x = seed_value_to_double(ctx, arguments[1], exception);
+ y = seed_value_to_double(ctx, arguments[2], exception);
- cairo_matrix_translate (&m, x, y);
+ cairo_matrix_translate(&m, x, y);
- return seed_value_from_cairo_matrix (ctx, &m, exception);
+ return seed_value_from_cairo_matrix(ctx, &m, exception);
}
static SeedValue
-seed_cairo_matrix_init_scale (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_matrix_init_scale(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x, y;
- cairo_matrix_t m;
+ gdouble x, y;
+ cairo_matrix_t m;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("init_scale", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("init_scale", "2 arguments");
}
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
- cairo_matrix_init_scale (&m, x, y);
+ cairo_matrix_init_scale(&m, x, y);
- return seed_value_from_cairo_matrix (ctx, &m, exception);
+ return seed_value_from_cairo_matrix(ctx, &m, exception);
}
static SeedValue
-seed_cairo_matrix_scale (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_matrix_scale(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x, y;
- cairo_matrix_t m;
+ gdouble x, y;
+ cairo_matrix_t m;
- if (argument_count != 3)
- {
- EXPECTED_EXCEPTION("scale", "3 arguments");
+ if (argument_count != 3) {
+ EXPECTED_EXCEPTION("scale", "3 arguments");
}
- if (!seed_value_to_cairo_matrix (ctx, arguments[0], &m, exception))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "scale needs an array [xx, yx, xy, yy, x0, y0]");
+ if (!seed_value_to_cairo_matrix(ctx, arguments[0], &m, exception)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "scale needs an array [xx, yx, xy, yy, x0, y0]");
}
- x = seed_value_to_double (ctx, arguments[1], exception);
- y = seed_value_to_double (ctx, arguments[2], exception);
+ x = seed_value_to_double(ctx, arguments[1], exception);
+ y = seed_value_to_double(ctx, arguments[2], exception);
- cairo_matrix_scale (&m, x, y);
+ cairo_matrix_scale(&m, x, y);
- return seed_value_from_cairo_matrix (ctx, &m, exception);
+ return seed_value_from_cairo_matrix(ctx, &m, exception);
}
static SeedValue
-seed_cairo_matrix_init_rotate (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_matrix_init_rotate(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble angle;
- cairo_matrix_t m;
+ gdouble angle;
+ cairo_matrix_t m;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("init_rotate", "1 arguments");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("init_rotate", "1 arguments");
}
- angle = seed_value_to_double (ctx, arguments[0], exception);
- cairo_matrix_init_rotate (&m, angle);
+ angle = seed_value_to_double(ctx, arguments[0], exception);
+ cairo_matrix_init_rotate(&m, angle);
- return seed_value_from_cairo_matrix (ctx, &m, exception);
+ return seed_value_from_cairo_matrix(ctx, &m, exception);
}
static SeedValue
-seed_cairo_matrix_rotate (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_matrix_rotate(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble angle;
- cairo_matrix_t m;
+ gdouble angle;
+ cairo_matrix_t m;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("rotate", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("rotate", "2 arguments");
}
- if (!seed_value_to_cairo_matrix (ctx, arguments[0], &m, exception))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "rotate needs an array [xx, yx, xy, yy, x0,
y0]");
+ if (!seed_value_to_cairo_matrix(ctx, arguments[0], &m, exception)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "rotate needs an array [xx, yx, xy, yy, x0, y0]");
}
- angle = seed_value_to_double (ctx, arguments[1], exception);
+ angle = seed_value_to_double(ctx, arguments[1], exception);
- cairo_matrix_rotate (&m, angle);
+ cairo_matrix_rotate(&m, angle);
- return seed_value_from_cairo_matrix (ctx, &m, exception);
+ return seed_value_from_cairo_matrix(ctx, &m, exception);
}
-
static SeedValue
-seed_cairo_matrix_transform_distance (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_matrix_transform_distance(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue ret[2];
- gdouble x, y;
- cairo_matrix_t m;
+ SeedValue ret[2];
+ gdouble x, y;
+ cairo_matrix_t m;
- if (argument_count != 3)
- {
- EXPECTED_EXCEPTION("transform_distance", "3 arguments");
+ if (argument_count != 3) {
+ EXPECTED_EXCEPTION("transform_distance", "3 arguments");
}
- if (!seed_value_to_cairo_matrix (ctx, arguments[0], &m, exception))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "transform_distance needs an array [xx, yx, xy,
yy, x0, y0]");
+ if (!seed_value_to_cairo_matrix(ctx, arguments[0], &m, exception)) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "transform_distance needs an array [xx, yx, xy, yy, x0, y0]");
}
- x = seed_value_to_double (ctx, arguments[1], exception);
- y = seed_value_to_double (ctx, arguments[2], exception);
+ x = seed_value_to_double(ctx, arguments[1], exception);
+ y = seed_value_to_double(ctx, arguments[2], exception);
- cairo_matrix_transform_distance (&m, &x, &y);
+ cairo_matrix_transform_distance(&m, &x, &y);
- ret[0] = seed_value_from_double (ctx, x, exception);
- ret[1] = seed_value_from_double (ctx, y, exception);
+ ret[0] = seed_value_from_double(ctx, x, exception);
+ ret[1] = seed_value_from_double(ctx, y, exception);
- return seed_make_array (ctx, ret, 2, exception);
+ return seed_make_array(ctx, ret, 2, exception);
}
static SeedValue
-seed_cairo_matrix_transform_point (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_matrix_transform_point(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue ret[2];
- gdouble x, y;
- cairo_matrix_t m;
+ SeedValue ret[2];
+ gdouble x, y;
+ cairo_matrix_t m;
- if (argument_count != 3)
- {
- EXPECTED_EXCEPTION("transform_point", "3 arguments");
+ if (argument_count != 3) {
+ EXPECTED_EXCEPTION("transform_point", "3 arguments");
}
- if (!seed_value_to_cairo_matrix (ctx, arguments[0], &m, exception))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "transform_point needs an array [xx, yx, xy, yy,
x0, y0]");
+ if (!seed_value_to_cairo_matrix(ctx, arguments[0], &m, exception)) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "transform_point needs an array [xx, yx, xy, yy, x0, y0]");
}
- x = seed_value_to_double (ctx, arguments[1], exception);
- y = seed_value_to_double (ctx, arguments[2], exception);
+ x = seed_value_to_double(ctx, arguments[1], exception);
+ y = seed_value_to_double(ctx, arguments[2], exception);
- cairo_matrix_transform_point (&m, &x, &y);
+ cairo_matrix_transform_point(&m, &x, &y);
- ret[0] = seed_value_from_double (ctx, x, exception);
- ret[1] = seed_value_from_double (ctx, y, exception);
+ ret[0] = seed_value_from_double(ctx, x, exception);
+ ret[1] = seed_value_from_double(ctx, y, exception);
- return seed_make_array (ctx, ret, 2, exception);
+ return seed_make_array(ctx, ret, 2, exception);
}
-seed_static_function matrix_funcs[] = {
- {"init_identity", seed_cairo_matrix_init_identity, 0},
- {"init_translate", seed_cairo_matrix_init_translate, 0},
- {"init_scale", seed_cairo_matrix_init_scale, 0},
- {"init_rotate", seed_cairo_matrix_init_rotate, 0},
- {"translate", seed_cairo_matrix_translate, 0},
- {"scale", seed_cairo_matrix_scale, 0},
- {"rotate", seed_cairo_matrix_rotate, 0},
- {"transform_point", seed_cairo_matrix_transform_point, 0},
- {"transform_distance", seed_cairo_matrix_transform_distance, 0},
- {0, 0, 0}
-};
+seed_static_function matrix_funcs[]
+ = { { "init_identity", seed_cairo_matrix_init_identity, 0 },
+ { "init_translate", seed_cairo_matrix_init_translate, 0 },
+ { "init_scale", seed_cairo_matrix_init_scale, 0 },
+ { "init_rotate", seed_cairo_matrix_init_rotate, 0 },
+ { "translate", seed_cairo_matrix_translate, 0 },
+ { "scale", seed_cairo_matrix_scale, 0 },
+ { "rotate", seed_cairo_matrix_rotate, 0 },
+ { "transform_point", seed_cairo_matrix_transform_point, 0 },
+ { "transform_distance", seed_cairo_matrix_transform_distance, 0 },
+ { 0, 0, 0 } };
void
-seed_define_cairo_matrix (SeedContext ctx,
- SeedObject namespace_ref)
+seed_define_cairo_matrix(SeedContext ctx, SeedObject namespace_ref)
{
- seed_class_definition matrix_def = seed_empty_class;
+ seed_class_definition matrix_def = seed_empty_class;
- matrix_def.class_name = "Matrix";
- matrix_def.static_functions = matrix_funcs;
- seed_matrix_class = seed_create_class (&matrix_def);
+ matrix_def.class_name = "Matrix";
+ matrix_def.static_functions = matrix_funcs;
+ seed_matrix_class = seed_create_class(&matrix_def);
- seed_object_set_property (ctx, namespace_ref, "Matrix", seed_make_object (ctx, seed_matrix_class, NULL));
+ seed_object_set_property(ctx, namespace_ref, "Matrix",
+ seed_make_object(ctx, seed_matrix_class, NULL));
}
diff --git a/modules/cairo/seed-cairo-matrix.h b/modules/cairo/seed-cairo-matrix.h
index 4fa23d3..0c57d4c 100644
--- a/modules/cairo/seed-cairo-matrix.h
+++ b/modules/cairo/seed-cairo-matrix.h
@@ -3,12 +3,15 @@
#include <seed.h>
#include <cairo/cairo.h>
-void seed_define_cairo_matrix (SeedContext ctx, SeedObject namespace_ref);
+void seed_define_cairo_matrix(SeedContext ctx, SeedObject namespace_ref);
-gboolean seed_value_to_cairo_matrix (SeedContext ctx, SeedValue value,
- cairo_matrix_t *matrix, SeedException *exception);
+gboolean seed_value_to_cairo_matrix(SeedContext ctx,
+ SeedValue value,
+ cairo_matrix_t* matrix,
+ SeedException* exception);
-SeedValue seed_value_from_cairo_matrix (SeedContext ctx, const cairo_matrix_t *matrix,
- SeedException *exception);
+SeedValue seed_value_from_cairo_matrix(SeedContext ctx,
+ const cairo_matrix_t* matrix,
+ SeedException* exception);
#endif
diff --git a/modules/cairo/seed-cairo-pattern.c b/modules/cairo/seed-cairo-pattern.c
index 5d664f7..c7291b6 100644
--- a/modules/cairo/seed-cairo-pattern.c
+++ b/modules/cairo/seed-cairo-pattern.c
@@ -23,193 +23,206 @@
#include "seed-cairo.h"
#include "seed-cairo-matrix.h"
-#define CAIRO_PATTERN_PRIV(obj) ((cairo_pattern_t *)seed_object_get_private(obj))
-
-#define CHECK_PATTERN(obj, res) ({ \
- if (!seed_object_is_of_class (ctx, obj, seed_cairo_pattern_class)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Pattern"); \
- return seed_make_##res (ctx); \
- } \
- if (!seed_object_get_private (obj)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo pattern has been destroyed"); \
- return seed_make_##res (ctx);}})
-
-#define CHECK_THIS() if (!seed_object_get_private (this_object)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo pattern has been destroyed"); \
- return seed_make_undefined (ctx);}
-
-#define CHECK_THIS_BOOL(res) if (!seed_object_get_private (this_object)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo pattern has been destroyed"); return FALSE;}
-
-
+#define CAIRO_PATTERN_PRIV(obj) \
+ ((cairo_pattern_t*) seed_object_get_private(obj))
+
+#define CHECK_PATTERN(obj, res) \
+ ({ \
+ if (!seed_object_is_of_class(ctx, obj, seed_cairo_pattern_class)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Object is not a Cairo Pattern"); \
+ return seed_make_##res(ctx); \
+ } \
+ if (!seed_object_get_private(obj)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo pattern has been destroyed"); \
+ return seed_make_##res(ctx); \
+ } \
+ })
+
+#define CHECK_THIS() \
+ if (!seed_object_get_private(this_object)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo pattern has been destroyed"); \
+ return seed_make_undefined(ctx); \
+ }
+#define CHECK_THIS_BOOL(res) \
+ if (!seed_object_get_private(this_object)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo pattern has been destroyed"); \
+ return FALSE; \
+ }
SeedClass seed_cairo_pattern_class;
SeedClass
-seed_get_cairo_pattern_class ()
+seed_get_cairo_pattern_class()
{
- return seed_cairo_pattern_class;
+ return seed_cairo_pattern_class;
}
static void
-seed_cairo_pattern_finalize (SeedObject obj)
+seed_cairo_pattern_finalize(SeedObject obj)
{
- cairo_pattern_t *s = CAIRO_PATTERN_PRIV(obj);
- if (s)
- {
- cairo_pattern_set_user_data (s, seed_get_cairo_key(), NULL, NULL);
- cairo_pattern_destroy (s);
+ cairo_pattern_t* s = CAIRO_PATTERN_PRIV(obj);
+ if (s) {
+ cairo_pattern_set_user_data(s, seed_get_cairo_key(), NULL, NULL);
+ cairo_pattern_destroy(s);
}
}
-cairo_pattern_t *
-seed_object_to_cairo_pattern (SeedContext ctx, SeedObject obj, SeedException *exception)
+cairo_pattern_t*
+seed_object_to_cairo_pattern(SeedContext ctx,
+ SeedObject obj,
+ SeedException* exception)
{
- if (seed_object_is_of_class (ctx, obj, seed_cairo_pattern_class))
- return CAIRO_PATTERN_PRIV (obj);
- seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Pattern");
- return NULL;
+ if (seed_object_is_of_class(ctx, obj, seed_cairo_pattern_class))
+ return CAIRO_PATTERN_PRIV(obj);
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Object is not a Cairo Pattern");
+ return NULL;
}
SeedObject
-seed_object_from_cairo_pattern (SeedContext ctx, cairo_pattern_t *pat)
+seed_object_from_cairo_pattern(SeedContext ctx, cairo_pattern_t* pat)
{
- SeedObject jsobj;
+ SeedObject jsobj;
- jsobj = cairo_pattern_get_user_data (pat, seed_get_cairo_key());
- if (jsobj)
- return jsobj;
+ jsobj = cairo_pattern_get_user_data(pat, seed_get_cairo_key());
+ if (jsobj)
+ return jsobj;
- jsobj = seed_make_object (ctx, seed_cairo_pattern_class, pat);
- cairo_pattern_set_user_data (pat, seed_get_cairo_key(), jsobj, seed_cairo_destroy_func);
- return jsobj;
+ jsobj = seed_make_object(ctx, seed_cairo_pattern_class, pat);
+ cairo_pattern_set_user_data(pat, seed_get_cairo_key(), jsobj,
+ seed_cairo_destroy_func);
+ return jsobj;
}
static SeedObject
-seed_cairo_construct_linear_gradient (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_cairo_construct_linear_gradient(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x0,y0,x1,y1;
+ gdouble x0, y0, x1, y1;
- if (argument_count != 4)
- {
- EXPECTED_EXCEPTION("LinearGradient constructor", "4 arguments");
+ if (argument_count != 4) {
+ EXPECTED_EXCEPTION("LinearGradient constructor", "4 arguments");
}
- x0 = seed_value_to_double (ctx, arguments[0], exception);
- y0 = seed_value_to_double (ctx, arguments[1], exception);
- x1 = seed_value_to_double (ctx, arguments[2], exception);
- y1 = seed_value_to_double (ctx, arguments[3], exception);
+ x0 = seed_value_to_double(ctx, arguments[0], exception);
+ y0 = seed_value_to_double(ctx, arguments[1], exception);
+ x1 = seed_value_to_double(ctx, arguments[2], exception);
+ y1 = seed_value_to_double(ctx, arguments[3], exception);
- return seed_object_from_cairo_pattern (ctx, cairo_pattern_create_linear (x0, y0, x1, y1));
+ return seed_object_from_cairo_pattern(ctx,
+ cairo_pattern_create_linear(x0, y0,
+ x1, y1));
}
static SeedObject
-seed_cairo_construct_radial_gradient (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_cairo_construct_radial_gradient(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble cx0, cy0, r0, cx1, cy1, r1;
+ gdouble cx0, cy0, r0, cx1, cy1, r1;
- if (argument_count != 6)
- {
- EXPECTED_EXCEPTION("RadialGradient constructor", "6 arguments");
+ if (argument_count != 6) {
+ EXPECTED_EXCEPTION("RadialGradient constructor", "6 arguments");
}
- cx0 = seed_value_to_double (ctx, arguments[0], exception);
- cy0 = seed_value_to_double (ctx, arguments[1], exception);
- r0 = seed_value_to_double (ctx, arguments[2], exception);
- cx1 = seed_value_to_double (ctx, arguments[3], exception);
- cy1 = seed_value_to_double (ctx, arguments[4], exception);
- r1 = seed_value_to_double (ctx, arguments[5], exception);
-
+ cx0 = seed_value_to_double(ctx, arguments[0], exception);
+ cy0 = seed_value_to_double(ctx, arguments[1], exception);
+ r0 = seed_value_to_double(ctx, arguments[2], exception);
+ cx1 = seed_value_to_double(ctx, arguments[3], exception);
+ cy1 = seed_value_to_double(ctx, arguments[4], exception);
+ r1 = seed_value_to_double(ctx, arguments[5], exception);
- return seed_object_from_cairo_pattern (ctx, cairo_pattern_create_radial (cx0, cy0, r0, cx1, cy1, r1));
+ return seed_object_from_cairo_pattern(
+ ctx, cairo_pattern_create_radial(cx0, cy0, r0, cx1, cy1, r1));
}
static SeedValue
-seed_cairo_pattern_add_color_stop_rgb (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_pattern_add_color_stop_rgb(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble offset, r, g, b;
- cairo_pattern_t *pat;
- CHECK_THIS();
- if (argument_count != 4)
- {
- EXPECTED_EXCEPTION("add_color_stop_rgb", "4 arguments");
+ gdouble offset, r, g, b;
+ cairo_pattern_t* pat;
+ CHECK_THIS();
+ if (argument_count != 4) {
+ EXPECTED_EXCEPTION("add_color_stop_rgb", "4 arguments");
}
- pat = seed_object_get_private (this_object);
- offset = seed_value_to_double (ctx, arguments[0], exception);
- r = seed_value_to_double (ctx, arguments[1], exception);
- g = seed_value_to_double (ctx, arguments[2], exception);
- b = seed_value_to_double (ctx, arguments[3], exception);
+ pat = seed_object_get_private(this_object);
+ offset = seed_value_to_double(ctx, arguments[0], exception);
+ r = seed_value_to_double(ctx, arguments[1], exception);
+ g = seed_value_to_double(ctx, arguments[2], exception);
+ b = seed_value_to_double(ctx, arguments[3], exception);
- cairo_pattern_add_color_stop_rgb (pat, offset, r, g, b);
+ cairo_pattern_add_color_stop_rgb(pat, offset, r, g, b);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_pattern_add_color_stop_rgba (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_pattern_add_color_stop_rgba(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble offset, r, g, b, a;
- cairo_pattern_t *pat;
- CHECK_THIS();
- if (argument_count != 5)
- {
- EXPECTED_EXCEPTION("add_color_stop_rgba", "5 arguments");
+ gdouble offset, r, g, b, a;
+ cairo_pattern_t* pat;
+ CHECK_THIS();
+ if (argument_count != 5) {
+ EXPECTED_EXCEPTION("add_color_stop_rgba", "5 arguments");
}
- pat = seed_object_get_private (this_object);
- offset = seed_value_to_double (ctx, arguments[0], exception);
- r = seed_value_to_double (ctx, arguments[1], exception);
- g = seed_value_to_double (ctx, arguments[2], exception);
- b = seed_value_to_double (ctx, arguments[3], exception);
- a = seed_value_to_double (ctx, arguments[4], exception);
+ pat = seed_object_get_private(this_object);
+ offset = seed_value_to_double(ctx, arguments[0], exception);
+ r = seed_value_to_double(ctx, arguments[1], exception);
+ g = seed_value_to_double(ctx, arguments[2], exception);
+ b = seed_value_to_double(ctx, arguments[3], exception);
+ a = seed_value_to_double(ctx, arguments[4], exception);
- cairo_pattern_add_color_stop_rgba (pat, offset, r, g, b, a);
+ cairo_pattern_add_color_stop_rgba(pat, offset, r, g, b, a);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
-seed_static_function pattern_funcs[] = {
- {"add_color_stop_rgb", seed_cairo_pattern_add_color_stop_rgb, 0},
- {"add_color_stop_rgba", seed_cairo_pattern_add_color_stop_rgba, 0},
- {0,0,0}
-};
+seed_static_function pattern_funcs[]
+ = { { "add_color_stop_rgb", seed_cairo_pattern_add_color_stop_rgb, 0 },
+ { "add_color_stop_rgba", seed_cairo_pattern_add_color_stop_rgba, 0 },
+ { 0, 0, 0 } };
void
-seed_define_cairo_pattern (SeedContext ctx,
- SeedObject namespace_ref)
+seed_define_cairo_pattern(SeedContext ctx, SeedObject namespace_ref)
{
- SeedObject linear_constructor, radial_constructor;
- seed_class_definition pattern_def = seed_empty_class;
+ SeedObject linear_constructor, radial_constructor;
+ seed_class_definition pattern_def = seed_empty_class;
- pattern_def.class_name = "Pattern";
- pattern_def.finalize = seed_cairo_pattern_finalize;
- pattern_def.static_functions = pattern_funcs;
+ pattern_def.class_name = "Pattern";
+ pattern_def.finalize = seed_cairo_pattern_finalize;
+ pattern_def.static_functions = pattern_funcs;
- seed_cairo_pattern_class = seed_create_class (&pattern_def);
+ seed_cairo_pattern_class = seed_create_class(&pattern_def);
- linear_constructor = seed_make_constructor (ctx, NULL, seed_cairo_construct_linear_gradient);
- seed_object_set_property(ctx, namespace_ref, "LinearGradient", linear_constructor);
+ linear_constructor
+ = seed_make_constructor(ctx, NULL, seed_cairo_construct_linear_gradient);
+ seed_object_set_property(ctx, namespace_ref, "LinearGradient",
+ linear_constructor);
- radial_constructor = seed_make_constructor (ctx, NULL, seed_cairo_construct_radial_gradient);
- seed_object_set_property(ctx, namespace_ref, "RadialGradient", radial_constructor);
+ radial_constructor
+ = seed_make_constructor(ctx, NULL, seed_cairo_construct_radial_gradient);
+ seed_object_set_property(ctx, namespace_ref, "RadialGradient",
+ radial_constructor);
}
diff --git a/modules/cairo/seed-cairo-pattern.h b/modules/cairo/seed-cairo-pattern.h
index 427215a..db793d4 100644
--- a/modules/cairo/seed-cairo-pattern.h
+++ b/modules/cairo/seed-cairo-pattern.h
@@ -4,18 +4,15 @@
#include <seed.h>
#include <cairo/cairo.h>
-SeedClass
-seed_get_cairo_pattern_class ();
+SeedClass seed_get_cairo_pattern_class();
-cairo_pattern_t *
-seed_object_to_cairo_pattern (SeedContext ctx, SeedObject obj, SeedException *exception);
+cairo_pattern_t* seed_object_to_cairo_pattern(SeedContext ctx,
+ SeedObject obj,
+ SeedException* exception);
-SeedObject
-seed_object_from_cairo_pattern (SeedContext ctx, cairo_pattern_t *pat);
-
-void
-seed_define_cairo_pattern (SeedContext ctx,
- SeedObject namespace_ref);
+SeedObject seed_object_from_cairo_pattern(SeedContext ctx,
+ cairo_pattern_t* pat);
+void seed_define_cairo_pattern(SeedContext ctx, SeedObject namespace_ref);
#endif
diff --git a/modules/cairo/seed-cairo-pdf-surface.c b/modules/cairo/seed-cairo-pdf-surface.c
index 4c6648d..d63c892 100644
--- a/modules/cairo/seed-cairo-pdf-surface.c
+++ b/modules/cairo/seed-cairo-pdf-surface.c
@@ -24,116 +24,116 @@
#include "seed-cairo.h"
#include "seed-cairo-surface.h"
-#define CAIRO_SURFACE_PRIV(obj) ((cairo_surface_t *)seed_object_get_private(obj))
-
-#define CHECK_SURFACE(obj) ({ \
- if (!seed_object_is_of_class (ctx, obj, seed_cairo_pdf_surface_class)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Surface"); \
- return seed_make_undefined (ctx); \
- } \
- if (!seed_object_get_private (obj)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); \
- return seed_make_undefined (ctx);}})
-
-#define CHECK_THIS() if (!seed_object_get_private (this_object)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); \
- return seed_make_undefined (ctx);}
+#define CAIRO_SURFACE_PRIV(obj) \
+ ((cairo_surface_t*) seed_object_get_private(obj))
+
+#define CHECK_SURFACE(obj) \
+ ({ \
+ if (!seed_object_is_of_class(ctx, obj, \
+ seed_cairo_pdf_surface_class)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Object is not a Cairo Surface"); \
+ return seed_make_undefined(ctx); \
+ } \
+ if (!seed_object_get_private(obj)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo surface has been destroyed"); \
+ return seed_make_undefined(ctx); \
+ } \
+ })
+
+#define CHECK_THIS() \
+ if (!seed_object_get_private(this_object)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo surface has been destroyed"); \
+ return seed_make_undefined(ctx); \
+ }
SeedClass seed_cairo_pdf_surface_class;
SeedObject pdf_surface_constructor_ref;
-
static SeedObject
-seed_object_from_cairo_pdf_surface (SeedContext ctx, cairo_surface_t *surf)
+seed_object_from_cairo_pdf_surface(SeedContext ctx, cairo_surface_t* surf)
{
- SeedObject jsobj;
+ SeedObject jsobj;
- jsobj = cairo_surface_get_user_data (surf, seed_get_cairo_key());
- if (jsobj)
- return jsobj;
+ jsobj = cairo_surface_get_user_data(surf, seed_get_cairo_key());
+ if (jsobj)
+ return jsobj;
- jsobj = seed_make_object (ctx, seed_cairo_pdf_surface_class, surf);
- cairo_surface_set_user_data (surf, seed_get_cairo_key(), jsobj, seed_cairo_destroy_func);
- return jsobj;
+ jsobj = seed_make_object(ctx, seed_cairo_pdf_surface_class, surf);
+ cairo_surface_set_user_data(surf, seed_get_cairo_key(), jsobj,
+ seed_cairo_destroy_func);
+ return jsobj;
}
static SeedValue
-seed_cairo_pdf_surface_set_size (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_pdf_surface_set_size(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_surface_t *surf;
- gdouble x, y;
+ cairo_surface_t* surf;
+ gdouble x, y;
- CHECK_THIS();
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("set_size", "2 arguments");
+ CHECK_THIS();
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("set_size", "2 arguments");
}
- surf = seed_object_get_private (this_object);
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
+ surf = seed_object_get_private(this_object);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
- cairo_pdf_surface_set_size (surf, x, y);
+ cairo_pdf_surface_set_size(surf, x, y);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
-
static SeedObject
-seed_cairo_construct_pdf_surface (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_cairo_construct_pdf_surface(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_surface_t *ret;
- gchar *filename = NULL;
- gdouble width, height;
- if (argument_count != 3)
- {
- EXPECTED_EXCEPTION("PDFSurface", "3 arguments");
+ cairo_surface_t* ret;
+ gchar* filename = NULL;
+ gdouble width, height;
+ if (argument_count != 3) {
+ EXPECTED_EXCEPTION("PDFSurface", "3 arguments");
}
- if (!seed_value_is_null (ctx, arguments[0]))
- filename = seed_value_to_string (ctx, arguments[0], exception);
- width = seed_value_to_double (ctx, arguments[1], exception);
- height = seed_value_to_double (ctx, arguments[2], exception);
- ret = cairo_pdf_surface_create (filename, width, height);
+ if (!seed_value_is_null(ctx, arguments[0]))
+ filename = seed_value_to_string(ctx, arguments[0], exception);
+ width = seed_value_to_double(ctx, arguments[1], exception);
+ height = seed_value_to_double(ctx, arguments[2], exception);
+ ret = cairo_pdf_surface_create(filename, width, height);
- return seed_object_from_cairo_pdf_surface (ctx, ret);
+ return seed_object_from_cairo_pdf_surface(ctx, ret);
}
-seed_static_value pdf_surface_values[] = {
- {0, 0, 0, 0}
-};
-
-seed_static_function pdf_surface_funcs[] = {
- {"set_size", seed_cairo_pdf_surface_set_size, 0},
- {0, 0, 0}
-};
-
-
+seed_static_value pdf_surface_values[] = { { 0, 0, 0, 0 } };
+seed_static_function pdf_surface_funcs[]
+ = { { "set_size", seed_cairo_pdf_surface_set_size, 0 }, { 0, 0, 0 } };
void
-seed_define_cairo_pdf_surface (SeedContext ctx,
- SeedObject namespace_ref)
+seed_define_cairo_pdf_surface(SeedContext ctx, SeedObject namespace_ref)
{
- seed_class_definition pdf_def = seed_empty_class;
-
- pdf_def.class_name = "PDFSurface";
- pdf_def.static_values = pdf_surface_values;
- pdf_def.parent_class = seed_get_cairo_surface_class ();
- pdf_def.static_functions = pdf_surface_funcs;
- seed_cairo_pdf_surface_class = seed_create_class (&pdf_def);
-
- pdf_surface_constructor_ref = seed_make_constructor (ctx,
- NULL,
- //seed_cairo_pdf_surface_class,
- seed_cairo_construct_pdf_surface);
- seed_object_set_property (ctx, namespace_ref, "PDFSurface", pdf_surface_constructor_ref);
+ seed_class_definition pdf_def = seed_empty_class;
+
+ pdf_def.class_name = "PDFSurface";
+ pdf_def.static_values = pdf_surface_values;
+ pdf_def.parent_class = seed_get_cairo_surface_class();
+ pdf_def.static_functions = pdf_surface_funcs;
+ seed_cairo_pdf_surface_class = seed_create_class(&pdf_def);
+
+ pdf_surface_constructor_ref
+ = seed_make_constructor(ctx, NULL,
+ // seed_cairo_pdf_surface_class,
+ seed_cairo_construct_pdf_surface);
+ seed_object_set_property(ctx, namespace_ref, "PDFSurface",
+ pdf_surface_constructor_ref);
}
diff --git a/modules/cairo/seed-cairo-pdf-surface.h b/modules/cairo/seed-cairo-pdf-surface.h
index 88d9b7d..9accf15 100644
--- a/modules/cairo/seed-cairo-pdf-surface.h
+++ b/modules/cairo/seed-cairo-pdf-surface.h
@@ -4,6 +4,6 @@
#include <seed.h>
#include <cairo/cairo.h>
-void seed_define_cairo_pdf_surface (SeedContext ctx, SeedObject namespace_ref);
+void seed_define_cairo_pdf_surface(SeedContext ctx, SeedObject namespace_ref);
#endif
diff --git a/modules/cairo/seed-cairo-surface.c b/modules/cairo/seed-cairo-surface.c
index 55cf4f6..f08ef2a 100644
--- a/modules/cairo/seed-cairo-surface.c
+++ b/modules/cairo/seed-cairo-surface.c
@@ -24,393 +24,432 @@
#include "seed-cairo-image-surface.h"
#include "seed-cairo-pdf-surface.h"
-#define CAIRO_SURFACE_PRIV(obj) ((cairo_surface_t *)seed_object_get_private(obj))
-
-#define CHECK_SURFACE(obj, res) ({ \
- if (!seed_object_is_of_class (ctx, obj, seed_cairo_surface_class)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Surface"); \
- return seed_make_##res (ctx); \
- } \
- if (!seed_object_get_private (obj)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); \
- return seed_make_##res (ctx);}})
-
-#define CHECK_THIS() if (!seed_object_get_private (this_object)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); \
- return seed_make_undefined (ctx);}
-
-#define CHECK_THIS_BOOL(res) if (!seed_object_get_private (this_object)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); return FALSE;}
-
-
+#define CAIRO_SURFACE_PRIV(obj) \
+ ((cairo_surface_t*) seed_object_get_private(obj))
+
+#define CHECK_SURFACE(obj, res) \
+ ({ \
+ if (!seed_object_is_of_class(ctx, obj, seed_cairo_surface_class)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Object is not a Cairo Surface"); \
+ return seed_make_##res(ctx); \
+ } \
+ if (!seed_object_get_private(obj)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo surface has been destroyed"); \
+ return seed_make_##res(ctx); \
+ } \
+ })
+
+#define CHECK_THIS() \
+ if (!seed_object_get_private(this_object)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo surface has been destroyed"); \
+ return seed_make_undefined(ctx); \
+ }
+#define CHECK_THIS_BOOL(res) \
+ if (!seed_object_get_private(this_object)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo surface has been destroyed"); \
+ return FALSE; \
+ }
SeedClass seed_cairo_surface_class;
SeedClass
-seed_get_cairo_surface_class ()
+seed_get_cairo_surface_class()
{
- return seed_cairo_surface_class;
+ return seed_cairo_surface_class;
}
static void
-seed_cairo_surface_finalize (SeedObject obj)
+seed_cairo_surface_finalize(SeedObject obj)
{
- cairo_surface_t *s = CAIRO_SURFACE_PRIV(obj);
- if (s)
- {
- cairo_surface_set_user_data (s, seed_get_cairo_key(), NULL, NULL);
- cairo_surface_destroy (s);
- }
+ cairo_surface_t* s = CAIRO_SURFACE_PRIV(obj);
+ if (s) {
+ cairo_surface_set_user_data(s, seed_get_cairo_key(), NULL, NULL);
+ cairo_surface_destroy(s);
+ }
}
-cairo_surface_t *
-seed_object_to_cairo_surface (SeedContext ctx, SeedObject obj, SeedException *exception)
+cairo_surface_t*
+seed_object_to_cairo_surface(SeedContext ctx,
+ SeedObject obj,
+ SeedException* exception)
{
- if (seed_object_is_of_class (ctx, obj, seed_cairo_surface_class))
- return CAIRO_SURFACE_PRIV (obj);
- seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Surface");
- return NULL;
+ if (seed_object_is_of_class(ctx, obj, seed_cairo_surface_class))
+ return CAIRO_SURFACE_PRIV(obj);
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Object is not a Cairo Surface");
+ return NULL;
}
SeedObject
-seed_object_from_cairo_surface (SeedContext ctx, cairo_surface_t *surf)
+seed_object_from_cairo_surface(SeedContext ctx, cairo_surface_t* surf)
{
- SeedObject jsobj;
+ SeedObject jsobj;
- jsobj = cairo_surface_get_user_data (surf, seed_get_cairo_key());
- if (jsobj)
- return jsobj;
+ jsobj = cairo_surface_get_user_data(surf, seed_get_cairo_key());
+ if (jsobj)
+ return jsobj;
- jsobj = seed_make_object (ctx, seed_cairo_surface_class, surf);
- cairo_surface_set_user_data (surf, seed_get_cairo_key(), jsobj, seed_cairo_destroy_func);
- return jsobj;
+ jsobj = seed_make_object(ctx, seed_cairo_surface_class, surf);
+ cairo_surface_set_user_data(surf, seed_get_cairo_key(), jsobj,
+ seed_cairo_destroy_func);
+ return jsobj;
}
static SeedValue
-seed_cairo_surface_create_similar (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_surface_create_similar(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint width, height;
- cairo_surface_t *surface, *ret;
- cairo_content_t content;
- CHECK_THIS();
- if (argument_count != 3)
- {
- EXPECTED_EXCEPTION("create_similar", "3 arguments");
+ gint width, height;
+ cairo_surface_t *surface, *ret;
+ cairo_content_t content;
+ CHECK_THIS();
+ if (argument_count != 3) {
+ EXPECTED_EXCEPTION("create_similar", "3 arguments");
}
- surface = seed_object_to_cairo_surface (ctx, this_object, exception);
- if (!surface)
- return seed_make_undefined (ctx);
- content = seed_value_to_long (ctx, arguments[0], exception);
- width = seed_value_to_int (ctx, arguments[1], exception);
- height = seed_value_to_int (ctx, arguments[2], exception);
+ surface = seed_object_to_cairo_surface(ctx, this_object, exception);
+ if (!surface)
+ return seed_make_undefined(ctx);
+ content = seed_value_to_long(ctx, arguments[0], exception);
+ width = seed_value_to_int(ctx, arguments[1], exception);
+ height = seed_value_to_int(ctx, arguments[2], exception);
- ret = cairo_surface_create_similar (surface, content, width, height);
- return seed_object_from_cairo_surface (ctx, ret);
+ ret = cairo_surface_create_similar(surface, content, width, height);
+ return seed_object_from_cairo_surface(ctx, ret);
}
static SeedValue
-seed_cairo_surface_status (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_surface_status(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- CHECK_THIS();
- return seed_value_from_long (ctx, cairo_surface_status (seed_object_to_cairo_surface(ctx, this_object,
exception)), exception);
+ CHECK_THIS();
+ return seed_value_from_long(ctx,
+ cairo_surface_status(
+ seed_object_to_cairo_surface(ctx, this_object,
+ exception)),
+ exception);
}
static SeedValue
-seed_cairo_surface_get_content (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_surface_get_content(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- CHECK_THIS();
- return seed_value_from_long (ctx, cairo_surface_get_content (seed_object_to_cairo_surface(ctx,
this_object, exception)), exception);
+ CHECK_THIS();
+ return seed_value_from_long(ctx,
+ cairo_surface_get_content(
+ seed_object_to_cairo_surface(ctx, this_object,
+ exception)),
+ exception);
}
static SeedValue
-seed_cairo_surface_finish (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_surface_finish(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_surface_finish (seed_object_to_cairo_surface(ctx, this_object, exception));
- return seed_make_undefined (ctx);
+ CHECK_THIS();
+ cairo_surface_finish(
+ seed_object_to_cairo_surface(ctx, this_object, exception));
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_surface_flush (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_surface_flush(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_surface_flush (seed_object_to_cairo_surface(ctx, this_object, exception));
- return seed_make_undefined (ctx);
+ CHECK_THIS();
+ cairo_surface_flush(
+ seed_object_to_cairo_surface(ctx, this_object, exception));
+ return seed_make_undefined(ctx);
}
static SeedValue
seed_cairo_surface_mark_dirty_rectangle(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_surface_t *surf;
- guint x, y, width, height;
- CHECK_THIS();
- if (argument_count != 4)
- {
- EXPECTED_EXCEPTION("mark_dirty_rectangle", "4 arguments");
+ cairo_surface_t* surf;
+ guint x, y, width, height;
+ CHECK_THIS();
+ if (argument_count != 4) {
+ EXPECTED_EXCEPTION("mark_dirty_rectangle", "4 arguments");
}
- surf = seed_object_to_cairo_surface (ctx, this_object, exception);
- x = seed_value_to_int (ctx, arguments[0], exception);
- y = seed_value_to_int (ctx, arguments[1], exception);
- width = seed_value_to_int (ctx, arguments[2], exception);
- height = seed_value_to_int (ctx, arguments[3], exception);
+ surf = seed_object_to_cairo_surface(ctx, this_object, exception);
+ x = seed_value_to_int(ctx, arguments[0], exception);
+ y = seed_value_to_int(ctx, arguments[1], exception);
+ width = seed_value_to_int(ctx, arguments[2], exception);
+ height = seed_value_to_int(ctx, arguments[3], exception);
- cairo_surface_mark_dirty_rectangle (surf, x, y, width, height);
+ cairo_surface_mark_dirty_rectangle(surf, x, y, width, height);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_surface_mark_dirty (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_surface_mark_dirty(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_surface_mark_dirty (seed_object_to_cairo_surface(ctx, this_object, exception));
- return seed_make_undefined (ctx);
+ CHECK_THIS();
+ cairo_surface_mark_dirty(
+ seed_object_to_cairo_surface(ctx, this_object, exception));
+ return seed_make_undefined(ctx);
}
static gboolean
seed_cairo_surface_set_device_offset(SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- cairo_surface_t *surf;
- gdouble x, y;
- SeedValue jsx, jsy;
- CHECK_THIS_BOOL();
-
- if (!seed_value_is_object (ctx, value))
- {
- seed_make_exception(ctx, exception, "ArgumentError", "Cairo.Surface.device_offset must be an array
[x,y]");
- return FALSE;
+ cairo_surface_t* surf;
+ gdouble x, y;
+ SeedValue jsx, jsy;
+ CHECK_THIS_BOOL();
+
+ if (!seed_value_is_object(ctx, value)) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Cairo.Surface.device_offset must be an array [x,y]");
+ return FALSE;
}
- jsx = seed_object_get_property_at_index (ctx, (SeedObject) value, 0, exception);
- jsy = seed_object_get_property_at_index (ctx, (SeedObject) value, 1, exception);
+ jsx = seed_object_get_property_at_index(ctx, (SeedObject) value, 0,
+ exception);
+ jsy = seed_object_get_property_at_index(ctx, (SeedObject) value, 1,
+ exception);
- surf = seed_object_to_cairo_surface (ctx, this_object, exception);
- x = seed_value_to_double (ctx, jsx, exception);
- y = seed_value_to_double (ctx, jsy, exception);
+ surf = seed_object_to_cairo_surface(ctx, this_object, exception);
+ x = seed_value_to_double(ctx, jsx, exception);
+ y = seed_value_to_double(ctx, jsy, exception);
- cairo_surface_set_device_offset (surf, x, y);
- return TRUE;
+ cairo_surface_set_device_offset(surf, x, y);
+ return TRUE;
}
static SeedValue
seed_cairo_surface_get_device_offset(SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- SeedValue offsets[2];
- cairo_surface_t *surf;
- gdouble x, y;
- CHECK_THIS();
+ SeedValue offsets[2];
+ cairo_surface_t* surf;
+ gdouble x, y;
+ CHECK_THIS();
- surf = seed_object_to_cairo_surface (ctx, this_object, exception);
- cairo_surface_get_device_offset (surf, &x, &y);
+ surf = seed_object_to_cairo_surface(ctx, this_object, exception);
+ cairo_surface_get_device_offset(surf, &x, &y);
- offsets[0] = seed_value_from_double (ctx, x, exception);
- offsets[1] = seed_value_from_double (ctx, y, exception);
+ offsets[0] = seed_value_from_double(ctx, x, exception);
+ offsets[1] = seed_value_from_double(ctx, y, exception);
- return seed_make_array (ctx, offsets, 2, exception);
+ return seed_make_array(ctx, offsets, 2, exception);
}
static gboolean
seed_cairo_surface_set_fallback_resolution(SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- cairo_surface_t *surf;
- gdouble x, y;
- SeedValue jsx, jsy;
- CHECK_THIS_BOOL();
-
- if (!seed_value_is_object (ctx, value))
- {
- seed_make_exception(ctx, exception, "ArgumentError", "Cairo.Surface.fallback_resolution must be an
array [x,y]");
- return FALSE;
+ cairo_surface_t* surf;
+ gdouble x, y;
+ SeedValue jsx, jsy;
+ CHECK_THIS_BOOL();
+
+ if (!seed_value_is_object(ctx, value)) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Cairo.Surface.fallback_resolution must be an array [x,y]");
+ return FALSE;
}
- jsx = seed_object_get_property_at_index (ctx, (SeedObject) value, 0, exception);
- jsy = seed_object_get_property_at_index (ctx, (SeedObject) value, 1, exception);
+ jsx = seed_object_get_property_at_index(ctx, (SeedObject) value, 0,
+ exception);
+ jsy = seed_object_get_property_at_index(ctx, (SeedObject) value, 1,
+ exception);
- surf = seed_object_to_cairo_surface (ctx, this_object, exception);
- x = seed_value_to_double (ctx, jsx, exception);
- y = seed_value_to_double (ctx, jsy, exception);
+ surf = seed_object_to_cairo_surface(ctx, this_object, exception);
+ x = seed_value_to_double(ctx, jsx, exception);
+ y = seed_value_to_double(ctx, jsy, exception);
- cairo_surface_set_fallback_resolution (surf, x, y);
- return TRUE;
+ cairo_surface_set_fallback_resolution(surf, x, y);
+ return TRUE;
}
static SeedValue
seed_cairo_surface_get_fallback_resolution(SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- SeedValue offsets[2];
- cairo_surface_t *surf;
- gdouble x, y;
- CHECK_THIS();
+ SeedValue offsets[2];
+ cairo_surface_t* surf;
+ gdouble x, y;
+ CHECK_THIS();
- surf = seed_object_to_cairo_surface (ctx, this_object, exception);
- cairo_surface_get_fallback_resolution (surf, &x, &y);
+ surf = seed_object_to_cairo_surface(ctx, this_object, exception);
+ cairo_surface_get_fallback_resolution(surf, &x, &y);
- offsets[0] = seed_value_from_double (ctx, x, exception);
- offsets[1] = seed_value_from_double (ctx, y, exception);
+ offsets[0] = seed_value_from_double(ctx, x, exception);
+ offsets[1] = seed_value_from_double(ctx, y, exception);
- return seed_make_array (ctx, offsets, 2, exception);
+ return seed_make_array(ctx, offsets, 2, exception);
}
static SeedValue
-seed_cairo_surface_get_type (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_surface_get_type(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- CHECK_THIS();
- return seed_value_from_long (ctx, cairo_surface_get_type (seed_object_to_cairo_surface(ctx, this_object,
exception)), exception);
+ CHECK_THIS();
+ return seed_value_from_long(ctx,
+ cairo_surface_get_type(
+ seed_object_to_cairo_surface(ctx, this_object,
+ exception)),
+ exception);
}
static SeedValue
-seed_cairo_surface_copy_page (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_surface_copy_page(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_surface_copy_page (seed_object_to_cairo_surface(ctx, this_object, exception));
- return seed_make_undefined (ctx);
+ CHECK_THIS();
+ cairo_surface_copy_page(
+ seed_object_to_cairo_surface(ctx, this_object, exception));
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_surface_show_page (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_surface_show_page(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_surface_show_page (seed_object_to_cairo_surface(ctx, this_object, exception));
- return seed_make_undefined (ctx);
+ CHECK_THIS();
+ cairo_surface_show_page(
+ seed_object_to_cairo_surface(ctx, this_object, exception));
+ return seed_make_undefined(ctx);
}
static SeedValue
seed_cairo_surface_has_show_text_glyphs(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- return seed_value_from_boolean (ctx,
- cairo_surface_has_show_text_glyphs (seed_object_to_cairo_surface(ctx,
this_object, exception)), exception);
+ CHECK_THIS();
+ return seed_value_from_boolean(
+ ctx, cairo_surface_has_show_text_glyphs(
+ seed_object_to_cairo_surface(ctx, this_object, exception)),
+ exception);
}
static SeedValue
-seed_cairo_surface_write_to_png (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_surface_write_to_png(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_status_t ret;
- cairo_surface_t *surf;
- gchar *filename;
- CHECK_THIS();
-
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("write_to_png", "1 argument");
+ cairo_status_t ret;
+ cairo_surface_t* surf;
+ gchar* filename;
+ CHECK_THIS();
+
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("write_to_png", "1 argument");
}
- surf = seed_object_get_private (this_object);
- filename = seed_value_to_string (ctx, arguments[0], exception);
+ surf = seed_object_get_private(this_object);
+ filename = seed_value_to_string(ctx, arguments[0], exception);
- ret = cairo_surface_write_to_png (surf, filename);
- g_free (filename);
+ ret = cairo_surface_write_to_png(surf, filename);
+ g_free(filename);
- return seed_value_from_long (ctx, ret, exception);
+ return seed_value_from_long(ctx, ret, exception);
}
-
-seed_static_function surface_funcs[] = {
- {"create_similar", seed_cairo_surface_create_similar, 0},
- {"finish", seed_cairo_surface_finish, 0},
- {"flush", seed_cairo_surface_flush, 0},
- // {"get_font_options", seed_cairo_surface_get_font_options, 0},
- {"mark_dirty", seed_cairo_surface_mark_dirty, 0},
- {"mark_dirty_rectangle", seed_cairo_surface_mark_dirty_rectangle, 0},
- {"copy_page", seed_cairo_surface_copy_page, 0},
- {"show_page", seed_cairo_surface_show_page, 0},
- {"has_show_text_glyphs", seed_cairo_surface_has_show_text_glyphs, 0},
- {"write_to_png", seed_cairo_surface_write_to_png, 0},
- {0,0,0}
-};
+seed_static_function surface_funcs[]
+ = { { "create_similar", seed_cairo_surface_create_similar, 0 },
+ { "finish", seed_cairo_surface_finish, 0 },
+ { "flush", seed_cairo_surface_flush, 0 },
+ // {"get_font_options", seed_cairo_surface_get_font_options, 0},
+ { "mark_dirty", seed_cairo_surface_mark_dirty, 0 },
+ { "mark_dirty_rectangle", seed_cairo_surface_mark_dirty_rectangle, 0 },
+ { "copy_page", seed_cairo_surface_copy_page, 0 },
+ { "show_page", seed_cairo_surface_show_page, 0 },
+ { "has_show_text_glyphs", seed_cairo_surface_has_show_text_glyphs, 0 },
+ { "write_to_png", seed_cairo_surface_write_to_png, 0 },
+ { 0, 0, 0 } };
seed_static_value surface_values[] = {
- {"type", seed_cairo_surface_get_type, 0, SEED_PROPERTY_ATTRIBUTE_READ_ONLY |
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"content", seed_cairo_surface_get_content, 0, SEED_PROPERTY_ATTRIBUTE_READ_ONLY |
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"status", seed_cairo_surface_status, 0, SEED_PROPERTY_ATTRIBUTE_READ_ONLY |
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"device_offset", seed_cairo_surface_get_device_offset, seed_cairo_surface_set_device_offset,
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"fallback_resolution", seed_cairo_surface_get_fallback_resolution,
seed_cairo_surface_set_fallback_resolution, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {0, 0, 0, 0}
+ { "type", seed_cairo_surface_get_type, 0,
+ SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "content", seed_cairo_surface_get_content, 0,
+ SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "status", seed_cairo_surface_status, 0,
+ SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "device_offset", seed_cairo_surface_get_device_offset,
+ seed_cairo_surface_set_device_offset,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "fallback_resolution", seed_cairo_surface_get_fallback_resolution,
+ seed_cairo_surface_set_fallback_resolution,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { 0, 0, 0, 0 }
};
void
-seed_define_cairo_surface (SeedContext ctx,
- SeedObject namespace_ref)
+seed_define_cairo_surface(SeedContext ctx, SeedObject namespace_ref)
{
- seed_class_definition surface_def = seed_empty_class;
+ seed_class_definition surface_def = seed_empty_class;
- surface_def.class_name = "Surface";
- surface_def.finalize = seed_cairo_surface_finalize;
- surface_def.static_functions = surface_funcs;
- surface_def.static_values = surface_values;
+ surface_def.class_name = "Surface";
+ surface_def.finalize = seed_cairo_surface_finalize;
+ surface_def.static_functions = surface_funcs;
+ surface_def.static_values = surface_values;
- seed_cairo_surface_class = seed_create_class (&surface_def);
+ seed_cairo_surface_class = seed_create_class(&surface_def);
- seed_define_cairo_image_surface (ctx, namespace_ref);
- seed_define_cairo_pdf_surface (ctx, namespace_ref);
+ seed_define_cairo_image_surface(ctx, namespace_ref);
+ seed_define_cairo_pdf_surface(ctx, namespace_ref);
}
diff --git a/modules/cairo/seed-cairo-surface.h b/modules/cairo/seed-cairo-surface.h
index e58e9bb..d08ede6 100644
--- a/modules/cairo/seed-cairo-surface.h
+++ b/modules/cairo/seed-cairo-surface.h
@@ -1,11 +1,14 @@
#ifndef _SEED_CAIRO_SURFACE_H
#define _SEED_CAIRO_SURFACE_H
-SeedClass seed_get_cairo_surface_class ();
+SeedClass seed_get_cairo_surface_class();
-void seed_define_cairo_surface (SeedContext ctx, SeedObject namespace_ref);
+void seed_define_cairo_surface(SeedContext ctx, SeedObject namespace_ref);
-cairo_surface_t *seed_object_to_cairo_surface (SeedContext ctx, SeedObject obj, SeedException *exception);
-SeedObject seed_object_from_cairo_surface (SeedContext ctx, cairo_surface_t *surf);
+cairo_surface_t* seed_object_to_cairo_surface(SeedContext ctx,
+ SeedObject obj,
+ SeedException* exception);
+SeedObject seed_object_from_cairo_surface(SeedContext ctx,
+ cairo_surface_t* surf);
#endif
diff --git a/modules/cairo/seed-cairo.c b/modules/cairo/seed-cairo.c
index cdb9b5c..031591c 100644
--- a/modules/cairo/seed-cairo.c
+++ b/modules/cairo/seed-cairo.c
@@ -27,1822 +27,1805 @@
#include "seed-cairo-matrix.h"
#include "seed-cairo-pattern.h"
-SeedEngine *eng;
-
-#define CAIRO_CONTEXT_PRIV(obj) ((cairo_t *)seed_object_get_private(obj))
-
-#define CHECK_CAIRO(obj) ({ \
- if (!seed_object_is_of_class (ctx, obj, seed_cairo_class)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Context"); \
- return seed_make_undefined (ctx); \
- } \
- if (!seed_object_get_private (obj)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo Context has been destroyed"); \
- return seed_make_undefined (ctx);}})
-
-#define CHECK_THIS() if (!seed_object_get_private (this_object)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo Context has been destroyed"); \
- return seed_make_undefined (ctx);}
+SeedEngine* eng;
+
+#define CAIRO_CONTEXT_PRIV(obj) ((cairo_t*) seed_object_get_private(obj))
+
+#define CHECK_CAIRO(obj) \
+ ({ \
+ if (!seed_object_is_of_class(ctx, obj, seed_cairo_class)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Object is not a Cairo Context"); \
+ return seed_make_undefined(ctx); \
+ } \
+ if (!seed_object_get_private(obj)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo Context has been destroyed"); \
+ return seed_make_undefined(ctx); \
+ } \
+ })
+
+#define CHECK_THIS() \
+ if (!seed_object_get_private(this_object)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo Context has been destroyed"); \
+ return seed_make_undefined(ctx); \
+ }
-#define CHECK_THIS_BOOL() if (!seed_object_get_private (this_object)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo Context has been destroyed"); \
- return FALSE;}
+#define CHECK_THIS_BOOL() \
+ if (!seed_object_get_private(this_object)) { \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ "Cairo Context has been destroyed"); \
+ return FALSE; \
+ }
SeedClass seed_cairo_context_class;
-cairo_user_data_key_t *
-seed_get_cairo_key ()
+cairo_user_data_key_t*
+seed_get_cairo_key()
{
- static cairo_user_data_key_t foobaz;
+ static cairo_user_data_key_t foobaz;
- return &foobaz;
+ return &foobaz;
}
void
-seed_cairo_destroy_func (void *obj)
+seed_cairo_destroy_func(void* obj)
{
- SeedObject object = (SeedObject)obj;
- seed_object_set_private (object, NULL);
+ SeedObject object = (SeedObject) obj;
+ seed_object_set_private(object, NULL);
}
-cairo_t *
-seed_object_to_cairo_context (SeedContext ctx, SeedObject obj, SeedException *exception)
+cairo_t*
+seed_object_to_cairo_context(SeedContext ctx,
+ SeedObject obj,
+ SeedException* exception)
{
- if (seed_object_is_of_class (ctx, obj, seed_cairo_context_class))
- return CAIRO_CONTEXT_PRIV (obj);
- seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Context");
- return NULL;
+ if (seed_object_is_of_class(ctx, obj, seed_cairo_context_class))
+ return CAIRO_CONTEXT_PRIV(obj);
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Object is not a Cairo Context");
+ return NULL;
}
SeedObject
-seed_object_from_cairo_context (SeedContext ctx, cairo_t *cr)
+seed_object_from_cairo_context(SeedContext ctx, cairo_t* cr)
{
- SeedObject jsobj;
+ SeedObject jsobj;
- jsobj = cairo_get_user_data (cr, seed_get_cairo_key());
- if (jsobj)
- return jsobj;
+ jsobj = cairo_get_user_data(cr, seed_get_cairo_key());
+ if (jsobj)
+ return jsobj;
- jsobj = seed_make_object (ctx, seed_cairo_context_class, cr);
- cairo_set_user_data (cr, seed_get_cairo_key(), jsobj, seed_cairo_destroy_func);
- return jsobj;
+ jsobj = seed_make_object(ctx, seed_cairo_context_class, cr);
+ cairo_set_user_data(cr, seed_get_cairo_key(), jsobj,
+ seed_cairo_destroy_func);
+ return jsobj;
}
void
-seed_cairo_context_finalize (SeedObject obj)
+seed_cairo_context_finalize(SeedObject obj)
{
- cairo_t *cr = CAIRO_CONTEXT_PRIV (obj);
- if (cr)
- {
- cairo_set_user_data (cr, seed_get_cairo_key(), NULL, NULL);
- cairo_destroy (cr);
+ cairo_t* cr = CAIRO_CONTEXT_PRIV(obj);
+ if (cr) {
+ cairo_set_user_data(cr, seed_get_cairo_key(), NULL, NULL);
+ cairo_destroy(cr);
}
}
static SeedObject
-seed_cairo_construct_context (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
-{
- cairo_surface_t *surf;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION ("Context", "1 argument");
+seed_cairo_construct_context(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
+{
+ cairo_surface_t* surf;
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("Context", "1 argument");
}
- surf = seed_object_to_cairo_surface (ctx, arguments[0], exception);
- if (!surf)
- return seed_make_undefined (ctx);
- return seed_object_from_cairo_context (ctx, cairo_create (surf));
+ surf = seed_object_to_cairo_surface(ctx, arguments[0], exception);
+ if (!surf)
+ return seed_make_undefined(ctx);
+ return seed_object_from_cairo_context(ctx, cairo_create(surf));
}
static SeedObject
-seed_cairo_construct_context_from_window (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
-{
- GObject *obj;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION ("Context", "1 argument");
+seed_cairo_construct_context_from_window(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
+{
+ GObject* obj;
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("Context", "1 argument");
}
- obj = seed_value_to_object (ctx, arguments[0], exception);
- if (!GDK_IS_WINDOW(obj))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "Context.from_window requires a GdkWindow
argument");
- return seed_make_null (ctx);
+ obj = seed_value_to_object(ctx, arguments[0], exception);
+ if (!GDK_IS_WINDOW(obj)) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Context.from_window requires a GdkWindow argument");
+ return seed_make_null(ctx);
}
- return seed_object_from_cairo_context (ctx, gdk_cairo_create (GDK_WINDOW (obj)));
+ return seed_object_from_cairo_context(ctx,
+ gdk_cairo_create(GDK_WINDOW(obj)));
}
static SeedObject
-seed_cairo_construct_context_steal (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
-{
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION ("Context", "1 argument");
+seed_cairo_construct_context_steal(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
+{
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("Context", "1 argument");
+ }
+ cairo_t* cr = seed_pointer_get_pointer(ctx, arguments[0]);
+ if (!cr) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Context.steal requires a cairo context argument");
+ return seed_make_null(ctx);
}
- cairo_t* cr = seed_pointer_get_pointer(ctx, arguments[0]);
- if (!cr) {
- seed_make_exception (ctx, exception, "ArgumentError", "Context.steal requires a cairo context argument");
- return seed_make_null (ctx);
- }
- return seed_object_from_cairo_context (ctx, cr);
+ return seed_object_from_cairo_context(ctx, cr);
}
static SeedValue
-seed_cairo_save (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_save(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_save(cr);
- return seed_make_undefined (ctx);
+ cairo_save(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_restore (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_restore(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_restore(cr);
- return seed_make_undefined (ctx);
+ cairo_restore(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_get_target (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_get_target(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- return seed_object_from_cairo_surface (ctx, cairo_get_target (cr));
+ return seed_object_from_cairo_surface(ctx, cairo_get_target(cr));
}
static SeedValue
-seed_cairo_push_group (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_push_group(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_push_group(cr);
- return seed_make_undefined (ctx);
+ cairo_push_group(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_push_group_with_content (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_push_group_with_content(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_content_t content;
- cairo_t *cr;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("push_group_with_content", "1 argument");
+ cairo_content_t content;
+ cairo_t* cr;
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("push_group_with_content", "1 argument");
}
- CHECK_THIS();
- cr = seed_object_get_private (this_object);
- content = seed_value_to_long (ctx, arguments[0], exception);
- cairo_push_group_with_content(cr, content);
+ CHECK_THIS();
+ cr = seed_object_get_private(this_object);
+ content = seed_value_to_long(ctx, arguments[0], exception);
+ cairo_push_group_with_content(cr, content);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_pop_group_to_source (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_pop_group_to_source(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_pop_group_to_source(cr);
- return seed_make_undefined (ctx);
+ cairo_pop_group_to_source(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_get_group_target (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_get_group_target(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- return seed_object_from_cairo_surface (ctx, cairo_get_group_target (cr));
+ return seed_object_from_cairo_surface(ctx, cairo_get_group_target(cr));
}
static SeedValue
seed_cairo_set_source_rgb(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble r,g,b;
- cairo_t *cr;
+ gdouble r, g, b;
+ cairo_t* cr;
- CHECK_THIS();
- cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cr = seed_object_get_private(this_object);
- if (argument_count != 3)
- {
- EXPECTED_EXCEPTION("set_source_rgb", "3 arguments");
+ if (argument_count != 3) {
+ EXPECTED_EXCEPTION("set_source_rgb", "3 arguments");
}
- r = seed_value_to_double (ctx, arguments[0], exception);
- g = seed_value_to_double (ctx, arguments[1], exception);
- b = seed_value_to_double (ctx, arguments[2], exception);
- cairo_set_source_rgb (cr, r, g, b);
+ r = seed_value_to_double(ctx, arguments[0], exception);
+ g = seed_value_to_double(ctx, arguments[1], exception);
+ b = seed_value_to_double(ctx, arguments[2], exception);
+ cairo_set_source_rgb(cr, r, g, b);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
seed_cairo_set_source_rgba(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble r,g,b,a;
- cairo_t *cr;
+ gdouble r, g, b, a;
+ cairo_t* cr;
- CHECK_THIS();
- cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cr = seed_object_get_private(this_object);
- if (argument_count != 4)
- {
- EXPECTED_EXCEPTION("set_source_rgba", "4 arguments");
+ if (argument_count != 4) {
+ EXPECTED_EXCEPTION("set_source_rgba", "4 arguments");
}
- r = seed_value_to_double (ctx, arguments[0], exception);
- g = seed_value_to_double (ctx, arguments[1], exception);
- b = seed_value_to_double (ctx, arguments[2], exception);
- a = seed_value_to_double (ctx, arguments[3], exception);
- cairo_set_source_rgba (cr, r, g, b, a);
+ r = seed_value_to_double(ctx, arguments[0], exception);
+ g = seed_value_to_double(ctx, arguments[1], exception);
+ b = seed_value_to_double(ctx, arguments[2], exception);
+ a = seed_value_to_double(ctx, arguments[3], exception);
+ cairo_set_source_rgba(cr, r, g, b, a);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_set_source_surface (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_set_source_surface(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x,y;
- cairo_surface_t *surface;
- cairo_t *cr;
+ gdouble x, y;
+ cairo_surface_t* surface;
+ cairo_t* cr;
- CHECK_THIS();
- cr = seed_object_get_private (this_object);
- surface = seed_object_to_cairo_surface (ctx, arguments[0], exception);
- if (!surface)
- return seed_make_undefined (ctx);
+ CHECK_THIS();
+ cr = seed_object_get_private(this_object);
+ surface = seed_object_to_cairo_surface(ctx, arguments[0], exception);
+ if (!surface)
+ return seed_make_undefined(ctx);
- x = seed_value_to_double (ctx, arguments[1], exception);
- y = seed_value_to_double (ctx, arguments[2], exception);
- cairo_set_source_surface (cr, surface, x, y);
+ x = seed_value_to_double(ctx, arguments[1], exception);
+ y = seed_value_to_double(ctx, arguments[2], exception);
+ cairo_set_source_surface(cr, surface, x, y);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static gboolean
-seed_cairo_set_antialias (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_cairo_set_antialias(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- cairo_t *cr;
- cairo_antialias_t antialias;
+ cairo_t* cr;
+ cairo_antialias_t antialias;
- CHECK_THIS_BOOL();
- cr = seed_object_get_private (this_object);
- antialias = seed_value_to_long (ctx, value, exception);
+ CHECK_THIS_BOOL();
+ cr = seed_object_get_private(this_object);
+ antialias = seed_value_to_long(ctx, value, exception);
- cairo_set_antialias (cr, antialias);
- return TRUE;
+ cairo_set_antialias(cr, antialias);
+ return TRUE;
}
static SeedValue
-seed_cairo_get_antialias (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_get_antialias(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- cairo_antialias_t antialias;
- cairo_t *cr;
+ cairo_antialias_t antialias;
+ cairo_t* cr;
- CHECK_THIS();
- cr = seed_object_get_private (this_object);
- antialias = cairo_get_antialias (cr);
+ CHECK_THIS();
+ cr = seed_object_get_private(this_object);
+ antialias = cairo_get_antialias(cr);
- return seed_value_from_long (ctx, antialias, exception);
+ return seed_value_from_long(ctx, antialias, exception);
}
static SeedValue
seed_cairo_set_dash(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
-{
- SeedValue length;
- cairo_t *cr;
- gdouble *dashes, offset;
- gint num_dashes, i;
-
- CHECK_THIS();
- cr = seed_object_get_private (this_object);
-
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("set_dash", "2 arguments");
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
+{
+ SeedValue length;
+ cairo_t* cr;
+ gdouble *dashes, offset;
+ gint num_dashes, i;
+
+ CHECK_THIS();
+ cr = seed_object_get_private(this_object);
+
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("set_dash", "2 arguments");
}
- length = seed_object_get_property (ctx, arguments[0], "length");
- num_dashes = seed_value_to_int (ctx, length, exception);
- dashes = g_alloca (num_dashes * sizeof(gdouble));
- for (i = 0; i < num_dashes; i++)
- {
- dashes[i] = seed_value_to_double(ctx,
- seed_object_get_property_at_index (ctx,
- arguments[0],
- i,
- exception),
- exception);
-
+ length = seed_object_get_property(ctx, arguments[0], "length");
+ num_dashes = seed_value_to_int(ctx, length, exception);
+ dashes = g_alloca(num_dashes * sizeof(gdouble));
+ for (i = 0; i < num_dashes; i++) {
+ dashes[i] = seed_value_to_double(
+ ctx,
+ seed_object_get_property_at_index(ctx, arguments[0], i, exception),
+ exception);
}
- offset = seed_value_to_double (ctx, arguments[1], exception);
- cairo_set_dash (cr, dashes, num_dashes, offset);
+ offset = seed_value_to_double(ctx, arguments[1], exception);
+ cairo_set_dash(cr, dashes, num_dashes, offset);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_pop_group (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_pop_group(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS();
+ cairo_t* cr;
+ CHECK_THIS();
- cr = seed_object_get_private (this_object);
+ cr = seed_object_get_private(this_object);
- return seed_object_from_cairo_pattern (ctx, cairo_pop_group (cr));
+ return seed_object_from_cairo_pattern(ctx, cairo_pop_group(cr));
}
static SeedValue
-seed_cairo_get_dash_count (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_get_dash_count(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_t *cr;
- gint dash_count;
- CHECK_THIS();
+ cairo_t* cr;
+ gint dash_count;
+ CHECK_THIS();
- cr = seed_object_get_private (this_object);
- dash_count = cairo_get_dash_count (cr);
+ cr = seed_object_get_private(this_object);
+ dash_count = cairo_get_dash_count(cr);
- return seed_value_from_int (ctx, dash_count, exception);
+ return seed_value_from_int(ctx, dash_count, exception);
}
static SeedValue
-seed_cairo_get_dash (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_get_dash(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue ret[2], *jsdashes;
- cairo_t *cr;
- gint dash_count, i;
- gdouble *dashes, offset;
+ SeedValue ret[2], *jsdashes;
+ cairo_t* cr;
+ gint dash_count, i;
+ gdouble *dashes, offset;
- CHECK_THIS();
- cr = seed_object_get_private (this_object);
- dash_count = cairo_get_dash_count (cr);
- dashes = g_alloca (dash_count * sizeof(gdouble));
- jsdashes = g_alloca (dash_count * sizeof(SeedValue));
+ CHECK_THIS();
+ cr = seed_object_get_private(this_object);
+ dash_count = cairo_get_dash_count(cr);
+ dashes = g_alloca(dash_count * sizeof(gdouble));
+ jsdashes = g_alloca(dash_count * sizeof(SeedValue));
- cairo_get_dash (cr, dashes, &offset);
- for (i = 0; i < dash_count; i++)
- {
- jsdashes[i] = seed_value_from_double (ctx, dashes[i], exception);
+ cairo_get_dash(cr, dashes, &offset);
+ for (i = 0; i < dash_count; i++) {
+ jsdashes[i] = seed_value_from_double(ctx, dashes[i], exception);
}
- ret[0] = seed_make_array (ctx, jsdashes, dash_count, exception);
- ret[1] = seed_value_from_double (ctx, offset, exception);
+ ret[0] = seed_make_array(ctx, jsdashes, dash_count, exception);
+ ret[1] = seed_value_from_double(ctx, offset, exception);
- return seed_make_array (ctx, ret, 2, exception);
+ return seed_make_array(ctx, ret, 2, exception);
}
static SeedValue
-seed_cairo_get_fill_rule (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_get_fill_rule(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS();
+ cairo_t* cr;
+ CHECK_THIS();
- cr = seed_object_get_private (this_object);
- return seed_value_from_long (ctx, cairo_get_fill_rule (cr), exception);
+ cr = seed_object_get_private(this_object);
+ return seed_value_from_long(ctx, cairo_get_fill_rule(cr), exception);
}
static gboolean
-seed_cairo_set_fill_rule (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_cairo_set_fill_rule(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS_BOOL();
+ cairo_t* cr;
+ CHECK_THIS_BOOL();
- cr = seed_object_get_private (this_object);
- cairo_set_fill_rule (cr, seed_value_to_long (ctx, value, exception));
+ cr = seed_object_get_private(this_object);
+ cairo_set_fill_rule(cr, seed_value_to_long(ctx, value, exception));
- return TRUE;
+ return TRUE;
}
-
static SeedValue
-seed_cairo_get_line_cap (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_get_line_cap(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS();
+ cairo_t* cr;
+ CHECK_THIS();
- cr = seed_object_get_private (this_object);
- return seed_value_from_long (ctx, cairo_get_line_cap (cr), exception);
+ cr = seed_object_get_private(this_object);
+ return seed_value_from_long(ctx, cairo_get_line_cap(cr), exception);
}
static gboolean
-seed_cairo_set_line_cap (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_cairo_set_line_cap(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS_BOOL();
+ cairo_t* cr;
+ CHECK_THIS_BOOL();
- cr = seed_object_get_private (this_object);
- cairo_set_line_cap (cr, seed_value_to_long (ctx, value, exception));
+ cr = seed_object_get_private(this_object);
+ cairo_set_line_cap(cr, seed_value_to_long(ctx, value, exception));
- return TRUE;
+ return TRUE;
}
static SeedValue
-seed_cairo_get_line_join (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_get_line_join(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS();
+ cairo_t* cr;
+ CHECK_THIS();
- cr = seed_object_get_private (this_object);
- return seed_value_from_long (ctx, cairo_get_line_join (cr), exception);
+ cr = seed_object_get_private(this_object);
+ return seed_value_from_long(ctx, cairo_get_line_join(cr), exception);
}
static gboolean
-seed_cairo_set_line_join (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_cairo_set_line_join(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS_BOOL();
+ cairo_t* cr;
+ CHECK_THIS_BOOL();
- cr = seed_object_get_private (this_object);
- cairo_set_line_join (cr, seed_value_to_long (ctx, value, exception));
+ cr = seed_object_get_private(this_object);
+ cairo_set_line_join(cr, seed_value_to_long(ctx, value, exception));
- return TRUE;
+ return TRUE;
}
-
static SeedValue
-seed_cairo_get_line_width (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_get_line_width(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS();
+ cairo_t* cr;
+ CHECK_THIS();
- cr = seed_object_get_private (this_object);
- return seed_value_from_double (ctx, cairo_get_line_width (cr), exception);
+ cr = seed_object_get_private(this_object);
+ return seed_value_from_double(ctx, cairo_get_line_width(cr), exception);
}
static gboolean
-seed_cairo_set_line_width (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_cairo_set_line_width(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS_BOOL();
+ cairo_t* cr;
+ CHECK_THIS_BOOL();
- cr = seed_object_get_private (this_object);
- cairo_set_line_width (cr, seed_value_to_double (ctx, value, exception));
+ cr = seed_object_get_private(this_object);
+ cairo_set_line_width(cr, seed_value_to_double(ctx, value, exception));
- return TRUE;
+ return TRUE;
}
static SeedValue
-seed_cairo_get_miter_limit (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_get_miter_limit(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS();
+ cairo_t* cr;
+ CHECK_THIS();
- cr = seed_object_get_private (this_object);
- return seed_value_from_double (ctx, cairo_get_miter_limit (cr), exception);
+ cr = seed_object_get_private(this_object);
+ return seed_value_from_double(ctx, cairo_get_miter_limit(cr), exception);
}
static gboolean
-seed_cairo_set_miter_limit (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_cairo_set_miter_limit(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS_BOOL();
+ cairo_t* cr;
+ CHECK_THIS_BOOL();
- cr = seed_object_get_private (this_object);
- cairo_set_miter_limit (cr, seed_value_to_double (ctx, value, exception));
+ cr = seed_object_get_private(this_object);
+ cairo_set_miter_limit(cr, seed_value_to_double(ctx, value, exception));
- return TRUE;
+ return TRUE;
}
static SeedValue
-seed_cairo_get_operator (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_get_operator(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS();
+ cairo_t* cr;
+ CHECK_THIS();
- cr = seed_object_get_private (this_object);
- return seed_value_from_long (ctx, cairo_get_operator (cr), exception);
+ cr = seed_object_get_private(this_object);
+ return seed_value_from_long(ctx, cairo_get_operator(cr), exception);
}
static gboolean
-seed_cairo_set_operator (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_cairo_set_operator(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS_BOOL();
+ cairo_t* cr;
+ CHECK_THIS_BOOL();
- cr = seed_object_get_private (this_object);
- cairo_set_operator (cr, seed_value_to_long (ctx, value, exception));
+ cr = seed_object_get_private(this_object);
+ cairo_set_operator(cr, seed_value_to_long(ctx, value, exception));
- return TRUE;
+ return TRUE;
}
static SeedValue
-seed_cairo_get_tolerance (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_get_tolerance(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS();
+ cairo_t* cr;
+ CHECK_THIS();
- cr = seed_object_get_private (this_object);
- return seed_value_from_double (ctx, cairo_get_tolerance (cr), exception);
+ cr = seed_object_get_private(this_object);
+ return seed_value_from_double(ctx, cairo_get_tolerance(cr), exception);
}
static gboolean
-seed_cairo_set_tolerance (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_cairo_set_tolerance(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS_BOOL();
+ cairo_t* cr;
+ CHECK_THIS_BOOL();
- cr = seed_object_get_private (this_object);
- cairo_set_tolerance (cr, seed_value_to_double (ctx, value, exception));
+ cr = seed_object_get_private(this_object);
+ cairo_set_tolerance(cr, seed_value_to_double(ctx, value, exception));
- return TRUE;
+ return TRUE;
}
static SeedValue
-seed_cairo_clip (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_clip(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_clip(cr);
- return seed_make_undefined (ctx);
+ cairo_clip(cr);
+ return seed_make_undefined(ctx);
}
-
static SeedValue
-seed_cairo_clip_preserve (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_clip_preserve(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_clip_preserve(cr);
- return seed_make_undefined (ctx);
+ cairo_clip_preserve(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_reset_clip (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_reset_clip(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_reset_clip(cr);
- return seed_make_undefined (ctx);
+ cairo_reset_clip(cr);
+ return seed_make_undefined(ctx);
}
-
static SeedValue
-seed_cairo_clip_extents (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_clip_extents(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue jsextents[4];
- gdouble extents[4];
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ SeedValue jsextents[4];
+ gdouble extents[4];
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 4)
- {
- EXPECTED_EXCEPTION("clip_extents", "4 arguments");
+ if (argument_count != 4) {
+ EXPECTED_EXCEPTION("clip_extents", "4 arguments");
}
- cairo_clip_extents (cr, &extents[0], &extents[1], &extents[2], &extents[3]);
- jsextents[0] = seed_value_from_double (ctx, extents[0], exception);
- jsextents[1] = seed_value_from_double (ctx, extents[1], exception);
- jsextents[2] = seed_value_from_double (ctx, extents[2], exception);
- jsextents[3] = seed_value_from_double (ctx, extents[3], exception);
+ cairo_clip_extents(cr, &extents[0], &extents[1], &extents[2], &extents[3]);
+ jsextents[0] = seed_value_from_double(ctx, extents[0], exception);
+ jsextents[1] = seed_value_from_double(ctx, extents[1], exception);
+ jsextents[2] = seed_value_from_double(ctx, extents[2], exception);
+ jsextents[3] = seed_value_from_double(ctx, extents[3], exception);
- return seed_make_array (ctx, jsextents, 4, exception);
+ return seed_make_array(ctx, jsextents, 4, exception);
}
-
static SeedValue
-seed_cairo_fill (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_fill(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_fill(cr);
- return seed_make_undefined (ctx);
+ cairo_fill(cr);
+ return seed_make_undefined(ctx);
}
-
static SeedValue
-seed_cairo_fill_preserve (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_fill_preserve(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_fill_preserve(cr);
- return seed_make_undefined (ctx);
+ cairo_fill_preserve(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_fill_extents (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_fill_extents(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue jsextents[4];
- gdouble extents[4];
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ SeedValue jsextents[4];
+ gdouble extents[4];
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 4)
- {
- EXPECTED_EXCEPTION("clip_extents", "4 arguments");
+ if (argument_count != 4) {
+ EXPECTED_EXCEPTION("clip_extents", "4 arguments");
}
- cairo_fill_extents (cr, &extents[0], &extents[1], &extents[2], &extents[3]);
- jsextents[0] = seed_value_from_double (ctx, extents[0], exception);
- jsextents[1] = seed_value_from_double (ctx, extents[1], exception);
- jsextents[2] = seed_value_from_double (ctx, extents[2], exception);
- jsextents[3] = seed_value_from_double (ctx, extents[3], exception);
+ cairo_fill_extents(cr, &extents[0], &extents[1], &extents[2], &extents[3]);
+ jsextents[0] = seed_value_from_double(ctx, extents[0], exception);
+ jsextents[1] = seed_value_from_double(ctx, extents[1], exception);
+ jsextents[2] = seed_value_from_double(ctx, extents[2], exception);
+ jsextents[3] = seed_value_from_double(ctx, extents[3], exception);
- return seed_make_array (ctx, jsextents, 4, exception);
+ return seed_make_array(ctx, jsextents, 4, exception);
}
static SeedValue
-seed_cairo_in_fill (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_in_fill(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x, y;
- cairo_t *cr;
- CHECK_THIS();
- cr = seed_object_get_private (this_object);
+ gdouble x, y;
+ cairo_t* cr;
+ CHECK_THIS();
+ cr = seed_object_get_private(this_object);
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("in_fill", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("in_fill", "2 arguments");
}
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
- return seed_value_from_boolean (ctx, cairo_in_fill (cr, x, y), exception);
+ return seed_value_from_boolean(ctx, cairo_in_fill(cr, x, y), exception);
}
static SeedValue
-seed_cairo_mask_surface (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_mask_surface(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x,y;
- cairo_surface_t *surface;
- cairo_t *cr;
+ gdouble x, y;
+ cairo_surface_t* surface;
+ cairo_t* cr;
- cr = seed_object_get_private (this_object);
- surface = seed_object_to_cairo_surface (ctx, arguments[0], exception);
- if (!surface)
- return seed_make_undefined (ctx);
+ cr = seed_object_get_private(this_object);
+ surface = seed_object_to_cairo_surface(ctx, arguments[0], exception);
+ if (!surface)
+ return seed_make_undefined(ctx);
- x = seed_value_to_double (ctx, arguments[1], exception);
- y = seed_value_to_double (ctx, arguments[2], exception);
- cairo_mask_surface (cr, surface, x, y);
+ x = seed_value_to_double(ctx, arguments[1], exception);
+ y = seed_value_to_double(ctx, arguments[2], exception);
+ cairo_mask_surface(cr, surface, x, y);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_mask (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_mask(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_t *cr;
- cairo_pattern_t *pat;
+ cairo_t* cr;
+ cairo_pattern_t* pat;
- CHECK_THIS();
- if (argument_count != 1 && argument_count != 3)
- {
- EXPECTED_EXCEPTION("mask", "1 or 3 arguments");
+ CHECK_THIS();
+ if (argument_count != 1 && argument_count != 3) {
+ EXPECTED_EXCEPTION("mask", "1 or 3 arguments");
}
- if (argument_count == 3)
- return seed_cairo_mask_surface (ctx, function, this_object, argument_count, arguments, exception);
- cr = seed_object_get_private (this_object);
- pat = seed_object_to_cairo_pattern (ctx, arguments[0], exception);
- if (!pat)
- {
- seed_make_exception (ctx, arguments[0], "ArgumentError", "First argument should be a cairo_pattern"
- " (or cairo surface if there are three arguments)");
- return seed_make_undefined (ctx);
+ if (argument_count == 3)
+ return seed_cairo_mask_surface(ctx, function, this_object,
+ argument_count, arguments, exception);
+ cr = seed_object_get_private(this_object);
+ pat = seed_object_to_cairo_pattern(ctx, arguments[0], exception);
+ if (!pat) {
+ seed_make_exception(ctx, arguments[0], "ArgumentError",
+ "First argument should be a cairo_pattern"
+ " (or cairo surface if there are three arguments)");
+ return seed_make_undefined(ctx);
}
- cairo_mask (cr, pat);
- return seed_make_undefined (ctx);
+ cairo_mask(cr, pat);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_paint (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_paint(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_paint(cr);
- return seed_make_undefined (ctx);
+ cairo_paint(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_paint_with_alpha (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_paint_with_alpha(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_t *cr;
- CHECK_THIS();
+ cairo_t* cr;
+ CHECK_THIS();
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("paint_with_alpha", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("paint_with_alpha", "1 argument");
}
- cr = seed_object_get_private (this_object);
- cairo_paint_with_alpha (cr, seed_value_to_double (ctx, arguments[0], exception));
+ cr = seed_object_get_private(this_object);
+ cairo_paint_with_alpha(cr,
+ seed_value_to_double(ctx, arguments[0], exception));
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_stroke (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_stroke(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_stroke(cr);
- return seed_make_undefined (ctx);
+ cairo_stroke(cr);
+ return seed_make_undefined(ctx);
}
-
static SeedValue
-seed_cairo_stroke_preserve (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_stroke_preserve(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_stroke_preserve(cr);
- return seed_make_undefined (ctx);
+ cairo_stroke_preserve(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_stroke_extents (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_stroke_extents(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue jsextents[4];
- gdouble extents[4];
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ SeedValue jsextents[4];
+ gdouble extents[4];
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 4)
- {
- EXPECTED_EXCEPTION("clip_extents", "4 arguments");
+ if (argument_count != 4) {
+ EXPECTED_EXCEPTION("clip_extents", "4 arguments");
}
- cairo_stroke_extents (cr, &extents[0], &extents[1], &extents[2], &extents[3]);
- jsextents[0] = seed_value_from_double (ctx, extents[0], exception);
- jsextents[1] = seed_value_from_double (ctx, extents[1], exception);
- jsextents[2] = seed_value_from_double (ctx, extents[2], exception);
- jsextents[3] = seed_value_from_double (ctx, extents[3], exception);
+ cairo_stroke_extents(cr, &extents[0], &extents[1], &extents[2],
+ &extents[3]);
+ jsextents[0] = seed_value_from_double(ctx, extents[0], exception);
+ jsextents[1] = seed_value_from_double(ctx, extents[1], exception);
+ jsextents[2] = seed_value_from_double(ctx, extents[2], exception);
+ jsextents[3] = seed_value_from_double(ctx, extents[3], exception);
- return seed_make_array (ctx, jsextents, 4, exception);
+ return seed_make_array(ctx, jsextents, 4, exception);
}
static SeedValue
-seed_cairo_in_stroke (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_in_stroke(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x, y;
- cairo_t *cr;
- CHECK_THIS();
- cr = seed_object_get_private (this_object);
+ gdouble x, y;
+ cairo_t* cr;
+ CHECK_THIS();
+ cr = seed_object_get_private(this_object);
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("in_stroke", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("in_stroke", "2 arguments");
}
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
- return seed_value_from_boolean (ctx, cairo_in_stroke (cr, x, y), exception);
+ return seed_value_from_boolean(ctx, cairo_in_stroke(cr, x, y), exception);
}
static SeedValue
-seed_cairo_copy_page (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_copy_page(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_copy_page(cr);
- return seed_make_undefined (ctx);
+ cairo_copy_page(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_show_page (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_show_page(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_show_page(cr);
- return seed_make_undefined (ctx);
+ cairo_show_page(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_has_current_point (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_has_current_point(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- return seed_value_from_boolean (ctx, cairo_has_current_point(cr), exception);
+ return seed_value_from_boolean(ctx, cairo_has_current_point(cr), exception);
}
static SeedValue
-seed_cairo_get_current_point (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_get_current_point(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue points[2];
- gdouble x, y;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ SeedValue points[2];
+ gdouble x, y;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_get_current_point (cr, &x, &y);
- points[0] = seed_value_from_double (ctx, x, exception);
- points[1] = seed_value_from_double (ctx, y, exception);
+ cairo_get_current_point(cr, &x, &y);
+ points[0] = seed_value_from_double(ctx, x, exception);
+ points[1] = seed_value_from_double(ctx, y, exception);
- return seed_make_array (ctx, points, 2, exception);
+ return seed_make_array(ctx, points, 2, exception);
}
static SeedValue
-seed_cairo_new_path (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_new_path(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_new_path(cr);
- return seed_make_undefined (ctx);
+ cairo_new_path(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_new_sub_path (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_new_sub_path(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_new_sub_path(cr);
- return seed_make_undefined (ctx);
+ cairo_new_sub_path(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_close_path (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_close_path(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_close_path(cr);
- return seed_make_undefined (ctx);
+ cairo_close_path(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_arc (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_arc(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble xc, yc, radius, angle1, angle2;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble xc, yc, radius, angle1, angle2;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 5)
- {
- EXPECTED_EXCEPTION ("arc", "5 arguments");
+ if (argument_count != 5) {
+ EXPECTED_EXCEPTION("arc", "5 arguments");
}
- xc = seed_value_to_double (ctx, arguments[0], exception);
- yc = seed_value_to_double (ctx, arguments[1], exception);
- radius = seed_value_to_double (ctx, arguments[2], exception);
- angle1 = seed_value_to_double (ctx, arguments[3], exception);
- angle2 = seed_value_to_double (ctx, arguments[4], exception);
+ xc = seed_value_to_double(ctx, arguments[0], exception);
+ yc = seed_value_to_double(ctx, arguments[1], exception);
+ radius = seed_value_to_double(ctx, arguments[2], exception);
+ angle1 = seed_value_to_double(ctx, arguments[3], exception);
+ angle2 = seed_value_to_double(ctx, arguments[4], exception);
- cairo_arc (cr, xc, yc, radius, angle1, angle2);
- return seed_make_undefined (ctx);
+ cairo_arc(cr, xc, yc, radius, angle1, angle2);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_arc_negative (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_arc_negative(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble xc, yc, radius, angle1, angle2;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble xc, yc, radius, angle1, angle2;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 5)
- {
- EXPECTED_EXCEPTION ("arc_negative", "5 arguments");
+ if (argument_count != 5) {
+ EXPECTED_EXCEPTION("arc_negative", "5 arguments");
}
- xc = seed_value_to_double (ctx, arguments[0], exception);
- yc = seed_value_to_double (ctx, arguments[1], exception);
- radius = seed_value_to_double (ctx, arguments[2], exception);
- angle1 = seed_value_to_double (ctx, arguments[3], exception);
- angle2 = seed_value_to_double (ctx, arguments[4], exception);
+ xc = seed_value_to_double(ctx, arguments[0], exception);
+ yc = seed_value_to_double(ctx, arguments[1], exception);
+ radius = seed_value_to_double(ctx, arguments[2], exception);
+ angle1 = seed_value_to_double(ctx, arguments[3], exception);
+ angle2 = seed_value_to_double(ctx, arguments[4], exception);
- cairo_arc_negative (cr, xc, yc, radius, angle1, angle2);
- return seed_make_undefined (ctx);
+ cairo_arc_negative(cr, xc, yc, radius, angle1, angle2);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_curve_to (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_curve_to(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x1,y1,x2,y2,x3,y3;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble x1, y1, x2, y2, x3, y3;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 6)
- {
- EXPECTED_EXCEPTION ("curve_to", "6 arguments");
+ if (argument_count != 6) {
+ EXPECTED_EXCEPTION("curve_to", "6 arguments");
}
- x1 = seed_value_to_double (ctx, arguments[0], exception);
- y1 = seed_value_to_double (ctx, arguments[1], exception);
- x2 = seed_value_to_double (ctx, arguments[2], exception);
- y2 = seed_value_to_double (ctx, arguments[3], exception);
- x3 = seed_value_to_double (ctx, arguments[4], exception);
- y3 = seed_value_to_double (ctx, arguments[5], exception);
+ x1 = seed_value_to_double(ctx, arguments[0], exception);
+ y1 = seed_value_to_double(ctx, arguments[1], exception);
+ x2 = seed_value_to_double(ctx, arguments[2], exception);
+ y2 = seed_value_to_double(ctx, arguments[3], exception);
+ x3 = seed_value_to_double(ctx, arguments[4], exception);
+ y3 = seed_value_to_double(ctx, arguments[5], exception);
- cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
- return seed_make_undefined (ctx);
+ cairo_curve_to(cr, x1, y1, x2, y2, x3, y3);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_rel_curve_to (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_rel_curve_to(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x1,y1,x2,y2,x3,y3;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble x1, y1, x2, y2, x3, y3;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 6)
- {
- EXPECTED_EXCEPTION ("rel_curve_to", "6 arguments");
+ if (argument_count != 6) {
+ EXPECTED_EXCEPTION("rel_curve_to", "6 arguments");
}
- x1 = seed_value_to_double (ctx, arguments[0], exception);
- y1 = seed_value_to_double (ctx, arguments[1], exception);
- x2 = seed_value_to_double (ctx, arguments[2], exception);
- y2 = seed_value_to_double (ctx, arguments[3], exception);
- x3 = seed_value_to_double (ctx, arguments[4], exception);
- y3 = seed_value_to_double (ctx, arguments[5], exception);
+ x1 = seed_value_to_double(ctx, arguments[0], exception);
+ y1 = seed_value_to_double(ctx, arguments[1], exception);
+ x2 = seed_value_to_double(ctx, arguments[2], exception);
+ y2 = seed_value_to_double(ctx, arguments[3], exception);
+ x3 = seed_value_to_double(ctx, arguments[4], exception);
+ y3 = seed_value_to_double(ctx, arguments[5], exception);
- cairo_rel_curve_to (cr, x1, y1, x2, y2, x3, y3);
- return seed_make_undefined (ctx);
+ cairo_rel_curve_to(cr, x1, y1, x2, y2, x3, y3);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_line_to (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_line_to(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x1,y1;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble x1, y1;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("line_to", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("line_to", "2 arguments");
}
- x1 = seed_value_to_double (ctx, arguments[0], exception);
- y1 = seed_value_to_double (ctx, arguments[1], exception);
+ x1 = seed_value_to_double(ctx, arguments[0], exception);
+ y1 = seed_value_to_double(ctx, arguments[1], exception);
- cairo_line_to (cr, x1, y1);
- return seed_make_undefined (ctx);
+ cairo_line_to(cr, x1, y1);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_rel_line_to (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_rel_line_to(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x1,y1;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble x1, y1;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("rel_line_to", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("rel_line_to", "2 arguments");
}
- x1 = seed_value_to_double (ctx, arguments[0], exception);
- y1 = seed_value_to_double (ctx, arguments[1], exception);
+ x1 = seed_value_to_double(ctx, arguments[0], exception);
+ y1 = seed_value_to_double(ctx, arguments[1], exception);
- cairo_rel_line_to (cr, x1, y1);
- return seed_make_undefined (ctx);
+ cairo_rel_line_to(cr, x1, y1);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_move_to (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_move_to(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x1,y1;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble x1, y1;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("move_to", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("move_to", "2 arguments");
}
- x1 = seed_value_to_double (ctx, arguments[0], exception);
- y1 = seed_value_to_double (ctx, arguments[1], exception);
+ x1 = seed_value_to_double(ctx, arguments[0], exception);
+ y1 = seed_value_to_double(ctx, arguments[1], exception);
- cairo_move_to (cr, x1, y1);
- return seed_make_undefined (ctx);
+ cairo_move_to(cr, x1, y1);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_rel_move_to (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_rel_move_to(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x1,y1;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble x1, y1;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("rel_move_to", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("rel_move_to", "2 arguments");
}
- x1 = seed_value_to_double (ctx, arguments[0], exception);
- y1 = seed_value_to_double (ctx, arguments[1], exception);
+ x1 = seed_value_to_double(ctx, arguments[0], exception);
+ y1 = seed_value_to_double(ctx, arguments[1], exception);
- cairo_rel_move_to (cr, x1, y1);
- return seed_make_undefined (ctx);
+ cairo_rel_move_to(cr, x1, y1);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_rectangle (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_rectangle(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x1,y1, width, height;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble x1, y1, width, height;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 4)
- {
- EXPECTED_EXCEPTION ("rectangle", "2 arguments");
+ if (argument_count != 4) {
+ EXPECTED_EXCEPTION("rectangle", "2 arguments");
}
- x1 = seed_value_to_double (ctx, arguments[0], exception);
- y1 = seed_value_to_double (ctx, arguments[1], exception);
- width = seed_value_to_double (ctx, arguments[2], exception);
- height = seed_value_to_double (ctx, arguments[3], exception);
+ x1 = seed_value_to_double(ctx, arguments[0], exception);
+ y1 = seed_value_to_double(ctx, arguments[1], exception);
+ width = seed_value_to_double(ctx, arguments[2], exception);
+ height = seed_value_to_double(ctx, arguments[3], exception);
- cairo_rectangle (cr, x1, y1, width, height);
- return seed_make_undefined (ctx);
+ cairo_rectangle(cr, x1, y1, width, height);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_text_path (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_text_path(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_t *cr;
- gchar *text;
- CHECK_THIS();
- cr = seed_object_get_private (this_object);
+ cairo_t* cr;
+ gchar* text;
+ CHECK_THIS();
+ cr = seed_object_get_private(this_object);
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("text_path", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("text_path", "1 argument");
}
- text = seed_value_to_string (ctx, arguments[0], exception);
- cairo_text_path (cr, text);
- g_free (text);
+ text = seed_value_to_string(ctx, arguments[0], exception);
+ cairo_text_path(cr, text);
+ g_free(text);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_path_extents (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_path_extents(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue jsextents[4];
- gdouble extents[4];
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ SeedValue jsextents[4];
+ gdouble extents[4];
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 4)
- {
- EXPECTED_EXCEPTION("path_extents", "4 arguments");
+ if (argument_count != 4) {
+ EXPECTED_EXCEPTION("path_extents", "4 arguments");
}
- cairo_path_extents (cr, &extents[0], &extents[1], &extents[2], &extents[3]);
- jsextents[0] = seed_value_from_double (ctx, extents[0], exception);
- jsextents[1] = seed_value_from_double (ctx, extents[1], exception);
- jsextents[2] = seed_value_from_double (ctx, extents[2], exception);
- jsextents[3] = seed_value_from_double (ctx, extents[3], exception);
+ cairo_path_extents(cr, &extents[0], &extents[1], &extents[2], &extents[3]);
+ jsextents[0] = seed_value_from_double(ctx, extents[0], exception);
+ jsextents[1] = seed_value_from_double(ctx, extents[1], exception);
+ jsextents[2] = seed_value_from_double(ctx, extents[2], exception);
+ jsextents[3] = seed_value_from_double(ctx, extents[3], exception);
- return seed_make_array (ctx, jsextents, 4, exception);
+ return seed_make_array(ctx, jsextents, 4, exception);
}
static SeedValue
-seed_cairo_translate (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_translate(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x1,y1;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble x1, y1;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("translate", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("translate", "2 arguments");
}
- x1 = seed_value_to_double (ctx, arguments[0], exception);
- y1 = seed_value_to_double (ctx, arguments[1], exception);
+ x1 = seed_value_to_double(ctx, arguments[0], exception);
+ y1 = seed_value_to_double(ctx, arguments[1], exception);
- cairo_translate (cr, x1, y1);
- return seed_make_undefined (ctx);
+ cairo_translate(cr, x1, y1);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_scale (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_scale(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble x1,y1;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble x1, y1;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("scale", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("scale", "2 arguments");
}
- x1 = seed_value_to_double (ctx, arguments[0], exception);
- y1 = seed_value_to_double (ctx, arguments[1], exception);
+ x1 = seed_value_to_double(ctx, arguments[0], exception);
+ y1 = seed_value_to_double(ctx, arguments[1], exception);
- cairo_scale (cr, x1, y1);
- return seed_make_undefined (ctx);
+ cairo_scale(cr, x1, y1);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_rotate (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_rotate(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gdouble angle;
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ gdouble angle;
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION ("rotate", "1 arguments");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("rotate", "1 arguments");
}
- angle = seed_value_to_double (ctx, arguments[0], exception);
+ angle = seed_value_to_double(ctx, arguments[0], exception);
-
- cairo_rotate (cr, angle);
- return seed_make_undefined (ctx);
+ cairo_rotate(cr, angle);
+ return seed_make_undefined(ctx);
}
-
-
-
static SeedValue
-seed_cairo_transform (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_transform(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_matrix_t matrix;
- cairo_t *cr;
- CHECK_THIS();
+ cairo_matrix_t matrix;
+ cairo_t* cr;
+ CHECK_THIS();
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("transform", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("transform", "1 argument");
}
- if (!seed_value_to_cairo_matrix (ctx, arguments[0], &matrix, exception))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "transform expects an array
[xx,yx,xy,yy,x0,y0]");
- return seed_make_undefined (ctx);
+ if (!seed_value_to_cairo_matrix(ctx, arguments[0], &matrix, exception)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "transform expects an array [xx,yx,xy,yy,x0,y0]");
+ return seed_make_undefined(ctx);
}
- cr = seed_object_get_private (this_object);
+ cr = seed_object_get_private(this_object);
- cairo_transform (cr, &matrix);
- return seed_make_undefined (ctx);
+ cairo_transform(cr, &matrix);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_get_matrix (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_cairo_get_matrix(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- cairo_t *cr;
- cairo_matrix_t m;
- CHECK_THIS();
+ cairo_t* cr;
+ cairo_matrix_t m;
+ CHECK_THIS();
- cr = seed_object_get_private (this_object);
- cairo_get_matrix (cr, &m);
- return seed_value_from_cairo_matrix (ctx, &m, exception);
+ cr = seed_object_get_private(this_object);
+ cairo_get_matrix(cr, &m);
+ return seed_value_from_cairo_matrix(ctx, &m, exception);
}
static gboolean
-seed_cairo_set_matrix (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
-{
- cairo_matrix_t m;
- cairo_t *cr;
- CHECK_THIS_BOOL();
-
- cr = seed_object_get_private (this_object);
- if (!seed_value_to_cairo_matrix (ctx, value, &m, exception))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "matrix must be an array [xx,yx,xy,yy,x0,y0]");
- return FALSE;
+seed_cairo_set_matrix(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
+{
+ cairo_matrix_t m;
+ cairo_t* cr;
+ CHECK_THIS_BOOL();
+
+ cr = seed_object_get_private(this_object);
+ if (!seed_value_to_cairo_matrix(ctx, value, &m, exception)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "matrix must be an array [xx,yx,xy,yy,x0,y0]");
+ return FALSE;
}
- cairo_set_matrix (cr, &m);
+ cairo_set_matrix(cr, &m);
- return TRUE;
+ return TRUE;
}
static SeedValue
-seed_cairo_identity_matrix (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_identity_matrix(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- CHECK_THIS();
- cairo_t *cr = seed_object_get_private (this_object);
+ CHECK_THIS();
+ cairo_t* cr = seed_object_get_private(this_object);
- cairo_identity_matrix(cr);
- return seed_make_undefined (ctx);
+ cairo_identity_matrix(cr);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_cairo_user_to_device (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_user_to_device(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue out[2];
- cairo_t *cr;
- double ix, iy;
+ SeedValue out[2];
+ cairo_t* cr;
+ double ix, iy;
- CHECK_THIS();
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("user_to_device", "2 arguments");
+ CHECK_THIS();
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("user_to_device", "2 arguments");
}
- cr = seed_object_get_private (this_object);
- ix = seed_value_to_double (ctx, arguments[0], exception);
- iy = seed_value_to_double (ctx, arguments[1], exception);
+ cr = seed_object_get_private(this_object);
+ ix = seed_value_to_double(ctx, arguments[0], exception);
+ iy = seed_value_to_double(ctx, arguments[1], exception);
- cairo_user_to_device (cr, &ix, &iy);
- out[0] = seed_value_from_double (ctx, ix, exception);
- out[1] = seed_value_from_double (ctx, iy, exception);
+ cairo_user_to_device(cr, &ix, &iy);
+ out[0] = seed_value_from_double(ctx, ix, exception);
+ out[1] = seed_value_from_double(ctx, iy, exception);
- return seed_make_array (ctx, out, 2, exception);
+ return seed_make_array(ctx, out, 2, exception);
}
-
static SeedValue
-seed_cairo_user_to_device_distance (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_user_to_device_distance(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue out[2];
- cairo_t *cr;
- double ix, iy;
+ SeedValue out[2];
+ cairo_t* cr;
+ double ix, iy;
- CHECK_THIS();
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("user_to_device_distance", "2 arguments");
+ CHECK_THIS();
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("user_to_device_distance", "2 arguments");
}
- cr = seed_object_get_private (this_object);
- ix = seed_value_to_double (ctx, arguments[0], exception);
- iy = seed_value_to_double (ctx, arguments[1], exception);
+ cr = seed_object_get_private(this_object);
+ ix = seed_value_to_double(ctx, arguments[0], exception);
+ iy = seed_value_to_double(ctx, arguments[1], exception);
- cairo_user_to_device_distance (cr, &ix, &iy);
- out[0] = seed_value_from_double (ctx, ix, exception);
- out[1] = seed_value_from_double (ctx, iy, exception);
+ cairo_user_to_device_distance(cr, &ix, &iy);
+ out[0] = seed_value_from_double(ctx, ix, exception);
+ out[1] = seed_value_from_double(ctx, iy, exception);
- return seed_make_array (ctx, out, 2, exception);
+ return seed_make_array(ctx, out, 2, exception);
}
static SeedValue
-seed_cairo_device_to_user (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_device_to_user(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue out[2];
- cairo_t *cr;
- double ix, iy;
+ SeedValue out[2];
+ cairo_t* cr;
+ double ix, iy;
- CHECK_THIS();
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("device_to_user", "2 arguments");
+ CHECK_THIS();
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("device_to_user", "2 arguments");
}
- cr = seed_object_get_private (this_object);
- ix = seed_value_to_double (ctx, arguments[0], exception);
- iy = seed_value_to_double (ctx, arguments[1], exception);
+ cr = seed_object_get_private(this_object);
+ ix = seed_value_to_double(ctx, arguments[0], exception);
+ iy = seed_value_to_double(ctx, arguments[1], exception);
- cairo_device_to_user (cr, &ix, &iy);
- out[0] = seed_value_from_double (ctx, ix, exception);
- out[1] = seed_value_from_double (ctx, iy, exception);
+ cairo_device_to_user(cr, &ix, &iy);
+ out[0] = seed_value_from_double(ctx, ix, exception);
+ out[1] = seed_value_from_double(ctx, iy, exception);
- return seed_make_array (ctx, out, 2, exception);
+ return seed_make_array(ctx, out, 2, exception);
}
static SeedValue
-seed_cairo_device_to_user_distance (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_device_to_user_distance(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue out[2];
- cairo_t *cr;
- double ix, iy;
+ SeedValue out[2];
+ cairo_t* cr;
+ double ix, iy;
- CHECK_THIS();
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("device_to_user_distance", "2 arguments");
+ CHECK_THIS();
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("device_to_user_distance", "2 arguments");
}
- cr = seed_object_get_private (this_object);
- ix = seed_value_to_double (ctx, arguments[0], exception);
- iy = seed_value_to_double (ctx, arguments[1], exception);
+ cr = seed_object_get_private(this_object);
+ ix = seed_value_to_double(ctx, arguments[0], exception);
+ iy = seed_value_to_double(ctx, arguments[1], exception);
- cairo_device_to_user_distance (cr, &ix, &iy);
- out[0] = seed_value_from_double (ctx, ix, exception);
- out[1] = seed_value_from_double (ctx, iy, exception);
+ cairo_device_to_user_distance(cr, &ix, &iy);
+ out[0] = seed_value_from_double(ctx, ix, exception);
+ out[1] = seed_value_from_double(ctx, iy, exception);
- return seed_make_array (ctx, out, 2, exception);
+ return seed_make_array(ctx, out, 2, exception);
}
static SeedValue
-seed_cairo_set_source (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_cairo_set_source(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- cairo_t *cr;
- cairo_pattern_t *pat;
+ cairo_t* cr;
+ cairo_pattern_t* pat;
- CHECK_THIS();
- if (argument_count != 1 && argument_count != 3)
- {
- EXPECTED_EXCEPTION("set_source", "1 or 3 arguments");
+ CHECK_THIS();
+ if (argument_count != 1 && argument_count != 3) {
+ EXPECTED_EXCEPTION("set_source", "1 or 3 arguments");
}
- if (argument_count == 3)
- return seed_cairo_set_source_surface (ctx, function, this_object, argument_count, arguments, exception);
- pat = seed_object_to_cairo_pattern (ctx, arguments[0], exception);
- if (!pat)
- {
- seed_make_exception (ctx, exception, "ArgumentError", "set_source needs a Cairo Pattern as argument");
- return seed_make_undefined (ctx);
+ if (argument_count == 3)
+ return seed_cairo_set_source_surface(ctx, function, this_object,
+ argument_count, arguments,
+ exception);
+ pat = seed_object_to_cairo_pattern(ctx, arguments[0], exception);
+ if (!pat) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "set_source needs a Cairo Pattern as argument");
+ return seed_make_undefined(ctx);
}
- cr = seed_object_get_private (this_object);
- cairo_set_source (cr,pat);
-
- return seed_make_undefined (ctx);
-}
-
-static SeedValue
-seed_cairo_get_source (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
-{
- cairo_t *cr;
- CHECK_THIS();
-
- cr = seed_object_get_private (this_object);
-
- return seed_object_from_cairo_pattern (ctx, cairo_get_source(cr));
-}
-
-static SeedValue
-seed_cairo_destroy (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
-{
- seed_cairo_context_finalize(this_object);
- return seed_make_undefined (ctx);
-}
-
-seed_static_value cairo_values[] = {
- {"antialias", seed_cairo_get_antialias, seed_cairo_set_antialias, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"fill_rule", seed_cairo_get_fill_rule, seed_cairo_set_fill_rule, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"line_cap", seed_cairo_get_line_cap, seed_cairo_set_line_cap, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"line_join", seed_cairo_get_line_join, seed_cairo_set_line_join, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"line_width", seed_cairo_get_line_width, seed_cairo_set_line_width, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"miter_limit", seed_cairo_get_miter_limit, seed_cairo_set_miter_limit,
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"operator", seed_cairo_get_operator, seed_cairo_set_operator, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"tolerance", seed_cairo_get_tolerance, seed_cairo_set_tolerance, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"matrix", seed_cairo_get_matrix, seed_cairo_set_matrix, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"target", seed_cairo_get_target, NULL, SEED_PROPERTY_ATTRIBUTE_READ_ONLY |
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {NULL, NULL, NULL, 0}
-};
-
-seed_static_function cairo_funcs[] = {
- {"save", seed_cairo_save, 0},
- {"restore", seed_cairo_restore, 0},
- {"push_group", seed_cairo_push_group, 0},
- {"push_group_with_content", seed_cairo_push_group_with_content, 0},
- {"set_dash", seed_cairo_set_dash, 0},
- {"get_dash_count", seed_cairo_get_dash_count, 0},
- {"get_dash", seed_cairo_get_dash, 0},
- {"pop_group", seed_cairo_pop_group, 0},
- {"pop_group_to_source", seed_cairo_pop_group_to_source, 0},
- {"get_group_target", seed_cairo_get_group_target, 0},
- {"set_source_rgb", seed_cairo_set_source_rgb, 0},
- {"set_source_rgba", seed_cairo_set_source_rgba, 0},
- {"set_source", seed_cairo_set_source, 0},
- {"set_source_surface", seed_cairo_set_source_surface, 0},
- {"get_source", seed_cairo_get_source, 0},
- {"clip", seed_cairo_clip, 0},
- {"clip_preserve", seed_cairo_clip_preserve, 0},
- {"reset_clip", seed_cairo_reset_clip, 0},
- {"clip_extents", seed_cairo_clip_extents, 0},
- // Rectangle list stuff?
- {"fill", seed_cairo_fill, 0},
- {"fill_preserve", seed_cairo_fill_preserve, 0},
- {"fill_extents", seed_cairo_fill_extents, 0},
- {"mask", seed_cairo_mask, 0},
- {"in_fill", seed_cairo_in_fill, 0},
- {"paint", seed_cairo_paint, 0},
- {"paint_with_alpha", seed_cairo_paint_with_alpha, 0},
- {"stroke", seed_cairo_stroke, 0},
- {"stroke_preserve", seed_cairo_stroke_preserve, 0},
- {"stroke_extents", seed_cairo_stroke_extents, 0},
- {"in_stroke", seed_cairo_in_stroke, 0},
- {"copy_page", seed_cairo_copy_page, 0},
- {"show_page", seed_cairo_show_page, 0},
- {"has_current_point", seed_cairo_has_current_point, 0},
- {"get_current_point", seed_cairo_get_current_point, 0},
- {"new_path", seed_cairo_new_path, 0},
- {"new_sub_path", seed_cairo_new_sub_path, 0},
- {"close_path", seed_cairo_close_path, 0},
- {"arc", seed_cairo_arc, 0},
- {"arc_negative", seed_cairo_arc_negative, 0},
- {"curve_to", seed_cairo_curve_to, 0},
- {"line_to", seed_cairo_line_to, 0},
- {"move_to", seed_cairo_move_to, 0},
- {"rectangle", seed_cairo_rectangle, 0},
- //{"cairo_glpyh_path", seed_cairo_glyph_path, 0},
- {"text_path", seed_cairo_text_path, 0},
- {"rel_curve_to", seed_cairo_rel_curve_to, 0},
- {"rel_line_to", seed_cairo_rel_line_to, 0},
- {"rel_move_to", seed_cairo_rel_move_to, 0},
- {"path_extents", seed_cairo_path_extents, 0},
- {"translate", seed_cairo_translate, 0},
- {"scale", seed_cairo_scale, 0},
- {"rotate", seed_cairo_rotate, 0},
- {"transform", seed_cairo_transform, 0},
- {"identify_matrix", seed_cairo_identity_matrix, 0},
- {"user_to_device", seed_cairo_user_to_device, 0},
- {"user_to_device_distance", seed_cairo_user_to_device_distance, 0},
- {"device_to_user", seed_cairo_device_to_user, 0},
- {"device_to_user_distance", seed_cairo_device_to_user_distance, 0},
- {"destroy", seed_cairo_destroy, 0},
- {NULL, NULL, 0}
-};
+ cr = seed_object_get_private(this_object);
+ cairo_set_source(cr, pat);
+
+ return seed_make_undefined(ctx);
+}
+
+static SeedValue
+seed_cairo_get_source(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
+{
+ cairo_t* cr;
+ CHECK_THIS();
+
+ cr = seed_object_get_private(this_object);
+
+ return seed_object_from_cairo_pattern(ctx, cairo_get_source(cr));
+}
+
+static SeedValue
+seed_cairo_destroy(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
+{
+ seed_cairo_context_finalize(this_object);
+ return seed_make_undefined(ctx);
+}
+
+seed_static_value cairo_values[]
+ = { { "antialias", seed_cairo_get_antialias, seed_cairo_set_antialias,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "fill_rule", seed_cairo_get_fill_rule, seed_cairo_set_fill_rule,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "line_cap", seed_cairo_get_line_cap, seed_cairo_set_line_cap,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "line_join", seed_cairo_get_line_join, seed_cairo_set_line_join,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "line_width", seed_cairo_get_line_width, seed_cairo_set_line_width,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "miter_limit", seed_cairo_get_miter_limit, seed_cairo_set_miter_limit,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "operator", seed_cairo_get_operator, seed_cairo_set_operator,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "tolerance", seed_cairo_get_tolerance, seed_cairo_set_tolerance,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "matrix", seed_cairo_get_matrix, seed_cairo_set_matrix,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "target", seed_cairo_get_target, NULL,
+ SEED_PROPERTY_ATTRIBUTE_READ_ONLY
+ | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { NULL, NULL, NULL, 0 } };
+
+seed_static_function cairo_funcs[]
+ = { { "save", seed_cairo_save, 0 },
+ { "restore", seed_cairo_restore, 0 },
+ { "push_group", seed_cairo_push_group, 0 },
+ { "push_group_with_content", seed_cairo_push_group_with_content, 0 },
+ { "set_dash", seed_cairo_set_dash, 0 },
+ { "get_dash_count", seed_cairo_get_dash_count, 0 },
+ { "get_dash", seed_cairo_get_dash, 0 },
+ { "pop_group", seed_cairo_pop_group, 0 },
+ { "pop_group_to_source", seed_cairo_pop_group_to_source, 0 },
+ { "get_group_target", seed_cairo_get_group_target, 0 },
+ { "set_source_rgb", seed_cairo_set_source_rgb, 0 },
+ { "set_source_rgba", seed_cairo_set_source_rgba, 0 },
+ { "set_source", seed_cairo_set_source, 0 },
+ { "set_source_surface", seed_cairo_set_source_surface, 0 },
+ { "get_source", seed_cairo_get_source, 0 },
+ { "clip", seed_cairo_clip, 0 },
+ { "clip_preserve", seed_cairo_clip_preserve, 0 },
+ { "reset_clip", seed_cairo_reset_clip, 0 },
+ { "clip_extents", seed_cairo_clip_extents, 0 },
+ // Rectangle list stuff?
+ { "fill", seed_cairo_fill, 0 },
+ { "fill_preserve", seed_cairo_fill_preserve, 0 },
+ { "fill_extents", seed_cairo_fill_extents, 0 },
+ { "mask", seed_cairo_mask, 0 },
+ { "in_fill", seed_cairo_in_fill, 0 },
+ { "paint", seed_cairo_paint, 0 },
+ { "paint_with_alpha", seed_cairo_paint_with_alpha, 0 },
+ { "stroke", seed_cairo_stroke, 0 },
+ { "stroke_preserve", seed_cairo_stroke_preserve, 0 },
+ { "stroke_extents", seed_cairo_stroke_extents, 0 },
+ { "in_stroke", seed_cairo_in_stroke, 0 },
+ { "copy_page", seed_cairo_copy_page, 0 },
+ { "show_page", seed_cairo_show_page, 0 },
+ { "has_current_point", seed_cairo_has_current_point, 0 },
+ { "get_current_point", seed_cairo_get_current_point, 0 },
+ { "new_path", seed_cairo_new_path, 0 },
+ { "new_sub_path", seed_cairo_new_sub_path, 0 },
+ { "close_path", seed_cairo_close_path, 0 },
+ { "arc", seed_cairo_arc, 0 },
+ { "arc_negative", seed_cairo_arc_negative, 0 },
+ { "curve_to", seed_cairo_curve_to, 0 },
+ { "line_to", seed_cairo_line_to, 0 },
+ { "move_to", seed_cairo_move_to, 0 },
+ { "rectangle", seed_cairo_rectangle, 0 },
+ //{"cairo_glpyh_path", seed_cairo_glyph_path, 0},
+ { "text_path", seed_cairo_text_path, 0 },
+ { "rel_curve_to", seed_cairo_rel_curve_to, 0 },
+ { "rel_line_to", seed_cairo_rel_line_to, 0 },
+ { "rel_move_to", seed_cairo_rel_move_to, 0 },
+ { "path_extents", seed_cairo_path_extents, 0 },
+ { "translate", seed_cairo_translate, 0 },
+ { "scale", seed_cairo_scale, 0 },
+ { "rotate", seed_cairo_rotate, 0 },
+ { "transform", seed_cairo_transform, 0 },
+ { "identify_matrix", seed_cairo_identity_matrix, 0 },
+ { "user_to_device", seed_cairo_user_to_device, 0 },
+ { "user_to_device_distance", seed_cairo_user_to_device_distance, 0 },
+ { "device_to_user", seed_cairo_device_to_user, 0 },
+ { "device_to_user_distance", seed_cairo_device_to_user_distance, 0 },
+ { "destroy", seed_cairo_destroy, 0 },
+ { NULL, NULL, 0 } };
SeedObject
-seed_module_init(SeedEngine * local_eng)
-{
- SeedObject context_constructor_ref;
- SeedObject gdk_context_constructor_ref;
- SeedObject steal_context_constructor_ref;
- SeedObject namespace_ref;
- seed_class_definition cairo_def = seed_empty_class;
- eng = local_eng;
- namespace_ref = seed_make_object (eng->context, NULL, NULL);
-
- // Temporary hack until API changes.
- seed_value_protect (eng->context, namespace_ref);
-
- seed_define_cairo_enums (eng->context, namespace_ref);
- seed_define_cairo_surface (eng->context, namespace_ref);
- seed_define_cairo_matrix (eng->context, namespace_ref);
- seed_define_cairo_pattern (eng->context, namespace_ref);
-
- cairo_def.class_name = "Context";
- cairo_def.static_functions = cairo_funcs;
- cairo_def.static_values = cairo_values;
- cairo_def.finalize = seed_cairo_context_finalize;
- seed_cairo_context_class = seed_create_class (&cairo_def);
- // Hack around WebKit GC bug.
- context_constructor_ref = seed_make_constructor (eng->context,
- NULL,
- // seed_cairo_context_class,
- seed_cairo_construct_context);
- gdk_context_constructor_ref = seed_make_constructor (eng->context,
- NULL,
- //
seed_cairo_context_class,
- seed_cairo_construct_context_from_window);
- steal_context_constructor_ref = seed_make_constructor (eng->context,
- NULL,
- //
seed_cairo_context_class,
- seed_cairo_construct_context_steal);
-
- seed_object_set_property (eng->context, namespace_ref, "Context", context_constructor_ref);
- seed_object_set_property (eng->context, context_constructor_ref, "from_window",
gdk_context_constructor_ref);
- seed_object_set_property (eng->context, context_constructor_ref, "steal", steal_context_constructor_ref);
-
- return namespace_ref;
+seed_module_init(SeedEngine* local_eng)
+{
+ SeedObject context_constructor_ref;
+ SeedObject gdk_context_constructor_ref;
+ SeedObject steal_context_constructor_ref;
+ SeedObject namespace_ref;
+ seed_class_definition cairo_def = seed_empty_class;
+ eng = local_eng;
+ namespace_ref = seed_make_object(eng->context, NULL, NULL);
+
+ // Temporary hack until API changes.
+ seed_value_protect(eng->context, namespace_ref);
+
+ seed_define_cairo_enums(eng->context, namespace_ref);
+ seed_define_cairo_surface(eng->context, namespace_ref);
+ seed_define_cairo_matrix(eng->context, namespace_ref);
+ seed_define_cairo_pattern(eng->context, namespace_ref);
+
+ cairo_def.class_name = "Context";
+ cairo_def.static_functions = cairo_funcs;
+ cairo_def.static_values = cairo_values;
+ cairo_def.finalize = seed_cairo_context_finalize;
+ seed_cairo_context_class = seed_create_class(&cairo_def);
+ // Hack around WebKit GC bug.
+ context_constructor_ref = seed_make_constructor(
+ eng->context, NULL,
+ // seed_cairo_context_class,
+ seed_cairo_construct_context);
+ gdk_context_constructor_ref = seed_make_constructor(
+ eng->context, NULL,
+ // seed_cairo_context_class,
+ seed_cairo_construct_context_from_window);
+ steal_context_constructor_ref = seed_make_constructor(
+ eng->context, NULL,
+ // seed_cairo_context_class,
+ seed_cairo_construct_context_steal);
+
+ seed_object_set_property(eng->context, namespace_ref, "Context",
+ context_constructor_ref);
+ seed_object_set_property(eng->context, context_constructor_ref,
+ "from_window", gdk_context_constructor_ref);
+ seed_object_set_property(eng->context, context_constructor_ref, "steal",
+ steal_context_constructor_ref);
+
+ return namespace_ref;
}
diff --git a/modules/cairo/seed-cairo.h b/modules/cairo/seed-cairo.h
index 6892e4e..e0836d1 100644
--- a/modules/cairo/seed-cairo.h
+++ b/modules/cairo/seed-cairo.h
@@ -3,11 +3,12 @@
#include <seed.h>
#include <cairo/cairo.h>
-#define EXPECTED_EXCEPTION(name, argnum) \
- seed_make_exception (ctx, exception, "ArgumentError", name " expected " argnum " got %zd",
argument_count); \
- return seed_make_undefined (ctx);
+#define EXPECTED_EXCEPTION(name, argnum) \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ name " expected " argnum " got %zd", argument_count); \
+ return seed_make_undefined(ctx);
-cairo_user_data_key_t *seed_get_cairo_key ();
-void seed_cairo_destroy_func (void *obj);
+cairo_user_data_key_t* seed_get_cairo_key();
+void seed_cairo_destroy_func(void* obj);
#endif
diff --git a/modules/canvas/seed-canvas.c b/modules/canvas/seed-canvas.c
index aafac85..9ec9022 100644
--- a/modules/canvas/seed-canvas.c
+++ b/modules/canvas/seed-canvas.c
@@ -27,1069 +27,1068 @@
SeedObject namespace_ref;
SeedClass canvas_class;
-SeedEngine *eng;
+SeedEngine* eng;
-typedef struct _SeedCanvasColor {
- gdouble r;
- gdouble g;
- gdouble b;
- gdouble a;
+typedef struct _SeedCanvasColor
+{
+ gdouble r;
+ gdouble g;
+ gdouble b;
+ gdouble a;
} SeedCanvasColor;
-typedef struct _SeedCanvasStyle {
- SeedCanvasColor fill;
- SeedCanvasColor stroke;
+typedef struct _SeedCanvasStyle
+{
+ SeedCanvasColor fill;
+ SeedCanvasColor stroke;
- gdouble global_opacity;
- cairo_operator_t operator;
+ gdouble global_opacity;
+ cairo_operator_t operator;
} SeedCanvasStyle;
-typedef struct _SeedCanvasPrivates {
- cairo_t *cr;
+typedef struct _SeedCanvasPrivates
+{
+ cairo_t* cr;
- GSList *styles;
+ GSList* styles;
} SeedCanvasPrivates;
-#define GET_CR \
- SeedCanvasPrivates *priv = seed_object_get_private(this_object); \
- cairo_t *cr = priv->cr
-
+#define GET_CR \
+ SeedCanvasPrivates* priv = seed_object_get_private(this_object); \
+ cairo_t* cr = priv->cr
SeedObject
-canvas_construct_canvas_from_cairo (SeedContext ctx, cairo_t * cr,
- SeedException * exception)
+canvas_construct_canvas_from_cairo(SeedContext ctx,
+ cairo_t* cr,
+ SeedException* exception)
{
- SeedObject obj;
- SeedCanvasPrivates *priv = g_slice_alloc(sizeof(SeedCanvasPrivates));
-
- cairo_set_source_rgb (cr, 0, 0, 0);
- cairo_set_miter_limit (cr, 10);
-
- priv->cr = cr;
- priv->styles = NULL;
-
- obj = seed_make_object (ctx, canvas_class, priv);
-
- seed_object_set_property (ctx, obj, "globalAlpha",
- seed_value_from_double (ctx, 1.0, exception));
- seed_object_set_property (ctx, obj, "lineWidth",
- seed_value_from_double (ctx, 1.0, exception));
- seed_object_set_property (ctx, obj, "miterLimit",
- seed_value_from_double (ctx, 10, exception));
- seed_object_set_property (ctx, obj, "lineCap",
- seed_value_from_string (ctx, "butt", exception));
- seed_object_set_property (ctx, obj, "lineJoin",
- seed_value_from_string (ctx, "miter", exception));
- seed_object_set_property (ctx, obj, "cairo",
- (SeedValue) seed_make_pointer (ctx, cr));
-
- return obj;
+ SeedObject obj;
+ SeedCanvasPrivates* priv = g_slice_alloc(sizeof(SeedCanvasPrivates));
+
+ cairo_set_source_rgb(cr, 0, 0, 0);
+ cairo_set_miter_limit(cr, 10);
+
+ priv->cr = cr;
+ priv->styles = NULL;
+
+ obj = seed_make_object(ctx, canvas_class, priv);
+
+ seed_object_set_property(ctx, obj, "globalAlpha",
+ seed_value_from_double(ctx, 1.0, exception));
+ seed_object_set_property(ctx, obj, "lineWidth",
+ seed_value_from_double(ctx, 1.0, exception));
+ seed_object_set_property(ctx, obj, "miterLimit",
+ seed_value_from_double(ctx, 10, exception));
+ seed_object_set_property(ctx, obj, "lineCap",
+ seed_value_from_string(ctx, "butt", exception));
+ seed_object_set_property(ctx, obj, "lineJoin",
+ seed_value_from_string(ctx, "miter", exception));
+ seed_object_set_property(ctx, obj, "cairo",
+ (SeedValue) seed_make_pointer(ctx, cr));
+
+ return obj;
}
SeedObject
-seed_construct_image_canvas (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_construct_image_canvas(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedObject obj;
- cairo_surface_t *surface;
- cairo_t *cr;
- gchar *filename;
- gdouble width, height;
-
- if (argument_count != 3)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Canvas.PDFCanvas constructor expected"
- "3 arguments");
- return (SeedObject) seed_make_null (ctx);
+ SeedObject obj;
+ cairo_surface_t* surface;
+ cairo_t* cr;
+ gchar* filename;
+ gdouble width, height;
+
+ if (argument_count != 3) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Canvas.PDFCanvas constructor expected"
+ "3 arguments");
+ return (SeedObject) seed_make_null(ctx);
}
- filename = seed_value_to_string (ctx, arguments[0], exception);
+ filename = seed_value_to_string(ctx, arguments[0], exception);
- width = seed_value_to_double (ctx, arguments[1], exception);
- height = seed_value_to_double (ctx, arguments[2], exception);
+ width = seed_value_to_double(ctx, arguments[1], exception);
+ height = seed_value_to_double(ctx, arguments[2], exception);
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
- cr = cairo_create (surface);
- cairo_surface_destroy (surface);
+ surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
+ cr = cairo_create(surface);
+ cairo_surface_destroy(surface);
- obj = canvas_construct_canvas_from_cairo (ctx, cr, exception);
+ obj = canvas_construct_canvas_from_cairo(ctx, cr, exception);
- return obj;
+ return obj;
}
SeedObject
-canvas_construct_pdf_canvas (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+canvas_construct_pdf_canvas(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedObject obj;
- cairo_surface_t *surface;
- cairo_t *cr;
- gchar *filename;
- gdouble width, height;
-
- if (argument_count != 3)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Canvas.PDFCanvas constructor expected"
- "3 arguments");
- return (SeedObject) seed_make_null (ctx);
+ SeedObject obj;
+ cairo_surface_t* surface;
+ cairo_t* cr;
+ gchar* filename;
+ gdouble width, height;
+
+ if (argument_count != 3) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Canvas.PDFCanvas constructor expected"
+ "3 arguments");
+ return (SeedObject) seed_make_null(ctx);
}
- filename = seed_value_to_string (ctx, arguments[0], exception);
+ filename = seed_value_to_string(ctx, arguments[0], exception);
- width = seed_value_to_double (ctx, arguments[1], exception);
- height = seed_value_to_double (ctx, arguments[2], exception);
+ width = seed_value_to_double(ctx, arguments[1], exception);
+ height = seed_value_to_double(ctx, arguments[2], exception);
- surface = cairo_pdf_surface_create (filename, width, height);
- cr = cairo_create (surface);
- cairo_surface_destroy (surface);
+ surface = cairo_pdf_surface_create(filename, width, height);
+ cr = cairo_create(surface);
+ cairo_surface_destroy(surface);
- obj = canvas_construct_canvas_from_cairo (ctx, cr, exception);
+ obj = canvas_construct_canvas_from_cairo(ctx, cr, exception);
- return obj;
+ return obj;
}
SeedObject
-canvas_construct_svg_canvas (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+canvas_construct_svg_canvas(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedObject obj;
- cairo_surface_t *surface;
- cairo_t *cr;
- gchar *filename;
- gdouble width, height;
-
- if (argument_count != 3)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Canvas.PDFCanvas constructor expected"
- "3 arguments");
- return (SeedObject) seed_make_null (ctx);
+ SeedObject obj;
+ cairo_surface_t* surface;
+ cairo_t* cr;
+ gchar* filename;
+ gdouble width, height;
+
+ if (argument_count != 3) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Canvas.PDFCanvas constructor expected"
+ "3 arguments");
+ return (SeedObject) seed_make_null(ctx);
}
- filename = seed_value_to_string (ctx, arguments[0], exception);
+ filename = seed_value_to_string(ctx, arguments[0], exception);
- width = seed_value_to_double (ctx, arguments[1], exception);
- height = seed_value_to_double (ctx, arguments[2], exception);
+ width = seed_value_to_double(ctx, arguments[1], exception);
+ height = seed_value_to_double(ctx, arguments[2], exception);
- surface = cairo_svg_surface_create (filename, width, height);
- cr = cairo_create (surface);
- cairo_surface_destroy (surface);
+ surface = cairo_svg_surface_create(filename, width, height);
+ cr = cairo_create(surface);
+ cairo_surface_destroy(surface);
- obj = canvas_construct_canvas_from_cairo (ctx, cr, exception);
+ obj = canvas_construct_canvas_from_cairo(ctx, cr, exception);
- return obj;
+ return obj;
}
SeedObject
-canvas_construct_canvas (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+canvas_construct_canvas(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedObject obj;
- cairo_t *cr;
- if (argument_count != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Canvas.CairoCanvas constructor"
- "expected 1 argument");
- return (SeedObject) seed_make_null (ctx);
+ SeedObject obj;
+ cairo_t* cr;
+ if (argument_count != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Canvas.CairoCanvas constructor"
+ "expected 1 argument");
+ return (SeedObject) seed_make_null(ctx);
}
- cr = seed_pointer_get_pointer (ctx, arguments[0]);
+ cr = seed_pointer_get_pointer(ctx, arguments[0]);
- obj = canvas_construct_canvas_from_cairo (ctx, cr, exception);
+ obj = canvas_construct_canvas_from_cairo(ctx, cr, exception);
- return obj;
+ return obj;
}
void
-seed_canvas_parse_color (SeedCanvasColor *color,
- gchar *spec)
+seed_canvas_parse_color(SeedCanvasColor* color, gchar* spec)
{
- if (*spec == '#')
- {
- guint r = 0, g = 0, b = 0, a = 0, found;
-
- if (strlen (spec) > 4)
- found = sscanf(spec, "#%2x%2x%2x%2x", &r, &g, &b, &a);
- else
- {
- found = sscanf (spec, "#%1x%1x%1x%1x", &r, &g, &b, &a);
- r *= 17;
- g *= 17;
- b *= 17;
- a *= 17;
- }
- if (found < 4)
- a = 0xff;
-
- color->r = r / 255.0;
- color->g = g / 255.0;
- color->b = b / 255.0;
- color->a = a / 255.0;
-
- return;
- }
- else if (*spec == 'r')
- {
- switch (*(spec + 3))
- {
- case 'a':
- {
- gdouble r, g, b;
- gfloat a;
-
- sscanf (spec, "rgba(%lf,%lf,%lf,%f)", &r, &g, &b, &a);
-
- color->r = r/255.0;
- color->g = g/255.0;
- color->b = b/255.0;
- color->a = a;
-
- return;
- }
- case '(':
- {
- gdouble r, g, b;
-
- sscanf (spec, "rgb(%lf,%lf,%lf)", &r, &g, &b);
-
- color->r = r / 255.0;
- color->g = g / 255.0;
- color->b = b / 255.0;
- color->a = 1.0;
-
- return;
- }
- }
- }
- else if (*spec == '[')
- {
- color->r = color->b = color->g = 0;
- color->a = 1;
+ if (*spec == '#') {
+ guint r = 0, g = 0, b = 0, a = 0, found;
+
+ if (strlen(spec) > 4)
+ found = sscanf(spec, "#%2x%2x%2x%2x", &r, &g, &b, &a);
+ else {
+ found = sscanf(spec, "#%1x%1x%1x%1x", &r, &g, &b, &a);
+ r *= 17;
+ g *= 17;
+ b *= 17;
+ a *= 17;
+ }
+ if (found < 4)
+ a = 0xff;
+
+ color->r = r / 255.0;
+ color->g = g / 255.0;
+ color->b = b / 255.0;
+ color->a = a / 255.0;
+
+ return;
+ } else if (*spec == 'r') {
+ switch (*(spec + 3)) {
+ case 'a': {
+ gdouble r, g, b;
+ gfloat a;
+
+ sscanf(spec, "rgba(%lf,%lf,%lf,%f)", &r, &g, &b, &a);
+
+ color->r = r / 255.0;
+ color->g = g / 255.0;
+ color->b = b / 255.0;
+ color->a = a;
+
+ return;
+ }
+ case '(': {
+ gdouble r, g, b;
+
+ sscanf(spec, "rgb(%lf,%lf,%lf)", &r, &g, &b);
+
+ color->r = r / 255.0;
+ color->g = g / 255.0;
+ color->b = b / 255.0;
+ color->a = 1.0;
+
+ return;
+ }
+ }
+ } else if (*spec == '[') {
+ color->r = color->b = color->g = 0;
+ color->a = 1;
}
}
gboolean
-seed_canvas_update_stroke_style (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException * e)
+seed_canvas_update_stroke_style(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* e)
{
- SeedCanvasStyle *style;
- SeedCanvasPrivates *priv = seed_object_get_private(this_object);
+ SeedCanvasStyle* style;
+ SeedCanvasPrivates* priv = seed_object_get_private(this_object);
- gchar *stroke_style = seed_value_to_string (ctx, value, e);
+ gchar* stroke_style = seed_value_to_string(ctx, value, e);
- if (!priv->styles)
- {
- priv->styles = g_slist_prepend(priv->styles, g_new0(SeedCanvasStyle, 1));
- ((SeedCanvasStyle *) priv->styles->data)->global_opacity = 1;
- ((SeedCanvasStyle *) priv->styles->data)->fill.a = 1;
- ((SeedCanvasStyle *) priv->styles->data)->operator = CAIRO_OPERATOR_OVER;
+ if (!priv->styles) {
+ priv->styles
+ = g_slist_prepend(priv->styles, g_new0(SeedCanvasStyle, 1));
+ ((SeedCanvasStyle*) priv->styles->data)->global_opacity = 1;
+ ((SeedCanvasStyle*) priv->styles->data)->fill.a = 1;
+ ((SeedCanvasStyle*) priv->styles->data)->operator= CAIRO_OPERATOR_OVER;
}
- style = (SeedCanvasStyle *)priv->styles->data;
+ style = (SeedCanvasStyle*) priv->styles->data;
- seed_canvas_parse_color (&style->stroke, stroke_style);
+ seed_canvas_parse_color(&style->stroke, stroke_style);
- g_free(stroke_style);
+ g_free(stroke_style);
- return TRUE;
+ return TRUE;
}
-
gboolean
-seed_canvas_update_fill_style (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value, SeedException * e)
+seed_canvas_update_fill_style(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* e)
{
- SeedCanvasStyle *style;
- SeedCanvasPrivates *priv = seed_object_get_private(this_object);
+ SeedCanvasStyle* style;
+ SeedCanvasPrivates* priv = seed_object_get_private(this_object);
- gchar *fill_style = seed_value_to_string (ctx, value, e);
+ gchar* fill_style = seed_value_to_string(ctx, value, e);
- if (!priv->styles)
- {
- priv->styles = g_slist_prepend(priv->styles, g_new0(SeedCanvasStyle, 1));
- ((SeedCanvasStyle *) priv->styles->data)->global_opacity = 1;
- ((SeedCanvasStyle *) priv->styles->data)->stroke.a = 1;
- ((SeedCanvasStyle *) priv->styles->data)->operator = CAIRO_OPERATOR_OVER;
+ if (!priv->styles) {
+ priv->styles
+ = g_slist_prepend(priv->styles, g_new0(SeedCanvasStyle, 1));
+ ((SeedCanvasStyle*) priv->styles->data)->global_opacity = 1;
+ ((SeedCanvasStyle*) priv->styles->data)->stroke.a = 1;
+ ((SeedCanvasStyle*) priv->styles->data)->operator= CAIRO_OPERATOR_OVER;
}
- style = (SeedCanvasStyle *)priv->styles->data;
-
+ style = (SeedCanvasStyle*) priv->styles->data;
- seed_canvas_parse_color (&style->fill, fill_style);
+ seed_canvas_parse_color(&style->fill, fill_style);
- g_free(fill_style);
+ g_free(fill_style);
- return TRUE;
+ return TRUE;
}
gboolean
-seed_canvas_update_global_alpha (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value, SeedException * e)
+seed_canvas_update_global_alpha(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* e)
{
- SeedCanvasStyle *style;
- SeedCanvasPrivates *priv = seed_object_get_private(this_object);
-
- gdouble global_alpha = seed_value_to_double (ctx, value, e);
-
- if (!priv->styles)
- {
- priv->styles = g_slist_prepend(priv->styles, g_new0(SeedCanvasStyle, 1));
- ((SeedCanvasStyle *) priv->styles->data)->global_opacity = 1;
- ((SeedCanvasStyle *) priv->styles->data)->stroke.a = 1;
- ((SeedCanvasStyle *) priv->styles->data)->fill.a = 1;
- ((SeedCanvasStyle *) priv->styles->data)->operator = CAIRO_OPERATOR_OVER;
+ SeedCanvasStyle* style;
+ SeedCanvasPrivates* priv = seed_object_get_private(this_object);
+
+ gdouble global_alpha = seed_value_to_double(ctx, value, e);
+
+ if (!priv->styles) {
+ priv->styles
+ = g_slist_prepend(priv->styles, g_new0(SeedCanvasStyle, 1));
+ ((SeedCanvasStyle*) priv->styles->data)->global_opacity = 1;
+ ((SeedCanvasStyle*) priv->styles->data)->stroke.a = 1;
+ ((SeedCanvasStyle*) priv->styles->data)->fill.a = 1;
+ ((SeedCanvasStyle*) priv->styles->data)->operator= CAIRO_OPERATOR_OVER;
}
- style = (SeedCanvasStyle *)priv->styles->data;
+ style = (SeedCanvasStyle*) priv->styles->data;
- style->global_opacity = global_alpha;
+ style->global_opacity = global_alpha;
- return TRUE;
+ return TRUE;
}
gboolean
-seed_canvas_update_global_composite (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value, SeedException * e)
+seed_canvas_update_global_composite(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* e)
{
- SeedCanvasStyle *style;
- GET_CR;
- gchar *composite_op = seed_value_to_string (ctx, value, e);
-
- if (!priv->styles)
- {
- priv->styles = g_slist_prepend(priv->styles, g_new0(SeedCanvasStyle, 1));
- ((SeedCanvasStyle *) priv->styles->data)->global_opacity = 1;
- ((SeedCanvasStyle *) priv->styles->data)->stroke.a = 1;
- ((SeedCanvasStyle *) priv->styles->data)->fill.a = 1;
- ((SeedCanvasStyle *) priv->styles->data)->operator = CAIRO_OPERATOR_OVER;
+ SeedCanvasStyle* style;
+ GET_CR;
+ gchar* composite_op = seed_value_to_string(ctx, value, e);
+
+ if (!priv->styles) {
+ priv->styles
+ = g_slist_prepend(priv->styles, g_new0(SeedCanvasStyle, 1));
+ ((SeedCanvasStyle*) priv->styles->data)->global_opacity = 1;
+ ((SeedCanvasStyle*) priv->styles->data)->stroke.a = 1;
+ ((SeedCanvasStyle*) priv->styles->data)->fill.a = 1;
+ ((SeedCanvasStyle*) priv->styles->data)->operator= CAIRO_OPERATOR_OVER;
}
- style = (SeedCanvasStyle *)priv->styles->data;
-
- if (!strcmp (composite_op, "copy"))
- style->operator = CAIRO_OPERATOR_SOURCE;
- else if (!strcmp (composite_op, "source-over"))
- style->operator = CAIRO_OPERATOR_OVER;
- else if (!strcmp (composite_op, "source-in"))
- style->operator = CAIRO_OPERATOR_IN;
- else if (!strcmp (composite_op, "source-out"))
- style->operator = CAIRO_OPERATOR_OUT;
- else if (!strcmp (composite_op, "source-atop"))
- style->operator = CAIRO_OPERATOR_ATOP;
- else if (!strcmp (composite_op, "destination-over"))
- style->operator = CAIRO_OPERATOR_DEST_OVER;
- else if (!strcmp (composite_op, "destination-in"))
- style->operator = CAIRO_OPERATOR_DEST_IN;
- else if (!strcmp (composite_op, "destination-out"))
- style->operator = CAIRO_OPERATOR_DEST_OVER;
- else if (!strcmp (composite_op, "destination-atop"))
- style->operator = CAIRO_OPERATOR_DEST_ATOP;
- else if (!strcmp (composite_op, "xor"))
- style->operator = CAIRO_OPERATOR_XOR;
- else if (!strcmp (composite_op, "darker"))
- style->operator = CAIRO_OPERATOR_SATURATE;
- else if (!strcmp (composite_op, "lighter"))
- style->operator = CAIRO_OPERATOR_ADD;
- else
- style->operator = CAIRO_OPERATOR_OVER;
-
- cairo_set_operator (cr, style->operator);
-
- g_free (composite_op);
-
- return TRUE;
+ style = (SeedCanvasStyle*) priv->styles->data;
+
+ if (!strcmp(composite_op, "copy"))
+ style->operator= CAIRO_OPERATOR_SOURCE;
+ else if (!strcmp(composite_op, "source-over"))
+ style->operator= CAIRO_OPERATOR_OVER;
+ else if (!strcmp(composite_op, "source-in"))
+ style->operator= CAIRO_OPERATOR_IN;
+ else if (!strcmp(composite_op, "source-out"))
+ style->operator= CAIRO_OPERATOR_OUT;
+ else if (!strcmp(composite_op, "source-atop"))
+ style->operator= CAIRO_OPERATOR_ATOP;
+ else if (!strcmp(composite_op, "destination-over"))
+ style->operator= CAIRO_OPERATOR_DEST_OVER;
+ else if (!strcmp(composite_op, "destination-in"))
+ style->operator= CAIRO_OPERATOR_DEST_IN;
+ else if (!strcmp(composite_op, "destination-out"))
+ style->operator= CAIRO_OPERATOR_DEST_OVER;
+ else if (!strcmp(composite_op, "destination-atop"))
+ style->operator= CAIRO_OPERATOR_DEST_ATOP;
+ else if (!strcmp(composite_op, "xor"))
+ style->operator= CAIRO_OPERATOR_XOR;
+ else if (!strcmp(composite_op, "darker"))
+ style->operator= CAIRO_OPERATOR_SATURATE;
+ else if (!strcmp(composite_op, "lighter"))
+ style->operator= CAIRO_OPERATOR_ADD;
+ else
+ style->operator= CAIRO_OPERATOR_OVER;
+
+ cairo_set_operator(cr, style->operator);
+
+ g_free(composite_op);
+
+ return TRUE;
}
gboolean
-seed_canvas_set_linewidth (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value, SeedException * e)
+seed_canvas_set_linewidth(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* e)
{
- GET_CR;
- gdouble line_width = seed_value_to_double (ctx, value, e);
+ GET_CR;
+ gdouble line_width = seed_value_to_double(ctx, value, e);
- cairo_set_line_width (cr, line_width);
- return TRUE;
+ cairo_set_line_width(cr, line_width);
+ return TRUE;
}
gboolean
-seed_canvas_set_miterlimit (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value, SeedException * e)
+seed_canvas_set_miterlimit(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* e)
{
- GET_CR;
+ GET_CR;
- cairo_set_miter_limit (cr, seed_value_to_double (ctx, value, e));
- return TRUE;
+ cairo_set_miter_limit(cr, seed_value_to_double(ctx, value, e));
+ return TRUE;
}
gboolean
-seed_canvas_set_linecap (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value, SeedException * e)
+seed_canvas_set_linecap(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* e)
{
- GET_CR;
- cairo_line_cap_t cap = CAIRO_LINE_CAP_BUTT;
- gchar *line_cap = seed_value_to_string (ctx, value, e);
+ GET_CR;
+ cairo_line_cap_t cap = CAIRO_LINE_CAP_BUTT;
+ gchar* line_cap = seed_value_to_string(ctx, value, e);
- if (!strcmp (line_cap, "round"))
- cap = CAIRO_LINE_CAP_ROUND;
- else if (!strcmp (line_cap, "square"))
- cap = CAIRO_LINE_CAP_SQUARE;
+ if (!strcmp(line_cap, "round"))
+ cap = CAIRO_LINE_CAP_ROUND;
+ else if (!strcmp(line_cap, "square"))
+ cap = CAIRO_LINE_CAP_SQUARE;
- g_free (line_cap);
+ g_free(line_cap);
- cairo_set_line_cap (cr, cap);
- return TRUE;
+ cairo_set_line_cap(cr, cap);
+ return TRUE;
}
gboolean
-seed_canvas_set_linejoin (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value, SeedException * e)
+seed_canvas_set_linejoin(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* e)
{
- GET_CR;
- cairo_line_join_t join = CAIRO_LINE_JOIN_MITER;
- gchar *line_join = seed_value_to_string (ctx, value, e);
+ GET_CR;
+ cairo_line_join_t join = CAIRO_LINE_JOIN_MITER;
+ gchar* line_join = seed_value_to_string(ctx, value, e);
- if (!strcmp (line_join, "round"))
- join = CAIRO_LINE_JOIN_ROUND;
- else if (!strcmp (line_join, "bevel"))
- join = CAIRO_LINE_JOIN_BEVEL;
+ if (!strcmp(line_join, "round"))
+ join = CAIRO_LINE_JOIN_ROUND;
+ else if (!strcmp(line_join, "bevel"))
+ join = CAIRO_LINE_JOIN_BEVEL;
- g_free (line_join);
+ g_free(line_join);
- cairo_set_line_join (cr, join);
- return TRUE;
+ cairo_set_line_join(cr, join);
+ return TRUE;
}
void
-seed_canvas_apply_stroke_style (SeedCanvasStyle *style,
- cairo_t * cr)
+seed_canvas_apply_stroke_style(SeedCanvasStyle* style, cairo_t* cr)
{
- cairo_set_source_rgba(cr,
- style->stroke.r,
- style->stroke.g,
- style->stroke.b,
- style->stroke.a * style->global_opacity);
- cairo_set_operator (cr, style->operator);
+ cairo_set_source_rgba(cr, style->stroke.r, style->stroke.g, style->stroke.b,
+ style->stroke.a * style->global_opacity);
+ cairo_set_operator(cr, style->operator);
}
void
-seed_canvas_apply_fill_style (SeedCanvasStyle *style,
- cairo_t * cr)
+seed_canvas_apply_fill_style(SeedCanvasStyle* style, cairo_t* cr)
{
- cairo_set_source_rgba(cr,
- style->fill.r,
- style->fill.g,
- style->fill.b,
- style->fill.a * style->global_opacity);
- cairo_set_operator (cr, style->operator);
+ cairo_set_source_rgba(cr, style->fill.r, style->fill.g, style->fill.b,
+ style->fill.a * style->global_opacity);
+ cairo_set_operator(cr, style->operator);
}
SeedValue
-seed_canvas_save (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_save(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
+ GET_CR;
- SeedCanvasStyle *old_style = (SeedCanvasStyle *)priv->styles->data;
+ SeedCanvasStyle* old_style = (SeedCanvasStyle*) priv->styles->data;
- cairo_save (cr);
+ cairo_save(cr);
- priv->styles = g_slist_prepend(priv->styles, g_new(SeedCanvasStyle, 1));
+ priv->styles = g_slist_prepend(priv->styles, g_new(SeedCanvasStyle, 1));
- memcpy(priv->styles->data, old_style, sizeof(SeedCanvasStyle));
+ memcpy(priv->styles->data, old_style, sizeof(SeedCanvasStyle));
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_restore (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_restore(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
+ GET_CR;
- SeedCanvasStyle *style;
+ SeedCanvasStyle* style;
- style = (SeedCanvasStyle *)priv->styles->data;
- priv->styles = g_slist_delete_link(priv->styles, priv->styles);
- g_free(style);
+ style = (SeedCanvasStyle*) priv->styles->data;
+ priv->styles = g_slist_delete_link(priv->styles, priv->styles);
+ g_free(style);
- cairo_restore (cr);
+ cairo_restore(cr);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_scale (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_scale(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble x = seed_value_to_double (ctx, arguments[0], exception);
- gdouble y = seed_value_to_double (ctx, arguments[1], exception);
+ GET_CR;
+ gdouble x = seed_value_to_double(ctx, arguments[0], exception);
+ gdouble y = seed_value_to_double(ctx, arguments[1], exception);
- cairo_scale (cr, x, y);
+ cairo_scale(cr, x, y);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_translate (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_translate(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble x = seed_value_to_double (ctx, arguments[0], exception);
- gdouble y = seed_value_to_double (ctx, arguments[1], exception);
+ GET_CR;
+ gdouble x = seed_value_to_double(ctx, arguments[0], exception);
+ gdouble y = seed_value_to_double(ctx, arguments[1], exception);
- cairo_translate (cr, x, y);
+ cairo_translate(cr, x, y);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_rotate (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_rotate(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble x = seed_value_to_double (ctx, arguments[0], exception);
+ GET_CR;
+ gdouble x = seed_value_to_double(ctx, arguments[0], exception);
- cairo_rotate (cr, x);
+ cairo_rotate(cr, x);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_transform (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_transform(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- cairo_matrix_t matrix;
- gdouble xx, yx, xy, yy, x0, y0;
+ GET_CR;
+ cairo_matrix_t matrix;
+ gdouble xx, yx, xy, yy, x0, y0;
- xx = seed_value_to_double (ctx, arguments[0], exception);
- yx = seed_value_to_double (ctx, arguments[1], exception);
- xy = seed_value_to_double (ctx, arguments[2], exception);
- yy = seed_value_to_double (ctx, arguments[3], exception);
- x0 = seed_value_to_double (ctx, arguments[4], exception);
- y0 = seed_value_to_double (ctx, arguments[5], exception);
+ xx = seed_value_to_double(ctx, arguments[0], exception);
+ yx = seed_value_to_double(ctx, arguments[1], exception);
+ xy = seed_value_to_double(ctx, arguments[2], exception);
+ yy = seed_value_to_double(ctx, arguments[3], exception);
+ x0 = seed_value_to_double(ctx, arguments[4], exception);
+ y0 = seed_value_to_double(ctx, arguments[5], exception);
- cairo_matrix_init (&matrix, xx, yx, xy, yy, x0, y0);
- cairo_transform (cr, &matrix);
+ cairo_matrix_init(&matrix, xx, yx, xy, yy, x0, y0);
+ cairo_transform(cr, &matrix);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_set_transform (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_canvas_set_transform(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- cairo_matrix_t matrix;
- gdouble xx, yx, xy, yy, x0, y0;
+ GET_CR;
+ cairo_matrix_t matrix;
+ gdouble xx, yx, xy, yy, x0, y0;
- cairo_identity_matrix (cr);
+ cairo_identity_matrix(cr);
- xx = seed_value_to_double (ctx, arguments[0], exception);
- yx = seed_value_to_double (ctx, arguments[1], exception);
- xy = seed_value_to_double (ctx, arguments[2], exception);
- yy = seed_value_to_double (ctx, arguments[3], exception);
- x0 = seed_value_to_double (ctx, arguments[4], exception);
- y0 = seed_value_to_double (ctx, arguments[5], exception);
+ xx = seed_value_to_double(ctx, arguments[0], exception);
+ yx = seed_value_to_double(ctx, arguments[1], exception);
+ xy = seed_value_to_double(ctx, arguments[2], exception);
+ yy = seed_value_to_double(ctx, arguments[3], exception);
+ x0 = seed_value_to_double(ctx, arguments[4], exception);
+ y0 = seed_value_to_double(ctx, arguments[5], exception);
- cairo_matrix_init (&matrix, xx, yx, xy, yy, x0, y0);
- cairo_transform (cr, &matrix);
+ cairo_matrix_init(&matrix, xx, yx, xy, yy, x0, y0);
+ cairo_transform(cr, &matrix);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_clear_rect (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_canvas_clear_rect(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble x, y, width, height;
+ GET_CR;
+ gdouble x, y, width, height;
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
- width = seed_value_to_double (ctx, arguments[2], exception);
- height = seed_value_to_double (ctx, arguments[3], exception);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
+ width = seed_value_to_double(ctx, arguments[2], exception);
+ height = seed_value_to_double(ctx, arguments[3], exception);
- cairo_save (cr);
+ cairo_save(cr);
- cairo_set_source_rgb (cr, 1, 1, 1);
- cairo_rectangle (cr, x, y, width, height);
+ cairo_set_source_rgb(cr, 1, 1, 1);
+ cairo_rectangle(cr, x, y, width, height);
- cairo_fill (cr);
+ cairo_fill(cr);
- cairo_restore (cr);
+ cairo_restore(cr);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_stroke_rect (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_canvas_stroke_rect(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble x, y, width, height;
+ GET_CR;
+ gdouble x, y, width, height;
- seed_canvas_apply_stroke_style ((SeedCanvasStyle *)priv->styles->data, cr);
+ seed_canvas_apply_stroke_style((SeedCanvasStyle*) priv->styles->data, cr);
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
- width = seed_value_to_double (ctx, arguments[2], exception);
- height = seed_value_to_double (ctx, arguments[3], exception);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
+ width = seed_value_to_double(ctx, arguments[2], exception);
+ height = seed_value_to_double(ctx, arguments[3], exception);
- cairo_rectangle (cr, x, y, width, height);
- cairo_stroke (cr);
+ cairo_rectangle(cr, x, y, width, height);
+ cairo_stroke(cr);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_fill_rect (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_fill_rect(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble x, y, width, height;
- seed_canvas_apply_fill_style ((SeedCanvasStyle *)priv->styles->data, cr);
+ GET_CR;
+ gdouble x, y, width, height;
+ seed_canvas_apply_fill_style((SeedCanvasStyle*) priv->styles->data, cr);
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
- width = seed_value_to_double (ctx, arguments[2], exception);
- height = seed_value_to_double (ctx, arguments[3], exception);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
+ width = seed_value_to_double(ctx, arguments[2], exception);
+ height = seed_value_to_double(ctx, arguments[3], exception);
- cairo_rectangle (cr, x, y, width, height);
- cairo_fill (cr);
+ cairo_rectangle(cr, x, y, width, height);
+ cairo_fill(cr);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_end_path (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_end_path(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
+ GET_CR;
- cairo_close_path (cr);
+ cairo_close_path(cr);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_begin_path (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_canvas_begin_path(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
+ GET_CR;
- cairo_new_path (cr);
+ cairo_new_path(cr);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_move_to (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_move_to(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble x, y;
+ GET_CR;
+ gdouble x, y;
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
- cairo_move_to (cr, x, y);
+ cairo_move_to(cr, x, y);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_line_to (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_line_to(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble x, y;
+ GET_CR;
+ gdouble x, y;
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
- cairo_line_to (cr, x, y);
+ cairo_line_to(cr, x, y);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_stroke (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_stroke(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
+ GET_CR;
- seed_canvas_apply_stroke_style ((SeedCanvasStyle *)priv->styles->data,
- cr);
+ seed_canvas_apply_stroke_style((SeedCanvasStyle*) priv->styles->data, cr);
- cairo_stroke (cr);
+ cairo_stroke(cr);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_clip (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_clip(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
+ GET_CR;
- cairo_clip (cr);
+ cairo_clip(cr);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_fill (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_fill(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- seed_canvas_apply_fill_style ((SeedCanvasStyle *)priv->styles->data, cr);
+ GET_CR;
+ seed_canvas_apply_fill_style((SeedCanvasStyle*) priv->styles->data, cr);
- cairo_fill (cr);
+ cairo_fill(cr);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_arc (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_arc(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble xc, yc, radius, start, end;
- gboolean counter_clockwise;
-
- xc = seed_value_to_double (ctx, arguments[0], exception);
- yc = seed_value_to_double (ctx, arguments[1], exception);
- radius = seed_value_to_double (ctx, arguments[2], exception);
- start = seed_value_to_double (ctx, arguments[3], exception);
- end = seed_value_to_double (ctx, arguments[4], exception);
- counter_clockwise = seed_value_to_boolean (ctx, arguments[5], exception);
-
- if (counter_clockwise)
- cairo_arc_negative (cr, xc, yc, radius, end, start);
- else
- cairo_arc (cr, xc, yc, radius, start, end);
-
- return seed_make_null (ctx);
+ GET_CR;
+ gdouble xc, yc, radius, start, end;
+ gboolean counter_clockwise;
+
+ xc = seed_value_to_double(ctx, arguments[0], exception);
+ yc = seed_value_to_double(ctx, arguments[1], exception);
+ radius = seed_value_to_double(ctx, arguments[2], exception);
+ start = seed_value_to_double(ctx, arguments[3], exception);
+ end = seed_value_to_double(ctx, arguments[4], exception);
+ counter_clockwise = seed_value_to_boolean(ctx, arguments[5], exception);
+
+ if (counter_clockwise)
+ cairo_arc_negative(cr, xc, yc, radius, end, start);
+ else
+ cairo_arc(cr, xc, yc, radius, start, end);
+
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_quadratic (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_quadratic(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
-
- gdouble p0x, p0y, cp1x, cp1y, cp2x, cp2y, cp3x, cp3y;
- gdouble qp1x, qp1y, qp2x, qp2y;
+ GET_CR;
- cairo_get_current_point (cr, &p0x, &p0y);
+ gdouble p0x, p0y, cp1x, cp1y, cp2x, cp2y, cp3x, cp3y;
+ gdouble qp1x, qp1y, qp2x, qp2y;
- qp1x = seed_value_to_double (ctx, arguments[0], exception);
- qp1y = seed_value_to_double (ctx, arguments[1], exception);
- qp2x = seed_value_to_double (ctx, arguments[2], exception);
- qp2y = seed_value_to_double (ctx, arguments[3], exception);
+ cairo_get_current_point(cr, &p0x, &p0y);
+ qp1x = seed_value_to_double(ctx, arguments[0], exception);
+ qp1y = seed_value_to_double(ctx, arguments[1], exception);
+ qp2x = seed_value_to_double(ctx, arguments[2], exception);
+ qp2y = seed_value_to_double(ctx, arguments[3], exception);
- // Convert quadratic curve to cubic curve...
- // I think the math is explained in some
- // freetype documentation somewhere.
- cp3x = qp2x;
- cp3y = qp2y;
+ // Convert quadratic curve to cubic curve...
+ // I think the math is explained in some
+ // freetype documentation somewhere.
+ cp3x = qp2x;
+ cp3y = qp2y;
- cp1x = p0x + 2 / 3.0 * (qp1x - p0x);
- cp1y = p0y + 2 / 3.0 * (qp1y - p0y);
+ cp1x = p0x + 2 / 3.0 * (qp1x - p0x);
+ cp1y = p0y + 2 / 3.0 * (qp1y - p0y);
- cp2x = cp1x + 1 / 3.0 * (qp2x - p0x);
- cp2y = cp1y + 1 / 3.0 * (qp2y - p0y);
+ cp2x = cp1x + 1 / 3.0 * (qp2x - p0x);
+ cp2y = cp1y + 1 / 3.0 * (qp2y - p0y);
- cairo_curve_to (cr, cp1x, cp1y, cp2x, cp2y, cp3x, cp3y);
+ cairo_curve_to(cr, cp1x, cp1y, cp2x, cp2y, cp3x, cp3y);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_bezier (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_bezier(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble cp0x, cp0y, cp1x, cp1y, cp2x, cp2y;
+ GET_CR;
+ gdouble cp0x, cp0y, cp1x, cp1y, cp2x, cp2y;
- cp0x = seed_value_to_double (ctx, arguments[0], exception);
- cp0y = seed_value_to_double (ctx, arguments[1], exception);
- cp1x = seed_value_to_double (ctx, arguments[2], exception);
- cp1y = seed_value_to_double (ctx, arguments[3], exception);
- cp2x = seed_value_to_double (ctx, arguments[4], exception);
- cp2y = seed_value_to_double (ctx, arguments[5], exception);
+ cp0x = seed_value_to_double(ctx, arguments[0], exception);
+ cp0y = seed_value_to_double(ctx, arguments[1], exception);
+ cp1x = seed_value_to_double(ctx, arguments[2], exception);
+ cp1y = seed_value_to_double(ctx, arguments[3], exception);
+ cp2x = seed_value_to_double(ctx, arguments[4], exception);
+ cp2y = seed_value_to_double(ctx, arguments[5], exception);
- cairo_curve_to (cr, cp0x, cp0y, cp1x, cp1y, cp2x, cp2y);
+ cairo_curve_to(cr, cp0x, cp0y, cp1x, cp1y, cp2x, cp2y);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_rect (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_rect(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- gdouble x, y, width, height;
+ GET_CR;
+ gdouble x, y, width, height;
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
- width = seed_value_to_double (ctx, arguments[2], exception);
- height = seed_value_to_double (ctx, arguments[3], exception);
+ x = seed_value_to_double(ctx, arguments[0], exception);
+ y = seed_value_to_double(ctx, arguments[1], exception);
+ width = seed_value_to_double(ctx, arguments[2], exception);
+ height = seed_value_to_double(ctx, arguments[3], exception);
- cairo_rectangle (cr, x, y, width, height);
+ cairo_rectangle(cr, x, y, width, height);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_flush (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_flush(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- cairo_surface_t *surface = cairo_get_target (cr);
+ GET_CR;
+ cairo_surface_t* surface = cairo_get_target(cr);
- cairo_surface_flush (surface);
+ cairo_surface_flush(surface);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_finish (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_finish(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- cairo_surface_t *surface = cairo_get_target (cr);
+ GET_CR;
+ cairo_surface_t* surface = cairo_get_target(cr);
- cairo_surface_finish (surface);
+ cairo_surface_finish(surface);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_showpage (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
- {
- GET_CR;
- cairo_show_page (cr);
-
- return seed_make_null (ctx);
+seed_canvas_showpage(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
+{
+ GET_CR;
+ cairo_show_page(cr);
+
+ return seed_make_null(ctx);
}
SeedValue
-seed_canvas_destroy (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+seed_canvas_destroy(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CR;
- cairo_destroy (cr);
+ GET_CR;
+ cairo_destroy(cr);
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
}
static void
-canvas_finalize (SeedObject object)
+canvas_finalize(SeedObject object)
{
- cairo_t *cr = seed_object_get_private (object);
- if (cr)
- cairo_destroy (cr);
+ cairo_t* cr = seed_object_get_private(object);
+ if (cr)
+ cairo_destroy(cr);
}
-seed_static_function canvas_funcs[] = {
- {"save", seed_canvas_save, 0},
- {"restore", seed_canvas_restore, 0},
- {"scale", seed_canvas_scale, 0},
- {"rotate", seed_canvas_rotate, 0},
- {"translate", seed_canvas_translate, 0},
- {"transform", seed_canvas_transform, 0},
- {"setTransform", seed_canvas_set_transform, 0},
- {"clearRect", seed_canvas_clear_rect, 0},
- {"fillRect", seed_canvas_fill_rect, 0},
- {"strokeRect", seed_canvas_stroke_rect, 0},
- {"beginPath", seed_canvas_begin_path, 0},
- {"closePath", seed_canvas_end_path, 0},
- {"moveTo", seed_canvas_move_to, 0},
- {"lineTo", seed_canvas_line_to, 0},
- {"fill", seed_canvas_fill, 0},
- {"stroke", seed_canvas_stroke, 0},
- {"clip", seed_canvas_clip, 0},
- {"arc", seed_canvas_arc, 0},
- {"quadraticCurveTo", seed_canvas_quadratic, 0},
- {"bezierCurveTo", seed_canvas_bezier, 0},
- {"rect", seed_canvas_rect, 0},
- {"flush", seed_canvas_flush, 0},
- {"finish", seed_canvas_finish, 0},
- {"showPage", seed_canvas_showpage, 0},
- {"destroy", seed_canvas_destroy, 0},
- {NULL, NULL, 0}
-};
-
-seed_static_value canvas_properties[] = {
- {"lineWidth", 0, seed_canvas_set_linewidth, 0},
- {"lineCap", 0, seed_canvas_set_linecap, 0},
- {"lineJoin", 0, seed_canvas_set_linejoin, 0},
- {"miterLimit", 0, seed_canvas_set_miterlimit, 0},
- {"strokeStyle", 0, seed_canvas_update_stroke_style, 0},
- {"fillStyle", 0, seed_canvas_update_fill_style, 0},
- {"globalAlpha", 0, seed_canvas_update_global_alpha, 0},
- {"globalCompositeOperation", 0, seed_canvas_update_global_composite, 0},
- {NULL, NULL, NULL, 0}
-};
+seed_static_function canvas_funcs[]
+ = { { "save", seed_canvas_save, 0 },
+ { "restore", seed_canvas_restore, 0 },
+ { "scale", seed_canvas_scale, 0 },
+ { "rotate", seed_canvas_rotate, 0 },
+ { "translate", seed_canvas_translate, 0 },
+ { "transform", seed_canvas_transform, 0 },
+ { "setTransform", seed_canvas_set_transform, 0 },
+ { "clearRect", seed_canvas_clear_rect, 0 },
+ { "fillRect", seed_canvas_fill_rect, 0 },
+ { "strokeRect", seed_canvas_stroke_rect, 0 },
+ { "beginPath", seed_canvas_begin_path, 0 },
+ { "closePath", seed_canvas_end_path, 0 },
+ { "moveTo", seed_canvas_move_to, 0 },
+ { "lineTo", seed_canvas_line_to, 0 },
+ { "fill", seed_canvas_fill, 0 },
+ { "stroke", seed_canvas_stroke, 0 },
+ { "clip", seed_canvas_clip, 0 },
+ { "arc", seed_canvas_arc, 0 },
+ { "quadraticCurveTo", seed_canvas_quadratic, 0 },
+ { "bezierCurveTo", seed_canvas_bezier, 0 },
+ { "rect", seed_canvas_rect, 0 },
+ { "flush", seed_canvas_flush, 0 },
+ { "finish", seed_canvas_finish, 0 },
+ { "showPage", seed_canvas_showpage, 0 },
+ { "destroy", seed_canvas_destroy, 0 },
+ { NULL, NULL, 0 } };
+
+seed_static_value canvas_properties[]
+ = { { "lineWidth", 0, seed_canvas_set_linewidth, 0 },
+ { "lineCap", 0, seed_canvas_set_linecap, 0 },
+ { "lineJoin", 0, seed_canvas_set_linejoin, 0 },
+ { "miterLimit", 0, seed_canvas_set_miterlimit, 0 },
+ { "strokeStyle", 0, seed_canvas_update_stroke_style, 0 },
+ { "fillStyle", 0, seed_canvas_update_fill_style, 0 },
+ { "globalAlpha", 0, seed_canvas_update_global_alpha, 0 },
+ { "globalCompositeOperation", 0, seed_canvas_update_global_composite, 0 },
+ { NULL, NULL, NULL, 0 } };
SeedObject
-seed_module_init (SeedEngine * local_eng)
+seed_module_init(SeedEngine* local_eng)
{
- SeedObject canvas_constructor, pdf_constructor,
- svg_constructor, image_constructor;
- seed_class_definition canvas_class_def = seed_empty_class;
+ SeedObject canvas_constructor, pdf_constructor, svg_constructor,
+ image_constructor;
+ seed_class_definition canvas_class_def = seed_empty_class;
- eng = local_eng;
+ eng = local_eng;
- namespace_ref = seed_make_object (eng->context, 0, 0);
+ namespace_ref = seed_make_object(eng->context, 0, 0);
- canvas_class_def.class_name = "CairoCanvas";
- canvas_class_def.static_functions = canvas_funcs;
- canvas_class_def.finalize = canvas_finalize;
- canvas_class_def.static_values = canvas_properties;
+ canvas_class_def.class_name = "CairoCanvas";
+ canvas_class_def.static_functions = canvas_funcs;
+ canvas_class_def.finalize = canvas_finalize;
+ canvas_class_def.static_values = canvas_properties;
- canvas_class = seed_create_class (&canvas_class_def);
+ canvas_class = seed_create_class(&canvas_class_def);
- canvas_constructor = seed_make_constructor (eng->context,
- canvas_class,
- canvas_construct_canvas);
+ canvas_constructor = seed_make_constructor(eng->context, canvas_class,
+ canvas_construct_canvas);
- pdf_constructor = seed_make_constructor (eng->context,
- canvas_class,
- canvas_construct_pdf_canvas);
+ pdf_constructor = seed_make_constructor(eng->context, canvas_class,
+ canvas_construct_pdf_canvas);
- svg_constructor = seed_make_constructor (eng->context,
- canvas_class,
- canvas_construct_svg_canvas);
+ svg_constructor = seed_make_constructor(eng->context, canvas_class,
+ canvas_construct_svg_canvas);
- image_constructor = seed_make_constructor (eng->context,
- canvas_class,
- seed_construct_image_canvas);
+ image_constructor = seed_make_constructor(eng->context, canvas_class,
+ seed_construct_image_canvas);
- seed_object_set_property (eng->context, namespace_ref, "CairoCanvas",
- canvas_constructor);
- seed_object_set_property (eng->context, namespace_ref, "PDFCanvas",
- pdf_constructor);
- seed_object_set_property (eng->context, namespace_ref, "SVGCanvas",
- svg_constructor);
- seed_object_set_property (eng->context, namespace_ref, "ImageCanvas",
- svg_constructor);
+ seed_object_set_property(eng->context, namespace_ref, "CairoCanvas",
+ canvas_constructor);
+ seed_object_set_property(eng->context, namespace_ref, "PDFCanvas",
+ pdf_constructor);
+ seed_object_set_property(eng->context, namespace_ref, "SVGCanvas",
+ svg_constructor);
+ seed_object_set_property(eng->context, namespace_ref, "ImageCanvas",
+ svg_constructor);
- return namespace_ref;
+ return namespace_ref;
}
diff --git a/modules/dbus/dbus-exports.c b/modules/dbus/dbus-exports.c
index e3f91f6..92085c7 100644
--- a/modules/dbus/dbus-exports.c
+++ b/modules/dbus/dbus-exports.c
@@ -25,42 +25,34 @@
#include <util/dbus.h>
-typedef struct _Exports {
- // Why does GJS have this?
- SeedObject object;
+typedef struct _Exports
+{
+ // Why does GJS have this?
+ SeedObject object;
- DBusBusType which_bus;
- DBusConnection *connection_weak_ref;
- gboolean filter_was_registered;
+ DBusBusType which_bus;
+ DBusConnection* connection_weak_ref;
+ gboolean filter_was_registered;
} Exports;
SeedClass seed_js_exports_class = NULL;
-static void on_bus_opened (DBusConnection *connection,
- void *data);
-static void on_bus_closed (DBusConnection *connection,
- void *data);
-static DBusHandlerResult on_message (DBusConnection *connection,
- DBusMessage *message,
- void *user_data);
-
-static const BigDBusConnectFuncs system_connect_funcs = {
- DBUS_BUS_SYSTEM,
- on_bus_opened,
- on_bus_closed
-};
-
-static const BigDBusConnectFuncs session_connect_funcs = {
- DBUS_BUS_SESSION,
- on_bus_opened,
- on_bus_closed
-};
+static void on_bus_opened(DBusConnection* connection, void* data);
+static void on_bus_closed(DBusConnection* connection, void* data);
+static DBusHandlerResult on_message(DBusConnection* connection,
+ DBusMessage* message,
+ void* user_data);
+
+static const BigDBusConnectFuncs system_connect_funcs
+ = { DBUS_BUS_SYSTEM, on_bus_opened, on_bus_closed };
+
+static const BigDBusConnectFuncs session_connect_funcs
+ = { DBUS_BUS_SESSION, on_bus_opened, on_bus_closed };
static void
-on_bus_opened(DBusConnection *connection,
- void *data)
+on_bus_opened(DBusConnection* connection, void* data)
{
- Exports *priv = data;
+ Exports* priv = data;
g_assert(priv->connection_weak_ref == NULL);
@@ -69,67 +61,58 @@ on_bus_opened(DBusConnection *connection,
if (priv->filter_was_registered)
return;
- if (!dbus_connection_add_filter(connection,
- on_message, priv,
- NULL))
- {
- g_warning("DBus: Failed to add message filter");
- return;
- }
+ if (!dbus_connection_add_filter(connection, on_message, priv, NULL)) {
+ g_warning("DBus: Failed to add message filter");
+ return;
+ }
priv->filter_was_registered = TRUE;
}
static void
-on_bus_closed(DBusConnection *connection,
- void *data)
+on_bus_closed(DBusConnection* connection, void* data)
{
- Exports *priv = data;
+ Exports* priv = data;
g_assert(priv->connection_weak_ref != NULL);
priv->connection_weak_ref = NULL;
- if (priv->filter_was_registered)
- {
- dbus_connection_remove_filter(connection,
- on_message, priv);
+ if (priv->filter_was_registered) {
+ dbus_connection_remove_filter(connection, on_message, priv);
priv->filter_was_registered = FALSE;
- }
+ }
}
-#define dbus_reply_from_exception(ctx, message, reply_p, exception) \
- (dbus_reply_from_exception_and_sender((ctx), \
- dbus_message_get_sender(message), \
- dbus_message_get_serial(message), \
- (reply_p), exception))
+#define dbus_reply_from_exception(ctx, message, reply_p, exception) \
+ (dbus_reply_from_exception_and_sender((ctx), \
+ dbus_message_get_sender(message), \
+ dbus_message_get_serial(message), \
+ (reply_p), exception))
static gboolean
-dbus_reply_from_exception_and_sender(SeedContext ctx,
- const gchar *sender,
+dbus_reply_from_exception_and_sender(SeedContext ctx,
+ const gchar* sender,
dbus_uint32_t serial,
- DBusMessage **reply_p,
- SeedException *exception)
+ DBusMessage** reply_p,
+ SeedException* exception)
{
- SeedValue name_val;
- gchar *s;
- const gchar *name = NULL;
+ SeedValue name_val;
+ gchar* s;
+ const gchar* name = NULL;
+ *reply_p = NULL;
- *reply_p = NULL;
-
- if (seed_value_is_undefined (ctx, *exception) ||
- seed_value_is_null (ctx, *exception) ||
- !seed_value_is_object (ctx, *exception))
- return FALSE;
+ if (seed_value_is_undefined(ctx, *exception)
+ || seed_value_is_null(ctx, *exception)
+ || !seed_value_is_object(ctx, *exception))
+ return FALSE;
- name_val = seed_object_get_property(ctx, *exception, "dbusErrorName");
- name = seed_value_to_string (ctx, name_val, NULL);
+ name_val = seed_object_get_property(ctx, *exception, "dbusErrorName");
+ name = seed_value_to_string(ctx, name_val, NULL);
- s = seed_exception_to_string (ctx, *exception);
- g_warning("JS exception we will send as dbus reply to %s: %s",
- sender,
- s);
+ s = seed_exception_to_string(ctx, *exception);
+ g_warning("JS exception we will send as dbus reply to %s: %s", sender, s);
*reply_p = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR);
dbus_message_set_destination(*reply_p, sender);
@@ -137,13 +120,11 @@ dbus_reply_from_exception_and_sender(SeedContext ctx,
dbus_message_set_no_reply(*reply_p, TRUE);
dbus_message_set_error_name(*reply_p, name ? name : DBUS_ERROR_FAILED);
if (s != NULL) {
- DBusMessageIter iter;
+ DBusMessageIter iter;
dbus_message_iter_init_append(*reply_p, &iter);
- if (!dbus_message_iter_append_basic(&iter,
- DBUS_TYPE_STRING,
- &s)) {
+ if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &s)) {
dbus_message_unref(*reply_p);
g_free(s);
return FALSE;
@@ -157,32 +138,28 @@ dbus_reply_from_exception_and_sender(SeedContext ctx,
// Is this going to leak later?
static gboolean
signature_from_method(SeedContext ctx,
- SeedObject method_obj,
- const char **signature,
- SeedException *exception)
+ SeedObject method_obj,
+ const char** signature,
+ SeedException* exception)
{
- SeedValue signature_value;
-
- if ((signature_value = seed_object_get_property(ctx,
- method_obj, "outSignature")))
- {
- *signature = seed_value_to_string (ctx, signature_value, exception);
- if (*signature == NULL)
- {
- return FALSE;
+ SeedValue signature_value;
+
+ if ((signature_value
+ = seed_object_get_property(ctx, method_obj, "outSignature"))) {
+ *signature = seed_value_to_string(ctx, signature_value, exception);
+ if (*signature == NULL) {
+ return FALSE;
}
- }
- else
- {
- /* We default to a{sv} */
- *signature = "a{sv}";
+ } else {
+ /* We default to a{sv} */
+ *signature = "a{sv}";
}
- return TRUE;
+ return TRUE;
}
static gboolean
-signature_has_one_element(const char *signature)
+signature_has_one_element(const char* signature)
{
DBusSignatureIter iter;
@@ -194,15 +171,15 @@ signature_has_one_element(const char *signature)
return !dbus_signature_iter_next(&iter);
}
-static DBusMessage *
+static DBusMessage*
build_reply_from_jsval(SeedContext ctx,
- const char *signature,
- const char *sender,
- dbus_uint32_t serial,
- SeedValue rval,
- SeedException *exception)
+ const char* signature,
+ const char* sender,
+ dbus_uint32_t serial,
+ SeedValue rval,
+ SeedException* exception)
{
- DBusMessage *reply;
+ DBusMessage* reply;
DBusMessageIter arg_iter;
DBusSignatureIter sig_iter;
gboolean marshalled = FALSE;
@@ -214,35 +191,35 @@ build_reply_from_jsval(SeedContext ctx,
dbus_message_iter_init_append(reply, &arg_iter);
- if (seed_value_is_undefined (ctx, rval) || g_str_equal(signature, ""))
- {
+ if (seed_value_is_undefined(ctx, rval) || g_str_equal(signature, "")) {
/* We don't want to send anything in these cases so skip the
* marshalling altogether.
*/
return reply;
- }
+ }
dbus_signature_iter_init(&sig_iter, signature);
- if (signature_has_one_element(signature))
- {
- marshalled = seed_js_one_value_to_dbus(ctx, rval, &arg_iter, &sig_iter, exception);
- }
- else
- {
- if (!seed_value_is_object (ctx, rval))
- {
- g_warning("Signature has multiple items but return value is not an array");
- return reply;
- }
- marshalled = seed_js_values_to_dbus(ctx, 0, rval, &arg_iter, &sig_iter, exception);
- }
+ if (signature_has_one_element(signature)) {
+ marshalled = seed_js_one_value_to_dbus(ctx, rval, &arg_iter, &sig_iter,
+ exception);
+ } else {
+ if (!seed_value_is_object(ctx, rval)) {
+ g_warning(
+ "Signature has multiple items but return value is not an array");
+ return reply;
+ }
+ marshalled = seed_js_values_to_dbus(ctx, 0, rval, &arg_iter, &sig_iter,
+ exception);
+ }
if (!marshalled) {
/* replace our planned reply with an error */
dbus_message_unref(reply);
- if (!dbus_reply_from_exception_and_sender(ctx, sender, serial, &reply, exception))
- g_warning ("conversion of dbus return value failed but no exception was set?");
+ if (!dbus_reply_from_exception_and_sender(ctx, sender, serial, &reply,
+ exception))
+ g_warning("conversion of dbus return value failed but no exception "
+ "was set?");
}
return reply;
@@ -250,169 +227,155 @@ build_reply_from_jsval(SeedContext ctx,
static DBusMessage*
invoke_js_from_dbus(SeedContext ctx,
- DBusMessage *method_call,
+ DBusMessage* method_call,
SeedObject this_obj,
SeedObject method_obj,
- SeedException *exception)
+ SeedException* exception)
{
- DBusMessage *reply;
+ DBusMessage* reply;
int argc;
- SeedValue *argv;
+ SeedValue* argv;
SeedValue rval;
DBusMessageIter arg_iter;
- GArray *values;
- const char *signature;
+ GArray* values;
+ const char* signature;
reply = NULL;
dbus_message_iter_init(method_call, &arg_iter);
- if (!seed_js_values_from_dbus(ctx, &arg_iter, &values, exception))
- {
- if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
- g_warning("conversion of dbus method arg failed but no exception was set?");
+ if (!seed_js_values_from_dbus(ctx, &arg_iter, &values, exception)) {
+ if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
+ g_warning(
+ "conversion of dbus method arg failed but no exception was set?");
return reply;
- }
+ }
argc = values->len;
- argv = (SeedValue *)values->data;
+ argv = (SeedValue*) values->data;
seed_js_add_dbus_props(ctx, method_call, argv[0], exception);
- rval = seed_object_call (ctx, method_obj, NULL,
- argc, argv, exception);
- if (!seed_value_is_null (ctx, *exception) &&
- seed_value_is_object (ctx, *exception))
- {
- g_warning("dbus method invocation failed");
+ rval = seed_object_call(ctx, method_obj, NULL, argc, argv, exception);
+ if (!seed_value_is_null(ctx, *exception)
+ && seed_value_is_object(ctx, *exception)) {
+ g_warning("dbus method invocation failed");
if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
- g_warning("dbus method invocation failed but no exception was set?");
+ g_warning(
+ "dbus method invocation failed but no exception was set?");
goto out;
- }
-
- if (dbus_reply_from_exception(ctx, method_call, &reply, exception))
- {
- g_warning("Closure invocation succeeded but an exception was set?");
- goto out;
- }
-
- if (!signature_from_method(ctx,
- method_obj,
- &signature, exception))
- {
+ }
+
+ if (dbus_reply_from_exception(ctx, method_call, &reply, exception)) {
+ g_warning("Closure invocation succeeded but an exception was set?");
+ goto out;
+ }
+
+ if (!signature_from_method(ctx, method_obj, &signature, exception)) {
if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
- g_warning("dbus method invocation failed but no exception was set?");
+ g_warning(
+ "dbus method invocation failed but no exception was set?");
goto out;
- }
+ }
- reply = build_reply_from_jsval(ctx,
- signature,
+ reply = build_reply_from_jsval(ctx, signature,
dbus_message_get_sender(method_call),
- dbus_message_get_serial(method_call),
- rval,
- exception);
+ dbus_message_get_serial(method_call), rval,
+ exception);
- out:
+out:
g_array_free(values, TRUE);
if (reply)
- g_warning ("Sending %s reply to dbus method %s",
- dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN ?
- "normal" : "error",
- dbus_message_get_member(method_call));
+ g_warning("Sending %s reply to dbus method %s",
+ dbus_message_get_type(reply)
+ == DBUS_MESSAGE_TYPE_METHOD_RETURN
+ ? "normal"
+ : "error",
+ dbus_message_get_member(method_call));
else
- g_warning ("Failed to create reply to dbus method %s",
- dbus_message_get_member(method_call));
+ g_warning("Failed to create reply to dbus method %s",
+ dbus_message_get_member(method_call));
return reply;
}
static SeedValue
async_call_callback(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- DBusConnection *connection;
+ DBusConnection* connection;
DBusBusType which_bus;
- DBusMessage *reply;
- const char *sender;
+ DBusMessage* reply;
+ const char* sender;
dbus_uint32_t serial;
SeedValue prop_value, retval;
- const char *signature;
+ const char* signature;
gboolean thrown;
- retval = seed_make_undefined (ctx);
+ retval = seed_make_undefined(ctx);
reply = NULL;
thrown = FALSE;
- prop_value = seed_object_get_property (ctx, function, "_dbusSender");
- sender = seed_value_to_string (ctx, prop_value, exception);
+ prop_value = seed_object_get_property(ctx, function, "_dbusSender");
+ sender = seed_value_to_string(ctx, prop_value, exception);
if (!sender)
- return FALSE;
-
- prop_value = seed_object_get_property(ctx,
- function,
- "_dbusSerial");
+ return FALSE;
+ prop_value = seed_object_get_property(ctx, function, "_dbusSerial");
- serial = seed_value_to_uint (ctx, prop_value, exception);
- prop_value = seed_object_get_property(ctx,
- function,
- "_dbusBusType");
+ serial = seed_value_to_uint(ctx, prop_value, exception);
+ prop_value = seed_object_get_property(ctx, function, "_dbusBusType");
which_bus = seed_value_to_int(ctx, prop_value, exception);
/* From now we have enough information to
* send the exception back to the callee so we'll do so
*/
- prop_value = seed_object_get_property(ctx,
- function,
- "_dbusOutSignature");
+ prop_value = seed_object_get_property(ctx, function, "_dbusOutSignature");
- signature = seed_value_to_string (ctx, prop_value, exception);
+ signature = seed_value_to_string(ctx, prop_value, exception);
if (!signature)
return FALSE;
if (argument_count != 1) {
- seed_make_exception(ctx, exception, "ArgumentError",
- "The callback to async DBus calls takes one argument, "
- "the return value or array of return values");
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "The callback to async DBus calls takes one argument, "
+ "the return value or array of return values");
thrown = TRUE;
goto out;
}
- reply = build_reply_from_jsval(ctx,
- signature,
- sender,
- serial,
- arguments[0],
- exception);
+ reply = build_reply_from_jsval(ctx, signature, sender, serial, arguments[0],
+ exception);
out:
- if (!reply && thrown)
- {
- if (!dbus_reply_from_exception_and_sender(ctx, sender, serial, &reply, exception))
- g_warning("dbus method invocation failed but no exception was set?");
- }
+ if (!reply && thrown) {
+ if (!dbus_reply_from_exception_and_sender(ctx, sender, serial, &reply,
+ exception))
+ g_warning(
+ "dbus method invocation failed but no exception was set?");
+ }
- if (reply)
- {
+ if (reply) {
big_dbus_add_bus_weakref(which_bus, &connection);
- if (!connection)
- {
- seed_make_exception(ctx, exception, "DBusError",
- "We were disconnected from the bus before the callback "
- "to some async remote call was called");
+ if (!connection) {
+ seed_make_exception(
+ ctx, exception, "DBusError",
+ "We were disconnected from the bus before the callback "
+ "to some async remote call was called");
dbus_message_unref(reply);
big_dbus_remove_bus_weakref(which_bus, &connection);
return FALSE;
- }
+ }
dbus_connection_send(connection, reply, NULL);
big_dbus_remove_bus_weakref(which_bus, &connection);
dbus_message_unref(reply);
@@ -422,39 +385,39 @@ out:
}
/* returns an error message or NULL */
-static DBusMessage *
+static DBusMessage*
invoke_js_async_from_dbus(SeedContext ctx,
- DBusBusType bus_type,
- DBusMessage *method_call,
- SeedObject this_obj,
- SeedObject method_obj,
- SeedException *exception)
+ DBusBusType bus_type,
+ DBusMessage* method_call,
+ SeedObject this_obj,
+ SeedObject method_obj,
+ SeedException* exception)
{
- DBusMessage *reply;
+ DBusMessage* reply;
int argc;
- SeedValue *argv;
+ SeedValue* argv;
DBusMessageIter arg_iter;
- GArray *values;
+ GArray* values;
SeedObject callback_object;
SeedValue sender_string, signature_string;
gboolean thrown;
SeedValue ignored;
- const char *signature;
+ const char* signature;
reply = NULL;
thrown = FALSE;
argv = NULL;
- if (!seed_js_values_from_dbus(ctx, &arg_iter, &values, exception))
- {
- if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
- g_warning ("conversion of dbus method arg failed but no exception was set?");
+ if (!seed_js_values_from_dbus(ctx, &arg_iter, &values, exception)) {
+ if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
+ g_warning(
+ "conversion of dbus method arg failed but no exception was set?");
return reply;
- }
+ }
/* we will add an argument, the callback */
- callback_object = seed_make_function(ctx, async_call_callback,
- "" /* anonymous */);
+ callback_object
+ = seed_make_function(ctx, async_call_callback, "" /* anonymous */);
g_assert(callback_object);
@@ -463,60 +426,57 @@ invoke_js_async_from_dbus(SeedContext ctx,
/* We attach the DBus sender and serial as properties to
* callback, so we don't need to bother with memory managing them
* if the callback is never called and just discarded.*/
- sender_string = seed_value_from_string (ctx, dbus_message_get_sender (method_call), exception);
- if (!sender_string)
- {
+ sender_string
+ = seed_value_from_string(ctx, dbus_message_get_sender(method_call),
+ exception);
+ if (!sender_string) {
thrown = TRUE;
goto out;
- }
-
- seed_object_set_property (ctx, callback_object, "_dbusSender", sender_string);
- seed_object_set_property (ctx, callback_object, "_dbusSerial",
- seed_value_from_int (ctx, dbus_message_get_serial (method_call),
- exception));
- seed_object_set_property (ctx, callback_object, "_dbusBusType",
- seed_value_from_int (ctx, bus_type, exception));
-
- if (!signature_from_method(ctx,
- method_obj,
- &signature,
- exception))
- {
+ }
+
+ seed_object_set_property(ctx, callback_object, "_dbusSender",
+ sender_string);
+ seed_object_set_property(ctx, callback_object, "_dbusSerial",
+ seed_value_from_int(ctx, dbus_message_get_serial(
+ method_call),
+ exception));
+ seed_object_set_property(ctx, callback_object, "_dbusBusType",
+ seed_value_from_int(ctx, bus_type, exception));
+
+ if (!signature_from_method(ctx, method_obj, &signature, exception)) {
thrown = TRUE;
goto out;
- }
+ }
- signature_string = seed_value_from_string (ctx, signature, exception);
- if (!signature_string)
- {
+ signature_string = seed_value_from_string(ctx, signature, exception);
+ if (!signature_string) {
thrown = TRUE;
goto out;
- }
- seed_object_set_property (ctx, callback_object, "_dbusOutSignature",
- signature_string);
+ }
+ seed_object_set_property(ctx, callback_object, "_dbusOutSignature",
+ signature_string);
argc = values->len;
- argv = (SeedValue *)values->data;
+ argv = (SeedValue*) values->data;
- seed_object_call (ctx, method_obj, this_obj, argc,
- argv, &ignored);
+ seed_object_call(ctx, method_obj, this_obj, argc, argv, &ignored);
out:
- if (thrown)
- {
+ if (thrown) {
if (!dbus_reply_from_exception(ctx, method_call, &reply, exception))
- g_warning("conversion of dbus method arg failed but no exception was set?");
- }
+ g_warning(
+ "conversion of dbus method arg failed but no exception was set?");
+ }
- g_array_free (values, TRUE);
+ g_array_free(values, TRUE);
return reply;
}
static SeedObject
find_js_property_by_path(SeedContext ctx,
- SeedObject root_obj,
- const gchar *path)
+ SeedObject root_obj,
+ const gchar* path)
{
- gchar **elements;
+ gchar** elements;
gint i;
SeedObject obj;
@@ -526,17 +486,15 @@ find_js_property_by_path(SeedContext ctx,
/* g_strsplit returns empty string for the first
* '/' so we start with elements[1]
*/
- for (i = 1; elements[i] != NULL; ++i)
- {
+ for (i = 1; elements[i] != NULL; ++i) {
obj = seed_object_get_property(ctx, obj, elements[i]);
- if (seed_value_is_undefined (ctx, obj) ||
- !seed_value_is_object (ctx, obj))
- {
- obj = NULL;
- break;
- }
- }
+ if (seed_value_is_undefined(ctx, obj)
+ || !seed_value_is_object(ctx, obj)) {
+ obj = NULL;
+ break;
+ }
+ }
g_strfreev(elements);
@@ -545,102 +503,83 @@ find_js_property_by_path(SeedContext ctx,
static gboolean
find_method(SeedContext ctx,
- SeedObject obj,
- const gchar *method_name,
- SeedValue *method_value)
+ SeedObject obj,
+ const gchar* method_name,
+ SeedValue* method_value)
{
- *method_value = seed_object_get_property (ctx, obj, method_name);
- if (seed_value_is_undefined (ctx, *method_value) ||
- !seed_value_is_object (ctx, *method_value))
- return FALSE;
+ *method_value = seed_object_get_property(ctx, obj, method_name);
+ if (seed_value_is_undefined(ctx, *method_value)
+ || !seed_value_is_object(ctx, *method_value))
+ return FALSE;
- return TRUE;
+ return TRUE;
}
-
static DBusHandlerResult
-on_message(DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
+on_message(DBusConnection* connection, DBusMessage* message, void* user_data)
{
- SeedContext ctx;
- const char *path;
- DBusHandlerResult result;
- SeedObject obj;
- const char *method_name;
- char *async_method_name;
- SeedValue method_value;
- DBusMessage *reply;
- Exports *priv;
-
- priv = user_data;
- async_method_name = NULL;
- reply = NULL;
-
- ctx = seed_context_create (group, NULL);
- seed_prepare_global_context (ctx);
-
- if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- method_value = seed_make_undefined (ctx);
-
- result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- path = dbus_message_get_path(message);
-
- obj = find_js_property_by_path(ctx,
- priv->object,
- path);
- if (obj == NULL)
- {
- g_warning("There is no JS object at %s",
- path);
+ SeedContext ctx;
+ const char* path;
+ DBusHandlerResult result;
+ SeedObject obj;
+ const char* method_name;
+ char* async_method_name;
+ SeedValue method_value;
+ DBusMessage* reply;
+ Exports* priv;
+
+ priv = user_data;
+ async_method_name = NULL;
+ reply = NULL;
+
+ ctx = seed_context_create(group, NULL);
+ seed_prepare_global_context(ctx);
+
+ if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ method_value = seed_make_undefined(ctx);
+
+ result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ path = dbus_message_get_path(message);
+
+ obj = find_js_property_by_path(ctx, priv->object, path);
+ if (obj == NULL) {
+ g_warning("There is no JS object at %s", path);
goto out;
- }
+ }
method_name = dbus_message_get_member(message);
async_method_name = g_strdup_printf("%sAsync", method_name);
/* try first if an async version exists */
- if (find_method(ctx,
- obj,
- async_method_name,
- &method_value)) {
-
- g_warning ("Invoking async method %s on JS obj at dbus path %s",
- async_method_name, path);
-
- reply = invoke_js_async_from_dbus(ctx,
- priv->which_bus,
- message,
- obj,
+ if (find_method(ctx, obj, async_method_name, &method_value)) {
+
+ g_warning("Invoking async method %s on JS obj at dbus path %s",
+ async_method_name, path);
+
+ reply = invoke_js_async_from_dbus(ctx, priv->which_bus, message, obj,
method_value,
- NULL); // Need exception here.
+ NULL); // Need exception here.
result = DBUS_HANDLER_RESULT_HANDLED;
- /* otherwise try the sync version */
- } else if (find_method(ctx,
- obj,
- method_name,
- &method_value)) {
+ /* otherwise try the sync version */
+ } else if (find_method(ctx, obj, method_name, &method_value)) {
- g_warning("Invoking method %s on JS obj at dbus path %s",
- method_name, path);
+ g_warning("Invoking method %s on JS obj at dbus path %s", method_name,
+ path);
- reply = invoke_js_from_dbus(ctx,
- message,
- obj,
- method_value,
- NULL); // Need exception here
+ reply = invoke_js_from_dbus(ctx, message, obj, method_value,
+ NULL); // Need exception here
result = DBUS_HANDLER_RESULT_HANDLED;
- /* otherwise FAIL */
+ /* otherwise FAIL */
} else {
- g_warning("There is a JS object at %s but it has no method %s",
- path, method_name);
+ g_warning("There is a JS object at %s but it has no method %s", path,
+ method_name);
}
if (reply != NULL) {
@@ -649,58 +588,56 @@ on_message(DBusConnection *connection,
}
out:
- seed_context_unref (ctx);
+ seed_context_unref(ctx);
if (async_method_name)
g_free(async_method_name);
return result;
}
static void
-exports_constructor(SeedContext ctx,
- SeedObject obj)
+exports_constructor(SeedContext ctx, SeedObject obj)
{
- Exports *priv;
+ Exports* priv;
- priv = g_slice_new0(Exports);
+ priv = g_slice_new0(Exports);
- seed_object_set_private (obj, priv);
- priv->object = obj;
+ seed_object_set_private(obj, priv);
+ priv->object = obj;
}
static gboolean
-add_connect_funcs(SeedContext ctx,
- SeedObject obj,
- DBusBusType which_bus)
+add_connect_funcs(SeedContext ctx, SeedObject obj, DBusBusType which_bus)
{
- Exports *priv;
- BigDBusConnectFuncs const *connect_funcs;
+ Exports* priv;
+ BigDBusConnectFuncs const* connect_funcs;
- priv = seed_object_get_private (obj);
- if (priv == NULL)
- return FALSE;
+ priv = seed_object_get_private(obj);
+ if (priv == NULL)
+ return FALSE;
- if (which_bus == DBUS_BUS_SESSION) {
- connect_funcs = &session_connect_funcs;
- } else if (which_bus == DBUS_BUS_SYSTEM) {
- connect_funcs = &system_connect_funcs;
- } else
- g_assert_not_reached();
+ if (which_bus == DBUS_BUS_SESSION) {
+ connect_funcs = &session_connect_funcs;
+ } else if (which_bus == DBUS_BUS_SYSTEM) {
+ connect_funcs = &system_connect_funcs;
+ } else
+ g_assert_not_reached();
- priv->which_bus = which_bus;
- big_dbus_add_connect_funcs_sync_notify(connect_funcs, priv);
+ priv->which_bus = which_bus;
+ big_dbus_add_connect_funcs_sync_notify(connect_funcs, priv);
- return TRUE;
+ return TRUE;
}
static void
-exports_finalize (SeedObject obj)
+exports_finalize(SeedObject obj)
{
- Exports *priv;
- BigDBusConnectFuncs const *connect_funcs = NULL;
+ Exports* priv;
+ BigDBusConnectFuncs const* connect_funcs = NULL;
- priv = seed_object_get_private (obj);
+ priv = seed_object_get_private(obj);
if (priv == NULL)
- return; /* we are the prototype, not a real instance, so constructor never called */
+ return; /* we are the prototype, not a real instance, so constructor
+ never called */
if (priv->which_bus == DBUS_BUS_SESSION) {
connect_funcs = &session_connect_funcs;
@@ -718,43 +655,38 @@ exports_finalize (SeedObject obj)
g_slice_free(Exports, priv);
}
-
static SeedObject
-exports_new (SeedContext ctx,
- DBusBusType which_bus)
+exports_new(SeedContext ctx, DBusBusType which_bus)
{
- SeedObject exports;
+ SeedObject exports;
- if (!seed_js_exports_class)
- {
- seed_class_definition def = seed_empty_class;
- def.initialize = exports_constructor;
- def.finalize = exports_finalize;
+ if (!seed_js_exports_class) {
+ seed_class_definition def = seed_empty_class;
+ def.initialize = exports_constructor;
+ def.finalize = exports_finalize;
- seed_js_exports_class = seed_create_class (&def);
+ seed_js_exports_class = seed_create_class(&def);
}
- exports = seed_make_object (ctx, seed_js_exports_class, NULL);
+ exports = seed_make_object(ctx, seed_js_exports_class, NULL);
- return exports;
+ return exports;
}
gboolean
seed_js_define_dbus_exports(SeedContext ctx,
- SeedObject on_object,
- DBusBusType which_bus)
+ SeedObject on_object,
+ DBusBusType which_bus)
{
- SeedObject exports;
-
+ SeedObject exports;
exports = exports_new(ctx, which_bus);
if (!exports)
- return FALSE;
+ return FALSE;
if (!add_connect_funcs(ctx, exports, which_bus))
- return FALSE;
+ return FALSE;
- seed_object_set_property (ctx, on_object, "exports",
- exports);
+ seed_object_set_property(ctx, on_object, "exports", exports);
return TRUE;
}
diff --git a/modules/dbus/dbus-exports.h b/modules/dbus/dbus-exports.h
index 716cf61..caad5e7 100644
--- a/modules/dbus/dbus-exports.h
+++ b/modules/dbus/dbus-exports.h
@@ -8,9 +8,9 @@
G_BEGIN_DECLS
-gboolean seed_js_define_dbus_exports (SeedContext ctx,
- SeedObject object,
- DBusBusType which_bus);
+gboolean seed_js_define_dbus_exports(SeedContext ctx,
+ SeedObject object,
+ DBusBusType which_bus);
G_END_DECLS
diff --git a/modules/dbus/dbus-values.c b/modules/dbus/dbus-values.c
index 2338477..72c36e6 100644
--- a/modules/dbus/dbus-values.c
+++ b/modules/dbus/dbus-values.c
@@ -29,385 +29,342 @@
#include <string.h>
gboolean
-seed_js_one_value_from_dbus (SeedContext ctx,
- DBusMessageIter * iter,
- SeedValue *value_p,
- SeedException *exception)
+seed_js_one_value_from_dbus(SeedContext ctx,
+ DBusMessageIter* iter,
+ SeedValue* value_p,
+ SeedException* exception)
{
- int arg_type;
+ int arg_type;
- *value_p = seed_make_undefined (ctx);
+ *value_p = seed_make_undefined(ctx);
- arg_type = dbus_message_iter_get_arg_type (iter);
+ arg_type = dbus_message_iter_get_arg_type(iter);
- SEED_NOTE(MODULE,
- "Converting dbus type '%c' to SeedValue",
- arg_type != DBUS_TYPE_INVALID ? arg_type : '0');
+ SEED_NOTE(MODULE, "Converting dbus type '%c' to SeedValue",
+ arg_type != DBUS_TYPE_INVALID ? arg_type : '0');
- switch (arg_type)
- {
- case DBUS_TYPE_STRUCT:
- {
- SeedObject obj;
- DBusMessageIter struct_iter;
- int index;
-
- obj = seed_make_object (ctx, NULL, NULL);
-
- dbus_message_iter_recurse (iter, &struct_iter);
- index = 0;
- while (dbus_message_iter_get_arg_type (&struct_iter) !=
- DBUS_TYPE_INVALID)
- {
- SeedValue prop_value;
-
- prop_value = seed_make_undefined (ctx);
-
- if (!seed_js_one_value_from_dbus
- (ctx, &struct_iter, &prop_value, exception))
- {
- return FALSE;
- }
-
- seed_object_set_property_at_index (ctx, obj, index,
- prop_value, exception);
- dbus_message_iter_next (&struct_iter);
- index++;
- }
- seed_object_set_property (ctx, obj, "length",
- seed_value_from_int (ctx, index, exception));
- *value_p = (SeedValue) obj;
- }
- break;
- case DBUS_TYPE_ARRAY:
- {
- int elem_type = dbus_message_iter_get_element_type (iter);
-
- if (elem_type == DBUS_TYPE_DICT_ENTRY)
- {
- /* Create a dictionary object */
+ switch (arg_type) {
+ case DBUS_TYPE_STRUCT: {
SeedObject obj;
- DBusMessageIter array_iter;
-
- obj = seed_make_object (ctx, NULL, NULL);
+ DBusMessageIter struct_iter;
+ int index;
- dbus_message_iter_recurse (iter, &array_iter);
- while (dbus_message_iter_get_arg_type (&array_iter) !=
- DBUS_TYPE_INVALID)
- {
- DBusMessageIter entry_iter;
- const char *key;
- SeedValue entry_value;
+ obj = seed_make_object(ctx, NULL, NULL);
- dbus_message_iter_recurse (&array_iter, &entry_iter);
+ dbus_message_iter_recurse(iter, &struct_iter);
+ index = 0;
+ while (dbus_message_iter_get_arg_type(&struct_iter)
+ != DBUS_TYPE_INVALID) {
+ SeedValue prop_value;
- if (dbus_message_iter_get_arg_type (&entry_iter) !=
- DBUS_TYPE_STRING)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Dictionary keys are not strings,"
- "can't convert to JavaScript");
+ prop_value = seed_make_undefined(ctx);
+ if (!seed_js_one_value_from_dbus(ctx, &struct_iter, &prop_value,
+ exception)) {
return FALSE;
- }
-
- dbus_message_iter_get_basic (&entry_iter, &key);
-
- dbus_message_iter_next (&entry_iter);
-
- SEED_NOTE(MODULE,
- "Defining dict entry %s in jsval dict",
- key);
-
- entry_value = seed_make_undefined (ctx);
-
- if (!seed_js_one_value_from_dbus
- (ctx, &entry_iter, &entry_value, exception))
- {
- return FALSE;
- }
-
- seed_object_set_property (ctx, obj,
- key, entry_value);
-
- dbus_message_iter_next (&array_iter);
- }
-
- *value_p = (SeedValue) obj;
- }
- else if (elem_type == DBUS_TYPE_BYTE)
- {
- /* byte arrays go to a string */
- const char *v_BYTES;
- int n_bytes;
- DBusMessageIter array_iter;
-
- dbus_message_iter_recurse (iter, &array_iter);
- dbus_message_iter_get_fixed_array (&array_iter,
- &v_BYTES, &n_bytes);
- // This is where I am.
- *value_p = seed_value_from_binary_string (ctx, v_BYTES, n_bytes, exception);
- }
- else
- {
- SeedObject obj;
- DBusMessageIter array_iter;
- int index;
-
- obj = seed_make_object (ctx, NULL, NULL);
-
- dbus_message_iter_recurse (iter, &array_iter);
- index = 0;
- while (dbus_message_iter_get_arg_type (&array_iter) !=
- DBUS_TYPE_INVALID)
- {
- SeedValue prop_value;
-
- prop_value = seed_make_undefined (ctx);
-
- if (!seed_js_one_value_from_dbus
- (ctx, &array_iter, &prop_value, exception))
- {
- return FALSE;
- }
-
- seed_object_set_property_at_index (ctx, obj, index, prop_value, exception);
-
- dbus_message_iter_next (&array_iter);
- index++;
- }
- seed_object_set_property (ctx, obj, "length",
- seed_value_from_int (ctx,
- index, exception));
- *value_p = (SeedValue) obj;
- }
- }
- break;
- case DBUS_TYPE_BOOLEAN:
- {
- dbus_bool_t v_BOOLEAN;
- dbus_message_iter_get_basic (iter, &v_BOOLEAN);
- *value_p = seed_value_from_boolean (ctx, v_BOOLEAN, exception);
- }
- break;
- case DBUS_TYPE_BYTE:
- {
- unsigned char v_BYTE;
- dbus_message_iter_get_basic (iter, &v_BYTE);
- *value_p = seed_value_from_int (ctx, v_BYTE, exception);
- }
- break;
- case DBUS_TYPE_INT32:
- {
- dbus_int32_t v_INT32;
- dbus_message_iter_get_basic (iter, &v_INT32);
- *value_p = seed_value_from_int (ctx, v_INT32, exception);
- }
- break;
- case DBUS_TYPE_UINT32:
- {
- dbus_uint32_t v_UINT32;
- dbus_message_iter_get_basic (iter, &v_UINT32);
- *value_p = seed_value_from_uint (ctx, v_UINT32, exception);
- }
- break;
- case DBUS_TYPE_INT64:
- {
- dbus_int64_t v_INT64;
- dbus_message_iter_get_basic (iter, &v_INT64);
- *value_p = seed_value_from_int64 (ctx, v_INT64, exception);
- }
- break;
- case DBUS_TYPE_UINT64:
- {
- dbus_uint64_t v_UINT64;
- dbus_message_iter_get_basic (iter, &v_UINT64);
- *value_p = seed_value_from_uint64 (ctx, v_UINT64, exception);
- }
- break;
- case DBUS_TYPE_DOUBLE:
- {
- double v_DOUBLE;
- dbus_message_iter_get_basic (iter, &v_DOUBLE);
- *value_p = seed_value_from_double (ctx, v_DOUBLE, exception);
- }
- break;
- case DBUS_TYPE_OBJECT_PATH:
- case DBUS_TYPE_STRING:
- {
- char *v_STRING;
-
- dbus_message_iter_get_basic (iter, &v_STRING);
-
- *value_p = seed_value_from_string (ctx, v_STRING, exception);
- }
- break;
-
- case DBUS_TYPE_VARIANT:
- {
- DBusMessageIter variant_iter;
-
- dbus_message_iter_recurse (iter, &variant_iter);
-
- return seed_js_one_value_from_dbus (ctx, &variant_iter, value_p, exception);
- }
- break;
-
- case DBUS_TYPE_INVALID:
- *value_p = seed_make_undefined (ctx);
- break;
-
- default:
- SEED_NOTE (MODULE,
- "Don't know how to convert dbus type %c to JavaScript",
- arg_type);
- return FALSE;
+ }
+
+ seed_object_set_property_at_index(ctx, obj, index, prop_value,
+ exception);
+ dbus_message_iter_next(&struct_iter);
+ index++;
+ }
+ seed_object_set_property(ctx, obj, "length",
+ seed_value_from_int(ctx, index,
+ exception));
+ *value_p = (SeedValue) obj;
+ } break;
+ case DBUS_TYPE_ARRAY: {
+ int elem_type = dbus_message_iter_get_element_type(iter);
+
+ if (elem_type == DBUS_TYPE_DICT_ENTRY) {
+ /* Create a dictionary object */
+ SeedObject obj;
+ DBusMessageIter array_iter;
+
+ obj = seed_make_object(ctx, NULL, NULL);
+
+ dbus_message_iter_recurse(iter, &array_iter);
+ while (dbus_message_iter_get_arg_type(&array_iter)
+ != DBUS_TYPE_INVALID) {
+ DBusMessageIter entry_iter;
+ const char* key;
+ SeedValue entry_value;
+
+ dbus_message_iter_recurse(&array_iter, &entry_iter);
+
+ if (dbus_message_iter_get_arg_type(&entry_iter)
+ != DBUS_TYPE_STRING) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Dictionary keys are not strings,"
+ "can't convert to JavaScript");
+
+ return FALSE;
+ }
+
+ dbus_message_iter_get_basic(&entry_iter, &key);
+
+ dbus_message_iter_next(&entry_iter);
+
+ SEED_NOTE(MODULE, "Defining dict entry %s in jsval dict",
+ key);
+
+ entry_value = seed_make_undefined(ctx);
+
+ if (!seed_js_one_value_from_dbus(ctx, &entry_iter,
+ &entry_value, exception)) {
+ return FALSE;
+ }
+
+ seed_object_set_property(ctx, obj, key, entry_value);
+
+ dbus_message_iter_next(&array_iter);
+ }
+
+ *value_p = (SeedValue) obj;
+ } else if (elem_type == DBUS_TYPE_BYTE) {
+ /* byte arrays go to a string */
+ const char* v_BYTES;
+ int n_bytes;
+ DBusMessageIter array_iter;
+
+ dbus_message_iter_recurse(iter, &array_iter);
+ dbus_message_iter_get_fixed_array(&array_iter, &v_BYTES,
+ &n_bytes);
+ // This is where I am.
+ *value_p = seed_value_from_binary_string(ctx, v_BYTES, n_bytes,
+ exception);
+ } else {
+ SeedObject obj;
+ DBusMessageIter array_iter;
+ int index;
+
+ obj = seed_make_object(ctx, NULL, NULL);
+
+ dbus_message_iter_recurse(iter, &array_iter);
+ index = 0;
+ while (dbus_message_iter_get_arg_type(&array_iter)
+ != DBUS_TYPE_INVALID) {
+ SeedValue prop_value;
+
+ prop_value = seed_make_undefined(ctx);
+
+ if (!seed_js_one_value_from_dbus(ctx, &array_iter,
+ &prop_value, exception)) {
+ return FALSE;
+ }
+
+ seed_object_set_property_at_index(ctx, obj, index,
+ prop_value, exception);
+
+ dbus_message_iter_next(&array_iter);
+ index++;
+ }
+ seed_object_set_property(ctx, obj, "length",
+ seed_value_from_int(ctx, index,
+ exception));
+ *value_p = (SeedValue) obj;
+ }
+ } break;
+ case DBUS_TYPE_BOOLEAN: {
+ dbus_bool_t v_BOOLEAN;
+ dbus_message_iter_get_basic(iter, &v_BOOLEAN);
+ *value_p = seed_value_from_boolean(ctx, v_BOOLEAN, exception);
+ } break;
+ case DBUS_TYPE_BYTE: {
+ unsigned char v_BYTE;
+ dbus_message_iter_get_basic(iter, &v_BYTE);
+ *value_p = seed_value_from_int(ctx, v_BYTE, exception);
+ } break;
+ case DBUS_TYPE_INT32: {
+ dbus_int32_t v_INT32;
+ dbus_message_iter_get_basic(iter, &v_INT32);
+ *value_p = seed_value_from_int(ctx, v_INT32, exception);
+ } break;
+ case DBUS_TYPE_UINT32: {
+ dbus_uint32_t v_UINT32;
+ dbus_message_iter_get_basic(iter, &v_UINT32);
+ *value_p = seed_value_from_uint(ctx, v_UINT32, exception);
+ } break;
+ case DBUS_TYPE_INT64: {
+ dbus_int64_t v_INT64;
+ dbus_message_iter_get_basic(iter, &v_INT64);
+ *value_p = seed_value_from_int64(ctx, v_INT64, exception);
+ } break;
+ case DBUS_TYPE_UINT64: {
+ dbus_uint64_t v_UINT64;
+ dbus_message_iter_get_basic(iter, &v_UINT64);
+ *value_p = seed_value_from_uint64(ctx, v_UINT64, exception);
+ } break;
+ case DBUS_TYPE_DOUBLE: {
+ double v_DOUBLE;
+ dbus_message_iter_get_basic(iter, &v_DOUBLE);
+ *value_p = seed_value_from_double(ctx, v_DOUBLE, exception);
+ } break;
+ case DBUS_TYPE_OBJECT_PATH:
+ case DBUS_TYPE_STRING: {
+ char* v_STRING;
+
+ dbus_message_iter_get_basic(iter, &v_STRING);
+
+ *value_p = seed_value_from_string(ctx, v_STRING, exception);
+ } break;
+
+ case DBUS_TYPE_VARIANT: {
+ DBusMessageIter variant_iter;
+
+ dbus_message_iter_recurse(iter, &variant_iter);
+
+ return seed_js_one_value_from_dbus(ctx, &variant_iter, value_p,
+ exception);
+ } break;
+
+ case DBUS_TYPE_INVALID:
+ *value_p = seed_make_undefined(ctx);
+ break;
+
+ default:
+ SEED_NOTE(MODULE,
+ "Don't know how to convert dbus type %c to JavaScript",
+ arg_type);
+ return FALSE;
}
- return TRUE;
+ return TRUE;
}
gboolean
-seed_js_values_from_dbus (SeedContext ctx,
- DBusMessageIter * iter,
- GArray **array_p,
- SeedException *exception)
+seed_js_values_from_dbus(SeedContext ctx,
+ DBusMessageIter* iter,
+ GArray** array_p,
+ SeedException* exception)
{
- GArray *array;
- SeedValue value;
+ GArray* array;
+ SeedValue value;
- value = seed_make_undefined (ctx);
+ value = seed_make_undefined(ctx);
- array = g_array_new (FALSE, FALSE, sizeof(SeedValue));
+ array = g_array_new(FALSE, FALSE, sizeof(SeedValue));
- /* TODO */
- // THIS IS WHERE IA M
- // Wheee.
- do
- {
- if (!seed_js_one_value_from_dbus (ctx, iter, &value, exception))
- {
- g_array_free (array, TRUE);
- return FALSE;
- }
+ /* TODO */
+ // THIS IS WHERE IA M
+ // Wheee.
+ do {
+ if (!seed_js_one_value_from_dbus(ctx, iter, &value, exception)) {
+ g_array_free(array, TRUE);
+ return FALSE;
+ }
- g_array_append_val (array, value);
- }
- while (dbus_message_iter_next (iter));
+ g_array_append_val(array, value);
+ } while (dbus_message_iter_next(iter));
- *array_p = array;
- return TRUE;
+ *array_p = array;
+ return TRUE;
}
static void
-append_basic_maybe_in_variant (DBusMessageIter * iter,
- int dbus_type,
- void *value, gboolean wrap_in_variant)
+append_basic_maybe_in_variant(DBusMessageIter* iter,
+ int dbus_type,
+ void* value,
+ gboolean wrap_in_variant)
{
- if (wrap_in_variant)
- {
- char buf[2];
- DBusMessageIter variant_iter;
-
- buf[0] = dbus_type;
- buf[1] = '\0';
-
- dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, buf,
- &variant_iter);
- dbus_message_iter_append_basic (&variant_iter, dbus_type, value);
- dbus_message_iter_close_container (iter, &variant_iter);
- }
- else
- {
- dbus_message_iter_append_basic (iter, dbus_type, value);
+ if (wrap_in_variant) {
+ char buf[2];
+ DBusMessageIter variant_iter;
+
+ buf[0] = dbus_type;
+ buf[1] = '\0';
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, buf,
+ &variant_iter);
+ dbus_message_iter_append_basic(&variant_iter, dbus_type, value);
+ dbus_message_iter_close_container(iter, &variant_iter);
+ } else {
+ dbus_message_iter_append_basic(iter, dbus_type, value);
}
}
static void
-append_byte_array_maybe_in_variant (DBusMessageIter * iter,
- const char *data,
- gsize len,
- gboolean wrap_in_variant)
+append_byte_array_maybe_in_variant(DBusMessageIter* iter,
+ const char* data,
+ gsize len,
+ gboolean wrap_in_variant)
{
- DBusMessageIter array_iter;
- DBusMessageIter variant_iter;
+ DBusMessageIter array_iter;
+ DBusMessageIter variant_iter;
- if (wrap_in_variant)
- {
- dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "ay",
- &variant_iter);
+ if (wrap_in_variant) {
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "ay",
+ &variant_iter);
}
- dbus_message_iter_open_container (wrap_in_variant ? &variant_iter : iter,
- DBUS_TYPE_ARRAY, "y", &array_iter);
+ dbus_message_iter_open_container(wrap_in_variant ? &variant_iter : iter,
+ DBUS_TYPE_ARRAY, "y", &array_iter);
- dbus_message_iter_append_fixed_array (&array_iter, DBUS_TYPE_BYTE,
- &data, len);
+ dbus_message_iter_append_fixed_array(&array_iter, DBUS_TYPE_BYTE, &data,
+ len);
- dbus_message_iter_close_container (wrap_in_variant ? &variant_iter : iter,
- &array_iter);
+ dbus_message_iter_close_container(wrap_in_variant ? &variant_iter : iter,
+ &array_iter);
- if (wrap_in_variant)
- {
- dbus_message_iter_close_container (iter, &variant_iter);
+ if (wrap_in_variant) {
+ dbus_message_iter_close_container(iter, &variant_iter);
}
}
static gboolean
-append_string (SeedContext ctx,
- DBusMessageIter * iter,
- const char *forced_signature,
- const char *s,
- gsize len,
- SeedException *exception)
+append_string(SeedContext ctx,
+ DBusMessageIter* iter,
+ const char* forced_signature,
+ const char* s,
+ gsize len,
+ SeedException* exception)
{
- int forced_type;
-
- if (forced_signature == NULL || *forced_signature == DBUS_TYPE_INVALID)
- forced_type = DBUS_TYPE_STRING;
- else
- forced_type = *forced_signature;
-
- switch (forced_type)
- {
- case DBUS_TYPE_STRING:
- case DBUS_TYPE_OBJECT_PATH:
- case DBUS_TYPE_SIGNATURE:
- append_basic_maybe_in_variant (iter, forced_type, &s, FALSE);
- break;
- case DBUS_TYPE_VARIANT:
- append_basic_maybe_in_variant (iter, DBUS_TYPE_STRING, &s, TRUE);
- break;
- case DBUS_TYPE_ARRAY:
- g_assert (forced_signature != NULL);
- g_assert (forced_signature[0] == DBUS_TYPE_ARRAY);
- if (forced_signature[1] == DBUS_TYPE_BYTE)
- {
- append_byte_array_maybe_in_variant (iter, s, len, FALSE);
- }
- else
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "JavaScript string can't be converted to dbus array with elements of type
'%c'",
- forced_signature[1]);
- return FALSE;
- }
- break;
- default:
- seed_make_exception (ctx, exception, "ArgumentError",
- "JavaScript string can't be converted to dbus type '%c'",
- forced_type);
- return FALSE;
+ int forced_type;
+
+ if (forced_signature == NULL || *forced_signature == DBUS_TYPE_INVALID)
+ forced_type = DBUS_TYPE_STRING;
+ else
+ forced_type = *forced_signature;
+
+ switch (forced_type) {
+ case DBUS_TYPE_STRING:
+ case DBUS_TYPE_OBJECT_PATH:
+ case DBUS_TYPE_SIGNATURE:
+ append_basic_maybe_in_variant(iter, forced_type, &s, FALSE);
+ break;
+ case DBUS_TYPE_VARIANT:
+ append_basic_maybe_in_variant(iter, DBUS_TYPE_STRING, &s, TRUE);
+ break;
+ case DBUS_TYPE_ARRAY:
+ g_assert(forced_signature != NULL);
+ g_assert(forced_signature[0] == DBUS_TYPE_ARRAY);
+ if (forced_signature[1] == DBUS_TYPE_BYTE) {
+ append_byte_array_maybe_in_variant(iter, s, len, FALSE);
+ } else {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "JavaScript string can't be converted to "
+ "dbus array with elements of type '%c'",
+ forced_signature[1]);
+ return FALSE;
+ }
+ break;
+ default:
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "JavaScript string can't be converted to dbus type '%c'",
+ forced_type);
+ return FALSE;
}
- return TRUE;
+ return TRUE;
}
/* Seems to be unused
static gboolean
append_int32 (SeedContext ctx,
- DBusMessageIter * iter,
+ DBusMessageIter * iter,
int forced_type,
dbus_int32_t v_INT32,
SeedException *exception)
@@ -425,25 +382,26 @@ append_int32 (SeedContext ctx,
break;
case DBUS_TYPE_UINT32:
{
- dbus_uint32_t v_UINT32 = v_INT32;
- append_basic_maybe_in_variant (iter, forced_type, &v_UINT32, FALSE);
+ dbus_uint32_t v_UINT32 = v_INT32;
+ append_basic_maybe_in_variant (iter, forced_type, &v_UINT32, FALSE);
}
break;
case DBUS_TYPE_DOUBLE:
{
- double v_DOUBLE = v_INT32;
- append_basic_maybe_in_variant (iter, forced_type, &v_DOUBLE, FALSE);
+ double v_DOUBLE = v_INT32;
+ append_basic_maybe_in_variant (iter, forced_type, &v_DOUBLE, FALSE);
}
break;
case DBUS_TYPE_BYTE:
{
- unsigned char v_BYTE = v_INT32;
- append_basic_maybe_in_variant (iter, forced_type, &v_BYTE, FALSE);
+ unsigned char v_BYTE = v_INT32;
+ append_basic_maybe_in_variant (iter, forced_type, &v_BYTE, FALSE);
}
break;
default:
seed_make_exception (ctx, exception, "ArgumentError",
- "JavaScript Integer can't be converted to dbus type '%c'",
+ "JavaScript Integer can't be converted to dbus type
+'%c'",
forced_type);
return FALSE;
}
@@ -453,521 +411,485 @@ append_int32 (SeedContext ctx,
*/
static gboolean
-append_double (SeedContext ctx,
- DBusMessageIter * iter, int forced_type, double v_DOUBLE,
- SeedException *exception)
+append_double(SeedContext ctx,
+ DBusMessageIter* iter,
+ int forced_type,
+ double v_DOUBLE,
+ SeedException* exception)
{
- if (forced_type == DBUS_TYPE_INVALID)
- forced_type = DBUS_TYPE_DOUBLE;
-
- switch (forced_type)
- {
- case DBUS_TYPE_DOUBLE:
- append_basic_maybe_in_variant (iter, forced_type, &v_DOUBLE, FALSE);
- break;
- case DBUS_TYPE_VARIANT:
- append_basic_maybe_in_variant (iter, DBUS_TYPE_DOUBLE, &v_DOUBLE, TRUE);
- break;
- case DBUS_TYPE_INT32:
- {
- dbus_int32_t v_INT32 = v_DOUBLE;
- append_basic_maybe_in_variant (iter, forced_type, &v_INT32, FALSE);
- }
- break;
- case DBUS_TYPE_UINT32:
- {
- dbus_uint32_t v_UINT32 = v_DOUBLE;
- append_basic_maybe_in_variant (iter, forced_type, &v_UINT32, FALSE);
- }
- break;
- default:
- seed_make_exception (ctx, exception, "ArgumentError",
- "JavaScript Number can't be converted to dbus type '%c'",
- forced_type);
- return FALSE;
+ if (forced_type == DBUS_TYPE_INVALID)
+ forced_type = DBUS_TYPE_DOUBLE;
+
+ switch (forced_type) {
+ case DBUS_TYPE_DOUBLE:
+ append_basic_maybe_in_variant(iter, forced_type, &v_DOUBLE, FALSE);
+ break;
+ case DBUS_TYPE_VARIANT:
+ append_basic_maybe_in_variant(iter, DBUS_TYPE_DOUBLE, &v_DOUBLE,
+ TRUE);
+ break;
+ case DBUS_TYPE_INT32: {
+ dbus_int32_t v_INT32 = v_DOUBLE;
+ append_basic_maybe_in_variant(iter, forced_type, &v_INT32, FALSE);
+ } break;
+ case DBUS_TYPE_UINT32: {
+ dbus_uint32_t v_UINT32 = v_DOUBLE;
+ append_basic_maybe_in_variant(iter, forced_type, &v_UINT32, FALSE);
+ } break;
+ default:
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "JavaScript Number can't be converted to dbus type '%c'",
+ forced_type);
+ return FALSE;
}
- return TRUE;
+ return TRUE;
}
static gboolean
-append_boolean (SeedContext ctx,
- DBusMessageIter * iter,
- int forced_type, dbus_bool_t v_BOOLEAN,
- SeedException *exception)
+append_boolean(SeedContext ctx,
+ DBusMessageIter* iter,
+ int forced_type,
+ dbus_bool_t v_BOOLEAN,
+ SeedException* exception)
{
- if (forced_type == DBUS_TYPE_INVALID)
- forced_type = DBUS_TYPE_BOOLEAN;
-
- switch (forced_type)
- {
- case DBUS_TYPE_BOOLEAN:
- append_basic_maybe_in_variant (iter, forced_type, &v_BOOLEAN, FALSE);
- break;
- case DBUS_TYPE_VARIANT:
- append_basic_maybe_in_variant (iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN,
- TRUE);
- break;
- default:
- seed_make_exception (ctx, exception, "ArgumentError",
- "JavaScript Boolean can't be converted to dbus type '%c'",
- forced_type);
- return FALSE;
+ if (forced_type == DBUS_TYPE_INVALID)
+ forced_type = DBUS_TYPE_BOOLEAN;
+
+ switch (forced_type) {
+ case DBUS_TYPE_BOOLEAN:
+ append_basic_maybe_in_variant(iter, forced_type, &v_BOOLEAN, FALSE);
+ break;
+ case DBUS_TYPE_VARIANT:
+ append_basic_maybe_in_variant(iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN,
+ TRUE);
+ break;
+ default:
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "JavaScript Boolean can't be converted to dbus type '%c'",
+ forced_type);
+ return FALSE;
}
- return TRUE;
+ return TRUE;
}
static gboolean
-append_array (SeedContext ctx,
- DBusMessageIter * iter,
- DBusSignatureIter * sig_iter, SeedObject array,
- int length,
- SeedException *exception)
+append_array(SeedContext ctx,
+ DBusMessageIter* iter,
+ DBusSignatureIter* sig_iter,
+ SeedObject array,
+ int length,
+ SeedException* exception)
{
- DBusSignatureIter element_sig_iter;
- int forced_type;
- SeedValue element;
- DBusMessageIter array_iter;
- DBusMessageIter variant_iter;
- int i;
- char *sig;
-
- forced_type = dbus_signature_iter_get_current_type (sig_iter);
-
- if (forced_type == DBUS_TYPE_VARIANT)
- {
- DBusSignatureIter variant_sig_iter;
+ DBusSignatureIter element_sig_iter;
+ int forced_type;
+ SeedValue element;
+ DBusMessageIter array_iter;
+ DBusMessageIter variant_iter;
+ int i;
+ char* sig;
+
+ forced_type = dbus_signature_iter_get_current_type(sig_iter);
+
+ if (forced_type == DBUS_TYPE_VARIANT) {
+ DBusSignatureIter variant_sig_iter;
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "av",
+ &variant_iter);
+ dbus_signature_iter_init(&variant_sig_iter, "av");
+ if (!append_array(ctx, &variant_iter, &variant_sig_iter, array, length,
+ exception))
+ return FALSE;
+ dbus_message_iter_close_container(iter, &variant_iter);
- dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT,
- "av", &variant_iter);
- dbus_signature_iter_init (&variant_sig_iter, "av");
- if (!append_array (ctx, &variant_iter,
- &variant_sig_iter, array, length, exception))
+ return TRUE;
+ } else if (forced_type != DBUS_TYPE_ARRAY) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "JavaScript Array can't be converted to dbus type %c", forced_type);
return FALSE;
- dbus_message_iter_close_container (iter, &variant_iter);
-
- return TRUE;
- }
- else if (forced_type != DBUS_TYPE_ARRAY)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "JavaScript Array can't be converted to dbus type %c",
- forced_type);
- return FALSE;
}
- g_assert (dbus_signature_iter_get_current_type (sig_iter) ==
- DBUS_TYPE_ARRAY);
- dbus_signature_iter_recurse (sig_iter, &element_sig_iter);
+ g_assert(dbus_signature_iter_get_current_type(sig_iter) == DBUS_TYPE_ARRAY);
+ dbus_signature_iter_recurse(sig_iter, &element_sig_iter);
- sig = dbus_signature_iter_get_signature (&element_sig_iter);
- dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, sig, &array_iter);
- dbus_free (sig);
+ sig = dbus_signature_iter_get_signature(&element_sig_iter);
+ dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, sig, &array_iter);
+ dbus_free(sig);
- for (i = 0; i < length; i++)
- {
- element = seed_object_get_property_at_index (ctx, array, i, exception);
+ for (i = 0; i < length; i++) {
+ element = seed_object_get_property_at_index(ctx, array, i, exception);
- SEED_NOTE(MODULE, " Adding array element %u", i);
+ SEED_NOTE(MODULE, " Adding array element %u", i);
- if (!seed_js_one_value_to_dbus (ctx, element, &array_iter,
- &element_sig_iter, exception))
- return FALSE;
+ if (!seed_js_one_value_to_dbus(ctx, element, &array_iter,
+ &element_sig_iter, exception))
+ return FALSE;
}
- dbus_message_iter_close_container (iter, &array_iter);
+ dbus_message_iter_close_container(iter, &array_iter);
- return TRUE;
+ return TRUE;
}
// TODO: THIS IS WHERE I AM
static gboolean
-append_dict (SeedContext ctx,
- DBusMessageIter * iter,
- DBusSignatureIter * sig_iter,
- SeedObject props,
- SeedException *exception)
+append_dict(SeedContext ctx,
+ DBusMessageIter* iter,
+ DBusSignatureIter* sig_iter,
+ SeedObject props,
+ SeedException* exception)
{
- DBusSignatureIter element_sig_iter;
- int forced_type;
- DBusMessageIter variant_iter;
- gchar **prop_names;
- guint num_props, i;
- DBusMessageIter dict_iter;
- DBusSignatureIter dict_value_sig_iter;
- char *sig;
- SeedValue prop_signatures;
-
- forced_type = dbus_signature_iter_get_current_type (sig_iter);
-
- if (forced_type == DBUS_TYPE_VARIANT)
- {
- DBusSignatureIter variant_sig_iter;
+ DBusSignatureIter element_sig_iter;
+ int forced_type;
+ DBusMessageIter variant_iter;
+ gchar** prop_names;
+ guint num_props, i;
+ DBusMessageIter dict_iter;
+ DBusSignatureIter dict_value_sig_iter;
+ char* sig;
+ SeedValue prop_signatures;
+
+ forced_type = dbus_signature_iter_get_current_type(sig_iter);
+
+ if (forced_type == DBUS_TYPE_VARIANT) {
+ DBusSignatureIter variant_sig_iter;
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "a{sv}",
+ &variant_iter);
+ dbus_signature_iter_init(&variant_sig_iter, "a{sv}");
+ if (!append_dict(ctx, &variant_iter, &variant_sig_iter, props,
+ exception))
+ return FALSE;
+ dbus_message_iter_close_container(iter, &variant_iter);
- dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT,
- "a{sv}", &variant_iter);
- dbus_signature_iter_init (&variant_sig_iter, "a{sv}");
- if (!append_dict (ctx, &variant_iter, &variant_sig_iter, props, exception))
+ return TRUE;
+ } else if (forced_type != DBUS_TYPE_ARRAY) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "JavaScript Object can't be converted to dbus type %c", forced_type);
return FALSE;
- dbus_message_iter_close_container (iter, &variant_iter);
-
- return TRUE;
- }
- else if (forced_type != DBUS_TYPE_ARRAY)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "JavaScript Object can't be converted to dbus type %c",
- forced_type);
- return FALSE;
}
- g_assert (dbus_signature_iter_get_current_type (sig_iter) ==
- DBUS_TYPE_ARRAY);
- dbus_signature_iter_recurse (sig_iter, &element_sig_iter);
+ g_assert(dbus_signature_iter_get_current_type(sig_iter) == DBUS_TYPE_ARRAY);
+ dbus_signature_iter_recurse(sig_iter, &element_sig_iter);
- if (dbus_signature_iter_get_current_type (&element_sig_iter) !=
- DBUS_TYPE_DICT_ENTRY)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Objects must be marshaled as array of dict entry not of %c",
- dbus_signature_iter_get_current_type (&element_sig_iter));
- return FALSE;
+ if (dbus_signature_iter_get_current_type(&element_sig_iter)
+ != DBUS_TYPE_DICT_ENTRY) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Objects must be marshaled as array of dict entry not of %c",
+ dbus_signature_iter_get_current_type(&element_sig_iter));
+ return FALSE;
}
- /* dbus itself enforces that dict keys are strings */
-
- g_assert (dbus_signature_iter_get_current_type (&element_sig_iter) ==
- DBUS_TYPE_DICT_ENTRY);
- dbus_signature_iter_recurse (&element_sig_iter, &dict_value_sig_iter);
- /* check it points to key type first */
- g_assert (dbus_signature_iter_get_current_type (&dict_value_sig_iter) ==
- DBUS_TYPE_STRING);
- /* move to value type */
- dbus_signature_iter_next (&dict_value_sig_iter);
-
- sig = dbus_signature_iter_get_signature (&element_sig_iter);
- dbus_message_iter_open_container (iter, DBUS_TYPE_ARRAY, sig, &dict_iter);
- dbus_free (sig);
-
- /* If a dictionary contains another dictionary at key
- * _dbus_signatures, the sub-dictionary can provide the signature
- * of each value in the outer dictionary. This allows forcing
- * integers to unsigned or whatever.
- *
- * _dbus_signatures has a weird name to avoid conflicting with
- * real properties. Matches _dbus_sender which is used elsewhere.
- *
- * We don't bother rooting the signature object or the stuff in it
- * because we assume the outer dictionary is rooted so the stuff
- * in it is also.
- */
- prop_signatures = seed_object_get_property (ctx, props, "_dbus_signatures");
-
- if (!seed_value_is_undefined (ctx, prop_signatures) && !seed_value_is_object (ctx, prop_signatures))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "_dbus_signatures prop must be an object");
- return FALSE;
+ /* dbus itself enforces that dict keys are strings */
+
+ g_assert(dbus_signature_iter_get_current_type(&element_sig_iter)
+ == DBUS_TYPE_DICT_ENTRY);
+ dbus_signature_iter_recurse(&element_sig_iter, &dict_value_sig_iter);
+ /* check it points to key type first */
+ g_assert(dbus_signature_iter_get_current_type(&dict_value_sig_iter)
+ == DBUS_TYPE_STRING);
+ /* move to value type */
+ dbus_signature_iter_next(&dict_value_sig_iter);
+
+ sig = dbus_signature_iter_get_signature(&element_sig_iter);
+ dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, sig, &dict_iter);
+ dbus_free(sig);
+
+ /* If a dictionary contains another dictionary at key
+ * _dbus_signatures, the sub-dictionary can provide the signature
+ * of each value in the outer dictionary. This allows forcing
+ * integers to unsigned or whatever.
+ *
+ * _dbus_signatures has a weird name to avoid conflicting with
+ * real properties. Matches _dbus_sender which is used elsewhere.
+ *
+ * We don't bother rooting the signature object or the stuff in it
+ * because we assume the outer dictionary is rooted so the stuff
+ * in it is also.
+ */
+ prop_signatures = seed_object_get_property(ctx, props, "_dbus_signatures");
+
+ if (!seed_value_is_undefined(ctx, prop_signatures)
+ && !seed_value_is_object(ctx, prop_signatures)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "_dbus_signatures prop must be an object");
+ return FALSE;
}
- if (!seed_value_is_undefined (ctx, prop_signatures) &&
- dbus_signature_iter_get_current_type (&dict_value_sig_iter) !=
- DBUS_TYPE_VARIANT)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Specifying _dbus_signatures for a dictionary with non-variant values is
useless");
- return FALSE;
+ if (!seed_value_is_undefined(ctx, prop_signatures)
+ && dbus_signature_iter_get_current_type(&dict_value_sig_iter)
+ != DBUS_TYPE_VARIANT) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Specifying _dbus_signatures for a "
+ "dictionary with non-variant values "
+ "is useless");
+ return FALSE;
}
- prop_names = seed_object_copy_property_names (ctx, props);
- num_props = g_strv_length (prop_names);
-
- for (i = 0; i < num_props; i++)
- {
- char *name;
- SeedValue propval;
- DBusMessageIter entry_iter;
- const char *value_signature;
-
- name = prop_names[i];
-
- if (strcmp (name, "_dbus_signatures") == 0)
- {
- /* skip the magic "_dbus_signatures" field */
- goto next;
- }
-
- /* see if this prop has a forced signature */
- value_signature = NULL;
- if (!seed_value_is_undefined (ctx, prop_signatures))
- {
- SeedValue signature_value;
-
- signature_value = seed_object_get_property (ctx, prop_signatures, name);
- if (!seed_value_is_undefined (ctx, signature_value))
- {
- value_signature = seed_value_to_string (ctx, signature_value, exception);
- if (value_signature == NULL)
- {
- return FALSE;
- }
- }
- }
-
- // if (!gjs_object_require_property
- // (ctx, props, "DBus append_dict", name, &propval))
- //return FALSE;
- propval = seed_object_get_property (ctx, props, name);
-
- SEED_NOTE(MODULE, " Adding property %s", name);
-
- /* seed_js_one_value_to_dbus() would check this also, but would not
- * print the property name, which is often useful
- */
- if (seed_value_is_null (ctx, propval))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Property '%s' has a null value, can't send over dbus",
- name);
- return FALSE;
- }
-
- dbus_message_iter_open_container (&dict_iter, DBUS_TYPE_DICT_ENTRY,
- NULL, &entry_iter);
-
- dbus_message_iter_append_basic (&entry_iter, DBUS_TYPE_STRING, &name);
- g_free (name);
-
- if (value_signature != NULL)
- {
- DBusSignatureIter forced_signature_iter;
- DBusMessageIter variant_iter;
-
- g_assert (dbus_signature_iter_get_current_type
- (&dict_value_sig_iter) == DBUS_TYPE_VARIANT);
-
- dbus_message_iter_open_container (&entry_iter,
- DBUS_TYPE_VARIANT,
- value_signature, &variant_iter);
-
- dbus_signature_iter_init (&forced_signature_iter, value_signature);
-
- if (!seed_js_one_value_to_dbus (ctx, propval, &variant_iter,
- &forced_signature_iter, exception))
+ prop_names = seed_object_copy_property_names(ctx, props);
+ num_props = g_strv_length(prop_names);
+
+ for (i = 0; i < num_props; i++) {
+ char* name;
+ SeedValue propval;
+ DBusMessageIter entry_iter;
+ const char* value_signature;
+
+ name = prop_names[i];
+
+ if (strcmp(name, "_dbus_signatures") == 0) {
+ /* skip the magic "_dbus_signatures" field */
+ goto next;
+ }
+
+ /* see if this prop has a forced signature */
+ value_signature = NULL;
+ if (!seed_value_is_undefined(ctx, prop_signatures)) {
+ SeedValue signature_value;
+
+ signature_value
+ = seed_object_get_property(ctx, prop_signatures, name);
+ if (!seed_value_is_undefined(ctx, signature_value)) {
+ value_signature
+ = seed_value_to_string(ctx, signature_value, exception);
+ if (value_signature == NULL) {
+ return FALSE;
+ }
+ }
+ }
+
+ // if (!gjs_object_require_property
+ // (ctx, props, "DBus append_dict", name, &propval))
+ // return FALSE;
+ propval = seed_object_get_property(ctx, props, name);
+
+ SEED_NOTE(MODULE, " Adding property %s", name);
+
+ /* seed_js_one_value_to_dbus() would check this also, but would not
+ * print the property name, which is often useful
+ */
+ if (seed_value_is_null(ctx, propval)) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Property '%s' has a null value, can't send over dbus", name);
return FALSE;
+ }
- dbus_message_iter_close_container (&entry_iter, &variant_iter);
- }
- else
- {
- if (!seed_js_one_value_to_dbus (ctx, propval, &entry_iter,
- &dict_value_sig_iter, exception))
- return FALSE;
- }
+ dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_DICT_ENTRY, NULL,
+ &entry_iter);
+
+ dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_STRING, &name);
+ g_free(name);
+
+ if (value_signature != NULL) {
+ DBusSignatureIter forced_signature_iter;
+ DBusMessageIter variant_iter;
+
+ g_assert(dbus_signature_iter_get_current_type(&dict_value_sig_iter)
+ == DBUS_TYPE_VARIANT);
+
+ dbus_message_iter_open_container(&entry_iter, DBUS_TYPE_VARIANT,
+ value_signature, &variant_iter);
- dbus_message_iter_close_container (&dict_iter, &entry_iter);
+ dbus_signature_iter_init(&forced_signature_iter, value_signature);
+
+ if (!seed_js_one_value_to_dbus(ctx, propval, &variant_iter,
+ &forced_signature_iter, exception))
+ return FALSE;
+
+ dbus_message_iter_close_container(&entry_iter, &variant_iter);
+ } else {
+ if (!seed_js_one_value_to_dbus(ctx, propval, &entry_iter,
+ &dict_value_sig_iter, exception))
+ return FALSE;
+ }
+
+ dbus_message_iter_close_container(&dict_iter, &entry_iter);
next:
- continue;
+ continue;
}
- g_strfreev (prop_names);
+ g_strfreev(prop_names);
- dbus_message_iter_close_container (iter, &dict_iter);
+ dbus_message_iter_close_container(iter, &dict_iter);
- return TRUE;
+ return TRUE;
}
gboolean
-seed_js_one_value_to_dbus (SeedContext ctx,
- SeedValue value,
- DBusMessageIter * iter,
- DBusSignatureIter * sig_iter,
- SeedException *exception)
+seed_js_one_value_to_dbus(SeedContext ctx,
+ SeedValue value,
+ DBusMessageIter* iter,
+ DBusSignatureIter* sig_iter,
+ SeedException* exception)
{
- SeedType type;
- int forced_type;
+ SeedType type;
+ int forced_type;
- forced_type = dbus_signature_iter_get_current_type (sig_iter);
+ forced_type = dbus_signature_iter_get_current_type(sig_iter);
- SEED_NOTE(MODULE,
- "Converting dbus type '%c' from SeedValue",
- forced_type != DBUS_TYPE_INVALID ? forced_type : '0');
+ SEED_NOTE(MODULE, "Converting dbus type '%c' from SeedValue",
+ forced_type != DBUS_TYPE_INVALID ? forced_type : '0');
- /* Don't write anything on the bus if the signature is empty */
- if (forced_type == DBUS_TYPE_INVALID)
- return TRUE;
+ /* Don't write anything on the bus if the signature is empty */
+ if (forced_type == DBUS_TYPE_INVALID)
+ return TRUE;
- type = seed_value_get_type (ctx, value);
+ type = seed_value_get_type(ctx, value);
- if (seed_value_is_null (ctx, value))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "Can't send null values over dbus");
- return FALSE;
- }
- else if (type == SEED_TYPE_STRING)
- {
- char *data;
- gsize len;
- char buf[3] = { '\0', '\0', '\0' };
- if (forced_type == DBUS_TYPE_ARRAY)
- {
- buf[0] = DBUS_TYPE_ARRAY;
- buf[1] = dbus_signature_iter_get_element_type (sig_iter);
- }
- else
- {
- buf[0] = forced_type;
- }
-
- data = NULL;
- len = 0;
- // FIX?
- if (buf[1] == DBUS_TYPE_BYTE)
- {
- data = seed_value_to_string (ctx, value, exception);
- len = strlen (data);
- // if (!gjs_string_get_binary_data (ctx, value, &data, &len))
- //return FALSE;
- }
- else
- {
- data = seed_value_to_string (ctx, value, exception);
- len = strlen (data);
- }
-
- if (!append_string (ctx, iter, buf, data, len, exception))
- {
- g_free (data);
- return FALSE;
- }
-
- g_free (data);
- }
- /* else if (type == SEED_TYPE_NUMBER)
- {
- dbus_int32_t v_INT32;
- v_INT32 = seed_value_to_int (ctx, value, exception);
-
- if (!append_int32 (ctx, iter, forced_type, v_INT32, exception))
- return FALSE;
- }*/
- else if (type == SEED_TYPE_NUMBER)
- {
- double v_DOUBLE;
- v_DOUBLE = seed_value_to_double (ctx, value, exception);
-
- if (!append_double (ctx, iter, forced_type, v_DOUBLE, exception))
+ if (seed_value_is_null(ctx, value)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Can't send null values over dbus");
return FALSE;
+ } else if (type == SEED_TYPE_STRING) {
+ char* data;
+ gsize len;
+ char buf[3] = { '\0', '\0', '\0' };
+ if (forced_type == DBUS_TYPE_ARRAY) {
+ buf[0] = DBUS_TYPE_ARRAY;
+ buf[1] = dbus_signature_iter_get_element_type(sig_iter);
+ } else {
+ buf[0] = forced_type;
+ }
+
+ data = NULL;
+ len = 0;
+ // FIX?
+ if (buf[1] == DBUS_TYPE_BYTE) {
+ data = seed_value_to_string(ctx, value, exception);
+ len = strlen(data);
+ // if (!gjs_string_get_binary_data (ctx, value, &data, &len))
+ // return FALSE;
+ } else {
+ data = seed_value_to_string(ctx, value, exception);
+ len = strlen(data);
+ }
+
+ if (!append_string(ctx, iter, buf, data, len, exception)) {
+ g_free(data);
+ return FALSE;
+ }
+
+ g_free(data);
}
- else if (type == SEED_TYPE_BOOLEAN)
- {
- dbus_bool_t v_BOOLEAN;
- v_BOOLEAN = seed_value_to_boolean (ctx, value, exception);
+ /* else if (type == SEED_TYPE_NUMBER)
+ {
+ dbus_int32_t v_INT32;
+ v_INT32 = seed_value_to_int (ctx, value, exception);
- if (!append_boolean (ctx, iter, forced_type, v_BOOLEAN, exception))
+ if (!append_int32 (ctx, iter, forced_type, v_INT32, exception))
return FALSE;
- }
- else if (type == SEED_TYPE_OBJECT)
- {
- SeedValue lengthval;
+ }*/
+ else if (type == SEED_TYPE_NUMBER) {
+ double v_DOUBLE;
+ v_DOUBLE = seed_value_to_double(ctx, value, exception);
- /* see if there's a length property */
- lengthval = seed_object_get_property (ctx, value, "length");
+ if (!append_double(ctx, iter, forced_type, v_DOUBLE, exception))
+ return FALSE;
+ } else if (type == SEED_TYPE_BOOLEAN) {
+ dbus_bool_t v_BOOLEAN;
+ v_BOOLEAN = seed_value_to_boolean(ctx, value, exception);
- if (seed_value_get_type (ctx, lengthval) == SEED_TYPE_NUMBER)
- {
- guint length;
+ if (!append_boolean(ctx, iter, forced_type, v_BOOLEAN, exception))
+ return FALSE;
+ } else if (type == SEED_TYPE_OBJECT) {
+ SeedValue lengthval;
- length = seed_value_to_int (ctx, lengthval, exception);
+ /* see if there's a length property */
+ lengthval = seed_object_get_property(ctx, value, "length");
- SEED_NOTE(MODULE,
- "Looks like an array length %u", length);
- if (!append_array (ctx, iter, sig_iter, value, length, exception))
- return FALSE;
- }
- else
- {
- SEED_NOTE(MODULE, "Looks like a dictionary");
- if (!append_dict (ctx, iter, sig_iter, value, exception))
- return FALSE;
- }
- }
- else if (type == SEED_TYPE_UNDEFINED)
- {
- SEED_NOTE (MODULE,
- "Can't send void (undefined) values over dbus");
- seed_make_exception (ctx, exception, "ArgumentError", "Can't send void (undefined) values over dbus");
- return FALSE;
- }
- else
- {
- SEED_NOTE (MODULE,
- "Don't know how to convert this jsval to dbus type");
- seed_make_exception (ctx, exception, "ArgumentError",
- "Don't know how to convert this jsval to dbus type");
- return FALSE;
+ if (seed_value_get_type(ctx, lengthval) == SEED_TYPE_NUMBER) {
+ guint length;
+
+ length = seed_value_to_int(ctx, lengthval, exception);
+
+ SEED_NOTE(MODULE, "Looks like an array length %u", length);
+ if (!append_array(ctx, iter, sig_iter, value, length, exception))
+ return FALSE;
+ } else {
+ SEED_NOTE(MODULE, "Looks like a dictionary");
+ if (!append_dict(ctx, iter, sig_iter, value, exception))
+ return FALSE;
+ }
+ } else if (type == SEED_TYPE_UNDEFINED) {
+ SEED_NOTE(MODULE, "Can't send void (undefined) values over dbus");
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Can't send void (undefined) values over dbus");
+ return FALSE;
+ } else {
+ SEED_NOTE(MODULE, "Don't know how to convert this jsval to dbus type");
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Don't know how to convert this jsval to dbus type");
+ return FALSE;
}
- return TRUE;
+ return TRUE;
}
gboolean
-seed_js_values_to_dbus (SeedContext ctx,
- int index,
- SeedObject values,
- DBusMessageIter * iter,
- DBusSignatureIter * sig_iter,
- SeedException *exception)
+seed_js_values_to_dbus(SeedContext ctx,
+ int index,
+ SeedObject values,
+ DBusMessageIter* iter,
+ DBusSignatureIter* sig_iter,
+ SeedException* exception)
{
- SeedValue value;
- guint length;
-
- length = seed_value_to_int (ctx,
- seed_object_get_property (ctx, values, "length"),
- exception);
- if (index > (int) length)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Index %d is bigger than array length %d", index,
- length);
- return FALSE;
+ SeedValue value;
+ guint length;
+
+ length
+ = seed_value_to_int(ctx, seed_object_get_property(ctx, values, "length"),
+ exception);
+ if (index > (int) length) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Index %d is bigger than array length %d", index,
+ length);
+ return FALSE;
}
- if (index == (int) length)
- return TRUE;
+ if (index == (int) length)
+ return TRUE;
- value = seed_object_get_property_at_index (ctx, values, index, exception);
+ value = seed_object_get_property_at_index(ctx, values, index, exception);
- if (!seed_js_one_value_to_dbus (ctx, value, iter, sig_iter, exception))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "Error marshalling js value to dbus");
- return FALSE;
+ if (!seed_js_one_value_to_dbus(ctx, value, iter, sig_iter, exception)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Error marshalling js value to dbus");
+ return FALSE;
}
- if (dbus_signature_iter_next (sig_iter))
- {
- return seed_js_values_to_dbus (ctx, index + 1, values, iter,
- sig_iter, exception);
+ if (dbus_signature_iter_next(sig_iter)) {
+ return seed_js_values_to_dbus(ctx, index + 1, values, iter, sig_iter,
+ exception);
}
- return TRUE;
+ return TRUE;
}
/* If jsval is an object, add properties from the DBusMessage such as the
* sender. If jsval is not an object, do nothing.
*/
gboolean
-seed_js_add_dbus_props (SeedContext ctx, DBusMessage * message, SeedValue value,
- SeedException *exception)
+seed_js_add_dbus_props(SeedContext ctx,
+ DBusMessage* message,
+ SeedValue value,
+ SeedException* exception)
{
- gchar *sender;
+ gchar* sender;
- if (seed_value_is_null (ctx, value) || !seed_value_is_object (ctx, value))
- return TRUE;
+ if (seed_value_is_null(ctx, value) || !seed_value_is_object(ctx, value))
+ return TRUE;
- sender = (gchar *)dbus_message_get_sender (message);
+ sender = (gchar*) dbus_message_get_sender(message);
- seed_object_set_property (ctx, value, "_dbus_sender",
- seed_value_from_string (ctx, sender, exception));
+ seed_object_set_property(ctx, value, "_dbus_sender",
+ seed_value_from_string(ctx, sender, exception));
- return TRUE;
+ return TRUE;
}
diff --git a/modules/dbus/dbus-values.h b/modules/dbus/dbus-values.h
index 2aa948f..4b94aac 100644
--- a/modules/dbus/dbus-values.h
+++ b/modules/dbus/dbus-values.h
@@ -12,31 +12,30 @@ G_BEGIN_DECLS
extern SeedContextGroup group;
-gboolean seed_js_values_from_dbus (SeedContext ctx,
- DBusMessageIter *iter,
- GArray **aray_p,
- SeedException *exception);
-gboolean seed_js_one_value_from_dbus (SeedContext ctx,
- DBusMessageIter *iter,
- SeedValue *value_p,
- SeedException *exception);
-gboolean seed_js_values_to_dbus (SeedContext ctx,
- int index,
- SeedObject values,
- DBusMessageIter *iter,
- DBusSignatureIter *sig_iter,
- SeedException *exception);
-gboolean seed_js_one_value_to_dbus (SeedContext ctx,
- SeedValue value,
- DBusMessageIter *iter,
- DBusSignatureIter *sig_iter,
- SeedException *exception);
-gboolean seed_js_add_dbus_props (SeedContext ctx,
- DBusMessage *message,
- SeedValue value,
- SeedException *exception);
-
+gboolean seed_js_values_from_dbus(SeedContext ctx,
+ DBusMessageIter* iter,
+ GArray** aray_p,
+ SeedException* exception);
+gboolean seed_js_one_value_from_dbus(SeedContext ctx,
+ DBusMessageIter* iter,
+ SeedValue* value_p,
+ SeedException* exception);
+gboolean seed_js_values_to_dbus(SeedContext ctx,
+ int index,
+ SeedObject values,
+ DBusMessageIter* iter,
+ DBusSignatureIter* sig_iter,
+ SeedException* exception);
+gboolean seed_js_one_value_to_dbus(SeedContext ctx,
+ SeedValue value,
+ DBusMessageIter* iter,
+ DBusSignatureIter* sig_iter,
+ SeedException* exception);
+gboolean seed_js_add_dbus_props(SeedContext ctx,
+ DBusMessage* message,
+ SeedValue value,
+ SeedException* exception);
G_END_DECLS
-#endif /* __SEED_JS_DBUS_VALUES_H__ */
+#endif /* __SEED_JS_DBUS_VALUES_H__ */
diff --git a/modules/dbus/module.c b/modules/dbus/module.c
index 57ccea0..30e8daf 100644
--- a/modules/dbus/module.c
+++ b/modules/dbus/module.c
@@ -24,7 +24,8 @@
#include "dbus-values.h"
#include "dbus-exports.h"
-#define DBUS_CONNECTION_FROM_TYPE(type) ((type) == DBUS_BUS_SESSION ? session_bus : system_bus)
+#define DBUS_CONNECTION_FROM_TYPE(type) \
+ ((type) == DBUS_BUS_SESSION ? session_bus : system_bus)
SeedContext ctx;
SeedContextGroup group;
@@ -34,790 +35,765 @@ SeedClass dbus_namespace_class;
SeedClass dbus_bus_class;
static gboolean session_bus_weakref_added = FALSE;
-static DBusConnection *session_bus = NULL;
+static DBusConnection* session_bus = NULL;
static gboolean system_bus_weakref_added = FALSE;
-static DBusConnection *system_bus = NULL;
+static DBusConnection* system_bus = NULL;
SeedObject bus_proto;
static DBusBusType
-get_bus_type_from_object (SeedContext ctx,
- SeedObject object, SeedException * exception)
+get_bus_type_from_object(SeedContext ctx,
+ SeedObject object,
+ SeedException* exception)
{
- SeedValue jsbus_type =
- seed_object_get_property (ctx, object, "_dbusBusType");
+ SeedValue jsbus_type
+ = seed_object_get_property(ctx, object, "_dbusBusType");
- return seed_value_to_int (ctx, jsbus_type, exception);
+ return seed_value_to_int(ctx, jsbus_type, exception);
}
static gboolean
-bus_check (SeedContext ctx, DBusBusType bus_type, SeedException * exception)
+bus_check(SeedContext ctx, DBusBusType bus_type, SeedException* exception)
{
- gboolean bus_weakref_added;
- DBusConnection **bus_connection;
+ gboolean bus_weakref_added;
+ DBusConnection** bus_connection;
- bus_weakref_added =
- bus_type ==
- DBUS_BUS_SESSION ? session_bus_weakref_added : system_bus_weakref_added;
+ bus_weakref_added = bus_type == DBUS_BUS_SESSION ? session_bus_weakref_added
+ : system_bus_weakref_added;
- bus_connection = bus_type == DBUS_BUS_SESSION ? &session_bus : &system_bus;
+ bus_connection = bus_type == DBUS_BUS_SESSION ? &session_bus : &system_bus;
- /* This is all done lazily only if a dbus-related method is actually invoked */
+ /* This is all done lazily only if a dbus-related method is actually invoked
+ */
- if (!bus_weakref_added)
- {
- big_dbus_add_bus_weakref (bus_type, bus_connection);
+ if (!bus_weakref_added) {
+ big_dbus_add_bus_weakref(bus_type, bus_connection);
}
- if (*bus_connection == NULL)
- big_dbus_try_connecting_now (bus_type); /* force a synchronous connection attempt */
-
- /* Throw exception if connection attempt failed */
- if (*bus_connection == NULL)
- {
- const char *bus_type_name =
- bus_type == DBUS_BUS_SESSION ? "session" : "system";
- seed_make_exception (ctx, exception, "BusError",
- "Not connected to %s message bus", bus_type_name);
- return FALSE;
+ if (*bus_connection == NULL)
+ big_dbus_try_connecting_now(
+ bus_type); /* force a synchronous connection attempt */
+
+ /* Throw exception if connection attempt failed */
+ if (*bus_connection == NULL) {
+ const char* bus_type_name
+ = bus_type == DBUS_BUS_SESSION ? "session" : "system";
+ seed_make_exception(ctx, exception, "BusError",
+ "Not connected to %s message bus", bus_type_name);
+ return FALSE;
}
- return TRUE;
+ return TRUE;
}
-static DBusMessage *
-prepare_call (SeedContext ctx,
- SeedObject obj,
- SeedObject arg_array,
- guint argc,
- const SeedValue * argv,
- DBusBusType bus_type,
- SeedException * exception)
+static DBusMessage*
+prepare_call(SeedContext ctx,
+ SeedObject obj,
+ SeedObject arg_array,
+ guint argc,
+ const SeedValue* argv,
+ DBusBusType bus_type,
+ SeedException* exception)
{
- DBusMessage *message;
- const char *bus_name;
- const char *path;
- const char *interface;
- const char *method;
- gboolean auto_start;
- const char *out_signature;
- const char *in_signature;
- DBusMessageIter arg_iter;
- DBusSignatureIter sig_iter;
-
- if (!bus_check (ctx, bus_type, exception))
- return NULL;
-
- bus_name = seed_value_to_string (ctx, argv[0], exception);
- if (bus_name == NULL)
- return NULL;
-
- path = seed_value_to_string (ctx, argv[1], exception);
- if (path == NULL)
- return NULL;
-
- if (seed_value_is_null (ctx, argv[2]))
- {
- interface = NULL;
- }
- else
- {
- interface = seed_value_to_string (ctx, argv[2], exception);
- if (interface == NULL)
- return NULL; /* exception was set */
+ DBusMessage* message;
+ const char* bus_name;
+ const char* path;
+ const char* interface;
+ const char* method;
+ gboolean auto_start;
+ const char* out_signature;
+ const char* in_signature;
+ DBusMessageIter arg_iter;
+ DBusSignatureIter sig_iter;
+
+ if (!bus_check(ctx, bus_type, exception))
+ return NULL;
+
+ bus_name = seed_value_to_string(ctx, argv[0], exception);
+ if (bus_name == NULL)
+ return NULL;
+
+ path = seed_value_to_string(ctx, argv[1], exception);
+ if (path == NULL)
+ return NULL;
+
+ if (seed_value_is_null(ctx, argv[2])) {
+ interface = NULL;
+ } else {
+ interface = seed_value_to_string(ctx, argv[2], exception);
+ if (interface == NULL)
+ return NULL; /* exception was set */
}
- method = seed_value_to_string (ctx, argv[3], exception);
- if (method == NULL)
- return NULL;
+ method = seed_value_to_string(ctx, argv[3], exception);
+ if (method == NULL)
+ return NULL;
- out_signature = seed_value_to_string (ctx, argv[4], exception);
- if (out_signature == NULL)
- return NULL;
+ out_signature = seed_value_to_string(ctx, argv[4], exception);
+ if (out_signature == NULL)
+ return NULL;
- in_signature = seed_value_to_string (ctx, argv[5], exception);
- if (in_signature == NULL)
- return NULL;
+ in_signature = seed_value_to_string(ctx, argv[5], exception);
+ if (in_signature == NULL)
+ return NULL;
- g_assert (bus_name && path && method && in_signature && out_signature);
+ g_assert(bus_name && path && method && in_signature && out_signature);
- auto_start = seed_value_to_boolean (ctx, argv[6], exception);
+ auto_start = seed_value_to_boolean(ctx, argv[6], exception);
- /* FIXME should validate the bus_name, path, interface, method really, but
- * we should just not write buggy JS ;-)
- */
- message = dbus_message_new_method_call (bus_name, path, interface, method);
- if (message == NULL)
- {
- seed_make_exception (ctx, exception, "DBusError",
- "Could not create new method call. (OOM?)");
- return NULL;
+ /* FIXME should validate the bus_name, path, interface, method really, but
+ * we should just not write buggy JS ;-)
+ */
+ message = dbus_message_new_method_call(bus_name, path, interface, method);
+ if (message == NULL) {
+ seed_make_exception(ctx, exception, "DBusError",
+ "Could not create new method call. (OOM?)");
+ return NULL;
}
- dbus_message_set_auto_start (message, auto_start);
+ dbus_message_set_auto_start(message, auto_start);
- dbus_message_iter_init_append (message, &arg_iter);
+ dbus_message_iter_init_append(message, &arg_iter);
- if (in_signature)
- dbus_signature_iter_init (&sig_iter, in_signature);
- else
- dbus_signature_iter_init (&sig_iter, "a{sv}");
+ if (in_signature)
+ dbus_signature_iter_init(&sig_iter, in_signature);
+ else
+ dbus_signature_iter_init(&sig_iter, "a{sv}");
- if (!seed_js_values_to_dbus
- (ctx, 0, arg_array, &arg_iter, &sig_iter, exception))
- {
- SEED_NOTE(MODULE, "Failed to marshal call from JS to dbus");
- dbus_message_unref (message);
- return NULL;
+ if (!seed_js_values_to_dbus(ctx, 0, arg_array, &arg_iter, &sig_iter,
+ exception)) {
+ SEED_NOTE(MODULE, "Failed to marshal call from JS to dbus");
+ dbus_message_unref(message);
+ return NULL;
}
- return message;
+ return message;
}
static gboolean
-complete_call (SeedContext ctx,
- SeedValue * retval,
- DBusMessage * reply,
- DBusError * derror, SeedException * exception)
+complete_call(SeedContext ctx,
+ SeedValue* retval,
+ DBusMessage* reply,
+ DBusError* derror,
+ SeedException* exception)
{
- DBusMessageIter arg_iter;
- GArray *ret_values;
- int array_length;
-
- if (dbus_error_is_set (derror))
- {
- SEED_NOTE(MODULE,
- "Error sending call: %s: %s",
- derror->name, derror->message);
- seed_make_exception (ctx, exception, "DBusError",
- "DBus error: %s: %s",
- derror->name, derror->message);
- dbus_error_free (derror);
- return FALSE;
- }
-
- if (reply == NULL)
- {
- SEED_NOTE(MODULE,
- "No reply received to call");
- return FALSE;
+ DBusMessageIter arg_iter;
+ GArray* ret_values;
+ int array_length;
+
+ if (dbus_error_is_set(derror)) {
+ SEED_NOTE(MODULE, "Error sending call: %s: %s", derror->name,
+ derror->message);
+ seed_make_exception(ctx, exception, "DBusError", "DBus error: %s: %s",
+ derror->name, derror->message);
+ dbus_error_free(derror);
+ return FALSE;
}
- if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
- {
- dbus_set_error_from_message (derror, reply);
- seed_make_exception (ctx, exception, "DBusError",
- "DBus error: %s: %s",
- derror->name, derror->message);
- SEED_NOTE(MODULE, "DBus error: %s: %s",
- derror->name, derror->message);
- dbus_error_free (derror);
-
- return FALSE;
+ if (reply == NULL) {
+ SEED_NOTE(MODULE, "No reply received to call");
+ return FALSE;
}
- dbus_message_iter_init (reply, &arg_iter);
+ if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
+ dbus_set_error_from_message(derror, reply);
+ seed_make_exception(ctx, exception, "DBusError", "DBus error: %s: %s",
+ derror->name, derror->message);
+ SEED_NOTE(MODULE, "DBus error: %s: %s", derror->name, derror->message);
+ dbus_error_free(derror);
- if (!seed_js_values_from_dbus (ctx, &arg_iter, &ret_values, exception))
- {
- SEED_NOTE(MODULE, "Failed to marshal dbus call reply back to JS");
- return FALSE;
+ return FALSE;
}
- g_assert (ret_values != NULL);
- // TODO: I AM HERE
+ dbus_message_iter_init(reply, &arg_iter);
- array_length = ret_values->len;
- if (array_length == 1)
- {
- /* If the array only has one element return that element alone */
- *retval = g_array_index (ret_values, SeedValue, 0);
+ if (!seed_js_values_from_dbus(ctx, &arg_iter, &ret_values, exception)) {
+ SEED_NOTE(MODULE, "Failed to marshal dbus call reply back to JS");
+ return FALSE;
}
- else
- {
- /* Otherwise return an array with all the return values. The
- * funny assignment is to avoid creating a temporary JSObject
- * we'd need to root
- */
- *retval =
- seed_make_array (ctx, ret_values->data, array_length, exception);
+
+ g_assert(ret_values != NULL);
+ // TODO: I AM HERE
+
+ array_length = ret_values->len;
+ if (array_length == 1) {
+ /* If the array only has one element return that element alone */
+ *retval = g_array_index(ret_values, SeedValue, 0);
+ } else {
+ /* Otherwise return an array with all the return values. The
+ * funny assignment is to avoid creating a temporary JSObject
+ * we'd need to root
+ */
+ *retval
+ = seed_make_array(ctx, ret_values->data, array_length, exception);
}
- g_array_free (ret_values, TRUE);
+ g_array_free(ret_values, TRUE);
- seed_js_add_dbus_props (ctx, reply, *retval, exception);
+ seed_js_add_dbus_props(ctx, reply, *retval, exception);
- return TRUE;
+ return TRUE;
}
static void
-pending_notify (DBusPendingCall * pending, void *user_data)
+pending_notify(DBusPendingCall* pending, void* user_data)
{
- SeedException exception = NULL;
- GClosure *closure;
- SeedValue argv[2];
- DBusMessage *reply;
- DBusError derror;
+ SeedException exception = NULL;
+ GClosure* closure;
+ SeedValue argv[2];
+ DBusMessage* reply;
+ DBusError derror;
- closure = user_data;
+ closure = user_data;
- SEED_NOTE(MODULE,
- "Notified of reply to async call closure %p",
- closure);
+ SEED_NOTE(MODULE, "Notified of reply to async call closure %p", closure);
- if (closure == NULL) {
+ if (closure == NULL) {
SEED_NOTE(MODULE,
- "Closure destroyed before we could complete pending call");
- return;
+ "Closure destroyed before we could complete pending call");
+ return;
}
- /* reply may be NULL if none received? I think it may never be if
- * we've already been notified, but be safe here.
- */
+ /* reply may be NULL if none received? I think it may never be if
+ * we've already been notified, but be safe here.
+ */
-
- reply = dbus_pending_call_steal_reply (pending);
+ reply = dbus_pending_call_steal_reply(pending);
- dbus_error_init (&derror);
- /* argv[0] will be the return value if any, argv[1] we fill with exception if any */
- argv[0] = seed_make_null (ctx);
- argv[1] = seed_make_null (ctx);
- if (!complete_call (ctx, &argv[0], reply, &derror, &exception))
- goto noreply;
- g_assert (!dbus_error_is_set (&derror)); /* not supposed to be left set by complete_call() */
+ dbus_error_init(&derror);
+ /* argv[0] will be the return value if any, argv[1] we fill with exception
+ * if any */
+ argv[0] = seed_make_null(ctx);
+ argv[1] = seed_make_null(ctx);
+ if (!complete_call(ctx, &argv[0], reply, &derror, &exception))
+ goto noreply;
+ g_assert(!dbus_error_is_set(
+ &derror)); /* not supposed to be left set by complete_call() */
- if (reply)
- dbus_message_unref (reply);
+ if (reply)
+ dbus_message_unref(reply);
- if (exception)
- argv[1] = exception;
- seed_closure_invoke(closure, &argv[0], 2, &exception);
- if (exception && seed_value_is_object (ctx, exception))
- seed_closure_warn_exception(closure, ctx, exception);
- seed_context_unref (ctx);
- // TODO: Do something with exception
+ if (exception)
+ argv[1] = exception;
+ seed_closure_invoke(closure, &argv[0], 2, &exception);
+ if (exception && seed_value_is_object(ctx, exception))
+ seed_closure_warn_exception(closure, ctx, exception);
+ seed_context_unref(ctx);
+ // TODO: Do something with exception
- return;
+ return;
noreply:
- SEED_NOTE(MODULE,
- "No reply recieved from complete_call");
- if (reply)
- dbus_message_unref (reply);
- seed_context_unref (ctx);
+ SEED_NOTE(MODULE, "No reply recieved from complete_call");
+ if (reply)
+ dbus_message_unref(reply);
+ seed_context_unref(ctx);
}
static void
-pending_free_closure (void *data)
+pending_free_closure(void* data)
{
- GClosure *closure = data;
+ GClosure* closure = data;
- g_closure_invalidate (closure);
- g_closure_unref (closure);
+ g_closure_invalidate(closure);
+ g_closure_unref(closure);
}
-
static SeedValue
-seed_js_dbus_call_async (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_js_dbus_call_async(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GClosure *closure;
- DBusMessage *message;
- DBusPendingCall *pending;
- DBusConnection *bus_connection;
- DBusBusType bus_type;
- int timeout;
-
- if (argument_count < 10)
- {
- seed_make_exception (ctx, exception, "ArgmuentError",
- "Not enough args, need bus name, object path, interface, method, out signature, in
signature, autostart flag, timeout limit, args, and callback");
- return seed_make_null (ctx);
+ GClosure* closure;
+ DBusMessage* message;
+ DBusPendingCall* pending;
+ DBusConnection* bus_connection;
+ DBusBusType bus_type;
+ int timeout;
+
+ if (argument_count < 10) {
+ seed_make_exception(ctx, exception, "ArgmuentError",
+ "Not enough args, need bus name, "
+ "object path, interface, method, "
+ "out signature, in signature, "
+ "autostart flag, timeout limit, "
+ "args, and callback");
+ return seed_make_null(ctx);
}
- if (!seed_value_is_object (ctx, arguments[9])
- || !seed_value_is_function (ctx, arguments[9]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "arg 10 must be a callback to invoke when call completes");
- return FALSE;
+ if (!seed_value_is_object(ctx, arguments[9])
+ || !seed_value_is_function(ctx, arguments[9])) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "arg 10 must be a callback to invoke when call completes");
+ return FALSE;
}
- timeout = seed_value_to_int (ctx, arguments[7], exception);
+ timeout = seed_value_to_int(ctx, arguments[7], exception);
- bus_type = get_bus_type_from_object (ctx, this_object, exception);
+ bus_type = get_bus_type_from_object(ctx, this_object, exception);
- message =
- prepare_call (ctx, this_object, arguments[8], argument_count, arguments, bus_type,
- exception);
+ message = prepare_call(ctx, this_object, arguments[8], argument_count,
+ arguments, bus_type, exception);
- if (message == NULL)
- return seed_make_null (ctx);
+ if (message == NULL)
+ return seed_make_null(ctx);
- bus_connection = DBUS_CONNECTION_FROM_TYPE (bus_type);
+ bus_connection = DBUS_CONNECTION_FROM_TYPE(bus_type);
- pending = NULL;
- if (!dbus_connection_send_with_reply
- (bus_connection, message, &pending, timeout) || pending == NULL)
- {
- SEED_NOTE(MODULE, "Failed to send async dbus message");
- seed_make_exception (ctx, exception, "DBusError",
- "Failed to send dbus message");
- dbus_message_unref (message);
- return seed_make_null (ctx);
+ pending = NULL;
+ if (!dbus_connection_send_with_reply(bus_connection, message, &pending,
+ timeout)
+ || pending == NULL) {
+ SEED_NOTE(MODULE, "Failed to send async dbus message");
+ seed_make_exception(ctx, exception, "DBusError",
+ "Failed to send dbus message");
+ dbus_message_unref(message);
+ return seed_make_null(ctx);
}
- g_assert (pending != NULL);
+ g_assert(pending != NULL);
- dbus_message_unref (message);
+ dbus_message_unref(message);
- /* We cheat a bit here and use a closure to store a JavaScript function
- * and deal with the GC root and other issues, even though we
- * won't ever marshal via GValue
- */
- closure = seed_closure_new (ctx, arguments[9], NULL, "async DBus reply");
- if (closure == NULL)
- {
- dbus_pending_call_unref (pending);
- return seed_make_null (ctx);
+ /* We cheat a bit here and use a closure to store a JavaScript function
+ * and deal with the GC root and other issues, even though we
+ * won't ever marshal via GValue
+ */
+ closure = seed_closure_new(ctx, arguments[9], NULL, "async DBus reply");
+ if (closure == NULL) {
+ dbus_pending_call_unref(pending);
+ return seed_make_null(ctx);
}
- g_closure_ref (closure);
- g_closure_sink (closure);
- dbus_pending_call_set_notify (pending, pending_notify, closure,
- pending_free_closure);
+ g_closure_ref(closure);
+ g_closure_sink(closure);
+ dbus_pending_call_set_notify(pending, pending_notify, closure,
+ pending_free_closure);
- dbus_pending_call_unref (pending); /* DBusConnection should still hold a ref until it's completed */
+ dbus_pending_call_unref(
+ pending); /* DBusConnection should still hold a ref until it's completed
+ */
- return seed_value_from_boolean (ctx, TRUE, exception);
+ return seed_value_from_boolean(ctx, TRUE, exception);
}
-
-
static SeedValue
-seed_js_dbus_get_machine_id (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException * exception)
+seed_js_dbus_get_machine_id(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- SeedValue ret;
- gchar *id;
+ SeedValue ret;
+ gchar* id;
- id = dbus_get_local_machine_id ();
- ret = seed_value_from_string (ctx, id, exception);
- dbus_free (id);
+ id = dbus_get_local_machine_id();
+ ret = seed_value_from_string(ctx, id, exception);
+ dbus_free(id);
- return ret;
+ return ret;
}
static void
-fill_with_null_or_string (SeedContext ctx, const char **string_p,
- SeedValue value, SeedException * exception)
+fill_with_null_or_string(SeedContext ctx,
+ const char** string_p,
+ SeedValue value,
+ SeedException* exception)
{
- if (seed_value_is_null (ctx, value))
- *string_p = NULL;
- else
- *string_p = seed_value_to_string (ctx, value, exception);
+ if (seed_value_is_null(ctx, value))
+ *string_p = NULL;
+ else
+ *string_p = seed_value_to_string(ctx, value, exception);
}
typedef struct
{
- int refcount;
- DBusBusType bus_type;
- int connection_id;
- GClosure *closure;
+ int refcount;
+ DBusBusType bus_type;
+ int connection_id;
+ GClosure* closure;
} SignalHandler;
/* allow removal by passing in the callable
* FIXME don't think we ever end up using this,
* could get rid of it, it predates having an ID
* to remove by
*/
-static GHashTable *signal_handlers_by_callable = NULL;
+static GHashTable* signal_handlers_by_callable = NULL;
-static void signal_on_closure_invalidated (void *data, GClosure * closure);
-static void signal_handler_ref (SignalHandler * handler);
-static void signal_handler_unref (SignalHandler * handler);
+static void signal_on_closure_invalidated(void* data, GClosure* closure);
+static void signal_handler_ref(SignalHandler* handler);
+static void signal_handler_unref(SignalHandler* handler);
-static SignalHandler *
-signal_handler_new (SeedContext ctx,
- SeedValue callable, SeedException * exception)
+static SignalHandler*
+signal_handler_new(SeedContext ctx,
+ SeedValue callable,
+ SeedException* exception)
{
- SignalHandler *handler;
-
- if (signal_handlers_by_callable &&
- g_hash_table_lookup (signal_handlers_by_callable, callable) != NULL)
- {
- /* To fix this, get rid of signal_handlers_by_callable
- * and just require removal by id. Not sure we ever use
- * removal by callable anyway.
- */
- seed_make_exception (ctx, exception, "ArgumentError",
- "For now, same callback cannot be the handler for two dbus signal connections");
- return NULL;
+ SignalHandler* handler;
+
+ if (signal_handlers_by_callable
+ && g_hash_table_lookup(signal_handlers_by_callable, callable) != NULL) {
+ /* To fix this, get rid of signal_handlers_by_callable
+ * and just require removal by id. Not sure we ever use
+ * removal by callable anyway.
+ */
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "For now, same callback cannot be "
+ "the handler for two dbus signal "
+ "connections");
+ return NULL;
}
- handler = g_slice_new0 (SignalHandler);
- handler->refcount = 1;
-
- /* We cheat a bit here and use a closure to store a JavaScript function
- * and deal with the GC root and other issues, even though we
- * won't ever marshal via GValue
- */
- handler->closure = seed_closure_new (ctx, callable, NULL, "DBus signal handler");
- if (handler->closure == NULL)
- {
- g_free (handler);
- return NULL;
+ handler = g_slice_new0(SignalHandler);
+ handler->refcount = 1;
+
+ /* We cheat a bit here and use a closure to store a JavaScript function
+ * and deal with the GC root and other issues, even though we
+ * won't ever marshal via GValue
+ */
+ handler->closure
+ = seed_closure_new(ctx, callable, NULL, "DBus signal handler");
+ if (handler->closure == NULL) {
+ g_free(handler);
+ return NULL;
}
- g_closure_ref (handler->closure);
- g_closure_sink (handler->closure);
+ g_closure_ref(handler->closure);
+ g_closure_sink(handler->closure);
- g_closure_add_invalidate_notifier (handler->closure, handler,
- signal_on_closure_invalidated);
+ g_closure_add_invalidate_notifier(handler->closure, handler,
+ signal_on_closure_invalidated);
- if (!signal_handlers_by_callable)
- {
- signal_handlers_by_callable =
- g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL);
+ if (!signal_handlers_by_callable) {
+ signal_handlers_by_callable
+ = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
}
- /* We keep a weak reference on the closure in a table indexed
- * by the object, so we can retrieve it when removing the signal
- * watch. The signal_handlers_by_callable owns one ref to the SignalHandler.
- */
- signal_handler_ref (handler);
- g_hash_table_replace (signal_handlers_by_callable, callable, handler);
+ /* We keep a weak reference on the closure in a table indexed
+ * by the object, so we can retrieve it when removing the signal
+ * watch. The signal_handlers_by_callable owns one ref to the SignalHandler.
+ */
+ signal_handler_ref(handler);
+ g_hash_table_replace(signal_handlers_by_callable, callable, handler);
- return handler;
+ return handler;
}
static void
-signal_handler_ref (SignalHandler * handler)
+signal_handler_ref(SignalHandler* handler)
{
- g_assert (handler->refcount > 0);
- handler->refcount += 1;
+ g_assert(handler->refcount > 0);
+ handler->refcount += 1;
}
static void
-signal_handler_dispose (SignalHandler * handler)
+signal_handler_dispose(SignalHandler* handler)
{
- g_assert (handler->refcount > 0);
-
- signal_handler_ref (handler);
-
- if (handler->closure)
- {
- /* invalidating closure could dispose
- * re-entrantly, so set handler->closure
- * NULL before we invalidate
- */
- GClosure *closure = handler->closure;
- handler->closure = NULL;
-
- g_hash_table_remove (signal_handlers_by_callable,
- seed_closure_get_callable (closure));
- if (g_hash_table_size (signal_handlers_by_callable) == 0)
- {
- g_hash_table_destroy (signal_handlers_by_callable);
- signal_handlers_by_callable = NULL;
- }
- /* the hash table owned 1 ref */
- signal_handler_unref (handler);
-
- g_closure_invalidate (closure);
- g_closure_unref (closure);
+ g_assert(handler->refcount > 0);
+
+ signal_handler_ref(handler);
+
+ if (handler->closure) {
+ /* invalidating closure could dispose
+ * re-entrantly, so set handler->closure
+ * NULL before we invalidate
+ */
+ GClosure* closure = handler->closure;
+ handler->closure = NULL;
+
+ g_hash_table_remove(signal_handlers_by_callable,
+ seed_closure_get_callable(closure));
+ if (g_hash_table_size(signal_handlers_by_callable) == 0) {
+ g_hash_table_destroy(signal_handlers_by_callable);
+ signal_handlers_by_callable = NULL;
+ }
+ /* the hash table owned 1 ref */
+ signal_handler_unref(handler);
+
+ g_closure_invalidate(closure);
+ g_closure_unref(closure);
}
- /* remove signal if it hasn't been */
- if (handler->connection_id != 0)
- {
- int id = handler->connection_id;
- handler->connection_id = 0;
+ /* remove signal if it hasn't been */
+ if (handler->connection_id != 0) {
+ int id = handler->connection_id;
+ handler->connection_id = 0;
- /* this should clear another ref off the
- * handler by calling signal_on_watch_removed
- */
- big_dbus_unwatch_signal_by_id (handler->bus_type, id);
+ /* this should clear another ref off the
+ * handler by calling signal_on_watch_removed
+ */
+ big_dbus_unwatch_signal_by_id(handler->bus_type, id);
}
- signal_handler_unref (handler);
+ signal_handler_unref(handler);
}
static void
-signal_handler_unref (SignalHandler * handler)
+signal_handler_unref(SignalHandler* handler)
{
- g_assert (handler->refcount > 0);
+ g_assert(handler->refcount > 0);
- if (handler->refcount == 1)
- {
- signal_handler_dispose (handler);
+ if (handler->refcount == 1) {
+ signal_handler_dispose(handler);
}
- handler->refcount -= 1;
- if (handler->refcount == 0)
- {
- g_assert (handler->closure == NULL);
- g_assert (handler->connection_id == 0);
- g_slice_free (SignalHandler, handler);
+ handler->refcount -= 1;
+ if (handler->refcount == 0) {
+ g_assert(handler->closure == NULL);
+ g_assert(handler->connection_id == 0);
+ g_slice_free(SignalHandler, handler);
}
}
static void
-signal_on_watch_removed (void *data)
+signal_on_watch_removed(void* data)
{
- SignalHandler *handler = data;
+ SignalHandler* handler = data;
- handler->connection_id = 0; /* don't re-remove it */
+ handler->connection_id = 0; /* don't re-remove it */
- /* The watch owns a ref; removing it
- * also forces dispose, which invalidates
- * the closure if that hasn't been done.
- */
- signal_handler_dispose (handler);
- signal_handler_unref (handler);
+ /* The watch owns a ref; removing it
+ * also forces dispose, which invalidates
+ * the closure if that hasn't been done.
+ */
+ signal_handler_dispose(handler);
+ signal_handler_unref(handler);
}
static void
-signal_on_closure_invalidated (void *data, GClosure * closure)
+signal_on_closure_invalidated(void* data, GClosure* closure)
{
- SignalHandler *handler;
+ SignalHandler* handler;
- handler = data;
+ handler = data;
- /* this removes the watch if it has not been */
- signal_handler_dispose (handler);
+ /* this removes the watch if it has not been */
+ signal_handler_dispose(handler);
}
static void
-signal_handler_callback (DBusConnection * connection,
- DBusMessage * message, void *data)
+signal_handler_callback(DBusConnection* connection,
+ DBusMessage* message,
+ void* data)
{
- SeedContext ctx;
- SignalHandler *handler;
- DBusMessageIter arg_iter;
- GArray *arguments;
- SeedException exception;
+ SeedContext ctx;
+ SignalHandler* handler;
+ DBusMessageIter arg_iter;
+ GArray* arguments;
+ SeedException exception;
- SEED_NOTE(MODULE,
- "Signal handler called");
+ SEED_NOTE(MODULE, "Signal handler called");
- handler = data;
+ handler = data;
- if (handler->closure == NULL)
- {
- SEED_NOTE(MODULE, "dbus signal handler invalidated, ignoring");
- return;
+ if (handler->closure == NULL) {
+ SEED_NOTE(MODULE, "dbus signal handler invalidated, ignoring");
+ return;
}
- ctx = seed_context_create (group, NULL);
- seed_prepare_global_context (ctx);
+ ctx = seed_context_create(group, NULL);
+ seed_prepare_global_context(ctx);
- dbus_message_iter_init (message, &arg_iter);
- if (!seed_js_values_from_dbus (ctx, &arg_iter, &arguments, &exception))
- {
- SEED_NOTE(MODULE, "Failed to marshal dbus signal to JS");
- return;
+ dbus_message_iter_init(message, &arg_iter);
+ if (!seed_js_values_from_dbus(ctx, &arg_iter, &arguments, &exception)) {
+ SEED_NOTE(MODULE, "Failed to marshal dbus signal to JS");
+ return;
}
- signal_handler_ref (handler); /* for safety, in case handler removes itself */
+ signal_handler_ref(
+ handler); /* for safety, in case handler removes itself */
- g_assert (arguments != NULL);
+ g_assert(arguments != NULL);
- SEED_NOTE(MODULE,
- "Invoking closure on signal received, %d args",
- arguments->len);
- seed_closure_invoke_with_context (ctx, handler->closure,
- (SeedValue *) arguments->data,
- arguments->len, &exception);
+ SEED_NOTE(MODULE, "Invoking closure on signal received, %d args",
+ arguments->len);
+ seed_closure_invoke_with_context(ctx, handler->closure,
+ (SeedValue*) arguments->data,
+ arguments->len, &exception);
- g_array_free (arguments, TRUE);
+ g_array_free(arguments, TRUE);
- signal_handler_unref (handler); /* for safety */
+ signal_handler_unref(handler); /* for safety */
}
static SeedValue
-seed_js_dbus_watch_signal (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_js_dbus_watch_signal(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- const char *bus_name;
- const char *object_path;
- const char *iface;
- const char *signal;
- SignalHandler *handler;
- int id;
- DBusBusType bus_type;
-
- if (argument_count < 5)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Not enough args, need bus name, object path, interface, signal and callback");
- return seed_make_null (ctx);
+ const char* bus_name;
+ const char* object_path;
+ const char* iface;
+ const char* signal;
+ SignalHandler* handler;
+ int id;
+ DBusBusType bus_type;
+
+ if (argument_count < 5) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Not enough args, need bus name, "
+ "object path, interface, signal and "
+ "callback");
+ return seed_make_null(ctx);
}
- if (!seed_value_is_object (ctx, arguments[4])
- || !seed_value_is_function (ctx, arguments[4]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "arg 5 must be a callback to invoke when call completes");
- return seed_make_null (ctx);
+ if (!seed_value_is_object(ctx, arguments[4])
+ || !seed_value_is_function(ctx, arguments[4])) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "arg 5 must be a callback to invoke when call completes");
+ return seed_make_null(ctx);
}
- fill_with_null_or_string (ctx, &bus_name, arguments[0], exception);
- fill_with_null_or_string (ctx, &object_path, arguments[1], exception);
- fill_with_null_or_string (ctx, &iface, arguments[2], exception);
- fill_with_null_or_string (ctx, &signal, arguments[3], exception);
+ fill_with_null_or_string(ctx, &bus_name, arguments[0], exception);
+ fill_with_null_or_string(ctx, &object_path, arguments[1], exception);
+ fill_with_null_or_string(ctx, &iface, arguments[2], exception);
+ fill_with_null_or_string(ctx, &signal, arguments[3], exception);
- bus_type = get_bus_type_from_object (ctx, this_object, exception);
+ bus_type = get_bus_type_from_object(ctx, this_object, exception);
- handler = signal_handler_new (ctx, arguments[4], exception);
- if (handler == NULL)
- return seed_make_null (ctx);
+ handler = signal_handler_new(ctx, arguments[4], exception);
+ if (handler == NULL)
+ return seed_make_null(ctx);
- id = big_dbus_watch_signal (bus_type,
- bus_name,
- object_path,
- iface,
- signal,
- signal_handler_callback,
- handler, signal_on_watch_removed);
- handler->bus_type = bus_type;
- handler->connection_id = id;
+ id = big_dbus_watch_signal(bus_type, bus_name, object_path, iface, signal,
+ signal_handler_callback, handler,
+ signal_on_watch_removed);
+ handler->bus_type = bus_type;
+ handler->connection_id = id;
- /* signal_on_watch_removed() takes ownership of our
- * ref to the SignalHandler
- */
+ /* signal_on_watch_removed() takes ownership of our
+ * ref to the SignalHandler
+ */
- return seed_value_from_int (ctx, id, exception);
+ return seed_value_from_int(ctx, id, exception);
}
/* Args are handler id */
static SeedValue
-seed_js_dbus_unwatch_signal_by_id (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_js_dbus_unwatch_signal_by_id(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- int id;
- DBusBusType bus_type;
-
- if (argument_count < 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Not enough args, need handler id");
- return seed_make_null (ctx);
+ int id;
+ DBusBusType bus_type;
+
+ if (argument_count < 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Not enough args, need handler id");
+ return seed_make_null(ctx);
}
- bus_type = get_bus_type_from_object (ctx, this_object, exception);
- id = seed_value_to_int (ctx, arguments[0], exception);
+ bus_type = get_bus_type_from_object(ctx, this_object, exception);
+ id = seed_value_to_int(ctx, arguments[0], exception);
- big_dbus_unwatch_signal_by_id (bus_type, id);
- return seed_make_undefined (ctx);
+ big_dbus_unwatch_signal_by_id(bus_type, id);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_js_dbus_unwatch_signal (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_js_dbus_unwatch_signal(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- const char *bus_name;
- const char *object_path;
- const char *iface;
- const char *signal;
- SignalHandler *handler;
- DBusBusType bus_type;
-
- if (argument_count < 5)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Not enough args, need bus name, object path, interface, signal and callback");
- return seed_make_null (ctx);
+ const char* bus_name;
+ const char* object_path;
+ const char* iface;
+ const char* signal;
+ SignalHandler* handler;
+ DBusBusType bus_type;
+
+ if (argument_count < 5) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Not enough args, need bus name, "
+ "object path, interface, signal and "
+ "callback");
+ return seed_make_null(ctx);
}
- bus_type = get_bus_type_from_object (ctx, this_object, exception);
+ bus_type = get_bus_type_from_object(ctx, this_object, exception);
- if (!seed_value_is_object (ctx, arguments[4])
- || !seed_value_is_function (ctx, arguments[4]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "arg 5 must be a callback to invoke when call completes");
- return seed_make_null (ctx);
+ if (!seed_value_is_object(ctx, arguments[4])
+ || !seed_value_is_function(ctx, arguments[4])) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "arg 5 must be a callback to invoke when call completes");
+ return seed_make_null(ctx);
}
- fill_with_null_or_string (ctx, &bus_name, arguments[0], exception);
- fill_with_null_or_string (ctx, &object_path, arguments[1], exception);
- fill_with_null_or_string (ctx, &iface, arguments[2], exception);
- fill_with_null_or_string (ctx, &signal, arguments[3], exception);
+ fill_with_null_or_string(ctx, &bus_name, arguments[0], exception);
+ fill_with_null_or_string(ctx, &object_path, arguments[1], exception);
+ fill_with_null_or_string(ctx, &iface, arguments[2], exception);
+ fill_with_null_or_string(ctx, &signal, arguments[3], exception);
- /* we don't complain if the signal seems to have been already removed
- * or to never have been watched, to match g_signal_handler_disconnect
- */
- if (!signal_handlers_by_callable)
- return seed_make_undefined (ctx);
+ /* we don't complain if the signal seems to have been already removed
+ * or to never have been watched, to match g_signal_handler_disconnect
+ */
+ if (!signal_handlers_by_callable)
+ return seed_make_undefined(ctx);
- handler = g_hash_table_lookup (signal_handlers_by_callable, arguments[4]);
+ handler = g_hash_table_lookup(signal_handlers_by_callable, arguments[4]);
- if (!handler)
- return seed_make_undefined (ctx);
+ if (!handler)
+ return seed_make_undefined(ctx);
- /* This should dispose the handler which should in turn
- * remove it from the handler table
- */
- big_dbus_unwatch_signal (bus_type,
- bus_name,
- object_path,
- iface, signal, signal_handler_callback, handler);
+ /* This should dispose the handler which should in turn
+ * remove it from the handler table
+ */
+ big_dbus_unwatch_signal(bus_type, bus_name, object_path, iface, signal,
+ signal_handler_callback, handler);
- g_assert (g_hash_table_lookup (signal_handlers_by_callable,
- arguments[4]) == NULL);
+ g_assert(g_hash_table_lookup(signal_handlers_by_callable, arguments[4])
+ == NULL);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
seed_js_dbus_emit_signal(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- DBusConnection *bus_connection;
- DBusMessage *message;
+ DBusConnection* bus_connection;
+ DBusMessage* message;
DBusMessageIter arg_iter;
DBusSignatureIter sig_iter;
- const char *object_path;
- const char *iface;
- const char *signal;
- const char *in_signature;
+ const char* object_path;
+ const char* iface;
+ const char* signal;
+ const char* in_signature;
DBusBusType bus_type;
- if (argument_count < 4)
- {
- seed_make_exception(ctx, exception, "ArgumentError", "Not enough args, need object path, interface and
signal and the arguments");
- return seed_make_null (ctx);
+ if (argument_count < 4) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Not enough args, need object path, "
+ "interface and signal and the "
+ "arguments");
+ return seed_make_null(ctx);
}
- if (!seed_value_is_object (ctx, arguments[4]))
- {
- seed_make_exception(ctx, exception, "ArgumentError", "5th argument should be an array of arguments");
- return seed_make_null (ctx);
- }
+ if (!seed_value_is_object(ctx, arguments[4])) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "5th argument should be an array of arguments");
+ return seed_make_null(ctx);
+ }
- bus_type = get_bus_type_from_object (ctx, this_object, exception);
+ bus_type = get_bus_type_from_object(ctx, this_object, exception);
object_path = seed_value_to_string(ctx, arguments[0], exception);
iface = seed_value_to_string(ctx, arguments[1], exception);
@@ -825,68 +801,66 @@ seed_js_dbus_emit_signal(SeedContext ctx,
in_signature = seed_value_to_string(ctx, arguments[3], exception);
if (!bus_check(ctx, bus_type, exception))
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
- SEED_NOTE(MODULE,
- "Emitting signal %s %s %s",
- object_path,
- iface,
- signal);
+ SEED_NOTE(MODULE, "Emitting signal %s %s %s", object_path, iface, signal);
bus_connection = DBUS_CONNECTION_FROM_TYPE(bus_type);
- message = dbus_message_new_signal(object_path,
- iface,
- signal);
+ message = dbus_message_new_signal(object_path, iface, signal);
dbus_message_iter_init_append(message, &arg_iter);
dbus_signature_iter_init(&sig_iter, in_signature);
- if (!seed_js_values_to_dbus(ctx, 0, arguments[4], &arg_iter, &sig_iter, exception))
- {
+ if (!seed_js_values_to_dbus(ctx, 0, arguments[4], &arg_iter, &sig_iter,
+ exception)) {
dbus_message_unref(message);
- return seed_make_null (ctx);
- }
+ return seed_make_null(ctx);
+ }
dbus_connection_send(bus_connection, message, NULL);
dbus_message_unref(message);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
seed_js_dbus_call(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- DBusMessage *message;
+ DBusMessage* message;
DBusError derror;
- DBusMessage *reply;
- DBusConnection *bus_connection;
+ DBusMessage* reply;
+ DBusConnection* bus_connection;
DBusBusType bus_type;
SeedValue retval = NULL;
- if (argument_count < 8)
- {
- seed_make_exception(ctx, exception, "ArgumentError",
- "Not enough args, need bus name, object path, interface, method, out signature,
in signature, autostart flag, and args");
- return seed_make_null (ctx);
- }
+ if (argument_count < 8) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Not enough args, need bus name, "
+ "object path, interface, method, "
+ "out signature, in signature, "
+ "autostart flag, and args");
+ return seed_make_null(ctx);
+ }
- bus_type = get_bus_type_from_object (ctx, this_object, exception);
+ bus_type = get_bus_type_from_object(ctx, this_object, exception);
- message = prepare_call(ctx, this_object, arguments[7], argument_count, arguments, bus_type, exception);
+ message = prepare_call(ctx, this_object, arguments[7], argument_count,
+ arguments, bus_type, exception);
bus_connection = DBUS_CONNECTION_FROM_TYPE(bus_type);
/* send_with_reply_and_block() returns NULL if error was set. */
dbus_error_init(&derror);
- reply = dbus_connection_send_with_reply_and_block(bus_connection, message, -1, &derror);
+ reply = dbus_connection_send_with_reply_and_block(bus_connection, message,
+ -1, &derror);
dbus_message_unref(message);
@@ -898,145 +872,137 @@ seed_js_dbus_call(SeedContext ctx,
return retval;
}
-typedef struct {
+typedef struct
+{
BigDBusNameOwnerFuncs funcs;
- GClosure *acquired_closure;
- GClosure *lost_closure;
+ GClosure* acquired_closure;
+ GClosure* lost_closure;
DBusBusType bus_type;
} BigJSDBusNameOwner;
static void
-on_name_acquired(DBusConnection *connection,
- const char *name,
- void *data)
+on_name_acquired(DBusConnection* connection, const char* name, void* data)
{
int argc;
SeedValue argv[1];
SeedContext ctx;
- BigJSDBusNameOwner *owner;
+ BigJSDBusNameOwner* owner;
SeedException exception; // TODO: Do something with this...
owner = data;
- ctx = seed_context_create (group, NULL);
- seed_prepare_global_context (ctx);
- if (ctx == NULL)
- {
- SEED_NOTE(MODULE,
- "Closure destroyed before we could notify name acquired");
+ ctx = seed_context_create(group, NULL);
+ seed_prepare_global_context(ctx);
+ if (ctx == NULL) {
+ SEED_NOTE(MODULE,
+ "Closure destroyed before we could notify name acquired");
return;
- }
+ }
argc = 1;
- argv[0] = seed_value_from_string (ctx, name, &exception);
+ argv[0] = seed_value_from_string(ctx, name, &exception);
- seed_closure_invoke_with_context(ctx, owner->acquired_closure,
- argv, argc, &exception);
+ seed_closure_invoke_with_context(ctx, owner->acquired_closure, argv, argc,
+ &exception);
- seed_context_unref (ctx);
+ seed_context_unref(ctx);
}
-
static void
-on_name_lost(DBusConnection *connection,
- const char *name,
- void *data)
+on_name_lost(DBusConnection* connection, const char* name, void* data)
{
int argc;
SeedValue argv[1];
SeedContext ctx;
- BigJSDBusNameOwner *owner;
+ BigJSDBusNameOwner* owner;
SeedException exception; // TODO: Do something with this...
owner = data;
- ctx = seed_context_create (group, NULL);
- seed_prepare_global_context (ctx);
- if (ctx == NULL)
- {
- SEED_NOTE(MODULE,
- "Closure destroyed before we could notify name acquired");
+ ctx = seed_context_create(group, NULL);
+ seed_prepare_global_context(ctx);
+ if (ctx == NULL) {
+ SEED_NOTE(MODULE,
+ "Closure destroyed before we could notify name acquired");
return;
- }
+ }
argc = 1;
- argv[0] = seed_value_from_string (ctx, name, &exception);
+ argv[0] = seed_value_from_string(ctx, name, &exception);
- seed_closure_invoke_with_context(ctx, owner->lost_closure,
- argv, argc, &exception);
+ seed_closure_invoke_with_context(ctx, owner->lost_closure, argv, argc,
+ &exception);
- seed_context_unref (ctx);
+ seed_context_unref(ctx);
}
static void
-owner_closure_invalidated(gpointer data,
- GClosure *closure)
+owner_closure_invalidated(gpointer data, GClosure* closure)
{
- BigJSDBusNameOwner *owner;
+ BigJSDBusNameOwner* owner;
- owner = (BigJSDBusNameOwner*)data;
+ owner = (BigJSDBusNameOwner*) data;
if (owner) {
- big_dbus_release_name(owner->bus_type,
- &owner->funcs,
- owner);
+ big_dbus_release_name(owner->bus_type, &owner->funcs, owner);
g_closure_unref(owner->acquired_closure);
g_closure_unref(owner->lost_closure);
g_slice_free(BigJSDBusNameOwner, owner);
}
-
}
static SeedValue
seed_js_dbus_acquire_name(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- const char *bus_name;
+ const char* bus_name;
SeedObject acquire_func;
SeedObject lost_func;
- BigJSDBusNameOwner *owner;
+ BigJSDBusNameOwner* owner;
DBusBusType bus_type;
BigDBusNameType name_type;
unsigned int id;
- if (argument_count < 4)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Not enough args, need bus name, name type, acquired_func, lost_func");
- return seed_make_null (ctx);
- }
+ if (argument_count < 4) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Not enough args, need bus name, "
+ "name type, acquired_func, "
+ "lost_func");
+ return seed_make_null(ctx);
+ }
- bus_type = get_bus_type_from_object (ctx, this_object, exception);
+ bus_type = get_bus_type_from_object(ctx, this_object, exception);
- bus_name = seed_value_to_string (ctx, arguments[0], exception);
+ bus_name = seed_value_to_string(ctx, arguments[0], exception);
- name_type = (BigDBusNameType)seed_value_to_int (ctx, arguments[1], exception);
+ name_type
+ = (BigDBusNameType) seed_value_to_int(ctx, arguments[1], exception);
- if (!seed_value_is_object (ctx, arguments[2]) ||
- !seed_value_is_function (ctx, arguments[2]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Third arg is a callback to invoke on acquiring the name");
- return seed_make_null (ctx);
- }
+ if (!seed_value_is_object(ctx, arguments[2])
+ || !seed_value_is_function(ctx, arguments[2])) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Third arg is a callback to invoke on acquiring the name");
+ return seed_make_null(ctx);
+ }
acquire_func = arguments[2];
- if (!seed_value_is_object (ctx, arguments[3]) ||
- !seed_value_is_function (ctx, arguments[3]))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Fourth arg is a callback to invoke on acquiring the name");
- return seed_make_null (ctx);
- }
+ if (!seed_value_is_object(ctx, arguments[3])
+ || !seed_value_is_function(ctx, arguments[3])) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Fourth arg is a callback to invoke on acquiring the name");
+ return seed_make_null(ctx);
+ }
lost_func = arguments[3];
@@ -1048,12 +1014,14 @@ seed_js_dbus_acquire_name(SeedContext ctx,
owner->funcs.lost = on_name_lost;
owner->bus_type = bus_type;
- owner->acquired_closure = seed_closure_new (ctx, acquire_func, NULL, "DBus name acquired handler");
+ owner->acquired_closure
+ = seed_closure_new(ctx, acquire_func, NULL, "DBus name acquired handler");
g_closure_ref(owner->acquired_closure);
g_closure_sink(owner->acquired_closure);
- owner->lost_closure = seed_closure_new (ctx, lost_func, NULL, "DBus name lost handler");
+ owner->lost_closure
+ = seed_closure_new(ctx, lost_func, NULL, "DBus name lost handler");
g_closure_ref(owner->lost_closure);
g_closure_sink(owner->lost_closure);
@@ -1063,125 +1031,115 @@ seed_js_dbus_acquire_name(SeedContext ctx,
g_closure_add_invalidate_notifier(owner->acquired_closure, owner,
owner_closure_invalidated);
- id = big_dbus_acquire_name(bus_type,
- &owner->funcs,
- owner);
+ id = big_dbus_acquire_name(bus_type, &owner->funcs, owner);
- return seed_value_from_int (ctx, id, exception);
+ return seed_value_from_int(ctx, id, exception);
}
static SeedValue
-seed_js_dbus_release_name_by_id (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_js_dbus_release_name_by_id(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
DBusBusType bus_type;
unsigned int id;
- if (argument_count < 1)
- {
- seed_make_exception (ctx, exception,
- "ArgumentError", "Not enough args, need name owner monitor id");
- return seed_make_null (ctx);
- }
+ if (argument_count < 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Not enough args, need name owner monitor id");
+ return seed_make_null(ctx);
+ }
bus_type = get_bus_type_from_object(ctx, this_object, exception);
- id = seed_value_to_int (ctx, arguments[0], exception);
+ id = seed_value_to_int(ctx, arguments[0], exception);
- big_dbus_release_name_by_id(bus_type,
- id);
- return seed_make_undefined (ctx);
+ big_dbus_release_name_by_id(bus_type, id);
+ return seed_make_undefined(ctx);
}
-typedef struct {
- GClosure *appeared_closure;
- GClosure *vanished_closure;
- char *bus_name;
+typedef struct
+{
+ GClosure* appeared_closure;
+ GClosure* vanished_closure;
+ char* bus_name;
DBusBusType bus_type;
} BigJSDBusNameWatcher;
static void
-on_name_appeared(DBusConnection *connection,
- const char *name,
- const char *owner_unique_name,
- void *data)
+on_name_appeared(DBusConnection* connection,
+ const char* name,
+ const char* owner_unique_name,
+ void* data)
{
int argc;
SeedValue argv[2];
SeedContext ctx;
- BigJSDBusNameWatcher *watcher;
+ BigJSDBusNameWatcher* watcher;
SeedException exception;
watcher = data;
- ctx = seed_context_create (group, NULL);
- seed_prepare_global_context (ctx);
+ ctx = seed_context_create(group, NULL);
+ seed_prepare_global_context(ctx);
argc = 2;
- argv[0] = seed_value_from_string (ctx, name, &exception);
- argv[1] = seed_value_from_string (ctx, owner_unique_name, &exception);
+ argv[0] = seed_value_from_string(ctx, name, &exception);
+ argv[1] = seed_value_from_string(ctx, owner_unique_name, &exception);
- seed_closure_invoke_with_context (ctx, watcher->appeared_closure,
- argv, argc, &exception);
+ seed_closure_invoke_with_context(ctx, watcher->appeared_closure, argv, argc,
+ &exception);
// TODO: Do something with exception.
- seed_context_unref (ctx);
-
+ seed_context_unref(ctx);
}
static void
-on_name_vanished(DBusConnection *connection,
- const char *name,
- const char *owner_unique_name,
- void *data)
+on_name_vanished(DBusConnection* connection,
+ const char* name,
+ const char* owner_unique_name,
+ void* data)
{
int argc;
SeedValue argv[2];
SeedContext ctx;
- BigJSDBusNameWatcher *watcher;
+ BigJSDBusNameWatcher* watcher;
SeedException exception;
watcher = data;
- ctx = seed_context_create (group, NULL);
- seed_prepare_global_context (ctx);
+ ctx = seed_context_create(group, NULL);
+ seed_prepare_global_context(ctx);
argc = 2;
- argv[0] = seed_value_from_string (ctx, name, &exception);
- argv[1] = seed_value_from_string (ctx, owner_unique_name, &exception);
+ argv[0] = seed_value_from_string(ctx, name, &exception);
+ argv[1] = seed_value_from_string(ctx, owner_unique_name, &exception);
- seed_closure_invoke_with_context (ctx, watcher->vanished_closure,
- argv, argc, &exception);
+ seed_closure_invoke_with_context(ctx, watcher->vanished_closure, argv, argc,
+ &exception);
// TODO: Do something with exception.
- seed_context_unref (ctx);
-
+ seed_context_unref(ctx);
}
-static const BigDBusWatchNameFuncs watch_name_funcs = {
- on_name_appeared,
- on_name_vanished
-};
+static const BigDBusWatchNameFuncs watch_name_funcs
+ = { on_name_appeared, on_name_vanished };
static void
-watch_closure_invalidated(gpointer data,
- GClosure *closure)
+watch_closure_invalidated(gpointer data, GClosure* closure)
{
- BigJSDBusNameWatcher *watcher;
+ BigJSDBusNameWatcher* watcher;
- watcher = (BigJSDBusNameWatcher*)data;
+ watcher = (BigJSDBusNameWatcher*) data;
if (watcher) {
- big_dbus_unwatch_name(watcher->bus_type,
- watcher->bus_name,
- &watch_name_funcs,
- watcher);
+ big_dbus_unwatch_name(watcher->bus_type, watcher->bus_name,
+ &watch_name_funcs, watcher);
g_free(watcher->bus_name);
g_closure_unref(watcher->appeared_closure);
@@ -1189,61 +1147,66 @@ watch_closure_invalidated(gpointer data,
g_slice_free(BigJSDBusNameWatcher, watcher);
}
-
}
static SeedValue
seed_js_dbus_watch_name(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- const char *bus_name;
+ const char* bus_name;
gboolean start_if_not_found;
SeedObject appeared_func;
SeedObject vanished_func;
- BigJSDBusNameWatcher *watcher;
+ BigJSDBusNameWatcher* watcher;
DBusBusType bus_type;
- if (argument_count < 4)
- {
- seed_make_exception (ctx, exception,
- "ArgumentError", "Not enough args, need bus name, acquired_func, lost_func");
- return seed_make_null (ctx);
- }
+ if (argument_count < 4) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Not enough args, need bus name, acquired_func, lost_func");
+ return seed_make_null(ctx);
+ }
bus_type = get_bus_type_from_object(ctx, this_object, exception);
- bus_name = seed_value_to_string (ctx, arguments[0], exception);
+ bus_name = seed_value_to_string(ctx, arguments[0], exception);
- start_if_not_found = seed_value_to_boolean (ctx, arguments[1], exception);
+ start_if_not_found = seed_value_to_boolean(ctx, arguments[1], exception);
- if (!seed_value_is_object (ctx, arguments[2]) || !seed_value_is_function (ctx, arguments[2]))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "Third arg is a callback to invoke on seeing
the name");
- return seed_make_null (ctx);
- }
+ if (!seed_value_is_object(ctx, arguments[2])
+ || !seed_value_is_function(ctx, arguments[2])) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Third arg is a callback to invoke on seeing the name");
+ return seed_make_null(ctx);
+ }
appeared_func = arguments[2];
- if (!seed_value_is_object (ctx, arguments[3]) || !seed_value_is_function (ctx, arguments[3]))
- {
- seed_make_exception (ctx, exception, "ArgumentError", "Fourth arg is a callback to invoke on seeing
the name");
- return seed_make_null (ctx);
- }
+ if (!seed_value_is_object(ctx, arguments[3])
+ || !seed_value_is_function(ctx, arguments[3])) {
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "Fourth arg is a callback to invoke on seeing the name");
+ return seed_make_null(ctx);
+ }
vanished_func = arguments[3];
watcher = g_slice_new0(BigJSDBusNameWatcher);
- watcher->appeared_closure = seed_closure_new (ctx, appeared_func, NULL, "DBus name appeared handler");
+ watcher->appeared_closure = seed_closure_new(ctx, appeared_func, NULL,
+ "DBus name appeared handler");
g_closure_ref(watcher->appeared_closure);
g_closure_sink(watcher->appeared_closure);
- watcher->vanished_closure = seed_closure_new (ctx, vanished_func, NULL, "DBus name vanished handler");
+ watcher->vanished_closure = seed_closure_new(ctx, vanished_func, NULL,
+ "DBus name vanished handler");
g_closure_ref(watcher->vanished_closure);
g_closure_sink(watcher->vanished_closure);
@@ -1256,210 +1219,192 @@ seed_js_dbus_watch_name(SeedContext ctx,
g_closure_add_invalidate_notifier(watcher->appeared_closure, watcher,
watch_closure_invalidated);
- big_dbus_watch_name(bus_type,
- bus_name,
- start_if_not_found ?
- BIG_DBUS_NAME_START_IF_NOT_FOUND : 0,
- &watch_name_funcs,
- watcher);
+ big_dbus_watch_name(bus_type, bus_name,
+ start_if_not_found ? BIG_DBUS_NAME_START_IF_NOT_FOUND
+ : 0,
+ &watch_name_funcs, watcher);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-unique_name_getter (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+unique_name_getter(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- DBusConnection *bus_connection;
- DBusBusType bus_type;
+ DBusConnection* bus_connection;
+ DBusBusType bus_type;
- bus_type = get_bus_type_from_object (ctx, object, exception);
+ bus_type = get_bus_type_from_object(ctx, object, exception);
- bus_check (ctx, bus_type, exception);
+ bus_check(ctx, bus_type, exception);
- bus_connection = DBUS_CONNECTION_FROM_TYPE (bus_type);
+ bus_connection = DBUS_CONNECTION_FROM_TYPE(bus_type);
- if (bus_connection == NULL)
- {
- return seed_make_null (ctx);
- }
- else
- {
- const gchar *unique_name;
+ if (bus_connection == NULL) {
+ return seed_make_null(ctx);
+ } else {
+ const gchar* unique_name;
- unique_name = dbus_bus_get_unique_name (bus_connection);
- return seed_value_from_string (ctx, unique_name, exception);
+ unique_name = dbus_bus_get_unique_name(bus_connection);
+ return seed_value_from_string(ctx, unique_name, exception);
}
}
static SeedValue
seed_js_dbus_start_service(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- const char *name;
- DBusBusType bus_type;
- DBusConnection *bus_connection;
+ const char* name;
+ DBusBusType bus_type;
+ DBusConnection* bus_connection;
- if (argument_count != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Wrong number of arguments, expected service name");
- return seed_make_null (ctx);
- }
+ if (argument_count != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Wrong number of arguments, expected service name");
+ return seed_make_null(ctx);
+ }
- name = seed_value_to_string (ctx, arguments[0], exception);
+ name = seed_value_to_string(ctx, arguments[0], exception);
- bus_type = get_bus_type_from_object (ctx, this_object, exception);
+ bus_type = get_bus_type_from_object(ctx, this_object, exception);
if (!bus_check(ctx, bus_type, exception))
- return seed_make_null (ctx);
+ return seed_make_null(ctx);
bus_connection = DBUS_CONNECTION_FROM_TYPE(bus_type);
big_dbus_start_service(bus_connection, name);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_js_dbus_signature_length (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_js_dbus_signature_length(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- const gchar *signature;
- DBusSignatureIter iter;
- gint length = 0;
-
- if (argument_count < 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "dbus.signatureLength expected 1 argument, got %zd",
- argument_count);
- return seed_make_null (ctx);
+ const gchar* signature;
+ DBusSignatureIter iter;
+ gint length = 0;
+
+ if (argument_count < 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "dbus.signatureLength expected 1 argument, got %zd",
+ argument_count);
+ return seed_make_null(ctx);
}
- signature = seed_value_to_string (ctx, arguments[0], exception);
+ signature = seed_value_to_string(ctx, arguments[0], exception);
- if (!dbus_signature_validate (signature, NULL))
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "Invalid signature");
- return seed_make_null (ctx);
+ if (!dbus_signature_validate(signature, NULL)) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Invalid signature");
+ return seed_make_null(ctx);
}
- if (*signature == '\0')
- return seed_value_from_int (ctx, 0, exception);
+ if (*signature == '\0')
+ return seed_value_from_int(ctx, 0, exception);
- dbus_signature_iter_init (&iter, signature);
- do
- {
- length++;
- }
- while (dbus_signature_iter_next (&iter));
+ dbus_signature_iter_init(&iter, signature);
+ do {
+ length++;
+ } while (dbus_signature_iter_next(&iter));
- return seed_value_from_int (ctx, length, exception);
+ return seed_value_from_int(ctx, length, exception);
}
-seed_static_value bus_values[] = {
- {"unique_name", unique_name_getter, NULL, 0},
- {NULL, NULL, NULL, 0}
-};
-
-seed_static_function bus_funcs[] = {
- {"call", seed_js_dbus_call, 0},
- {"call_async", seed_js_dbus_call_async, 0},
- {"acquire_name", seed_js_dbus_acquire_name, 0},
- {"release_name_by_id", seed_js_dbus_release_name_by_id, 0},
- {"watch_name", seed_js_dbus_watch_name, 0},
- {"watch_signal", seed_js_dbus_watch_signal, 0},
- {"unwatch_signal_by_id", seed_js_dbus_unwatch_signal_by_id, 0},
- {"unwatch_signal", seed_js_dbus_unwatch_signal, 0},
- {"emit_signal", seed_js_dbus_emit_signal, 0},
- {"start_service", seed_js_dbus_start_service, 0},
- {NULL, NULL, 0}
-};
-
-seed_static_function dbus_funcs[] = {
- {"signatureLength", seed_js_dbus_signature_length, 0},
- {NULL, NULL, 0}
-};
-
-seed_static_value dbus_values[] = {
- {"localMachineID", seed_js_dbus_get_machine_id, NULL, 0},
- {NULL, NULL, NULL, 0}
-};
+seed_static_value bus_values[]
+ = { { "unique_name", unique_name_getter, NULL, 0 }, { NULL, NULL, NULL, 0 } };
+
+seed_static_function bus_funcs[]
+ = { { "call", seed_js_dbus_call, 0 },
+ { "call_async", seed_js_dbus_call_async, 0 },
+ { "acquire_name", seed_js_dbus_acquire_name, 0 },
+ { "release_name_by_id", seed_js_dbus_release_name_by_id, 0 },
+ { "watch_name", seed_js_dbus_watch_name, 0 },
+ { "watch_signal", seed_js_dbus_watch_signal, 0 },
+ { "unwatch_signal_by_id", seed_js_dbus_unwatch_signal_by_id, 0 },
+ { "unwatch_signal", seed_js_dbus_unwatch_signal, 0 },
+ { "emit_signal", seed_js_dbus_emit_signal, 0 },
+ { "start_service", seed_js_dbus_start_service, 0 },
+ { NULL, NULL, 0 } };
+
+seed_static_function dbus_funcs[]
+ = { { "signatureLength", seed_js_dbus_signature_length, 0 },
+ { NULL, NULL, 0 } };
+
+seed_static_value dbus_values[]
+ = { { "localMachineID", seed_js_dbus_get_machine_id, NULL, 0 },
+ { NULL, NULL, NULL, 0 } };
static void
-define_bus_object (SeedContext ctx,
- DBusBusType which_bus)
+define_bus_object(SeedContext ctx, DBusBusType which_bus)
{
- SeedObject bus_obj;
- const gchar *bus_name;
+ SeedObject bus_obj;
+ const gchar* bus_name;
- bus_name = BIG_DBUS_NAME_FROM_TYPE(which_bus);
- bus_obj = seed_make_object (ctx, dbus_bus_class, NULL);
- seed_object_set_property (ctx, bus_obj, "_dbusBusType",
- seed_value_from_int (ctx, which_bus, NULL));
- //TODO: Define exports
- seed_js_define_dbus_exports (ctx, bus_obj, which_bus);
+ bus_name = BIG_DBUS_NAME_FROM_TYPE(which_bus);
+ bus_obj = seed_make_object(ctx, dbus_bus_class, NULL);
+ seed_object_set_property(ctx, bus_obj, "_dbusBusType",
+ seed_value_from_int(ctx, which_bus, NULL));
+ // TODO: Define exports
+ seed_js_define_dbus_exports(ctx, bus_obj, which_bus);
- seed_object_set_property (ctx, namespace_ref, bus_name, bus_obj);
+ seed_object_set_property(ctx, namespace_ref, bus_name, bus_obj);
}
- /*static void
+/*static void
seed_define_bus_proto (SeedContext ctx)
{
- bus_proto = seed_make_object (ctx, NULL, NULL);
+bus_proto = seed_make_object (ctx, NULL, NULL);
- seed_value_protect (ctx, bus_proto);
- }*/
+seed_value_protect (ctx, bus_proto);
+}*/
SeedObject
-seed_module_init (SeedEngine * eng)
+seed_module_init(SeedEngine* eng)
{
- seed_class_definition dbus_namespace_class_def = seed_empty_class;
- seed_class_definition dbus_bus_class_def = seed_empty_class;
+ seed_class_definition dbus_namespace_class_def = seed_empty_class;
+ seed_class_definition dbus_bus_class_def = seed_empty_class;
- ctx = eng->context;
- group = eng->group;
+ ctx = eng->context;
+ group = eng->group;
- dbus_namespace_class_def.class_name = "dbusnative";
- dbus_namespace_class_def.static_functions = dbus_funcs;
- dbus_namespace_class_def.static_values = dbus_values;
+ dbus_namespace_class_def.class_name = "dbusnative";
+ dbus_namespace_class_def.static_functions = dbus_funcs;
+ dbus_namespace_class_def.static_values = dbus_values;
- dbus_bus_class_def.class_name = "dbusbus";
- dbus_bus_class_def.static_functions = bus_funcs;
- dbus_bus_class_def.static_values = bus_values;
+ dbus_bus_class_def.class_name = "dbusbus";
+ dbus_bus_class_def.static_functions = bus_funcs;
+ dbus_bus_class_def.static_values = bus_values;
- dbus_namespace_class = seed_create_class (&dbus_namespace_class_def);
- dbus_bus_class = seed_create_class (&dbus_bus_class_def);
+ dbus_namespace_class = seed_create_class(&dbus_namespace_class_def);
+ dbus_bus_class = seed_create_class(&dbus_bus_class_def);
- namespace_ref = seed_make_object (eng->context, dbus_namespace_class, NULL);
+ namespace_ref = seed_make_object(eng->context, dbus_namespace_class, NULL);
- seed_object_set_property (ctx, namespace_ref, "BUS_SESSION",
- seed_value_from_int (ctx, DBUS_BUS_SESSION,
- NULL));
- seed_object_set_property (ctx, namespace_ref, "BUS_SYSTEM",
- seed_value_from_int (ctx, DBUS_BUS_SYSTEM, NULL));
- seed_object_set_property (ctx, namespace_ref, "BUS_STARTER",
- seed_value_from_int (ctx, DBUS_BUS_STARTER,
- NULL));
+ seed_object_set_property(ctx, namespace_ref, "BUS_SESSION",
+ seed_value_from_int(ctx, DBUS_BUS_SESSION, NULL));
+ seed_object_set_property(ctx, namespace_ref, "BUS_SYSTEM",
+ seed_value_from_int(ctx, DBUS_BUS_SYSTEM, NULL));
+ seed_object_set_property(ctx, namespace_ref, "BUS_STARTER",
+ seed_value_from_int(ctx, DBUS_BUS_STARTER, NULL));
- seed_create_function (ctx, "signatureLength",
- (SeedFunctionCallback) seed_js_dbus_signature_length,
- namespace_ref);
+ seed_create_function(ctx, "signatureLength",
+ (SeedFunctionCallback) seed_js_dbus_signature_length,
+ namespace_ref);
- define_bus_object (ctx, DBUS_BUS_SESSION);
- define_bus_object (ctx, DBUS_BUS_SYSTEM);
+ define_bus_object(ctx, DBUS_BUS_SESSION);
+ define_bus_object(ctx, DBUS_BUS_SYSTEM);
- return namespace_ref;
+ return namespace_ref;
}
diff --git a/modules/dbus/util/dbus-private.h b/modules/dbus/util/dbus-private.h
index 9a31321..3d58d06 100644
--- a/modules/dbus/util/dbus-private.h
+++ b/modules/dbus/util/dbus-private.h
@@ -10,46 +10,47 @@
G_BEGIN_DECLS
-typedef struct {
+typedef struct
+{
DBusBusType bus_type;
- void *where_connection_was;
- BigDBusProxy *driver_proxy;
- GHashTable *json_ifaces;
- GSList *name_ownership_monitors;
- GHashTable *name_watches;
+ void* where_connection_was;
+ BigDBusProxy* driver_proxy;
+ GHashTable* json_ifaces;
+ GSList* name_ownership_monitors;
+ GHashTable* name_watches;
- GSList *all_signal_watchers;
+ GSList* all_signal_watchers;
/* These signal watcher tables are maps from a
* string to a GSList of BigSignalWatcher,
* and they are lazily created if a signal watcher
* needs to be looked up by the given key.
*/
- GHashTable *signal_watchers_by_unique_sender;
- GHashTable *signal_watchers_by_path;
- GHashTable *signal_watchers_by_iface;
- GHashTable *signal_watchers_by_signal;
+ GHashTable* signal_watchers_by_unique_sender;
+ GHashTable* signal_watchers_by_path;
+ GHashTable* signal_watchers_by_iface;
+ GHashTable* signal_watchers_by_signal;
/* These are matching on well-known name only,
* or watching all signals
*/
- GSList *signal_watchers_in_no_table;
+ GSList* signal_watchers_in_no_table;
} BigDBusInfo;
-BigDBusInfo* _big_dbus_ensure_info (DBusConnection *connection);
-void _big_dbus_dispose_info (DBusConnection *connection);
-void _big_dbus_process_pending_signal_watchers (DBusConnection *connection,
- BigDBusInfo *info);
-DBusHandlerResult _big_dbus_signal_watch_filter_message (DBusConnection *connection,
- DBusMessage *message,
- void *data);
-void _big_dbus_set_matching_name_owner_changed (DBusConnection *connection,
- const char *bus_name,
- gboolean matched);
-void _big_dbus_ensure_connect_idle (DBusBusType bus_type);
-DBusConnection* _big_dbus_get_weak_ref (DBusBusType which_bus);
-
+BigDBusInfo* _big_dbus_ensure_info(DBusConnection* connection);
+void _big_dbus_dispose_info(DBusConnection* connection);
+void _big_dbus_process_pending_signal_watchers(DBusConnection* connection,
+ BigDBusInfo* info);
+DBusHandlerResult _big_dbus_signal_watch_filter_message(
+ DBusConnection* connection,
+ DBusMessage* message,
+ void* data);
+void _big_dbus_set_matching_name_owner_changed(DBusConnection* connection,
+ const char* bus_name,
+ gboolean matched);
+void _big_dbus_ensure_connect_idle(DBusBusType bus_type);
+DBusConnection* _big_dbus_get_weak_ref(DBusBusType which_bus);
G_END_DECLS
-#endif /* __BIG_UTIL_DBUS_PRIVATE_H__ */
+#endif /* __BIG_UTIL_DBUS_PRIVATE_H__ */
diff --git a/modules/dbus/util/dbus-proxy.c b/modules/dbus/util/dbus-proxy.c
index a9a413c..610cde0 100644
--- a/modules/dbus/util/dbus-proxy.c
+++ b/modules/dbus/util/dbus-proxy.c
@@ -9,20 +9,19 @@
#include <dbus/dbus-glib-lowlevel.h>
#include <stdarg.h>
-typedef enum {
- REPLY_CLOSURE_PLAIN,
- REPLY_CLOSURE_JSON
-} ReplyClosureType;
+typedef enum { REPLY_CLOSURE_PLAIN, REPLY_CLOSURE_JSON } ReplyClosureType;
-typedef struct {
- BigDBusProxy *proxy;
+typedef struct
+{
+ BigDBusProxy* proxy;
ReplyClosureType type;
- union {
- BigDBusProxyReplyFunc plain;
+ union
+ {
+ BigDBusProxyReplyFunc plain;
BigDBusProxyJsonReplyFunc json;
} func;
BigDBusProxyErrorReplyFunc error_func;
- void *data;
+ void* data;
/* this is a debug thing; we want to guarantee
* we call exactly 1 time either the reply or error
* callback.
@@ -31,30 +30,33 @@ typedef struct {
guint error_invoked : 1;
} ReplyClosure;
-static void big_dbus_proxy_dispose (GObject *object);
-static void big_dbus_proxy_finalize (GObject *object);
-static GObject* big_dbus_proxy_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params);
-static void big_dbus_proxy_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void big_dbus_proxy_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-
-struct _BigDBusProxy {
+static void big_dbus_proxy_dispose(GObject* object);
+static void big_dbus_proxy_finalize(GObject* object);
+static GObject* big_dbus_proxy_constructor(
+ GType type,
+ guint n_construct_properties,
+ GObjectConstructParam* construct_params);
+static void big_dbus_proxy_get_property(GObject* object,
+ guint prop_id,
+ GValue* value,
+ GParamSpec* pspec);
+static void big_dbus_proxy_set_property(GObject* object,
+ guint prop_id,
+ const GValue* value,
+ GParamSpec* pspec);
+
+struct _BigDBusProxy
+{
GObject parent;
- DBusConnection *connection;
- char *bus_name;
- char *object_path;
- char *iface;
+ DBusConnection* connection;
+ char* bus_name;
+ char* object_path;
+ char* iface;
};
-struct _BigDBusProxyClass {
+struct _BigDBusProxyClass
+{
GObjectClass parent;
};
@@ -68,7 +70,8 @@ enum {
static int signals[LAST_SIGNAL];
#endif
-enum {
+enum
+{
PROP_0,
PROP_CONNECTION,
PROP_BUS_NAME,
@@ -77,15 +80,14 @@ enum {
};
static void
-big_dbus_proxy_init(BigDBusProxy *proxy)
+big_dbus_proxy_init(BigDBusProxy* proxy)
{
-
}
static void
-big_dbus_proxy_class_init(BigDBusProxyClass *klass)
+big_dbus_proxy_class_init(BigDBusProxyClass* klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass* object_class = G_OBJECT_CLASS(klass);
object_class->dispose = big_dbus_proxy_dispose;
object_class->finalize = big_dbus_proxy_finalize;
@@ -94,41 +96,31 @@ big_dbus_proxy_class_init(BigDBusProxyClass *klass)
object_class->get_property = big_dbus_proxy_get_property;
object_class->set_property = big_dbus_proxy_set_property;
- g_object_class_install_property(object_class,
- PROP_CONNECTION,
- g_param_spec_boxed("connection",
- "DBusConnection",
- "Our connection to the bus",
- DBUS_TYPE_CONNECTION,
- G_PARAM_READWRITE));
- g_object_class_install_property(object_class,
- PROP_BUS_NAME,
- g_param_spec_string("bus-name",
- "Bus Name",
- "Name of app on the bus",
- NULL,
- G_PARAM_READWRITE));
- g_object_class_install_property(object_class,
- PROP_OBJECT_PATH,
- g_param_spec_string("object-path",
- "Object Path",
- "Object's dbus path",
- NULL,
- G_PARAM_READWRITE));
-
- g_object_class_install_property(object_class,
- PROP_INTERFACE,
- g_param_spec_string("interface",
- "Interface",
- "Interface to invoke methods on",
- NULL,
- G_PARAM_READWRITE));
+ g_object_class_install_property(
+ object_class, PROP_CONNECTION,
+ g_param_spec_boxed("connection", "DBusConnection",
+ "Our connection to the bus", DBUS_TYPE_CONNECTION,
+ G_PARAM_READWRITE));
+ g_object_class_install_property(
+ object_class, PROP_BUS_NAME,
+ g_param_spec_string("bus-name", "Bus Name", "Name of app on the bus",
+ NULL, G_PARAM_READWRITE));
+ g_object_class_install_property(
+ object_class, PROP_OBJECT_PATH,
+ g_param_spec_string("object-path", "Object Path", "Object's dbus path",
+ NULL, G_PARAM_READWRITE));
+
+ g_object_class_install_property(
+ object_class, PROP_INTERFACE,
+ g_param_spec_string("interface", "Interface",
+ "Interface to invoke methods on", NULL,
+ G_PARAM_READWRITE));
}
static void
-big_dbus_proxy_dispose(GObject *object)
+big_dbus_proxy_dispose(GObject* object)
{
- BigDBusProxy *proxy;
+ BigDBusProxy* proxy;
proxy = BIG_DBUS_PROXY(object);
@@ -156,23 +148,22 @@ big_dbus_proxy_dispose(GObject *object)
}
static void
-big_dbus_proxy_finalize(GObject *object)
+big_dbus_proxy_finalize(GObject* object)
{
G_OBJECT_CLASS(big_dbus_proxy_parent_class)->finalize(object);
}
static GObject*
-big_dbus_proxy_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
+big_dbus_proxy_constructor(GType type,
+ guint n_construct_properties,
+ GObjectConstructParam* construct_params)
{
- GObject *object;
- BigDBusProxy *proxy;
+ GObject* object;
+ BigDBusProxy* proxy;
- object = (* G_OBJECT_CLASS (big_dbus_proxy_parent_class)->constructor) (type,
- n_construct_properties,
- construct_params);
+ object = (*G_OBJECT_CLASS(big_dbus_proxy_parent_class)
+ ->constructor)(type, n_construct_properties, construct_params);
proxy = BIG_DBUS_PROXY(object);
@@ -180,76 +171,80 @@ big_dbus_proxy_constructor (GType type,
}
static void
-big_dbus_proxy_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+big_dbus_proxy_get_property(GObject* object,
+ guint prop_id,
+ GValue* value,
+ GParamSpec* pspec)
{
- BigDBusProxy *proxy;
+ BigDBusProxy* proxy;
- proxy = BIG_DBUS_PROXY (object);
+ proxy = BIG_DBUS_PROXY(object);
switch (prop_id) {
- case PROP_CONNECTION:
- g_value_set_boxed(value, proxy->connection);
- break;
- case PROP_BUS_NAME:
- g_value_set_string(value, proxy->bus_name);
- break;
- case PROP_OBJECT_PATH:
- g_value_set_string(value, proxy->object_path);
- break;
- case PROP_INTERFACE:
- g_value_set_string(value, proxy->iface);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ case PROP_CONNECTION:
+ g_value_set_boxed(value, proxy->connection);
+ break;
+ case PROP_BUS_NAME:
+ g_value_set_string(value, proxy->bus_name);
+ break;
+ case PROP_OBJECT_PATH:
+ g_value_set_string(value, proxy->object_path);
+ break;
+ case PROP_INTERFACE:
+ g_value_set_string(value, proxy->iface);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
}
}
static void
-big_dbus_proxy_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+big_dbus_proxy_set_property(GObject* object,
+ guint prop_id,
+ const GValue* value,
+ GParamSpec* pspec)
{
- BigDBusProxy *proxy;
+ BigDBusProxy* proxy;
- proxy = BIG_DBUS_PROXY (object);
+ proxy = BIG_DBUS_PROXY(object);
switch (prop_id) {
- case PROP_CONNECTION:
- if (proxy->connection != NULL) {
- g_warning("Cannot change BigDBusProxy::connection after it's set");
- return;
- }
- proxy->connection = dbus_connection_ref(g_value_get_boxed(value));
- break;
- case PROP_BUS_NAME:
- if (proxy->bus_name != NULL) {
- g_warning("Cannot change BigDBusProxy::bus-name after it's set");
- return;
- }
- proxy->bus_name = g_value_dup_string(value);
- break;
- case PROP_OBJECT_PATH:
- if (proxy->object_path != NULL) {
- g_warning("Cannot change BigDBusProxy::object-path after it's set");
- return;
- }
- proxy->object_path = g_value_dup_string(value);
- break;
- case PROP_INTERFACE:
- if (proxy->iface != NULL) {
- g_warning("Cannot change BigDBusProxy::interface after it's set");
- return;
- }
- proxy->iface = g_value_dup_string(value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ case PROP_CONNECTION:
+ if (proxy->connection != NULL) {
+ g_warning(
+ "Cannot change BigDBusProxy::connection after it's set");
+ return;
+ }
+ proxy->connection = dbus_connection_ref(g_value_get_boxed(value));
+ break;
+ case PROP_BUS_NAME:
+ if (proxy->bus_name != NULL) {
+ g_warning(
+ "Cannot change BigDBusProxy::bus-name after it's set");
+ return;
+ }
+ proxy->bus_name = g_value_dup_string(value);
+ break;
+ case PROP_OBJECT_PATH:
+ if (proxy->object_path != NULL) {
+ g_warning(
+ "Cannot change BigDBusProxy::object-path after it's set");
+ return;
+ }
+ proxy->object_path = g_value_dup_string(value);
+ break;
+ case PROP_INTERFACE:
+ if (proxy->iface != NULL) {
+ g_warning(
+ "Cannot change BigDBusProxy::interface after it's set");
+ return;
+ }
+ proxy->iface = g_value_dup_string(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
}
}
@@ -257,48 +252,42 @@ big_dbus_proxy_set_property (GObject *object,
* iface is allowed to be NULL but likely should not be.
*/
BigDBusProxy*
-big_dbus_proxy_new(DBusConnection *connection,
- const char *bus_name,
- const char *object_path,
- const char *iface)
+big_dbus_proxy_new(DBusConnection* connection,
+ const char* bus_name,
+ const char* object_path,
+ const char* iface)
{
- BigDBusProxy *proxy;
+ BigDBusProxy* proxy;
g_return_val_if_fail(connection != NULL, NULL);
g_return_val_if_fail(object_path != NULL, NULL);
- proxy = g_object_new(BIG_TYPE_DBUS_PROXY,
- "connection", connection,
- "bus-name", bus_name,
- "object-path", object_path,
- "interface", iface,
- NULL);
+ proxy = g_object_new(BIG_TYPE_DBUS_PROXY, "connection", connection,
+ "bus-name", bus_name, "object-path", object_path,
+ "interface", iface, NULL);
return proxy;
}
DBusConnection*
-big_dbus_proxy_get_connection(BigDBusProxy *proxy)
+big_dbus_proxy_get_connection(BigDBusProxy* proxy)
{
return proxy->connection;
}
const char*
-big_dbus_proxy_get_bus_name(BigDBusProxy *proxy)
+big_dbus_proxy_get_bus_name(BigDBusProxy* proxy)
{
return proxy->bus_name;
}
DBusMessage*
-big_dbus_proxy_new_method_call(BigDBusProxy *proxy,
- const char *method_name)
+big_dbus_proxy_new_method_call(BigDBusProxy* proxy, const char* method_name)
{
- DBusMessage *message;
+ DBusMessage* message;
- message = dbus_message_new_method_call(proxy->bus_name,
- proxy->object_path,
- proxy->iface,
- method_name);
+ message = dbus_message_new_method_call(proxy->bus_name, proxy->object_path,
+ proxy->iface, method_name);
if (message == NULL)
g_error("no memory");
@@ -312,29 +301,30 @@ big_dbus_proxy_new_method_call(BigDBusProxy *proxy,
}
DBusMessage*
-big_dbus_proxy_new_json_call(BigDBusProxy *proxy,
- const char *method_name,
- DBusMessageIter *arg_iter,
- DBusMessageIter *dict_iter)
+big_dbus_proxy_new_json_call(BigDBusProxy* proxy,
+ const char* method_name,
+ DBusMessageIter* arg_iter,
+ DBusMessageIter* dict_iter)
{
- DBusMessage *message;
+ DBusMessage* message;
message = big_dbus_proxy_new_method_call(proxy, method_name);
dbus_message_iter_init_append(message, arg_iter);
- dbus_message_iter_open_container(arg_iter, DBUS_TYPE_ARRAY, "{sv}", dict_iter);
+ dbus_message_iter_open_container(arg_iter, DBUS_TYPE_ARRAY, "{sv}",
+ dict_iter);
return message;
}
static ReplyClosure*
-reply_closure_new(BigDBusProxy *proxy,
- BigDBusProxyReplyFunc plain_func,
- BigDBusProxyJsonReplyFunc json_func,
+reply_closure_new(BigDBusProxy* proxy,
+ BigDBusProxyReplyFunc plain_func,
+ BigDBusProxyJsonReplyFunc json_func,
BigDBusProxyErrorReplyFunc error_func,
- void *data)
+ void* data)
{
- ReplyClosure *c;
+ ReplyClosure* c;
c = g_slice_new0(ReplyClosure);
@@ -357,19 +347,18 @@ reply_closure_new(BigDBusProxy *proxy,
}
static void
-reply_closure_free(ReplyClosure *c)
+reply_closure_free(ReplyClosure* c)
{
/* call exactly one of these */
- g_assert(!(c->error_invoked &&
- c->reply_invoked));
+ g_assert(!(c->error_invoked && c->reply_invoked));
- if (!(c->error_invoked ||
- c->reply_invoked)) {
+ if (!(c->error_invoked || c->reply_invoked)) {
c->error_invoked = TRUE;
if (c->error_func) {
- (* c->error_func) (c->proxy, DBUS_ERROR_FAILED,
- "Pending call was freed (due to dbus_shutdown() probably) before it was ever
notified",
- c->data);
+ (*c->error_func)(c->proxy, DBUS_ERROR_FAILED,
+ "Pending call was freed (due to dbus_shutdown() "
+ "probably) before it was ever notified",
+ c->data);
}
}
@@ -378,8 +367,7 @@ reply_closure_free(ReplyClosure *c)
}
static void
-reply_closure_invoke_error(ReplyClosure *c,
- DBusMessage *reply)
+reply_closure_invoke_error(ReplyClosure* c, DBusMessage* reply)
{
g_assert(dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR);
@@ -395,17 +383,14 @@ reply_closure_invoke_error(ReplyClosure *c,
dbus_set_error_from_message(&derror, reply);
- (* c->error_func) (c->proxy, derror.name,
- derror.message,
- c->data);
+ (*c->error_func)(c->proxy, derror.name, derror.message, c->data);
dbus_error_free(&derror);
}
}
static void
-reply_closure_invoke(ReplyClosure *c,
- DBusMessage *reply)
+reply_closure_invoke(ReplyClosure* c, DBusMessage* reply)
{
if (c->type == REPLY_CLOSURE_PLAIN) {
if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
@@ -415,9 +400,7 @@ reply_closure_invoke(ReplyClosure *c,
c->reply_invoked = TRUE;
if (c->func.plain != NULL) {
- (* c->func.plain) (c->proxy,
- reply,
- c->data);
+ (*c->func.plain)(c->proxy, reply, c->data);
}
} else if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
reply_closure_invoke_error(c, reply);
@@ -428,9 +411,9 @@ reply_closure_invoke(ReplyClosure *c,
c->error_invoked = TRUE;
if (c->error_func) {
- (* c->error_func) (c->proxy, DBUS_ERROR_FAILED,
- "Got weird message type back as a reply",
- c->data);
+ (*c->error_func)(c->proxy, DBUS_ERROR_FAILED,
+ "Got weird message type back as a reply",
+ c->data);
}
}
} else if (c->type == REPLY_CLOSURE_JSON) {
@@ -448,10 +431,7 @@ reply_closure_invoke(ReplyClosure *c,
dbus_message_iter_init(reply, &arg_iter);
dbus_message_iter_recurse(&arg_iter, &dict_iter);
- (* c->func.json) (c->proxy,
- reply,
- &dict_iter,
- c->data);
+ (*c->func.json)(c->proxy, reply, &dict_iter, c->data);
}
} else {
g_assert(!c->reply_invoked);
@@ -460,10 +440,10 @@ reply_closure_invoke(ReplyClosure *c,
c->error_invoked = TRUE;
if (c->error_func) {
- (* c->error_func) (c->proxy,
- DBUS_ERROR_FAILED,
- "Message we got back did not have the right signature",
- c->data);
+ (*c->error_func)(
+ c->proxy, DBUS_ERROR_FAILED,
+ "Message we got back did not have the right signature",
+ c->data);
}
}
} else if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
@@ -475,9 +455,9 @@ reply_closure_invoke(ReplyClosure *c,
c->error_invoked = TRUE;
if (c->error_func) {
- (* c->error_func) (c->proxy, DBUS_ERROR_FAILED,
- "Got weird message type back as a reply",
- c->data);
+ (*c->error_func)(c->proxy, DBUS_ERROR_FAILED,
+ "Got weird message type back as a reply",
+ c->data);
}
}
} else {
@@ -485,11 +465,10 @@ reply_closure_invoke(ReplyClosure *c,
}
}
-
static gboolean
-failed_to_send_idle(void *data)
+failed_to_send_idle(void* data)
{
- ReplyClosure *c;
+ ReplyClosure* c;
c = data;
@@ -499,10 +478,8 @@ failed_to_send_idle(void *data)
c->error_invoked = TRUE;
if (c->error_func) {
- (* c->error_func) (c->proxy,
- DBUS_ERROR_NO_MEMORY,
- "Unable to send method call",
- c->data);
+ (*c->error_func)(c->proxy, DBUS_ERROR_NO_MEMORY,
+ "Unable to send method call", c->data);
}
reply_closure_free(c);
@@ -510,13 +487,11 @@ failed_to_send_idle(void *data)
return FALSE;
}
-
static void
-pending_call_notify(DBusPendingCall *pending,
- void *user_data)
+pending_call_notify(DBusPendingCall* pending, void* user_data)
{
- DBusMessage *reply;
- ReplyClosure *c;
+ DBusMessage* reply;
+ ReplyClosure* c;
big_debug(BIG_DEBUG_UTIL_DBUS,
"BigDBusProxy received reply to pending call");
@@ -540,10 +515,8 @@ pending_call_notify(DBusPendingCall *pending,
c->error_invoked = TRUE;
if (c->error_func) {
- (* c->error_func) (c->proxy,
- DBUS_ERROR_TIMED_OUT,
- "Did not receive a reply or error",
- c->data);
+ (*c->error_func)(c->proxy, DBUS_ERROR_TIMED_OUT,
+ "Did not receive a reply or error", c->data);
}
}
@@ -551,41 +524,40 @@ pending_call_notify(DBusPendingCall *pending,
}
static void
-pending_call_free_data(void *data)
+pending_call_free_data(void* data)
{
- ReplyClosure *c = data;
+ ReplyClosure* c = data;
reply_closure_free(c);
}
static void
-big_dbus_proxy_send_internal(BigDBusProxy *proxy,
- DBusMessage *message,
- BigDBusProxyReplyFunc plain_func,
- BigDBusProxyJsonReplyFunc json_func,
+big_dbus_proxy_send_internal(BigDBusProxy* proxy,
+ DBusMessage* message,
+ BigDBusProxyReplyFunc plain_func,
+ BigDBusProxyJsonReplyFunc json_func,
BigDBusProxyErrorReplyFunc error_func,
- void *data)
+ void* data)
{
- ReplyClosure *c;
- DBusPendingCall *pending;
+ ReplyClosure* c;
+ DBusPendingCall* pending;
if (!(plain_func || json_func || error_func)) {
/* Fire and forget! */
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Firing and forgetting dbus proxy call");
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Firing and forgetting dbus proxy call");
dbus_connection_send(proxy->connection, message, NULL);
return;
}
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Sending dbus proxy call %s",
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Sending dbus proxy call %s",
dbus_message_get_member(message));
c = reply_closure_new(proxy, plain_func, json_func, error_func, data);
pending = NULL;
- if (!dbus_connection_send_with_reply(proxy->connection, message, &pending, -1) ||
- pending == NULL) {
+ if (!dbus_connection_send_with_reply(proxy->connection, message, &pending,
+ -1)
+ || pending == NULL) {
big_debug(BIG_DEBUG_UTIL_DBUS,
"Failed to send call, will report error in idle handler");
@@ -598,27 +570,30 @@ big_dbus_proxy_send_internal(BigDBusProxy *proxy,
dbus_pending_call_set_notify(pending, pending_call_notify, c,
pending_call_free_data);
- dbus_pending_call_unref(pending); /* DBusConnection should still hold a ref until it's completed */
+ dbus_pending_call_unref(
+ pending); /* DBusConnection should still hold a ref until it's completed
+ */
}
void
-big_dbus_proxy_send(BigDBusProxy *proxy,
- DBusMessage *message,
- BigDBusProxyReplyFunc reply_func,
+big_dbus_proxy_send(BigDBusProxy* proxy,
+ DBusMessage* message,
+ BigDBusProxyReplyFunc reply_func,
BigDBusProxyErrorReplyFunc error_func,
- void *data)
+ void* data)
{
- big_dbus_proxy_send_internal(proxy, message, reply_func, NULL, error_func, data);
+ big_dbus_proxy_send_internal(proxy, message, reply_func, NULL, error_func,
+ data);
}
static void
-append_entries_from_valist(DBusMessageIter *dict_iter,
- const char *first_key,
- va_list args)
+append_entries_from_valist(DBusMessageIter* dict_iter,
+ const char* first_key,
+ va_list args)
{
- const char *key;
+ const char* key;
int dbus_type;
- void *value_p;
+ void* value_p;
key = first_key;
dbus_type = va_arg(args, int);
@@ -638,19 +613,20 @@ append_entries_from_valist(DBusMessageIter *dict_iter,
}
void
-big_dbus_proxy_call_json_async (BigDBusProxy *proxy,
- const char *method_name,
- BigDBusProxyJsonReplyFunc reply_func,
- BigDBusProxyErrorReplyFunc error_func,
- void *data,
- const char *first_key,
- ...)
+big_dbus_proxy_call_json_async(BigDBusProxy* proxy,
+ const char* method_name,
+ BigDBusProxyJsonReplyFunc reply_func,
+ BigDBusProxyErrorReplyFunc error_func,
+ void* data,
+ const char* first_key,
+ ...)
{
DBusMessageIter arg_iter, dict_iter;
- DBusMessage *message;
+ DBusMessage* message;
va_list args;
- message = big_dbus_proxy_new_json_call(proxy, method_name, &arg_iter, &dict_iter);
+ message
+ = big_dbus_proxy_new_json_call(proxy, method_name, &arg_iter, &dict_iter);
if (first_key != NULL) {
va_start(args, first_key);
@@ -660,7 +636,8 @@ big_dbus_proxy_call_json_async (BigDBusProxy *proxy,
dbus_message_iter_close_container(&arg_iter, &dict_iter);
- big_dbus_proxy_send_internal(proxy, message, NULL, reply_func, error_func, data);
+ big_dbus_proxy_send_internal(proxy, message, NULL, reply_func, error_func,
+ data);
dbus_message_unref(message);
}
diff --git a/modules/dbus/util/dbus-proxy.h b/modules/dbus/util/dbus-proxy.h
index 6b793e6..c90e2f4 100644
--- a/modules/dbus/util/dbus-proxy.h
+++ b/modules/dbus/util/dbus-proxy.h
@@ -9,49 +9,52 @@
G_BEGIN_DECLS
-
-typedef struct _BigDBusProxy BigDBusProxy;
+typedef struct _BigDBusProxy BigDBusProxy;
typedef struct _BigDBusProxyClass BigDBusProxyClass;
-typedef void (* BigDBusProxyReplyFunc) (BigDBusProxy *proxy,
- DBusMessage *message,
- void *data);
-typedef void (* BigDBusProxyJsonReplyFunc) (BigDBusProxy *proxy,
- DBusMessage *message,
- DBusMessageIter *return_value_iter,
- void *data);
-typedef void (* BigDBusProxyErrorReplyFunc) (BigDBusProxy *proxy,
- const char *error_name,
- const char *error_message,
- void *data);
-
-#define BIG_TYPE_DBUS_PROXY (big_dbus_proxy_get_type ())
-#define BIG_DBUS_PROXY(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), BIG_TYPE_DBUS_PROXY,
BigDBusProxy))
-#define BIG_DBUS_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BIG_TYPE_DBUS_PROXY,
BigDBusProxyClass))
-#define BIG_IS_DBUS_PROXY(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), BIG_TYPE_DBUS_PROXY))
-#define BIG_IS_DBUS_PROXY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BIG_TYPE_DBUS_PROXY))
-#define BIG_DBUS_PROXY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BIG_TYPE_DBUS_PROXY,
BigDBusProxyClass))
+typedef void (*BigDBusProxyReplyFunc)(BigDBusProxy* proxy,
+ DBusMessage* message,
+ void* data);
+typedef void (*BigDBusProxyJsonReplyFunc)(BigDBusProxy* proxy,
+ DBusMessage* message,
+ DBusMessageIter* return_value_iter,
+ void* data);
+typedef void (*BigDBusProxyErrorReplyFunc)(BigDBusProxy* proxy,
+ const char* error_name,
+ const char* error_message,
+ void* data);
-GType big_dbus_proxy_get_type (void) G_GNUC_CONST;
+#define BIG_TYPE_DBUS_PROXY (big_dbus_proxy_get_type())
+#define BIG_DBUS_PROXY(object) \
+ (G_TYPE_CHECK_INSTANCE_CAST((object), BIG_TYPE_DBUS_PROXY, BigDBusProxy))
+#define BIG_DBUS_PROXY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), BIG_TYPE_DBUS_PROXY, BigDBusProxyClass))
+#define BIG_IS_DBUS_PROXY(object) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((object), BIG_TYPE_DBUS_PROXY))
+#define BIG_IS_DBUS_PROXY_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), BIG_TYPE_DBUS_PROXY))
+#define BIG_DBUS_PROXY_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS((obj), BIG_TYPE_DBUS_PROXY, BigDBusProxyClass))
+GType big_dbus_proxy_get_type(void) G_GNUC_CONST;
-BigDBusProxy* big_dbus_proxy_new (DBusConnection *connection,
- const char *bus_name,
- const char *object_path,
- const char *iface);
-DBusConnection* big_dbus_proxy_get_connection (BigDBusProxy *proxy);
-const char* big_dbus_proxy_get_bus_name (BigDBusProxy *proxy);
-DBusMessage* big_dbus_proxy_new_method_call (BigDBusProxy *proxy,
- const char *method_name);
-DBusMessage* big_dbus_proxy_new_json_call (BigDBusProxy *proxy,
- const char *method_name,
- DBusMessageIter *arg_iter,
- DBusMessageIter *dict_iter);
-void big_dbus_proxy_send (BigDBusProxy *proxy,
- DBusMessage *message,
- BigDBusProxyReplyFunc reply_func,
- BigDBusProxyErrorReplyFunc error_func,
- void *data);
+BigDBusProxy* big_dbus_proxy_new(DBusConnection* connection,
+ const char* bus_name,
+ const char* object_path,
+ const char* iface);
+DBusConnection* big_dbus_proxy_get_connection(BigDBusProxy* proxy);
+const char* big_dbus_proxy_get_bus_name(BigDBusProxy* proxy);
+DBusMessage* big_dbus_proxy_new_method_call(BigDBusProxy* proxy,
+ const char* method_name);
+DBusMessage* big_dbus_proxy_new_json_call(BigDBusProxy* proxy,
+ const char* method_name,
+ DBusMessageIter* arg_iter,
+ DBusMessageIter* dict_iter);
+void big_dbus_proxy_send(BigDBusProxy* proxy,
+ DBusMessage* message,
+ BigDBusProxyReplyFunc reply_func,
+ BigDBusProxyErrorReplyFunc error_func,
+ void* data);
/* varargs are like:
*
@@ -61,14 +64,14 @@ void big_dbus_proxy_send (BigDBusProxy *prox
*
* Basic types only (no arrays)
*/
-void big_dbus_proxy_call_json_async (BigDBusProxy *proxy,
- const char *method_name,
- BigDBusProxyJsonReplyFunc reply_func,
- BigDBusProxyErrorReplyFunc error_func,
- void *data,
- const char *first_key,
- ...);
+void big_dbus_proxy_call_json_async(BigDBusProxy* proxy,
+ const char* method_name,
+ BigDBusProxyJsonReplyFunc reply_func,
+ BigDBusProxyErrorReplyFunc error_func,
+ void* data,
+ const char* first_key,
+ ...);
G_END_DECLS
-#endif /* __BIG_UTIL_DBUS_PROXY_H__ */
+#endif /* __BIG_UTIL_DBUS_PROXY_H__ */
diff --git a/modules/dbus/util/dbus-signals.c b/modules/dbus/util/dbus-signals.c
index f2e5ba2..e91d4e6 100644
--- a/modules/dbus/util/dbus-signals.c
+++ b/modules/dbus/util/dbus-signals.c
@@ -10,41 +10,41 @@
#define INVALID_SIGNAL_ID (-1)
-typedef struct {
- DBusBusType bus_type;
- int refcount;
- char *sender;
- char *path;
- char *iface;
- char *name;
- BigDBusSignalHandler handler;
- void *data;
- GDestroyNotify data_dnotify;
- int id;
- unsigned int matching : 1;
- unsigned int destroyed : 1;
+typedef struct
+{
+ DBusBusType bus_type;
+ int refcount;
+ char* sender;
+ char* path;
+ char* iface;
+ char* name;
+ BigDBusSignalHandler handler;
+ void* data;
+ GDestroyNotify data_dnotify;
+ int id;
+ unsigned int matching : 1;
+ unsigned int destroyed : 1;
} BigSignalWatcher;
-static GSList *pending_signal_watchers = NULL;
-
-static void signal_watcher_remove (DBusConnection *connection,
- BigDBusInfo *info,
- BigSignalWatcher *watcher);
+static GSList* pending_signal_watchers = NULL;
+static void signal_watcher_remove(DBusConnection* connection,
+ BigDBusInfo* info,
+ BigSignalWatcher* watcher);
static int global_handler_id = 0;
static BigSignalWatcher*
-signal_watcher_new(DBusBusType bus_type,
- const char *sender,
- const char *path,
- const char *iface,
- const char *name,
- BigDBusSignalHandler handler,
- void *data,
- GDestroyNotify data_dnotify)
+signal_watcher_new(DBusBusType bus_type,
+ const char* sender,
+ const char* path,
+ const char* iface,
+ const char* name,
+ BigDBusSignalHandler handler,
+ void* data,
+ GDestroyNotify data_dnotify)
{
- BigSignalWatcher *watcher;
+ BigSignalWatcher* watcher;
watcher = g_slice_new0(BigSignalWatcher);
@@ -64,23 +64,23 @@ signal_watcher_new(DBusBusType bus_type,
}
static void
-signal_watcher_dnotify(BigSignalWatcher *watcher)
+signal_watcher_dnotify(BigSignalWatcher* watcher)
{
if (watcher->data_dnotify != NULL) {
- (* watcher->data_dnotify) (watcher->data);
+ (*watcher->data_dnotify)(watcher->data);
watcher->data_dnotify = NULL;
}
watcher->destroyed = TRUE;
}
static void
-signal_watcher_ref(BigSignalWatcher *watcher)
+signal_watcher_ref(BigSignalWatcher* watcher)
{
watcher->refcount += 1;
}
static void
-signal_watcher_unref(BigSignalWatcher *watcher)
+signal_watcher_unref(BigSignalWatcher* watcher)
{
watcher->refcount -= 1;
@@ -97,9 +97,9 @@ signal_watcher_unref(BigSignalWatcher *watcher)
}
static char*
-signal_watcher_build_match_rule(BigSignalWatcher *watcher)
+signal_watcher_build_match_rule(BigSignalWatcher* watcher)
{
- GString *s;
+ GString* s;
s = g_string_new("type='signal'");
@@ -122,10 +122,8 @@ signal_watcher_build_match_rule(BigSignalWatcher *watcher)
return g_string_free(s, FALSE);
}
-
static GSList*
-signal_watcher_table_lookup(GHashTable *table,
- const char *key)
+signal_watcher_table_lookup(GHashTable* table, const char* key)
{
if (table == NULL) {
return NULL;
@@ -135,11 +133,11 @@ signal_watcher_table_lookup(GHashTable *table,
}
static void
-signal_watcher_list_free(void *data)
+signal_watcher_list_free(void* data)
{
- GSList *l = data;
+ GSList* l = data;
while (l != NULL) {
- GSList *next = l->next;
+ GSList* next = l->next;
signal_watcher_unref(l->data);
g_slist_free_1(l);
l = next;
@@ -147,25 +145,22 @@ signal_watcher_list_free(void *data)
}
static void
-signal_watcher_table_add(GHashTable **table_p,
- const char *key,
- BigSignalWatcher *watcher)
+signal_watcher_table_add(GHashTable** table_p,
+ const char* key,
+ BigSignalWatcher* watcher)
{
- GSList *list;
- char *original_key;
+ GSList* list;
+ char* original_key;
if (*table_p == NULL) {
list = NULL;
original_key = g_strdup(key);
- *table_p = g_hash_table_new_full(g_str_hash,
- g_str_equal,
- g_free,
+ *table_p = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
signal_watcher_list_free);
} else {
- if (!g_hash_table_lookup_extended(*table_p,
- key,
- (gpointer*)&original_key,
- (gpointer*)&list)) {
+ if (!g_hash_table_lookup_extended(*table_p, key,
+ (gpointer*) &original_key,
+ (gpointer*) &list)) {
original_key = g_strdup(key);
list = NULL;
}
@@ -179,21 +174,19 @@ signal_watcher_table_add(GHashTable **table_p,
}
static void
-signal_watcher_table_remove(GHashTable *table,
- const char *key,
- BigSignalWatcher *watcher)
+signal_watcher_table_remove(GHashTable* table,
+ const char* key,
+ BigSignalWatcher* watcher)
{
- GSList *list;
- GSList *l;
- char *original_key;
+ GSList* list;
+ GSList* l;
+ char* original_key;
if (table == NULL)
return; /* Never lazily-created the table, nothing ever added */
- if (!g_hash_table_lookup_extended(table,
- key,
- (gpointer*)&original_key,
- (gpointer*)&list)) {
+ if (!g_hash_table_lookup_extended(table, key, (gpointer*) &original_key,
+ (gpointer*) &list)) {
return;
}
@@ -214,10 +207,10 @@ signal_watcher_table_remove(GHashTable *table,
}
static void
-signal_emitter_name_appeared(DBusConnection *connection,
- const char *name,
- const char *new_owner_unique_name,
- void *data)
+signal_emitter_name_appeared(DBusConnection* connection,
+ const char* name,
+ const char* new_owner_unique_name,
+ void* data)
{
/* We don't need to do anything here, we installed a name watch so
* we could call big_dbus_get_watched_name_owner() to dispatch
@@ -226,26 +219,25 @@ signal_emitter_name_appeared(DBusConnection *connection,
}
static void
-signal_emitter_name_vanished(DBusConnection *connection,
- const char *name,
- const char *old_owner_unique_name,
- void *data)
+signal_emitter_name_vanished(DBusConnection* connection,
+ const char* name,
+ const char* old_owner_unique_name,
+ void* data)
{
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Signal emitter '%s' is now gone",
- name);
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Signal emitter '%s' is now gone", name);
/* If a watcher is matching on a unique name sender, once the unique
* name goes away, the watcher can never see anything so nuke it.
*/
if (*name == ':') {
- GSList *list;
- BigDBusInfo *info;
+ GSList* list;
+ BigDBusInfo* info;
info = _big_dbus_ensure_info(connection);
- list = signal_watcher_table_lookup(info->signal_watchers_by_unique_sender,
- name);
+ list
+ = signal_watcher_table_lookup(info->signal_watchers_by_unique_sender,
+ name);
if (list == NULL)
return;
@@ -261,17 +253,15 @@ signal_emitter_name_vanished(DBusConnection *connection,
}
}
-static BigDBusWatchNameFuncs signal_emitter_name_funcs = {
- signal_emitter_name_appeared,
- signal_emitter_name_vanished
-};
+static BigDBusWatchNameFuncs signal_emitter_name_funcs
+ = { signal_emitter_name_appeared, signal_emitter_name_vanished };
static void
-signal_watcher_set_matching(DBusConnection *connection,
- BigSignalWatcher *watcher,
- gboolean matching)
+signal_watcher_set_matching(DBusConnection* connection,
+ BigSignalWatcher* watcher,
+ gboolean matching)
{
- char *rule;
+ char* rule;
if (watcher->matching == (matching != FALSE)) {
return;
@@ -291,8 +281,8 @@ signal_watcher_set_matching(DBusConnection *connection,
rule = signal_watcher_build_match_rule(watcher);
if (matching)
- dbus_bus_add_match(connection,
- rule, NULL); /* asking for error would make this block */
+ dbus_bus_add_match(connection, rule,
+ NULL); /* asking for error would make this block */
else
dbus_bus_remove_match(connection, rule, NULL);
@@ -306,115 +296,102 @@ signal_watcher_set_matching(DBusConnection *connection,
* the watcher if the unique name goes away
*/
if (matching) {
- big_dbus_watch_name(watcher->bus_type,
- watcher->sender,
- 0,
- &signal_emitter_name_funcs,
- NULL);
+ big_dbus_watch_name(watcher->bus_type, watcher->sender, 0,
+ &signal_emitter_name_funcs, NULL);
} else {
- big_dbus_unwatch_name(watcher->bus_type,
- watcher->sender,
- &signal_emitter_name_funcs,
- NULL);
+ big_dbus_unwatch_name(watcher->bus_type, watcher->sender,
+ &signal_emitter_name_funcs, NULL);
}
}
}
static void
-signal_watcher_add(DBusConnection *connection,
- BigDBusInfo *info,
- BigSignalWatcher *watcher)
+signal_watcher_add(DBusConnection* connection,
+ BigDBusInfo* info,
+ BigSignalWatcher* watcher)
{
gboolean in_some_table;
signal_watcher_set_matching(connection, watcher, TRUE);
- info->all_signal_watchers = g_slist_prepend(info->all_signal_watchers, watcher);
+ info->all_signal_watchers
+ = g_slist_prepend(info->all_signal_watchers, watcher);
signal_watcher_ref(watcher);
in_some_table = FALSE;
if (watcher->sender && *(watcher->sender) == ':') {
signal_watcher_table_add(&info->signal_watchers_by_unique_sender,
- watcher->sender,
- watcher);
+ watcher->sender, watcher);
in_some_table = TRUE;
}
if (watcher->path) {
- signal_watcher_table_add(&info->signal_watchers_by_path,
- watcher->path,
+ signal_watcher_table_add(&info->signal_watchers_by_path, watcher->path,
watcher);
in_some_table = TRUE;
}
if (watcher->iface) {
signal_watcher_table_add(&info->signal_watchers_by_iface,
- watcher->iface,
- watcher);
+ watcher->iface, watcher);
in_some_table = TRUE;
}
if (watcher->name) {
signal_watcher_table_add(&info->signal_watchers_by_signal,
- watcher->name,
- watcher);
+ watcher->name, watcher);
in_some_table = TRUE;
}
if (!in_some_table) {
- info->signal_watchers_in_no_table =
- g_slist_prepend(info->signal_watchers_in_no_table,
- watcher);
+ info->signal_watchers_in_no_table
+ = g_slist_prepend(info->signal_watchers_in_no_table, watcher);
signal_watcher_ref(watcher);
}
}
static void
-signal_watcher_remove(DBusConnection *connection,
- BigDBusInfo *info,
- BigSignalWatcher *watcher)
+signal_watcher_remove(DBusConnection* connection,
+ BigDBusInfo* info,
+ BigSignalWatcher* watcher)
{
gboolean in_some_table;
signal_watcher_set_matching(connection, watcher, FALSE);
- info->all_signal_watchers = g_slist_remove(info->all_signal_watchers, watcher);
+ info->all_signal_watchers
+ = g_slist_remove(info->all_signal_watchers, watcher);
in_some_table = FALSE;
if (watcher->sender && *(watcher->sender) == ':') {
signal_watcher_table_remove(info->signal_watchers_by_unique_sender,
- watcher->sender,
- watcher);
+ watcher->sender, watcher);
in_some_table = TRUE;
}
if (watcher->path) {
signal_watcher_table_remove(info->signal_watchers_by_path,
- watcher->path,
- watcher);
+ watcher->path, watcher);
in_some_table = TRUE;
}
if (watcher->iface) {
signal_watcher_table_remove(info->signal_watchers_by_iface,
- watcher->iface,
- watcher);
+ watcher->iface, watcher);
in_some_table = TRUE;
}
if (watcher->name) {
signal_watcher_table_remove(info->signal_watchers_by_signal,
- watcher->name,
- watcher);
+ watcher->name, watcher);
in_some_table = TRUE;
}
if (!in_some_table) {
- info->signal_watchers_in_no_table =
- g_slist_remove(info->signal_watchers_in_no_table,
- watcher);
+ info->signal_watchers_in_no_table
+ = g_slist_remove(info->signal_watchers_in_no_table, watcher);
signal_watcher_unref(watcher);
}
@@ -433,14 +410,14 @@ signal_watcher_remove(DBusConnection *connection,
* callback needs to be first.
*/
void
-_big_dbus_process_pending_signal_watchers(DBusConnection *connection,
- BigDBusInfo *info)
+_big_dbus_process_pending_signal_watchers(DBusConnection* connection,
+ BigDBusInfo* info)
{
- GSList *remaining;
+ GSList* remaining;
remaining = NULL;
while (pending_signal_watchers) {
- BigSignalWatcher *watcher = pending_signal_watchers->data;
+ BigSignalWatcher* watcher = pending_signal_watchers->data;
pending_signal_watchers = g_slist_delete_link(pending_signal_watchers,
pending_signal_watchers);
@@ -460,8 +437,7 @@ _big_dbus_process_pending_signal_watchers(DBusConnection *connection,
}
static void
-signal_watchers_disconnected(DBusConnection *connection,
- BigDBusInfo *info)
+signal_watchers_disconnected(DBusConnection* connection, BigDBusInfo* info)
{
/* None should be pending on this bus, because at start of
* _big_dbus_signal_watch_filter_message() we process all the pending ones.
@@ -469,26 +445,23 @@ signal_watchers_disconnected(DBusConnection *connection,
* another bus. Anyway bottom line we can ignore pending_signal_watchers
* in here.
*/
- GSList *list;
- GSList *destroyed;
+ GSList* list;
+ GSList* destroyed;
/* Build a separate list to destroy to avoid re-entrancy as we are
* walking the list
*/
destroyed = NULL;
- for (list = info->all_signal_watchers;
- list != NULL;
- list = list->next) {
- BigSignalWatcher *watcher = list->data;
+ for (list = info->all_signal_watchers; list != NULL; list = list->next) {
+ BigSignalWatcher* watcher = list->data;
if (watcher->sender && *(watcher->sender) == ':') {
- destroyed = g_slist_prepend(destroyed,
- watcher);
+ destroyed = g_slist_prepend(destroyed, watcher);
signal_watcher_ref(watcher);
}
}
while (destroyed != NULL) {
- BigSignalWatcher *watcher = destroyed->data;
+ BigSignalWatcher* watcher = destroyed->data;
destroyed = g_slist_delete_link(destroyed, destroyed);
signal_watcher_remove(connection, info, watcher);
@@ -497,46 +470,39 @@ signal_watchers_disconnected(DBusConnection *connection,
}
static void
-concat_candidates(GSList **candidates_p,
- GHashTable *table,
- const char *key)
+concat_candidates(GSList** candidates_p, GHashTable* table, const char* key)
{
- GSList *list;
+ GSList* list;
list = signal_watcher_table_lookup(table, key);
if (list == NULL)
return;
- *candidates_p = g_slist_concat(*candidates_p,
- g_slist_copy(list));
+ *candidates_p = g_slist_concat(*candidates_p, g_slist_copy(list));
}
static int
-direct_cmp(gconstpointer a,
- gconstpointer b)
+direct_cmp(gconstpointer a, gconstpointer b)
{
/* gcc dislikes pointer math on void* so cast */
- return ((const char*)a) - ((const char*)b);
+ return ((const char*) a) - ((const char*) b);
}
static gboolean
-signal_watcher_watches(BigDBusInfo *info,
- BigSignalWatcher *watcher,
- const char *sender,
- const char *path,
- const char *iface,
- const char *name)
+signal_watcher_watches(BigDBusInfo* info,
+ BigSignalWatcher* watcher,
+ const char* sender,
+ const char* path,
+ const char* iface,
+ const char* name)
{
- if (watcher->path &&
- strcmp(watcher->path, path) != 0)
+ if (watcher->path && strcmp(watcher->path, path) != 0)
return FALSE;
- if (watcher->iface &&
- strcmp(watcher->iface, iface) != 0)
+ if (watcher->iface && strcmp(watcher->iface, iface) != 0)
return FALSE;
- if (watcher->name &&
- strcmp(watcher->name, name) != 0)
+ if (watcher->name && strcmp(watcher->name, name) != 0)
return FALSE;
/* "sender" from message is always the unique name, but
@@ -546,17 +512,15 @@ signal_watcher_watches(BigDBusInfo *info,
if (watcher->sender == NULL)
return TRUE;
-
- if (* (watcher->sender) == ':') {
+ if (*(watcher->sender) == ':') {
return strcmp(watcher->sender, sender) == 0;
} else {
- const char *owner;
+ const char* owner;
- owner = big_dbus_get_watched_name_owner(info->bus_type,
- watcher->sender);
+ owner
+ = big_dbus_get_watched_name_owner(info->bus_type, watcher->sender);
- if (owner != NULL &&
- strcmp(sender, owner) == 0)
+ if (owner != NULL && strcmp(sender, owner) == 0)
return TRUE;
else
return FALSE;
@@ -564,9 +528,9 @@ signal_watcher_watches(BigDBusInfo *info,
}
DBusHandlerResult
-_big_dbus_signal_watch_filter_message(DBusConnection *connection,
- DBusMessage *message,
- void *data)
+_big_dbus_signal_watch_filter_message(DBusConnection* connection,
+ DBusMessage* message,
+ void* data)
{
/* Two things we're looking for
* 1) signals
@@ -574,13 +538,13 @@ _big_dbus_signal_watch_filter_message(DBusConnection *connection,
* we want to destroy notify when it vanishes or
* when the bus disconnects.
*/
- BigDBusInfo *info;
- const char *sender;
- const char *path;
- const char *iface;
- const char *name;
- GSList *candidates;
- BigSignalWatcher *previous;
+ BigDBusInfo* info;
+ const char* sender;
+ const char* path;
+ const char* iface;
+ const char* name;
+ GSList* candidates;
+ BigSignalWatcher* previous;
info = _big_dbus_ensure_info(connection);
@@ -603,35 +567,28 @@ _big_dbus_signal_watch_filter_message(DBusConnection *connection,
g_assert(iface != NULL);
g_assert(name != NULL);
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Signal from %s %s.%s sender %s",
- path, iface, name, sender ? sender : "(none)");
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Signal from %s %s.%s sender %s", path,
+ iface, name, sender ? sender : "(none)");
candidates = NULL;
if (sender != NULL) {
- concat_candidates(&candidates,
- info->signal_watchers_by_unique_sender,
+ concat_candidates(&candidates, info->signal_watchers_by_unique_sender,
sender);
}
- concat_candidates(&candidates,
- info->signal_watchers_by_path,
- path);
- concat_candidates(&candidates,
- info->signal_watchers_by_iface,
- iface);
- concat_candidates(&candidates,
- info->signal_watchers_by_signal,
- name);
- candidates = g_slist_concat(candidates,
- g_slist_copy(info->signal_watchers_in_no_table));
+ concat_candidates(&candidates, info->signal_watchers_by_path, path);
+ concat_candidates(&candidates, info->signal_watchers_by_iface, iface);
+ concat_candidates(&candidates, info->signal_watchers_by_signal, name);
+ candidates
+ = g_slist_concat(candidates,
+ g_slist_copy(info->signal_watchers_in_no_table));
/* Sort so we can find dups */
candidates = g_slist_sort(candidates, direct_cmp);
previous = NULL;
while (candidates != NULL) {
- BigSignalWatcher *watcher;
+ BigSignalWatcher* watcher;
watcher = candidates->data;
candidates = g_slist_delete_link(candidates, candidates);
@@ -641,9 +598,7 @@ _big_dbus_signal_watch_filter_message(DBusConnection *connection,
previous = watcher;
- if (!signal_watcher_watches(info,
- watcher,
- sender, path, iface, name))
+ if (!signal_watcher_watches(info, watcher, sender, path, iface, name))
continue;
/* destroyed would happen if e.g. removed while we are going
@@ -656,9 +611,7 @@ _big_dbus_signal_watch_filter_message(DBusConnection *connection,
signal_watcher_ref(watcher);
- (* watcher->handler) (connection,
- message,
- watcher->data);
+ (*watcher->handler)(connection, message, watcher->data);
signal_watcher_unref(watcher);
}
@@ -676,20 +629,19 @@ _big_dbus_signal_watch_filter_message(DBusConnection *connection,
}
int
-big_dbus_watch_signal(DBusBusType bus_type,
- const char *sender,
- const char *path,
- const char *iface,
- const char *name,
- BigDBusSignalHandler handler,
- void *data,
- GDestroyNotify data_dnotify)
+big_dbus_watch_signal(DBusBusType bus_type,
+ const char* sender,
+ const char* path,
+ const char* iface,
+ const char* name,
+ BigDBusSignalHandler handler,
+ void* data,
+ GDestroyNotify data_dnotify)
{
- BigSignalWatcher *watcher;
- DBusConnection *weak;
+ BigSignalWatcher* watcher;
+ DBusConnection* weak;
- watcher = signal_watcher_new(bus_type, sender, path,
- iface, name, handler,
+ watcher = signal_watcher_new(bus_type, sender, path, iface, name, handler,
data, data_dnotify);
/* If we're already connected, it's essential to get the
@@ -716,7 +668,8 @@ big_dbus_watch_signal(DBusBusType bus_type,
signal_watcher_add(weak, _big_dbus_ensure_info(weak), watcher);
signal_watcher_unref(watcher);
} else {
- pending_signal_watchers = g_slist_prepend(pending_signal_watchers, watcher);
+ pending_signal_watchers
+ = g_slist_prepend(pending_signal_watchers, watcher);
_big_dbus_ensure_connect_idle(bus_type);
}
@@ -725,15 +678,15 @@ big_dbus_watch_signal(DBusBusType bus_type,
/* Does the watcher match a removal request? */
static gboolean
-signal_watcher_matches(BigSignalWatcher *watcher,
- DBusBusType bus_type,
- const char *sender,
- const char *path,
- const char *iface,
- const char *name,
- int id,
- BigDBusSignalHandler handler,
- void *data)
+signal_watcher_matches(BigSignalWatcher* watcher,
+ DBusBusType bus_type,
+ const char* sender,
+ const char* path,
+ const char* iface,
+ const char* name,
+ int id,
+ BigDBusSignalHandler handler,
+ void* data)
{
/* If we have an ID, check that first. If it matches, we are
* done
@@ -770,44 +723,36 @@ signal_watcher_matches(BigSignalWatcher *watcher,
}
static void
-unwatch_signal(DBusBusType bus_type,
- const char *sender,
- const char *path,
- const char *iface,
- const char *name,
- int id,
- BigDBusSignalHandler handler,
- void *data)
+unwatch_signal(DBusBusType bus_type,
+ const char* sender,
+ const char* path,
+ const char* iface,
+ const char* name,
+ int id,
+ BigDBusSignalHandler handler,
+ void* data)
{
- GSList *list;
- DBusConnection *weak;
- BigDBusInfo *info;
+ GSList* list;
+ DBusConnection* weak;
+ BigDBusInfo* info;
/* Always remove only ONE watcher (the first one we find) */
weak = _big_dbus_get_weak_ref(bus_type);
/* First see if it's still pending */
- for (list = pending_signal_watchers;
- list != NULL;
- list = list->next) {
- if (signal_watcher_matches(list->data,
- bus_type,
- sender,
- path,
- iface,
- name,
- id,
- handler,
- data)) {
- BigSignalWatcher *watcher = list->data;
- pending_signal_watchers = g_slist_remove_link(pending_signal_watchers,
- list);
+ for (list = pending_signal_watchers; list != NULL; list = list->next) {
+ if (signal_watcher_matches(list->data, bus_type, sender, path, iface,
+ name, id, handler, data)) {
+ BigSignalWatcher* watcher = list->data;
+ pending_signal_watchers
+ = g_slist_remove_link(pending_signal_watchers, list);
if (weak != NULL)
signal_watcher_set_matching(weak, watcher, FALSE);
- signal_watcher_dnotify(watcher); /* destroy even if we don't finalize */
+ signal_watcher_dnotify(
+ watcher); /* destroy even if we don't finalize */
signal_watcher_unref(watcher);
return;
}
@@ -823,18 +768,9 @@ unwatch_signal(DBusBusType bus_type,
info = _big_dbus_ensure_info(weak);
- for (list = info->all_signal_watchers;
- list != NULL;
- list = list->next) {
- if (signal_watcher_matches(list->data,
- bus_type,
- sender,
- path,
- iface,
- name,
- id,
- handler,
- data)) {
+ for (list = info->all_signal_watchers; list != NULL; list = list->next) {
+ if (signal_watcher_matches(list->data, bus_type, sender, path, iface,
+ name, id, handler, data)) {
signal_watcher_remove(weak, info, list->data);
/* note that "list" node is now invalid */
return;
@@ -847,36 +783,23 @@ unwatch_signal(DBusBusType bus_type,
}
void
-big_dbus_unwatch_signal(DBusBusType bus_type,
- const char *sender,
- const char *path,
- const char *iface,
- const char *name,
- BigDBusSignalHandler handler,
- void *data)
+big_dbus_unwatch_signal(DBusBusType bus_type,
+ const char* sender,
+ const char* path,
+ const char* iface,
+ const char* name,
+ BigDBusSignalHandler handler,
+ void* data)
{
- unwatch_signal(bus_type,
- sender,
- path,
- iface,
- name,
- INVALID_SIGNAL_ID,
- handler,
- data);
+ unwatch_signal(bus_type, sender, path, iface, name, INVALID_SIGNAL_ID,
+ handler, data);
}
void
-big_dbus_unwatch_signal_by_id(DBusBusType bus_type,
- int id)
+big_dbus_unwatch_signal_by_id(DBusBusType bus_type, int id)
{
- unwatch_signal(bus_type,
- NULL,
- NULL,
- NULL,
- NULL,
- id,
- (BigDBusSignalHandler)NULL,
- NULL);
+ unwatch_signal(bus_type, NULL, NULL, NULL, NULL, id,
+ (BigDBusSignalHandler) NULL, NULL);
}
#if BIG_BUILD_TESTS
@@ -892,29 +815,29 @@ big_dbus_unwatch_signal_by_id(DBusBusType bus_type,
#include <sys/wait.h>
static pid_t test_service_pid = 0;
-static BigDBusProxy *test_service_proxy = NULL;
+static BigDBusProxy* test_service_proxy = NULL;
-static GMainLoop *outer_loop = NULL;
-static GMainLoop *inner_loop = NULL;
+static GMainLoop* outer_loop = NULL;
+static GMainLoop* inner_loop = NULL;
static int n_running_children = 0;
-typedef struct {
- const char *sender;
- const char *path;
- const char *iface;
- const char *member;
+typedef struct
+{
+ const char* sender;
+ const char* path;
+ const char* iface;
+ const char* member;
} SignalWatchTest;
-static SignalWatchTest watch_tests[] = {
- { NULL, NULL, NULL, NULL },
- { "com.litl.TestService", NULL, NULL, NULL },
- { NULL, "/com/litl/test/object42", NULL, NULL },
- { NULL, NULL, "com.litl.TestIface", NULL },
- { NULL, NULL, NULL, "TheSignal" }
-};
+static SignalWatchTest watch_tests[]
+ = { { NULL, NULL, NULL, NULL },
+ { "com.litl.TestService", NULL, NULL, NULL },
+ { NULL, "/com/litl/test/object42", NULL, NULL },
+ { NULL, NULL, "com.litl.TestIface", NULL },
+ { NULL, NULL, NULL, "TheSignal" } };
-static void do_test_service_child (void);
+static void do_test_service_child(void);
/* quit when all children are gone */
static void
@@ -962,7 +885,8 @@ static void
kill_child(void)
{
if (kill(test_service_pid, SIGTERM) < 0) {
- g_error("Test service was no longer around... it must have failed somehow (%s)",
+ g_error("Test service was no longer around... it must have failed "
+ "somehow (%s)",
strerror(errno));
}
@@ -973,31 +897,28 @@ static int signal_received_count = 0;
static int destroy_notify_count = 0;
static void
-the_destroy_notifier(void *data)
+the_destroy_notifier(void* data)
{
- big_debug(BIG_DEBUG_IN_TESTS,
- "got destroy notification on signal watch");
+ big_debug(BIG_DEBUG_IN_TESTS, "got destroy notification on signal watch");
destroy_notify_count += 1;
}
static void
-the_destroy_notifier_that_quits(void *data)
+the_destroy_notifier_that_quits(void* data)
{
the_destroy_notifier(data);
g_main_loop_quit(inner_loop);
}
static void
-expect_receive_signal_handler(DBusConnection *connection,
- DBusMessage *message,
- void *data)
+expect_receive_signal_handler(DBusConnection* connection,
+ DBusMessage* message,
+ void* data)
{
- big_debug(BIG_DEBUG_IN_TESTS,
- "dbus signal watch handler called");
+ big_debug(BIG_DEBUG_IN_TESTS, "dbus signal watch handler called");
- g_assert(dbus_message_is_signal(message,
- "com.litl.TestIface",
- "TheSignal"));
+ g_assert(
+ dbus_message_is_signal(message, "com.litl.TestIface", "TheSignal"));
signal_received_count += 1;
@@ -1005,73 +926,51 @@ expect_receive_signal_handler(DBusConnection *connection,
}
static void
-test_match_combo(const char *sender,
- const char *path,
- const char *iface,
- const char *member)
+test_match_combo(const char* sender,
+ const char* path,
+ const char* iface,
+ const char* member)
{
signal_received_count = 0;
destroy_notify_count = 0;
- big_debug(BIG_DEBUG_IN_TESTS,
- "Watching %s %s %s %s",
- sender,
- path,
- iface,
+ big_debug(BIG_DEBUG_IN_TESTS, "Watching %s %s %s %s", sender, path, iface,
member);
- big_dbus_watch_signal(DBUS_BUS_SESSION,
- sender,
- path,
- iface,
- member,
- expect_receive_signal_handler,
- GINT_TO_POINTER(1),
+ big_dbus_watch_signal(DBUS_BUS_SESSION, sender, path, iface, member,
+ expect_receive_signal_handler, GINT_TO_POINTER(1),
the_destroy_notifier);
- big_dbus_proxy_call_json_async(test_service_proxy,
- "emitTheSignal",
- NULL,
- NULL,
- NULL,
- NULL);
+ big_dbus_proxy_call_json_async(test_service_proxy, "emitTheSignal", NULL,
+ NULL, NULL, NULL);
g_main_loop_run(inner_loop);
g_assert(signal_received_count == 1);
g_assert(destroy_notify_count == 0);
- big_dbus_unwatch_signal(DBUS_BUS_SESSION,
- sender,
- path,
- iface,
- member,
- expect_receive_signal_handler,
- GINT_TO_POINTER(1));
+ big_dbus_unwatch_signal(DBUS_BUS_SESSION, sender, path, iface, member,
+ expect_receive_signal_handler, GINT_TO_POINTER(1));
g_assert(destroy_notify_count == 1);
}
static gboolean
-run_signal_tests_idle(void *data)
+run_signal_tests_idle(void* data)
{
int i;
- const char *unique_name;
+ const char* unique_name;
for (i = 0; i < (int) G_N_ELEMENTS(watch_tests); ++i) {
- SignalWatchTest *test = &watch_tests[i];
+ SignalWatchTest* test = &watch_tests[i];
- test_match_combo(test->sender,
- test->path,
- test->iface,
- test->member);
+ test_match_combo(test->sender, test->path, test->iface, test->member);
}
/* Now try on the unique bus name */
unique_name = big_dbus_proxy_get_bus_name(test_service_proxy);
- test_match_combo(unique_name,
- NULL, NULL, NULL);
+ test_match_combo(unique_name, NULL, NULL, NULL);
/* Now test we get destroy notify when the unique name disappears
* on killing the child.
@@ -1079,15 +978,10 @@ run_signal_tests_idle(void *data)
signal_received_count = 0;
destroy_notify_count = 0;
- big_debug(BIG_DEBUG_IN_TESTS,
- "Watching unique name %s",
- unique_name);
+ big_debug(BIG_DEBUG_IN_TESTS, "Watching unique name %s", unique_name);
- big_dbus_watch_signal(DBUS_BUS_SESSION,
- unique_name,
- NULL, NULL, NULL,
- expect_receive_signal_handler,
- GINT_TO_POINTER(1),
+ big_dbus_watch_signal(DBUS_BUS_SESSION, unique_name, NULL, NULL, NULL,
+ expect_receive_signal_handler, GINT_TO_POINTER(1),
the_destroy_notifier_that_quits);
/* kill owner of unique_name */
@@ -1101,11 +995,8 @@ run_signal_tests_idle(void *data)
g_assert(destroy_notify_count > 0);
g_assert(destroy_notify_count < 2);
- big_dbus_unwatch_signal(DBUS_BUS_SESSION,
- unique_name,
- NULL, NULL, NULL,
- expect_receive_signal_handler,
- GINT_TO_POINTER(1));
+ big_dbus_unwatch_signal(DBUS_BUS_SESSION, unique_name, NULL, NULL, NULL,
+ expect_receive_signal_handler, GINT_TO_POINTER(1));
g_assert(signal_received_count == 0);
g_assert(destroy_notify_count == 1);
@@ -1115,41 +1006,35 @@ run_signal_tests_idle(void *data)
}
static void
-on_test_service_appeared(DBusConnection *connection,
- const char *name,
- const char *new_owner_unique_name,
- void *data)
+on_test_service_appeared(DBusConnection* connection,
+ const char* name,
+ const char* new_owner_unique_name,
+ void* data)
{
- big_debug(BIG_DEBUG_IN_TESTS,
- "%s appeared",
- name);
+ big_debug(BIG_DEBUG_IN_TESTS, "%s appeared", name);
inner_loop = g_main_loop_new(NULL, FALSE);
- test_service_proxy =
- big_dbus_proxy_new(connection, new_owner_unique_name,
- "/com/litl/test/object42",
- "com.litl.TestIface");
+ test_service_proxy
+ = big_dbus_proxy_new(connection, new_owner_unique_name,
+ "/com/litl/test/object42", "com.litl.TestIface");
g_idle_add(run_signal_tests_idle, NULL);
}
static void
-on_test_service_vanished(DBusConnection *connection,
- const char *name,
- const char *old_owner_unique_name,
- void *data)
+on_test_service_vanished(DBusConnection* connection,
+ const char* name,
+ const char* old_owner_unique_name,
+ void* data)
{
- big_debug(BIG_DEBUG_IN_TESTS,
- "%s vanished", name);
+ big_debug(BIG_DEBUG_IN_TESTS, "%s vanished", name);
another_child_down();
}
-static BigDBusWatchNameFuncs watch_test_service_funcs = {
- on_test_service_appeared,
- on_test_service_vanished
-};
+static BigDBusWatchNameFuncs watch_test_service_funcs
+ = { on_test_service_appeared, on_test_service_vanished };
void
bigtest_test_func_util_dbus_signals_client(void)
@@ -1175,11 +1060,8 @@ bigtest_test_func_util_dbus_signals_client(void)
/* We rely on the child-forking test functions being called first */
g_assert(test_service_pid != 0);
- big_dbus_watch_name(DBUS_BUS_SESSION,
- "com.litl.TestService",
- 0,
- &watch_test_service_funcs,
- NULL);
+ big_dbus_watch_name(DBUS_BUS_SESSION, "com.litl.TestService", 0,
+ &watch_test_service_funcs, NULL);
outer_loop = g_main_loop_new(NULL, FALSE);
@@ -1188,8 +1070,7 @@ bigtest_test_func_util_dbus_signals_client(void)
if (test_service_proxy != NULL)
g_object_unref(test_service_proxy);
- big_debug(BIG_DEBUG_IN_TESTS,
- "waitpid() for first child");
+ big_debug(BIG_DEBUG_IN_TESTS, "waitpid() for first child");
result = waitpid(test_service_pid, &status, 0);
if (result < 0) {
@@ -1197,11 +1078,13 @@ bigtest_test_func_util_dbus_signals_client(void)
}
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
- g_error("Forked dbus service child exited with error code %d", WEXITSTATUS(status));
+ g_error("Forked dbus service child exited with error code %d",
+ WEXITSTATUS(status));
}
if (WIFSIGNALED(status) && WTERMSIG(status) != SIGTERM) {
- g_error("Forked dbus service child exited on wrong signal number %d", WTERMSIG(status));
+ g_error("Forked dbus service child exited on wrong signal number %d",
+ WTERMSIG(status));
}
big_debug(BIG_DEBUG_IN_TESTS, "dbus signals test completed");
@@ -1224,90 +1107,74 @@ bigtest_test_func_util_dbus_signals_client(void)
*/
static gboolean currently_have_test_service = FALSE;
-static GObject *test_service_object = NULL;
+static GObject* test_service_object = NULL;
static void
-test_service_emit_the_signal(DBusConnection *connection,
- DBusMessage *message,
- DBusMessageIter *in_iter,
- DBusMessageIter *out_iter,
- void *data,
- DBusError *error)
+test_service_emit_the_signal(DBusConnection* connection,
+ DBusMessage* message,
+ DBusMessageIter* in_iter,
+ DBusMessageIter* out_iter,
+ void* data,
+ DBusError* error)
{
- DBusMessage *signal;
+ DBusMessage* signal;
signal = dbus_message_new_signal("/com/litl/test/object42",
- "com.litl.TestIface",
- "TheSignal");
+ "com.litl.TestIface", "TheSignal");
dbus_connection_send(connection, signal, NULL);
dbus_message_unref(signal);
}
-static BigDBusJsonMethod test_service_methods[] = {
- { "emitTheSignal", test_service_emit_the_signal, NULL }
-};
+static BigDBusJsonMethod test_service_methods[]
+ = { { "emitTheSignal", test_service_emit_the_signal, NULL } };
static void
-on_test_service_acquired(DBusConnection *connection,
- const char *name,
- void *data)
+on_test_service_acquired(DBusConnection* connection,
+ const char* name,
+ void* data)
{
g_assert(!currently_have_test_service);
currently_have_test_service = TRUE;
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestService acquired by child");
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestService acquired by child");
- big_dbus_register_json(connection,
- "com.litl.TestIface",
+ big_dbus_register_json(connection, "com.litl.TestIface",
test_service_methods,
G_N_ELEMENTS(test_service_methods));
test_service_object = g_object_new(G_TYPE_OBJECT, NULL);
- big_dbus_register_g_object(connection,
- "/com/litl/test/object42",
- test_service_object,
- "com.litl.TestIface");
+ big_dbus_register_g_object(connection, "/com/litl/test/object42",
+ test_service_object, "com.litl.TestIface");
}
static void
-on_test_service_lost(DBusConnection *connection,
- const char *name,
- void *data)
+on_test_service_lost(DBusConnection* connection, const char* name, void* data)
{
g_assert(currently_have_test_service);
currently_have_test_service = FALSE;
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestService lost by child");
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestService lost by child");
- big_dbus_unregister_g_object(connection,
- "/com/litl/test/object42");
+ big_dbus_unregister_g_object(connection, "/com/litl/test/object42");
- big_dbus_unregister_json(connection,
- "com.litl.TestIface");
+ big_dbus_unregister_json(connection, "com.litl.TestIface");
}
-static BigDBusNameOwnerFuncs test_service_funcs = {
- "com.litl.TestService",
- DBUS_BUS_SESSION,
- on_test_service_acquired,
- on_test_service_lost
-};
+static BigDBusNameOwnerFuncs test_service_funcs
+ = { "com.litl.TestService", DBUS_BUS_SESSION, on_test_service_acquired,
+ on_test_service_lost };
static void
do_test_service_child(void)
{
- GMainLoop *loop;
+ GMainLoop* loop;
g_type_init();
loop = g_main_loop_new(NULL, FALSE);
- big_dbus_acquire_name(DBUS_BUS_SESSION,
- &test_service_funcs,
- NULL);
+ big_dbus_acquire_name(DBUS_BUS_SESSION, &test_service_funcs, NULL);
g_main_loop_run(loop);
diff --git a/modules/dbus/util/dbus.c b/modules/dbus/util/dbus.c
index 89adf27..a918059 100644
--- a/modules/dbus/util/dbus.c
+++ b/modules/dbus/util/dbus.c
@@ -16,9 +16,10 @@
#include "log.h"
#include "glib.h"
-typedef struct {
- const BigDBusConnectFuncs *funcs;
- void *data;
+typedef struct
+{
+ const BigDBusConnectFuncs* funcs;
+ void* data;
unsigned int opened : 1;
} ConnectFuncs;
@@ -29,84 +30,90 @@ typedef enum {
NAME_NOT_OWNED
} NameOwnershipState;
-typedef struct {
- char *name;
- const BigDBusJsonMethod *methods;
+typedef struct
+{
+ char* name;
+ const BigDBusJsonMethod* methods;
int n_methods;
} BigJsonIface;
-typedef struct {
+typedef struct
+{
DBusBusType bus_type;
/* If prev_state != state then we may need to notify */
NameOwnershipState prev_state;
NameOwnershipState state;
- const BigDBusNameOwnerFuncs *funcs;
- void *data;
+ const BigDBusNameOwnerFuncs* funcs;
+ void* data;
unsigned int id;
} BigNameOwnershipMonitor;
-typedef struct {
- char *name;
- char *current_owner;
- GSList *watchers;
+typedef struct
+{
+ char* name;
+ char* current_owner;
+ GSList* watchers;
} BigNameWatch;
-typedef struct {
+typedef struct
+{
BigDBusWatchNameFlags flags;
- const BigDBusWatchNameFuncs *funcs;
- void *data;
+ const BigDBusWatchNameFuncs* funcs;
+ void* data;
DBusBusType bus_type;
- BigNameWatch *watch;
+ BigNameWatch* watch;
guint notify_idle;
int refcount;
guint destroyed : 1;
} BigNameWatcher;
-typedef struct {
+typedef struct
+{
DBusBusType bus_type;
- char *name;
- BigNameWatcher *watcher;
+ char* name;
+ BigNameWatcher* watcher;
} BigPendingNameWatcher;
-static DBusConnection *session_bus_weak_ref = NULL;
-static GSList *session_bus_weak_refs = NULL;
-static DBusConnection *system_bus_weak_ref = NULL;
-static GSList *system_bus_weak_refs = NULL;
+static DBusConnection* session_bus_weak_ref = NULL;
+static GSList* session_bus_weak_refs = NULL;
+static DBusConnection* system_bus_weak_ref = NULL;
+static GSList* system_bus_weak_refs = NULL;
static guint session_connect_idle_id = 0;
static guint system_connect_idle_id = 0;
-static GSList *all_connect_funcs = NULL;
+static GSList* all_connect_funcs = NULL;
-static GSList *pending_name_ownership_monitors = NULL;
-static GSList *pending_name_watchers = NULL;
+static GSList* pending_name_ownership_monitors = NULL;
+static GSList* pending_name_watchers = NULL;
#define BIG_DBUS_NAME_OWNER_MONITOR_INVALID_ID 0
static unsigned int global_monitor_id = 0;
-static DBusHandlerResult disconnect_filter_message (DBusConnection *connection,
- DBusMessage *message,
- void *data);
-static DBusHandlerResult name_ownership_monitor_filter_message (DBusConnection *connection,
- DBusMessage *message,
- void *data);
-static void process_name_ownership_monitors (DBusConnection *connection,
- BigDBusInfo *info);
-static void name_watch_remove_watcher (BigNameWatch *watch,
- BigNameWatcher *watcher);
-static DBusHandlerResult name_watch_filter_message (DBusConnection *connection,
- DBusMessage *message,
- void *data);
-static void process_pending_name_watchers (DBusConnection *connection,
- BigDBusInfo *info);
-static void json_iface_free (BigJsonIface *iface);
-static void info_free (BigDBusInfo *info);
-static gboolean notify_watcher_name_appeared (gpointer data);
+static DBusHandlerResult disconnect_filter_message(DBusConnection* connection,
+ DBusMessage* message,
+ void* data);
+static DBusHandlerResult name_ownership_monitor_filter_message(
+ DBusConnection* connection,
+ DBusMessage* message,
+ void* data);
+static void process_name_ownership_monitors(DBusConnection* connection,
+ BigDBusInfo* info);
+static void name_watch_remove_watcher(BigNameWatch* watch,
+ BigNameWatcher* watcher);
+static DBusHandlerResult name_watch_filter_message(DBusConnection* connection,
+ DBusMessage* message,
+ void* data);
+static void process_pending_name_watchers(DBusConnection* connection,
+ BigDBusInfo* info);
+static void json_iface_free(BigJsonIface* iface);
+static void info_free(BigDBusInfo* info);
+static gboolean notify_watcher_name_appeared(gpointer data);
static dbus_int32_t info_slot = -1;
BigDBusInfo*
-_big_dbus_ensure_info(DBusConnection *connection)
+_big_dbus_ensure_info(DBusConnection* connection)
{
- BigDBusInfo *info;
+ BigDBusInfo* info;
dbus_connection_allocate_data_slot(&info_slot);
@@ -124,32 +131,33 @@ _big_dbus_ensure_info(DBusConnection *connection)
else
g_error("Unknown bus type opened in %s", __FILE__);
- info->json_ifaces = g_hash_table_new_full(g_str_hash, g_str_equal,
- NULL, (GFreeFunc) json_iface_free);
+ info->json_ifaces = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
+ (GFreeFunc) json_iface_free);
info->name_watches = g_hash_table_new(g_str_hash, g_str_equal);
- dbus_connection_set_data(connection, info_slot, info, (DBusFreeFunction) info_free);
+ dbus_connection_set_data(connection, info_slot, info,
+ (DBusFreeFunction) info_free);
- dbus_connection_add_filter(connection, name_ownership_monitor_filter_message,
- NULL, NULL);
- dbus_connection_add_filter(connection, name_watch_filter_message,
- NULL, NULL);
- dbus_connection_add_filter(connection, _big_dbus_signal_watch_filter_message,
- NULL, NULL);
+ dbus_connection_add_filter(connection,
+ name_ownership_monitor_filter_message, NULL,
+ NULL);
+ dbus_connection_add_filter(connection, name_watch_filter_message, NULL,
+ NULL);
+ dbus_connection_add_filter(connection,
+ _big_dbus_signal_watch_filter_message, NULL,
+ NULL);
/* Important: disconnect_filter_message() must be LAST so
* it runs last when the disconnect message arrives.
*/
- dbus_connection_add_filter(connection, disconnect_filter_message,
- NULL, NULL);
+ dbus_connection_add_filter(connection, disconnect_filter_message, NULL,
+ NULL);
/* caution, this could get circular if proxy_new() goes back around
* and tries to use dbus.c - but we'll fix it when it happens.
* Also, this refs the connection ...
*/
- info->driver_proxy =
- big_dbus_proxy_new(connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
+ info->driver_proxy
+ = big_dbus_proxy_new(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
}
@@ -157,9 +165,9 @@ _big_dbus_ensure_info(DBusConnection *connection)
}
void
-_big_dbus_dispose_info(DBusConnection *connection)
+_big_dbus_dispose_info(DBusConnection* connection)
{
- BigDBusInfo *info;
+ BigDBusInfo* info;
if (info_slot < 0)
return;
@@ -168,8 +176,7 @@ _big_dbus_dispose_info(DBusConnection *connection)
if (info != NULL) {
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Disposing info on connection %p",
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Disposing info on connection %p",
connection);
/* the driver proxy refs the connection, we want
@@ -192,15 +199,15 @@ _big_dbus_get_weak_ref(DBusBusType which_bus)
} else if (which_bus == DBUS_BUS_SYSTEM) {
return system_bus_weak_ref;
}
-
+
g_assert_not_reached();
return NULL;
}
static DBusHandlerResult
-disconnect_filter_message(DBusConnection *connection,
- DBusMessage *message,
- void *data)
+disconnect_filter_message(DBusConnection* connection,
+ DBusMessage* message,
+ void* data)
{
/* We should be running after all other filters */
if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
@@ -222,23 +229,20 @@ static DBusConnection*
try_connecting(DBusBusType which_bus)
{
- DBusGConnection *gconnection;
- DBusConnection *connection;
- GError *error;
+ DBusGConnection* gconnection;
+ DBusConnection* connection;
+ GError* error;
connection = _big_dbus_get_weak_ref(which_bus);
if (connection != NULL)
return connection;
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "trying to connect to message bus");
+ big_debug(BIG_DEBUG_UTIL_DBUS, "trying to connect to message bus");
error = NULL;
- gconnection = dbus_g_bus_get(which_bus,
- &error);
+ gconnection = dbus_g_bus_get(which_bus, &error);
if (gconnection == NULL) {
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "bus connection failed: %s",
+ big_debug(BIG_DEBUG_UTIL_DBUS, "bus connection failed: %s",
error->message);
g_error_free(error);
return NULL;
@@ -249,38 +253,35 @@ try_connecting(DBusBusType which_bus)
/* Disable this because all our apps will be well-behaved! */
dbus_connection_set_exit_on_disconnect(connection, FALSE);
- if (which_bus == DBUS_BUS_SESSION &&
- session_bus_weak_ref == NULL) {
- GSList *l;
+ if (which_bus == DBUS_BUS_SESSION && session_bus_weak_ref == NULL) {
+ GSList* l;
session_bus_weak_ref = connection;
for (l = session_bus_weak_refs; l != NULL; l = l->next) {
- DBusConnection **connection_p = l->data;
+ DBusConnection** connection_p = l->data;
*connection_p = session_bus_weak_ref;
}
- } else if (which_bus == DBUS_BUS_SYSTEM &&
- system_bus_weak_ref == NULL) {
- GSList *l;
+ } else if (which_bus == DBUS_BUS_SYSTEM && system_bus_weak_ref == NULL) {
+ GSList* l;
system_bus_weak_ref = connection;
for (l = system_bus_weak_refs; l != NULL; l = l->next) {
- DBusConnection **connection_p = l->data;
+ DBusConnection** connection_p = l->data;
*connection_p = system_bus_weak_ref;
}
}
dbus_g_connection_unref(gconnection); /* rely on libdbus holding a ref */
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Successfully connected");
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Successfully connected");
return connection;
}
static gboolean
-connect_idle(void *data)
+connect_idle(void* data)
{
- GSList *l;
- DBusConnection *connection;
- BigDBusInfo *info;
+ GSList* l;
+ DBusConnection* connection;
+ BigDBusInfo* info;
DBusBusType bus_type;
bus_type = GPOINTER_TO_INT(data);
@@ -293,7 +294,8 @@ connect_idle(void *data)
g_assert_not_reached();
big_debug(BIG_DEBUG_UTIL_DBUS,
- "connection idle with %d connect listeners to traverse", g_slist_length(all_connect_funcs));
+ "connection idle with %d connect listeners to traverse",
+ g_slist_length(all_connect_funcs));
connection = try_connecting(bus_type);
if (connection == NULL) {
@@ -328,12 +330,12 @@ connect_idle(void *data)
*/
for (l = all_connect_funcs; l != NULL; l = l->next) {
- ConnectFuncs *f;
+ ConnectFuncs* f;
f = l->data;
if (!f->opened && f->funcs->which_bus == bus_type) {
f->opened = TRUE;
- (* f->funcs->opened) (connection, f->data);
+ (*f->funcs->opened)(connection, f->data);
}
}
@@ -354,11 +356,13 @@ _big_dbus_ensure_connect_idle(DBusBusType bus_type)
{
if (bus_type == DBUS_BUS_SESSION) {
if (session_connect_idle_id == 0) {
- session_connect_idle_id = g_idle_add(connect_idle, GINT_TO_POINTER(bus_type));
+ session_connect_idle_id
+ = g_idle_add(connect_idle, GINT_TO_POINTER(bus_type));
}
} else if (bus_type == DBUS_BUS_SYSTEM) {
if (system_connect_idle_id == 0) {
- system_connect_idle_id = g_idle_add(connect_idle, GINT_TO_POINTER(bus_type));
+ system_connect_idle_id
+ = g_idle_add(connect_idle, GINT_TO_POINTER(bus_type));
}
} else {
g_assert_not_reached();
@@ -366,11 +370,11 @@ _big_dbus_ensure_connect_idle(DBusBusType bus_type)
}
static void
-internal_add_connect_funcs(const BigDBusConnectFuncs *funcs,
- void *data,
- gboolean sync_notify)
+internal_add_connect_funcs(const BigDBusConnectFuncs* funcs,
+ void* data,
+ gboolean sync_notify)
{
- ConnectFuncs *f;
+ ConnectFuncs* f;
f = g_slice_new0(ConnectFuncs);
f->funcs = funcs;
@@ -386,13 +390,13 @@ internal_add_connect_funcs(const BigDBusConnectFuncs *funcs,
* (we have a weak ref != NULL) then notify
* right away before we return.
*/
- DBusConnection *connection;
+ DBusConnection* connection;
connection = _big_dbus_get_weak_ref(f->funcs->which_bus);
if (connection != NULL && !f->opened) {
f->opened = TRUE;
- (* f->funcs->opened) (connection, f->data);
+ (*f->funcs->opened)(connection, f->data);
}
}
}
@@ -402,8 +406,7 @@ internal_add_connect_funcs(const BigDBusConnectFuncs *funcs,
* main loop.
*/
void
-big_dbus_add_connect_funcs(const BigDBusConnectFuncs *funcs,
- void *data)
+big_dbus_add_connect_funcs(const BigDBusConnectFuncs* funcs, void* data)
{
internal_add_connect_funcs(funcs, data, FALSE);
}
@@ -412,25 +415,23 @@ big_dbus_add_connect_funcs(const BigDBusConnectFuncs *funcs,
* we are already connected.
*/
void
-big_dbus_add_connect_funcs_sync_notify(const BigDBusConnectFuncs *funcs,
- void *data)
+big_dbus_add_connect_funcs_sync_notify(const BigDBusConnectFuncs* funcs,
+ void* data)
{
internal_add_connect_funcs(funcs, data, TRUE);
}
void
-big_dbus_remove_connect_funcs(const BigDBusConnectFuncs *funcs,
- void *data)
+big_dbus_remove_connect_funcs(const BigDBusConnectFuncs* funcs, void* data)
{
- ConnectFuncs *f;
- GSList *l;
+ ConnectFuncs* f;
+ GSList* l;
f = NULL;
for (l = all_connect_funcs; l != NULL; l = l->next) {
f = l->data;
- if (f->funcs == funcs &&
- f->data == data)
+ if (f->funcs == funcs && f->data == data)
break;
}
@@ -445,15 +446,16 @@ big_dbus_remove_connect_funcs(const BigDBusConnectFuncs *funcs,
}
void
-big_dbus_add_bus_weakref(DBusBusType which_bus,
- DBusConnection **connection_p)
+big_dbus_add_bus_weakref(DBusBusType which_bus, DBusConnection** connection_p)
{
if (which_bus == DBUS_BUS_SESSION) {
*connection_p = session_bus_weak_ref;
- session_bus_weak_refs = g_slist_prepend(session_bus_weak_refs, connection_p);
+ session_bus_weak_refs
+ = g_slist_prepend(session_bus_weak_refs, connection_p);
} else if (which_bus == DBUS_BUS_SYSTEM) {
*connection_p = system_bus_weak_ref;
- system_bus_weak_refs = g_slist_prepend(system_bus_weak_refs, connection_p);
+ system_bus_weak_refs
+ = g_slist_prepend(system_bus_weak_refs, connection_p);
} else {
g_assert_not_reached();
}
@@ -462,15 +464,17 @@ big_dbus_add_bus_weakref(DBusBusType which_bus,
}
void
-big_dbus_remove_bus_weakref(DBusBusType which_bus,
- DBusConnection **connection_p)
+big_dbus_remove_bus_weakref(DBusBusType which_bus,
+ DBusConnection** connection_p)
{
if (which_bus == DBUS_BUS_SESSION) {
*connection_p = NULL;
- session_bus_weak_refs = g_slist_remove(session_bus_weak_refs, connection_p);
+ session_bus_weak_refs
+ = g_slist_remove(session_bus_weak_refs, connection_p);
} else if (which_bus == DBUS_BUS_SYSTEM) {
*connection_p = NULL;
- system_bus_weak_refs = g_slist_remove(system_bus_weak_refs, connection_p);
+ system_bus_weak_refs
+ = g_slist_remove(system_bus_weak_refs, connection_p);
} else {
g_assert_not_reached();
}
@@ -483,11 +487,11 @@ big_dbus_try_connecting_now(DBusBusType which_bus)
}
static BigJsonIface*
-json_iface_new(const char *name,
- const BigDBusJsonMethod *methods,
+json_iface_new(const char* name,
+ const BigDBusJsonMethod* methods,
int n_methods)
{
- BigJsonIface *iface;
+ BigJsonIface* iface;
iface = g_slice_new0(BigJsonIface);
iface->name = g_strdup(name);
@@ -498,18 +502,18 @@ json_iface_new(const char *name,
}
static void
-json_iface_free(BigJsonIface *iface)
+json_iface_free(BigJsonIface* iface)
{
g_free(iface->name);
g_slice_free(BigJsonIface, iface);
}
static BigNameOwnershipMonitor*
-name_ownership_monitor_new(DBusBusType bus_type,
- const BigDBusNameOwnerFuncs *funcs,
- void *data)
+name_ownership_monitor_new(DBusBusType bus_type,
+ const BigDBusNameOwnerFuncs* funcs,
+ void* data)
{
- BigNameOwnershipMonitor *monitor;
+ BigNameOwnershipMonitor* monitor;
monitor = g_slice_new0(BigNameOwnershipMonitor);
monitor->bus_type = bus_type;
@@ -519,20 +523,20 @@ name_ownership_monitor_new(DBusBusType bus_type,
monitor->data = data;
monitor->id = ++global_monitor_id;
- return monitor;
+ return monitor;
}
static void
-name_ownership_monitor_free(BigNameOwnershipMonitor *monitor)
+name_ownership_monitor_free(BigNameOwnershipMonitor* monitor)
{
g_slice_free(BigNameOwnershipMonitor, monitor);
}
static BigNameWatch*
-name_watch_new(const char *name)
+name_watch_new(const char* name)
{
- BigNameWatch *watch;
+ BigNameWatch* watch;
watch = g_slice_new0(BigNameWatch);
watch->name = g_strdup(name);
@@ -549,7 +553,7 @@ name_watch_new(const char *name)
}
static void
-name_watch_free(BigNameWatch *watch)
+name_watch_free(BigNameWatch* watch)
{
g_assert(watch->watchers == NULL);
@@ -559,12 +563,12 @@ name_watch_free(BigNameWatch *watch)
}
static BigNameWatcher*
-name_watcher_new(BigDBusWatchNameFlags flags,
- const BigDBusWatchNameFuncs *funcs,
- void *data,
- DBusBusType bus_type)
+name_watcher_new(BigDBusWatchNameFlags flags,
+ const BigDBusWatchNameFuncs* funcs,
+ void* data,
+ DBusBusType bus_type)
{
- BigNameWatcher *watcher;
+ BigNameWatcher* watcher;
watcher = g_slice_new0(BigNameWatcher);
watcher->flags = flags;
@@ -578,13 +582,13 @@ name_watcher_new(BigDBusWatchNameFlags flags,
}
static void
-name_watcher_ref(BigNameWatcher *watcher)
+name_watcher_ref(BigNameWatcher* watcher)
{
watcher->refcount += 1;
}
static void
-name_watcher_unref(BigNameWatcher *watcher)
+name_watcher_unref(BigNameWatcher* watcher)
{
watcher->refcount -= 1;
@@ -593,10 +597,10 @@ name_watcher_unref(BigNameWatcher *watcher)
}
static void
-info_free(BigDBusInfo *info)
+info_free(BigDBusInfo* info)
{
- void *key;
- void *value;
+ void* key;
+ void* value;
big_debug(BIG_DEBUG_UTIL_DBUS,
"Destroy notify invoked on bus connection info for %p",
@@ -620,20 +624,20 @@ info_free(BigDBusInfo *info)
while (info->name_ownership_monitors != NULL) {
name_ownership_monitor_free(info->name_ownership_monitors->data);
- info->name_ownership_monitors = g_slist_remove(info->name_ownership_monitors,
- info->name_ownership_monitors->data);
+ info->name_ownership_monitors
+ = g_slist_remove(info->name_ownership_monitors,
+ info->name_ownership_monitors->data);
}
- while ((value = g_hash_table_lookup(info->name_watches, &key)))
- {
- BigNameWatch *watch = value;
-
+ while ((value = g_hash_table_lookup(info->name_watches, &key))) {
+ BigNameWatch* watch = value;
+
while (watch->watchers) {
name_watch_remove_watcher(watch, watch->watchers->data);
}
-
+
name_watch_free(watch);
- g_hash_table_steal (info->name_watches, &key);
+ g_hash_table_steal(info->name_watches, &key);
}
if (info->signal_watchers_by_unique_sender) {
@@ -658,34 +662,33 @@ info_free(BigDBusInfo *info)
}
static DBusHandlerResult
-name_ownership_monitor_filter_message(DBusConnection *connection,
- DBusMessage *message,
- void *data)
+name_ownership_monitor_filter_message(DBusConnection* connection,
+ DBusMessage* message,
+ void* data)
{
- BigDBusInfo *info;
+ BigDBusInfo* info;
gboolean states_changed;
info = _big_dbus_ensure_info(connection);
states_changed = FALSE;
- if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameLost") &&
- dbus_message_has_sender(message, DBUS_SERVICE_DBUS)) {
- const char *name = NULL;
- if (dbus_message_get_args(message, NULL,
- DBUS_TYPE_STRING, &name,
+ if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameLost")
+ && dbus_message_has_sender(message, DBUS_SERVICE_DBUS)) {
+ const char* name = NULL;
+ if (dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID)) {
- GSList *l;
+ GSList* l;
big_debug(BIG_DEBUG_UTIL_DBUS, "Lost name %s", name);
for (l = info->name_ownership_monitors; l != NULL; l = l->next) {
- BigNameOwnershipMonitor *monitor;
+ BigNameOwnershipMonitor* monitor;
monitor = l->data;
- if (monitor->state == NAME_PRIMARY_OWNER &&
- strcmp(name, monitor->funcs->name) == 0) {
+ if (monitor->state == NAME_PRIMARY_OWNER
+ && strcmp(name, monitor->funcs->name) == 0) {
monitor->prev_state = monitor->state;
monitor->state = NAME_NOT_OWNED;
states_changed = TRUE;
@@ -695,23 +698,23 @@ name_ownership_monitor_filter_message(DBusConnection *connection,
} else {
big_debug(BIG_DEBUG_UTIL_DBUS, "NameLost has wrong arguments???");
}
- } else if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameAcquired") &&
- dbus_message_has_sender(message, DBUS_SERVICE_DBUS)) {
- const char *name = NULL;
- if (dbus_message_get_args(message, NULL,
- DBUS_TYPE_STRING, &name,
+ } else if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS,
+ "NameAcquired")
+ && dbus_message_has_sender(message, DBUS_SERVICE_DBUS)) {
+ const char* name = NULL;
+ if (dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID)) {
- GSList *l;
+ GSList* l;
big_debug(BIG_DEBUG_UTIL_DBUS, "Acquired name %s", name);
for (l = info->name_ownership_monitors; l != NULL; l = l->next) {
- BigNameOwnershipMonitor *monitor;
+ BigNameOwnershipMonitor* monitor;
monitor = l->data;
- if (monitor->state != NAME_PRIMARY_OWNER &&
- strcmp(name, monitor->funcs->name) == 0) {
+ if (monitor->state != NAME_PRIMARY_OWNER
+ && strcmp(name, monitor->funcs->name) == 0) {
monitor->prev_state = monitor->state;
monitor->state = NAME_PRIMARY_OWNER;
states_changed = TRUE;
@@ -719,15 +722,17 @@ name_ownership_monitor_filter_message(DBusConnection *connection,
}
}
} else {
- big_debug(BIG_DEBUG_UTIL_DBUS, "NameAcquired has wrong arguments???");
+ big_debug(BIG_DEBUG_UTIL_DBUS,
+ "NameAcquired has wrong arguments???");
}
- } else if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
- GSList *l;
+ } else if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL,
+ "Disconnected")) {
+ GSList* l;
big_debug(BIG_DEBUG_UTIL_DBUS, "Disconnected in %s", G_STRFUNC);
for (l = info->name_ownership_monitors; l != NULL; l = l->next) {
- BigNameOwnershipMonitor *monitor;
+ BigNameOwnershipMonitor* monitor;
monitor = l->data;
@@ -739,7 +744,8 @@ name_ownership_monitor_filter_message(DBusConnection *connection,
}
}
- /* FIXME move the monitors back to the pending list so they'll be found on reconnect */
+ /* FIXME move the monitors back to the pending list so they'll be found
+ * on reconnect */
}
if (states_changed)
@@ -749,28 +755,26 @@ name_ownership_monitor_filter_message(DBusConnection *connection,
}
static void
-process_name_ownership_monitors(DBusConnection *connection,
- BigDBusInfo *info)
+process_name_ownership_monitors(DBusConnection* connection, BigDBusInfo* info)
{
- GSList *l;
+ GSList* l;
gboolean connected;
- GSList *still_pending;
+ GSList* still_pending;
/* First pull anything out of pending queue */
still_pending = NULL;
while (pending_name_ownership_monitors != NULL) {
- BigNameOwnershipMonitor *monitor;
+ BigNameOwnershipMonitor* monitor;
monitor = pending_name_ownership_monitors->data;
- pending_name_ownership_monitors =
- g_slist_remove(pending_name_ownership_monitors,
+ pending_name_ownership_monitors
+ = g_slist_remove(pending_name_ownership_monitors,
pending_name_ownership_monitors->data);
if (monitor->bus_type == info->bus_type) {
- info->name_ownership_monitors =
- g_slist_prepend(info->name_ownership_monitors,
- monitor);
+ info->name_ownership_monitors
+ = g_slist_prepend(info->name_ownership_monitors, monitor);
} else {
still_pending = g_slist_prepend(still_pending, monitor);
}
@@ -784,7 +788,7 @@ process_name_ownership_monitors(DBusConnection *connection,
if (connected) {
for (l = info->name_ownership_monitors; l != NULL; l = l->next) {
- BigNameOwnershipMonitor *monitor;
+ BigNameOwnershipMonitor* monitor;
monitor = l->data;
@@ -798,17 +802,17 @@ process_name_ownership_monitors(DBusConnection *connection,
flags |= DBUS_NAME_FLAG_DO_NOT_QUEUE;
dbus_error_init(&derror);
- result = dbus_bus_request_name(connection,
- monitor->funcs->name,
- flags,
- &derror);
+ result = dbus_bus_request_name(connection, monitor->funcs->name,
+ flags, &derror);
/* log 'error' word only when one occurred */
if (derror.message != NULL) {
- big_debug(BIG_DEBUG_UTIL_DBUS, "Requested name %s result %d error %s",
+ big_debug(BIG_DEBUG_UTIL_DBUS,
+ "Requested name %s result %d error %s",
monitor->funcs->name, result, derror.message);
} else {
- big_debug(BIG_DEBUG_UTIL_DBUS, "Requested name %s result %d",
+ big_debug(BIG_DEBUG_UTIL_DBUS,
+ "Requested name %s result %d",
monitor->funcs->name, result);
}
@@ -827,8 +831,8 @@ process_name_ownership_monitors(DBusConnection *connection,
monitor->prev_state = monitor->state;
- if (result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ||
- result == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER) {
+ if (result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER
+ || result == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER) {
monitor->state = NAME_PRIMARY_OWNER;
} else if (result == DBUS_REQUEST_NAME_REPLY_IN_QUEUE) {
monitor->state = NAME_IN_QUEUE;
@@ -848,7 +852,7 @@ process_name_ownership_monitors(DBusConnection *connection,
*/
l = g_slist_copy(info->name_ownership_monitors);
while (l != NULL) {
- BigNameOwnershipMonitor *monitor;
+ BigNameOwnershipMonitor* monitor;
monitor = l->data;
l = g_slist_remove(l, l->data);
@@ -859,25 +863,28 @@ process_name_ownership_monitors(DBusConnection *connection,
if (monitor->state == NAME_PRIMARY_OWNER) {
big_debug(BIG_DEBUG_UTIL_DBUS, "Notifying acquired %s",
monitor->funcs->name);
- (* monitor->funcs->acquired) (connection, monitor->funcs->name, monitor->data);
+ (*monitor->funcs->acquired)(connection, monitor->funcs->name,
+ monitor->data);
} else if (monitor->state != NAME_PRIMARY_OWNER) {
big_debug(BIG_DEBUG_UTIL_DBUS, "Notifying lost %s",
monitor->funcs->name);
- (* monitor->funcs->lost) (connection, monitor->funcs->name, monitor->data);
+ (*monitor->funcs->lost)(connection, monitor->funcs->name,
+ monitor->data);
}
}
}
}
unsigned int
-big_dbus_acquire_name (DBusBusType bus_type,
- const BigDBusNameOwnerFuncs *funcs,
- void *data)
+big_dbus_acquire_name(DBusBusType bus_type,
+ const BigDBusNameOwnerFuncs* funcs,
+ void* data)
{
- BigNameOwnershipMonitor *monitor;
+ BigNameOwnershipMonitor* monitor;
monitor = name_ownership_monitor_new(bus_type, funcs, data);
- pending_name_ownership_monitors = g_slist_prepend(pending_name_ownership_monitors, monitor);
+ pending_name_ownership_monitors
+ = g_slist_prepend(pending_name_ownership_monitors, monitor);
_big_dbus_ensure_connect_idle(bus_type);
@@ -885,15 +892,15 @@ big_dbus_acquire_name (DBusBusType bus_type,
}
static void
-release_name_internal (DBusBusType bus_type,
- const BigDBusNameOwnerFuncs *funcs,
- void *data,
- unsigned int id)
+release_name_internal(DBusBusType bus_type,
+ const BigDBusNameOwnerFuncs* funcs,
+ void* data,
+ unsigned int id)
{
- BigDBusInfo *info;
- GSList *l;
- BigNameOwnershipMonitor *monitor;
- DBusConnection *connection;
+ BigDBusInfo* info;
+ GSList* l;
+ BigNameOwnershipMonitor* monitor;
+ DBusConnection* connection;
connection = _big_dbus_get_weak_ref(bus_type);
if (!connection)
@@ -905,14 +912,13 @@ release_name_internal (DBusBusType bus_type,
for (l = pending_name_ownership_monitors; l; l = l->next) {
monitor = l->data;
/* If the id is valid an matches, we are done */
- if (monitor->state == NAME_PRIMARY_OWNER &&
- ((id != BIG_DBUS_NAME_OWNER_MONITOR_INVALID_ID && monitor->id == id) ||
- (monitor->funcs == funcs &&
- monitor->data == data))) {
+ if (monitor->state == NAME_PRIMARY_OWNER
+ && ((id != BIG_DBUS_NAME_OWNER_MONITOR_INVALID_ID
+ && monitor->id == id)
+ || (monitor->funcs == funcs && monitor->data == data))) {
dbus_bus_release_name(connection, monitor->funcs->name, NULL);
- pending_name_ownership_monitors =
- g_slist_remove(pending_name_ownership_monitors,
- monitor);
+ pending_name_ownership_monitors
+ = g_slist_remove(pending_name_ownership_monitors, monitor);
name_ownership_monitor_free(monitor);
/* If the monitor was in the pending list it
* can't be in the processed list
@@ -924,13 +930,13 @@ release_name_internal (DBusBusType bus_type,
for (l = info->name_ownership_monitors; l; l = l->next) {
monitor = l->data;
/* If the id is valid an matches, we are done */
- if (monitor->state == NAME_PRIMARY_OWNER &&
- ((id != BIG_DBUS_NAME_OWNER_MONITOR_INVALID_ID && monitor->id == id) ||
- (monitor->funcs == funcs &&
- monitor->data == data))) {
+ if (monitor->state == NAME_PRIMARY_OWNER
+ && ((id != BIG_DBUS_NAME_OWNER_MONITOR_INVALID_ID
+ && monitor->id == id)
+ || (monitor->funcs == funcs && monitor->data == data))) {
dbus_bus_release_name(connection, monitor->funcs->name, NULL);
- info->name_ownership_monitors = g_slist_remove(info->name_ownership_monitors,
- monitor);
+ info->name_ownership_monitors
+ = g_slist_remove(info->name_ownership_monitors, monitor);
name_ownership_monitor_free(monitor);
break;
}
@@ -938,30 +944,29 @@ release_name_internal (DBusBusType bus_type,
}
void
-big_dbus_release_name_by_id (DBusBusType bus_type,
- unsigned int id)
+big_dbus_release_name_by_id(DBusBusType bus_type, unsigned int id)
{
release_name_internal(bus_type, NULL, NULL, id);
}
void
-big_dbus_release_name (DBusBusType bus_type,
- const BigDBusNameOwnerFuncs *funcs,
- void *data)
+big_dbus_release_name(DBusBusType bus_type,
+ const BigDBusNameOwnerFuncs* funcs,
+ void* data)
{
release_name_internal(bus_type, funcs, data,
BIG_DBUS_NAME_OWNER_MONITOR_INVALID_ID);
}
static void
-notify_name_owner_changed(DBusConnection *connection,
- const char *name,
- const char *new_owner)
+notify_name_owner_changed(DBusConnection* connection,
+ const char* name,
+ const char* new_owner)
{
- BigDBusInfo *info;
- BigNameWatch *watch;
+ BigDBusInfo* info;
+ BigNameWatch* watch;
GSList *l, *watchers;
- gchar *old_owner;
+ gchar* old_owner;
info = _big_dbus_ensure_info(connection);
@@ -973,9 +978,9 @@ notify_name_owner_changed(DBusConnection *connection,
if (watch == NULL)
return;
- if ((watch->current_owner == new_owner) ||
- (watch->current_owner && new_owner &&
- strcmp(watch->current_owner, new_owner) == 0)) {
+ if ((watch->current_owner == new_owner)
+ || (watch->current_owner && new_owner
+ && strcmp(watch->current_owner, new_owner) == 0)) {
/* No change */
return;
}
@@ -983,7 +988,7 @@ notify_name_owner_changed(DBusConnection *connection,
/* we copy the list before iterating, because the
* callbacks may modify it */
watchers = g_slist_copy(watch->watchers);
- g_slist_foreach(watchers, (GFunc)name_watcher_ref, NULL);
+ g_slist_foreach(watchers, (GFunc) name_watcher_ref, NULL);
/* copy the old owner in case the watch is removed in
* the callbacks */
@@ -991,10 +996,8 @@ notify_name_owner_changed(DBusConnection *connection,
/* vanish the old owner */
if (old_owner != NULL) {
- for (l = watchers;
- l != NULL;
- l = l->next) {
- BigNameWatcher *watcher = l->data;
+ for (l = watchers; l != NULL; l = l->next) {
+ BigNameWatcher* watcher = l->data;
if (watcher->notify_idle != 0) {
/* Name owner changed before we notified
@@ -1011,10 +1014,8 @@ notify_name_owner_changed(DBusConnection *connection,
}
if (!watcher->destroyed) {
- (* watcher->funcs->vanished) (connection,
- name,
- old_owner,
- watcher->data);
+ (*watcher->funcs->vanished)(connection, name, old_owner,
+ watcher->data);
}
}
}
@@ -1031,43 +1032,38 @@ notify_name_owner_changed(DBusConnection *connection,
/* appear the new owner */
if (new_owner != NULL) {
- for (l = watchers;
- l != NULL;
- l = l->next) {
- BigNameWatcher *watcher = l->data;
+ for (l = watchers; l != NULL; l = l->next) {
+ BigNameWatcher* watcher = l->data;
if (!watcher->destroyed) {
- (* watcher->funcs->appeared) (connection,
- name,
- new_owner,
- watcher->data);
+ (*watcher->funcs->appeared)(connection, name, new_owner,
+ watcher->data);
}
}
}
/* now destroy our copy */
- g_slist_foreach(watchers, (GFunc)name_watcher_unref, NULL);
+ g_slist_foreach(watchers, (GFunc) name_watcher_unref, NULL);
g_slist_free(watchers);
g_free(old_owner);
}
static DBusHandlerResult
-name_watch_filter_message(DBusConnection *connection,
- DBusMessage *message,
- void *data)
+name_watch_filter_message(DBusConnection* connection,
+ DBusMessage* message,
+ void* data)
{
- BigDBusInfo *info;
+ BigDBusInfo* info;
info = _big_dbus_ensure_info(connection);
- if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged") &&
- dbus_message_has_sender(message, DBUS_SERVICE_DBUS)) {
- const char *name = NULL;
- const char *old_owner = NULL;
- const char *new_owner = NULL;
- if (dbus_message_get_args(message, NULL,
- DBUS_TYPE_STRING, &name,
+ if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")
+ && dbus_message_has_sender(message, DBUS_SERVICE_DBUS)) {
+ const char* name = NULL;
+ const char* old_owner = NULL;
+ const char* new_owner = NULL;
+ if (dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &old_owner,
DBUS_TYPE_STRING, &new_owner,
DBUS_TYPE_INVALID)) {
@@ -1076,13 +1072,16 @@ name_watch_filter_message(DBusConnection *connection,
notify_name_owner_changed(connection, name, new_owner);
} else {
- big_debug(BIG_DEBUG_UTIL_DBUS, "NameOwnerChanged has wrong arguments???");
+ big_debug(BIG_DEBUG_UTIL_DBUS,
+ "NameOwnerChanged has wrong arguments???");
}
- } else if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
+ } else if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL,
+ "Disconnected")) {
big_debug(BIG_DEBUG_UTIL_DBUS, "Disconnected in %s", G_STRFUNC);
- /* FIXME set all current owners to NULL, and move watches back to the pending
+ /* FIXME set all current owners to NULL, and move watches back to the
+ * pending
* list so they are found on reconnect.
*/
}
@@ -1090,31 +1089,25 @@ name_watch_filter_message(DBusConnection *connection,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-
void
-_big_dbus_set_matching_name_owner_changed(DBusConnection *connection,
- const char *bus_name,
- gboolean matched)
+_big_dbus_set_matching_name_owner_changed(DBusConnection* connection,
+ const char* bus_name,
+ gboolean matched)
{
- char *s;
+ char* s;
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "%s NameOwnerChanged on name '%s'",
- matched ? "Matching" : "No longer matching",
- bus_name);
-
- s = g_strdup_printf("type='signal',sender='"
- DBUS_SERVICE_DBUS
- "',interface='"
- DBUS_INTERFACE_DBUS
- "',member='"
+ big_debug(BIG_DEBUG_UTIL_DBUS, "%s NameOwnerChanged on name '%s'",
+ matched ? "Matching" : "No longer matching", bus_name);
+
+ s = g_strdup_printf("type='signal',sender='" DBUS_SERVICE_DBUS
+ "',interface='" DBUS_INTERFACE_DBUS "',member='"
"NameOwnerChanged"
"',arg0='%s'",
bus_name);
if (matched)
- dbus_bus_add_match(connection,
- s, NULL); /* asking for error would make this block */
+ dbus_bus_add_match(connection, s,
+ NULL); /* asking for error would make this block */
else
dbus_bus_remove_match(connection, s, NULL);
@@ -1122,36 +1115,29 @@ _big_dbus_set_matching_name_owner_changed(DBusConnection *connection,
}
static void
-on_start_service_reply(BigDBusProxy *proxy,
- DBusMessage *message,
- void *data)
+on_start_service_reply(BigDBusProxy* proxy, DBusMessage* message, void* data)
{
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Got successful reply to service start");
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Got successful reply to service start");
}
static void
-on_start_service_error(BigDBusProxy *proxy,
- const char *error_name,
- const char *error_message,
- void *data)
+on_start_service_error(BigDBusProxy* proxy,
+ const char* error_name,
+ const char* error_message,
+ void* data)
{
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Got error starting service: %s: %s",
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Got error starting service: %s: %s",
error_name, error_message);
}
void
-big_dbus_start_service(DBusConnection *connection,
- const char *name)
+big_dbus_start_service(DBusConnection* connection, const char* name)
{
- DBusMessage *message;
+ DBusMessage* message;
dbus_uint32_t flags;
- BigDBusInfo *info;
+ BigDBusInfo* info;
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Starting service '%s'",
- name);
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Starting service '%s'", name);
info = _big_dbus_ensure_info(connection);
@@ -1159,15 +1145,10 @@ big_dbus_start_service(DBusConnection *connection,
"StartServiceByName");
flags = 0;
- if (dbus_message_append_args(message,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_UINT32, &flags,
- DBUS_TYPE_INVALID)) {
- big_dbus_proxy_send(info->driver_proxy,
- message,
- on_start_service_reply,
- on_start_service_error,
- NULL);
+ if (dbus_message_append_args(message, DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID)) {
+ big_dbus_proxy_send(info->driver_proxy, message, on_start_service_reply,
+ on_start_service_error, NULL);
} else {
big_debug(BIG_DEBUG_UTIL_DBUS,
"No memory appending args to StartServiceByName");
@@ -1176,18 +1157,19 @@ big_dbus_start_service(DBusConnection *connection,
dbus_message_unref(message);
}
-typedef struct {
- DBusConnection *connection;
- char *name;
+typedef struct
+{
+ DBusConnection* connection;
+ char* name;
BigDBusWatchNameFlags flags;
} GetOwnerRequest;
static GetOwnerRequest*
-get_owner_request_new(DBusConnection *connection,
- const char *name,
+get_owner_request_new(DBusConnection* connection,
+ const char* name,
BigDBusWatchNameFlags flags)
{
- GetOwnerRequest *gor;
+ GetOwnerRequest* gor;
gor = g_slice_new0(GetOwnerRequest);
gor->connection = connection;
@@ -1199,7 +1181,7 @@ get_owner_request_new(DBusConnection *connection,
}
static void
-get_owner_request_free(GetOwnerRequest *gor)
+get_owner_request_free(GetOwnerRequest* gor)
{
dbus_connection_unref(gor->connection);
g_free(gor->name);
@@ -1207,11 +1189,10 @@ get_owner_request_free(GetOwnerRequest *gor)
}
static void
-on_get_owner_reply(DBusPendingCall *pending,
- void *user_data)
+on_get_owner_reply(DBusPendingCall* pending, void* user_data)
{
- DBusMessage *reply;
- GetOwnerRequest *gor;
+ DBusMessage* reply;
+ GetOwnerRequest* gor;
gor = user_data;
@@ -1222,53 +1203,41 @@ on_get_owner_reply(DBusPendingCall *pending,
}
if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
- const char *current_owner = NULL;
+ const char* current_owner = NULL;
- if (!dbus_message_get_args(reply, NULL,
- DBUS_TYPE_STRING, ¤t_owner,
- DBUS_TYPE_INVALID)) {
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "GetNameOwner has wrong args '%s'",
+ if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING,
+ ¤t_owner, DBUS_TYPE_INVALID)) {
+ big_debug(BIG_DEBUG_UTIL_DBUS, "GetNameOwner has wrong args '%s'",
dbus_message_get_signature(reply));
} else {
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Got owner '%s' for name '%s'",
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Got owner '%s' for name '%s'",
current_owner, gor->name);
if (current_owner != NULL) {
- notify_name_owner_changed(gor->connection,
- gor->name,
+ notify_name_owner_changed(gor->connection, gor->name,
current_owner);
}
}
} else if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
if (g_str_equal(dbus_message_get_error_name(reply),
DBUS_ERROR_NAME_HAS_NO_OWNER)) {
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "'%s' was not running",
- gor->name);
+ big_debug(BIG_DEBUG_UTIL_DBUS, "'%s' was not running", gor->name);
if (gor->flags & BIG_DBUS_NAME_START_IF_NOT_FOUND) {
- big_debug(BIG_DEBUG_UTIL_DBUS,
- " (starting it up)");
+ big_debug(BIG_DEBUG_UTIL_DBUS, " (starting it up)");
big_dbus_start_service(gor->connection, gor->name);
} else {
/* no owner for now, notify app */
- notify_name_owner_changed(gor->connection,
- gor->name,
- "");
+ notify_name_owner_changed(gor->connection, gor->name, "");
}
} else {
big_debug(BIG_DEBUG_UTIL_DBUS,
- "Error getting owner of name '%s': %s",
- gor->name,
+ "Error getting owner of name '%s': %s", gor->name,
dbus_message_get_error_name(reply));
/* Notify no owner for now, ensuring the app
* gets advised "appeared" or "vanished",
* one or the other.
*/
- notify_name_owner_changed(gor->connection,
- gor->name,
- "");
+ notify_name_owner_changed(gor->connection, gor->name, "");
}
} else {
big_debug(BIG_DEBUG_UTIL_DBUS,
@@ -1279,41 +1248,35 @@ on_get_owner_reply(DBusPendingCall *pending,
}
static void
-request_name_owner(DBusConnection *connection,
- BigDBusInfo *info,
- BigNameWatch *watch)
+request_name_owner(DBusConnection* connection,
+ BigDBusInfo* info,
+ BigNameWatch* watch)
{
- DBusMessage *message;
- DBusPendingCall *call;
+ DBusMessage* message;
+ DBusPendingCall* call;
- message = dbus_message_new_method_call(DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- "GetNameOwner");
+ message = dbus_message_new_method_call(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS, "GetNameOwner");
if (message == NULL)
g_error("no memory");
- if (!dbus_message_append_args(message,
- DBUS_TYPE_STRING, &watch->name,
+ if (!dbus_message_append_args(message, DBUS_TYPE_STRING, &watch->name,
DBUS_TYPE_INVALID))
g_error("no memory");
call = NULL;
dbus_connection_send_with_reply(connection, message, &call, -1);
if (call != NULL) {
- GetOwnerRequest *gor;
+ GetOwnerRequest* gor;
BigDBusWatchNameFlags flags;
- GSList *l;
+ GSList* l;
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Sent GetNameOwner for '%s'",
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Sent GetNameOwner for '%s'",
watch->name);
flags = 0;
- for (l = watch->watchers;
- l != NULL;
- l = l->next) {
- BigNameWatcher *watcher = l->data;
+ for (l = watch->watchers; l != NULL; l = l->next) {
+ BigNameWatcher* watcher = l->data;
if (watcher->flags & BIG_DBUS_NAME_START_IF_NOT_FOUND)
flags |= BIG_DBUS_NAME_START_IF_NOT_FOUND;
@@ -1321,9 +1284,9 @@ request_name_owner(DBusConnection *connection,
gor = get_owner_request_new(connection, watch->name, flags);
- if (!dbus_pending_call_set_notify(call, on_get_owner_reply,
- gor,
- (DBusFreeFunction) get_owner_request_free))
+ if (!dbus_pending_call_set_notify(call, on_get_owner_reply, gor,
+ (DBusFreeFunction)
+ get_owner_request_free))
g_error("no memory");
/* the connection will hold a ref to the pending call */
@@ -1338,8 +1301,8 @@ request_name_owner(DBusConnection *connection,
static gboolean
notify_watcher_name_appeared(gpointer data)
{
- BigNameWatcher *watcher;
- DBusConnection *connection;
+ BigNameWatcher* watcher;
+ DBusConnection* connection;
watcher = data;
watcher->notify_idle = 0;
@@ -1349,20 +1312,18 @@ notify_watcher_name_appeared(gpointer data)
if (!connection)
return FALSE;
- (* watcher->funcs->appeared) (connection,
- watcher->watch->name,
- watcher->watch->current_owner,
- watcher->data);
+ (*watcher->funcs->appeared)(connection, watcher->watch->name,
+ watcher->watch->current_owner, watcher->data);
return FALSE;
}
static void
-create_watch_for_watcher(DBusConnection *connection,
- BigDBusInfo *info,
- const char *name,
- BigNameWatcher *watcher)
+create_watch_for_watcher(DBusConnection* connection,
+ BigDBusInfo* info,
+ const char* name,
+ BigNameWatcher* watcher)
{
- BigNameWatch *watch;
+ BigNameWatch* watch;
watch = g_hash_table_lookup(info->name_watches, name);
if (watch == NULL) {
@@ -1372,7 +1333,8 @@ create_watch_for_watcher(DBusConnection *connection,
watch->watchers = g_slist_prepend(watch->watchers, watcher);
- _big_dbus_set_matching_name_owner_changed(connection, watch->name, TRUE);
+ _big_dbus_set_matching_name_owner_changed(connection, watch->name,
+ TRUE);
request_name_owner(connection, info, watch);
} else {
@@ -1381,42 +1343,37 @@ create_watch_for_watcher(DBusConnection *connection,
name_watcher_ref(watcher);
watcher->watch = watch;
-
}
static void
-process_pending_name_watchers(DBusConnection *connection,
- BigDBusInfo *info)
+process_pending_name_watchers(DBusConnection* connection, BigDBusInfo* info)
{
- GSList *still_pending;
+ GSList* still_pending;
still_pending = NULL;
while (pending_name_watchers != NULL) {
- BigPendingNameWatcher *pending;
- BigNameWatch *watch;
+ BigPendingNameWatcher* pending;
+ BigNameWatch* watch;
pending = pending_name_watchers->data;
- pending_name_watchers = g_slist_remove(pending_name_watchers,
- pending_name_watchers->data);
+ pending_name_watchers
+ = g_slist_remove(pending_name_watchers, pending_name_watchers->data);
if (pending->bus_type != info->bus_type) {
still_pending = g_slist_prepend(still_pending, pending);
continue;
}
- create_watch_for_watcher(connection,
- info,
- pending->name,
+ create_watch_for_watcher(connection, info, pending->name,
pending->watcher);
watch = pending->watcher->watch;
/* If we already know the owner, let the new watcher know */
if (watch->current_owner != NULL) {
- (* pending->watcher->funcs->appeared) (connection,
- watch->name,
- watch->current_owner,
- pending->watcher->data);
+ (*pending->watcher->funcs->appeared)(connection, watch->name,
+ watch->current_owner,
+ pending->watcher->data);
}
g_free(pending->name);
@@ -1429,11 +1386,9 @@ process_pending_name_watchers(DBusConnection *connection,
}
static void
-name_watch_remove_watcher(BigNameWatch *watch,
- BigNameWatcher *watcher)
+name_watch_remove_watcher(BigNameWatch* watch, BigNameWatcher* watcher)
{
- watch->watchers = g_slist_remove(watch->watchers,
- watcher);
+ watch->watchers = g_slist_remove(watch->watchers, watcher);
if (watcher->notify_idle) {
g_source_remove(watcher->notify_idle);
@@ -1445,47 +1400,41 @@ name_watch_remove_watcher(BigNameWatch *watch,
}
void
-big_dbus_watch_name(DBusBusType bus_type,
- const char *name,
- BigDBusWatchNameFlags flags,
- const BigDBusWatchNameFuncs *funcs,
- void *data)
+big_dbus_watch_name(DBusBusType bus_type,
+ const char* name,
+ BigDBusWatchNameFlags flags,
+ const BigDBusWatchNameFuncs* funcs,
+ void* data)
{
- BigNameWatcher *watcher;
- DBusConnection *connection;
+ BigNameWatcher* watcher;
+ DBusConnection* connection;
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Adding watch on name '%s'",
- name);
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Adding watch on name '%s'", name);
watcher = name_watcher_new(flags, funcs, data, bus_type);
connection = _big_dbus_get_weak_ref(bus_type);
if (connection) {
- BigDBusInfo *info;
+ BigDBusInfo* info;
info = _big_dbus_ensure_info(connection);
- create_watch_for_watcher(connection,
- info,
- name,
- watcher);
+ create_watch_for_watcher(connection, info, name, watcher);
/* The initial reference is now transferred to the watch */
name_watcher_unref(watcher);
/* If we already know the owner, notify the user in an idle */
if (watcher->watch->current_owner) {
- watcher->notify_idle =
- g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
- notify_watcher_name_appeared,
- watcher,
- (GDestroyNotify)name_watcher_unref);
+ watcher->notify_idle
+ = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE,
+ notify_watcher_name_appeared, watcher,
+ (GDestroyNotify) name_watcher_unref);
name_watcher_ref(watcher);
}
} else {
- BigPendingNameWatcher *pending;
+ BigPendingNameWatcher* pending;
pending = g_slice_new0(BigPendingNameWatcher);
@@ -1500,20 +1449,18 @@ big_dbus_watch_name(DBusBusType bus_type,
}
void
-big_dbus_unwatch_name(DBusBusType bus_type,
- const char *name,
- const BigDBusWatchNameFuncs *funcs,
- void *data)
+big_dbus_unwatch_name(DBusBusType bus_type,
+ const char* name,
+ const BigDBusWatchNameFuncs* funcs,
+ void* data)
{
- DBusConnection *connection;
- BigDBusInfo *info;
- BigNameWatch *watch;
- GSList *l;
- BigNameWatcher *watcher;
+ DBusConnection* connection;
+ BigDBusInfo* info;
+ BigNameWatch* watch;
+ GSList* l;
+ BigNameWatcher* watcher;
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Removing watch on name '%s'",
- name);
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Removing watch on name '%s'", name);
connection = _big_dbus_get_weak_ref(bus_type);
if (connection == NULL) {
@@ -1542,14 +1489,13 @@ big_dbus_unwatch_name(DBusBusType bus_type,
for (l = watch->watchers; l != NULL; l = l->next) {
watcher = l->data;
- if (watcher->funcs == funcs &&
- watcher->data == data)
+ if (watcher->funcs == funcs && watcher->data == data)
break;
}
if (l == NULL) {
- g_warning("Could not find a watch on %s matching %p %p",
- name, funcs, data);
+ g_warning("Could not find a watch on %s matching %p %p", name, funcs,
+ data);
return;
}
g_assert(l->data == watcher);
@@ -1560,19 +1506,19 @@ big_dbus_unwatch_name(DBusBusType bus_type,
if (watch->watchers == NULL) {
g_hash_table_remove(info->name_watches, watch->name);
- _big_dbus_set_matching_name_owner_changed(connection, watch->name, FALSE);
+ _big_dbus_set_matching_name_owner_changed(connection, watch->name,
+ FALSE);
name_watch_free(watch);
}
}
const char*
-big_dbus_get_watched_name_owner(DBusBusType bus_type,
- const char *name)
+big_dbus_get_watched_name_owner(DBusBusType bus_type, const char* name)
{
- DBusConnection *connection;
- BigNameWatch *watch;
- BigDBusInfo *info;
+ DBusConnection* connection;
+ BigNameWatch* watch;
+ BigDBusInfo* info;
connection = _big_dbus_get_weak_ref(bus_type);
if (connection == NULL) {
@@ -1595,13 +1541,13 @@ big_dbus_get_watched_name_owner(DBusBusType bus_type,
}
void
-big_dbus_register_json(DBusConnection *connection,
- const char *iface_name,
- const BigDBusJsonMethod *methods,
- int n_methods)
+big_dbus_register_json(DBusConnection* connection,
+ const char* iface_name,
+ const BigDBusJsonMethod* methods,
+ int n_methods)
{
- BigDBusInfo *info;
- BigJsonIface *iface;
+ BigDBusInfo* info;
+ BigJsonIface* iface;
info = _big_dbus_ensure_info(connection);
@@ -1611,27 +1557,26 @@ big_dbus_register_json(DBusConnection *connection,
}
void
-big_dbus_unregister_json(DBusConnection *connection,
- const char *iface_name)
+big_dbus_unregister_json(DBusConnection* connection, const char* iface_name)
{
- BigDBusInfo *info;
+ BigDBusInfo* info;
info = _big_dbus_ensure_info(connection);
g_hash_table_remove(info->json_ifaces, iface_name);
}
-typedef struct {
- DBusConnection *connection;
- GObject *gobj;
- char *iface_name;
+typedef struct
+{
+ DBusConnection* connection;
+ GObject* gobj;
+ char* iface_name;
} BigDBusGObject;
static void
-gobj_path_unregistered(DBusConnection *connection,
- void *user_data)
+gobj_path_unregistered(DBusConnection* connection, void* user_data)
{
- BigDBusGObject *g;
+ BigDBusGObject* g;
g = user_data;
@@ -1645,25 +1590,24 @@ gobj_path_unregistered(DBusConnection *connection,
}
static DBusHandlerResult
-gobj_path_message(DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
-{
- BigDBusGObject *g;
- BigDBusInfo *info;
- BigJsonIface *iface;
- const char *message_iface;
- const char *message_method;
+gobj_path_message(DBusConnection* connection,
+ DBusMessage* message,
+ void* user_data)
+{
+ BigDBusGObject* g;
+ BigDBusInfo* info;
+ BigJsonIface* iface;
+ const char* message_iface;
+ const char* message_method;
DBusError derror;
int i;
- const BigDBusJsonMethod *method;
+ const BigDBusJsonMethod* method;
DBusMessageIter arg_iter, dict_iter;
info = _big_dbus_ensure_info(connection);
g = user_data;
- big_debug(BIG_DEBUG_UTIL_DBUS,
- "Received message to iface %s gobj %p",
+ big_debug(BIG_DEBUG_UTIL_DBUS, "Received message to iface %s gobj %p",
g->iface_name, g->gobj);
if (g->gobj == NULL) {
@@ -1680,24 +1624,23 @@ gobj_path_message(DBusConnection *connection,
/* FIXME implement Introspectable() just to enable dbus debugger */
- if (message_iface != NULL &&
- strcmp(message_iface, g->iface_name) != 0) {
+ if (message_iface != NULL && strcmp(message_iface, g->iface_name) != 0) {
- dbus_set_error(&derror, DBUS_ERROR_UNKNOWN_METHOD,
- "Interface '%s' not implemented by this object, did you mean '%s'?",
- message_iface, g->iface_name);
+ dbus_set_error(
+ &derror, DBUS_ERROR_UNKNOWN_METHOD,
+ "Interface '%s' not implemented by this object, did you mean '%s'?",
+ message_iface, g->iface_name);
goto out;
}
- iface = g_hash_table_lookup(info->json_ifaces,
- g->iface_name);
+ iface = g_hash_table_lookup(info->json_ifaces, g->iface_name);
if (iface == NULL) {
- g_warning("Object registered with iface %s but that iface is not registered",
- g->iface_name);
+ g_warning(
+ "Object registered with iface %s but that iface is not registered",
+ g->iface_name);
dbus_set_error(&derror, DBUS_ERROR_UNKNOWN_METHOD,
- "Bug - '%s' is not registered",
- g->iface_name);
+ "Bug - '%s' is not registered", g->iface_name);
goto out;
}
@@ -1712,15 +1655,16 @@ gobj_path_message(DBusConnection *connection,
if (method == NULL) {
dbus_set_error(&derror, DBUS_ERROR_UNKNOWN_METHOD,
- "Interface '%s' has no method '%s'",
- g->iface_name, message_method);
+ "Interface '%s' has no method '%s'", g->iface_name,
+ message_method);
goto out;
}
if (!dbus_message_has_signature(message, "a{sv}")) {
- dbus_set_error(&derror, DBUS_ERROR_INVALID_ARGS,
- "Method %s.%s should have 1 argument which is a dictionary",
- g->iface_name, message_method);
+ dbus_set_error(
+ &derror, DBUS_ERROR_INVALID_ARGS,
+ "Method %s.%s should have 1 argument which is a dictionary",
+ g->iface_name, message_method);
goto out;
}
@@ -1728,26 +1672,22 @@ gobj_path_message(DBusConnection *connection,
dbus_message_iter_recurse(&arg_iter, &dict_iter);
if (method->sync_func != NULL) {
- DBusMessage *reply;
+ DBusMessage* reply;
DBusMessageIter out_arg_iter, out_dict_iter;
reply = dbus_message_new_method_return(message);
if (reply == NULL) {
- dbus_set_error(&derror, DBUS_ERROR_NO_MEMORY,
- "No memory");
+ dbus_set_error(&derror, DBUS_ERROR_NO_MEMORY, "No memory");
goto out;
}
dbus_message_iter_init_append(reply, &out_arg_iter);
- dbus_message_iter_open_container(&out_arg_iter,
- DBUS_TYPE_ARRAY, "{sv}",
+ dbus_message_iter_open_container(&out_arg_iter, DBUS_TYPE_ARRAY, "{sv}",
&out_dict_iter);
g_object_ref(g->gobj);
- (* method->sync_func) (connection, message,
- &dict_iter, &out_dict_iter,
- g->gobj,
- &derror);
+ (*method->sync_func)(connection, message, &dict_iter, &out_dict_iter,
+ g->gobj, &derror);
g_object_unref(g->gobj);
dbus_message_iter_close_container(&out_arg_iter, &out_dict_iter);
@@ -1759,21 +1699,17 @@ gobj_path_message(DBusConnection *connection,
} else if (method->async_func != NULL) {
g_object_ref(g->gobj);
- (* method->async_func) (connection, message,
- &dict_iter,
- g->gobj);
+ (*method->async_func)(connection, message, &dict_iter, g->gobj);
g_object_unref(g->gobj);
} else {
g_warning("Method %s does not have any implementation", method->name);
}
- out:
+out:
if (dbus_error_is_set(&derror)) {
- DBusMessage *reply;
+ DBusMessage* reply;
- reply = dbus_message_new_error(message,
- derror.name,
- derror.message);
+ reply = dbus_message_new_error(message, derror.name, derror.message);
dbus_error_free(&derror);
if (reply != NULL) {
@@ -1792,9 +1728,7 @@ gobj_path_message(DBusConnection *connection,
}
static DBusObjectPathVTable gobj_vtable = {
- gobj_path_unregistered,
- gobj_path_message,
- NULL,
+ gobj_path_unregistered, gobj_path_message, NULL,
};
/* Note that because of how this works, each object can be registered
@@ -1802,19 +1736,19 @@ static DBusObjectPathVTable gobj_vtable = {
* but we'll fix it when we need it.
*/
void
-big_dbus_register_g_object(DBusConnection *connection,
- const char *path,
- GObject *gobj,
- const char *iface_name)
+big_dbus_register_g_object(DBusConnection* connection,
+ const char* path,
+ GObject* gobj,
+ const char* iface_name)
{
- BigDBusGObject *g;
+ BigDBusGObject* g;
g = g_slice_new0(BigDBusGObject);
g->iface_name = g_strdup(iface_name);
g->gobj = gobj;
- if (!dbus_connection_register_object_path(connection, path,
- &gobj_vtable, g)) {
+ if (!dbus_connection_register_object_path(connection, path, &gobj_vtable,
+ g)) {
g_warning("Failed to register object path %s", path);
}
@@ -1822,30 +1756,31 @@ big_dbus_register_g_object(DBusConnection *connection,
}
void
-big_dbus_unregister_g_object (DBusConnection *connection,
- const char *path)
+big_dbus_unregister_g_object(DBusConnection* connection, const char* path)
{
dbus_connection_unregister_object_path(connection, path);
}
static void
-open_json_entry(DBusMessageIter *dict_iter,
- const char *key,
- const char *signature,
- DBusMessageIter *entry_iter,
- DBusMessageIter *variant_iter)
+open_json_entry(DBusMessageIter* dict_iter,
+ const char* key,
+ const char* signature,
+ DBusMessageIter* entry_iter,
+ DBusMessageIter* variant_iter)
{
- dbus_message_iter_open_container(dict_iter, DBUS_TYPE_DICT_ENTRY, NULL, entry_iter);
+ dbus_message_iter_open_container(dict_iter, DBUS_TYPE_DICT_ENTRY, NULL,
+ entry_iter);
dbus_message_iter_append_basic(entry_iter, DBUS_TYPE_STRING, &key);
- dbus_message_iter_open_container(entry_iter, DBUS_TYPE_VARIANT, signature, variant_iter);
+ dbus_message_iter_open_container(entry_iter, DBUS_TYPE_VARIANT, signature,
+ variant_iter);
}
static void
-close_json_entry(DBusMessageIter *dict_iter,
- DBusMessageIter *entry_iter,
- DBusMessageIter *variant_iter)
+close_json_entry(DBusMessageIter* dict_iter,
+ DBusMessageIter* entry_iter,
+ DBusMessageIter* variant_iter)
{
dbus_message_iter_close_container(entry_iter, variant_iter);
@@ -1853,12 +1788,12 @@ close_json_entry(DBusMessageIter *dict_iter,
}
static void
-open_json_entry_array(DBusMessageIter *dict_iter,
- const char *key,
- int array_element_type,
- DBusMessageIter *entry_iter,
- DBusMessageIter *variant_iter,
- DBusMessageIter *array_iter)
+open_json_entry_array(DBusMessageIter* dict_iter,
+ const char* key,
+ int array_element_type,
+ DBusMessageIter* entry_iter,
+ DBusMessageIter* variant_iter,
+ DBusMessageIter* array_iter)
{
char buf[3];
buf[0] = 'a';
@@ -1867,14 +1802,15 @@ open_json_entry_array(DBusMessageIter *dict_iter,
open_json_entry(dict_iter, key, buf, entry_iter, variant_iter);
- dbus_message_iter_open_container(variant_iter, DBUS_TYPE_ARRAY, &buf[1], array_iter);
+ dbus_message_iter_open_container(variant_iter, DBUS_TYPE_ARRAY, &buf[1],
+ array_iter);
}
static void
-close_json_entry_array(DBusMessageIter *dict_iter,
- DBusMessageIter *entry_iter,
- DBusMessageIter *variant_iter,
- DBusMessageIter *array_iter)
+close_json_entry_array(DBusMessageIter* dict_iter,
+ DBusMessageIter* entry_iter,
+ DBusMessageIter* variant_iter,
+ DBusMessageIter* array_iter)
{
dbus_message_iter_close_container(variant_iter, array_iter);
@@ -1882,10 +1818,10 @@ close_json_entry_array(DBusMessageIter *dict_iter,
}
void
-big_dbus_append_json_entry (DBusMessageIter *dict_iter,
- const char *key,
- int dbus_type,
- void *basic_value_p)
+big_dbus_append_json_entry(DBusMessageIter* dict_iter,
+ const char* key,
+ int dbus_type,
+ void* basic_value_p)
{
DBusMessageIter entry_iter, variant_iter;
char buf[2];
@@ -1901,138 +1837,128 @@ big_dbus_append_json_entry (DBusMessageIter *dict_iter,
}
void
-big_dbus_append_json_entry_STRING (DBusMessageIter *dict_iter,
- const char *key,
- const char *value)
+big_dbus_append_json_entry_STRING(DBusMessageIter* dict_iter,
+ const char* key,
+ const char* value)
{
big_dbus_append_json_entry(dict_iter, key, DBUS_TYPE_STRING, &value);
}
void
-big_dbus_append_json_entry_INT32 (DBusMessageIter *dict_iter,
- const char *key,
- dbus_int32_t value)
+big_dbus_append_json_entry_INT32(DBusMessageIter* dict_iter,
+ const char* key,
+ dbus_int32_t value)
{
big_dbus_append_json_entry(dict_iter, key, DBUS_TYPE_INT32, &value);
}
void
-big_dbus_append_json_entry_DOUBLE (DBusMessageIter *dict_iter,
- const char *key,
- double value)
+big_dbus_append_json_entry_DOUBLE(DBusMessageIter* dict_iter,
+ const char* key,
+ double value)
{
big_dbus_append_json_entry(dict_iter, key, DBUS_TYPE_DOUBLE, &value);
}
void
-big_dbus_append_json_entry_BOOLEAN (DBusMessageIter *dict_iter,
- const char *key,
- dbus_bool_t value)
+big_dbus_append_json_entry_BOOLEAN(DBusMessageIter* dict_iter,
+ const char* key,
+ dbus_bool_t value)
{
big_dbus_append_json_entry(dict_iter, key, DBUS_TYPE_BOOLEAN, &value);
}
-/* when coming from a dynamic language, we don't know what type of array '[]' is supposed to be */
+/* when coming from a dynamic language, we don't know what type of array '[]' is
+ * supposed to be */
void
-big_dbus_append_json_entry_EMPTY_ARRAY (DBusMessageIter *dict_iter,
- const char *key)
+big_dbus_append_json_entry_EMPTY_ARRAY(DBusMessageIter* dict_iter,
+ const char* key)
{
DBusMessageIter entry_iter, variant_iter, array_iter;
- /* so just say VARIANT even though there won't be any elements in the array */
- open_json_entry_array(dict_iter, key, DBUS_TYPE_VARIANT, &entry_iter, &variant_iter, &array_iter);
+ /* so just say VARIANT even though there won't be any elements in the array
+ */
+ open_json_entry_array(dict_iter, key, DBUS_TYPE_VARIANT, &entry_iter,
+ &variant_iter, &array_iter);
close_json_entry_array(dict_iter, &entry_iter, &variant_iter, &array_iter);
}
void
-big_dbus_append_json_entry_STRING_ARRAY (DBusMessageIter *dict_iter,
- const char *key,
- const char **value)
+big_dbus_append_json_entry_STRING_ARRAY(DBusMessageIter* dict_iter,
+ const char* key,
+ const char** value)
{
DBusMessageIter entry_iter, variant_iter, array_iter;
int i;
- open_json_entry_array(dict_iter, key, DBUS_TYPE_STRING, &entry_iter, &variant_iter, &array_iter);
+ open_json_entry_array(dict_iter, key, DBUS_TYPE_STRING, &entry_iter,
+ &variant_iter, &array_iter);
for (i = 0; value[i] != NULL; ++i) {
- dbus_message_iter_append_basic(&array_iter, DBUS_TYPE_STRING, &value[i]);
+ dbus_message_iter_append_basic(&array_iter, DBUS_TYPE_STRING,
+ &value[i]);
}
close_json_entry_array(dict_iter, &entry_iter, &variant_iter, &array_iter);
}
gboolean
-big_dbus_message_iter_get_gsize(DBusMessageIter *iter,
- gsize *value_p)
+big_dbus_message_iter_get_gsize(DBusMessageIter* iter, gsize* value_p)
{
switch (dbus_message_iter_get_arg_type(iter)) {
- case DBUS_TYPE_INT32:
- {
+ case DBUS_TYPE_INT32: {
dbus_int32_t v;
dbus_message_iter_get_basic(iter, &v);
if (v < 0)
return FALSE;
*value_p = v;
- }
- break;
- case DBUS_TYPE_UINT32:
- {
+ } break;
+ case DBUS_TYPE_UINT32: {
dbus_uint32_t v;
dbus_message_iter_get_basic(iter, &v);
*value_p = v;
- }
- break;
- case DBUS_TYPE_INT64:
- {
+ } break;
+ case DBUS_TYPE_INT64: {
dbus_int64_t v;
dbus_message_iter_get_basic(iter, &v);
if (v < 0)
return FALSE;
- if (((guint64)v) > G_MAXSIZE)
+ if (((guint64) v) > G_MAXSIZE)
return FALSE;
*value_p = v;
- }
- break;
- case DBUS_TYPE_UINT64:
- {
+ } break;
+ case DBUS_TYPE_UINT64: {
dbus_uint64_t v;
dbus_message_iter_get_basic(iter, &v);
if (v > G_MAXSIZE)
return FALSE;
*value_p = v;
- }
- break;
- default:
- return FALSE;
+ } break;
+ default:
+ return FALSE;
}
return TRUE;
}
gboolean
-big_dbus_message_iter_get_gssize(DBusMessageIter *iter,
- gssize *value_p)
+big_dbus_message_iter_get_gssize(DBusMessageIter* iter, gssize* value_p)
{
switch (dbus_message_iter_get_arg_type(iter)) {
- case DBUS_TYPE_INT32:
- {
+ case DBUS_TYPE_INT32: {
dbus_int32_t v;
dbus_message_iter_get_basic(iter, &v);
*value_p = v;
- }
- break;
- case DBUS_TYPE_UINT32:
- {
+ } break;
+ case DBUS_TYPE_UINT32: {
dbus_uint32_t v;
dbus_message_iter_get_basic(iter, &v);
if (v > (guint32) G_MAXSSIZE)
return FALSE;
*value_p = v;
- }
- break;
- case DBUS_TYPE_INT64:
- {
+ } break;
+ case DBUS_TYPE_INT64: {
dbus_int64_t v;
dbus_message_iter_get_basic(iter, &v);
if (v > (gint64) G_MAXSSIZE)
@@ -2040,19 +1966,16 @@ big_dbus_message_iter_get_gssize(DBusMessageIter *iter,
if (v < (gint64) G_MINSSIZE)
return FALSE;
*value_p = v;
- }
- break;
- case DBUS_TYPE_UINT64:
- {
+ } break;
+ case DBUS_TYPE_UINT64: {
dbus_uint64_t v;
dbus_message_iter_get_basic(iter, &v);
if (v > (guint64) G_MAXSSIZE)
return FALSE;
*value_p = v;
- }
- break;
- default:
- return FALSE;
+ } break;
+ default:
+ return FALSE;
}
return TRUE;
@@ -2073,23 +1996,27 @@ big_dbus_message_iter_get_gssize(DBusMessageIter *iter,
#include <sys/wait.h>
static pid_t test_service_pid = 0;
-static BigDBusProxy *test_service_proxy = NULL;
+static BigDBusProxy* test_service_proxy = NULL;
static pid_t test_io_pid = 0;
-static BigDBusProxy *test_io_proxy = NULL;
+static BigDBusProxy* test_io_proxy = NULL;
-static GMainLoop *client_loop = NULL;
+static GMainLoop* client_loop = NULL;
static int n_running_children = 0;
-static BigDBusInputStream *input_from_io_service;
-static BigDBusOutputStream *output_to_io_service;
+static BigDBusInputStream* input_from_io_service;
+static BigDBusOutputStream* output_to_io_service;
-static const char stream_data_to_io_service[] = "This is sent from the main test process to the IO service.";
-static const char stream_data_from_io_service[] = "This is sent from the IO service to the main test
process. The quick brown fox, etc.";
+static const char stream_data_to_io_service[]
+ = "This is sent from the main test process to the IO service.";
+static const char stream_data_from_io_service[] = "This is sent from the IO "
+ "service to the main test "
+ "process. The quick brown "
+ "fox, etc.";
-static void do_test_service_child (void);
-static void do_test_io_child (void);
+static void do_test_service_child(void);
+static void do_test_io_child(void);
/* quit when all children are gone */
static void
@@ -2104,16 +2031,16 @@ another_child_down(void)
}
static const char*
-extract_string_arg(DBusMessageIter *in_iter,
- const char *prop_name,
- DBusError *error)
+extract_string_arg(DBusMessageIter* in_iter,
+ const char* prop_name,
+ DBusError* error)
{
- const char *s;
+ const char* s;
s = NULL;
while (dbus_message_iter_get_arg_type(in_iter) == DBUS_TYPE_DICT_ENTRY) {
DBusMessageIter entry_iter, variant_iter;
- const char *key;
+ const char* key;
dbus_message_iter_recurse(in_iter, &entry_iter);
@@ -2123,7 +2050,8 @@ extract_string_arg(DBusMessageIter *in_iter,
dbus_message_iter_next(&entry_iter);
dbus_message_iter_recurse(&entry_iter, &variant_iter);
- if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING) {
+ if (dbus_message_iter_get_arg_type(&variant_iter)
+ != DBUS_TYPE_STRING) {
dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
"Value of '%s' prop should be a string",
prop_name);
@@ -2136,8 +2064,8 @@ extract_string_arg(DBusMessageIter *in_iter,
}
}
- dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
- "No '%s' prop provided", prop_name);
+ dbus_set_error(error, DBUS_ERROR_INVALID_ARGS, "No '%s' prop provided",
+ prop_name);
return NULL;
}
@@ -2199,22 +2127,23 @@ fork_child_test_io(void)
}
static void
-on_expected_fnf_error_reply_kill_child(BigDBusProxy *proxy,
- const char *error_name,
- const char *error_message,
- void *data)
+on_expected_fnf_error_reply_kill_child(BigDBusProxy* proxy,
+ const char* error_name,
+ const char* error_message,
+ void* data)
{
big_debug(BIG_DEBUG_IN_TESTS,
"got expected error reply to alwaysErrorSync, killing child");
/* We were expecting an error, good. */
if (strcmp(error_name, DBUS_ERROR_FILE_NOT_FOUND) != 0) {
- g_error("Got error we did not expect %s: %s",
- error_name, error_message);
+ g_error("Got error we did not expect %s: %s", error_name,
+ error_message);
}
if (kill(test_service_pid, SIGTERM) < 0) {
- g_error("Test service was no longer around... it must have failed somehow (%s)",
+ g_error("Test service was no longer around... it must have failed "
+ "somehow (%s)",
strerror(errno));
}
@@ -2222,148 +2151,132 @@ on_expected_fnf_error_reply_kill_child(BigDBusProxy *proxy,
}
static void
-on_unexpected_error_reply(BigDBusProxy *proxy,
- const char *error_name,
- const char *error_message,
- void *data)
+on_unexpected_error_reply(BigDBusProxy* proxy,
+ const char* error_name,
+ const char* error_message,
+ void* data)
{
- const char *context_text = data;
+ const char* context_text = data;
- g_error("Got error %s: '%s' context was: %s",
- error_name, error_message, context_text);
+ g_error("Got error %s: '%s' context was: %s", error_name, error_message,
+ context_text);
}
static void
-on_get_always_error_reply(BigDBusProxy *proxy,
- DBusMessage *message,
- DBusMessageIter *return_value_iter,
- void *data)
+on_get_always_error_reply(BigDBusProxy* proxy,
+ DBusMessage* message,
+ DBusMessageIter* return_value_iter,
+ void* data)
{
- g_error("alwaysError json method supposed to return an error always, not a valid reply");
+ g_error("alwaysError json method supposed to return an error always, not a "
+ "valid reply");
}
static void
-on_get_some_stuff_reply(BigDBusProxy *proxy,
- DBusMessage *message,
- DBusMessageIter *return_value_iter,
- void *data)
+on_get_some_stuff_reply(BigDBusProxy* proxy,
+ DBusMessage* message,
+ DBusMessageIter* return_value_iter,
+ void* data)
{
- big_debug(BIG_DEBUG_IN_TESTS,
- "reply received to getSomeStuffSync");
+ big_debug(BIG_DEBUG_IN_TESTS, "reply received to getSomeStuffSync");
/* FIXME look at the return value to see if it's what
* the test service sends
*/
- big_dbus_proxy_call_json_async(test_service_proxy,
- "alwaysErrorSync",
+ big_dbus_proxy_call_json_async(test_service_proxy, "alwaysErrorSync",
on_get_always_error_reply,
- on_expected_fnf_error_reply_kill_child,
- NULL,
+ on_expected_fnf_error_reply_kill_child, NULL,
NULL);
}
static void
-on_test_service_appeared(DBusConnection *connection,
- const char *name,
- const char *new_owner_unique_name,
- void *data)
+on_test_service_appeared(DBusConnection* connection,
+ const char* name,
+ const char* new_owner_unique_name,
+ void* data)
{
dbus_int32_t v_INT32;
- big_debug(BIG_DEBUG_IN_TESTS,
- "%s appeared",
- name);
+ big_debug(BIG_DEBUG_IN_TESTS, "%s appeared", name);
- test_service_proxy =
- big_dbus_proxy_new(connection, new_owner_unique_name,
- "/com/litl/test/object42",
- "com.litl.TestIface");
+ test_service_proxy
+ = big_dbus_proxy_new(connection, new_owner_unique_name,
+ "/com/litl/test/object42", "com.litl.TestIface");
v_INT32 = 42;
- big_dbus_proxy_call_json_async(test_service_proxy,
- "getSomeStuffSync",
- on_get_some_stuff_reply,
- on_unexpected_error_reply,
- "getSomeStuffSync call from on_test_service_appeared",
- "yourNameIs", DBUS_TYPE_STRING, &name,
- "yourUniqueNameIs", DBUS_TYPE_STRING, &new_owner_unique_name,
- "anIntegerIs", DBUS_TYPE_INT32, &v_INT32,
- NULL);
+ big_dbus_proxy_call_json_async(
+ test_service_proxy, "getSomeStuffSync", on_get_some_stuff_reply,
+ on_unexpected_error_reply,
+ "getSomeStuffSync call from on_test_service_appeared", "yourNameIs",
+ DBUS_TYPE_STRING, &name, "yourUniqueNameIs", DBUS_TYPE_STRING,
+ &new_owner_unique_name, "anIntegerIs", DBUS_TYPE_INT32, &v_INT32, NULL);
}
static void
-on_test_service_vanished(DBusConnection *connection,
- const char *name,
- const char *old_owner_unique_name,
- void *data)
+on_test_service_vanished(DBusConnection* connection,
+ const char* name,
+ const char* old_owner_unique_name,
+ void* data)
{
- big_debug(BIG_DEBUG_IN_TESTS,
- "%s vanished", name);
+ big_debug(BIG_DEBUG_IN_TESTS, "%s vanished", name);
another_child_down();
}
-static BigDBusWatchNameFuncs watch_test_service_funcs = {
- on_test_service_appeared,
- on_test_service_vanished
-};
+static BigDBusWatchNameFuncs watch_test_service_funcs
+ = { on_test_service_appeared, on_test_service_vanished };
static void
-on_confirm_streams_reply(BigDBusProxy *proxy,
- DBusMessage *message,
- DBusMessageIter *return_value_iter,
- void *data)
+on_confirm_streams_reply(BigDBusProxy* proxy,
+ DBusMessage* message,
+ DBusMessageIter* return_value_iter,
+ void* data)
{
- const char *received;
+ const char* received;
- received = extract_string_arg(return_value_iter,
- "received",
- NULL);
+ received = extract_string_arg(return_value_iter, "received", NULL);
g_assert(received != NULL);
if (strcmp(received, stream_data_to_io_service) != 0) {
g_error("We sent the child process '%s' but it says it got '%s'",
- stream_data_to_io_service,
- received);
+ stream_data_to_io_service, received);
}
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestIO says it got: '%s'", received);
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestIO says it got: '%s'",
+ received);
/* We've exchanged all our streams - time to kill the TestIO
* child process
*/
big_debug(BIG_DEBUG_IN_TESTS, "Sending TERM to TestIO child");
if (kill(test_io_pid, SIGTERM) < 0) {
- g_error("Test IO service was no longer around... it must have failed somehow (%s)",
+ g_error("Test IO service was no longer around... it must have failed "
+ "somehow (%s)",
strerror(errno));
}
}
static void
-on_setup_streams_reply(BigDBusProxy *proxy,
- DBusMessage *message,
- DBusMessageIter *return_value_iter,
- void *data)
+on_setup_streams_reply(BigDBusProxy* proxy,
+ DBusMessage* message,
+ DBusMessageIter* return_value_iter,
+ void* data)
{
- const char *stream_path;
+ const char* stream_path;
gsize total;
gssize result;
gsize read_size;
- GError *error;
- GString *str;
+ GError* error;
+ GString* str;
char buf[10];
- big_debug(BIG_DEBUG_IN_TESTS,
- "Got reply to setupStreams");
+ big_debug(BIG_DEBUG_IN_TESTS, "Got reply to setupStreams");
- stream_path = extract_string_arg(return_value_iter,
- "stream",
- NULL);
+ stream_path = extract_string_arg(return_value_iter, "stream", NULL);
g_assert(stream_path != NULL);
- output_to_io_service =
- big_dbus_output_stream_new(big_dbus_proxy_get_connection(proxy),
+ output_to_io_service
+ = big_dbus_output_stream_new(big_dbus_proxy_get_connection(proxy),
dbus_message_get_sender(message),
stream_path);
@@ -2375,10 +2288,7 @@ on_setup_streams_reply(BigDBusProxy *proxy,
error = NULL;
result = g_output_stream_write(G_OUTPUT_STREAM(output_to_io_service),
- stream_data_to_io_service,
- 10,
- NULL,
- &error);
+ stream_data_to_io_service, 10, NULL, &error);
if (result < 0) {
g_error("Error writing to output stream: %s", error->message);
g_error_free(error);
@@ -2389,8 +2299,7 @@ on_setup_streams_reply(BigDBusProxy *proxy,
}
if (!g_output_stream_write_all(G_OUTPUT_STREAM(output_to_io_service),
- stream_data_to_io_service + 10,
- total - 10,
+ stream_data_to_io_service + 10, total - 10,
NULL, NULL, &error)) {
g_error("Error writing all to output stream: %s", error->message);
g_error_free(error);
@@ -2399,12 +2308,14 @@ on_setup_streams_reply(BigDBusProxy *proxy,
/* flush should do nothing here, and is not needed, but
* just calling it to test it
*/
- if (!g_output_stream_flush(G_OUTPUT_STREAM(output_to_io_service), NULL, &error)) {
+ if (!g_output_stream_flush(G_OUTPUT_STREAM(output_to_io_service), NULL,
+ &error)) {
g_error("Error flushing output stream: %s", error->message);
g_error_free(error);
}
- if (!g_output_stream_close(G_OUTPUT_STREAM(output_to_io_service), NULL, &error)) {
+ if (!g_output_stream_close(G_OUTPUT_STREAM(output_to_io_service), NULL,
+ &error)) {
g_error("Error closing output stream: %s", error->message);
g_error_free(error);
}
@@ -2420,16 +2331,15 @@ on_setup_streams_reply(BigDBusProxy *proxy,
while (TRUE) {
/* test get_received() */
- g_assert(big_dbus_input_stream_get_received(input_from_io_service) <=
strlen(stream_data_from_io_service));
+ g_assert(big_dbus_input_stream_get_received(input_from_io_service)
+ <= strlen(stream_data_from_io_service));
/* This is a blocking read... in production code, you would
* want to use the ready-to-read signal instead to avoid
* blocking when there is nothing to read.
*/
- result = g_input_stream_read(G_INPUT_STREAM(input_from_io_service),
- buf,
- read_size,
- NULL, &error);
+ result = g_input_stream_read(G_INPUT_STREAM(input_from_io_service), buf,
+ read_size, NULL, &error);
if (result < 0) {
g_error("Error reading %d bytes from input stream: %s",
(int) read_size, error->message);
@@ -2447,7 +2357,8 @@ on_setup_streams_reply(BigDBusProxy *proxy,
read_size += 1;
}
- if (!g_input_stream_close(G_INPUT_STREAM(input_from_io_service), NULL, &error)) {
+ if (!g_input_stream_close(G_INPUT_STREAM(input_from_io_service), NULL,
+ &error)) {
g_error("Error closing input stream: %s", error->message);
g_error_free(error);
}
@@ -2456,45 +2367,38 @@ on_setup_streams_reply(BigDBusProxy *proxy,
/* Now make the confirmStreams call
*/
- big_debug(BIG_DEBUG_IN_TESTS,
- "Confirming to com.litl.TestIO we got: '%s'", str->str);
+ big_debug(BIG_DEBUG_IN_TESTS, "Confirming to com.litl.TestIO we got: '%s'",
+ str->str);
- big_dbus_proxy_call_json_async(test_io_proxy,
- "confirmStreamsData",
- on_confirm_streams_reply,
- on_unexpected_error_reply,
- "confirmStreamsData call from on_setup_streams_reply",
- "received", DBUS_TYPE_STRING, &str->str,
- NULL);
+ big_dbus_proxy_call_json_async(
+ test_io_proxy, "confirmStreamsData", on_confirm_streams_reply,
+ on_unexpected_error_reply,
+ "confirmStreamsData call from on_setup_streams_reply", "received",
+ DBUS_TYPE_STRING, &str->str, NULL);
g_string_free(str, TRUE);
}
static void
-on_test_io_appeared(DBusConnection *connection,
- const char *name,
- const char *new_owner_unique_name,
- void *data)
+on_test_io_appeared(DBusConnection* connection,
+ const char* name,
+ const char* new_owner_unique_name,
+ void* data)
{
- const char *stream_path;
+ const char* stream_path;
- big_debug(BIG_DEBUG_IN_TESTS,
- "%s appeared",
- name);
+ big_debug(BIG_DEBUG_IN_TESTS, "%s appeared", name);
- test_io_proxy =
- big_dbus_proxy_new(connection, new_owner_unique_name,
- "/com/litl/test/object47",
- "com.litl.TestIO");
+ test_io_proxy
+ = big_dbus_proxy_new(connection, new_owner_unique_name,
+ "/com/litl/test/object47", "com.litl.TestIO");
- input_from_io_service =
- g_object_new(BIG_TYPE_DBUS_INPUT_STREAM, NULL);
+ input_from_io_service = g_object_new(BIG_TYPE_DBUS_INPUT_STREAM, NULL);
big_dbus_input_stream_attach(input_from_io_service, connection);
stream_path = big_dbus_input_stream_get_path(input_from_io_service);
- big_dbus_proxy_call_json_async(test_io_proxy,
- "setupStreams",
+ big_dbus_proxy_call_json_async(test_io_proxy, "setupStreams",
on_setup_streams_reply,
on_unexpected_error_reply,
"setupStreams call from on_test_io_appeared",
@@ -2503,21 +2407,18 @@ on_test_io_appeared(DBusConnection *connection,
}
static void
-on_test_io_vanished(DBusConnection *connection,
- const char *name,
- const char *old_owner_unique_name,
- void *data)
+on_test_io_vanished(DBusConnection* connection,
+ const char* name,
+ const char* old_owner_unique_name,
+ void* data)
{
- big_debug(BIG_DEBUG_IN_TESTS,
- "%s vanished", name);
+ big_debug(BIG_DEBUG_IN_TESTS, "%s vanished", name);
another_child_down();
}
-static BigDBusWatchNameFuncs watch_test_io_funcs = {
- on_test_io_appeared,
- on_test_io_vanished
-};
+static BigDBusWatchNameFuncs watch_test_io_funcs
+ = { on_test_io_appeared, on_test_io_vanished };
void
bigtest_test_func_util_dbus_client(void)
@@ -2552,17 +2453,11 @@ bigtest_test_func_util_dbus_client(void)
g_assert(test_service_pid != 0);
g_assert(test_io_pid != 0);
- big_dbus_watch_name(DBUS_BUS_SESSION,
- "com.litl.TestService",
- 0,
- &watch_test_service_funcs,
- NULL);
+ big_dbus_watch_name(DBUS_BUS_SESSION, "com.litl.TestService", 0,
+ &watch_test_service_funcs, NULL);
- big_dbus_watch_name(DBUS_BUS_SESSION,
- "com.litl.TestIO",
- 0,
- &watch_test_io_funcs,
- NULL);
+ big_dbus_watch_name(DBUS_BUS_SESSION, "com.litl.TestIO", 0,
+ &watch_test_io_funcs, NULL);
client_loop = g_main_loop_new(NULL, FALSE);
@@ -2576,8 +2471,7 @@ bigtest_test_func_util_dbus_client(void)
/* child was killed already, or should have been */
- big_debug(BIG_DEBUG_IN_TESTS,
- "waitpid() for first child");
+ big_debug(BIG_DEBUG_IN_TESTS, "waitpid() for first child");
result = waitpid(test_service_pid, &status, 0);
if (result < 0) {
@@ -2585,15 +2479,16 @@ bigtest_test_func_util_dbus_client(void)
}
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
- g_error("Forked dbus service child exited with error code %d", WEXITSTATUS(status));
+ g_error("Forked dbus service child exited with error code %d",
+ WEXITSTATUS(status));
}
if (WIFSIGNALED(status) && WTERMSIG(status) != SIGTERM) {
- g_error("Forked dbus service child exited on wrong signal number %d", WTERMSIG(status));
+ g_error("Forked dbus service child exited on wrong signal number %d",
+ WTERMSIG(status));
}
- big_debug(BIG_DEBUG_IN_TESTS,
- "waitpid() for second child");
+ big_debug(BIG_DEBUG_IN_TESTS, "waitpid() for second child");
result = waitpid(test_io_pid, &status, 0);
if (result < 0) {
@@ -2601,11 +2496,13 @@ bigtest_test_func_util_dbus_client(void)
}
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
- g_error("Forked dbus service child exited with error code %d", WEXITSTATUS(status));
+ g_error("Forked dbus service child exited with error code %d",
+ WEXITSTATUS(status));
}
if (WIFSIGNALED(status) && WTERMSIG(status) != SIGTERM) {
- g_error("Forked dbus service child exited on wrong signal number %d", WTERMSIG(status));
+ g_error("Forked dbus service child exited on wrong signal number %d",
+ WTERMSIG(status));
}
big_debug(BIG_DEBUG_IN_TESTS, "dbus client test completed");
@@ -2630,36 +2527,33 @@ bigtest_test_func_util_dbus_client(void)
*/
static gboolean currently_have_test_service = FALSE;
-static GObject *test_service_object = NULL;
+static GObject* test_service_object = NULL;
static void
-test_service_get_some_stuff_sync(DBusConnection *connection,
- DBusMessage *message,
- DBusMessageIter *in_iter,
- DBusMessageIter *out_iter,
- void *data,
- DBusError *error)
+test_service_get_some_stuff_sync(DBusConnection* connection,
+ DBusMessage* message,
+ DBusMessageIter* in_iter,
+ DBusMessageIter* out_iter,
+ void* data,
+ DBusError* error)
{
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestService got getSomeStuffSync");
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestService got getSomeStuffSync");
g_assert(G_IS_OBJECT(data));
- big_dbus_append_json_entry_BOOLEAN(out_iter,
- "haveTestService",
+ big_dbus_append_json_entry_BOOLEAN(out_iter, "haveTestService",
currently_have_test_service);
}
static void
-test_service_always_error_sync(DBusConnection *connection,
- DBusMessage *message,
- DBusMessageIter *in_iter,
- DBusMessageIter *out_iter,
- void *data,
- DBusError *error)
+test_service_always_error_sync(DBusConnection* connection,
+ DBusMessage* message,
+ DBusMessageIter* in_iter,
+ DBusMessageIter* out_iter,
+ void* data,
+ DBusError* error)
{
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestService got alwaysErrorSync");
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestService got alwaysErrorSync");
g_assert(G_IS_OBJECT(data));
@@ -2667,72 +2561,57 @@ test_service_always_error_sync(DBusConnection *connection,
"Did not find some kind of file! Help!");
}
-static BigDBusJsonMethod test_service_methods[] = {
- { "getSomeStuffSync", test_service_get_some_stuff_sync, NULL },
- { "alwaysErrorSync", test_service_always_error_sync, NULL }
-};
+static BigDBusJsonMethod test_service_methods[]
+ = { { "getSomeStuffSync", test_service_get_some_stuff_sync, NULL },
+ { "alwaysErrorSync", test_service_always_error_sync, NULL } };
static void
-on_test_service_acquired(DBusConnection *connection,
- const char *name,
- void *data)
+on_test_service_acquired(DBusConnection* connection,
+ const char* name,
+ void* data)
{
g_assert(!currently_have_test_service);
currently_have_test_service = TRUE;
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestService acquired by child");
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestService acquired by child");
- big_dbus_register_json(connection,
- "com.litl.TestIface",
+ big_dbus_register_json(connection, "com.litl.TestIface",
test_service_methods,
G_N_ELEMENTS(test_service_methods));
test_service_object = g_object_new(G_TYPE_OBJECT, NULL);
- big_dbus_register_g_object(connection,
- "/com/litl/test/object42",
- test_service_object,
- "com.litl.TestIface");
+ big_dbus_register_g_object(connection, "/com/litl/test/object42",
+ test_service_object, "com.litl.TestIface");
}
static void
-on_test_service_lost(DBusConnection *connection,
- const char *name,
- void *data)
+on_test_service_lost(DBusConnection* connection, const char* name, void* data)
{
g_assert(currently_have_test_service);
currently_have_test_service = FALSE;
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestService lost by child");
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestService lost by child");
- big_dbus_unregister_g_object(connection,
- "/com/litl/test/object42");
+ big_dbus_unregister_g_object(connection, "/com/litl/test/object42");
- big_dbus_unregister_json(connection,
- "com.litl.TestIface");
+ big_dbus_unregister_json(connection, "com.litl.TestIface");
}
-static BigDBusNameOwnerFuncs test_service_funcs = {
- "com.litl.TestService",
- BIG_DBUS_NAME_SINGLE_INSTANCE,
- on_test_service_acquired,
- on_test_service_lost
-};
+static BigDBusNameOwnerFuncs test_service_funcs
+ = { "com.litl.TestService", BIG_DBUS_NAME_SINGLE_INSTANCE,
+ on_test_service_acquired, on_test_service_lost };
static void
do_test_service_child(void)
{
- GMainLoop *loop;
+ GMainLoop* loop;
g_type_init();
loop = g_main_loop_new(NULL, FALSE);
- big_dbus_acquire_name(DBUS_BUS_SESSION,
- &test_service_funcs,
- NULL);
+ big_dbus_acquire_name(DBUS_BUS_SESSION, &test_service_funcs, NULL);
g_main_loop_run(loop);
@@ -2745,25 +2624,24 @@ do_test_service_child(void)
*/
static gboolean currently_have_test_io = FALSE;
-static GObject *test_io_object = NULL;
+static GObject* test_io_object = NULL;
-static BigDBusInputStream *io_input_stream = NULL;
-static BigDBusOutputStream *io_output_stream = NULL;
+static BigDBusInputStream* io_input_stream = NULL;
+static BigDBusOutputStream* io_output_stream = NULL;
-static GString *input_buffer = NULL;
+static GString* input_buffer = NULL;
static void
-test_io_confirm_streams_data(DBusConnection *connection,
- DBusMessage *message,
- DBusMessageIter *in_iter,
- DBusMessageIter *out_iter,
- void *data,
- DBusError *error)
+test_io_confirm_streams_data(DBusConnection* connection,
+ DBusMessage* message,
+ DBusMessageIter* in_iter,
+ DBusMessageIter* out_iter,
+ void* data,
+ DBusError* error)
{
- const char *received;
+ const char* received;
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestIO got confirmStreamsData");
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestIO got confirmStreamsData");
g_assert(G_IS_OBJECT(data));
@@ -2775,8 +2653,7 @@ test_io_confirm_streams_data(DBusConnection *connection,
if (strcmp(received, stream_data_from_io_service) != 0) {
g_error("We sent the main process '%s' but it says it got '%s'",
- stream_data_from_io_service,
- received);
+ stream_data_from_io_service, received);
return;
}
@@ -2790,46 +2667,41 @@ test_io_confirm_streams_data(DBusConnection *connection,
g_main_context_iteration(NULL, TRUE);
}
- big_dbus_append_json_entry_STRING(out_iter,
- "received",
- input_buffer->str);
+ big_dbus_append_json_entry_STRING(out_iter, "received", input_buffer->str);
g_string_free(input_buffer, TRUE);
input_buffer = NULL;
}
static void
-on_input_ready(BigDBusInputStream *dbus_stream,
- void *data)
+on_input_ready(BigDBusInputStream* dbus_stream, void* data)
{
- GInputStream *stream;
+ GInputStream* stream;
char buf[3];
gssize result;
- GError *error;
+ GError* error;
stream = G_INPUT_STREAM(dbus_stream);
g_assert(dbus_stream == io_input_stream);
/* test get_received() */
- g_assert(big_dbus_input_stream_get_received(dbus_stream) <= strlen(stream_data_to_io_service));
+ g_assert(big_dbus_input_stream_get_received(dbus_stream)
+ <= strlen(stream_data_to_io_service));
/* Should not block, since we got the ready-to-read signal */
error = NULL;
- result = g_input_stream_read(G_INPUT_STREAM(io_input_stream),
- buf,
- sizeof(buf),
- NULL,
- &error);
+ result = g_input_stream_read(G_INPUT_STREAM(io_input_stream), buf,
+ sizeof(buf), NULL, &error);
if (result < 0) {
- g_error("Error reading bytes from input stream: %s",
- error->message);
+ g_error("Error reading bytes from input stream: %s", error->message);
g_error_free(error);
}
if (result == 0) {
/* EOF */
- if (!g_input_stream_close(G_INPUT_STREAM(io_input_stream), NULL, &error)) {
+ if (!g_input_stream_close(G_INPUT_STREAM(io_input_stream), NULL,
+ &error)) {
g_error("Error closing input stream in child: %s", error->message);
g_error_free(error);
}
@@ -2847,21 +2719,20 @@ on_input_ready(BigDBusInputStream *dbus_stream,
}
static void
-test_io_setup_streams(DBusConnection *connection,
- DBusMessage *message,
- DBusMessageIter *in_iter,
- DBusMessageIter *out_iter,
- void *data,
- DBusError *error)
-{
- const char *stream_path;
+test_io_setup_streams(DBusConnection* connection,
+ DBusMessage* message,
+ DBusMessageIter* in_iter,
+ DBusMessageIter* out_iter,
+ void* data,
+ DBusError* error)
+{
+ const char* stream_path;
gsize total;
gsize remaining;
gssize result;
- GError *gerror;
+ GError* gerror;
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestIO got setupStreams");
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestIO got setupStreams");
g_assert(G_IS_OBJECT(data));
@@ -2873,30 +2744,22 @@ test_io_setup_streams(DBusConnection *connection,
}
/* Create output stream to write to caller's path */
- io_output_stream =
- big_dbus_output_stream_new(connection,
- dbus_message_get_sender(message),
+ io_output_stream
+ = big_dbus_output_stream_new(connection, dbus_message_get_sender(message),
stream_path);
/* Create input stream and return its path to caller */
- io_input_stream =
- g_object_new(BIG_TYPE_DBUS_INPUT_STREAM,
- NULL);
- big_dbus_input_stream_attach(io_input_stream,
- connection);
+ io_input_stream = g_object_new(BIG_TYPE_DBUS_INPUT_STREAM, NULL);
+ big_dbus_input_stream_attach(io_input_stream, connection);
stream_path = big_dbus_input_stream_get_path(io_input_stream);
- big_dbus_append_json_entry_STRING(out_iter,
- "stream",
- stream_path);
+ big_dbus_append_json_entry_STRING(out_iter, "stream", stream_path);
/* Set up callbacks to read input stream in an async way */
input_buffer = g_string_new(NULL);
- g_signal_connect(io_input_stream,
- "ready-to-read",
- G_CALLBACK(on_input_ready),
- NULL);
+ g_signal_connect(io_input_stream, "ready-to-read",
+ G_CALLBACK(on_input_ready), NULL);
/* Write to output stream */
gerror = NULL;
@@ -2907,10 +2770,9 @@ test_io_setup_streams(DBusConnection *connection,
* code of course
*/
result = g_output_stream_write(G_OUTPUT_STREAM(io_output_stream),
- stream_data_from_io_service + (total - remaining),
- 1,
- NULL,
- &gerror);
+ stream_data_from_io_service
+ + (total - remaining),
+ 1, NULL, &gerror);
if (result < 0) {
g_assert(gerror != NULL);
g_error("Error writing to output stream: %s", gerror->message);
@@ -2927,13 +2789,15 @@ test_io_setup_streams(DBusConnection *connection,
/* flush should do nothing here, and is not needed, but
* just calling it to test it
*/
- if (!g_output_stream_flush(G_OUTPUT_STREAM(io_output_stream), NULL, &gerror)) {
+ if (!g_output_stream_flush(G_OUTPUT_STREAM(io_output_stream), NULL,
+ &gerror)) {
g_assert(gerror != NULL);
g_error("Error flushing output stream: %s", gerror->message);
g_error_free(gerror);
}
- if (!g_output_stream_close(G_OUTPUT_STREAM(io_output_stream), NULL, &gerror)) {
+ if (!g_output_stream_close(G_OUTPUT_STREAM(io_output_stream), NULL,
+ &gerror)) {
g_assert(gerror != NULL);
g_error("Error closing output stream: %s", gerror->message);
g_error_free(gerror);
@@ -2941,78 +2805,59 @@ test_io_setup_streams(DBusConnection *connection,
g_object_unref(io_output_stream);
io_output_stream = NULL;
-
/* Now return, and wait for our input stream data to come in from
* the main process
*/
}
-static BigDBusJsonMethod test_io_methods[] = {
- { "setupStreams", test_io_setup_streams, NULL },
- { "confirmStreamsData", test_io_confirm_streams_data, NULL }
-};
+static BigDBusJsonMethod test_io_methods[]
+ = { { "setupStreams", test_io_setup_streams, NULL },
+ { "confirmStreamsData", test_io_confirm_streams_data, NULL } };
static void
-on_test_io_acquired(DBusConnection *connection,
- const char *name,
- void *data)
+on_test_io_acquired(DBusConnection* connection, const char* name, void* data)
{
g_assert(!currently_have_test_io);
currently_have_test_io = TRUE;
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestIO acquired by child");
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestIO acquired by child");
- big_dbus_register_json(connection,
- "com.litl.TestIO",
- test_io_methods,
+ big_dbus_register_json(connection, "com.litl.TestIO", test_io_methods,
G_N_ELEMENTS(test_io_methods));
test_io_object = g_object_new(G_TYPE_OBJECT, NULL);
- big_dbus_register_g_object(connection,
- "/com/litl/test/object47",
- test_io_object,
- "com.litl.TestIO");
+ big_dbus_register_g_object(connection, "/com/litl/test/object47",
+ test_io_object, "com.litl.TestIO");
}
static void
-on_test_io_lost(DBusConnection *connection,
- const char *name,
- void *data)
+on_test_io_lost(DBusConnection* connection, const char* name, void* data)
{
g_assert(currently_have_test_io);
currently_have_test_io = FALSE;
- big_debug(BIG_DEBUG_IN_TESTS,
- "com.litl.TestIO lost by child");
+ big_debug(BIG_DEBUG_IN_TESTS, "com.litl.TestIO lost by child");
- big_dbus_unregister_g_object(connection,
- "/com/litl/test/object47");
+ big_dbus_unregister_g_object(connection, "/com/litl/test/object47");
- big_dbus_unregister_json(connection,
- "com.litl.TestIO");
+ big_dbus_unregister_json(connection, "com.litl.TestIO");
}
-static BigDBusNameOwnerFuncs test_io_funcs = {
- "com.litl.TestIO",
- BIG_DBUS_NAME_SINGLE_INSTANCE,
- on_test_io_acquired,
- on_test_io_lost
-};
+static BigDBusNameOwnerFuncs test_io_funcs
+ = { "com.litl.TestIO", BIG_DBUS_NAME_SINGLE_INSTANCE, on_test_io_acquired,
+ on_test_io_lost };
static void
do_test_io_child(void)
{
- GMainLoop *loop;
+ GMainLoop* loop;
g_type_init();
loop = g_main_loop_new(NULL, FALSE);
- big_dbus_acquire_name(DBUS_BUS_SESSION,
- &test_io_funcs,
- NULL);
+ big_dbus_acquire_name(DBUS_BUS_SESSION, &test_io_funcs, NULL);
g_main_loop_run(loop);
diff --git a/modules/dbus/util/dbus.h b/modules/dbus/util/dbus.h
index 5b31c39..10f4b63 100644
--- a/modules/dbus/util/dbus.h
+++ b/modules/dbus/util/dbus.h
@@ -11,40 +11,41 @@ G_BEGIN_DECLS
/* Convenience macro */
-#define BIG_DBUS_NAME_FROM_TYPE(type) ((type) == DBUS_BUS_SESSION ? "session" : "system")
+#define BIG_DBUS_NAME_FROM_TYPE(type) \
+ ((type) == DBUS_BUS_SESSION ? "session" : "system")
/* Error names */
-#define BIG_DBUS_ERROR_STREAM_RECEIVER_CLOSED "com.litl.Error.Stream.ReceiverClosed"
+#define BIG_DBUS_ERROR_STREAM_RECEIVER_CLOSED \
+ "com.litl.Error.Stream.ReceiverClosed"
/*
* Monitor whether we are connected / not-connected to the bus
*/
-typedef void (* BigDBusConnectionOpenedFunc) (DBusConnection *connection,
- void *data);
-typedef void (* BigDBusConnectionClosedFunc) (DBusConnection *connection,
- void *data);
+typedef void (*BigDBusConnectionOpenedFunc)(DBusConnection* connection,
+ void* data);
+typedef void (*BigDBusConnectionClosedFunc)(DBusConnection* connection,
+ void* data);
-typedef struct {
+typedef struct
+{
DBusBusType which_bus;
BigDBusConnectionOpenedFunc opened;
BigDBusConnectionClosedFunc closed;
} BigDBusConnectFuncs;
-void big_dbus_add_connect_funcs (const BigDBusConnectFuncs *funcs,
- void *data);
-void big_dbus_remove_connect_funcs (const BigDBusConnectFuncs *funcs,
- void *data);
-void big_dbus_add_connect_funcs_sync_notify (const BigDBusConnectFuncs *funcs,
- void *data);
+void big_dbus_add_connect_funcs(const BigDBusConnectFuncs* funcs, void* data);
+void big_dbus_remove_connect_funcs(const BigDBusConnectFuncs* funcs,
+ void* data);
+void big_dbus_add_connect_funcs_sync_notify(const BigDBusConnectFuncs* funcs,
+ void* data);
+void big_dbus_add_bus_weakref(DBusBusType bus_type,
+ DBusConnection** connection_p);
+void big_dbus_remove_bus_weakref(DBusBusType bus_type,
+ DBusConnection** connection_p);
-void big_dbus_add_bus_weakref (DBusBusType bus_type,
- DBusConnection **connection_p);
-void big_dbus_remove_bus_weakref (DBusBusType bus_type,
- DBusConnection **connection_p);
-
-void big_dbus_try_connecting_now (DBusBusType which_bus);
+void big_dbus_try_connecting_now(DBusBusType which_bus);
/*
* Own a bus name
@@ -56,85 +57,82 @@ typedef enum {
BIG_DBUS_NAME_MANY_INSTANCES
} BigDBusNameType;
-typedef void (* BigDBusNameAcquiredFunc) (DBusConnection *connection,
- const char *name,
- void *data);
-typedef void (* BigDBusNameLostFunc) (DBusConnection *connection,
- const char *name,
- void *data);
+typedef void (*BigDBusNameAcquiredFunc)(DBusConnection* connection,
+ const char* name,
+ void* data);
+typedef void (*BigDBusNameLostFunc)(DBusConnection* connection,
+ const char* name,
+ void* data);
-typedef struct {
- const char *name;
+typedef struct
+{
+ const char* name;
BigDBusNameType type;
BigDBusNameAcquiredFunc acquired;
BigDBusNameLostFunc lost;
} BigDBusNameOwnerFuncs;
-guint big_dbus_acquire_name (DBusBusType bus_type,
- const BigDBusNameOwnerFuncs *funcs,
- void *data);
-void big_dbus_release_name (DBusBusType bus_type,
- const BigDBusNameOwnerFuncs *funcs,
- void *data);
-void big_dbus_release_name_by_id (DBusBusType bus_type,
- guint id);
+guint big_dbus_acquire_name(DBusBusType bus_type,
+ const BigDBusNameOwnerFuncs* funcs,
+ void* data);
+void big_dbus_release_name(DBusBusType bus_type,
+ const BigDBusNameOwnerFuncs* funcs,
+ void* data);
+void big_dbus_release_name_by_id(DBusBusType bus_type, guint id);
/*
* Keep track of someone else's bus name
*
*/
-typedef enum {
- BIG_DBUS_NAME_START_IF_NOT_FOUND = 0x1
-} BigDBusWatchNameFlags;
-
-typedef void (* BigDBusNameAppearedFunc) (DBusConnection *connection,
- const char *name,
- const char *new_owner_unique_name,
- void *data);
-typedef void (* BigDBusNameVanishedFunc) (DBusConnection *connection,
- const char *name,
- const char *old_owner_unique_name,
- void *data);
-
-typedef struct {
+typedef enum { BIG_DBUS_NAME_START_IF_NOT_FOUND = 0x1 } BigDBusWatchNameFlags;
+
+typedef void (*BigDBusNameAppearedFunc)(DBusConnection* connection,
+ const char* name,
+ const char* new_owner_unique_name,
+ void* data);
+typedef void (*BigDBusNameVanishedFunc)(DBusConnection* connection,
+ const char* name,
+ const char* old_owner_unique_name,
+ void* data);
+
+typedef struct
+{
BigDBusNameAppearedFunc appeared;
BigDBusNameVanishedFunc vanished;
} BigDBusWatchNameFuncs;
-void big_dbus_watch_name (DBusBusType bus_type,
- const char *name,
- BigDBusWatchNameFlags flags,
- const BigDBusWatchNameFuncs *funcs,
- void *data);
-void big_dbus_unwatch_name (DBusBusType bus_type,
- const char *name,
- const BigDBusWatchNameFuncs *funcs,
- void *data);
-const char* big_dbus_get_watched_name_owner (DBusBusType bus_type,
- const char *name);
-
-
-typedef void (* BigDBusSignalHandler) (DBusConnection *connection,
- DBusMessage *message,
- void *data);
-int big_dbus_watch_signal (DBusBusType bus_type,
- const char *sender,
- const char *path,
- const char *iface,
- const char *name,
- BigDBusSignalHandler handler,
- void *data,
- GDestroyNotify data_dnotify);
-void big_dbus_unwatch_signal (DBusBusType bus_type,
- const char *sender,
- const char *path,
- const char *iface,
- const char *name,
- BigDBusSignalHandler handler,
- void *data);
-void big_dbus_unwatch_signal_by_id (DBusBusType bus_type,
- int id);
+void big_dbus_watch_name(DBusBusType bus_type,
+ const char* name,
+ BigDBusWatchNameFlags flags,
+ const BigDBusWatchNameFuncs* funcs,
+ void* data);
+void big_dbus_unwatch_name(DBusBusType bus_type,
+ const char* name,
+ const BigDBusWatchNameFuncs* funcs,
+ void* data);
+const char* big_dbus_get_watched_name_owner(DBusBusType bus_type,
+ const char* name);
+
+typedef void (*BigDBusSignalHandler)(DBusConnection* connection,
+ DBusMessage* message,
+ void* data);
+int big_dbus_watch_signal(DBusBusType bus_type,
+ const char* sender,
+ const char* path,
+ const char* iface,
+ const char* name,
+ BigDBusSignalHandler handler,
+ void* data,
+ GDestroyNotify data_dnotify);
+void big_dbus_unwatch_signal(DBusBusType bus_type,
+ const char* sender,
+ const char* path,
+ const char* iface,
+ const char* name,
+ BigDBusSignalHandler handler,
+ void* data);
+void big_dbus_unwatch_signal_by_id(DBusBusType bus_type, int id);
/* A "json method" is a D-Bus method with signature
* DICT jsonMethodName(DICT)
@@ -149,68 +147,66 @@ void big_dbus_unwatch_signal_by_id (DBusBusType bus_type,
* that happens to consist of multiple processes
* and have bits written in JS.
*/
-typedef void (* BigDBusJsonSyncMethodFunc) (DBusConnection *connection,
- DBusMessage *message,
- DBusMessageIter *in_iter,
- DBusMessageIter *out_iter,
- void *data,
- DBusError *error);
-
-typedef void (* BigDBusJsonAsyncMethodFunc) (DBusConnection *connection,
- DBusMessage *message,
- DBusMessageIter *in_iter,
- void *data);
-
-typedef struct {
- const char *name;
+typedef void (*BigDBusJsonSyncMethodFunc)(DBusConnection* connection,
+ DBusMessage* message,
+ DBusMessageIter* in_iter,
+ DBusMessageIter* out_iter,
+ void* data,
+ DBusError* error);
+
+typedef void (*BigDBusJsonAsyncMethodFunc)(DBusConnection* connection,
+ DBusMessage* message,
+ DBusMessageIter* in_iter,
+ void* data);
+
+typedef struct
+{
+ const char* name;
/* one of these two but not both should be non-NULL */
BigDBusJsonSyncMethodFunc sync_func;
BigDBusJsonAsyncMethodFunc async_func;
} BigDBusJsonMethod;
-void big_dbus_register_json (DBusConnection *connection,
- const char *iface_name,
- const BigDBusJsonMethod *methods,
- int n_methods);
-void big_dbus_unregister_json (DBusConnection *connection,
- const char *iface_name);
-void big_dbus_register_g_object (DBusConnection *connection,
- const char *path,
- GObject *gobj,
- const char *iface_name);
-void big_dbus_unregister_g_object (DBusConnection *connection,
- const char *path);
-
-void big_dbus_append_json_entry (DBusMessageIter *dict_iter,
- const char *key,
- int dbus_type,
- void *basic_value_p);
-void big_dbus_append_json_entry_STRING (DBusMessageIter *dict_iter,
- const char *key,
- const char *value);
-void big_dbus_append_json_entry_INT32 (DBusMessageIter *dict_iter,
- const char *key,
- dbus_int32_t value);
-void big_dbus_append_json_entry_DOUBLE (DBusMessageIter *dict_iter,
- const char *key,
- double value);
-void big_dbus_append_json_entry_BOOLEAN (DBusMessageIter *dict_iter,
- const char *key,
- dbus_bool_t value);
-void big_dbus_append_json_entry_EMPTY_ARRAY (DBusMessageIter *dict_iter,
- const char *key);
-void big_dbus_append_json_entry_STRING_ARRAY (DBusMessageIter *dict_iter,
- const char *key,
- const char **value);
-
-gboolean big_dbus_message_iter_get_gsize (DBusMessageIter *iter,
- gsize *value_p);
-gboolean big_dbus_message_iter_get_gssize (DBusMessageIter *iter,
- gssize *value_p);
-
-void big_dbus_start_service(DBusConnection *connection,
- const char *name);
+void big_dbus_register_json(DBusConnection* connection,
+ const char* iface_name,
+ const BigDBusJsonMethod* methods,
+ int n_methods);
+void big_dbus_unregister_json(DBusConnection* connection,
+ const char* iface_name);
+void big_dbus_register_g_object(DBusConnection* connection,
+ const char* path,
+ GObject* gobj,
+ const char* iface_name);
+void big_dbus_unregister_g_object(DBusConnection* connection, const char* path);
+
+void big_dbus_append_json_entry(DBusMessageIter* dict_iter,
+ const char* key,
+ int dbus_type,
+ void* basic_value_p);
+void big_dbus_append_json_entry_STRING(DBusMessageIter* dict_iter,
+ const char* key,
+ const char* value);
+void big_dbus_append_json_entry_INT32(DBusMessageIter* dict_iter,
+ const char* key,
+ dbus_int32_t value);
+void big_dbus_append_json_entry_DOUBLE(DBusMessageIter* dict_iter,
+ const char* key,
+ double value);
+void big_dbus_append_json_entry_BOOLEAN(DBusMessageIter* dict_iter,
+ const char* key,
+ dbus_bool_t value);
+void big_dbus_append_json_entry_EMPTY_ARRAY(DBusMessageIter* dict_iter,
+ const char* key);
+void big_dbus_append_json_entry_STRING_ARRAY(DBusMessageIter* dict_iter,
+ const char* key,
+ const char** value);
+
+gboolean big_dbus_message_iter_get_gsize(DBusMessageIter* iter, gsize* value_p);
+gboolean big_dbus_message_iter_get_gssize(DBusMessageIter* iter,
+ gssize* value_p);
+
+void big_dbus_start_service(DBusConnection* connection, const char* name);
G_END_DECLS
-#endif /* __BIG_UTIL_DBUS_H__ */
+#endif /* __BIG_UTIL_DBUS_H__ */
diff --git a/modules/dbus/util/log.h b/modules/dbus/util/log.h
index 39299dd..1e1dcb8 100644
--- a/modules/dbus/util/log.h
+++ b/modules/dbus/util/log.h
@@ -1,2 +1,2 @@
#define BIG_DEBUG_UTIL_DBUS 1
-#define big_debug(type,...)
+#define big_debug(type, ...)
diff --git a/modules/example/seed-example.c b/modules/example/seed-example.c
index 111bc04..d06ca80 100644
--- a/modules/example/seed-example.c
+++ b/modules/example/seed-example.c
@@ -21,8 +21,8 @@
#include <seed-module.h>
SeedObject
-seed_module_init(SeedEngine * eng)
+seed_module_init(SeedEngine* eng)
{
- g_print("Hello Seed Module World\n");
- return seed_make_object (eng->context, NULL, NULL);
+ g_print("Hello Seed Module World\n");
+ return seed_make_object(eng->context, NULL, NULL);
}
diff --git a/modules/ffi/seed-ffi.c b/modules/ffi/seed-ffi.c
index c7c2f9d..6f966e2 100644
--- a/modules/ffi/seed-ffi.c
+++ b/modules/ffi/seed-ffi.c
@@ -22,492 +22,489 @@
#include <ffi.h>
-SeedEngine *eng;
+SeedEngine* eng;
SeedObject namespace_ref;
SeedClass ffi_library_class;
SeedClass ffi_function_class;
-typedef struct _seed_ffi_function_priv {
- gchar *name;
- gpointer symbol;
-
- GType *args;
- gint n_args;
-
- GType ret_val;
-
- SeedObject signature_obj;
- SeedObject module_obj;
+typedef struct _seed_ffi_function_priv
+{
+ gchar* name;
+ gpointer symbol;
+
+ GType* args;
+ gint n_args;
+
+ GType ret_val;
+
+ SeedObject signature_obj;
+ SeedObject module_obj;
} seed_ffi_function_priv;
-typedef struct _seed_ffi_library_priv {
- GModule *mod;
- GHashTable *symbols;
+typedef struct _seed_ffi_library_priv
+{
+ GModule* mod;
+ GHashTable* symbols;
} seed_ffi_library_priv;
-static ffi_type *
-gtype_to_ffi_type (SeedContext ctx,
- SeedValue value,
- GType otype,
- GArgument *garg,
- gpointer *arg,
- SeedException *exception)
+static ffi_type*
+gtype_to_ffi_type(SeedContext ctx,
+ SeedValue value,
+ GType otype,
+ GArgument* garg,
+ gpointer* arg,
+ SeedException* exception)
{
- ffi_type *return_type;
- GType type = g_type_fundamental (otype);
- g_assert (type != G_TYPE_INVALID);
-
- switch (type)
- {
- case G_TYPE_BOOLEAN:
- case G_TYPE_CHAR:
- case G_TYPE_INT:
- return_type = &ffi_type_sint;
- garg->v_int = seed_value_to_int (ctx, value, exception);
- *arg = (gpointer)garg;
- break;
- case G_TYPE_UCHAR:
- case G_TYPE_UINT:
- return_type = &ffi_type_uint;
- garg->v_uint = seed_value_to_uint (ctx, value, exception);
- *arg = (gpointer)garg;
- break;
- case G_TYPE_STRING:
- return_type = &ffi_type_pointer;
- garg->v_pointer = seed_value_to_string (ctx, value, exception);
- *arg = (gpointer)garg;
- break;
- case G_TYPE_OBJECT:
- // case G_TYPE_BOXED:
- case G_TYPE_POINTER:
- return_type = &ffi_type_pointer;
- garg->v_pointer = seed_pointer_get_pointer (ctx, value);
- *arg = (gpointer)garg;
- break;
- case G_TYPE_FLOAT:
- return_type = &ffi_type_float;
- garg->v_float = seed_value_to_float (ctx, value, exception);
- *arg = (gpointer)garg;
- break;
- case G_TYPE_DOUBLE:
- return_type = &ffi_type_double;
- garg->v_double = seed_value_to_double (ctx, value, exception);
- *arg = (gpointer)garg;
- break;
- case G_TYPE_LONG:
- return_type = &ffi_type_slong;
- garg->v_uint = seed_value_to_uint (ctx, value, exception);
- *arg = (gpointer)garg;
- break;
- case G_TYPE_ULONG:
- return_type = &ffi_type_ulong;
- garg->v_ulong = seed_value_to_ulong (ctx, value, exception);
- *arg = (gpointer)garg;
- break;
- case G_TYPE_INT64:
- return_type = &ffi_type_sint64;
- garg->v_int64 = seed_value_to_int64 (ctx, value, exception);
- *arg = (gpointer)garg;
- break;
- case G_TYPE_UINT64:
- return_type = &ffi_type_uint64;
- garg->v_uint64 = seed_value_to_uint64 (ctx, value, exception);
- *arg = (gpointer)garg;
- break;
- default:
- g_warning ("Unsupported fundamental in type: %s", g_type_name (type));
- return_type = &ffi_type_pointer;
- garg->v_pointer = NULL;
- *arg = (garg->v_pointer);
- break;
+ ffi_type* return_type;
+ GType type = g_type_fundamental(otype);
+ g_assert(type != G_TYPE_INVALID);
+
+ switch (type) {
+ case G_TYPE_BOOLEAN:
+ case G_TYPE_CHAR:
+ case G_TYPE_INT:
+ return_type = &ffi_type_sint;
+ garg->v_int = seed_value_to_int(ctx, value, exception);
+ *arg = (gpointer) garg;
+ break;
+ case G_TYPE_UCHAR:
+ case G_TYPE_UINT:
+ return_type = &ffi_type_uint;
+ garg->v_uint = seed_value_to_uint(ctx, value, exception);
+ *arg = (gpointer) garg;
+ break;
+ case G_TYPE_STRING:
+ return_type = &ffi_type_pointer;
+ garg->v_pointer = seed_value_to_string(ctx, value, exception);
+ *arg = (gpointer) garg;
+ break;
+ case G_TYPE_OBJECT:
+ // case G_TYPE_BOXED:
+ case G_TYPE_POINTER:
+ return_type = &ffi_type_pointer;
+ garg->v_pointer = seed_pointer_get_pointer(ctx, value);
+ *arg = (gpointer) garg;
+ break;
+ case G_TYPE_FLOAT:
+ return_type = &ffi_type_float;
+ garg->v_float = seed_value_to_float(ctx, value, exception);
+ *arg = (gpointer) garg;
+ break;
+ case G_TYPE_DOUBLE:
+ return_type = &ffi_type_double;
+ garg->v_double = seed_value_to_double(ctx, value, exception);
+ *arg = (gpointer) garg;
+ break;
+ case G_TYPE_LONG:
+ return_type = &ffi_type_slong;
+ garg->v_uint = seed_value_to_uint(ctx, value, exception);
+ *arg = (gpointer) garg;
+ break;
+ case G_TYPE_ULONG:
+ return_type = &ffi_type_ulong;
+ garg->v_ulong = seed_value_to_ulong(ctx, value, exception);
+ *arg = (gpointer) garg;
+ break;
+ case G_TYPE_INT64:
+ return_type = &ffi_type_sint64;
+ garg->v_int64 = seed_value_to_int64(ctx, value, exception);
+ *arg = (gpointer) garg;
+ break;
+ case G_TYPE_UINT64:
+ return_type = &ffi_type_uint64;
+ garg->v_uint64 = seed_value_to_uint64(ctx, value, exception);
+ *arg = (gpointer) garg;
+ break;
+ default:
+ g_warning("Unsupported fundamental in type: %s", g_type_name(type));
+ return_type = &ffi_type_pointer;
+ garg->v_pointer = NULL;
+ *arg = (garg->v_pointer);
+ break;
}
- return return_type;
+ return return_type;
}
-static ffi_type *
-return_type_to_ffi_type (GType otype)
+static ffi_type*
+return_type_to_ffi_type(GType otype)
{
- GType type = g_type_fundamental (otype);
- g_assert (type != G_TYPE_INVALID);
-
- switch (type)
- {
- case G_TYPE_BOOLEAN:
- case G_TYPE_CHAR:
- case G_TYPE_INT:
- return &ffi_type_sint;
- break;
- case G_TYPE_UCHAR:
- case G_TYPE_UINT:
- return &ffi_type_uint;
- break;
- case G_TYPE_STRING:
- return &ffi_type_pointer;
- break;
- case G_TYPE_OBJECT:
- // case G_TYPE_BOXED:
- case G_TYPE_POINTER:
- return &ffi_type_pointer;
- break;
- case G_TYPE_FLOAT:
- return &ffi_type_float;
- break;
- case G_TYPE_DOUBLE:
- return &ffi_type_double;
- break;
- case G_TYPE_LONG:
- return &ffi_type_slong;
- break;
- case G_TYPE_ULONG:
- return &ffi_type_ulong;
- break;
- case G_TYPE_INT64:
- return &ffi_type_sint64;
- break;
- case G_TYPE_UINT64:
- return &ffi_type_uint64;
- break;
- default:
- g_warning ("Unsupported fundamental out type: %s", g_type_name (type));
- return &ffi_type_pointer;
- break;
+ GType type = g_type_fundamental(otype);
+ g_assert(type != G_TYPE_INVALID);
+
+ switch (type) {
+ case G_TYPE_BOOLEAN:
+ case G_TYPE_CHAR:
+ case G_TYPE_INT:
+ return &ffi_type_sint;
+ break;
+ case G_TYPE_UCHAR:
+ case G_TYPE_UINT:
+ return &ffi_type_uint;
+ break;
+ case G_TYPE_STRING:
+ return &ffi_type_pointer;
+ break;
+ case G_TYPE_OBJECT:
+ // case G_TYPE_BOXED:
+ case G_TYPE_POINTER:
+ return &ffi_type_pointer;
+ break;
+ case G_TYPE_FLOAT:
+ return &ffi_type_float;
+ break;
+ case G_TYPE_DOUBLE:
+ return &ffi_type_double;
+ break;
+ case G_TYPE_LONG:
+ return &ffi_type_slong;
+ break;
+ case G_TYPE_ULONG:
+ return &ffi_type_ulong;
+ break;
+ case G_TYPE_INT64:
+ return &ffi_type_sint64;
+ break;
+ case G_TYPE_UINT64:
+ return &ffi_type_uint64;
+ break;
+ default:
+ g_warning("Unsupported fundamental out type: %s",
+ g_type_name(type));
+ return &ffi_type_pointer;
+ break;
}
}
static SeedValue
-seed_ffi_get_signature (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_ffi_get_signature(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- seed_ffi_function_priv *priv = seed_object_get_private (this_object);
-
- if (priv->signature_obj)
- return priv->signature_obj;
- else
- return seed_make_null (ctx);
+ seed_ffi_function_priv* priv = seed_object_get_private(this_object);
+
+ if (priv->signature_obj)
+ return priv->signature_obj;
+ else
+ return seed_make_null(ctx);
}
static gboolean
-seed_ffi_build_signature (SeedContext ctx,
- seed_ffi_function_priv *priv,
- SeedObject sig,
- SeedException *exception)
+seed_ffi_build_signature(SeedContext ctx,
+ seed_ffi_function_priv* priv,
+ SeedObject sig,
+ SeedException* exception)
{
- SeedObject arguments;
- SeedValue ret_type_ref, length_ref;
- guint length, i;
-
- arguments = seed_object_get_property (ctx, sig, "arguments");
- ret_type_ref = seed_object_get_property (ctx, sig, "returns");
-
- if (!seed_value_is_object (ctx, arguments))
- {
- seed_make_exception (ctx, exception, "FFIError",
- "Signature arguments member must be an array describing argument types");
- return FALSE;
+ SeedObject arguments;
+ SeedValue ret_type_ref, length_ref;
+ guint length, i;
+
+ arguments = seed_object_get_property(ctx, sig, "arguments");
+ ret_type_ref = seed_object_get_property(ctx, sig, "returns");
+
+ if (!seed_value_is_object(ctx, arguments)) {
+ seed_make_exception(ctx, exception, "FFIError",
+ "Signature arguments member must be an "
+ "array describing argument types");
+ return FALSE;
}
- length_ref = seed_object_get_property (ctx, arguments, "length");
-
- length = seed_value_to_uint (ctx, length_ref, exception);
- priv->n_args = length;
- priv->args = g_slice_alloc (length * sizeof (GType));
-
- for (i = 0; i < length; i++)
- {
- SeedValue type = seed_object_get_property_at_index (ctx, arguments,
- i, exception);
- priv->args[i] = seed_value_to_int (ctx, type, exception);
+ length_ref = seed_object_get_property(ctx, arguments, "length");
+
+ length = seed_value_to_uint(ctx, length_ref, exception);
+ priv->n_args = length;
+ priv->args = g_slice_alloc(length * sizeof(GType));
+
+ for (i = 0; i < length; i++) {
+ SeedValue type
+ = seed_object_get_property_at_index(ctx, arguments, i, exception);
+ priv->args[i] = seed_value_to_int(ctx, type, exception);
}
- priv->ret_val = seed_value_to_int (ctx, ret_type_ref, exception);
-
- priv->signature_obj = sig;
- seed_value_protect (ctx, sig);
+ priv->ret_val = seed_value_to_int(ctx, ret_type_ref, exception);
- return TRUE;
+ priv->signature_obj = sig;
+ seed_value_protect(ctx, sig);
+
+ return TRUE;
}
static gboolean
-seed_ffi_set_signature (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_ffi_set_signature(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- seed_ffi_function_priv *priv = seed_object_get_private (this_object);
-
- if (priv->signature_obj)
- {
- seed_make_exception (ctx, exception, "FFIError",
- "Can not reset signature of function once set");
- return FALSE;
- }
- else if (!seed_value_is_object (ctx, value))
- {
- seed_make_exception (ctx, exception, "FFIError",
- "Signature must be an object");
- return FALSE;
- }
- else
- {
- if (!seed_ffi_build_signature (ctx, priv, (SeedObject) value, exception))
- return FALSE;
+ seed_ffi_function_priv* priv = seed_object_get_private(this_object);
+
+ if (priv->signature_obj) {
+ seed_make_exception(ctx, exception, "FFIError",
+ "Can not reset signature of function once set");
+ return FALSE;
+ } else if (!seed_value_is_object(ctx, value)) {
+ seed_make_exception(ctx, exception, "FFIError",
+ "Signature must be an object");
+ return FALSE;
+ } else {
+ if (!seed_ffi_build_signature(ctx, priv, (SeedObject) value, exception))
+ return FALSE;
}
- return TRUE;
+ return TRUE;
}
static void
-seed_ffi_function_finalize (SeedObject obj)
+seed_ffi_function_finalize(SeedObject obj)
{
- seed_ffi_function_priv *priv = seed_object_get_private (obj);
-
- if (priv->signature_obj)
- {
- seed_value_unprotect (eng->context, priv->signature_obj);
-
- g_slice_free1 (priv->n_args * sizeof(GType), priv->args);
+ seed_ffi_function_priv* priv = seed_object_get_private(obj);
+
+ if (priv->signature_obj) {
+ seed_value_unprotect(eng->context, priv->signature_obj);
+
+ g_slice_free1(priv->n_args * sizeof(GType), priv->args);
}
-
- g_free (priv->name);
- g_slice_free1 (sizeof(seed_ffi_function_priv), priv);
- seed_value_unprotect (eng->context, priv->module_obj);
+ g_free(priv->name);
+ g_slice_free1(sizeof(seed_ffi_function_priv), priv);
+
+ seed_value_unprotect(eng->context, priv->module_obj);
}
static SeedObject
-seed_ffi_make_function (SeedContext ctx, SeedObject module_obj, gpointer symbol, const gchar *name,
GHashTable *symbols)
+seed_ffi_make_function(SeedContext ctx,
+ SeedObject module_obj,
+ gpointer symbol,
+ const gchar* name,
+ GHashTable* symbols)
{
- SeedValue ret;
- seed_ffi_function_priv *priv =
- g_slice_alloc0 (sizeof (seed_ffi_function_priv));
-
- priv->symbol = symbol;
- priv->module_obj = module_obj;
- priv->name = g_strdup (name);
-
- ret = seed_make_object (ctx, ffi_function_class, priv);
- seed_value_protect (ctx, ret);
-
- g_hash_table_insert (symbols, g_strdup (name), ret);
- return ret;
+ SeedValue ret;
+ seed_ffi_function_priv* priv
+ = g_slice_alloc0(sizeof(seed_ffi_function_priv));
+
+ priv->symbol = symbol;
+ priv->module_obj = module_obj;
+ priv->name = g_strdup(name);
+
+ ret = seed_make_object(ctx, ffi_function_class, priv);
+ seed_value_protect(ctx, ret);
+
+ g_hash_table_insert(symbols, g_strdup(name), ret);
+ return ret;
}
static SeedValue
-value_from_ffi_type (SeedContext ctx,
- GType otype,
- GArgument *value,
- SeedException *exception)
+value_from_ffi_type(SeedContext ctx,
+ GType otype,
+ GArgument* value,
+ SeedException* exception)
{
- switch (g_type_fundamental (otype))
- {
- case G_TYPE_INT:
- return seed_value_from_int (ctx, value->v_int, exception);
- break;
- case G_TYPE_FLOAT:
- return seed_value_from_float (ctx, value->v_float, exception);
- break;
- case G_TYPE_DOUBLE:
- return seed_value_from_double (ctx, value->v_double, exception);
- break;
- case G_TYPE_BOOLEAN:
- return seed_value_from_boolean (ctx, value->v_boolean, exception);
- break;
- case G_TYPE_STRING:
- return seed_value_from_string (ctx, value->v_pointer, exception);
- break;
- case G_TYPE_CHAR:
- return seed_value_from_char (ctx, value->v_int, exception);
- break;
- case G_TYPE_UCHAR:
- return seed_value_from_uchar (ctx, value->v_uint, exception);
- break;
- case G_TYPE_UINT:
- return seed_value_from_uint (ctx, value->v_uint, exception);
- break;
- case G_TYPE_POINTER:
- return seed_make_pointer (ctx, value->v_pointer);
- break;
- case G_TYPE_LONG:
- return seed_value_from_long (ctx, value->v_long, exception);
- break;
- case G_TYPE_ULONG:
- return seed_value_from_ulong (ctx, value->v_ulong, exception);
- break;
- case G_TYPE_INT64:
- return seed_value_from_int64 (ctx, value->v_int64, exception);
- break;
- case G_TYPE_UINT64:
- return seed_value_from_uint64 (ctx, value->v_uint64, exception);
- break;
- case G_TYPE_NONE:
- return seed_make_null (ctx);
- default:
- g_warning ("Unsupported fundamental type in value_from_ffi_type: %s",
- g_type_name(g_type_fundamental (otype)));
- return seed_make_null (ctx);
+ switch (g_type_fundamental(otype)) {
+ case G_TYPE_INT:
+ return seed_value_from_int(ctx, value->v_int, exception);
+ break;
+ case G_TYPE_FLOAT:
+ return seed_value_from_float(ctx, value->v_float, exception);
+ break;
+ case G_TYPE_DOUBLE:
+ return seed_value_from_double(ctx, value->v_double, exception);
+ break;
+ case G_TYPE_BOOLEAN:
+ return seed_value_from_boolean(ctx, value->v_boolean, exception);
+ break;
+ case G_TYPE_STRING:
+ return seed_value_from_string(ctx, value->v_pointer, exception);
+ break;
+ case G_TYPE_CHAR:
+ return seed_value_from_char(ctx, value->v_int, exception);
+ break;
+ case G_TYPE_UCHAR:
+ return seed_value_from_uchar(ctx, value->v_uint, exception);
+ break;
+ case G_TYPE_UINT:
+ return seed_value_from_uint(ctx, value->v_uint, exception);
+ break;
+ case G_TYPE_POINTER:
+ return seed_make_pointer(ctx, value->v_pointer);
+ break;
+ case G_TYPE_LONG:
+ return seed_value_from_long(ctx, value->v_long, exception);
+ break;
+ case G_TYPE_ULONG:
+ return seed_value_from_ulong(ctx, value->v_ulong, exception);
+ break;
+ case G_TYPE_INT64:
+ return seed_value_from_int64(ctx, value->v_int64, exception);
+ break;
+ case G_TYPE_UINT64:
+ return seed_value_from_uint64(ctx, value->v_uint64, exception);
+ break;
+ case G_TYPE_NONE:
+ return seed_make_null(ctx);
+ default:
+ g_warning("Unsupported fundamental type in value_from_ffi_type: %s",
+ g_type_name(g_type_fundamental(otype)));
+ return seed_make_null(ctx);
}
}
static SeedValue
-seed_ffi_function_call (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_ffi_function_call(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GArgument rvalue;
- GArgument *gargs;
- ffi_type *rtype;
- ffi_type **atypes;
- gpointer *args;
- int i;
- ffi_cif cif;
-
- seed_ffi_function_priv *priv = seed_object_get_private (function);
-
- if (argument_count != priv->n_args)
- {
- seed_make_exception (ctx, exception, "ArgumentError", "%s expected %d arguments got %zd",
- priv->name, priv->n_args, argument_count);
- return seed_make_null (ctx);
+ GArgument rvalue;
+ GArgument* gargs;
+ ffi_type* rtype;
+ ffi_type** atypes;
+ gpointer* args;
+ int i;
+ ffi_cif cif;
+
+ seed_ffi_function_priv* priv = seed_object_get_private(function);
+
+ if (argument_count != priv->n_args) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "%s expected %d arguments got %zd", priv->name,
+ priv->n_args, argument_count);
+ return seed_make_null(ctx);
}
- atypes = g_alloca (sizeof (ffi_type *) * (argument_count));
- args = g_alloca (sizeof (gpointer) * (argument_count));
- gargs = g_alloca (sizeof (GArgument) * (argument_count));
+ atypes = g_alloca(sizeof(ffi_type*) * (argument_count));
+ args = g_alloca(sizeof(gpointer) * (argument_count));
+ gargs = g_alloca(sizeof(GArgument) * (argument_count));
- for (i = 0; i < argument_count; i++)
- {
- atypes[i] = gtype_to_ffi_type (ctx, arguments[i], priv->args[i], &(gargs[i]), &args[i],exception);
+ for (i = 0; i < argument_count; i++) {
+ atypes[i] = gtype_to_ffi_type(ctx, arguments[i], priv->args[i],
+ &(gargs[i]), &args[i], exception);
}
- rtype = return_type_to_ffi_type (priv->ret_val);
-
- if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, argument_count, rtype, atypes) != FFI_OK)
- g_assert_not_reached();
-
- ffi_call (&cif, priv->symbol, &rvalue, args);
-
- return value_from_ffi_type (ctx, priv->ret_val, &rvalue, exception);
+ rtype = return_type_to_ffi_type(priv->ret_val);
+
+ if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, argument_count, rtype, atypes)
+ != FFI_OK)
+ g_assert_not_reached();
+
+ ffi_call(&cif, priv->symbol, &rvalue, args);
+
+ return value_from_ffi_type(ctx, priv->ret_val, &rvalue, exception);
}
static SeedValue
-seed_ffi_library_get_property (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_ffi_library_get_property(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- SeedValue ret;
- GModule *mod;
- gchar *prop;
- gsize len = seed_string_get_maximum_size (property_name);
- gpointer symbol;
- seed_ffi_library_priv *priv;
-
- prop = g_alloca (len);
- seed_string_to_utf8_buffer (property_name, prop, len);
-
- priv = seed_object_get_private (this_object);
- mod = priv->mod;
-
- if ((ret = g_hash_table_lookup (priv->symbols, prop)))
- return ret;
+ SeedValue ret;
+ GModule* mod;
+ gchar* prop;
+ gsize len = seed_string_get_maximum_size(property_name);
+ gpointer symbol;
+ seed_ffi_library_priv* priv;
+
+ prop = g_alloca(len);
+ seed_string_to_utf8_buffer(property_name, prop, len);
- if (!g_module_symbol (mod, prop, &symbol))
- {
- return NULL;
+ priv = seed_object_get_private(this_object);
+ mod = priv->mod;
+
+ if ((ret = g_hash_table_lookup(priv->symbols, prop)))
+ return ret;
+
+ if (!g_module_symbol(mod, prop, &symbol)) {
+ return NULL;
}
- return seed_ffi_make_function (ctx, this_object, symbol, prop, priv->symbols);
+ return seed_ffi_make_function(ctx, this_object, symbol, prop,
+ priv->symbols);
}
-
static SeedObject
-seed_ffi_construct_library (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_ffi_construct_library(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GModule *mod;
- SeedObject ret;
- gchar *filename;
- seed_ffi_library_priv *priv;
-
- if (argument_count != 1 && argument_count != 0)
- {
- seed_make_exception (ctx, exception,
- "ArgumentError",
- "ffi.Library constructor expects 1 argument (filename, or none to use NULL
GModule), got %zd",
- argument_count);
- return seed_make_null (ctx);
+ GModule* mod;
+ SeedObject ret;
+ gchar* filename;
+ seed_ffi_library_priv* priv;
+
+ if (argument_count != 1 && argument_count != 0) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "ffi.Library constructor expects 1 argument "
+ "(filename, or none to use NULL GModule), got %zd",
+ argument_count);
+ return seed_make_null(ctx);
}
- if (argument_count == 1)
- filename = seed_value_to_string (ctx, arguments[0], exception);
- else
- filename = NULL;
-
- mod = g_module_open (filename, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY);
- if (!mod)
- {
- seed_make_exception (ctx, exception, "GModuleError",
- "Opening module (%s) failed with: %s",
- filename, g_module_error ());
- g_free (filename);
- return seed_make_null (ctx);
+ if (argument_count == 1)
+ filename = seed_value_to_string(ctx, arguments[0], exception);
+ else
+ filename = NULL;
+
+ mod = g_module_open(filename, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY);
+ if (!mod) {
+ seed_make_exception(ctx, exception, "GModuleError",
+ "Opening module (%s) failed with: %s", filename,
+ g_module_error());
+ g_free(filename);
+ return seed_make_null(ctx);
}
-
- priv = g_slice_alloc (sizeof (seed_ffi_library_priv));
- priv->mod = mod;
-
- // TODO: Value destroy function.
- priv->symbols = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, NULL);
-
- ret = seed_make_object (ctx, ffi_library_class, priv);
-
- g_free (filename);
-
- return ret;
+
+ priv = g_slice_alloc(sizeof(seed_ffi_library_priv));
+ priv->mod = mod;
+
+ // TODO: Value destroy function.
+ priv->symbols
+ = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+
+ ret = seed_make_object(ctx, ffi_library_class, priv);
+
+ g_free(filename);
+
+ return ret;
}
static void
-seed_ffi_library_finalize (SeedObject obj)
+seed_ffi_library_finalize(SeedObject obj)
{
- seed_ffi_library_priv *priv;
- priv = seed_object_get_private (obj);
-
- g_module_close (priv->mod);
+ seed_ffi_library_priv* priv;
+ priv = seed_object_get_private(obj);
+
+ g_module_close(priv->mod);
}
-seed_static_value ffi_function_values [] = {
- {"signature", seed_ffi_get_signature, seed_ffi_set_signature, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {NULL, NULL, NULL, 0}
-};
+seed_static_value ffi_function_values[]
+ = { { "signature", seed_ffi_get_signature, seed_ffi_set_signature,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { NULL, NULL, NULL, 0 } };
SeedObject
-seed_module_init(SeedEngine *local_eng)
+seed_module_init(SeedEngine* local_eng)
{
- SeedObject library_constructor;
- seed_class_definition ffi_library_def = seed_empty_class;
- seed_class_definition ffi_function_def = seed_empty_class;
-
- ffi_library_def.class_name = "FFILibrary";
- ffi_library_def.finalize = seed_ffi_library_finalize;
- ffi_library_def.get_property = seed_ffi_library_get_property;
-
- ffi_function_def.class_name = "FFIFunction";
- ffi_function_def.finalize = seed_ffi_function_finalize;
- ffi_function_def.static_values = ffi_function_values;
- ffi_function_def.call_as_function = seed_ffi_function_call;
-
- ffi_library_class = seed_create_class (&ffi_library_def);
- ffi_function_class = seed_create_class (&ffi_function_def);
-
- eng = local_eng;
- namespace_ref = seed_make_object (eng->context, NULL, NULL);
-
- library_constructor = seed_make_constructor (eng->context, ffi_library_class, seed_ffi_construct_library);
- seed_object_set_property (eng->context, namespace_ref, "Library", library_constructor);
-
- return namespace_ref;
+ SeedObject library_constructor;
+ seed_class_definition ffi_library_def = seed_empty_class;
+ seed_class_definition ffi_function_def = seed_empty_class;
+
+ ffi_library_def.class_name = "FFILibrary";
+ ffi_library_def.finalize = seed_ffi_library_finalize;
+ ffi_library_def.get_property = seed_ffi_library_get_property;
+
+ ffi_function_def.class_name = "FFIFunction";
+ ffi_function_def.finalize = seed_ffi_function_finalize;
+ ffi_function_def.static_values = ffi_function_values;
+ ffi_function_def.call_as_function = seed_ffi_function_call;
+
+ ffi_library_class = seed_create_class(&ffi_library_def);
+ ffi_function_class = seed_create_class(&ffi_function_def);
+
+ eng = local_eng;
+ namespace_ref = seed_make_object(eng->context, NULL, NULL);
+
+ library_constructor = seed_make_constructor(eng->context, ffi_library_class,
+ seed_ffi_construct_library);
+ seed_object_set_property(eng->context, namespace_ref, "Library",
+ library_constructor);
+
+ return namespace_ref;
}
diff --git a/modules/gettext/seed-gettext.c b/modules/gettext/seed-gettext.c
index 9e78837..84fbd4f 100644
--- a/modules/gettext/seed-gettext.c
+++ b/modules/gettext/seed-gettext.c
@@ -23,320 +23,317 @@
#include <locale.h>
SeedObject ns_ref;
-SeedEngine * eng;
+SeedEngine* eng;
static SeedValue
-seed_gettext_gettext (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_gettext_gettext(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gchar * msgid;
- SeedValue ret;
+ gchar* msgid;
+ SeedValue ret;
- CHECK_ARG_COUNT("gettext.gettext", 1);
+ CHECK_ARG_COUNT("gettext.gettext", 1);
- msgid = seed_value_to_string (ctx, arguments[0], exception);
+ msgid = seed_value_to_string(ctx, arguments[0], exception);
- ret = seed_value_from_string (ctx, gettext(msgid), exception);
+ ret = seed_value_from_string(ctx, gettext(msgid), exception);
- g_free(msgid);
+ g_free(msgid);
- return ret;
+ return ret;
}
static SeedValue
-seed_gettext_textdomain (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_gettext_textdomain(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gchar * domain_name;
- SeedValue ret;
+ gchar* domain_name;
+ SeedValue ret;
- CHECK_ARG_COUNT("gettext.textdomain", 1);
+ CHECK_ARG_COUNT("gettext.textdomain", 1);
- domain_name = seed_value_to_string (ctx, arguments[0], exception);
+ domain_name = seed_value_to_string(ctx, arguments[0], exception);
- ret = seed_value_from_string (ctx, textdomain(domain_name), exception);
- g_free(domain_name);
+ ret = seed_value_from_string(ctx, textdomain(domain_name), exception);
+ g_free(domain_name);
- return ret;
+ return ret;
}
static SeedValue
-seed_gettext_bindtextdomain (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException * exception)
+seed_gettext_bindtextdomain(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
- gchar * domainname, * dirname;
- SeedValue ret;
+ gchar *domainname, *dirname;
+ SeedValue ret;
- CHECK_ARG_COUNT("gettext.bindtextdomain", 2);
+ CHECK_ARG_COUNT("gettext.bindtextdomain", 2);
- domainname = seed_value_to_string (ctx, args[0], exception);
- dirname = seed_value_to_string (ctx, args[1], exception);
+ domainname = seed_value_to_string(ctx, args[0], exception);
+ dirname = seed_value_to_string(ctx, args[1], exception);
- ret = seed_value_from_string (ctx,
- bindtextdomain(domainname, dirname),
- exception);
- g_free(domainname);
- g_free(dirname);
+ ret = seed_value_from_string(ctx, bindtextdomain(domainname, dirname),
+ exception);
+ g_free(domainname);
+ g_free(dirname);
- return ret;
+ return ret;
}
static SeedValue
-seed_gettext_bind_textdomain_codeset (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException * exception)
+seed_gettext_bind_textdomain_codeset(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
- gchar * domainname, * codeset;
- SeedValue ret;
+ gchar *domainname, *codeset;
+ SeedValue ret;
- CHECK_ARG_COUNT("gettext.bind_textdomain_codeset", 2);
+ CHECK_ARG_COUNT("gettext.bind_textdomain_codeset", 2);
- domainname = seed_value_to_string (ctx, args[0], exception);
- codeset = seed_value_to_string (ctx, args[1], exception);
+ domainname = seed_value_to_string(ctx, args[0], exception);
+ codeset = seed_value_to_string(ctx, args[1], exception);
- ret = seed_value_from_string (ctx,
- bind_textdomain_codeset(domainname, codeset),
- exception);
- g_free(domainname);
- g_free(codeset);
+ ret = seed_value_from_string(ctx,
+ bind_textdomain_codeset(domainname, codeset),
+ exception);
+ g_free(domainname);
+ g_free(codeset);
- return ret;
+ return ret;
}
static SeedValue
-seed_gettext_dgettext (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException * exception)
+seed_gettext_dgettext(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
- gchar * domainname, * msgid;
- SeedValue ret;
-
- CHECK_ARG_COUNT("gettext.dgettext", 2);
+ gchar *domainname, *msgid;
+ SeedValue ret;
- domainname = seed_value_to_string (ctx, args[0], exception);
- msgid = seed_value_to_string (ctx, args[1], exception);
+ CHECK_ARG_COUNT("gettext.dgettext", 2);
- ret = seed_value_from_string (ctx, dgettext(domainname, msgid), exception);
- g_free(domainname);
- g_free(msgid);
+ domainname = seed_value_to_string(ctx, args[0], exception);
+ msgid = seed_value_to_string(ctx, args[1], exception);
- return ret;
-}
+ ret = seed_value_from_string(ctx, dgettext(domainname, msgid), exception);
+ g_free(domainname);
+ g_free(msgid);
-static SeedValue
-seed_gettext_dcgettext (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException * exception)
-{
- gchar * domainname, * msgid;
- gint category;
- SeedValue ret;
-
- CHECK_ARG_COUNT("gettext.dcgettext", 3);
-
- domainname = seed_value_to_string (ctx, args[0], exception);
- msgid = seed_value_to_string (ctx, args[1], exception);
- category = seed_value_to_int (ctx, args[2], exception);
-
- ret = seed_value_from_string (ctx,
- dcgettext(domainname, msgid, category),
- exception);
- g_free(domainname);
- g_free(msgid);
-
- return ret;
+ return ret;
}
static SeedValue
-seed_gettext_ngettext (SeedContext ctx,
+seed_gettext_dcgettext(SeedContext ctx,
SeedObject function,
SeedObject this_object,
gsize argument_count,
const SeedValue args[],
- SeedException * exception)
+ SeedException* exception)
{
- gchar * msgid, * msgid_plural;
- guint n;
- SeedValue ret;
+ gchar *domainname, *msgid;
+ gint category;
+ SeedValue ret;
- CHECK_ARG_COUNT("gettext.ngettext", 3);
+ CHECK_ARG_COUNT("gettext.dcgettext", 3);
- msgid = seed_value_to_string (ctx, args[0], exception);
- msgid_plural = seed_value_to_string (ctx, args[1], exception);
- n = seed_value_to_uint (ctx, args[2], exception);
+ domainname = seed_value_to_string(ctx, args[0], exception);
+ msgid = seed_value_to_string(ctx, args[1], exception);
+ category = seed_value_to_int(ctx, args[2], exception);
- ret = seed_value_from_string (ctx, ngettext(msgid, msgid_plural, n), exception);
- g_free(msgid);
- g_free(msgid_plural);
+ ret = seed_value_from_string(ctx, dcgettext(domainname, msgid, category),
+ exception);
+ g_free(domainname);
+ g_free(msgid);
- return ret;
+ return ret;
}
static SeedValue
-seed_gettext_dngettext (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException * exception)
+seed_gettext_ngettext(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
- gchar * domainname, * msgid, * msgid_plural;
- guint n;
- SeedValue ret;
+ gchar *msgid, *msgid_plural;
+ guint n;
+ SeedValue ret;
- CHECK_ARG_COUNT("gettext.dngettext", 4);
+ CHECK_ARG_COUNT("gettext.ngettext", 3);
- domainname = seed_value_to_string (ctx, args[0], exception);
- msgid = seed_value_to_string (ctx, args[1], exception);
- msgid_plural = seed_value_to_string (ctx, args[2], exception);
- n = seed_value_to_uint (ctx, args[3], exception);
+ msgid = seed_value_to_string(ctx, args[0], exception);
+ msgid_plural = seed_value_to_string(ctx, args[1], exception);
+ n = seed_value_to_uint(ctx, args[2], exception);
- ret = seed_value_from_string (ctx, dngettext(domainname, msgid, msgid_plural, n), exception);
- g_free(domainname);
- g_free(msgid);
- g_free(msgid_plural);
+ ret = seed_value_from_string(ctx, ngettext(msgid, msgid_plural, n),
+ exception);
+ g_free(msgid);
+ g_free(msgid_plural);
- return ret;
+ return ret;
}
static SeedValue
-seed_gettext_dcngettext (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException * exception)
+seed_gettext_dngettext(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
- gchar * domainname, * msgid, * msgid_plural;
- guint n;
- gint category;
- SeedValue ret;
-
- CHECK_ARG_COUNT("gettext.dcngettext", 5);
-
- domainname = seed_value_to_string (ctx, args[0], exception);
- msgid = seed_value_to_string (ctx, args[1], exception);
- msgid_plural = seed_value_to_string (ctx, args[2], exception);
- n = seed_value_to_uint (ctx, args[3], exception);
- category = seed_value_to_int (ctx, args[4], exception);
-
- ret = seed_value_from_string (ctx,
- dcngettext(domainname, msgid, msgid_plural, n, category),
- exception);
- g_free(domainname);
- g_free(msgid);
- g_free(msgid_plural);
-
- return ret;
+ gchar *domainname, *msgid, *msgid_plural;
+ guint n;
+ SeedValue ret;
+
+ CHECK_ARG_COUNT("gettext.dngettext", 4);
+
+ domainname = seed_value_to_string(ctx, args[0], exception);
+ msgid = seed_value_to_string(ctx, args[1], exception);
+ msgid_plural = seed_value_to_string(ctx, args[2], exception);
+ n = seed_value_to_uint(ctx, args[3], exception);
+
+ ret = seed_value_from_string(ctx,
+ dngettext(domainname, msgid, msgid_plural, n),
+ exception);
+ g_free(domainname);
+ g_free(msgid);
+ g_free(msgid_plural);
+
+ return ret;
}
static SeedValue
-seed_gettext_setlocale (SeedContext ctx,
+seed_gettext_dcngettext(SeedContext ctx,
SeedObject function,
SeedObject this_object,
gsize argument_count,
const SeedValue args[],
- SeedException * exception)
+ SeedException* exception)
{
- gchar * locale;
- gint category;
- SeedValue ret;
+ gchar *domainname, *msgid, *msgid_plural;
+ guint n;
+ gint category;
+ SeedValue ret;
+
+ CHECK_ARG_COUNT("gettext.dcngettext", 5);
+
+ domainname = seed_value_to_string(ctx, args[0], exception);
+ msgid = seed_value_to_string(ctx, args[1], exception);
+ msgid_plural = seed_value_to_string(ctx, args[2], exception);
+ n = seed_value_to_uint(ctx, args[3], exception);
+ category = seed_value_to_int(ctx, args[4], exception);
+
+ ret = seed_value_from_string(ctx, dcngettext(domainname, msgid,
+ msgid_plural, n, category),
+ exception);
+ g_free(domainname);
+ g_free(msgid);
+ g_free(msgid_plural);
+
+ return ret;
+}
- CHECK_ARG_COUNT("gettext.setlocale", 2);
+static SeedValue
+seed_gettext_setlocale(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
+{
+ gchar* locale;
+ gint category;
+ SeedValue ret;
+
+ CHECK_ARG_COUNT("gettext.setlocale", 2);
- category = seed_value_to_int (ctx, args[0], exception);
- locale = seed_value_to_string (ctx, args[1], exception);
+ category = seed_value_to_int(ctx, args[0], exception);
+ locale = seed_value_to_string(ctx, args[1], exception);
- ret = seed_value_from_string (ctx,
- setlocale(category, locale),
- exception);
- g_free(locale);
+ ret = seed_value_from_string(ctx, setlocale(category, locale), exception);
+ g_free(locale);
- return ret;
+ return ret;
}
-seed_static_function gettext_funcs[] = {
- {"gettext", seed_gettext_gettext, 0},
- {"textdomain", seed_gettext_textdomain, 0},
- {"bindtextdomain", seed_gettext_bindtextdomain, 0},
- {"bind_textdomain_codeset", seed_gettext_bind_textdomain_codeset, 0},
- {"dgettext", seed_gettext_dgettext, 0},
- {"dcgettext", seed_gettext_dcgettext, 0},
- {"ngettext", seed_gettext_ngettext, 0},
- {"dngettext", seed_gettext_dngettext, 0},
- {"dcngettext", seed_gettext_dcngettext, 0},
- {"setlocale", seed_gettext_setlocale, 0},
- {"gettext", seed_gettext_gettext, 0},
- {NULL, NULL, 0}
-};
+seed_static_function gettext_funcs[]
+ = { { "gettext", seed_gettext_gettext, 0 },
+ { "textdomain", seed_gettext_textdomain, 0 },
+ { "bindtextdomain", seed_gettext_bindtextdomain, 0 },
+ { "bind_textdomain_codeset", seed_gettext_bind_textdomain_codeset, 0 },
+ { "dgettext", seed_gettext_dgettext, 0 },
+ { "dcgettext", seed_gettext_dcgettext, 0 },
+ { "ngettext", seed_gettext_ngettext, 0 },
+ { "dngettext", seed_gettext_dngettext, 0 },
+ { "dcngettext", seed_gettext_dcngettext, 0 },
+ { "setlocale", seed_gettext_setlocale, 0 },
+ { "gettext", seed_gettext_gettext, 0 },
+ { NULL, NULL, 0 } };
SeedObject
-seed_module_init(SeedEngine *local_eng)
+seed_module_init(SeedEngine* local_eng)
{
- SeedGlobalContext ctx = local_eng->context;
+ SeedGlobalContext ctx = local_eng->context;
- seed_class_definition gettext_ns_class_def = seed_empty_class;
+ seed_class_definition gettext_ns_class_def = seed_empty_class;
gettext_ns_class_def.static_functions = gettext_funcs;
- SeedClass gettext_ns_class = seed_create_class(&gettext_ns_class_def);
+ SeedClass gettext_ns_class = seed_create_class(&gettext_ns_class_def);
+
+ ns_ref = seed_make_object(ctx, gettext_ns_class, NULL);
+ seed_value_protect(ctx, ns_ref);
- ns_ref = seed_make_object (ctx, gettext_ns_class, NULL);
- seed_value_protect (ctx, ns_ref);
+ /* define enums for setlocale. Where to put them? */
- /* define enums for setlocale. Where to put them? */
+ DEFINE_ENUM_MEMBER(ns_ref, LC_CTYPE);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_NUMERIC);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_TIME);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_COLLATE);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_MONETARY);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_MESSAGES);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_ALL);
+
+/* these are gnu extensions - and not available on BSD systems */
- DEFINE_ENUM_MEMBER(ns_ref, LC_CTYPE);
- DEFINE_ENUM_MEMBER(ns_ref, LC_NUMERIC);
- DEFINE_ENUM_MEMBER(ns_ref, LC_TIME);
- DEFINE_ENUM_MEMBER(ns_ref, LC_COLLATE);
- DEFINE_ENUM_MEMBER(ns_ref, LC_MONETARY);
- DEFINE_ENUM_MEMBER(ns_ref, LC_MESSAGES);
- DEFINE_ENUM_MEMBER(ns_ref, LC_ALL);
-
- /* these are gnu extensions - and not available on BSD systems */
-
#ifdef LC_PAPER
- DEFINE_ENUM_MEMBER(ns_ref, LC_PAPER);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_PAPER);
#endif
#ifdef LC_NAME
- DEFINE_ENUM_MEMBER(ns_ref, LC_NAME);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_NAME);
#endif
#ifdef LC_ADDRESS
- DEFINE_ENUM_MEMBER(ns_ref, LC_ADDRESS);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_ADDRESS);
#endif
#ifdef LC_TELEPHONE
- DEFINE_ENUM_MEMBER(ns_ref, LC_TELEPHONE);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_TELEPHONE);
#endif
#ifdef LC_MEASUREMENT
- DEFINE_ENUM_MEMBER(ns_ref, LC_MEASUREMENT);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_MEASUREMENT);
#endif
#ifdef LC_IDENTIFICATION
- DEFINE_ENUM_MEMBER(ns_ref, LC_IDENTIFICATION);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_IDENTIFICATION);
#endif
- DEFINE_ENUM_MEMBER(ns_ref, LC_CTYPE);
+ DEFINE_ENUM_MEMBER(ns_ref, LC_CTYPE);
- return ns_ref;
+ return ns_ref;
}
-
diff --git a/modules/gjs/system/seed-system.c b/modules/gjs/system/seed-system.c
index a04d575..867acca 100644
--- a/modules/gjs/system/seed-system.c
+++ b/modules/gjs/system/seed-system.c
@@ -35,16 +35,18 @@
#define GJS_COMPAT_VERSION (1 * 100 + 40) * 100 + 0
-#define NUMARG_EXPECTED_EXCEPTION(name, argc) \
- seed_make_exception (ctx, exception, "ArgumentError", name " expected " argc " but got %zd",
argumentCount); \
+#define NUMARG_EXPECTED_EXCEPTION(name, argc) \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ name " expected " argc " but got %zd", argumentCount); \
return seed_make_undefined(ctx);
static SeedValue
-gjs_address_of (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argumentCount,
- const SeedValue arguments[], SeedException * exception)
+gjs_address_of(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[],
+ SeedException* exception)
{
if (argumentCount != 1) {
NUMARG_EXPECTED_EXCEPTION("addressOf", "1 argument")
@@ -52,11 +54,12 @@ gjs_address_of (SeedContext ctx,
SeedValue targetValue = arguments[0];
if (!seed_value_is_object(ctx, targetValue)) {
- seed_make_exception (ctx, exception, "ArgumentError", "addressOf expects an object");
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "addressOf expects an object");
return seed_make_undefined(ctx);
}
- char *pointer_string = g_strdup_printf("%p", targetValue);
+ char* pointer_string = g_strdup_printf("%p", targetValue);
SeedValue ret = seed_value_from_string(ctx, pointer_string, exception);
g_free(pointer_string);
@@ -64,18 +67,19 @@ gjs_address_of (SeedContext ctx,
}
static SeedValue
-gjs_refcount (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argumentCount,
- const SeedValue arguments[], SeedException * exception)
+gjs_refcount(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[],
+ SeedException* exception)
{
if (argumentCount != 1) {
- NUMARG_EXPECTED_EXCEPTION("refcount", "1 argument");
+ NUMARG_EXPECTED_EXCEPTION("refcount", "1 argument");
}
SeedValue targetValue = arguments[0];
- GObject *object = seed_value_to_object (ctx, targetValue, exception);
+ GObject* object = seed_value_to_object(ctx, targetValue, exception);
if (!object)
return seed_make_undefined(ctx);
@@ -84,41 +88,44 @@ gjs_refcount (SeedContext ctx,
}
static SeedValue
-gjs_breakpoint (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argumentCount,
- const SeedValue arguments[], SeedException * exception)
+gjs_breakpoint(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[],
+ SeedException* exception)
{
if (argumentCount != 0) {
- NUMARG_EXPECTED_EXCEPTION("breakpoint", "0 arguments");
+ NUMARG_EXPECTED_EXCEPTION("breakpoint", "0 arguments");
}
G_BREAKPOINT();
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-gjs_gc (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argumentCount,
- const SeedValue arguments[], SeedException * exception)
+gjs_gc(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[],
+ SeedException* exception)
{
if (argumentCount != 0) {
- NUMARG_EXPECTED_EXCEPTION("gc", "0 arguments");
+ NUMARG_EXPECTED_EXCEPTION("gc", "0 arguments");
}
seed_context_collect(ctx);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-gjs_exit (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argumentCount,
- const SeedValue arguments[], SeedException * exception)
+gjs_exit(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[],
+ SeedException* exception)
{
gint32 ret = EXIT_SUCCESS;
if (argumentCount > 1) {
@@ -130,7 +137,8 @@ gjs_exit (SeedContext ctx,
if (seed_value_is_number(ctx, target)) {
ret = seed_value_to_int(ctx, target, exception);
} else {
- seed_make_exception (ctx, exception, "ArgumentError", "exit expects a number argument");
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "exit expects a number argument");
ret = EXIT_FAILURE;
}
}
@@ -139,54 +147,56 @@ gjs_exit (SeedContext ctx,
}
static SeedValue
-gjs_clear_date_caches (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argumentCount,
- const SeedValue arguments[], SeedException * exception)
+gjs_clear_date_caches(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argumentCount,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- // This is provided just for compatibility as javascriptcore doesn't provide the same
+ // This is provided just for compatibility as javascriptcore doesn't provide
+ // the same
// feature.
// I'm not even sure that this is needed for webkit.
- seed_make_exception (ctx, exception, "ImplementationError", "clearDateCache is not implemented.");
+ seed_make_exception(ctx, exception, "ImplementationError",
+ "clearDateCache is not implemented.");
return seed_make_undefined(ctx);
}
-static seed_static_function module_funcs[] = {
- {"addressOf", gjs_address_of, 0},
- {"refcount", gjs_refcount, 0},
- {"breakpoint", gjs_breakpoint, 0},
- {"gc", gjs_gc, 0},
- {"exit", gjs_exit, 0},
- {"clearDateCaches", gjs_clear_date_caches, 0},
- {0, 0, 0}
-};
+static seed_static_function module_funcs[]
+ = { { "addressOf", gjs_address_of, 0 },
+ { "refcount", gjs_refcount, 0 },
+ { "breakpoint", gjs_breakpoint, 0 },
+ { "gc", gjs_gc, 0 },
+ { "exit", gjs_exit, 0 },
+ { "clearDateCaches", gjs_clear_date_caches, 0 },
+ { 0, 0, 0 } };
static seed_class_definition system_def = {
- 0, /* Version, always 0 */
- SEED_CLASS_ATTRIBUTE_NO_SHARED_PROTOTYPE, /* JSClassAttributes */
- "System", /* Class Name */
- NULL, /* Parent Class */
- NULL, /* Static Values */
- module_funcs, /* Static Functions */
- NULL,
- NULL, /* Finalize */
- NULL, /* Has Property */
- NULL, /* Get Property */
- NULL, /* Set Property */
- NULL, /* Delete Property */
- NULL, /* Get Property Names */
- NULL, /* Call As Function */
- NULL, /* Call As Constructor */
- NULL, /* Has Instance */
- NULL /* Convert To Type */
+ 0, /* Version, always 0 */
+ SEED_CLASS_ATTRIBUTE_NO_SHARED_PROTOTYPE, /* JSClassAttributes */
+ "System", /* Class Name */
+ NULL, /* Parent Class */
+ NULL, /* Static Values */
+ module_funcs, /* Static Functions */
+ NULL,
+ NULL, /* Finalize */
+ NULL, /* Has Property */
+ NULL, /* Get Property */
+ NULL, /* Set Property */
+ NULL, /* Delete Property */
+ NULL, /* Get Property Names */
+ NULL, /* Call As Function */
+ NULL, /* Call As Constructor */
+ NULL, /* Has Instance */
+ NULL /* Convert To Type */
};
SeedObject
-gjs_compat_define_system_stuff(SeedEngine *eng)
+gjs_compat_define_system_stuff(SeedEngine* eng)
{
- SeedContext context = eng->context;
- char *program_name = "gnome-weather";
+ SeedContext context = eng->context;
+ char* program_name = "gnome-weather";
SeedObject module;
gboolean ret;
@@ -199,30 +209,32 @@ gjs_compat_define_system_stuff(SeedEngine *eng)
g_print("Seed: %p\n", seed);
g_print("Argv: %p\n", argv);
- //gjs_context = (GjsContext*) JS_GetContextPrivate(context);
- //g_object_get(gjs_context,
+ // gjs_context = (GjsContext*) JS_GetContextPrivate(context);
+ // g_object_get(gjs_context,
// "program-name", &program_name,
// NULL);
- //if (!gjs_string_from_utf8(context, program_name,
+ // if (!gjs_string_from_utf8(context, program_name,
// -1, &value))
// goto out;
/* The name is modeled after program_invocation_name,
part of the glibc */
- ret = seed_object_set_property (context, module, "programInvocationName",
- (SeedValue)seed_value_from_string (context, program_name, NULL));
+ ret = seed_object_set_property(
+ context, module, "programInvocationName",
+ (SeedValue) seed_value_from_string(context, program_name, NULL));
g_print("Module: %d\n", ret);
- ret = seed_object_set_property (context, module, "version",
- (SeedValue)seed_value_from_int (context, GJS_COMPAT_VERSION, NULL));
+ ret = seed_object_set_property(
+ context, module, "version",
+ (SeedValue) seed_value_from_int(context, GJS_COMPAT_VERSION, NULL));
g_print("Module: %d\n", ret);
return module;
}
SeedObject
-seed_module_init(SeedEngine * eng)
+seed_module_init(SeedEngine* eng)
{
- return gjs_compat_define_system_stuff(eng);
+ return gjs_compat_define_system_stuff(eng);
}
diff --git a/modules/gtkbuilder/seed-gtkbuilder.c b/modules/gtkbuilder/seed-gtkbuilder.c
index f08270d..960ded3 100644
--- a/modules/gtkbuilder/seed-gtkbuilder.c
+++ b/modules/gtkbuilder/seed-gtkbuilder.c
@@ -21,85 +21,84 @@
#include <gtk/gtk.h>
-typedef struct _builder_ud {
- SeedContext ctx;
- SeedObject obj;
- SeedObject user_data;
+typedef struct _builder_ud
+{
+ SeedContext ctx;
+ SeedObject obj;
+ SeedObject user_data;
} builder_ud;
static void
-seed_builder_connect_func (GtkBuilder *builder,
- GObject *object,
- const gchar *signal_name,
- const gchar *handler_name,
- GObject *connect_object,
- GConnectFlags flags,
- gpointer user_data)
+seed_builder_connect_func(GtkBuilder* builder,
+ GObject* object,
+ const gchar* signal_name,
+ const gchar* handler_name,
+ GObject* connect_object,
+ GConnectFlags flags,
+ gpointer user_data)
{
- SeedContext ctx;
- SeedObject obj, func;
- builder_ud *priv = (builder_ud *)user_data;
- GClosure *closure;
+ SeedContext ctx;
+ SeedObject obj, func;
+ builder_ud* priv = (builder_ud*) user_data;
+ GClosure* closure;
- ctx = priv->ctx;
- obj = priv->obj;
+ ctx = priv->ctx;
+ obj = priv->obj;
- func = seed_object_get_property (ctx, obj, handler_name);
- if (!seed_value_is_object (ctx, func) || !seed_value_is_function (ctx, func))
- return;
+ func = seed_object_get_property(ctx, obj, handler_name);
+ if (!seed_value_is_object(ctx, func) || !seed_value_is_function(ctx, func))
+ return;
- closure = seed_closure_new (ctx, func, priv->user_data,
- "signal handler (GtkBuilder)");
- if (connect_object != NULL)
- g_object_watch_closure (connect_object, closure);
+ closure = seed_closure_new(ctx, func, priv->user_data,
+ "signal handler (GtkBuilder)");
+ if (connect_object != NULL)
+ g_object_watch_closure(connect_object, closure);
- g_signal_connect_closure (object, signal_name, closure, FALSE);
+ g_signal_connect_closure(object, signal_name, closure, FALSE);
}
SeedValue
seed_gtk_builder_connect_signals(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- builder_ud ud;
- GtkBuilder *b;
-
- CHECK_ARG_COUNT("GtkBuilder.connect_signals", 1);
-
- if (!seed_value_is_object (ctx, arguments[0]))
- {
- seed_make_exception (ctx, exception, "TypeError",
- "connect_signals expects one object as the first argument");
- return seed_make_undefined (ctx);
+ builder_ud ud;
+ GtkBuilder* b;
+
+ CHECK_ARG_COUNT("GtkBuilder.connect_signals", 1);
+
+ if (!seed_value_is_object(ctx, arguments[0])) {
+ seed_make_exception(
+ ctx, exception, "TypeError",
+ "connect_signals expects one object as the first argument");
+ return seed_make_undefined(ctx);
}
- b = GTK_BUILDER (seed_value_to_object (ctx, this_object, exception));
- ud.ctx = ctx;
- ud.obj = arguments[0];
- if (argument_count == 2)
- ud.user_data = arguments[1];
- else
- ud.user_data = NULL;
- gtk_builder_connect_signals_full(b, seed_builder_connect_func, &ud);
+ b = GTK_BUILDER(seed_value_to_object(ctx, this_object, exception));
+ ud.ctx = ctx;
+ ud.obj = arguments[0];
+ if (argument_count == 2)
+ ud.user_data = arguments[1];
+ else
+ ud.user_data = NULL;
+ gtk_builder_connect_signals_full(b, seed_builder_connect_func, &ud);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
SeedObject
-seed_module_init(SeedEngine *eng)
+seed_module_init(SeedEngine* eng)
{
- SeedObject gtkbuilder_proto;
+ SeedObject gtkbuilder_proto;
- gtkbuilder_proto = seed_simple_evaluate (eng->context,
- "imports.gi.Gtk.Builder.prototype",
- NULL);
- seed_create_function (eng->context,
- "connect_signals",
- seed_gtk_builder_connect_signals,
- gtkbuilder_proto);
+ gtkbuilder_proto
+ = seed_simple_evaluate(eng->context, "imports.gi.Gtk.Builder.prototype",
+ NULL);
+ seed_create_function(eng->context, "connect_signals",
+ seed_gtk_builder_connect_signals, gtkbuilder_proto);
- return seed_make_object (eng->context, NULL, NULL);
+ return seed_make_object(eng->context, NULL, NULL);
}
diff --git a/modules/libxml/seed-libxml.c b/modules/libxml/seed-libxml.c
index 845eb21..10d7ac6 100644
--- a/modules/libxml/seed-libxml.c
+++ b/modules/libxml/seed-libxml.c
@@ -27,7 +27,7 @@
#include <libxml/xpathInternals.h> // for xmlXPathRegisterNs
SeedObject namespace_ref;
-SeedEngine *eng;
+SeedEngine* eng;
SeedClass xml_doc_class;
SeedClass xml_node_class;
@@ -36,546 +36,522 @@ SeedClass xml_attr_class;
SeedClass xml_xpath_class;
SeedClass xml_xpathobj_class;
-#define XML_DOC_PRIV(obj) ((xmlDocPtr)seed_object_get_private(obj))
-#define XML_NODE_PRIV(obj) ((xmlNodePtr)seed_object_get_private(obj))
-#define XML_XPATH_PRIV(obj) ((xmlXPathContextPtr)seed_object_get_private (obj))
-#define XML_XPATHOBJ_PRIV(obj) ((xmlXPathObjectPtr)seed_object_get_private (obj))
+#define XML_DOC_PRIV(obj) ((xmlDocPtr) seed_object_get_private(obj))
+#define XML_NODE_PRIV(obj) ((xmlNodePtr) seed_object_get_private(obj))
+#define XML_XPATH_PRIV(obj) ((xmlXPathContextPtr) seed_object_get_private(obj))
+#define XML_XPATHOBJ_PRIV(obj) \
+ ((xmlXPathObjectPtr) seed_object_get_private(obj))
static SeedObject
-seed_make_xml_doc (SeedContext ctx,
- xmlDocPtr doc)
+seed_make_xml_doc(SeedContext ctx, xmlDocPtr doc)
{
- SeedObject ret;
- if (doc->_private)
- return (SeedObject) doc->_private;
- ret = seed_make_object (ctx, xml_doc_class, doc);
- doc->_private = ret;
- return ret;
+ SeedObject ret;
+ if (doc->_private)
+ return (SeedObject) doc->_private;
+ ret = seed_make_object(ctx, xml_doc_class, doc);
+ doc->_private = ret;
+ return ret;
}
static SeedObject
-seed_make_xml_node (SeedContext ctx,
- xmlNodePtr node)
+seed_make_xml_node(SeedContext ctx, xmlNodePtr node)
{
- SeedObject ret;
- if (node == NULL)
- return seed_make_null (ctx);
- if (node->_private)
- return (SeedObject) node->_private;
- ret = seed_make_object (ctx, xml_node_class, node);
- node->_private = ret;
- return ret;
+ SeedObject ret;
+ if (node == NULL)
+ return seed_make_null(ctx);
+ if (node->_private)
+ return (SeedObject) node->_private;
+ ret = seed_make_object(ctx, xml_node_class, node);
+ node->_private = ret;
+ return ret;
}
static SeedObject
-seed_make_xml_attr (SeedContext ctx,
- xmlAttrPtr attr)
+seed_make_xml_attr(SeedContext ctx, xmlAttrPtr attr)
{
- SeedObject ret;
- if (attr == NULL)
- return seed_make_null (ctx);
- if (attr->_private)
- return (SeedObject) attr->_private;
- ret = seed_make_object (ctx, xml_attr_class, attr);
- attr->_private = ret;
- return ret;
+ SeedObject ret;
+ if (attr == NULL)
+ return seed_make_null(ctx);
+ if (attr->_private)
+ return (SeedObject) attr->_private;
+ ret = seed_make_object(ctx, xml_attr_class, attr);
+ attr->_private = ret;
+ return ret;
}
-static gchar *
-seed_xml_element_type_to_string (xmlElementType type)
+static gchar*
+seed_xml_element_type_to_string(xmlElementType type)
{
- if (type == XML_ELEMENT_NODE)
- return "element";
- else if (type == XML_ATTRIBUTE_NODE)
- return "attribute";
- else if (type == XML_TEXT_NODE)
- return "text";
- else
- return "Implement more types! racarr is lazy.";
+ if (type == XML_ELEMENT_NODE)
+ return "element";
+ else if (type == XML_ATTRIBUTE_NODE)
+ return "attribute";
+ else if (type == XML_TEXT_NODE)
+ return "text";
+ else
+ return "Implement more types! racarr is lazy.";
}
static SeedValue
-seed_xml_parse_file (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_xml_parse_file(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedObject ret;
- xmlDocPtr doc;
- gchar *path;
- if (argument_count != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "parseFile expected 1 argument, got %zd",
- argument_count);
- return seed_make_null (ctx);
+ SeedObject ret;
+ xmlDocPtr doc;
+ gchar* path;
+ if (argument_count != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "parseFile expected 1 argument, got %zd",
+ argument_count);
+ return seed_make_null(ctx);
}
- path = seed_value_to_string (ctx, arguments[0], exception);
- doc = xmlParseFile (path);
- if (!doc)
- {
- seed_make_exception (ctx, exception, "XMLError",
- "Document not parsed successfully");
- g_free (path);
- return seed_make_null (ctx);
+ path = seed_value_to_string(ctx, arguments[0], exception);
+ doc = xmlParseFile(path);
+ if (!doc) {
+ seed_make_exception(ctx, exception, "XMLError",
+ "Document not parsed successfully");
+ g_free(path);
+ return seed_make_null(ctx);
}
- ret = seed_make_xml_doc (ctx, doc);
+ ret = seed_make_xml_doc(ctx, doc);
- g_free (path);
- return ret;
+ g_free(path);
+ return ret;
}
static SeedValue
-seed_xml_parse_string (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_xml_parse_string(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedObject ret;
- xmlDocPtr doc;
- gchar *string;
- if (argument_count != 1)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "parseString expected 1 argument, got %zd",
- argument_count);
- return seed_make_null (ctx);
+ SeedObject ret;
+ xmlDocPtr doc;
+ gchar* string;
+ if (argument_count != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "parseString expected 1 argument, got %zd",
+ argument_count);
+ return seed_make_null(ctx);
}
- string = seed_value_to_string (ctx, arguments[0], exception);
- doc = xmlParseMemory (string, strlen (string));
- if (!doc)
- {
- seed_make_exception (ctx, exception, "XMLError",
- "Document not parsed successfully");
- g_free (string);
- return seed_make_null (ctx);
+ string = seed_value_to_string(ctx, arguments[0], exception);
+ doc = xmlParseMemory(string, strlen(string));
+ if (!doc) {
+ seed_make_exception(ctx, exception, "XMLError",
+ "Document not parsed successfully");
+ g_free(string);
+ return seed_make_null(ctx);
}
- ret = seed_make_xml_doc (ctx, doc);
+ ret = seed_make_xml_doc(ctx, doc);
- g_free (string);
- return ret;
+ g_free(string);
+ return ret;
}
static SeedValue
-seed_xml_doc_get_root (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_doc_get_root(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlDocPtr doc = XML_DOC_PRIV (object);
- return seed_make_xml_node (ctx, xmlDocGetRootElement (doc));
+ xmlDocPtr doc = XML_DOC_PRIV(object);
+ return seed_make_xml_node(ctx, xmlDocGetRootElement(doc));
}
static void
-seed_xml_doc_finalize (SeedObject object)
+seed_xml_doc_finalize(SeedObject object)
{
- xmlDocPtr ptr = XML_DOC_PRIV (object);
- xmlFreeDoc (ptr);
+ xmlDocPtr ptr = XML_DOC_PRIV(object);
+ xmlFreeDoc(ptr);
}
static SeedValue
-seed_xml_node_get_name (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_node_get_name(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
- return seed_value_from_string (ctx, (gchar *)node->name, exception);
+ xmlNodePtr node = XML_NODE_PRIV(object);
+ return seed_value_from_string(ctx, (gchar*) node->name, exception);
}
static SeedValue
-seed_xml_node_get_children (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_node_get_children(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
-
- return seed_make_xml_node (ctx, node->children);
+ xmlNodePtr node = XML_NODE_PRIV(object);
+ return seed_make_xml_node(ctx, node->children);
}
static SeedValue
-seed_xml_node_get_parent (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_node_get_parent(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
+ xmlNodePtr node = XML_NODE_PRIV(object);
- return seed_make_xml_node (ctx, node->parent);
+ return seed_make_xml_node(ctx, node->parent);
}
static SeedValue
-seed_xml_node_get_next (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_node_get_next(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
+ xmlNodePtr node = XML_NODE_PRIV(object);
- return seed_make_xml_node (ctx, node->next);
+ return seed_make_xml_node(ctx, node->next);
}
static SeedValue
-seed_xml_node_get_prev (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_node_get_prev(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
+ xmlNodePtr node = XML_NODE_PRIV(object);
- return seed_make_xml_node (ctx, node->prev);
+ return seed_make_xml_node(ctx, node->prev);
}
static SeedValue
-seed_xml_node_get_last (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_node_get_last(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
+ xmlNodePtr node = XML_NODE_PRIV(object);
- return seed_make_xml_node (ctx, node->last);
+ return seed_make_xml_node(ctx, node->last);
}
static SeedValue
-seed_xml_node_get_doc (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_node_get_doc(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
+ xmlNodePtr node = XML_NODE_PRIV(object);
- return seed_make_xml_doc (ctx, node->doc);
+ return seed_make_xml_doc(ctx, node->doc);
}
static SeedValue
-seed_xml_node_get_content (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_node_get_content(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- SeedValue ret;
- gchar *content;
- xmlNodePtr node = XML_NODE_PRIV (object);
+ SeedValue ret;
+ gchar* content;
+ xmlNodePtr node = XML_NODE_PRIV(object);
- content = (gchar *)xmlNodeGetContent (node);
- ret = seed_value_from_string (ctx, content, exception);
- g_free (content);
+ content = (gchar*) xmlNodeGetContent(node);
+ ret = seed_value_from_string(ctx, content, exception);
+ g_free(content);
- return ret;
+ return ret;
}
static SeedValue
-seed_xml_node_get_type (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_node_get_type(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
+ xmlNodePtr node = XML_NODE_PRIV(object);
- return seed_value_from_string (ctx,
- seed_xml_element_type_to_string
- (node->type), exception);
+ return seed_value_from_string(ctx,
+ seed_xml_element_type_to_string(node->type),
+ exception);
}
static SeedValue
-seed_xml_node_get_properties (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_node_get_properties(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
+ xmlNodePtr node = XML_NODE_PRIV(object);
- return seed_make_xml_attr (ctx, node->properties);
+ return seed_make_xml_attr(ctx, node->properties);
}
static void
-seed_xml_node_init (SeedContext ctx,
- SeedObject object)
+seed_xml_node_init(SeedContext ctx, SeedObject object)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
- if (node && node->doc->_private)
- seed_value_protect (ctx, node->doc->_private);
+ xmlNodePtr node = XML_NODE_PRIV(object);
+ if (node && node->doc->_private)
+ seed_value_protect(ctx, node->doc->_private);
}
static void
-seed_xml_node_finalize (SeedObject object)
+seed_xml_node_finalize(SeedObject object)
{
- xmlNodePtr node = XML_NODE_PRIV (object);
- if (!node)
- return;
- node->_private = NULL;
- // This might be invalid.
- if (node->doc->_private)
- seed_value_unprotect (eng->context, node->doc->_private);
+ xmlNodePtr node = XML_NODE_PRIV(object);
+ if (!node)
+ return;
+ node->_private = NULL;
+ // This might be invalid.
+ if (node->doc->_private)
+ seed_value_unprotect(eng->context, node->doc->_private);
}
static SeedValue
-seed_xml_xpath_eval (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_xml_xpath_eval(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- xmlXPathObjectPtr xpath_obj;
- xmlXPathContextPtr xpath_ctx;
- guchar *xpath;
-
- if (argument_count != 1)
- {
- seed_make_exception (ctx, exception,
- "ArgumentError",
- "xpathEval expected 1 argument, got %zd",
- argument_count);
- return seed_make_null (ctx);
+ xmlXPathObjectPtr xpath_obj;
+ xmlXPathContextPtr xpath_ctx;
+ guchar* xpath;
+
+ if (argument_count != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "xpathEval expected 1 argument, got %zd",
+ argument_count);
+ return seed_make_null(ctx);
}
- xpath_ctx = XML_XPATH_PRIV (this_object);
+ xpath_ctx = XML_XPATH_PRIV(this_object);
- xpath = (guchar *)seed_value_to_string (ctx, arguments[0], exception);
- xpath_obj = xmlXPathEval (xpath, xpath_ctx);
- g_free (xpath);
+ xpath = (guchar*) seed_value_to_string(ctx, arguments[0], exception);
+ xpath_obj = xmlXPathEval(xpath, xpath_ctx);
+ g_free(xpath);
- return seed_make_object (ctx, xml_xpathobj_class, xpath_obj);
+ return seed_make_object(ctx, xml_xpathobj_class, xpath_obj);
}
static SeedValue
-seed_xml_xpath_register_ns (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_xml_xpath_register_ns(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- xmlXPathContextPtr xpath;
- guchar *prefix;
- guchar *ns_uri;
- if (argument_count != 2)
- {
- seed_make_exception (ctx, exception, "ArgumentError",
- "xpathRegisterNs expects 2 arguments, got %zd",
- argument_count);
- return seed_make_undefined (ctx);
+ xmlXPathContextPtr xpath;
+ guchar* prefix;
+ guchar* ns_uri;
+ if (argument_count != 2) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "xpathRegisterNs expects 2 arguments, got %zd",
+ argument_count);
+ return seed_make_undefined(ctx);
}
- xpath = XML_XPATH_PRIV (this_object);
- prefix = (guchar *)seed_value_to_string (ctx, arguments[0], exception);
- ns_uri = (guchar *)seed_value_to_string (ctx, arguments[1], exception);
+ xpath = XML_XPATH_PRIV(this_object);
+ prefix = (guchar*) seed_value_to_string(ctx, arguments[0], exception);
+ ns_uri = (guchar*) seed_value_to_string(ctx, arguments[1], exception);
- xmlXPathRegisterNs (xpath, prefix, ns_uri);
- g_free (prefix);
- g_free (ns_uri);
+ xmlXPathRegisterNs(xpath, prefix, ns_uri);
+ g_free(prefix);
+ g_free(ns_uri);
- return seed_make_undefined (ctx);
+ return seed_make_undefined(ctx);
}
static SeedValue
-seed_xml_construct_xpath_context (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_xml_construct_xpath_context(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- xmlXPathContextPtr xpath;
- xmlDocPtr doc;
+ xmlXPathContextPtr xpath;
+ xmlDocPtr doc;
- doc = XML_DOC_PRIV (this_object);
- xpath = xmlXPathNewContext (doc);
+ doc = XML_DOC_PRIV(this_object);
+ xpath = xmlXPathNewContext(doc);
- seed_value_protect (ctx, this_object);
+ seed_value_protect(ctx, this_object);
- return seed_make_object (ctx, xml_xpath_class, xpath);
+ return seed_make_object(ctx, xml_xpath_class, xpath);
}
static void
-seed_xml_xpath_finalize (SeedObject object)
+seed_xml_xpath_finalize(SeedObject object)
{
- xmlXPathContextPtr xpath = XML_XPATH_PRIV (object);
- // Maybe unsafe. Seems to work.
- seed_value_unprotect (eng->context, xpath->doc->_private);
- xmlXPathFreeContext (xpath);
+ xmlXPathContextPtr xpath = XML_XPATH_PRIV(object);
+ // Maybe unsafe. Seems to work.
+ seed_value_unprotect(eng->context, xpath->doc->_private);
+ xmlXPathFreeContext(xpath);
}
static void
-seed_xml_xpathobj_finalize (SeedObject object)
+seed_xml_xpathobj_finalize(SeedObject object)
{
- xmlXPathObjectPtr xpath = XML_XPATHOBJ_PRIV (object);
- xmlXPathFreeObject (xpath);
+ xmlXPathObjectPtr xpath = XML_XPATHOBJ_PRIV(object);
+ xmlXPathFreeObject(xpath);
}
static SeedValue
-seed_xml_array_from_nodeset (SeedContext ctx,
- xmlNodeSetPtr nodeset,
- SeedException *exception)
+seed_xml_array_from_nodeset(SeedContext ctx,
+ xmlNodeSetPtr nodeset,
+ SeedException* exception)
{
- SeedValue *ary = g_alloca (nodeset->nodeNr * sizeof (SeedValue));
- int i;
+ SeedValue* ary = g_alloca(nodeset->nodeNr * sizeof(SeedValue));
+ int i;
- for (i = 0; i < nodeset->nodeNr; i++)
- {
- ary[i] = seed_make_xml_node (ctx, nodeset->nodeTab[i]);
+ for (i = 0; i < nodeset->nodeNr; i++) {
+ ary[i] = seed_make_xml_node(ctx, nodeset->nodeTab[i]);
}
- return seed_make_array (ctx, ary, nodeset->nodeNr, exception);
+ return seed_make_array(ctx, ary, nodeset->nodeNr, exception);
}
static SeedValue
-seed_xml_xpathobj_get_value (SeedContext ctx,
- SeedObject object,
- SeedString property_name,
- SeedException *exception)
+seed_xml_xpathobj_get_value(SeedContext ctx,
+ SeedObject object,
+ SeedString property_name,
+ SeedException* exception)
{
- xmlXPathObjectPtr xpath = XML_XPATHOBJ_PRIV (object);
-
- switch (xpath->type)
- {
-/* case XPATH_BOOLEAN:
- return seed_value_from_boolean (ctx, xpath->boolval, exception);
- case XPATH_NUMBER:
- return seed_value_from_double (ctx, xpath->floatval, exception);
- case XPATH_STRING:
- return seed_value_from_string (ctx, xpath->stringval, exception);*/
- case XPATH_NODESET:
- return seed_xml_array_from_nodeset (ctx, xpath->nodesetval, exception);
- default:
- return seed_make_null (ctx);
+ xmlXPathObjectPtr xpath = XML_XPATHOBJ_PRIV(object);
+
+ switch (xpath->type) {
+ /* case XPATH_BOOLEAN:
+ return seed_value_from_boolean (ctx, xpath->boolval, exception);
+ case XPATH_NUMBER:
+ return seed_value_from_double (ctx, xpath->floatval, exception);
+ case XPATH_STRING:
+ return seed_value_from_string (ctx, xpath->stringval, exception);*/
+ case XPATH_NODESET:
+ return seed_xml_array_from_nodeset(ctx, xpath->nodesetval,
+ exception);
+ default:
+ return seed_make_null(ctx);
}
}
-
-seed_static_function doc_funcs[] = {
- {"xpathNewContext", seed_xml_construct_xpath_context, 0},
- {NULL, NULL, 0}
-};
-
-seed_static_value doc_values[] = {
- {"root", seed_xml_doc_get_root, NULL, 0},
- {"name", seed_xml_node_get_name, NULL, 0},
- {"children", seed_xml_node_get_children, NULL, 0},
- {"parent", seed_xml_node_get_parent, NULL, 0},
- {"next", seed_xml_node_get_next, NULL, 0},
- {"prev", seed_xml_node_get_prev, NULL, 0},
- {"last", seed_xml_node_get_last, NULL, 0},
- {"doc", seed_xml_node_get_doc, NULL, 0},
- {"type", seed_xml_node_get_type, NULL, 0},
- {NULL, NULL, NULL, 0}
-};
-
-seed_static_function node_funcs[] = {
- {NULL, NULL, 0}
-};
-
-seed_static_value node_values[] = {
- {"name", seed_xml_node_get_name, NULL, 0},
- {"children", seed_xml_node_get_children, NULL, 0},
- {"parent", seed_xml_node_get_parent, NULL, 0},
- {"next", seed_xml_node_get_next, NULL, 0},
- {"prev", seed_xml_node_get_prev, NULL, 0},
- {"content", seed_xml_node_get_content, NULL, 0},
- {"last", seed_xml_node_get_last, NULL, 0},
- {"doc", seed_xml_node_get_doc, NULL, 0},
- {"type", seed_xml_node_get_type, NULL, 0},
- {"properties", seed_xml_node_get_properties, NULL, 0},
- {NULL, NULL, NULL, 0}
-};
-
-seed_static_function attr_funcs[] = {
- {NULL, NULL, 0}
-};
-
-seed_static_value attr_values[] = {
- {"name", seed_xml_node_get_name, NULL, 0},
- {"children", seed_xml_node_get_children, NULL, 0},
- {"parent", seed_xml_node_get_parent, NULL, 0},
- {"next", seed_xml_node_get_next, NULL, 0},
- {"prev", seed_xml_node_get_prev, NULL, 0},
- {"last", seed_xml_node_get_last, NULL, 0},
- {"doc", seed_xml_node_get_doc, NULL, 0},
- {"type", seed_xml_node_get_type, NULL, 0},
- {NULL, NULL, NULL, 0}
-};
-
-seed_static_function xpath_funcs[] = {
- {"xpathEval", seed_xml_xpath_eval, 0},
- {"xpathRegisterNs", seed_xml_xpath_register_ns, 0},
- {NULL, NULL, 0}
-};
-
-seed_static_value xpathobj_values[] = {
- {"value", seed_xml_xpathobj_get_value, NULL, 0},
- {NULL, NULL, NULL, 0}
-};
+seed_static_function doc_funcs[]
+ = { { "xpathNewContext", seed_xml_construct_xpath_context, 0 },
+ { NULL, NULL, 0 } };
+
+seed_static_value doc_values[]
+ = { { "root", seed_xml_doc_get_root, NULL, 0 },
+ { "name", seed_xml_node_get_name, NULL, 0 },
+ { "children", seed_xml_node_get_children, NULL, 0 },
+ { "parent", seed_xml_node_get_parent, NULL, 0 },
+ { "next", seed_xml_node_get_next, NULL, 0 },
+ { "prev", seed_xml_node_get_prev, NULL, 0 },
+ { "last", seed_xml_node_get_last, NULL, 0 },
+ { "doc", seed_xml_node_get_doc, NULL, 0 },
+ { "type", seed_xml_node_get_type, NULL, 0 },
+ { NULL, NULL, NULL, 0 } };
+
+seed_static_function node_funcs[] = { { NULL, NULL, 0 } };
+
+seed_static_value node_values[]
+ = { { "name", seed_xml_node_get_name, NULL, 0 },
+ { "children", seed_xml_node_get_children, NULL, 0 },
+ { "parent", seed_xml_node_get_parent, NULL, 0 },
+ { "next", seed_xml_node_get_next, NULL, 0 },
+ { "prev", seed_xml_node_get_prev, NULL, 0 },
+ { "content", seed_xml_node_get_content, NULL, 0 },
+ { "last", seed_xml_node_get_last, NULL, 0 },
+ { "doc", seed_xml_node_get_doc, NULL, 0 },
+ { "type", seed_xml_node_get_type, NULL, 0 },
+ { "properties", seed_xml_node_get_properties, NULL, 0 },
+ { NULL, NULL, NULL, 0 } };
+
+seed_static_function attr_funcs[] = { { NULL, NULL, 0 } };
+
+seed_static_value attr_values[]
+ = { { "name", seed_xml_node_get_name, NULL, 0 },
+ { "children", seed_xml_node_get_children, NULL, 0 },
+ { "parent", seed_xml_node_get_parent, NULL, 0 },
+ { "next", seed_xml_node_get_next, NULL, 0 },
+ { "prev", seed_xml_node_get_prev, NULL, 0 },
+ { "last", seed_xml_node_get_last, NULL, 0 },
+ { "doc", seed_xml_node_get_doc, NULL, 0 },
+ { "type", seed_xml_node_get_type, NULL, 0 },
+ { NULL, NULL, NULL, 0 } };
+
+seed_static_function xpath_funcs[]
+ = { { "xpathEval", seed_xml_xpath_eval, 0 },
+ { "xpathRegisterNs", seed_xml_xpath_register_ns, 0 },
+ { NULL, NULL, 0 } };
+
+seed_static_value xpathobj_values[]
+ = { { "value", seed_xml_xpathobj_get_value, NULL, 0 },
+ { NULL, NULL, NULL, 0 } };
static void
-seed_libxml_define_stuff ()
+seed_libxml_define_stuff()
{
- SeedObject node_proto;
-
- seed_class_definition xml_doc_class_def = seed_empty_class;
- seed_class_definition xml_node_class_def = seed_empty_class;
- seed_class_definition xml_attr_class_def = seed_empty_class;
- seed_class_definition xml_xpath_class_def = seed_empty_class;
- seed_class_definition xml_xpathobj_class_def = seed_empty_class;
-
- xml_doc_class_def.class_name="XMLDocument";
- xml_doc_class_def.static_functions = doc_funcs;
- xml_doc_class_def.static_values = doc_values;
- xml_doc_class_def.finalize = seed_xml_doc_finalize;
- xml_doc_class = seed_create_class (&xml_doc_class_def);
-
- xml_node_class_def.class_name="XMLNode";
- xml_node_class_def.static_functions = node_funcs;
- xml_node_class_def.static_values = node_values;
- xml_node_class_def.finalize = seed_xml_node_finalize;
- xml_node_class_def.initialize = seed_xml_node_init;
- xml_node_class = seed_create_class (&xml_node_class_def);
-
- xml_attr_class_def.class_name="XMLAttribute";
- xml_attr_class_def.static_functions = attr_funcs;
- xml_attr_class_def.static_values = attr_values;
- xml_attr_class_def.finalize = seed_xml_node_finalize;
- xml_attr_class_def.initialize = seed_xml_node_init;
- xml_attr_class = seed_create_class (&xml_attr_class_def);
-
- xml_xpath_class_def.class_name = "XMLXPathContext";
- xml_xpath_class_def.finalize = seed_xml_xpath_finalize;
- xml_xpath_class_def.static_functions = xpath_funcs;
- xml_xpath_class = seed_create_class (&xml_xpath_class_def);
-
- xml_xpathobj_class_def.class_name = "XMLXPathObj";
- xml_xpathobj_class_def.finalize = seed_xml_xpathobj_finalize;
- xml_xpathobj_class_def.static_values = xpathobj_values;
- xml_xpathobj_class = seed_create_class (&xml_xpathobj_class_def);
-
- seed_create_function (eng->context, "parseFile",
- (SeedFunctionCallback) seed_xml_parse_file,
- namespace_ref);
- seed_create_function (eng->context, "parseString",
- (SeedFunctionCallback) seed_xml_parse_string,
- namespace_ref);
-
- node_proto = seed_object_get_prototype (eng->context,
- seed_make_object (eng->context,
- xml_node_class,
- NULL));
- seed_make_object (eng->context, xml_node_class, NULL);
- seed_object_set_property (eng->context, namespace_ref, "_nodeProto", node_proto);
- seed_simple_evaluate (eng->context, "imports.extensions.xml", NULL);
+ SeedObject node_proto;
+
+ seed_class_definition xml_doc_class_def = seed_empty_class;
+ seed_class_definition xml_node_class_def = seed_empty_class;
+ seed_class_definition xml_attr_class_def = seed_empty_class;
+ seed_class_definition xml_xpath_class_def = seed_empty_class;
+ seed_class_definition xml_xpathobj_class_def = seed_empty_class;
+
+ xml_doc_class_def.class_name = "XMLDocument";
+ xml_doc_class_def.static_functions = doc_funcs;
+ xml_doc_class_def.static_values = doc_values;
+ xml_doc_class_def.finalize = seed_xml_doc_finalize;
+ xml_doc_class = seed_create_class(&xml_doc_class_def);
+
+ xml_node_class_def.class_name = "XMLNode";
+ xml_node_class_def.static_functions = node_funcs;
+ xml_node_class_def.static_values = node_values;
+ xml_node_class_def.finalize = seed_xml_node_finalize;
+ xml_node_class_def.initialize = seed_xml_node_init;
+ xml_node_class = seed_create_class(&xml_node_class_def);
+
+ xml_attr_class_def.class_name = "XMLAttribute";
+ xml_attr_class_def.static_functions = attr_funcs;
+ xml_attr_class_def.static_values = attr_values;
+ xml_attr_class_def.finalize = seed_xml_node_finalize;
+ xml_attr_class_def.initialize = seed_xml_node_init;
+ xml_attr_class = seed_create_class(&xml_attr_class_def);
+
+ xml_xpath_class_def.class_name = "XMLXPathContext";
+ xml_xpath_class_def.finalize = seed_xml_xpath_finalize;
+ xml_xpath_class_def.static_functions = xpath_funcs;
+ xml_xpath_class = seed_create_class(&xml_xpath_class_def);
+
+ xml_xpathobj_class_def.class_name = "XMLXPathObj";
+ xml_xpathobj_class_def.finalize = seed_xml_xpathobj_finalize;
+ xml_xpathobj_class_def.static_values = xpathobj_values;
+ xml_xpathobj_class = seed_create_class(&xml_xpathobj_class_def);
+
+ seed_create_function(eng->context, "parseFile",
+ (SeedFunctionCallback) seed_xml_parse_file,
+ namespace_ref);
+ seed_create_function(eng->context, "parseString",
+ (SeedFunctionCallback) seed_xml_parse_string,
+ namespace_ref);
+
+ node_proto = seed_object_get_prototype(
+ eng->context, seed_make_object(eng->context, xml_node_class, NULL));
+ seed_make_object(eng->context, xml_node_class, NULL);
+ seed_object_set_property(eng->context, namespace_ref, "_nodeProto",
+ node_proto);
+ seed_simple_evaluate(eng->context, "imports.extensions.xml", NULL);
}
SeedObject
-seed_module_init(SeedEngine *local_eng)
+seed_module_init(SeedEngine* local_eng)
{
- eng = local_eng;
- namespace_ref = seed_make_object (eng->context, NULL, NULL);
- seed_value_protect (eng->context, namespace_ref);
+ eng = local_eng;
+ namespace_ref = seed_make_object(eng->context, NULL, NULL);
+ seed_value_protect(eng->context, namespace_ref);
- seed_libxml_define_stuff();
+ seed_libxml_define_stuff();
- return namespace_ref;
+ return namespace_ref;
}
diff --git a/modules/mpfr/seed-mpfr-arithmetic.c b/modules/mpfr/seed-mpfr-arithmetic.c
index 5fce150..fd22f7c 100644
--- a/modules/mpfr/seed-mpfr-arithmetic.c
+++ b/modules/mpfr/seed-mpfr-arithmetic.c
@@ -21,12 +21,13 @@
#include "seed-mpfr.h"
/* This is a bit disgusting. Oh well. */
-SeedValue seed_mpfr_add (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_add(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -44,50 +45,41 @@ SeedValue seed_mpfr_add (SeedContext ctx,
argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
argt2 = seed_mpfr_arg_type(ctx, args[1], exception);
- if ( (argt1 & argt2) == SEED_MPFR_MPFR )
- {
+ if ((argt1 & argt2) == SEED_MPFR_MPFR) {
/* both mpfr_t */
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
ret = mpfr_add(rop, op1, op2, rnd);
- }
- else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
- {
+ } else if ((argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE)) {
/* a double and an mpfr_t. Figure out the order */
- if ( argt1 == SEED_MPFR_MPFR )
- {
+ if (argt1 == SEED_MPFR_MPFR) {
op1 = seed_object_get_private(args[0]);
dop2 = seed_value_to_double(ctx, args[1], exception);
ret = mpfr_add_d(rop, op1, dop2, rnd);
- }
- else
- {
+ } else {
dop2 = seed_value_to_double(ctx, args[0], exception);
op1 = seed_object_get_private(args[1]);
ret = mpfr_add_d(rop, op1, dop2, rnd);
}
- }
- else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
- {
+ } else if ((argt1 & argt2) == SEED_MPFR_DOUBLE) {
/* 2 doubles. hopefully doesn't happen */
dop1 = seed_value_to_double(ctx, args[0], exception);
dop2 = seed_value_to_double(ctx, args[1], exception);
ret = mpfr_set_d(rop, dop1 + dop2, rnd);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.add", "double or mpfr_t");
}
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_sub (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_sub(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -105,50 +97,41 @@ SeedValue seed_mpfr_sub (SeedContext ctx,
argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
argt2 = seed_mpfr_arg_type(ctx, args[1], exception);
- if ( (argt1 & argt2) == SEED_MPFR_MPFR )
- {
+ if ((argt1 & argt2) == SEED_MPFR_MPFR) {
/* both mpfr_t */
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
ret = mpfr_sub(rop, op1, op2, rnd);
- }
- else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
- {
+ } else if ((argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE)) {
/* a double and an mpfr_t. Figure out the order */
- if ( argt1 == SEED_MPFR_MPFR )
- {
+ if (argt1 == SEED_MPFR_MPFR) {
op1 = seed_object_get_private(args[0]);
dop2 = seed_value_to_double(ctx, args[1], exception);
ret = mpfr_sub_d(rop, op1, dop2, rnd);
- }
- else
- {
+ } else {
dop1 = seed_value_to_double(ctx, args[0], exception);
op2 = seed_object_get_private(args[1]);
ret = mpfr_d_sub(rop, dop1, op2, rnd);
}
- }
- else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
- {
+ } else if ((argt1 & argt2) == SEED_MPFR_DOUBLE) {
/* 2 doubles. hopefully doesn't happen */
dop1 = seed_value_to_double(ctx, args[0], exception);
dop2 = seed_value_to_double(ctx, args[1], exception);
ret = mpfr_set_d(rop, dop1 - dop2, rnd);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.sub", "double or mpfr_t");
}
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_mul (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_mul(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -166,50 +149,41 @@ SeedValue seed_mpfr_mul (SeedContext ctx,
argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
argt2 = seed_mpfr_arg_type(ctx, args[1], exception);
- if ( (argt1 & argt2) == SEED_MPFR_MPFR )
- {
+ if ((argt1 & argt2) == SEED_MPFR_MPFR) {
/* both mpfr_t */
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
ret = mpfr_mul(rop, op1, op2, rnd);
- }
- else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
- {
+ } else if ((argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE)) {
/* a double and an mpfr_t. Figure out the order */
- if ( argt1 == SEED_MPFR_MPFR )
- {
+ if (argt1 == SEED_MPFR_MPFR) {
op1 = seed_object_get_private(args[0]);
dop2 = seed_value_to_double(ctx, args[1], exception);
ret = mpfr_mul_d(rop, op1, dop2, rnd);
- }
- else
- {
+ } else {
dop2 = seed_value_to_double(ctx, args[0], exception);
op1 = seed_object_get_private(args[1]);
ret = mpfr_mul_d(rop, op1, dop2, rnd);
}
- }
- else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
- {
+ } else if ((argt1 & argt2) == SEED_MPFR_DOUBLE) {
/* 2 doubles. hopefully doesn't happen */
dop1 = seed_value_to_double(ctx, args[0], exception);
dop2 = seed_value_to_double(ctx, args[1], exception);
ret = mpfr_set_d(rop, dop1 * dop2, rnd);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.mul", "double or mpfr_t");
}
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_div (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException * exception)
+SeedValue
+seed_mpfr_div(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -227,51 +201,41 @@ SeedValue seed_mpfr_div (SeedContext ctx,
argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
argt2 = seed_mpfr_arg_type(ctx, args[1], exception);
- if ( (argt1 & argt2) == SEED_MPFR_MPFR )
- {
+ if ((argt1 & argt2) == SEED_MPFR_MPFR) {
/* both mpfr_t */
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
ret = mpfr_div(rop, op1, op2, rnd);
- }
- else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
- {
+ } else if ((argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE)) {
/* a double and an mpfr_t. Figure out the order */
- if ( argt1 == SEED_MPFR_MPFR )
- {
+ if (argt1 == SEED_MPFR_MPFR) {
op1 = seed_object_get_private(args[0]);
dop2 = seed_value_to_double(ctx, args[1], exception);
ret = mpfr_div_d(rop, op1, dop2, rnd);
- }
- else
- {
+ } else {
dop1 = seed_value_to_double(ctx, args[0], exception);
op2 = seed_object_get_private(args[1]);
ret = mpfr_d_div(rop, dop1, op2, rnd);
}
- }
- else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
- {
+ } else if ((argt1 & argt2) == SEED_MPFR_DOUBLE) {
/* 2 doubles. hopefully doesn't happen */
dop1 = seed_value_to_double(ctx, args[0], exception);
dop2 = seed_value_to_double(ctx, args[1], exception);
ret = mpfr_set_d(rop, dop1 / dop2, rnd);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.div", "double or mpfr_t");
}
return seed_value_from_int(ctx, ret, exception);
}
-
-SeedValue seed_mpfr_pow (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException * exception)
+SeedValue
+seed_mpfr_pow(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -290,52 +254,43 @@ SeedValue seed_mpfr_pow (SeedContext ctx,
argt1 = seed_mpfr_arg_type(ctx, args[0], exception);
argt2 = seed_mpfr_arg_type(ctx, args[1], exception);
- if ( (argt1 & argt2) == SEED_MPFR_MPFR )
- {
+ if ((argt1 & argt2) == SEED_MPFR_MPFR) {
/* both mpfr_t */
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
ret = mpfr_pow(rop, op1, op2, rnd);
- }
- else if ( (argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE) )
- {
+ } else if ((argt1 | argt2) == (SEED_MPFR_MPFR | SEED_MPFR_DOUBLE)) {
/* a double and an mpfr_t. Figure out the order */
/* FIXME: is this switching ui and si bad? si_pow doesn't exist,
and it's all from double anyway */
- if ( argt1 == SEED_MPFR_MPFR )
- {
+ if (argt1 == SEED_MPFR_MPFR) {
op1 = seed_object_get_private(args[0]);
iop = seed_value_to_long(ctx, args[1], exception);
ret = mpfr_pow_si(rop, op1, iop, rnd);
- }
- else
- {
+ } else {
uiop1 = seed_value_to_ulong(ctx, args[0], exception);
op2 = seed_object_get_private(args[1]);
ret = mpfr_ui_pow(rop, uiop1, op2, rnd);
}
- }
- else if ( (argt1 & argt2) == SEED_MPFR_DOUBLE )
- {
+ } else if ((argt1 & argt2) == SEED_MPFR_DOUBLE) {
/* pretend both ui */
uiop1 = seed_value_to_ulong(ctx, args[0], exception);
uiop2 = seed_value_to_ulong(ctx, args[1], exception);
ret = mpfr_ui_pow_ui(rop, uiop1, uiop2, rnd);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.pow", "int or unsigned int and mpfr_t");
}
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_sqrt (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_sqrt(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -346,12 +301,9 @@ SeedValue seed_mpfr_sqrt (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.sqrt", "mpfr_t");
}
@@ -360,12 +312,13 @@ SeedValue seed_mpfr_sqrt (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_rec_sqrt (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_rec_sqrt(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -376,12 +329,9 @@ SeedValue seed_mpfr_rec_sqrt (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.rec_sqrt", "mpfr_t");
}
@@ -390,12 +340,13 @@ SeedValue seed_mpfr_rec_sqrt (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_sqr (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_sqr(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -406,12 +357,9 @@ SeedValue seed_mpfr_sqr (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.sqr", "mpfr_t");
}
@@ -420,12 +368,13 @@ SeedValue seed_mpfr_sqr (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_root (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_root(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -437,36 +386,30 @@ SeedValue seed_mpfr_root (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.root", "mpfr_t");
}
- if ( seed_value_is_number(ctx, args[1]) )
- {
+ if (seed_value_is_number(ctx, args[1])) {
k = seed_value_to_ulong(ctx, args[1], exception);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.root", "unsigned long int");
}
-
ret = mpfr_root(rop, op, k, rnd);
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_cbrt (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_cbrt(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -477,12 +420,9 @@ SeedValue seed_mpfr_cbrt (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.cbrt", "mpfr_t");
}
@@ -491,12 +431,13 @@ SeedValue seed_mpfr_cbrt (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_neg (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_neg(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -507,12 +448,9 @@ SeedValue seed_mpfr_neg (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.neg", "mpfr_t");
}
@@ -521,12 +459,13 @@ SeedValue seed_mpfr_neg (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_abs (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_abs(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -537,12 +476,9 @@ SeedValue seed_mpfr_abs (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.abs", "mpfr_t");
}
@@ -551,12 +487,13 @@ SeedValue seed_mpfr_abs (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_dim (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_dim(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -567,14 +504,11 @@ SeedValue seed_mpfr_dim (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[1], mpfr_class))
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[1], mpfr_class)) {
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.dim", "mpfr_t");
}
@@ -583,15 +517,15 @@ SeedValue seed_mpfr_dim (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-
/* Rounding functions */
-SeedValue seed_mpfr_rint (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_rint(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -602,12 +536,9 @@ SeedValue seed_mpfr_rint (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.rint", "mpfr_t");
}
@@ -616,12 +547,13 @@ SeedValue seed_mpfr_rint (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_ceil (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_ceil(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gint ret;
@@ -630,12 +562,9 @@ SeedValue seed_mpfr_ceil (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.ceil", "mpfr_t");
}
@@ -644,12 +573,13 @@ SeedValue seed_mpfr_ceil (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_floor (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException * exception)
+SeedValue
+seed_mpfr_floor(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gint ret;
@@ -658,12 +588,9 @@ SeedValue seed_mpfr_floor (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.floor", "mpfr_t");
}
@@ -672,12 +599,13 @@ SeedValue seed_mpfr_floor (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_round (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_round(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gint ret;
@@ -686,12 +614,9 @@ SeedValue seed_mpfr_round (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.round", "mpfr_t");
}
@@ -700,12 +625,13 @@ SeedValue seed_mpfr_round (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_trunc (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException * exception)
+SeedValue
+seed_mpfr_trunc(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gint ret;
@@ -714,12 +640,9 @@ SeedValue seed_mpfr_trunc (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.trunc", "mpfr_t");
}
@@ -728,12 +651,13 @@ SeedValue seed_mpfr_trunc (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_rint_ceil (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_rint_ceil(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -744,12 +668,9 @@ SeedValue seed_mpfr_rint_ceil (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.rint_ceil", "mpfr_t");
}
@@ -758,12 +679,13 @@ SeedValue seed_mpfr_rint_ceil (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_rint_floor (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_rint_floor(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -774,12 +696,9 @@ SeedValue seed_mpfr_rint_floor (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.rint_floor", "mpfr_t");
}
@@ -788,12 +707,13 @@ SeedValue seed_mpfr_rint_floor (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_rint_round (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_rint_round(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -804,12 +724,9 @@ SeedValue seed_mpfr_rint_round (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.rint_round", "mpfr_t");
}
@@ -818,12 +735,13 @@ SeedValue seed_mpfr_rint_round (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_rint_trunc (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_rint_trunc(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -834,12 +752,9 @@ SeedValue seed_mpfr_rint_trunc (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.rint_trunc", "mpfr_t");
}
@@ -848,12 +763,13 @@ SeedValue seed_mpfr_rint_trunc (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_frac (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_frac(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -864,12 +780,9 @@ SeedValue seed_mpfr_frac (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.frac", "mpfr_t");
}
@@ -878,12 +791,13 @@ SeedValue seed_mpfr_frac (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_integer_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_integer_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
gboolean ret;
@@ -895,12 +809,13 @@ SeedValue seed_mpfr_integer_p (SeedContext ctx,
return seed_value_from_boolean(ctx, ret, exception);
}
-SeedValue seed_mpfr_fmod (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_fmod(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -911,14 +826,11 @@ SeedValue seed_mpfr_fmod (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[1], mpfr_class))
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[1], mpfr_class)) {
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.fmod", "mpfr_t");
}
@@ -927,12 +839,13 @@ SeedValue seed_mpfr_fmod (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_remainder (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_remainder(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -943,14 +856,11 @@ SeedValue seed_mpfr_remainder (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[1], mpfr_class))
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[1], mpfr_class)) {
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.remainder", "mpfr_t");
}
@@ -959,12 +869,13 @@ SeedValue seed_mpfr_remainder (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_nexttoward (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_nexttoward(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
@@ -972,12 +883,9 @@ SeedValue seed_mpfr_nexttoward (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.nexttoward", "mpfr_t");
}
@@ -986,12 +894,13 @@ SeedValue seed_mpfr_nexttoward (SeedContext ctx,
return seed_make_null(ctx);
}
-SeedValue seed_mpfr_nextabove (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_nextabove(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
@@ -1003,12 +912,13 @@ SeedValue seed_mpfr_nextabove (SeedContext ctx,
return seed_make_null(ctx);
}
-SeedValue seed_mpfr_nextbelow (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_nextbelow(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
@@ -1020,12 +930,13 @@ SeedValue seed_mpfr_nextbelow (SeedContext ctx,
return seed_make_null(ctx);
}
-SeedValue seed_mpfr_min (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_min(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -1036,14 +947,11 @@ SeedValue seed_mpfr_min (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[1], mpfr_class))
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[1], mpfr_class)) {
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.min", "mpfr_t");
}
@@ -1052,12 +960,13 @@ SeedValue seed_mpfr_min (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_max (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_max(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -1068,14 +977,11 @@ SeedValue seed_mpfr_max (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[1], mpfr_class))
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[1], mpfr_class)) {
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.max", "mpfr_t");
}
@@ -1084,12 +990,13 @@ SeedValue seed_mpfr_max (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_prec_round (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_prec_round(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mp_prec_t prec;
@@ -1107,12 +1014,13 @@ SeedValue seed_mpfr_prec_round (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_signbit (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_signbit(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
gboolean ret;
@@ -1124,12 +1032,13 @@ SeedValue seed_mpfr_signbit (SeedContext ctx,
return seed_value_from_boolean(ctx, ret, exception);
}
-SeedValue seed_mpfr_setsign (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_setsign(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gint ret;
@@ -1142,12 +1051,9 @@ SeedValue seed_mpfr_setsign (SeedContext ctx,
s = seed_value_to_int(ctx, args[1], exception);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.setsign", "mpfr_t");
}
@@ -1156,12 +1062,13 @@ SeedValue seed_mpfr_setsign (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_copysign (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_copysign(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -1172,14 +1079,11 @@ SeedValue seed_mpfr_copysign (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[1], mpfr_class))
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[1], mpfr_class)) {
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.copysign", "mpfr_t");
}
@@ -1188,12 +1092,13 @@ SeedValue seed_mpfr_copysign (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_mul_2si (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_mul_2si(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -1205,21 +1110,15 @@ SeedValue seed_mpfr_mul_2si (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.mul_2si", "mpfr_t");
}
- if ( seed_value_is_number(ctx, args[1]) )
- {
+ if (seed_value_is_number(ctx, args[1])) {
k = seed_value_to_ulong(ctx, args[1], exception);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.mul_2si", "long int");
}
@@ -1228,12 +1127,13 @@ SeedValue seed_mpfr_mul_2si (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_div_2si (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_div_2si(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -1245,21 +1145,15 @@ SeedValue seed_mpfr_div_2si (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.div_2si", "mpfr_t");
}
- if ( seed_value_is_number(ctx, args[1]) )
- {
+ if (seed_value_is_number(ctx, args[1])) {
k = seed_value_to_ulong(ctx, args[1], exception);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.div_2si", "long int");
}
@@ -1267,4 +1161,3 @@ SeedValue seed_mpfr_div_2si (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-
diff --git a/modules/mpfr/seed-mpfr-cmp.c b/modules/mpfr/seed-mpfr-cmp.c
index 5446cf5..6b10ffc 100644
--- a/modules/mpfr/seed-mpfr-cmp.c
+++ b/modules/mpfr/seed-mpfr-cmp.c
@@ -20,12 +20,13 @@
#include <mpfr.h>
#include "seed-mpfr.h"
-SeedValue seed_mpfr_cmp (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_cmp(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gdouble dop;
@@ -35,31 +36,26 @@ SeedValue seed_mpfr_cmp (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
ret = mpfr_cmp(rop, op);
- }
- else if ( seed_value_is_number(ctx, args[0]))
- {
+ } else if (seed_value_is_number(ctx, args[0])) {
dop = seed_value_to_double(ctx, args[0], exception);
ret = mpfr_cmp_d(rop, dop);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.cmp", "mpfr_t or double");
}
-
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_cmpabs (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_cmpabs(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gint ret;
@@ -68,12 +64,9 @@ SeedValue seed_mpfr_cmpabs (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.cmpabs", "mpfr_t");
}
@@ -83,12 +76,12 @@ SeedValue seed_mpfr_cmpabs (SeedContext ctx,
}
SeedValue
-seed_mpfr_nan_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_nan_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
gboolean ret;
@@ -103,12 +96,12 @@ seed_mpfr_nan_p (SeedContext ctx,
}
SeedValue
-seed_mpfr_inf_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_inf_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
gboolean ret;
@@ -123,12 +116,12 @@ seed_mpfr_inf_p (SeedContext ctx,
}
SeedValue
-seed_mpfr_number_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_number_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
gboolean ret;
@@ -143,12 +136,12 @@ seed_mpfr_number_p (SeedContext ctx,
}
SeedValue
-seed_mpfr_zero_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_zero_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
gboolean ret;
@@ -163,12 +156,12 @@ seed_mpfr_zero_p (SeedContext ctx,
}
SeedValue
-seed_mpfr_sgn (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_sgn(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
gint ret;
@@ -182,12 +175,13 @@ seed_mpfr_sgn (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_greater_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_greater_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gboolean ret;
@@ -196,12 +190,9 @@ SeedValue seed_mpfr_greater_p (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.greater_p", "mpfr_t");
}
@@ -210,12 +201,13 @@ SeedValue seed_mpfr_greater_p (SeedContext ctx,
return seed_value_from_boolean(ctx, ret, exception);
}
-SeedValue seed_mpfr_greaterequal_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_greaterequal_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gboolean ret;
@@ -224,12 +216,9 @@ SeedValue seed_mpfr_greaterequal_p (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.greaterequal_p", "mpfr_t");
}
@@ -238,12 +227,13 @@ SeedValue seed_mpfr_greaterequal_p (SeedContext ctx,
return seed_value_from_boolean(ctx, ret, exception);
}
-SeedValue seed_mpfr_less_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_less_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gboolean ret;
@@ -252,12 +242,9 @@ SeedValue seed_mpfr_less_p (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.less_p", "mpfr_t");
}
@@ -266,12 +253,13 @@ SeedValue seed_mpfr_less_p (SeedContext ctx,
return seed_value_from_boolean(ctx, ret, exception);
}
-SeedValue seed_mpfr_lessequal_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_lessequal_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gboolean ret;
@@ -280,12 +268,9 @@ SeedValue seed_mpfr_lessequal_p (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.less_equal_p", "mpfr_t");
}
@@ -294,12 +279,13 @@ SeedValue seed_mpfr_lessequal_p (SeedContext ctx,
return seed_value_from_boolean(ctx, ret, exception);
}
-SeedValue seed_mpfr_lessgreater_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_lessgreater_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gboolean ret;
@@ -308,12 +294,9 @@ SeedValue seed_mpfr_lessgreater_p (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.lessgreater_p", "mpfr_t");
}
@@ -322,12 +305,13 @@ SeedValue seed_mpfr_lessgreater_p (SeedContext ctx,
return seed_value_from_boolean(ctx, ret, exception);
}
-SeedValue seed_mpfr_equal_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_equal_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gboolean ret;
@@ -336,12 +320,9 @@ SeedValue seed_mpfr_equal_p (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.equal_p", "mpfr_t");
}
@@ -350,12 +331,13 @@ SeedValue seed_mpfr_equal_p (SeedContext ctx,
return seed_value_from_boolean(ctx, ret, exception);
}
-SeedValue seed_mpfr_unordered_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_unordered_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
gboolean ret;
@@ -364,12 +346,9 @@ SeedValue seed_mpfr_unordered_p (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.unordered_p", "mpfr_t");
}
@@ -378,13 +357,13 @@ SeedValue seed_mpfr_unordered_p (SeedContext ctx,
return seed_value_from_boolean(ctx, ret, exception);
}
-
-SeedValue seed_mpfr_cmp_si_2exp (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_cmp_si_2exp(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr op1;
gulong op2;
@@ -395,21 +374,15 @@ SeedValue seed_mpfr_cmp_si_2exp (SeedContext ctx,
op1 = seed_object_get_private(this_object);
- if ( seed_value_is_number(ctx, args[0]) )
- {
+ if (seed_value_is_number(ctx, args[0])) {
op2 = seed_value_to_ulong(ctx, args[0], exception);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.cmp_si_2exp", "long int");
}
- if ( seed_value_is_number(ctx, args[1]) )
- {
+ if (seed_value_is_number(ctx, args[1])) {
exp = seed_value_to_mp_exp_t(ctx, args[1], exception);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.cmp_si_2exp", "mp_exp_t");
}
@@ -417,4 +390,3 @@ SeedValue seed_mpfr_cmp_si_2exp (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-
diff --git a/modules/mpfr/seed-mpfr-trig.c b/modules/mpfr/seed-mpfr-trig.c
index 3d28dbc..213377b 100644
--- a/modules/mpfr/seed-mpfr-trig.c
+++ b/modules/mpfr/seed-mpfr-trig.c
@@ -21,12 +21,13 @@
#include "seed-mpfr.h"
-SeedValue seed_mpfr_sin (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_sin(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -37,12 +38,9 @@ SeedValue seed_mpfr_sin (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.sin", "mpfr_t");
}
@@ -51,12 +49,13 @@ SeedValue seed_mpfr_sin (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_cos (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_cos(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -67,12 +66,9 @@ SeedValue seed_mpfr_cos (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.cos", "mpfr_t");
}
@@ -81,12 +77,13 @@ SeedValue seed_mpfr_cos (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_tan (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_tan(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -97,12 +94,9 @@ SeedValue seed_mpfr_tan (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.tan", "mpfr_t");
}
@@ -111,12 +105,13 @@ SeedValue seed_mpfr_tan (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_csc (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_csc(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -127,12 +122,9 @@ SeedValue seed_mpfr_csc (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.csc", "mpfr_t");
}
@@ -141,12 +133,13 @@ SeedValue seed_mpfr_csc (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_sec (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_sec(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -157,12 +150,9 @@ SeedValue seed_mpfr_sec (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.sec", "mpfr_t");
}
@@ -171,12 +161,13 @@ SeedValue seed_mpfr_sec (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_cot (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_cot(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -187,12 +178,9 @@ SeedValue seed_mpfr_cot (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.cot", "mpfr_t");
}
@@ -201,12 +189,13 @@ SeedValue seed_mpfr_cot (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_asin (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_asin(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -217,12 +206,9 @@ SeedValue seed_mpfr_asin (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.asin", "mpfr_t");
}
@@ -231,13 +217,13 @@ SeedValue seed_mpfr_asin (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-
-SeedValue seed_mpfr_acos (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_acos(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -248,12 +234,9 @@ SeedValue seed_mpfr_acos (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.acos", "mpfr_t");
}
@@ -262,12 +245,13 @@ SeedValue seed_mpfr_acos (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_atan (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_atan(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -278,12 +262,9 @@ SeedValue seed_mpfr_atan (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.atan", "mpfr_t");
}
@@ -292,15 +273,15 @@ SeedValue seed_mpfr_atan (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-
/* log functions */
-SeedValue seed_mpfr_log (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_log(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -311,12 +292,9 @@ SeedValue seed_mpfr_log (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.log", "mpfr_t");
}
@@ -325,12 +303,13 @@ SeedValue seed_mpfr_log (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_log2 (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_log2(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -341,12 +320,9 @@ SeedValue seed_mpfr_log2 (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.log2", "mpfr_t");
}
@@ -355,12 +331,13 @@ SeedValue seed_mpfr_log2 (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_log10 (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_log10(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -371,12 +348,9 @@ SeedValue seed_mpfr_log10 (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.log10", "mpfr_t");
}
@@ -387,12 +361,13 @@ SeedValue seed_mpfr_log10 (SeedContext ctx,
/* hyperbolic trig functions */
-SeedValue seed_mpfr_sinh (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_sinh(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -403,12 +378,9 @@ SeedValue seed_mpfr_sinh (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.sinh", "mpfr_t");
}
@@ -417,12 +389,13 @@ SeedValue seed_mpfr_sinh (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_cosh (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_cosh(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -433,12 +406,9 @@ SeedValue seed_mpfr_cosh (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.cosh", "mpfr_t");
}
@@ -447,12 +417,13 @@ SeedValue seed_mpfr_cosh (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_tanh (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_tanh(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -463,12 +434,9 @@ SeedValue seed_mpfr_tanh (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.tanh", "mpfr_t");
}
@@ -477,13 +445,13 @@ SeedValue seed_mpfr_tanh (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-
-SeedValue seed_mpfr_sech (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_sech(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -494,12 +462,9 @@ SeedValue seed_mpfr_sech (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.sech", "mpfr_t");
}
@@ -508,12 +473,13 @@ SeedValue seed_mpfr_sech (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_csch (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_csch(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -524,12 +490,9 @@ SeedValue seed_mpfr_csch (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.csch", "mpfr_t");
}
@@ -538,12 +501,13 @@ SeedValue seed_mpfr_csch (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_coth (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_coth(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -554,12 +518,9 @@ SeedValue seed_mpfr_coth (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.coth", "mpfr_t");
}
@@ -570,12 +531,13 @@ SeedValue seed_mpfr_coth (SeedContext ctx,
/* inverse hyperbolic trig */
-SeedValue seed_mpfr_asinh (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_asinh(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -586,12 +548,9 @@ SeedValue seed_mpfr_asinh (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.asinh", "mpfr_t");
}
@@ -600,12 +559,13 @@ SeedValue seed_mpfr_asinh (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_acosh (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_acosh(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -616,12 +576,9 @@ SeedValue seed_mpfr_acosh (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.acosh", "mpfr_t");
}
@@ -630,12 +587,13 @@ SeedValue seed_mpfr_acosh (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_atanh (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_atanh(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -646,12 +604,9 @@ SeedValue seed_mpfr_atanh (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.atanh", "mpfr_t");
}
@@ -660,12 +615,13 @@ SeedValue seed_mpfr_atanh (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_log1p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_log1p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -676,12 +632,9 @@ SeedValue seed_mpfr_log1p (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.log1p", "mpfr_t");
}
@@ -690,12 +643,13 @@ SeedValue seed_mpfr_log1p (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_expm1 (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_expm1(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -706,12 +660,9 @@ SeedValue seed_mpfr_expm1 (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.expm1", "mpfr_t");
}
@@ -720,12 +671,13 @@ SeedValue seed_mpfr_expm1 (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_li2 (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_li2(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -736,12 +688,9 @@ SeedValue seed_mpfr_li2 (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.li2", "mpfr_t");
}
@@ -750,12 +699,13 @@ SeedValue seed_mpfr_li2 (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_gamma (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_gamma(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -766,12 +716,9 @@ SeedValue seed_mpfr_gamma (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.gamma", "mpfr_t");
}
@@ -780,12 +727,13 @@ SeedValue seed_mpfr_gamma (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_lngamma (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_lngamma(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -796,12 +744,9 @@ SeedValue seed_mpfr_lngamma (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.lngamma", "mpfr_t");
}
@@ -810,12 +755,13 @@ SeedValue seed_mpfr_lngamma (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_zeta (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_zeta(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -827,30 +773,26 @@ SeedValue seed_mpfr_zeta (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
ret = mpfr_zeta(rop, op, rnd);
- }
- else if ( seed_value_is_number(ctx, args[0]) )
- {
+ } else if (seed_value_is_number(ctx, args[0])) {
uiop = seed_value_to_ulong(ctx, args[0], exception);
ret = mpfr_zeta_ui(rop, uiop, rnd);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.zeta", "mpfr_t or unsigned int");
}
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_erf (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_erf(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -861,12 +803,9 @@ SeedValue seed_mpfr_erf (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.erf", "mpfr_t");
}
@@ -875,12 +814,13 @@ SeedValue seed_mpfr_erf (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_erfc (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_erfc(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -891,12 +831,9 @@ SeedValue seed_mpfr_erfc (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.erfc", "mpfr_t");
}
@@ -906,12 +843,13 @@ SeedValue seed_mpfr_erfc (SeedContext ctx,
}
/* bessel functions */
-SeedValue seed_mpfr_j0 (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_j0(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -922,12 +860,9 @@ SeedValue seed_mpfr_j0 (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.j0", "mpfr_t");
}
@@ -936,12 +871,13 @@ SeedValue seed_mpfr_j0 (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_j1 (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_j1(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -952,12 +888,9 @@ SeedValue seed_mpfr_j1 (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.j1", "mpfr_t");
}
@@ -966,12 +899,13 @@ SeedValue seed_mpfr_j1 (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_jn (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_jn(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -982,21 +916,15 @@ SeedValue seed_mpfr_jn (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[1], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[1], mpfr_class)) {
op = seed_object_get_private(args[1]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.jn", "mpfr_t");
}
- if ( seed_value_is_number(ctx, args[0]) )
- {
+ if (seed_value_is_number(ctx, args[0])) {
n = seed_value_to_int(ctx, args[0], exception);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.jn", "int");
}
@@ -1005,12 +933,13 @@ SeedValue seed_mpfr_jn (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_y0 (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_y0(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -1021,12 +950,9 @@ SeedValue seed_mpfr_y0 (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.y0", "mpfr_t");
}
@@ -1035,12 +961,13 @@ SeedValue seed_mpfr_y0 (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_y1 (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_y1(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -1051,12 +978,9 @@ SeedValue seed_mpfr_y1 (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.y1", "mpfr_t");
}
@@ -1065,12 +989,13 @@ SeedValue seed_mpfr_y1 (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_yn (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_yn(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -1081,21 +1006,15 @@ SeedValue seed_mpfr_yn (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[1], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[1], mpfr_class)) {
op = seed_object_get_private(args[1]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.yn", "mpfr_t");
}
- if ( seed_value_is_number(ctx, args[0]) )
- {
+ if (seed_value_is_number(ctx, args[0])) {
n = seed_value_to_int(ctx, args[0], exception);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.yn", "int");
}
@@ -1104,12 +1023,13 @@ SeedValue seed_mpfr_yn (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_fma (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_fma(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2, op3;
@@ -1120,16 +1040,13 @@ SeedValue seed_mpfr_fma (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[3], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[1], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[2], mpfr_class))
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[1], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[2], mpfr_class)) {
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
op3 = seed_object_get_private(args[2]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.fma", "mpfr_t");
}
@@ -1138,12 +1055,13 @@ SeedValue seed_mpfr_fma (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_fms (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_fms(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2, op3;
@@ -1154,16 +1072,13 @@ SeedValue seed_mpfr_fms (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[3], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[1], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[2], mpfr_class))
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[1], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[2], mpfr_class)) {
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
op3 = seed_object_get_private(args[2]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.fms", "mpfr_t");
}
@@ -1172,12 +1087,13 @@ SeedValue seed_mpfr_fms (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_agm (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_agm(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -1188,14 +1104,11 @@ SeedValue seed_mpfr_agm (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[1], mpfr_class))
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[1], mpfr_class)) {
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.agm", "mpfr_t");
}
@@ -1204,12 +1117,13 @@ SeedValue seed_mpfr_agm (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_hypot (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_hypot(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op1, op2;
@@ -1220,14 +1134,11 @@ SeedValue seed_mpfr_hypot (SeedContext ctx,
rop = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) &&
- seed_value_is_object_of_class(ctx, args[1], mpfr_class))
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)
+ && seed_value_is_object_of_class(ctx, args[1], mpfr_class)) {
op1 = seed_object_get_private(args[0]);
op2 = seed_object_get_private(args[1]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.hypot", "mpfr_t");
}
@@ -1236,27 +1147,28 @@ SeedValue seed_mpfr_hypot (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_free_cache (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_free_cache(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
CHECK_ARG_COUNT("mpfr.free_cache", 0);
mpfr_free_cache();
return seed_make_null(ctx);
}
-SeedValue seed_mpfr_clear_flags (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_clear_flags(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
CHECK_ARG_COUNT("mpfr.clear_flags", 0);
mpfr_clear_flags();
return seed_make_null(ctx);
}
-
diff --git a/modules/mpfr/seed-mpfr.c b/modules/mpfr/seed-mpfr.c
index 5188cb1..85cb185 100644
--- a/modules/mpfr/seed-mpfr.c
+++ b/modules/mpfr/seed-mpfr.c
@@ -27,30 +27,31 @@
SeedObject ns_ref;
SeedClass mpfr_class;
-/* For now at least ignoring the ability to use gmp types since there is no gmp module */
+/* For now at least ignoring the ability to use gmp types since there is no gmp
+ * module */
-SeedEngine * eng;
+SeedEngine* eng;
seed_mpfr_t
seed_mpfr_arg_type(SeedContext ctx, SeedValue arg, SeedException exept)
{
- if ( seed_value_is_object_of_class(ctx, arg, mpfr_class) )
+ if (seed_value_is_object_of_class(ctx, arg, mpfr_class))
return SEED_MPFR_MPFR;
- else if ( seed_value_is_number(ctx, arg) )
+ else if (seed_value_is_number(ctx, arg))
return SEED_MPFR_DOUBLE;
- else if ( seed_value_is_string(ctx, arg) )
+ else if (seed_value_is_string(ctx, arg))
return SEED_MPFR_STRING;
else
return SEED_MPFR_UNKNOWN;
}
static SeedValue
-seed_mpfr_out_str (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_out_str(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
gsize n;
FILE* stream;
@@ -66,19 +67,19 @@ seed_mpfr_out_str (SeedContext ctx,
op = seed_object_get_private(this_object);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[3], exception);
- return seed_value_from_uint(ctx,
- mpfr_out_str(stream, base, n, op, rnd),
+ return seed_value_from_uint(ctx, mpfr_out_str(stream, base, n, op, rnd),
exception);
}
-/* no way to do real printf with varargs yet, this is a way to get fake printf */
+/* no way to do real printf with varargs yet, this is a way to get fake printf
+ */
static SeedValue
-seed_mpfr_print (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_print(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr op;
mpfr_rnd_t rnd;
@@ -92,18 +93,18 @@ seed_mpfr_print (SeedContext ctx,
sigdigits = seed_value_to_uint(ctx, args[1], exception);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[2], exception);
- ret = mpfr_printf("%*.*R*g", width, sigdigits, rnd, op );
+ ret = mpfr_printf("%*.*R*g", width, sigdigits, rnd, op);
return seed_value_from_int(ctx, ret, exception);
}
static SeedValue
-seed_mpfr_const_pi (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_const_pi(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -120,12 +121,12 @@ seed_mpfr_const_pi (SeedContext ctx,
}
static SeedValue
-seed_mpfr_const_euler (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_const_euler(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -142,12 +143,12 @@ seed_mpfr_const_euler (SeedContext ctx,
}
static SeedValue
-seed_mpfr_const_catalan (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_const_catalan(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -164,12 +165,12 @@ seed_mpfr_const_catalan (SeedContext ctx,
}
static SeedValue
-seed_mpfr_get_d (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_get_d(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -186,12 +187,12 @@ seed_mpfr_get_d (SeedContext ctx,
}
static SeedValue
-seed_mpfr_fits_ulong_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_fits_ulong_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -208,12 +209,12 @@ seed_mpfr_fits_ulong_p (SeedContext ctx,
}
static SeedValue
-seed_mpfr_fits_slong_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_fits_slong_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -230,12 +231,12 @@ seed_mpfr_fits_slong_p (SeedContext ctx,
}
static SeedValue
-seed_mpfr_fits_uint_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_fits_uint_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -252,12 +253,12 @@ seed_mpfr_fits_uint_p (SeedContext ctx,
}
static SeedValue
-seed_mpfr_fits_sint_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_fits_sint_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -274,12 +275,12 @@ seed_mpfr_fits_sint_p (SeedContext ctx,
}
static SeedValue
-seed_mpfr_fits_ushort_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_fits_ushort_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -296,12 +297,12 @@ seed_mpfr_fits_ushort_p (SeedContext ctx,
}
static SeedValue
-seed_mpfr_fits_sshort_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_fits_sshort_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -318,12 +319,12 @@ seed_mpfr_fits_sshort_p (SeedContext ctx,
}
static SeedValue
-seed_mpfr_fits_intmax_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_fits_intmax_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -340,12 +341,12 @@ seed_mpfr_fits_intmax_p (SeedContext ctx,
}
static SeedValue
-seed_mpfr_fits_uintmax_p (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_fits_uintmax_p(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -362,21 +363,21 @@ seed_mpfr_fits_uintmax_p (SeedContext ctx,
}
static SeedValue
-seed_mpfr_get_exp (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_mpfr_get_exp(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
mpfr_ptr ptr = seed_object_get_private(this_object);
return seed_value_from_mp_exp_t(ctx, mpfr_get_exp(ptr), exception);
}
static gboolean
-seed_mpfr_set_exp (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_mpfr_set_exp(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
mpfr_ptr ptr = seed_object_get_private(this_object);
mpfr_set_exp(ptr, seed_value_to_mp_exp_t(ctx, value, exception));
@@ -384,41 +385,43 @@ seed_mpfr_set_exp (SeedContext ctx,
}
static gboolean
-seed_mpfr_set_default_rounding_mode (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_mpfr_set_default_rounding_mode(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
- mpfr_set_default_rounding_mode(seed_value_to_mpfr_rnd_t(ctx, value, exception));
+ mpfr_set_default_rounding_mode(
+ seed_value_to_mpfr_rnd_t(ctx, value, exception));
return TRUE;
}
static SeedValue
-seed_mpfr_get_default_rounding_mode (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_mpfr_get_default_rounding_mode(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
- return seed_value_from_mpfr_rnd_t(ctx, mpfr_get_default_rounding_mode(), exception);
+ return seed_value_from_mpfr_rnd_t(ctx, mpfr_get_default_rounding_mode(),
+ exception);
}
static SeedValue
-seed_mpfr_get_prec (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+seed_mpfr_get_prec(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
mpfr_ptr ptr = seed_object_get_private(this_object);
return seed_value_from_mpfr_prec_t(ctx, mpfr_get_prec(ptr), exception);
}
static gboolean
-seed_mpfr_set_prec (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+seed_mpfr_set_prec(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
mpfr_ptr ptr = seed_object_get_private(this_object);
mpfr_set_prec(ptr, seed_value_to_mpfr_prec_t(ctx, value, exception));
@@ -426,23 +429,22 @@ seed_mpfr_set_prec (SeedContext ctx,
}
static void
-seed_mpfr_finalize (SeedObject obj)
+seed_mpfr_finalize(SeedObject obj)
{
mpfr_ptr ptr = seed_object_get_private(obj);
- if ( ptr )
- {
+ if (ptr) {
mpfr_clear(ptr);
- g_free( ptr );
+ g_free(ptr);
}
}
static SeedValue
-seed_mpfr_set (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_set(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop, op;
@@ -457,8 +459,7 @@ seed_mpfr_set (SeedContext ctx,
argt = seed_mpfr_arg_type(ctx, args[0], exception);
rnd = seed_value_to_mpfr_rnd_t(ctx, args[1], exception);
- switch ( argt )
- {
+ switch (argt) {
case SEED_MPFR_MPFR:
op = seed_object_get_private(args[0]);
ret = mpfr_set(rop, op, rnd);
@@ -470,7 +471,7 @@ seed_mpfr_set (SeedContext ctx,
case SEED_MPFR_STRING:
str = seed_value_to_string(ctx, args[0], exception);
ret = mpfr_set_str(rop, str, 10, rnd);
- g_free( str );
+ g_free(str);
break;
default:
TYPE_EXCEPTION("mpfr.set", "mpfr_t, double or string");
@@ -479,12 +480,13 @@ seed_mpfr_set (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-SeedValue seed_mpfr_set_inf (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_set_inf(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
gint sign;
@@ -493,12 +495,9 @@ SeedValue seed_mpfr_set_inf (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_number(ctx, args[0]) )
- {
+ if (seed_value_is_number(ctx, args[0])) {
sign = seed_value_to_int(ctx, args[0], exception);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.set_inf", "int");
}
@@ -507,12 +506,13 @@ SeedValue seed_mpfr_set_inf (SeedContext ctx,
return seed_make_null(ctx);
}
-SeedValue seed_mpfr_set_nan (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_set_nan(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop;
@@ -525,12 +525,13 @@ SeedValue seed_mpfr_set_nan (SeedContext ctx,
return seed_make_null(ctx);
}
-SeedValue seed_mpfr_swap (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_swap(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_ptr rop, op;
@@ -538,12 +539,9 @@ SeedValue seed_mpfr_swap (SeedContext ctx,
rop = seed_object_get_private(this_object);
- if ( seed_value_is_object_of_class(ctx, args[0], mpfr_class) )
- {
+ if (seed_value_is_object_of_class(ctx, args[0], mpfr_class)) {
op = seed_object_get_private(args[0]);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr.swap", "mpfr_t");
}
@@ -552,12 +550,13 @@ SeedValue seed_mpfr_swap (SeedContext ctx,
return seed_make_null(ctx);
}
-SeedValue seed_mpfr_can_round (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+SeedValue
+seed_mpfr_can_round(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd1, rnd2;
mpfr_ptr rop;
@@ -578,13 +577,14 @@ SeedValue seed_mpfr_can_round (SeedContext ctx,
return seed_value_from_boolean(ctx, ret, exception);
}
-/* init and set functions, using default precision, or optionally specifying it */
+/* init and set functions, using default precision, or optionally specifying it
+ */
SeedObject
seed_mpfr_construct_with_set(SeedContext ctx,
SeedObject constructor,
gsize argument_count,
const SeedValue args[],
- SeedException*exception)
+ SeedException* exception)
{
mpfr_prec_t prec;
mpfr_rnd_t rnd;
@@ -595,32 +595,30 @@ seed_mpfr_construct_with_set(SeedContext ctx,
seed_mpfr_t argt;
/* TODO: Precision range check */
- switch ( argument_count )
- {
+ switch (argument_count) {
case 2:
prec = mpfr_get_default_prec();
break;
case 3:
- if ( seed_value_is_number(ctx, args[1]) )
- {
+ if (seed_value_is_number(ctx, args[1])) {
prec = seed_value_to_mpfr_prec_t(ctx, args[1], exception);
- }
- else
- {
+ } else {
TYPE_EXCEPTION("mpfr constructor with set", "mpfr_prec_t");
}
break;
default:
- seed_make_exception (ctx, exception, "ArgumentError",
- "mpfr_t constructor.set expected 2 or 3 arguments got %zd", argument_count);
- return seed_make_undefined (ctx);
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "mpfr_t constructor.set expected 2 or 3 arguments got %zd",
+ argument_count);
+ return seed_make_undefined(ctx);
}
/* last argument is always rnd */
- if ( seed_value_is_number(ctx, args[argument_count - 1]) )
- rnd = seed_value_to_mpfr_rnd_t(ctx, args[argument_count - 1], exception);
- else
- {
+ if (seed_value_is_number(ctx, args[argument_count - 1]))
+ rnd
+ = seed_value_to_mpfr_rnd_t(ctx, args[argument_count - 1], exception);
+ else {
TYPE_EXCEPTION("mpfr constructor", "mpfr_rnd_t");
}
@@ -629,8 +627,7 @@ seed_mpfr_construct_with_set(SeedContext ctx,
argt = seed_mpfr_arg_type(ctx, args[0], exception);
- switch ( argt )
- {
+ switch (argt) {
case SEED_MPFR_MPFR:
obj = seed_value_to_object(ctx, args[0], exception);
op = seed_object_get_private(obj);
@@ -646,8 +643,8 @@ seed_mpfr_construct_with_set(SeedContext ctx,
mpfr_set_str(newmp, str, 10, rnd);
break;
default:
- mpfr_clear( newmp );
- g_free( newmp );
+ mpfr_clear(newmp);
+ g_free(newmp);
TYPE_EXCEPTION("mpfr_constructor", "mpfr_t, double or string");
}
@@ -660,41 +657,40 @@ seed_mpfr_construct(SeedContext ctx,
SeedObject constructor,
gsize argument_count,
const SeedValue args[],
- SeedException*exception)
+ SeedException* exception)
{
mpfr_prec_t prec;
mpfr_ptr newmp = (mpfr_ptr) g_malloc(sizeof(mpfr_t));
- switch (argument_count)
- {
+ switch (argument_count) {
case 0:
- mpfr_init(newmp); /* use default precision */
+ mpfr_init(newmp); /* use default precision */
break;
case 1:
- if ( seed_value_is_number(ctx, args[0]) )
- {
+ if (seed_value_is_number(ctx, args[0])) {
prec = seed_value_to_mpfr_prec_t(ctx, args[0], exception);
mpfr_init2(newmp, prec);
- }
- else
- {
- g_free( newmp );
+ } else {
+ g_free(newmp);
TYPE_EXCEPTION("mpfr constructor", "mpfr_prec_t");
}
break;
default:
- seed_make_exception (ctx, exception, "ArgumentError",
- "mpfr_t constructor expected 0 or 1 arguments got %zd", argument_count);
- return seed_make_undefined (ctx);
+ seed_make_exception(
+ ctx, exception, "ArgumentError",
+ "mpfr_t constructor expected 0 or 1 arguments got %zd",
+ argument_count);
+ return seed_make_undefined(ctx);
}
return seed_make_object(ctx, mpfr_class, newmp);
}
-SeedValue seed_mpfr_get_version (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+SeedValue
+seed_mpfr_get_version(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
const gchar* str;
SeedValue ret;
@@ -705,10 +701,11 @@ SeedValue seed_mpfr_get_version (SeedContext ctx,
return ret;
}
-SeedValue seed_mpfr_get_patches (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+SeedValue
+seed_mpfr_get_patches(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
const gchar* str;
SeedValue ret;
@@ -719,11 +716,12 @@ SeedValue seed_mpfr_get_patches (SeedContext ctx,
return ret;
}
-static gboolean seed_mpfr_set_emin (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException*exception)
+static gboolean
+seed_mpfr_set_emin(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
mp_exp_t exp;
gint ret;
@@ -734,11 +732,12 @@ static gboolean seed_mpfr_set_emin (SeedContext ctx,
return ret;
}
-static gboolean seed_mpfr_set_emax (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+static gboolean
+seed_mpfr_set_emax(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
mp_exp_t exp;
gint ret;
@@ -749,84 +748,92 @@ static gboolean seed_mpfr_set_emax (SeedContext ctx,
return ret;
}
-SeedValue seed_mpfr_get_emax (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+SeedValue
+seed_mpfr_get_emax(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
mp_exp_t exp;
exp = mpfr_get_emax();
return seed_value_from_mp_exp_t(ctx, exp, exception);
}
-SeedValue seed_mpfr_get_emin (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException* exception)
+SeedValue
+seed_mpfr_get_emin(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
mp_exp_t exp;
exp = mpfr_get_emin();
return seed_value_from_mp_exp_t(ctx, exp, exception);
}
-SeedValue seed_mpfr_get_emin_min (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException* exception)
+SeedValue
+seed_mpfr_get_emin_min(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
mp_exp_t exp;
exp = mpfr_get_emin_min();
return seed_value_from_mp_exp_t(ctx, exp, exception);
}
-SeedValue seed_mpfr_get_emin_max (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException* exception)
+SeedValue
+seed_mpfr_get_emin_max(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
mp_exp_t exp;
exp = mpfr_get_emin_max();
return seed_value_from_mp_exp_t(ctx, exp, exception);
}
-SeedValue seed_mpfr_get_emax_min (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException* exception)
+SeedValue
+seed_mpfr_get_emax_min(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
mp_exp_t exp;
exp = mpfr_get_emax_min();
return seed_value_from_mp_exp_t(ctx, exp, exception);
}
-SeedValue seed_mpfr_get_emax_max (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException* exception)
+SeedValue
+seed_mpfr_get_emax_max(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
mp_exp_t exp;
exp = mpfr_get_emax_max();
return seed_value_from_mp_exp_t(ctx, exp, exception);
}
-SeedValue seed_mpfr_underflow_p (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException* exception)
+SeedValue
+seed_mpfr_underflow_p(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
gint ret = mpfr_underflow_p();
return seed_value_from_int(ctx, ret, exception);
}
-gboolean seed_mpfr_set_underflow (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException * exception)
+gboolean
+seed_mpfr_set_underflow(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
gboolean setorclear;
setorclear = seed_value_to_boolean(ctx, value, exception);
- if ( setorclear )
+ if (setorclear)
mpfr_set_underflow();
else
mpfr_clear_underflow();
@@ -834,24 +841,26 @@ gboolean seed_mpfr_set_underflow (SeedContext ctx,
return setorclear;
}
-SeedValue seed_mpfr_overflow_p (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException* exception)
+SeedValue
+seed_mpfr_overflow_p(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
gint ret = mpfr_overflow_p();
return seed_value_from_int(ctx, ret, exception);
}
-gboolean seed_mpfr_set_overflow (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+gboolean
+seed_mpfr_set_overflow(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
gboolean setorclear;
setorclear = seed_value_to_boolean(ctx, value, exception);
- if ( setorclear )
+ if (setorclear)
mpfr_set_overflow();
else
mpfr_clear_overflow();
@@ -859,24 +868,26 @@ gboolean seed_mpfr_set_overflow (SeedContext ctx,
return setorclear;
}
-SeedValue seed_mpfr_nanflag_p (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException*exception)
+SeedValue
+seed_mpfr_nanflag_p(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
gint ret = mpfr_nanflag_p();
return seed_value_from_int(ctx, ret, exception);
}
-gboolean seed_mpfr_set_nanflag (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+gboolean
+seed_mpfr_set_nanflag(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
gboolean setorclear;
setorclear = seed_value_to_boolean(ctx, value, exception);
- if ( setorclear )
+ if (setorclear)
mpfr_set_nanflag();
else
mpfr_clear_nanflag();
@@ -884,24 +895,26 @@ gboolean seed_mpfr_set_nanflag (SeedContext ctx,
return setorclear;
}
-SeedValue seed_mpfr_inexflag_p (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException*exception)
+SeedValue
+seed_mpfr_inexflag_p(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
gint ret = mpfr_inexflag_p();
return seed_value_from_int(ctx, ret, exception);
}
-gboolean seed_mpfr_set_inexflag (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+gboolean
+seed_mpfr_set_inexflag(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
gboolean setorclear;
setorclear = seed_value_to_boolean(ctx, value, exception);
- if ( setorclear )
+ if (setorclear)
mpfr_set_inexflag();
else
mpfr_clear_inexflag();
@@ -909,24 +922,26 @@ gboolean seed_mpfr_set_inexflag (SeedContext ctx,
return setorclear;
}
-SeedValue seed_mpfr_erangeflag_p (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedException *exception)
+SeedValue
+seed_mpfr_erangeflag_p(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException* exception)
{
gint ret = mpfr_erangeflag_p();
return seed_value_from_int(ctx, ret, exception);
}
-gboolean seed_mpfr_set_erangeflag (SeedContext ctx,
- SeedObject this_object,
- SeedString property_name,
- SeedValue value,
- SeedException *exception)
+gboolean
+seed_mpfr_set_erangeflag(SeedContext ctx,
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException* exception)
{
gboolean setorclear;
setorclear = seed_value_to_boolean(ctx, value, exception);
- if ( setorclear )
+ if (setorclear)
mpfr_set_erangeflag();
else
mpfr_clear_erangeflag();
@@ -935,12 +950,12 @@ gboolean seed_mpfr_set_erangeflag (SeedContext ctx,
}
static SeedValue
-seed_mpfr_subnormalize (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_subnormalize(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -958,12 +973,12 @@ seed_mpfr_subnormalize (SeedContext ctx,
}
static SeedValue
-seed_mpfr_check_range (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue args[],
- SeedException *exception)
+seed_mpfr_check_range(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue args[],
+ SeedException* exception)
{
mpfr_rnd_t rnd;
mpfr_ptr rop;
@@ -980,158 +995,167 @@ seed_mpfr_check_range (SeedContext ctx,
return seed_value_from_int(ctx, ret, exception);
}
-seed_static_value mpfr_ns_values[] =
-{
- {"default_rounding_mode", seed_mpfr_get_default_rounding_mode, seed_mpfr_set_default_rounding_mode,
SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"emax", seed_mpfr_get_emax, seed_mpfr_set_emax, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"emin", seed_mpfr_get_emin, seed_mpfr_set_emin, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"emin_min", seed_mpfr_get_emin_min, NULL, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"emin_max", seed_mpfr_get_emin_max, NULL, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"emax_min", seed_mpfr_get_emax_min, NULL, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"emax_max", seed_mpfr_get_emax_max, NULL, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"underflow", seed_mpfr_underflow_p, seed_mpfr_set_underflow, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"overflow", seed_mpfr_overflow_p, seed_mpfr_set_overflow, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"nanflag", seed_mpfr_nanflag_p, seed_mpfr_set_nanflag, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"inexflag", seed_mpfr_inexflag_p, seed_mpfr_set_inexflag, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"erangeflag", seed_mpfr_erangeflag_p, seed_mpfr_set_erangeflag, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"version", seed_mpfr_get_version, NULL, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"patches", seed_mpfr_get_patches, NULL, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {NULL, NULL, NULL, 0}
-};
-
-seed_static_function mpfr_ns_funcs[] =
-{
- {"free_cache", seed_mpfr_free_cache, 0},
- {"clear_flags", seed_mpfr_clear_flags, 0},
- {NULL, NULL, 0}
-};
-
-seed_static_function mpfr_funcs[] =
-{
- {"add", seed_mpfr_add, 0},
- {"sub", seed_mpfr_sub, 0},
- {"mul", seed_mpfr_mul, 0},
- {"div", seed_mpfr_div, 0},
- {"sqrt", seed_mpfr_sqrt, 0},
- {"sqr", seed_mpfr_sqr, 0},
- {"pow", seed_mpfr_pow, 0},
- {"mul_2si", seed_mpfr_mul_2si, 0},
- {"div_2si", seed_mpfr_div_2si, 0},
- {"root", seed_mpfr_root, 0},
- {"rec_sqrt", seed_mpfr_rec_sqrt, 0},
- {"cbrt", seed_mpfr_cbrt, 0},
- {"neg", seed_mpfr_neg, 0},
- {"abs", seed_mpfr_abs, 0},
- {"rint", seed_mpfr_rint, 0},
- {"ceil", seed_mpfr_ceil, 0},
- {"floor", seed_mpfr_floor, 0},
- {"round", seed_mpfr_round, 0},
- {"trunc", seed_mpfr_trunc, 0},
- {"prec_round", seed_mpfr_prec_round, 0},
- {"can_round", seed_mpfr_can_round, 0},
- {"signbit", seed_mpfr_signbit, 0},
- {"setsign", seed_mpfr_setsign, 0},
- {"copysign", seed_mpfr_copysign, 0},
- {"nexttoward", seed_mpfr_nexttoward, 0},
- {"nextabove", seed_mpfr_nextabove, 0},
- {"nextbelow", seed_mpfr_nextbelow, 0},
- {"rint_ceil", seed_mpfr_rint_ceil, 0},
- {"rint_floor", seed_mpfr_rint_floor, 0},
- {"rint_round", seed_mpfr_rint_round, 0},
- {"rint_trunc", seed_mpfr_rint_trunc, 0},
- {"min", seed_mpfr_min, 0},
- {"max", seed_mpfr_max, 0},
- {"frac", seed_mpfr_frac, 0},
- {"fmod", seed_mpfr_fmod, 0},
- {"remainder", seed_mpfr_remainder, 0},
- {"integer_p", seed_mpfr_integer_p, 0},
- {"dim", seed_mpfr_dim, 0},
- {"sin", seed_mpfr_sin, 0},
- {"cos", seed_mpfr_cos, 0},
- {"tan", seed_mpfr_tan, 0},
- {"asin", seed_mpfr_asin, 0},
- {"acos", seed_mpfr_acos, 0},
- {"atan", seed_mpfr_atan, 0},
- {"csc", seed_mpfr_csc, 0},
- {"sec", seed_mpfr_sec, 0},
- {"cot", seed_mpfr_cot, 0},
- {"log", seed_mpfr_log, 0},
- {"log2", seed_mpfr_log2, 0},
- {"log10", seed_mpfr_log10, 0},
- {"sinh", seed_mpfr_sinh, 0},
- {"cosh", seed_mpfr_cosh, 0},
- {"tanh", seed_mpfr_tanh, 0},
- {"csch", seed_mpfr_csch, 0},
- {"sech", seed_mpfr_sech, 0},
- {"coth", seed_mpfr_coth, 0},
- {"asinh", seed_mpfr_asinh, 0},
- {"acosh", seed_mpfr_acosh, 0},
- {"atanh", seed_mpfr_atanh, 0},
- {"log1p", seed_mpfr_log1p, 0},
- {"expm1", seed_mpfr_expm1, 0},
- {"li2", seed_mpfr_li2, 0},
- {"gamma", seed_mpfr_gamma, 0},
- {"lngamma", seed_mpfr_lngamma, 0},
- {"zeta", seed_mpfr_zeta, 0},
- {"erf", seed_mpfr_erf, 0},
- {"erfc", seed_mpfr_erfc, 0},
- {"j0", seed_mpfr_j0, 0},
- {"j1", seed_mpfr_j1, 0},
- {"jn", seed_mpfr_jn, 0},
- {"y0", seed_mpfr_y0, 0},
- {"y1", seed_mpfr_y1, 0},
- {"yn", seed_mpfr_yn, 0},
- {"fma", seed_mpfr_fma, 0},
- {"fms", seed_mpfr_fms, 0},
- {"agm", seed_mpfr_agm, 0},
- {"hypot", seed_mpfr_hypot, 0},
- {"set", seed_mpfr_set, 0},
- {"set_inf", seed_mpfr_set_inf, 0},
- {"set_nan", seed_mpfr_set_nan, 0},
- {"swap", seed_mpfr_swap, 0},
- {"cmp", seed_mpfr_cmp, 0},
- {"cmpabs", seed_mpfr_cmpabs, 0},
- {"cmp_si_2exp", seed_mpfr_cmp_si_2exp, 0},
- {"greater_p", seed_mpfr_greater_p, 0},
- {"greaterequal_p", seed_mpfr_greaterequal_p, 0},
- {"less_p", seed_mpfr_less_p, 0},
- {"lessequal_p", seed_mpfr_lessequal_p, 0},
- {"lessgreater_p", seed_mpfr_lessgreater_p, 0},
- {"equal_p", seed_mpfr_equal_p, 0},
- {"unordered_p", seed_mpfr_unordered_p, 0},
- {"nan_p", seed_mpfr_nan_p, 0},
- {"inf_p", seed_mpfr_inf_p, 0},
- {"number_p", seed_mpfr_number_p, 0},
- {"zero_p", seed_mpfr_zero_p, 0},
- {"sgn", seed_mpfr_sgn, 0},
- {"get_d", seed_mpfr_get_d, 0},
- {"fits_ulong_p", seed_mpfr_fits_ulong_p, 0},
- {"fits_slong_p", seed_mpfr_fits_slong_p, 0},
- {"fits_uint_p", seed_mpfr_fits_uint_p, 0},
- {"fits_sint_p", seed_mpfr_fits_sint_p, 0},
- {"fits_ushort_p", seed_mpfr_fits_ushort_p, 0},
- {"fits_sshort_p", seed_mpfr_fits_sshort_p, 0},
- {"fits_intmax_p", seed_mpfr_fits_intmax_p, 0},
- {"fits_uintmax_p", seed_mpfr_fits_uintmax_p, 0},
- {"out_str", seed_mpfr_out_str, 0},
- {"print", seed_mpfr_print, 0},
- {"pi", seed_mpfr_const_pi, 0},
- {"euler", seed_mpfr_const_euler, 0},
- {"catalan", seed_mpfr_const_catalan, 0},
- {"subnormalize", seed_mpfr_subnormalize, 0},
- {"check_range", seed_mpfr_check_range, 0},
- {NULL, NULL, 0}
-};
-
-seed_static_value mpfr_values[] =
-{
- {"prec", seed_mpfr_get_prec, seed_mpfr_set_prec, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {"exp", seed_mpfr_get_exp, seed_mpfr_set_exp, SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
- {NULL, NULL, NULL, 0}
-};
+seed_static_value mpfr_ns_values[]
+ = { { "default_rounding_mode", seed_mpfr_get_default_rounding_mode,
+ seed_mpfr_set_default_rounding_mode,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "emax", seed_mpfr_get_emax, seed_mpfr_set_emax,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "emin", seed_mpfr_get_emin, seed_mpfr_set_emin,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "emin_min", seed_mpfr_get_emin_min, NULL,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "emin_max", seed_mpfr_get_emin_max, NULL,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "emax_min", seed_mpfr_get_emax_min, NULL,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "emax_max", seed_mpfr_get_emax_max, NULL,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "underflow", seed_mpfr_underflow_p, seed_mpfr_set_underflow,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "overflow", seed_mpfr_overflow_p, seed_mpfr_set_overflow,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "nanflag", seed_mpfr_nanflag_p, seed_mpfr_set_nanflag,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "inexflag", seed_mpfr_inexflag_p, seed_mpfr_set_inexflag,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "erangeflag", seed_mpfr_erangeflag_p, seed_mpfr_set_erangeflag,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "version", seed_mpfr_get_version, NULL,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "patches", seed_mpfr_get_patches, NULL,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { NULL, NULL, NULL, 0 } };
+
+seed_static_function mpfr_ns_funcs[]
+ = { { "free_cache", seed_mpfr_free_cache, 0 },
+ { "clear_flags", seed_mpfr_clear_flags, 0 },
+ { NULL, NULL, 0 } };
+
+seed_static_function mpfr_funcs[]
+ = { { "add", seed_mpfr_add, 0 },
+ { "sub", seed_mpfr_sub, 0 },
+ { "mul", seed_mpfr_mul, 0 },
+ { "div", seed_mpfr_div, 0 },
+ { "sqrt", seed_mpfr_sqrt, 0 },
+ { "sqr", seed_mpfr_sqr, 0 },
+ { "pow", seed_mpfr_pow, 0 },
+ { "mul_2si", seed_mpfr_mul_2si, 0 },
+ { "div_2si", seed_mpfr_div_2si, 0 },
+ { "root", seed_mpfr_root, 0 },
+ { "rec_sqrt", seed_mpfr_rec_sqrt, 0 },
+ { "cbrt", seed_mpfr_cbrt, 0 },
+ { "neg", seed_mpfr_neg, 0 },
+ { "abs", seed_mpfr_abs, 0 },
+ { "rint", seed_mpfr_rint, 0 },
+ { "ceil", seed_mpfr_ceil, 0 },
+ { "floor", seed_mpfr_floor, 0 },
+ { "round", seed_mpfr_round, 0 },
+ { "trunc", seed_mpfr_trunc, 0 },
+ { "prec_round", seed_mpfr_prec_round, 0 },
+ { "can_round", seed_mpfr_can_round, 0 },
+ { "signbit", seed_mpfr_signbit, 0 },
+ { "setsign", seed_mpfr_setsign, 0 },
+ { "copysign", seed_mpfr_copysign, 0 },
+ { "nexttoward", seed_mpfr_nexttoward, 0 },
+ { "nextabove", seed_mpfr_nextabove, 0 },
+ { "nextbelow", seed_mpfr_nextbelow, 0 },
+ { "rint_ceil", seed_mpfr_rint_ceil, 0 },
+ { "rint_floor", seed_mpfr_rint_floor, 0 },
+ { "rint_round", seed_mpfr_rint_round, 0 },
+ { "rint_trunc", seed_mpfr_rint_trunc, 0 },
+ { "min", seed_mpfr_min, 0 },
+ { "max", seed_mpfr_max, 0 },
+ { "frac", seed_mpfr_frac, 0 },
+ { "fmod", seed_mpfr_fmod, 0 },
+ { "remainder", seed_mpfr_remainder, 0 },
+ { "integer_p", seed_mpfr_integer_p, 0 },
+ { "dim", seed_mpfr_dim, 0 },
+ { "sin", seed_mpfr_sin, 0 },
+ { "cos", seed_mpfr_cos, 0 },
+ { "tan", seed_mpfr_tan, 0 },
+ { "asin", seed_mpfr_asin, 0 },
+ { "acos", seed_mpfr_acos, 0 },
+ { "atan", seed_mpfr_atan, 0 },
+ { "csc", seed_mpfr_csc, 0 },
+ { "sec", seed_mpfr_sec, 0 },
+ { "cot", seed_mpfr_cot, 0 },
+ { "log", seed_mpfr_log, 0 },
+ { "log2", seed_mpfr_log2, 0 },
+ { "log10", seed_mpfr_log10, 0 },
+ { "sinh", seed_mpfr_sinh, 0 },
+ { "cosh", seed_mpfr_cosh, 0 },
+ { "tanh", seed_mpfr_tanh, 0 },
+ { "csch", seed_mpfr_csch, 0 },
+ { "sech", seed_mpfr_sech, 0 },
+ { "coth", seed_mpfr_coth, 0 },
+ { "asinh", seed_mpfr_asinh, 0 },
+ { "acosh", seed_mpfr_acosh, 0 },
+ { "atanh", seed_mpfr_atanh, 0 },
+ { "log1p", seed_mpfr_log1p, 0 },
+ { "expm1", seed_mpfr_expm1, 0 },
+ { "li2", seed_mpfr_li2, 0 },
+ { "gamma", seed_mpfr_gamma, 0 },
+ { "lngamma", seed_mpfr_lngamma, 0 },
+ { "zeta", seed_mpfr_zeta, 0 },
+ { "erf", seed_mpfr_erf, 0 },
+ { "erfc", seed_mpfr_erfc, 0 },
+ { "j0", seed_mpfr_j0, 0 },
+ { "j1", seed_mpfr_j1, 0 },
+ { "jn", seed_mpfr_jn, 0 },
+ { "y0", seed_mpfr_y0, 0 },
+ { "y1", seed_mpfr_y1, 0 },
+ { "yn", seed_mpfr_yn, 0 },
+ { "fma", seed_mpfr_fma, 0 },
+ { "fms", seed_mpfr_fms, 0 },
+ { "agm", seed_mpfr_agm, 0 },
+ { "hypot", seed_mpfr_hypot, 0 },
+ { "set", seed_mpfr_set, 0 },
+ { "set_inf", seed_mpfr_set_inf, 0 },
+ { "set_nan", seed_mpfr_set_nan, 0 },
+ { "swap", seed_mpfr_swap, 0 },
+ { "cmp", seed_mpfr_cmp, 0 },
+ { "cmpabs", seed_mpfr_cmpabs, 0 },
+ { "cmp_si_2exp", seed_mpfr_cmp_si_2exp, 0 },
+ { "greater_p", seed_mpfr_greater_p, 0 },
+ { "greaterequal_p", seed_mpfr_greaterequal_p, 0 },
+ { "less_p", seed_mpfr_less_p, 0 },
+ { "lessequal_p", seed_mpfr_lessequal_p, 0 },
+ { "lessgreater_p", seed_mpfr_lessgreater_p, 0 },
+ { "equal_p", seed_mpfr_equal_p, 0 },
+ { "unordered_p", seed_mpfr_unordered_p, 0 },
+ { "nan_p", seed_mpfr_nan_p, 0 },
+ { "inf_p", seed_mpfr_inf_p, 0 },
+ { "number_p", seed_mpfr_number_p, 0 },
+ { "zero_p", seed_mpfr_zero_p, 0 },
+ { "sgn", seed_mpfr_sgn, 0 },
+ { "get_d", seed_mpfr_get_d, 0 },
+ { "fits_ulong_p", seed_mpfr_fits_ulong_p, 0 },
+ { "fits_slong_p", seed_mpfr_fits_slong_p, 0 },
+ { "fits_uint_p", seed_mpfr_fits_uint_p, 0 },
+ { "fits_sint_p", seed_mpfr_fits_sint_p, 0 },
+ { "fits_ushort_p", seed_mpfr_fits_ushort_p, 0 },
+ { "fits_sshort_p", seed_mpfr_fits_sshort_p, 0 },
+ { "fits_intmax_p", seed_mpfr_fits_intmax_p, 0 },
+ { "fits_uintmax_p", seed_mpfr_fits_uintmax_p, 0 },
+ { "out_str", seed_mpfr_out_str, 0 },
+ { "print", seed_mpfr_print, 0 },
+ { "pi", seed_mpfr_const_pi, 0 },
+ { "euler", seed_mpfr_const_euler, 0 },
+ { "catalan", seed_mpfr_const_catalan, 0 },
+ { "subnormalize", seed_mpfr_subnormalize, 0 },
+ { "check_range", seed_mpfr_check_range, 0 },
+ { NULL, NULL, 0 } };
+
+seed_static_value mpfr_values[]
+ = { { "prec", seed_mpfr_get_prec, seed_mpfr_set_prec,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { "exp", seed_mpfr_get_exp, seed_mpfr_set_exp,
+ SEED_PROPERTY_ATTRIBUTE_DONT_DELETE },
+ { NULL, NULL, NULL, 0 } };
SeedObject
-seed_module_init(SeedEngine *local_eng)
+seed_module_init(SeedEngine* local_eng)
{
SeedGlobalContext ctx = local_eng->context;
seed_class_definition mpfr_def = seed_empty_class;
@@ -1154,11 +1178,14 @@ seed_module_init(SeedEngine *local_eng)
mpfr_class = seed_create_class(&mpfr_def);
- mpfr_constructor = seed_make_constructor(ctx, mpfr_class, seed_mpfr_construct);
- mpfr_constructor_set = seed_make_constructor(ctx, mpfr_class, seed_mpfr_construct_with_set);
+ mpfr_constructor
+ = seed_make_constructor(ctx, mpfr_class, seed_mpfr_construct);
+ mpfr_constructor_set
+ = seed_make_constructor(ctx, mpfr_class, seed_mpfr_construct_with_set);
seed_object_set_property(ctx, ns_ref, "mpfr_t", mpfr_constructor);
- seed_object_set_property(ctx, mpfr_constructor, "set", mpfr_constructor_set);
+ seed_object_set_property(ctx, mpfr_constructor, "set",
+ mpfr_constructor_set);
/* Setup enums */
DEFINE_ENUM_MEMBER(ns_ref, GMP_RNDN);
@@ -1168,9 +1195,11 @@ seed_module_init(SeedEngine *local_eng)
DEFINE_ENUM_MEMBER_EXT(ns_ref, "VERSION_MAJOR", MPFR_VERSION_MAJOR);
DEFINE_ENUM_MEMBER_EXT(ns_ref, "VERSION_MINOR", MPFR_VERSION_MINOR);
- DEFINE_ENUM_MEMBER_EXT(ns_ref, "VERSION_PATCHLEVEL", MPFR_VERSION_PATCHLEVEL);
+ DEFINE_ENUM_MEMBER_EXT(ns_ref, "VERSION_PATCHLEVEL",
+ MPFR_VERSION_PATCHLEVEL);
seed_object_set_property(ctx, ns_ref, "VERSION_STRING",
- seed_value_from_string(ctx, MPFR_VERSION_STRING, NULL));
+ seed_value_from_string(ctx, MPFR_VERSION_STRING,
+ NULL));
DEFINE_ENUM_MEMBER_EXT(ns_ref, "PREC_MIN", MPFR_PREC_MIN);
DEFINE_ENUM_MEMBER_EXT(ns_ref, "PREC_MAX", MPFR_PREC_MAX);
@@ -1185,4 +1214,3 @@ seed_module_init(SeedEngine *local_eng)
return ns_ref;
}
-
diff --git a/modules/mpfr/seed-mpfr.h b/modules/mpfr/seed-mpfr.h
index ee3fa0b..a7ad1a4 100644
--- a/modules/mpfr/seed-mpfr.h
+++ b/modules/mpfr/seed-mpfr.h
@@ -4,26 +4,27 @@
#include <seed-module.h>
#include <seed.h>
-#define TYPE_EXCEPTION(name, wanted) \
- seed_make_exception(ctx, exception, "TypeError", name " expected " wanted ); \
+#define TYPE_EXCEPTION(name, wanted) \
+ seed_make_exception(ctx, exception, "TypeError", \
+ name " expected " wanted); \
return seed_make_undefined(ctx);
#if 0 /* TODO: Make this work */
/* kind of stupid hack */
#if MPFR_PREC_MAX == G_MAXLONG
- #define seed_value_to_mpfr_prec_t(a, b, c) seed_value_to_ulong(a, b, c)
- #define seed_value_from_mpfr_prec_t(a, b, c) seed_value_from_ulong(a, b, c)
+#define seed_value_to_mpfr_prec_t(a, b, c) seed_value_to_ulong(a, b, c)
+#define seed_value_from_mpfr_prec_t(a, b, c) seed_value_from_ulong(a, b, c)
#elif MPFR_PREC_MAX == G_MAXUSHORT
- #define seed_value_to_mpfr_prec_t(a, b, c) seed_value_to_ushort(a, b, c)
- #define seed_value_from_mpfr_prec_t(a, b, c) seed_value_from_ushort(a, b, c)
+#define seed_value_to_mpfr_prec_t(a, b, c) seed_value_to_ushort(a, b, c)
+#define seed_value_from_mpfr_prec_t(a, b, c) seed_value_from_ushort(a, b, c)
#elif MPFR_PREC_MAX == G_MAXINT
- #define seed_value_to_mpfr_prec_t(a, b, c) seed_value_to_int(a, b, c)
- #define seed_value_from_mpfr_prec_t(a, b, c) seed_value_from_int(a, b, c)
+#define seed_value_to_mpfr_prec_t(a, b, c) seed_value_to_int(a, b, c)
+#define seed_value_from_mpfr_prec_t(a, b, c) seed_value_from_int(a, b, c)
#elif MPFR_PREC_MAX == G_MAXUINT64
- #define seed_value_to_mpfr_prec_t(a, b, c) seed_value_to_uint64(a, b, c)
- #define seed_value_from_mpfr_prec_t(a, b, c) seed_value_from_uint64(a, b, c)
+#define seed_value_to_mpfr_prec_t(a, b, c) seed_value_to_uint64(a, b, c)
+#define seed_value_from_mpfr_prec_t(a, b, c) seed_value_from_uint64(a, b, c)
#else
- #error "Wrong mpfr_prec_t size somehow?"
+#error "Wrong mpfr_prec_t size somehow?"
#endif
#endif
@@ -37,15 +38,14 @@
#define seed_value_from_mp_exp_t(a, b, c) seed_value_from_ulong(a, b, c)
#define seed_value_to_mp_exp_t(a, b, c) seed_value_to_ulong(a, b, c)
-
-#define DEF_SEED_MPFR_FUNC(name) SeedValue name( SeedContext,SeedObject,\
-SeedObject, gsize, const SeedValue[], SeedException*)
+#define DEF_SEED_MPFR_FUNC(name) \
+ SeedValue name(SeedContext, SeedObject, SeedObject, gsize, \
+ const SeedValue[], SeedException*)
extern SeedObject ns_ref;
extern SeedClass mpfr_class;
-typedef enum _seed_mpfr_t
-{
+typedef enum _seed_mpfr_t {
SEED_MPFR_UNKNOWN = 0,
SEED_MPFR_MPFR = 1 << 1,
SEED_MPFR_DOUBLE = 1 << 2,
@@ -170,6 +170,4 @@ DEF_SEED_MPFR_FUNC(seed_mpfr_hypot);
DEF_SEED_MPFR_FUNC(seed_mpfr_free_cache);
DEF_SEED_MPFR_FUNC(seed_mpfr_clear_flags);
-
-#endif /* _SEED_MFPR_H_ */
-
+#endif /* _SEED_MFPR_H_ */
diff --git a/modules/multiprocessing/seed-multiprocessing.c b/modules/multiprocessing/seed-multiprocessing.c
index 38d0655..4cce55c 100644
--- a/modules/multiprocessing/seed-multiprocessing.c
+++ b/modules/multiprocessing/seed-multiprocessing.c
@@ -22,191 +22,194 @@
#include <unistd.h>
#include <stdio.h>
-SeedEngine *eng;
+SeedEngine* eng;
SeedObject namespace_ref;
SeedClass pipe_class;
-typedef struct _pipe_priv {
- GIOChannel *read;
- GIOChannel *write;
+typedef struct _pipe_priv
+{
+ GIOChannel* read;
+ GIOChannel* write;
} pipe_priv;
-void pipe_finalize(SeedObject pipeobj)
+void
+pipe_finalize(SeedObject pipeobj)
{
- pipe_priv *priv = seed_object_get_private(pipeobj);
- g_io_channel_unref(priv->read);
- g_io_channel_unref(priv->write);
- g_free(priv);
+ pipe_priv* priv = seed_object_get_private(pipeobj);
+ g_io_channel_unref(priv->read);
+ g_io_channel_unref(priv->write);
+ g_free(priv);
}
-SeedObject seed_construct_pipe(SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+SeedObject
+seed_construct_pipe(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedObject jsone, jstwo, jsret;
- int fd1[2], fd2[2];
- pipe_priv *priv_one, *priv_two;
-
- CHECK_ARG_COUNT("multiprocessing.pipe constructor", 0);
-
- if (pipe(fd1) < 0)
- {
- perror("Pipe failed. Make me a javascript exception");
- return seed_make_null(ctx);
+ SeedObject jsone, jstwo, jsret;
+ int fd1[2], fd2[2];
+ pipe_priv *priv_one, *priv_two;
+
+ CHECK_ARG_COUNT("multiprocessing.pipe constructor", 0);
+
+ if (pipe(fd1) < 0) {
+ perror("Pipe failed. Make me a javascript exception");
+ return seed_make_null(ctx);
}
- if (pipe(fd2) < 0)
- {
- perror("Pipe failed. Make me a javascript exception");
- return seed_make_null(ctx);
+ if (pipe(fd2) < 0) {
+ perror("Pipe failed. Make me a javascript exception");
+ return seed_make_null(ctx);
}
- priv_one = g_new0(pipe_priv, 1);
- priv_two = g_new0(pipe_priv, 1);
+ priv_one = g_new0(pipe_priv, 1);
+ priv_two = g_new0(pipe_priv, 1);
- priv_one->read = g_io_channel_unix_new(fd1[0]);
- priv_one->write = g_io_channel_unix_new(fd2[1]);
- priv_two->read = g_io_channel_unix_new(fd2[0]);
- priv_two->write = g_io_channel_unix_new(fd1[1]);
+ priv_one->read = g_io_channel_unix_new(fd1[0]);
+ priv_one->write = g_io_channel_unix_new(fd2[1]);
+ priv_two->read = g_io_channel_unix_new(fd2[0]);
+ priv_two->write = g_io_channel_unix_new(fd1[1]);
- g_io_channel_set_close_on_unref(priv_one->read, TRUE);
- g_io_channel_set_close_on_unref(priv_one->write, TRUE);
- g_io_channel_set_close_on_unref(priv_two->read, TRUE);
- g_io_channel_set_close_on_unref(priv_two->write, TRUE);
+ g_io_channel_set_close_on_unref(priv_one->read, TRUE);
+ g_io_channel_set_close_on_unref(priv_one->write, TRUE);
+ g_io_channel_set_close_on_unref(priv_two->read, TRUE);
+ g_io_channel_set_close_on_unref(priv_two->write, TRUE);
- jsret = seed_make_object(ctx, 0, 0);
- jsone = seed_make_object(ctx, pipe_class, priv_one);
- jstwo = seed_make_object(ctx, pipe_class, priv_two);
+ jsret = seed_make_object(ctx, 0, 0);
+ jsone = seed_make_object(ctx, pipe_class, priv_one);
+ jstwo = seed_make_object(ctx, pipe_class, priv_two);
- seed_object_set_property_at_index(ctx, jsret, 0, jsone, exception);
- seed_object_set_property_at_index(ctx, jsret, 1, jstwo, exception);
+ seed_object_set_property_at_index(ctx, jsret, 0, jsone, exception);
+ seed_object_set_property_at_index(ctx, jsret, 1, jstwo, exception);
- return jsret;
+ return jsret;
}
-#define GET_CHANNEL pipe_priv * priv = \
- seed_object_get_private(this_object)
+#define GET_CHANNEL pipe_priv* priv = seed_object_get_private(this_object)
-SeedValue seed_pipe_read(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+SeedValue
+seed_pipe_read(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue ret;
- gchar *read;
- GET_CHANNEL;
-
- CHECK_ARG_COUNT("multiprocessing.pipe.read", 0);
+ SeedValue ret;
+ gchar* read;
+ GET_CHANNEL;
+
+ CHECK_ARG_COUNT("multiprocessing.pipe.read", 0);
- g_io_channel_read_line(priv->read, &read, 0, 0, 0);
- ret = seed_value_from_string(ctx, read, exception);
- g_free(read);
+ g_io_channel_read_line(priv->read, &read, 0, 0, 0);
+ ret = seed_value_from_string(ctx, read, exception);
+ g_free(read);
- return ret;
+ return ret;
}
-typedef struct _marshal_privates {
- SeedObject function;
- SeedObject source;
- SeedValue user_data;
+typedef struct _marshal_privates
+{
+ SeedObject function;
+ SeedObject source;
+ SeedValue user_data;
} marshal_privates;
-static gboolean gio_marshal_func(GIOChannel * source,
- GIOCondition condition, gpointer data)
+static gboolean
+gio_marshal_func(GIOChannel* source, GIOCondition condition, gpointer data)
{
- SeedGlobalContext ctx = seed_context_create(eng->group, 0);
- SeedValue jscondition = seed_value_from_long(ctx, (glong) condition, 0);
- SeedValue args[3], ret;
- marshal_privates *priv = (marshal_privates *) data;
- gboolean bret;
+ SeedGlobalContext ctx = seed_context_create(eng->group, 0);
+ SeedValue jscondition = seed_value_from_long(ctx, (glong) condition, 0);
+ SeedValue args[3], ret;
+ marshal_privates* priv = (marshal_privates*) data;
+ gboolean bret;
- args[0] = priv->source;
- args[1] = jscondition;
- args[2] = priv->user_data;
+ args[0] = priv->source;
+ args[1] = jscondition;
+ args[2] = priv->user_data;
- ret = seed_object_call(ctx, priv->function, 0, 3, args, 0);
+ ret = seed_object_call(ctx, priv->function, 0, 3, args, 0);
- bret = seed_value_to_boolean(ctx, ret, 0);
- seed_context_unref(ctx);
+ bret = seed_value_to_boolean(ctx, ret, 0);
+ seed_context_unref(ctx);
- if (!bret)
- g_free(priv);
+ if (!bret)
+ g_free(priv);
- return bret;
+ return bret;
}
-SeedValue seed_pipe_write(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+SeedValue
+seed_pipe_write(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gchar *data;
- gsize written;
- gchar eol = '\n';
- GET_CHANNEL;
-
- CHECK_ARG_COUNT("multiprocessing.pipe.write", 1);
-
- data = seed_value_to_string(ctx, arguments[0], exception);
- g_io_channel_write_chars(priv->write, data, -1, &written, 0);
- g_io_channel_write_chars(priv->write, &eol, 1, 0, 0);
- g_io_channel_flush(priv->write, 0);
-
- return seed_value_from_int(ctx, written, exception);
+ gchar* data;
+ gsize written;
+ gchar eol = '\n';
+ GET_CHANNEL;
+
+ CHECK_ARG_COUNT("multiprocessing.pipe.write", 1);
+
+ data = seed_value_to_string(ctx, arguments[0], exception);
+ g_io_channel_write_chars(priv->write, data, -1, &written, 0);
+ g_io_channel_write_chars(priv->write, &eol, 1, 0, 0);
+ g_io_channel_flush(priv->write, 0);
+
+ return seed_value_from_int(ctx, written, exception);
}
-SeedValue seed_pipe_add_watch(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+SeedValue
+seed_pipe_add_watch(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- GET_CHANNEL;
-
- marshal_privates *mpriv = g_malloc0(sizeof(marshal_privates));
- glong condition = seed_value_to_long(ctx, arguments[0], exception);
+ GET_CHANNEL;
+
+ marshal_privates* mpriv = g_malloc0(sizeof(marshal_privates));
+ glong condition = seed_value_to_long(ctx, arguments[0], exception);
- mpriv->function = arguments[1];
- mpriv->source = this_object;
- mpriv->user_data = argument_count == 3 ? arguments[2] : seed_make_null(ctx);
+ mpriv->function = arguments[1];
+ mpriv->source = this_object;
+ mpriv->user_data = argument_count == 3 ? arguments[2] : seed_make_null(ctx);
- g_io_add_watch(priv->read, condition, gio_marshal_func, mpriv);
+ g_io_add_watch(priv->read, condition, gio_marshal_func, mpriv);
- return seed_value_from_boolean(ctx, TRUE, exception);
+ return seed_value_from_boolean(ctx, TRUE, exception);
}
-seed_static_function pipe_funcs[] = {
- {"read", seed_pipe_read, 0},
- {"write", seed_pipe_write, 0},
- {"add_watch", seed_pipe_add_watch, 0},
- {NULL, NULL, 0}
-};
+seed_static_function pipe_funcs[] = { { "read", seed_pipe_read, 0 },
+ { "write", seed_pipe_write, 0 },
+ { "add_watch", seed_pipe_add_watch, 0 },
+ { NULL, NULL, 0 } };
SeedObject
-seed_module_init(SeedEngine * local_eng)
+seed_module_init(SeedEngine* local_eng)
{
- SeedObject pipe_constructor;
- seed_class_definition pipe_class_def = seed_empty_class;
- eng = local_eng;
+ SeedObject pipe_constructor;
+ seed_class_definition pipe_class_def = seed_empty_class;
+ eng = local_eng;
- namespace_ref = seed_make_object(eng->context, 0, 0);
+ namespace_ref = seed_make_object(eng->context, 0, 0);
- pipe_class_def.class_name = "Pipe";
- pipe_class_def.static_functions = pipe_funcs;
- pipe_class_def.finalize = pipe_finalize;
+ pipe_class_def.class_name = "Pipe";
+ pipe_class_def.static_functions = pipe_funcs;
+ pipe_class_def.finalize = pipe_finalize;
- pipe_class = seed_create_class(&pipe_class_def);
+ pipe_class = seed_create_class(&pipe_class_def);
- pipe_constructor = seed_make_constructor(eng->context,
- 0, seed_construct_pipe);
+ pipe_constructor
+ = seed_make_constructor(eng->context, 0, seed_construct_pipe);
- seed_object_set_property(eng->context,
- namespace_ref, "Pipe", pipe_constructor);
+ seed_object_set_property(eng->context, namespace_ref, "Pipe",
+ pipe_constructor);
- return namespace_ref;
+ return namespace_ref;
}
diff --git a/modules/os/seed-os.c b/modules/os/seed-os.c
index bc327e5..1a5a0dd 100644
--- a/modules/os/seed-os.c
+++ b/modules/os/seed-os.c
@@ -51,1107 +51,1055 @@
SeedObject os_namespace;
-#define EXPECTED_EXCEPTION(name, argnum) \
- seed_make_exception (ctx, exception, "ArgumentError", name " expected " argnum " got %zd",
argument_count); \
- return seed_make_undefined (ctx);
+#define EXPECTED_EXCEPTION(name, argnum) \
+ seed_make_exception(ctx, exception, "ArgumentError", \
+ name " expected " argnum " got %zd", argument_count); \
+ return seed_make_undefined(ctx);
SeedValue
-seed_os_realpath (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_realpath(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue sv;
- gchar *arg;
- gchar *resolved_path;
+ SeedValue sv;
+ gchar* arg;
+ gchar* resolved_path;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.realpath", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.realpath", "1 argument");
}
- arg = seed_value_to_string (ctx, arguments[0], exception);
- resolved_path = realpath (arg, NULL);
- g_free (arg);
+ arg = seed_value_to_string(ctx, arguments[0], exception);
+ resolved_path = realpath(arg, NULL);
+ g_free(arg);
- sv = seed_value_from_string (ctx, resolved_path, exception);
- g_free (resolved_path);
+ sv = seed_value_from_string(ctx, resolved_path, exception);
+ g_free(resolved_path);
- return sv;
+ return sv;
}
SeedValue
-seed_os_chdir (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_chdir(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gchar *arg;
- gint ret;
+ gchar* arg;
+ gint ret;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.chdir", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.chdir", "1 argument");
}
- arg = seed_value_to_string (ctx, arguments[0], exception);
- ret = chdir (arg);
- g_free (arg);
+ arg = seed_value_to_string(ctx, arguments[0], exception);
+ ret = chdir(arg);
+ g_free(arg);
- return seed_value_from_int (ctx, ret, exception);
+ return seed_value_from_int(ctx, ret, exception);
}
SeedValue
-seed_os_fchdir (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_fchdir(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint ret, arg;
+ gint ret, arg;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.fchdir", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.fchdir", "1 argument");
}
- arg = seed_value_to_int (ctx, arguments[0], exception);
- ret = fchdir (arg);
+ arg = seed_value_to_int(ctx, arguments[0], exception);
+ ret = fchdir(arg);
- return seed_value_from_int (ctx, ret, exception);
+ return seed_value_from_int(ctx, ret, exception);
}
SeedValue
-seed_os_getcwd (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getcwd(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue seed_ret;
- gchar *ret;
+ SeedValue seed_ret;
+ gchar* ret;
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.getcwd", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.getcwd", "no arguments");
}
- ret = getcwd (NULL, 0);
- seed_ret = seed_value_from_string (ctx, ret, exception);
- g_free (ret);
+ ret = getcwd(NULL, 0);
+ seed_ret = seed_value_from_string(ctx, ret, exception);
+ g_free(ret);
- return seed_ret;
+ return seed_ret;
}
SeedValue
-seed_os_ctermid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_ctermid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue seed_ret;
- gchar *ret;
+ SeedValue seed_ret;
+ gchar* ret;
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.getcwd", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.getcwd", "no arguments");
}
- // ctermid returns a static buffer
- ret = ctermid (NULL);
- seed_ret = seed_value_from_string (ctx, ret, exception);
+ // ctermid returns a static buffer
+ ret = ctermid(NULL);
+ seed_ret = seed_value_from_string(ctx, ret, exception);
- return seed_ret;
+ return seed_ret;
}
SeedValue
-seed_os_getegid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getegid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gid_t ret;
+ gid_t ret;
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.getegid", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.getegid", "no arguments");
}
- ret = getegid ();
+ ret = getegid();
- return seed_value_from_long (ctx, (glong) ret, exception);
+ return seed_value_from_long(ctx, (glong) ret, exception);
}
SeedValue
-seed_os_geteuid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_geteuid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- uid_t ret;
+ uid_t ret;
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.geteuid", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.geteuid", "no arguments");
}
- ret = geteuid ();
+ ret = geteuid();
- return seed_value_from_long (ctx, (glong) ret, exception);
+ return seed_value_from_long(ctx, (glong) ret, exception);
}
SeedValue
-seed_os_getgid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getgid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gid_t ret;
+ gid_t ret;
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.getgid", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.getgid", "no arguments");
}
- ret = getgid ();
+ ret = getgid();
- return seed_value_from_long (ctx, (glong) ret, exception);
+ return seed_value_from_long(ctx, (glong) ret, exception);
}
SeedValue
-seed_os_getuid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getuid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- uid_t ret;
+ uid_t ret;
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.getuid", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.getuid", "no arguments");
}
- ret = getuid ();
+ ret = getuid();
- return seed_value_from_long (ctx, (glong) ret, exception);
+ return seed_value_from_long(ctx, (glong) ret, exception);
}
SeedValue
-seed_os_getgroups (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getgroups(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue ret;
- SeedValue *groups;
- gid_t *group_list;
- guint num_groups, i;
-
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.getgroups", "no arguments");
+ SeedValue ret;
+ SeedValue* groups;
+ gid_t* group_list;
+ guint num_groups, i;
+
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.getgroups", "no arguments");
}
- num_groups = getgroups(0, NULL);
- group_list = g_alloca (num_groups * sizeof(gid_t));
- groups = g_alloca (num_groups * sizeof(SeedValue));
- if (getgroups (num_groups, group_list) < 0)
- {
- // TODO: Decide on how to handle exceptions for things like this...
- // Investigate python
- return seed_make_null (ctx);
+ num_groups = getgroups(0, NULL);
+ group_list = g_alloca(num_groups * sizeof(gid_t));
+ groups = g_alloca(num_groups * sizeof(SeedValue));
+ if (getgroups(num_groups, group_list) < 0) {
+ // TODO: Decide on how to handle exceptions for things like this...
+ // Investigate python
+ return seed_make_null(ctx);
}
- for (i = 0; i < num_groups; i++)
- {
- groups[i] = seed_value_from_long (ctx, (glong) group_list[i], exception);
+ for (i = 0; i < num_groups; i++) {
+ groups[i] = seed_value_from_long(ctx, (glong) group_list[i], exception);
}
- ret = seed_make_array (ctx, groups, num_groups, exception);
+ ret = seed_make_array(ctx, groups, num_groups, exception);
- return ret;
+ return ret;
}
SeedValue
-seed_os_getlogin (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getlogin(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.getlogin", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.getlogin", "no arguments");
}
- return seed_value_from_string (ctx, getlogin(), exception);
+ return seed_value_from_string(ctx, getlogin(), exception);
}
SeedValue
-seed_os_getpgid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getpgid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- pid_t pid;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.getpgid", "1 argument");
+ pid_t pid;
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.getpgid", "1 argument");
}
- pid = (pid_t) seed_value_to_long (ctx, arguments[0], exception);
+ pid = (pid_t) seed_value_to_long(ctx, arguments[0], exception);
- return seed_value_from_long (ctx, (glong) getpgid(pid), exception);
+ return seed_value_from_long(ctx, (glong) getpgid(pid), exception);
}
SeedValue
-seed_os_getpgrp (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getpgrp(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.getpgrp", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.getpgrp", "no arguments");
}
- return seed_value_from_long (ctx, (glong) getpgrp(), exception);
+ return seed_value_from_long(ctx, (glong) getpgrp(), exception);
}
SeedValue
-seed_os_getpid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getpid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.getpid", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.getpid", "no arguments");
}
- return seed_value_from_long (ctx, (glong) getpid(), exception);
+ return seed_value_from_long(ctx, (glong) getpid(), exception);
}
SeedValue
-seed_os_getppid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getppid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.getppid", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.getppid", "no arguments");
}
- return seed_value_from_long (ctx, (glong) getppid(), exception);
+ return seed_value_from_long(ctx, (glong) getppid(), exception);
}
SeedValue
-seed_os_getenv (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_getenv(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue ret;
- gchar *name, *value;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.getenv", "1 arguments");
+ SeedValue ret;
+ gchar *name, *value;
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.getenv", "1 arguments");
}
- name = seed_value_to_string (ctx, arguments[0], exception);
- value = getenv (name);
- ret = seed_value_from_string (ctx, value, exception);
- g_free (name);
+ name = seed_value_to_string(ctx, arguments[0], exception);
+ value = getenv(name);
+ ret = seed_value_from_string(ctx, value, exception);
+ g_free(name);
- return ret;
+ return ret;
}
SeedValue
-seed_os_putenv (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_putenv(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint ret;
- gchar *name, *value, *arg;
+ gint ret;
+ gchar *name, *value, *arg;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("os.putenv", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("os.putenv", "2 arguments");
}
- name = seed_value_to_string (ctx, arguments[0], exception);
- value = seed_value_to_string (ctx, arguments[1], exception);
- arg = g_strconcat (name, "=", value, NULL);
+ name = seed_value_to_string(ctx, arguments[0], exception);
+ value = seed_value_to_string(ctx, arguments[1], exception);
+ arg = g_strconcat(name, "=", value, NULL);
- ret = putenv (arg);
+ ret = putenv(arg);
- g_free (name);
- g_free (value);
+ g_free(name);
+ g_free(value);
- return seed_value_from_int (ctx, ret, exception);
+ return seed_value_from_int(ctx, ret, exception);
}
-
SeedValue
-seed_os_setegid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_setegid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gid_t arg;
+ gid_t arg;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.setegid", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.setegid", "1 argument");
}
- arg = seed_value_to_long (ctx, arguments[0], exception);
+ arg = seed_value_to_long(ctx, arguments[0], exception);
- return seed_value_from_int (ctx, setegid(arg), exception);
+ return seed_value_from_int(ctx, setegid(arg), exception);
}
SeedValue
-seed_os_setgid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_setgid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gid_t arg;
+ gid_t arg;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.setgid", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.setgid", "1 argument");
}
- arg = seed_value_to_long (ctx, arguments[0], exception);
+ arg = seed_value_to_long(ctx, arguments[0], exception);
- return seed_value_from_int (ctx, setgid(arg), exception);
+ return seed_value_from_int(ctx, setgid(arg), exception);
}
SeedValue
-seed_os_seteuid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_seteuid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- uid_t arg;
+ uid_t arg;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.seteuid", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.seteuid", "1 argument");
}
- arg = seed_value_to_long (ctx, arguments[0], exception);
+ arg = seed_value_to_long(ctx, arguments[0], exception);
- return seed_value_from_int (ctx, seteuid(arg), exception);
+ return seed_value_from_int(ctx, seteuid(arg), exception);
}
SeedValue
-seed_os_setuid (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_setuid(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- uid_t arg;
+ uid_t arg;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.setuid", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.setuid", "1 argument");
}
- arg = seed_value_to_long (ctx, arguments[0], exception);
+ arg = seed_value_to_long(ctx, arguments[0], exception);
- return seed_value_from_int (ctx, setuid(arg), exception);
+ return seed_value_from_int(ctx, setuid(arg), exception);
}
SeedValue
-seed_os_strerror (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_strerror(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- int arg;
+ int arg;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.strerror", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.strerror", "1 argument");
}
- arg = seed_value_to_int (ctx, arguments[0], exception);
+ arg = seed_value_to_int(ctx, arguments[0], exception);
- return seed_value_from_string (ctx, strerror(arg), exception);
+ return seed_value_from_string(ctx, strerror(arg), exception);
}
SeedValue
-seed_os_umask (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_umask(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- mode_t arg;
+ mode_t arg;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.umask", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.umask", "1 argument");
}
- arg = seed_value_to_long (ctx, arguments[0], exception);
+ arg = seed_value_to_long(ctx, arguments[0], exception);
- return seed_value_from_long (ctx, umask(arg), exception);
+ return seed_value_from_long(ctx, umask(arg), exception);
}
SeedValue
-seed_os_uname (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_uname(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue elements[5], ret;
- guint c;
- struct utsname name;
+ SeedValue elements[5], ret;
+ guint c;
+ struct utsname name;
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("os.uname", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.uname", "no arguments");
}
- c = uname (&name);
- // TODO: Do something with c
- elements[0] = seed_value_from_string (ctx, name.sysname, exception);
- elements[1] = seed_value_from_string (ctx, name.nodename, exception);
- elements[2] = seed_value_from_string (ctx, name.release, exception);
- elements[3] = seed_value_from_string (ctx, name.version, exception);
- elements[4] = seed_value_from_string (ctx, name.machine, exception);
- ret = seed_make_array (ctx, elements, 5, exception);
-
-
- return ret;
+ c = uname(&name);
+ // TODO: Do something with c
+ elements[0] = seed_value_from_string(ctx, name.sysname, exception);
+ elements[1] = seed_value_from_string(ctx, name.nodename, exception);
+ elements[2] = seed_value_from_string(ctx, name.release, exception);
+ elements[3] = seed_value_from_string(ctx, name.version, exception);
+ elements[4] = seed_value_from_string(ctx, name.machine, exception);
+ ret = seed_make_array(ctx, elements, 5, exception);
+
+ return ret;
}
-
SeedValue
-seed_os_unsetenv (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_unsetenv(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint ret;
- gchar *arg;
+ gint ret;
+ gchar* arg;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.unsetenv", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.unsetenv", "1 argument");
}
- arg = seed_value_to_string (ctx, arguments[0], exception);
+ arg = seed_value_to_string(ctx, arguments[0], exception);
#if __FreeBSD_version < 700000
- ret = 0;
- unsetenv (arg);
+ ret = 0;
+ unsetenv(arg);
#else
- ret = unsetenv (arg);
+ ret = unsetenv(arg);
#endif
- g_free (arg);
+ g_free(arg);
- return seed_value_from_int (ctx, ret, exception);
+ return seed_value_from_int(ctx, ret, exception);
}
SeedValue
-seed_os_open (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_open(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gchar *path;
- gint flags, ret;
+ gchar* path;
+ gint flags, ret;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("os.open", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("os.open", "2 arguments");
}
- path = seed_value_to_string (ctx, arguments[0], exception);
- flags = seed_value_to_int (ctx, arguments[1], exception);
+ path = seed_value_to_string(ctx, arguments[0], exception);
+ flags = seed_value_to_int(ctx, arguments[1], exception);
- ret = open (path, flags);
- g_free (path);
+ ret = open(path, flags);
+ g_free(path);
- return seed_value_from_int (ctx, ret, exception);
+ return seed_value_from_int(ctx, ret, exception);
}
SeedValue
-seed_os_close (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_close(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint arg;
+ gint arg;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.close", "2 arguments");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.close", "2 arguments");
}
- arg = seed_value_to_int (ctx, arguments[0], exception);
+ arg = seed_value_to_int(ctx, arguments[0], exception);
- return seed_value_from_int (ctx, close (arg), exception);
+ return seed_value_from_int(ctx, close(arg), exception);
}
SeedValue
-seed_os_dup (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_dup(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint arg;
+ gint arg;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION("os.dup", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.dup", "1 argument");
}
- arg = seed_value_to_int (ctx, arguments[0], exception);
+ arg = seed_value_to_int(ctx, arguments[0], exception);
- return seed_value_from_int (ctx, dup (arg), exception);
+ return seed_value_from_int(ctx, dup(arg), exception);
}
SeedValue
-seed_os_dup2 (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_dup2(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint arg, arg2;
+ gint arg, arg2;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION("os.dup2", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("os.dup2", "2 arguments");
}
- arg = seed_value_to_int (ctx, arguments[0], exception);
- arg2 = seed_value_to_int (ctx, arguments[0], exception);
+ arg = seed_value_to_int(ctx, arguments[0], exception);
+ arg2 = seed_value_to_int(ctx, arguments[0], exception);
- return seed_value_from_int (ctx, dup2 (arg, arg2), exception);
+ return seed_value_from_int(ctx, dup2(arg, arg2), exception);
}
SeedValue
-seed_os_fchmod (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_fchmod(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd;
- mode_t mode;
+ gint fd;
+ mode_t mode;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("os.fchmod", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("os.fchmod", "2 arguments");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
- mode = seed_value_to_long (ctx, arguments[1], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
+ mode = seed_value_to_long(ctx, arguments[1], exception);
- return seed_value_from_int (ctx, fchmod (fd, mode), exception);
+ return seed_value_from_int(ctx, fchmod(fd, mode), exception);
}
SeedValue
-seed_os_fchown (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_fchown(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd;
- gid_t gid;
- uid_t uid;
+ gint fd;
+ gid_t gid;
+ uid_t uid;
- if (argument_count != 3)
- {
- EXPECTED_EXCEPTION ("os.fchown", "3 arguments");
+ if (argument_count != 3) {
+ EXPECTED_EXCEPTION("os.fchown", "3 arguments");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
- uid = seed_value_to_long (ctx, arguments[1], exception);
- gid = seed_value_to_long (ctx, arguments[2], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
+ uid = seed_value_to_long(ctx, arguments[1], exception);
+ gid = seed_value_to_long(ctx, arguments[2], exception);
- return seed_value_from_int (ctx, fchown (fd, uid, gid), exception);
+ return seed_value_from_int(ctx, fchown(fd, uid, gid), exception);
}
SeedValue
-seed_os_fdatasync (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_fdatasync(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
- gint fd;
+ gint fd;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION ("os.fdatasync", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.fdatasync", "1 argument");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
- return seed_value_from_int (ctx, fdatasync (fd), exception);
+ return seed_value_from_int(ctx, fdatasync(fd), exception);
#else
- errno = ENOSYS;
- return seed_value_from_int (ctx, -1, exception);
+ errno = ENOSYS;
+ return seed_value_from_int(ctx, -1, exception);
#endif
}
SeedValue
-seed_os_fpathconf (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_fpathconf(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd, name;
+ gint fd, name;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("os.fpathconf", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("os.fpathconf", "2 arguments");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
- name = seed_value_to_int (ctx, arguments[1], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
+ name = seed_value_to_int(ctx, arguments[1], exception);
- return seed_value_from_long (ctx, fpathconf (fd, name), exception);
+ return seed_value_from_long(ctx, fpathconf(fd, name), exception);
}
SeedValue
-seed_os_fsync (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_fsync(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd;
+ gint fd;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION ("os.fsync", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.fsync", "1 argument");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
- return seed_value_from_long (ctx, fsync (fd), exception);
+ return seed_value_from_long(ctx, fsync(fd), exception);
}
SeedValue
-seed_os_ftruncate (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_ftruncate(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd;
- off_t length;
+ gint fd;
+ off_t length;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("os.ftruncate", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("os.ftruncate", "2 arguments");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
- length = seed_value_to_int (ctx, arguments[1], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
+ length = seed_value_to_int(ctx, arguments[1], exception);
- return seed_value_from_long (ctx, ftruncate (fd, length), exception);
+ return seed_value_from_long(ctx, ftruncate(fd, length), exception);
}
SeedValue
-seed_os_isatty (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_isatty(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd;
+ gint fd;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION ("os.isatty", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.isatty", "1 argument");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
- return seed_value_from_boolean (ctx, isatty (fd), exception);
+ return seed_value_from_boolean(ctx, isatty(fd), exception);
}
SeedValue
-seed_os_lseek (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_lseek(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd, whence;
- off_t offset;
+ gint fd, whence;
+ off_t offset;
- if (argument_count != 3)
- {
- EXPECTED_EXCEPTION ("os.lseek", "3 arguments");
+ if (argument_count != 3) {
+ EXPECTED_EXCEPTION("os.lseek", "3 arguments");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
- offset = seed_value_to_long (ctx, arguments[1], exception);
- whence = seed_value_to_int (ctx, arguments[2], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
+ offset = seed_value_to_long(ctx, arguments[1], exception);
+ whence = seed_value_to_int(ctx, arguments[2], exception);
- return seed_value_from_long (ctx, lseek (fd, offset, whence), exception);
+ return seed_value_from_long(ctx, lseek(fd, offset, whence), exception);
}
SeedValue
-seed_os_openpty (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_openpty(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue fds[2], ret;
- gint master,slave;
+ SeedValue fds[2], ret;
+ gint master, slave;
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION ("os.openpty", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.openpty", "no arguments");
}
- openpty (&master, &slave, NULL, NULL, NULL);
+ openpty(&master, &slave, NULL, NULL, NULL);
- fds[0] = seed_value_from_int (ctx, master, exception);
- fds[1] = seed_value_from_int (ctx, slave, exception);
+ fds[0] = seed_value_from_int(ctx, master, exception);
+ fds[1] = seed_value_from_int(ctx, slave, exception);
- ret = seed_make_array (ctx, fds, 2, exception);
+ ret = seed_make_array(ctx, fds, 2, exception);
- return ret;
+ return ret;
}
SeedValue
-seed_os_pipe (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_pipe(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue fds[2], ret;
- gint fildes[2];
+ SeedValue fds[2], ret;
+ gint fildes[2];
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION ("os.pipe", "no arguments");
+ if (argument_count != 0) {
+ EXPECTED_EXCEPTION("os.pipe", "no arguments");
}
- if (pipe (fildes) < 0)
- {
- // TODO
+ if (pipe(fildes) < 0) {
+ // TODO
}
- fds[0] = seed_value_from_int (ctx, fildes[0], exception);
- fds[1] = seed_value_from_int (ctx, fildes[1], exception);
+ fds[0] = seed_value_from_int(ctx, fildes[0], exception);
+ fds[1] = seed_value_from_int(ctx, fildes[1], exception);
- ret = seed_make_array (ctx, fds, 2, exception);
+ ret = seed_make_array(ctx, fds, 2, exception);
- return ret;
+ return ret;
}
SeedValue
-seed_os_read (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_read(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedValue ret;
- gint fd, n, nr;
- gchar *buf;
+ SeedValue ret;
+ gint fd, n, nr;
+ gchar* buf;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("os.read", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("os.read", "2 arguments");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
- n = seed_value_to_int (ctx, arguments[1], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
+ n = seed_value_to_int(ctx, arguments[1], exception);
- buf = g_alloca (n * sizeof (gchar));
- nr = read (fd, buf, n);
- buf[nr] = '\0';
+ buf = g_alloca(n * sizeof(gchar));
+ nr = read(fd, buf, n);
+ buf[nr] = '\0';
- if (nr)
- ret = seed_value_from_string (ctx, buf, exception);
- else
- ret = seed_make_null (ctx);
+ if (nr)
+ ret = seed_value_from_string(ctx, buf, exception);
+ else
+ ret = seed_make_null(ctx);
- return ret;
+ return ret;
}
SeedValue
-seed_os_write (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_write(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd, nw;
- gchar *buf;
+ gint fd, nw;
+ gchar* buf;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("os.write", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("os.write", "2 arguments");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
- buf = seed_value_to_string (ctx, arguments[1], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
+ buf = seed_value_to_string(ctx, arguments[1], exception);
- nw = write (fd, buf, strlen (buf));
+ nw = write(fd, buf, strlen(buf));
- return seed_value_from_int (ctx, nw, exception);
+ return seed_value_from_int(ctx, nw, exception);
}
SeedValue
-seed_os_ttyname (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_ttyname(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd;
+ gint fd;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION ("os.ttyname", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.ttyname", "1 argument");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
- return seed_value_from_string (ctx, ttyname (fd), exception);
+ return seed_value_from_string(ctx, ttyname(fd), exception);
}
SeedValue
-seed_os_tcgetpgrp (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_tcgetpgrp(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd;
+ gint fd;
- if (argument_count != 1)
- {
- EXPECTED_EXCEPTION ("os.tcgetpgrp", "1 argument");
+ if (argument_count != 1) {
+ EXPECTED_EXCEPTION("os.tcgetpgrp", "1 argument");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
- return seed_value_from_long (ctx, tcgetpgrp (fd), exception);
+ return seed_value_from_long(ctx, tcgetpgrp(fd), exception);
}
SeedValue
-seed_os_tcsetpgrp (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_tcsetpgrp(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gint fd;
- pid_t pgrp;
+ gint fd;
+ pid_t pgrp;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("os.tcsetpgrp", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("os.tcsetpgrp", "2 arguments");
}
- fd = seed_value_to_int (ctx, arguments[0], exception);
- pgrp = seed_value_to_int (ctx, arguments[1], exception);
+ fd = seed_value_to_int(ctx, arguments[0], exception);
+ pgrp = seed_value_to_int(ctx, arguments[1], exception);
- return seed_value_from_int (ctx, tcsetpgrp (fd, pgrp), exception);
+ return seed_value_from_int(ctx, tcsetpgrp(fd, pgrp), exception);
}
SeedValue
-seed_os_access (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_os_access(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- int ret;
- gchar *path;
- int amd;
+ int ret;
+ gchar* path;
+ int amd;
- if (argument_count != 2)
- {
- EXPECTED_EXCEPTION ("os.access", "2 arguments");
+ if (argument_count != 2) {
+ EXPECTED_EXCEPTION("os.access", "2 arguments");
}
- path = seed_value_to_string (ctx, arguments[0], exception);
- amd = seed_value_to_int (ctx, arguments[1], exception);
+ path = seed_value_to_string(ctx, arguments[0], exception);
+ amd = seed_value_to_int(ctx, arguments[1], exception);
- ret = access (path, amd);
+ ret = access(path, amd);
- if (ret == 0)
- return seed_value_from_boolean (ctx, TRUE, exception);
- else
- return seed_value_from_boolean (ctx, FALSE, exception);
+ if (ret == 0)
+ return seed_value_from_boolean(ctx, TRUE, exception);
+ else
+ return seed_value_from_boolean(ctx, FALSE, exception);
}
static SeedValue
-seed_os_fork (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+seed_os_fork(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- pid_t t = fork();
+ pid_t t = fork();
- return seed_value_from_long (ctx, t, exception);
+ return seed_value_from_long(ctx, t, exception);
}
-seed_static_function os_funcs[] = {
- {"fork", seed_os_fork, 0},
- {"realpath", seed_os_realpath, 0},
- {"chdir", seed_os_chdir, 0},
- {"fchdir", seed_os_fchdir, 0},
- {"getcwd", seed_os_getcwd, 0},
- {"ctermid", seed_os_ctermid, 0},
- {"getegid", seed_os_getegid, 0},
- {"geteuid", seed_os_geteuid, 0},
- {"getgid", seed_os_getgid, 0},
- {"getuid", seed_os_getuid, 0},
- {"getlogin", seed_os_getlogin, 0},
- {"getpgid", seed_os_getpgid, 0},
- {"getpgrp", seed_os_getpgrp, 0},
- {"getpid", seed_os_getpid, 0},
- {"getppid", seed_os_getuid, 0},
- {"getenv", seed_os_getenv, 0},
- {"putenv", seed_os_putenv, 0},
- {"setegid", seed_os_setegid, 0},
- {"setgid", seed_os_setegid, 0},
- {"seteuid", seed_os_setegid, 0},
- {"setuid", seed_os_setuid, 0},
- {"strerror", seed_os_strerror, 0},
- {"umask", seed_os_umask, 0},
- {"uname", seed_os_uname, 0},
- {"unsetenv", seed_os_unsetenv, 0},
- {"open", seed_os_open, 0},
- {"close", seed_os_close, 0},
- {"dup", seed_os_dup, 0},
- {"dup2", seed_os_dup2, 0},
- {"fchmod", seed_os_fchmod, 0},
- {"fchown", seed_os_fchown, 0},
- {"fdatasync", seed_os_fdatasync, 0},
- {"fpathconf", seed_os_fpathconf, 0},
- {"fsync", seed_os_fsync, 0},
- {"ftruncate", seed_os_ftruncate, 0},
- {"isatty", seed_os_isatty, 0},
- {"lseek", seed_os_lseek, 0},
- {"openpty", seed_os_openpty, 0},
- {"pipe", seed_os_pipe, 0},
- {"read", seed_os_read, 0},
- {"write", seed_os_write, 0},
- {"ttyname", seed_os_ttyname, 0},
- {"tcgetpgrp", seed_os_tcgetpgrp, 0},
- {"tcsetpgrp", seed_os_tcsetpgrp, 0},
- {"access", seed_os_access, 0},
- {NULL, NULL, 0}
-};
-
-#define OS_DEFINE_ENUM(name, value) \
- seed_object_set_property (eng->context, os_namespace, name, \
- seed_value_from_long (eng->context, value, NULL))
-#define OS_DEFINE_QUICK_ENUM(value) \
-seed_object_set_property (eng->context, os_namespace, #value, \
- seed_value_from_long (eng->context, value, NULL)) \
+seed_static_function os_funcs[] = { { "fork", seed_os_fork, 0 },
+ { "realpath", seed_os_realpath, 0 },
+ { "chdir", seed_os_chdir, 0 },
+ { "fchdir", seed_os_fchdir, 0 },
+ { "getcwd", seed_os_getcwd, 0 },
+ { "ctermid", seed_os_ctermid, 0 },
+ { "getegid", seed_os_getegid, 0 },
+ { "geteuid", seed_os_geteuid, 0 },
+ { "getgid", seed_os_getgid, 0 },
+ { "getuid", seed_os_getuid, 0 },
+ { "getlogin", seed_os_getlogin, 0 },
+ { "getpgid", seed_os_getpgid, 0 },
+ { "getpgrp", seed_os_getpgrp, 0 },
+ { "getpid", seed_os_getpid, 0 },
+ { "getppid", seed_os_getuid, 0 },
+ { "getenv", seed_os_getenv, 0 },
+ { "putenv", seed_os_putenv, 0 },
+ { "setegid", seed_os_setegid, 0 },
+ { "setgid", seed_os_setegid, 0 },
+ { "seteuid", seed_os_setegid, 0 },
+ { "setuid", seed_os_setuid, 0 },
+ { "strerror", seed_os_strerror, 0 },
+ { "umask", seed_os_umask, 0 },
+ { "uname", seed_os_uname, 0 },
+ { "unsetenv", seed_os_unsetenv, 0 },
+ { "open", seed_os_open, 0 },
+ { "close", seed_os_close, 0 },
+ { "dup", seed_os_dup, 0 },
+ { "dup2", seed_os_dup2, 0 },
+ { "fchmod", seed_os_fchmod, 0 },
+ { "fchown", seed_os_fchown, 0 },
+ { "fdatasync", seed_os_fdatasync, 0 },
+ { "fpathconf", seed_os_fpathconf, 0 },
+ { "fsync", seed_os_fsync, 0 },
+ { "ftruncate", seed_os_ftruncate, 0 },
+ { "isatty", seed_os_isatty, 0 },
+ { "lseek", seed_os_lseek, 0 },
+ { "openpty", seed_os_openpty, 0 },
+ { "pipe", seed_os_pipe, 0 },
+ { "read", seed_os_read, 0 },
+ { "write", seed_os_write, 0 },
+ { "ttyname", seed_os_ttyname, 0 },
+ { "tcgetpgrp", seed_os_tcgetpgrp, 0 },
+ { "tcsetpgrp", seed_os_tcsetpgrp, 0 },
+ { "access", seed_os_access, 0 },
+ { NULL, NULL, 0 } };
+
+#define OS_DEFINE_ENUM(name, value) \
+ seed_object_set_property(eng->context, os_namespace, name, \
+ seed_value_from_long(eng->context, value, NULL))
+#define OS_DEFINE_QUICK_ENUM(value) \
+ seed_object_set_property(eng->context, os_namespace, #value, \
+ seed_value_from_long(eng->context, value, NULL))
SeedObject
-seed_module_init(SeedEngine * eng)
+seed_module_init(SeedEngine* eng)
{
- SeedClass os_namespace_class;
- seed_class_definition os_namespace_class_definition = seed_empty_class;
+ SeedClass os_namespace_class;
+ seed_class_definition os_namespace_class_definition = seed_empty_class;
- os_namespace_class_definition.static_functions = os_funcs;
- os_namespace_class = seed_create_class (&os_namespace_class_definition);
+ os_namespace_class_definition.static_functions = os_funcs;
+ os_namespace_class = seed_create_class(&os_namespace_class_definition);
- os_namespace = seed_make_object (eng->context, os_namespace_class, NULL);
+ os_namespace = seed_make_object(eng->context, os_namespace_class, NULL);
- OS_DEFINE_QUICK_ENUM (O_RDONLY);
- OS_DEFINE_QUICK_ENUM (O_WRONLY);
- OS_DEFINE_QUICK_ENUM (O_RDWR);
- OS_DEFINE_QUICK_ENUM (O_APPEND);
- OS_DEFINE_QUICK_ENUM (O_CREAT);
- OS_DEFINE_QUICK_ENUM (O_EXCL);
- OS_DEFINE_QUICK_ENUM (O_TRUNC);
+ OS_DEFINE_QUICK_ENUM(O_RDONLY);
+ OS_DEFINE_QUICK_ENUM(O_WRONLY);
+ OS_DEFINE_QUICK_ENUM(O_RDWR);
+ OS_DEFINE_QUICK_ENUM(O_APPEND);
+ OS_DEFINE_QUICK_ENUM(O_CREAT);
+ OS_DEFINE_QUICK_ENUM(O_EXCL);
+ OS_DEFINE_QUICK_ENUM(O_TRUNC);
-#if defined (O_DSYNC)
- OS_DEFINE_QUICK_ENUM (O_DSYNC);
+#if defined(O_DSYNC)
+ OS_DEFINE_QUICK_ENUM(O_DSYNC);
#endif
-#if defined (O_RSYNC)
- OS_DEFINE_QUICK_ENUM (O_RSYNC);
+#if defined(O_RSYNC)
+ OS_DEFINE_QUICK_ENUM(O_RSYNC);
#endif
- OS_DEFINE_QUICK_ENUM (O_SYNC);
- OS_DEFINE_QUICK_ENUM (O_NDELAY);
- OS_DEFINE_QUICK_ENUM (O_NONBLOCK);
- OS_DEFINE_QUICK_ENUM (O_NOCTTY);
- // OS_DEFINE_QUICK_ENUM (O_SHLOCK);
- // OS_DEFINE_QUICK_ENUM (O_EXLOCK);
+ OS_DEFINE_QUICK_ENUM(O_SYNC);
+ OS_DEFINE_QUICK_ENUM(O_NDELAY);
+ OS_DEFINE_QUICK_ENUM(O_NONBLOCK);
+ OS_DEFINE_QUICK_ENUM(O_NOCTTY);
+ // OS_DEFINE_QUICK_ENUM (O_SHLOCK);
+ // OS_DEFINE_QUICK_ENUM (O_EXLOCK);
- OS_DEFINE_QUICK_ENUM (O_ASYNC);
-#if defined (O_DIRECT)
- OS_DEFINE_QUICK_ENUM (O_DIRECT);
+ OS_DEFINE_QUICK_ENUM(O_ASYNC);
+#if defined(O_DIRECT)
+ OS_DEFINE_QUICK_ENUM(O_DIRECT);
#endif
-#if defined (O_DIRECTORY)
- OS_DEFINE_QUICK_ENUM (O_DIRECTORY);
+#if defined(O_DIRECTORY)
+ OS_DEFINE_QUICK_ENUM(O_DIRECTORY);
#endif
- OS_DEFINE_QUICK_ENUM (O_NOFOLLOW);
-#if defined (O_NOATIME)
- OS_DEFINE_QUICK_ENUM (O_NOATIME);
+ OS_DEFINE_QUICK_ENUM(O_NOFOLLOW);
+#if defined(O_NOATIME)
+ OS_DEFINE_QUICK_ENUM(O_NOATIME);
#endif
- OS_DEFINE_QUICK_ENUM (SEEK_SET);
- OS_DEFINE_QUICK_ENUM (SEEK_CUR);
- OS_DEFINE_QUICK_ENUM (SEEK_END);
+ OS_DEFINE_QUICK_ENUM(SEEK_SET);
+ OS_DEFINE_QUICK_ENUM(SEEK_CUR);
+ OS_DEFINE_QUICK_ENUM(SEEK_END);
- OS_DEFINE_QUICK_ENUM (F_OK);
- OS_DEFINE_QUICK_ENUM (R_OK);
- OS_DEFINE_QUICK_ENUM (W_OK);
- OS_DEFINE_QUICK_ENUM (X_OK);
+ OS_DEFINE_QUICK_ENUM(F_OK);
+ OS_DEFINE_QUICK_ENUM(R_OK);
+ OS_DEFINE_QUICK_ENUM(W_OK);
+ OS_DEFINE_QUICK_ENUM(X_OK);
- return os_namespace;
+ return os_namespace;
}
diff --git a/modules/readline/seed-readline.c b/modules/readline/seed-readline.c
index 49d1faa..fb3f7de 100644
--- a/modules/readline/seed-readline.c
+++ b/modules/readline/seed-readline.c
@@ -26,173 +26,167 @@
#include <sys/mman.h>
SeedObject namespace_ref;
-SeedEngine *eng;
+SeedEngine* eng;
gboolean readline_has_initialized = FALSE;
static void
-seed_handle_rl_closure(ffi_cif * cif, void *result, void **args, void *userdata)
+seed_handle_rl_closure(ffi_cif* cif, void* result, void** args, void* userdata)
{
- SeedContext ctx = seed_context_create(eng->group, NULL);
- SeedValue exception = 0;
- SeedObject function = (SeedObject) userdata;
-
- seed_object_call(ctx, function, 0, 0, 0, &exception);
- if (exception)
- {
- gchar *mes = seed_exception_to_string(ctx,
- exception);
- g_warning("Exception in readline bind key closure. %s \n", mes);
+ SeedContext ctx = seed_context_create(eng->group, NULL);
+ SeedValue exception = 0;
+ SeedObject function = (SeedObject) userdata;
+
+ seed_object_call(ctx, function, 0, 0, 0, &exception);
+ if (exception) {
+ gchar* mes = seed_exception_to_string(ctx, exception);
+ g_warning("Exception in readline bind key closure. %s \n", mes);
}
- seed_context_unref((SeedContext) ctx);
+ seed_context_unref((SeedContext) ctx);
}
// "Leaky" in that it exists for lifetime of program,
// kind of unavoidable though.
-static ffi_closure *seed_make_rl_closure(SeedObject function)
+static ffi_closure*
+seed_make_rl_closure(SeedObject function)
{
- ffi_cif *cif;
- ffi_closure *closure;
+ ffi_cif* cif;
+ ffi_closure* closure;
- cif = g_new0(ffi_cif, 1);
- closure = mmap(0, sizeof(ffi_closure), PROT_READ | PROT_WRITE |
- PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
- ffi_prep_cif(cif, FFI_DEFAULT_ABI, 0, &ffi_type_sint, 0);
- ffi_prep_closure(closure, cif, seed_handle_rl_closure, function);
+ cif = g_new0(ffi_cif, 1);
+ closure = mmap(0, sizeof(ffi_closure), PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_ANON | MAP_PRIVATE, -1, 0);
+ ffi_prep_cif(cif, FFI_DEFAULT_ABI, 0, &ffi_type_sint, 0);
+ ffi_prep_closure(closure, cif, seed_handle_rl_closure, function);
- return closure;
+ return closure;
}
static SeedValue
seed_readline_bind(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedValue * exception)
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedValue* exception)
{
- gchar *key;
- ffi_closure *c;
-
- CHECK_ARG_COUNT("readline.bind", 2);
+ gchar* key;
+ ffi_closure* c;
- key = seed_value_to_string(ctx, arguments[0], exception);
- c = seed_make_rl_closure((SeedObject) arguments[1]);
+ CHECK_ARG_COUNT("readline.bind", 2);
- rl_bind_key(*key, (rl_command_func_t *) c);
+ key = seed_value_to_string(ctx, arguments[0], exception);
+ c = seed_make_rl_closure((SeedObject) arguments[1]);
- g_free(key);
+ rl_bind_key(*key, (rl_command_func_t*) c);
- return seed_make_null(ctx);
+ g_free(key);
+
+ return seed_make_null(ctx);
}
static SeedValue
seed_rl_done(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedValue * exception)
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedValue* exception)
{
- CHECK_ARG_COUNT("readline.done", 0);
- rl_done = 1;
- return seed_make_null (ctx);
+ CHECK_ARG_COUNT("readline.done", 0);
+ rl_done = 1;
+ return seed_make_null(ctx);
}
static SeedValue
seed_rl_buffer(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedValue * exception)
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedValue* exception)
{
- CHECK_ARG_COUNT("readline.buffer", 0);
- return seed_value_from_string (ctx, rl_line_buffer, exception);
+ CHECK_ARG_COUNT("readline.buffer", 0);
+ return seed_value_from_string(ctx, rl_line_buffer, exception);
}
static SeedValue
seed_rl_insert(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedValue * exception)
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedValue* exception)
{
- gchar *ins;
- gint ret;
-
- CHECK_ARG_COUNT("readline.insert", 1);
-
- ins = seed_value_to_string (ctx, arguments[0], exception);
- ret = rl_insert_text (ins);
- g_free (ins);
-
- return seed_value_from_int (ctx, ret, exception);
+ gchar* ins;
+ gint ret;
+
+ CHECK_ARG_COUNT("readline.insert", 1);
+
+ ins = seed_value_to_string(ctx, arguments[0], exception);
+ ret = rl_insert_text(ins);
+ g_free(ins);
+
+ return seed_value_from_int(ctx, ret, exception);
}
static SeedValue
seed_readline(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedValue * exception)
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedValue* exception)
{
- SeedValue valstr = 0;
- gchar *str = NULL;
- gchar *buf;
- const gchar *histfname = g_get_home_dir();
- gchar *path = g_build_filename(histfname, ".seed_history", NULL);
-
- if (!readline_has_initialized)
- {
- read_history(path);
- readline_has_initialized = TRUE;
+ SeedValue valstr = 0;
+ gchar* str = NULL;
+ gchar* buf;
+ const gchar* histfname = g_get_home_dir();
+ gchar* path = g_build_filename(histfname, ".seed_history", NULL);
+
+ if (!readline_has_initialized) {
+ read_history(path);
+ readline_has_initialized = TRUE;
}
- CHECK_ARG_COUNT("readline.readline", 1);
+ CHECK_ARG_COUNT("readline.readline", 1);
- buf = seed_value_to_string(ctx, arguments[0], exception);
+ buf = seed_value_to_string(ctx, arguments[0], exception);
- str = readline(buf);
- if (str && *str)
- {
- add_history(str);
- valstr = seed_value_from_string(ctx, str, exception);
- g_free(str);
+ str = readline(buf);
+ if (str && *str) {
+ add_history(str);
+ valstr = seed_value_from_string(ctx, str, exception);
+ g_free(str);
}
- write_history(path);
- history_truncate_file(path, 1000);
+ write_history(path);
+ history_truncate_file(path, 1000);
- g_free(buf);
- g_free(path);
+ g_free(buf);
+ g_free(path);
- if (valstr == 0)
- valstr = seed_make_null(ctx);
+ if (valstr == 0)
+ valstr = seed_make_null(ctx);
- return valstr;
+ return valstr;
}
-seed_static_function readline_funcs[] = {
- {"readline", seed_readline, 0},
- {"bind", seed_readline_bind, 0},
- {"done", seed_rl_done, 0},
- {"buffer", seed_rl_buffer, 0},
- {"insert", seed_rl_insert, 0},
- {NULL, NULL, 0}
-};
+seed_static_function readline_funcs[]
+ = { { "readline", seed_readline, 0 }, { "bind", seed_readline_bind, 0 },
+ { "done", seed_rl_done, 0 }, { "buffer", seed_rl_buffer, 0 },
+ { "insert", seed_rl_insert, 0 }, { NULL, NULL, 0 } };
SeedObject
-seed_module_init(SeedEngine * local_eng)
+seed_module_init(SeedEngine* local_eng)
{
- seed_class_definition readline_ns_class_def = seed_empty_class;
- readline_ns_class_def.static_functions = readline_funcs;
-
- SeedClass readline_ns_class = seed_create_class(&readline_ns_class_def);
+ seed_class_definition readline_ns_class_def = seed_empty_class;
+ readline_ns_class_def.static_functions = readline_funcs;
- eng = local_eng;
+ SeedClass readline_ns_class = seed_create_class(&readline_ns_class_def);
- namespace_ref = seed_make_object(eng->context, readline_ns_class, 0);
+ eng = local_eng;
- return namespace_ref;
-}
+ namespace_ref = seed_make_object(eng->context, readline_ns_class, 0);
+ return namespace_ref;
+}
diff --git a/modules/sandbox/seed-sandbox.c b/modules/sandbox/seed-sandbox.c
index 20e0a5f..b6251ae 100644
--- a/modules/sandbox/seed-sandbox.c
+++ b/modules/sandbox/seed-sandbox.c
@@ -25,122 +25,119 @@ SeedObject namespace_ref;
SeedClass context_class;
static SeedObject
-seed_construct_sandbox_context (SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_construct_sandbox_context(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedObject ret;
- SeedContext c;
+ SeedObject ret;
+ SeedContext c;
- c = seed_context_create (group, NULL);
- ret = seed_make_object (ctx, context_class, c);
+ c = seed_context_create(group, NULL);
+ ret = seed_make_object(ctx, context_class, c);
- seed_object_set_property (ctx, ret, "global", seed_context_get_global_object (c));
- return ret;
+ seed_object_set_property(ctx, ret, "global",
+ seed_context_get_global_object(c));
+ return ret;
}
static SeedValue
-seed_context_eval (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_context_eval(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedContext c = seed_object_get_private (this_object);
- SeedValue ret;
- gchar *s;
-
- if (!c)
- {
- seed_make_exception (ctx, exception,
- "ArgumentError", "Context is destroyed");
- return seed_make_undefined (ctx);
+ SeedContext c = seed_object_get_private(this_object);
+ SeedValue ret;
+ gchar* s;
+
+ if (!c) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Context is destroyed");
+ return seed_make_undefined(ctx);
}
- s = seed_value_to_string (ctx, arguments[0], exception);
- ret = seed_simple_evaluate (c, s, exception);
- g_free (s);
+ s = seed_value_to_string(ctx, arguments[0], exception);
+ ret = seed_simple_evaluate(c, s, exception);
+ g_free(s);
- return ret;
+ return ret;
}
static SeedValue
-seed_sandbox_context_add_globals (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_sandbox_context_add_globals(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedContext c = seed_object_get_private (this_object);
- if (!c)
- {
- seed_make_exception (ctx, exception,
- "ArgumentError", "Context is destroyed");
- return seed_make_undefined (ctx);
+ SeedContext c = seed_object_get_private(this_object);
+ if (!c) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "Context is destroyed");
+ return seed_make_undefined(ctx);
}
- seed_prepare_global_context (c);
+ seed_prepare_global_context(c);
- SeedObject g = seed_context_get_global_object (c);
- SeedObject global = seed_context_get_global_object (ctx);
+ SeedObject g = seed_context_get_global_object(c);
+ SeedObject global = seed_context_get_global_object(ctx);
- SeedValue script_path = seed_object_get_property (ctx, global, "__script_path__");
+ SeedValue script_path
+ = seed_object_get_property(ctx, global, "__script_path__");
- seed_object_set_property (c, g, "__script_path__",
- (script_path && seed_value_is_object(ctx, script_path)) ?
- script_path : seed_make_undefined(ctx)
- );
-
- return seed_make_null (ctx);
-}
+ seed_object_set_property(c, g, "__script_path__",
+ (script_path
+ && seed_value_is_object(ctx, script_path))
+ ? script_path
+ : seed_make_undefined(ctx));
+ return seed_make_null(ctx);
+}
static SeedValue
-seed_sandbox_context_destroy (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+seed_sandbox_context_destroy(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedContext c = seed_object_get_private (this_object);
+ SeedContext c = seed_object_get_private(this_object);
- seed_context_unref (c);
- seed_object_set_private (this_object, NULL);
- return seed_make_null (ctx);
+ seed_context_unref(c);
+ seed_object_set_private(this_object, NULL);
+ return seed_make_null(ctx);
}
-seed_static_function context_funcs[] = {
- {"eval", seed_context_eval, 0},
- {"add_globals", seed_sandbox_context_add_globals, 0},
- {"destroy", seed_sandbox_context_destroy, 0},
- {NULL, NULL, 0}
-};
+seed_static_function context_funcs[]
+ = { { "eval", seed_context_eval, 0 },
+ { "add_globals", seed_sandbox_context_add_globals, 0 },
+ { "destroy", seed_sandbox_context_destroy, 0 },
+ { NULL, NULL, 0 } };
SeedObject
-seed_module_init(SeedEngine * eng)
+seed_module_init(SeedEngine* eng)
{
- SeedObject context_constructor;
- seed_class_definition context_class_def = seed_empty_class;
-
- ctx = eng->context;
- group = eng->group;
- namespace_ref = seed_make_object (ctx, NULL, NULL);
-
- context_class_def.class_name = "Context";
- context_class_def.static_functions = context_funcs;
+ SeedObject context_constructor;
+ seed_class_definition context_class_def = seed_empty_class;
- context_class = seed_create_class (&context_class_def);
+ ctx = eng->context;
+ group = eng->group;
+ namespace_ref = seed_make_object(ctx, NULL, NULL);
+ context_class_def.class_name = "Context";
+ context_class_def.static_functions = context_funcs;
- context_constructor = seed_make_constructor (eng->context,
- context_class,
- seed_construct_sandbox_context);
- seed_object_set_property (eng->context, namespace_ref, "Context", context_constructor);
+ context_class = seed_create_class(&context_class_def);
- return namespace_ref;
+ context_constructor = seed_make_constructor(eng->context, context_class,
+ seed_construct_sandbox_context);
+ seed_object_set_property(eng->context, namespace_ref, "Context",
+ context_constructor);
+ return namespace_ref;
}
diff --git a/modules/sqlite/seed-sqlite.c b/modules/sqlite/seed-sqlite.c
index 18f204c..9dcafae 100644
--- a/modules/sqlite/seed-sqlite.c
+++ b/modules/sqlite/seed-sqlite.c
@@ -22,194 +22,191 @@
SeedObject namespace_ref;
SeedClass sqlite_class;
-SeedEngine *eng;
+SeedEngine* eng;
-#define MAKE_ERROR_ENUM(name) \
- seed_object_set_property(eng->context, namespace_ref, #name, \
- seed_value_from_int(eng->context, SQLITE_##name, 0))
+#define MAKE_ERROR_ENUM(name) \
+ seed_object_set_property(eng->context, namespace_ref, #name, \
+ seed_value_from_int(eng->context, SQLITE_##name, \
+ 0))
-void define_errors(SeedEngine * eng)
+void
+define_errors(SeedEngine* eng)
{
- MAKE_ERROR_ENUM(OK);
- MAKE_ERROR_ENUM(ERROR);
- MAKE_ERROR_ENUM(INTERNAL);
- MAKE_ERROR_ENUM(PERM);
- MAKE_ERROR_ENUM(ABORT);
- MAKE_ERROR_ENUM(BUSY);
- MAKE_ERROR_ENUM(LOCKED);
- MAKE_ERROR_ENUM(NOMEM);
- MAKE_ERROR_ENUM(READONLY);
- MAKE_ERROR_ENUM(INTERRUPT);
- MAKE_ERROR_ENUM(CORRUPT);
- MAKE_ERROR_ENUM(NOTFOUND);
- MAKE_ERROR_ENUM(FULL);
- MAKE_ERROR_ENUM(CANTOPEN);
- MAKE_ERROR_ENUM(PROTOCOL);
- MAKE_ERROR_ENUM(EMPTY);
- MAKE_ERROR_ENUM(SCHEMA);
- MAKE_ERROR_ENUM(TOOBIG);
- MAKE_ERROR_ENUM(CONSTRAINT);
- MAKE_ERROR_ENUM(MISMATCH);
- MAKE_ERROR_ENUM(MISUSE);
- MAKE_ERROR_ENUM(NOLFS);
- MAKE_ERROR_ENUM(AUTH);
- MAKE_ERROR_ENUM(FORMAT);
- MAKE_ERROR_ENUM(RANGE);
- MAKE_ERROR_ENUM(NOTADB);
- MAKE_ERROR_ENUM(ROW);
- MAKE_ERROR_ENUM(DONE);
+ MAKE_ERROR_ENUM(OK);
+ MAKE_ERROR_ENUM(ERROR);
+ MAKE_ERROR_ENUM(INTERNAL);
+ MAKE_ERROR_ENUM(PERM);
+ MAKE_ERROR_ENUM(ABORT);
+ MAKE_ERROR_ENUM(BUSY);
+ MAKE_ERROR_ENUM(LOCKED);
+ MAKE_ERROR_ENUM(NOMEM);
+ MAKE_ERROR_ENUM(READONLY);
+ MAKE_ERROR_ENUM(INTERRUPT);
+ MAKE_ERROR_ENUM(CORRUPT);
+ MAKE_ERROR_ENUM(NOTFOUND);
+ MAKE_ERROR_ENUM(FULL);
+ MAKE_ERROR_ENUM(CANTOPEN);
+ MAKE_ERROR_ENUM(PROTOCOL);
+ MAKE_ERROR_ENUM(EMPTY);
+ MAKE_ERROR_ENUM(SCHEMA);
+ MAKE_ERROR_ENUM(TOOBIG);
+ MAKE_ERROR_ENUM(CONSTRAINT);
+ MAKE_ERROR_ENUM(MISMATCH);
+ MAKE_ERROR_ENUM(MISUSE);
+ MAKE_ERROR_ENUM(NOLFS);
+ MAKE_ERROR_ENUM(AUTH);
+ MAKE_ERROR_ENUM(FORMAT);
+ MAKE_ERROR_ENUM(RANGE);
+ MAKE_ERROR_ENUM(NOTADB);
+ MAKE_ERROR_ENUM(ROW);
+ MAKE_ERROR_ENUM(DONE);
}
-void sqlite_database_finalize(SeedObject object)
+void
+sqlite_database_finalize(SeedObject object)
{
- sqlite3 *db = seed_object_get_private(object);
- if (db)
- sqlite3_close(db);
+ sqlite3* db = seed_object_get_private(object);
+ if (db)
+ sqlite3_close(db);
}
-SeedObject sqlite_construct_database(SeedContext ctx,
- SeedObject constructor,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+SeedObject
+sqlite_construct_database(SeedContext ctx,
+ SeedObject constructor,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- SeedObject ret;
- gchar *file;
- sqlite3 *db;
- int rc;
-
- if (argument_count != 1)
- {
- seed_make_exception(ctx, exception, "ArgumentError",
- "sqlite.Database constructor expected 1 argument");
- return (SeedObject) seed_make_null(ctx);
+ SeedObject ret;
+ gchar* file;
+ sqlite3* db;
+ int rc;
+
+ if (argument_count != 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "sqlite.Database constructor expected 1 argument");
+ return (SeedObject) seed_make_null(ctx);
}
- file = seed_value_to_string(ctx, arguments[0], exception);
+ file = seed_value_to_string(ctx, arguments[0], exception);
- rc = sqlite3_open(file, &db);
+ rc = sqlite3_open(file, &db);
- g_free(file);
+ g_free(file);
- ret = seed_make_object(ctx, sqlite_class, db);
- seed_object_set_property(ctx, ret, "status",
- seed_value_from_int(ctx, rc, exception));
+ ret = seed_make_object(ctx, sqlite_class, db);
+ seed_object_set_property(ctx, ret, "status",
+ seed_value_from_int(ctx, rc, exception));
- return ret;
+ return ret;
}
-static int seed_sqlite_exec_callback(SeedObject function,
- int argc,
- gchar ** argv, gchar ** azColName)
+static int
+seed_sqlite_exec_callback(SeedObject function,
+ int argc,
+ gchar** argv,
+ gchar** azColName)
{
- SeedGlobalContext ctx;
- SeedObject hash;
- int i;
+ SeedGlobalContext ctx;
+ SeedObject hash;
+ int i;
- if (!function)
- return 0;
+ if (!function)
+ return 0;
- ctx = seed_context_create(eng->group, NULL);
+ ctx = seed_context_create(eng->group, NULL);
- hash = seed_make_object(ctx, 0, 0);
- for (i = 0; i < argc; i++)
- {
- seed_object_set_property(ctx, hash,
- azColName[i],
- seed_value_from_string(ctx, argv[i], 0));
+ hash = seed_make_object(ctx, 0, 0);
+ for (i = 0; i < argc; i++) {
+ seed_object_set_property(ctx, hash, azColName[i],
+ seed_value_from_string(ctx, argv[i], 0));
}
- seed_object_call(ctx, function, 0, 1, &hash, 0);
+ seed_object_call(ctx, function, 0, 1, &hash, 0);
- seed_context_unref(ctx);
+ seed_context_unref(ctx);
- return 0;
+ return 0;
}
-SeedValue seed_sqlite_exec(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+SeedValue
+seed_sqlite_exec(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- gchar *statement;
- gchar *sqlite_error = 0;
- sqlite3 *db;
- int rc;
-
- if (argument_count < 1)
- {
- seed_make_exception(ctx, exception, "ArgumentError",
- "sqlite.Database.exec expected 1 or 2 arguments");
- return seed_make_null(ctx);
+ gchar* statement;
+ gchar* sqlite_error = 0;
+ sqlite3* db;
+ int rc;
+
+ if (argument_count < 1) {
+ seed_make_exception(ctx, exception, "ArgumentError",
+ "sqlite.Database.exec expected 1 or 2 arguments");
+ return seed_make_null(ctx);
}
- statement = seed_value_to_string(ctx, arguments[0], exception);
- db = seed_object_get_private(this_object);
-
- g_assert(db);
-
- rc = sqlite3_exec(db, statement,
- seed_sqlite_exec_callback,
- argument_count == 2 ? arguments[1] : 0, &sqlite_error);
- g_free(statement);
-
- if (rc != SQLITE_OK)
- {
- if (sqlite_error)
- {
- seed_make_exception(ctx, exception, "SqliteError",
- sqlite_error, NULL);
- sqlite3_free(sqlite_error);
- }
- return seed_make_null(ctx);
- }
+ statement = seed_value_to_string(ctx, arguments[0], exception);
+ db = seed_object_get_private(this_object);
- return seed_value_from_int(ctx, rc, exception);
+ g_assert(db);
+ rc = sqlite3_exec(db, statement, seed_sqlite_exec_callback,
+ argument_count == 2 ? arguments[1] : 0, &sqlite_error);
+ g_free(statement);
+
+ if (rc != SQLITE_OK) {
+ if (sqlite_error) {
+ seed_make_exception(ctx, exception, "SqliteError", sqlite_error,
+ NULL);
+ sqlite3_free(sqlite_error);
+ }
+ return seed_make_null(ctx);
+ }
+
+ return seed_value_from_int(ctx, rc, exception);
}
-SeedValue seed_sqlite_close(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+SeedValue
+seed_sqlite_close(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- sqlite3 *db = seed_object_get_private(this_object);
- sqlite3_close(db);
- return seed_value_from_boolean(ctx, TRUE, exception);
+ sqlite3* db = seed_object_get_private(this_object);
+ sqlite3_close(db);
+ return seed_value_from_boolean(ctx, TRUE, exception);
}
-seed_static_function database_funcs[] = {
- {"close", seed_sqlite_close, 0},
- {"exec", seed_sqlite_exec, 0},
- {NULL, NULL, 0}
-};
+seed_static_function database_funcs[] = { { "close", seed_sqlite_close, 0 },
+ { "exec", seed_sqlite_exec, 0 },
+ { NULL, NULL, 0 } };
SeedObject
-seed_module_init(SeedEngine * local_eng)
+seed_module_init(SeedEngine* local_eng)
{
- SeedObject db_constructor;
- seed_class_definition sqlite_class_def = seed_empty_class;
+ SeedObject db_constructor;
+ seed_class_definition sqlite_class_def = seed_empty_class;
- eng = local_eng;
+ eng = local_eng;
- namespace_ref = seed_make_object(eng->context, 0, 0);
+ namespace_ref = seed_make_object(eng->context, 0, 0);
- define_errors(eng);
+ define_errors(eng);
- sqlite_class_def.class_name = "Database";
- sqlite_class_def.finalize = sqlite_database_finalize;
- sqlite_class_def.static_functions = database_funcs;
+ sqlite_class_def.class_name = "Database";
+ sqlite_class_def.finalize = sqlite_database_finalize;
+ sqlite_class_def.static_functions = database_funcs;
- sqlite_class = seed_create_class(&sqlite_class_def);
+ sqlite_class = seed_create_class(&sqlite_class_def);
- db_constructor = seed_make_constructor(eng->context,
- sqlite_class,
- sqlite_construct_database);
- seed_object_set_property(eng->context,
- namespace_ref, "Database", db_constructor);
+ db_constructor = seed_make_constructor(eng->context, sqlite_class,
+ sqlite_construct_database);
+ seed_object_set_property(eng->context, namespace_ref, "Database",
+ db_constructor);
- return namespace_ref;
+ return namespace_ref;
}
diff --git a/modules/xorg/seed-xorg.c b/modules/xorg/seed-xorg.c
index 75cc764..df57f3a 100644
--- a/modules/xorg/seed-xorg.c
+++ b/modules/xorg/seed-xorg.c
@@ -16,8 +16,9 @@
*
* Copyright (C) Alan Knowles 2011 <alan akbkhome com>
*
- * This started of as a way to get Xorg information not easily available elsewhere
- *
+ * This started of as a way to get Xorg information not easily available
+ * elsewhere
+ *
* It currently is only used with libxss (screensaver extension) to
* get the idle time.
*
@@ -26,56 +27,51 @@
#include "../../libseed/seed.h"
#include <X11/extensions/scrnsaver.h>
-
/**
* screensaverinfo_get_idletime()
* @returns screen idle time.
*/
-SeedValue seed_xorg_screensaverinfo_get_idletime(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[],
- SeedException * exception)
+SeedValue
+seed_xorg_screensaverinfo_get_idletime(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- int rc = -1;
-
- XScreenSaverInfo *info = XScreenSaverAllocInfo();
- Display *display = XOpenDisplay(NULL);
-
- if (display != NULL) {
- XScreenSaverQueryInfo(display, DefaultRootWindow(display), info);
- rc = info->idle;
- XCloseDisplay(display);
- }
-
+ int rc = -1;
- XFree(info);
- return seed_value_from_int(ctx, rc, exception);
-
+ XScreenSaverInfo* info = XScreenSaverAllocInfo();
+ Display* display = XOpenDisplay(NULL);
+ if (display != NULL) {
+ XScreenSaverQueryInfo(display, DefaultRootWindow(display), info);
+ rc = info->idle;
+ XCloseDisplay(display);
+ }
+
+ XFree(info);
+ return seed_value_from_int(ctx, rc, exception);
}
-
-seed_static_function xorg_funcs[] = {
- {"screensaverinfo_get_idletime", seed_xorg_screensaverinfo_get_idletime, 0},
-
- {NULL, NULL, 0}
-};
+seed_static_function xorg_funcs[]
+ = { { "screensaverinfo_get_idletime", seed_xorg_screensaverinfo_get_idletime,
+ 0 },
+
+ { NULL, NULL, 0 } };
SeedObject
-seed_module_init(SeedEngine * eng)
+seed_module_init(SeedEngine* eng)
{
- SeedObject seed_xorg;
- SeedClass seed_xorg_class;
- seed_class_definition seed_xorg_class_definition = seed_empty_class;
+ SeedObject seed_xorg;
+ SeedClass seed_xorg_class;
+ seed_class_definition seed_xorg_class_definition = seed_empty_class;
- seed_xorg_class_definition.static_functions = xorg_funcs;
- seed_xorg_class = seed_create_class (&seed_xorg_class_definition);
+ seed_xorg_class_definition.static_functions = xorg_funcs;
+ seed_xorg_class = seed_create_class(&seed_xorg_class_definition);
- seed_xorg = seed_make_object (eng->context, seed_xorg_class, NULL);
-
+ seed_xorg = seed_make_object(eng->context, seed_xorg_class, NULL);
- return seed_xorg;
+ return seed_xorg;
}
diff --git a/src/args.c b/src/args.c
index 156ad70..ccdc415 100644
--- a/src/args.c
+++ b/src/args.c
@@ -26,60 +26,59 @@
#include "config.h"
extern gboolean seed_interpreter_arg_print_version;
-extern gchar *seed_interpreter_arg_exec_string;
+extern gchar* seed_interpreter_arg_exec_string;
static GOptionEntry seed_args[] = {
- {"version", 0, 0, G_OPTION_ARG_NONE, &seed_interpreter_arg_print_version,
- "Print interpreter version", 0},
- {"execute", 'e', 0, G_OPTION_ARG_STRING, &seed_interpreter_arg_exec_string,
- "Pass program in as string", "expression"},
- {NULL,},
+ { "version", 0, 0, G_OPTION_ARG_NONE, &seed_interpreter_arg_print_version,
+ "Print interpreter version", 0 },
+ { "execute", 'e', 0, G_OPTION_ARG_STRING, &seed_interpreter_arg_exec_string,
+ "Pass program in as string", "expression" },
+ {
+ NULL,
+ },
};
-
-static GOptionGroup *
-seed_interpreter_get_option_group (void)
+static GOptionGroup*
+seed_interpreter_get_option_group(void)
{
- GOptionGroup *group;
+ GOptionGroup* group;
- group = g_option_group_new ("seed-interpreter", "Interpreter Options",
- "Show Interpreter Options", NULL, NULL);
- g_option_group_add_entries (group, seed_args);
+ group = g_option_group_new("seed-interpreter", "Interpreter Options",
+ "Show Interpreter Options", NULL, NULL);
+ g_option_group_add_entries(group, seed_args);
- return group;
+ return group;
}
gboolean
-seed_interpreter_parse_args (int *argc, char ***argv)
+seed_interpreter_parse_args(int* argc, char*** argv)
{
- GOptionContext *option_context;
- GOptionGroup *interpreter_group;
+ GOptionContext* option_context;
+ GOptionGroup* interpreter_group;
- GError *error = NULL;
- gboolean ret = TRUE;
+ GError* error = NULL;
+ gboolean ret = TRUE;
- option_context = g_option_context_new (NULL);
- g_option_context_set_ignore_unknown_options (option_context, TRUE);
- g_option_context_set_help_enabled (option_context, TRUE);
+ option_context = g_option_context_new(NULL);
+ g_option_context_set_ignore_unknown_options(option_context, TRUE);
+ g_option_context_set_help_enabled(option_context, TRUE);
- /* Initiate any command line options from the backend */
+ /* Initiate any command line options from the backend */
- interpreter_group = seed_interpreter_get_option_group ();
- g_option_context_set_main_group (option_context, interpreter_group);
- g_option_context_add_group (option_context, seed_get_option_group ());
+ interpreter_group = seed_interpreter_get_option_group();
+ g_option_context_set_main_group(option_context, interpreter_group);
+ g_option_context_add_group(option_context, seed_get_option_group());
- if (!g_option_context_parse (option_context, argc, argv, &error))
- {
- if (error)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
+ if (!g_option_context_parse(option_context, argc, argv, &error)) {
+ if (error) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ }
- ret = FALSE;
+ ret = FALSE;
}
- g_option_context_free (option_context);
+ g_option_context_free(option_context);
- return ret;
+ return ret;
}
diff --git a/src/main.c b/src/main.c
index 81e7915..317121e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -27,140 +27,128 @@
#define DEFAULT_PATH "."
-SeedEngine *eng;
+SeedEngine* eng;
gboolean seed_interpreter_arg_print_version;
-gchar *seed_interpreter_arg_exec_string;
+gchar* seed_interpreter_arg_exec_string;
-gboolean seed_interpreter_parse_args (int *argc, char ***argv);
+gboolean seed_interpreter_parse_args(int* argc, char*** argv);
static void
-seed_repl ()
+seed_repl()
{
- SeedScript *script;
- SeedException e;
+ SeedScript* script;
+ SeedException e;
- script = seed_make_script (eng->context, "repl = imports.repl", NULL, 0);
+ script = seed_make_script(eng->context, "repl = imports.repl", NULL, 0);
- if ((e = seed_script_exception (script)))
- {
- g_critical ("%s", seed_exception_to_string (eng->context, e));
- exit (EXIT_FAILURE);
+ if ((e = seed_script_exception(script))) {
+ g_critical("%s", seed_exception_to_string(eng->context, e));
+ exit(EXIT_FAILURE);
}
- seed_evaluate (eng->context, script, 0);
+ seed_evaluate(eng->context, script, 0);
- if ((e = seed_script_exception (script)))
- {
- g_critical ("%s", seed_exception_to_string (eng->context, e));
- exit (EXIT_FAILURE);
+ if ((e = seed_script_exception(script))) {
+ g_critical("%s", seed_exception_to_string(eng->context, e));
+ exit(EXIT_FAILURE);
}
- g_free (script);
+ g_free(script);
}
static void
-seed_exec (gchar * filename)
+seed_exec(gchar* filename)
{
- SeedObject global;
- SeedScript *script;
- SeedException e;
- gchar *buffer;
+ SeedObject global;
+ SeedScript* script;
+ SeedException e;
+ gchar* buffer;
- g_file_get_contents (filename, &buffer, 0, 0);
+ g_file_get_contents(filename, &buffer, 0, 0);
- if (!buffer)
- {
- g_critical ("File %s not found!", filename);
- exit (EXIT_FAILURE);
+ if (!buffer) {
+ g_critical("File %s not found!", filename);
+ exit(EXIT_FAILURE);
}
- if (*buffer == '#')
- {
- while (*buffer != '\n')
- buffer++;
- buffer++;
+ if (*buffer == '#') {
+ while (*buffer != '\n')
+ buffer++;
+ buffer++;
}
- script = seed_make_script (eng->context, buffer, filename, 1);
+ script = seed_make_script(eng->context, buffer, filename, 1);
- if ((e = seed_script_exception (script)))
- {
- g_critical ("%s", seed_exception_to_string (eng->context, e));
- exit (EXIT_FAILURE);
+ if ((e = seed_script_exception(script))) {
+ g_critical("%s", seed_exception_to_string(eng->context, e));
+ exit(EXIT_FAILURE);
}
- global = seed_context_get_global_object (eng->context);
- seed_importer_add_global (global, filename);
+ global = seed_context_get_global_object(eng->context);
+ seed_importer_add_global(global, filename);
- seed_evaluate (eng->context, script, 0);
- if ((e = seed_script_exception (script)))
- {
- g_critical ("%s", seed_exception_to_string (eng->context, e));
- exit (EXIT_FAILURE);
+ seed_evaluate(eng->context, script, 0);
+ if ((e = seed_script_exception(script))) {
+ g_critical("%s", seed_exception_to_string(eng->context, e));
+ exit(EXIT_FAILURE);
}
- g_free (script);
+ g_free(script);
}
static void
-seed_exec_str ()
+seed_exec_str()
{
- SeedException e = NULL;
- SeedValue val;
- gchar *val_str;
-
- val =
- seed_simple_evaluate (eng->context, seed_interpreter_arg_exec_string, &e);
-
- if (e)
- {
- g_critical ("%s", seed_exception_to_string (eng->context, e));
- exit (EXIT_FAILURE);
+ SeedException e = NULL;
+ SeedValue val;
+ gchar* val_str;
+
+ val = seed_simple_evaluate(eng->context, seed_interpreter_arg_exec_string,
+ &e);
+
+ if (e) {
+ g_critical("%s", seed_exception_to_string(eng->context, e));
+ exit(EXIT_FAILURE);
+ } else {
+ val_str = seed_value_to_string(eng->context, val, &e);
+ if (e) {
+ g_critical("%s", seed_exception_to_string(eng->context, e));
+ exit(EXIT_FAILURE);
+ }
+
+ g_print("%s\n", val_str);
+ g_free(seed_interpreter_arg_exec_string);
+ g_free(val_str);
+
+ exit(EXIT_SUCCESS);
}
- else
- {
- val_str = seed_value_to_string (eng->context, val, &e);
- if (e)
- {
- g_critical ("%s", seed_exception_to_string (eng->context, e));
- exit (EXIT_FAILURE);
- }
-
- g_print ("%s\n", val_str);
- g_free (seed_interpreter_arg_exec_string);
- g_free (val_str);
-
- exit (EXIT_SUCCESS);
- }
-
}
gint
-main (gint argc, gchar ** argv)
+main(gint argc, gchar** argv)
{
- g_set_prgname ("seed");
+ g_set_prgname("seed");
#if !GLIB_CHECK_VERSION(2, 32, 0)
- g_thread_init (NULL);
+ g_thread_init(NULL);
#endif
- seed_interpreter_parse_args (&argc, &argv);
+ seed_interpreter_parse_args(&argc, &argv);
- if (seed_interpreter_arg_print_version)
- {
- g_print ("%s\n", "Seed " VERSION);
- exit (EXIT_SUCCESS);
+ if (seed_interpreter_arg_print_version) {
+ g_print("%s\n", "Seed " VERSION);
+ exit(EXIT_SUCCESS);
}
- eng = seed_init (&argc, &argv);
+ eng = seed_init(&argc, &argv);
- seed_engine_set_search_path (eng, DEFAULT_PATH);
+ seed_engine_set_search_path(eng, DEFAULT_PATH);
- if (seed_interpreter_arg_exec_string)
- seed_exec_str ();
- else if (argc == 1)
- seed_repl ();
- else
- seed_exec (argv[1]);
+ if (seed_interpreter_arg_exec_string)
+ seed_exec_str();
+ else if (argc == 1)
+ seed_repl();
+ else
+ seed_exec(argv[1]);
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
diff --git a/tests/c/api-closure.c b/tests/c/api-closure.c
index 44939a5..ae8c13f 100644
--- a/tests/c/api-closure.c
+++ b/tests/c/api-closure.c
@@ -20,46 +20,50 @@
#include "../../libseed/seed.h"
#include "test-common.h"
-SeedValue do_some_math(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- size_t argument_count,
- const SeedValue arguments[], SeedException * exception)
+SeedValue
+do_some_math(SeedContext ctx,
+ SeedObject function,
+ SeedObject this_object,
+ size_t argument_count,
+ const SeedValue arguments[],
+ SeedException* exception)
{
- g_assert(argument_count == 4);
+ g_assert(argument_count == 4);
- guint a = seed_value_to_uint(ctx, arguments[0], NULL);
- gdouble b = seed_value_to_int(ctx, arguments[1], NULL);
- gint c = seed_value_to_int(ctx, arguments[2], NULL);
- gchar *d = seed_value_to_string(ctx, arguments[3], NULL);
+ guint a = seed_value_to_uint(ctx, arguments[0], NULL);
+ gdouble b = seed_value_to_int(ctx, arguments[1], NULL);
+ gint c = seed_value_to_int(ctx, arguments[2], NULL);
+ gchar* d = seed_value_to_string(ctx, arguments[3], NULL);
- g_assert(d[0] == 'a');
+ g_assert(d[0] == 'a');
- return seed_value_from_double(ctx, (a + b) / c, NULL);
+ return seed_value_from_double(ctx, (a + b) / c, NULL);
}
-void closures(TestSimpleFixture * fixture, gconstpointer _data)
+void
+closures(TestSimpleFixture* fixture, gconstpointer _data)
{
- TestSharedState *state = (TestSharedState *) _data;
+ TestSharedState* state = (TestSharedState*) _data;
- seed_create_function(state->eng->context, "do_some_math",
- (SeedFunctionCallback) do_some_math,
- (SeedObject) state->eng->global);
+ seed_create_function(state->eng->context, "do_some_math",
+ (SeedFunctionCallback) do_some_math,
+ (SeedObject) state->eng->global);
- SeedValue *val = seed_simple_evaluate(state->eng->context,
- "do_some_math(5, 8.66, -2,
'a')", NULL);
- g_assert(seed_value_to_double(state->eng->context, val, NULL) == -6.5);
+ SeedValue* val
+ = seed_simple_evaluate(state->eng->context,
+ "do_some_math(5, 8.66, -2, 'a')", NULL);
+ g_assert(seed_value_to_double(state->eng->context, val, NULL) == -6.5);
- SeedObject *dsm_obj = seed_object_get_property(state->eng->context,
-
(SeedObject) state->eng->
- global,
-
"do_some_math");
- SeedValue args[4];
- args[0] = seed_value_from_uint(state->eng->context, 5, NULL);
- args[1] = seed_value_from_double(state->eng->context, 8.66, NULL);
- args[2] = seed_value_from_int(state->eng->context, -2, NULL);
- args[3] = seed_value_from_string(state->eng->context, "a", NULL);
- val = seed_object_call(state->eng->context, dsm_obj, NULL, 4, args, NULL);
+ SeedObject* dsm_obj
+ = seed_object_get_property(state->eng->context,
+ (SeedObject) state->eng->global,
+ "do_some_math");
+ SeedValue args[4];
+ args[0] = seed_value_from_uint(state->eng->context, 5, NULL);
+ args[1] = seed_value_from_double(state->eng->context, 8.66, NULL);
+ args[2] = seed_value_from_int(state->eng->context, -2, NULL);
+ args[3] = seed_value_from_string(state->eng->context, "a", NULL);
+ val = seed_object_call(state->eng->context, dsm_obj, NULL, 4, args, NULL);
- g_assert(seed_value_to_double(state->eng->context, val, NULL) == -6.5);
+ g_assert(seed_value_to_double(state->eng->context, val, NULL) == -6.5);
}
diff --git a/tests/c/api-js-signal-from-c.c b/tests/c/api-js-signal-from-c.c
index b16c1ff..534d9b7 100644
--- a/tests/c/api-js-signal-from-c.c
+++ b/tests/c/api-js-signal-from-c.c
@@ -22,46 +22,52 @@
#include <string.h>
-gdouble hello_cb(gpointer w, gint a, gchar * b)
+gdouble
+hello_cb(gpointer w, gint a, gchar* b)
{
- g_assert(a == 2);
- g_assert(strncmp(b, "Test", 4) == 0);
+ g_assert(a == 2);
+ g_assert(strncmp(b, "Test", 4) == 0);
- return 5.12;
+ return 5.12;
}
-void js_signal_from_c(TestSimpleFixture * fixture, gconstpointer _data)
+void
+js_signal_from_c(TestSimpleFixture* fixture, gconstpointer _data)
{
- TestSharedState *state = (TestSharedState *) _data;
+ TestSharedState* state = (TestSharedState*) _data;
- SeedValue *val = seed_simple_evaluate(state->eng->context,
- "Gtk = imports.gi.Gtk;"
- "GObject = imports.gi.GObject;"
- "Gtk.init(null, null);"
- "HelloWindowType = {"
- " parent: Gtk.Window.type,"
- " name: \"HelloWindow\","
- " class_init: function(klass, prototype)"
- " {"
- " var HelloSignalDefinition = {name: \"hello\","
- "
parameters: [GObject.TYPE_INT,"
- "
GObject.TYPE_STRING],"
- "
return_type: GObject.TYPE_DOUBLE};"
- " hello_signal_id =
klass.install_signal(HelloSignalDefinition);"
- " },"
- " init: function(instance)"
- " {"
- " }};"
- "HelloWindow = new GType(HelloWindowType);"
- "w = new HelloWindow();", NULL);
+ SeedValue* val = seed_simple_evaluate(
+ state->eng->context,
+ "Gtk = imports.gi.Gtk;"
+ "GObject = imports.gi.GObject;"
+ "Gtk.init(null, null);"
+ "HelloWindowType = {"
+ " parent: Gtk.Window.type,"
+ " name: \"HelloWindow\","
+ " class_init: function(klass, prototype)"
+ " {"
+ " var HelloSignalDefinition = {name: \"hello\","
+ " "
+ "parameters: [GObject.TYPE_INT,"
+ " "
+ " GObject.TYPE_STRING],"
+ " "
+ "return_type: GObject.TYPE_DOUBLE};"
+ " hello_signal_id = klass.install_signal(HelloSignalDefinition);"
+ " },"
+ " init: function(instance)"
+ " {"
+ " }};"
+ "HelloWindow = new GType(HelloWindowType);"
+ "w = new HelloWindow();",
+ NULL);
- GObject *obj = seed_value_to_object(state->eng->context, val, NULL);
+ GObject* obj = seed_value_to_object(state->eng->context, val, NULL);
- g_signal_connect(obj, "hello", G_CALLBACK(hello_cb), NULL);
+ g_signal_connect(obj, "hello", G_CALLBACK(hello_cb), NULL);
- val =
- seed_simple_evaluate(state->eng->context,
- "g = w.signal.hello.emit(2,'Test')", NULL);
+ val = seed_simple_evaluate(state->eng->context,
+ "g = w.signal.hello.emit(2,'Test')", NULL);
- g_assert(seed_value_to_double(state->eng->context, val, NULL) == 5.12);
+ g_assert(seed_value_to_double(state->eng->context, val, NULL) == 5.12);
}
diff --git a/tests/c/api-types.c b/tests/c/api-types.c
index 4d6bbde..560bf47 100644
--- a/tests/c/api-types.c
+++ b/tests/c/api-types.c
@@ -23,149 +23,144 @@
// The biggest problem here is everything gets cast to a double in JSCore!
-void basic_types(TestSimpleFixture * fixture, gconstpointer _data)
+void
+basic_types(TestSimpleFixture* fixture, gconstpointer _data)
{
- // bool to/from JS equality
+ // bool to/from JS equality
- gboolean bool_test_in = TRUE;
- SeedValue *bool_test = seed_value_from_boolean(fixture->context,
-
bool_test_in, NULL);
- gboolean bool_test_out = seed_value_to_boolean(fixture->context,
- bool_test,
NULL);
+ gboolean bool_test_in = TRUE;
+ SeedValue* bool_test
+ = seed_value_from_boolean(fixture->context, bool_test_in, NULL);
+ gboolean bool_test_out
+ = seed_value_to_boolean(fixture->context, bool_test, NULL);
- g_assert(bool_test_in == bool_test_out);
+ g_assert(bool_test_in == bool_test_out);
- // uint to/from JS equality
+ // uint to/from JS equality
- guint uint_test_in = 2946623;
- SeedValue *uint_test = seed_value_from_uint(fixture->context,
- uint_test_in,
NULL);
- guint uint_test_out = seed_value_to_uint(fixture->context,
- uint_test, NULL);
+ guint uint_test_in = 2946623;
+ SeedValue* uint_test
+ = seed_value_from_uint(fixture->context, uint_test_in, NULL);
+ guint uint_test_out = seed_value_to_uint(fixture->context, uint_test, NULL);
- g_assert(uint_test_in == uint_test_out);
+ g_assert(uint_test_in == uint_test_out);
- // int to/from JS equality
+ // int to/from JS equality
- gint int_test_in = -54374;
- SeedValue *int_test = seed_value_from_int(fixture->context,
- int_test_in, NULL);
- gint int_test_out = seed_value_to_int(fixture->context,
- int_test, NULL);
+ gint int_test_in = -54374;
+ SeedValue* int_test
+ = seed_value_from_int(fixture->context, int_test_in, NULL);
+ gint int_test_out = seed_value_to_int(fixture->context, int_test, NULL);
- g_assert(int_test_in == int_test_out);
+ g_assert(int_test_in == int_test_out);
- // char to/from JS equality
+ // char to/from JS equality
- gchar char_test_in = -126;
- SeedValue *char_test = seed_value_from_char(fixture->context,
- char_test_in,
NULL);
- gchar char_test_out = seed_value_to_char(fixture->context,
- char_test, NULL);
+ gchar char_test_in = -126;
+ SeedValue* char_test
+ = seed_value_from_char(fixture->context, char_test_in, NULL);
+ gchar char_test_out = seed_value_to_char(fixture->context, char_test, NULL);
- g_assert(char_test_in == char_test_out);
+ g_assert(char_test_in == char_test_out);
- // uchar to/from JS equality
+ // uchar to/from JS equality
- guchar uchar_test_in = 250;
- SeedValue *uchar_test = seed_value_from_uchar(fixture->context,
-
uchar_test_in, NULL);
- guchar uchar_test_out = seed_value_to_uchar(fixture->context,
- uchar_test,
NULL);
+ guchar uchar_test_in = 250;
+ SeedValue* uchar_test
+ = seed_value_from_uchar(fixture->context, uchar_test_in, NULL);
+ guchar uchar_test_out
+ = seed_value_to_uchar(fixture->context, uchar_test, NULL);
- g_assert(uchar_test_in == uchar_test_out);
+ g_assert(uchar_test_in == uchar_test_out);
- // long to/from JS equality
+ // long to/from JS equality
- glong long_test_in = -454250;
- SeedValue *long_test = seed_value_from_long(fixture->context,
- long_test_in,
NULL);
- glong long_test_out = seed_value_to_long(fixture->context,
- long_test, NULL);
+ glong long_test_in = -454250;
+ SeedValue* long_test
+ = seed_value_from_long(fixture->context, long_test_in, NULL);
+ glong long_test_out = seed_value_to_long(fixture->context, long_test, NULL);
- g_assert(long_test_in == long_test_out);
+ g_assert(long_test_in == long_test_out);
- // ulong to/from JS equality
+ // ulong to/from JS equality
- gulong ulong_test_in = 250;
- SeedValue *ulong_test = seed_value_from_ulong(fixture->context,
-
ulong_test_in, NULL);
- gulong ulong_test_out = seed_value_to_ulong(fixture->context,
- ulong_test,
NULL);
+ gulong ulong_test_in = 250;
+ SeedValue* ulong_test
+ = seed_value_from_ulong(fixture->context, ulong_test_in, NULL);
+ gulong ulong_test_out
+ = seed_value_to_ulong(fixture->context, ulong_test, NULL);
- g_assert(ulong_test_in == ulong_test_out);
+ g_assert(ulong_test_in == ulong_test_out);
- // int64 to/from JS equality
+ // int64 to/from JS equality
- gint64 int64_test_in = -54374;
- SeedValue *int64_test = seed_value_from_int64(fixture->context,
-
int64_test_in, NULL);
- gint64 int64_test_out = seed_value_to_int64(fixture->context,
- int64_test,
NULL);
+ gint64 int64_test_in = -54374;
+ SeedValue* int64_test
+ = seed_value_from_int64(fixture->context, int64_test_in, NULL);
+ gint64 int64_test_out
+ = seed_value_to_int64(fixture->context, int64_test, NULL);
- g_assert(int64_test_in == int64_test_out);
+ g_assert(int64_test_in == int64_test_out);
- // uint64 to/from JS equality
+ // uint64 to/from JS equality
- guint64 uint64_test_in = 2946623;
- SeedValue *uint64_test = seed_value_from_uint64(fixture->context,
-
uint64_test_in, NULL);
- guint64 uint64_test_out = seed_value_to_uint64(fixture->context,
-
uint64_test, NULL);
+ guint64 uint64_test_in = 2946623;
+ SeedValue* uint64_test
+ = seed_value_from_uint64(fixture->context, uint64_test_in, NULL);
+ guint64 uint64_test_out
+ = seed_value_to_uint64(fixture->context, uint64_test, NULL);
- g_assert(uint64_test_in == uint64_test_out);
+ g_assert(uint64_test_in == uint64_test_out);
- // float to/from JS equality
+ // float to/from JS equality
- gfloat float_test_in = 1.618;
- SeedValue *float_test = seed_value_from_float(fixture->context,
-
float_test_in, NULL);
- gfloat float_test_out = seed_value_to_float(fixture->context,
- float_test,
NULL);
+ gfloat float_test_in = 1.618;
+ SeedValue* float_test
+ = seed_value_from_float(fixture->context, float_test_in, NULL);
+ gfloat float_test_out
+ = seed_value_to_float(fixture->context, float_test, NULL);
- g_assert(float_test_in == float_test_out);
+ g_assert(float_test_in == float_test_out);
- // double to/from JS equality
+ // double to/from JS equality
- gdouble double_test_in = 1.6134857638;
- SeedValue *double_test = seed_value_from_double(fixture->context,
-
double_test_in, NULL);
- gdouble double_test_out = seed_value_to_double(fixture->context,
-
double_test, NULL);
+ gdouble double_test_in = 1.6134857638;
+ SeedValue* double_test
+ = seed_value_from_double(fixture->context, double_test_in, NULL);
+ gdouble double_test_out
+ = seed_value_to_double(fixture->context, double_test, NULL);
- g_assert(double_test_in == double_test_out);
+ g_assert(double_test_in == double_test_out);
- // string to/from JS equality
+ // string to/from JS equality
- gchar *string_test_in = "Hello, world!";
- SeedValue *string_test = seed_value_from_string(fixture->context,
-
string_test_in, NULL);
- gchar *string_test_out = seed_value_to_string(fixture->context,
-
string_test, NULL);
+ gchar* string_test_in = "Hello, world!";
+ SeedValue* string_test
+ = seed_value_from_string(fixture->context, string_test_in, NULL);
+ gchar* string_test_out
+ = seed_value_to_string(fixture->context, string_test, NULL);
- g_assert(strncmp(string_test_in, string_test_out,
- strlen(string_test_in)) == 0);
+ g_assert(strncmp(string_test_in, string_test_out, strlen(string_test_in))
+ == 0);
- // filename to/from JS equality
+ // filename to/from JS equality
- gchar *filename_test_in = "/bin";
- SeedValue *filename_test = seed_value_from_filename(fixture->context,
-
filename_test_in,
-
NULL);
- gchar *filename_test_out = seed_value_to_filename(fixture->context,
-
filename_test, NULL);
-
- g_assert(strncmp(filename_test_in, filename_test_out,
- strlen(filename_test_in)) == 0);
- SeedValue si[2];
- si[0] = seed_value_from_string (fixture->context, "Hi", NULL);
- si[1] = seed_value_from_int (fixture->context, 1, NULL);
- gint ni;
- gchar *ns;
-
- seed_value_to_format (fixture->context, "si", si, NULL, &ns, &ni, NULL);
- g_assert (ni == 1);
- g_assert (!strcmp(ns, "Hi"));
+ gchar* filename_test_in = "/bin";
+ SeedValue* filename_test
+ = seed_value_from_filename(fixture->context, filename_test_in, NULL);
+ gchar* filename_test_out
+ = seed_value_to_filename(fixture->context, filename_test, NULL);
+ g_assert(
+ strncmp(filename_test_in, filename_test_out, strlen(filename_test_in))
+ == 0);
+ SeedValue si[2];
+ si[0] = seed_value_from_string(fixture->context, "Hi", NULL);
+ si[1] = seed_value_from_int(fixture->context, 1, NULL);
+ gint ni;
+ gchar* ns;
+ seed_value_to_format(fixture->context, "si", si, NULL, &ns, &ni, NULL);
+ g_assert(ni == 1);
+ g_assert(!strcmp(ns, "Hi"));
}
diff --git a/tests/c/basic.c b/tests/c/basic.c
index 14c6809..3c75046 100644
--- a/tests/c/basic.c
+++ b/tests/c/basic.c
@@ -20,7 +20,8 @@
#include "../../libseed/seed.h"
#include "test-common.h"
-void basic(TestSimpleFixture * fixture, gconstpointer _data)
+void
+basic(TestSimpleFixture* fixture, gconstpointer _data)
{
- g_assert(1);
+ g_assert(1);
}
diff --git a/tests/c/main.c b/tests/c/main.c
index 03b406d..013f39d 100644
--- a/tests/c/main.c
+++ b/tests/c/main.c
@@ -23,50 +23,47 @@
// Test stuff stolen from Clutter
-#define TEST_SIMPLE(NAMESPACE, FUNC) \
- extern void FUNC (TestSimpleFixture *fixture, gconstpointer data); \
- g_test_add (NAMESPACE "/" #FUNC, \
- TestSimpleFixture, \
- shared_state, \
- test_simple_fixture_setup, \
- FUNC, \
- test_simple_fixture_teardown);
+#define TEST_SIMPLE(NAMESPACE, FUNC) \
+ extern void FUNC(TestSimpleFixture* fixture, gconstpointer data); \
+ g_test_add(NAMESPACE "/" #FUNC, TestSimpleFixture, shared_state, \
+ test_simple_fixture_setup, FUNC, test_simple_fixture_teardown);
-void test_simple_fixture_setup(TestSimpleFixture * fixture, gconstpointer data)
+void
+test_simple_fixture_setup(TestSimpleFixture* fixture, gconstpointer data)
{
- TestSharedState *state = (TestSharedState *) data;
- fixture->context = seed_context_create(state->eng->group, NULL);
+ TestSharedState* state = (TestSharedState*) data;
+ fixture->context = seed_context_create(state->eng->group, NULL);
}
-void test_simple_fixture_teardown(TestSimpleFixture * fixture,
- gconstpointer data)
+void
+test_simple_fixture_teardown(TestSimpleFixture* fixture, gconstpointer data)
{
- seed_context_unref(fixture->context);
+ seed_context_unref(fixture->context);
}
-int main(int argc, char **argv)
+int
+main(int argc, char** argv)
{
- TestSharedState *shared_state = g_new0(TestSharedState, 1);
- const gchar *display = g_getenv("DISPLAY");
+ TestSharedState* shared_state = g_new0(TestSharedState, 1);
+ const gchar* display = g_getenv("DISPLAY");
- if (!display || *display == '\0')
- {
- g_print("No DISPLAY found. Unable to run the test suite without X11.");
- return EXIT_SUCCESS;
+ if (!display || *display == '\0') {
+ g_print("No DISPLAY found. Unable to run the test suite without X11.");
+ return EXIT_SUCCESS;
}
- g_test_init(&argc, &argv, NULL);
+ g_test_init(&argc, &argv, NULL);
- SeedEngine *eng = seed_init(NULL, NULL);
+ SeedEngine* eng = seed_init(NULL, NULL);
- shared_state->argc_addr = &argc;
- shared_state->argv_addr = &argv;
- shared_state->eng = eng;
+ shared_state->argc_addr = &argc;
+ shared_state->argv_addr = &argv;
+ shared_state->eng = eng;
- TEST_SIMPLE("/", basic);
- TEST_SIMPLE("/", closures);
- TEST_SIMPLE("/types/", basic_types);
- TEST_SIMPLE("/js-signal-from-c/", js_signal_from_c);
+ TEST_SIMPLE("/", basic);
+ TEST_SIMPLE("/", closures);
+ TEST_SIMPLE("/types/", basic_types);
+ TEST_SIMPLE("/js-signal-from-c/", js_signal_from_c);
- return g_test_run();
+ return g_test_run();
}
diff --git a/tests/c/test-common.h b/tests/c/test-common.h
index e70cfe0..5c0b6a5 100644
--- a/tests/c/test-common.h
+++ b/tests/c/test-common.h
@@ -2,16 +2,18 @@
/* Stuff you put in here is setup once in main() and gets passed around to
* all test functions and fixture setup/teardown functions in the data
* argument */
-typedef struct _TestSharedState {
- int *argc_addr;
- char ***argv_addr;
- SeedEngine *eng;
+typedef struct _TestSharedState
+{
+ int* argc_addr;
+ char*** argv_addr;
+ SeedEngine* eng;
} TestSharedState;
/* This fixture structure is allocated by glib, and before running each test
* the test_conform_simple_fixture_setup func (see below) is called to
* initialise it, and test_conform_simple_fixture_teardown is called when
* the test is finished. */
-typedef struct _TestSimpleFixture {
- SeedContext *context;
+typedef struct _TestSimpleFixture
+{
+ SeedContext* context;
} TestSimpleFixture;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]