gjs r84 - in trunk: . gi test/js
- From: tko svn gnome org
- To: svn-commits-list gnome org
- Subject: gjs r84 - in trunk: . gi test/js
- Date: Tue, 11 Nov 2008 18:02:11 +0000 (UTC)
Author: tko
Date: Tue Nov 11 18:02:11 2008
New Revision: 84
URL: http://svn.gnome.org/viewvc/gjs?rev=84&view=rev
Log:
Bug 558148 â 'const char*' in arguments are leaked
* gi/arg.c (gjs_g_arg_release_in_arg):
* gi/arg.h: add function for releasing in args
* gi/function.c (gjs_invoke_c_function): release in args that
may have been allocated for the invocation only
* Makefile-test.am:
* test/js/testGI.js (testUTF8): add test that exposes the leak
Added:
trunk/test/js/testGI.js
Modified:
trunk/Makefile-test.am
trunk/gi/arg.c
trunk/gi/arg.h
trunk/gi/function.c
Modified: trunk/Makefile-test.am
==============================================================================
--- trunk/Makefile-test.am (original)
+++ trunk/Makefile-test.am Tue Nov 11 18:02:11 2008
@@ -106,6 +106,7 @@
test/js/modules/jsUnit.js \
test/js/testself.js \
test/js/testEverythingBasic.js \
+ test/js/testGI.js \
test/js/testImporter.js \
test/js/testLang.js \
test/js/testMainloop.js \
Modified: trunk/gi/arg.c
==============================================================================
--- trunk/gi/arg.c (original)
+++ trunk/gi/arg.c Tue Nov 11 18:02:11 2008
@@ -998,3 +998,34 @@
return gjs_g_arg_release_internal(context, transfer, type_info, type_tag, arg);
}
+
+JSBool
+gjs_g_arg_release_in_arg(JSContext *context,
+ GITransfer transfer,
+ GITypeInfo *type_info,
+ GArgument *arg)
+{
+ GITypeTag type_tag;
+
+ /* we don't own the argument anymore */
+ if (transfer == GI_TRANSFER_EVERYTHING)
+ return;
+
+ type_tag = g_type_info_get_tag( (GITypeInfo*) type_info);
+
+ gjs_debug_marshal(GJS_DEBUG_GFUNCTION,
+ "Releasing GArgument %s in param",
+ g_type_tag_to_string(type_tag));
+
+ /* release all (temporary) arguments we allocated from JS types */
+ /* FIXME: check with lists, arrays, boxed types, objects, ... */
+
+ switch (type_tag) {
+ case GI_TYPE_TAG_UTF8:
+ return gjs_g_arg_release_internal(context, GI_TRANSFER_EVERYTHING,
+ type_info, type_tag, arg);
+ }
+
+ return JS_TRUE;
+}
+
Modified: trunk/gi/arg.h
==============================================================================
--- trunk/gi/arg.h (original)
+++ trunk/gi/arg.h Tue Nov 11 18:02:11 2008
@@ -44,6 +44,10 @@
GITransfer transfer,
GITypeInfo *type_info,
GArgument *arg);
+JSBool gjs_g_arg_release_in_arg (JSContext *context,
+ GITransfer transfer,
+ GITypeInfo *type_info,
+ GArgument *arg);
JSBool _gjs_flags_value_is_valid (JSContext *context,
GFlagsClass *klass,
Modified: trunk/gi/function.c
==============================================================================
--- trunk/gi/function.c (original)
+++ trunk/gi/function.c Tue Nov 11 18:02:11 2008
@@ -279,8 +279,8 @@
}
}
- /* We walk over all args (not just out args) and skip
- * the non-out args
+ /* We walk over all args, release in args (if allocated) and convert
+ * all out args to JS
*/
in_args_pos = is_method ? 1 : 0; /* index into in_args */
out_args_pos = 0; /* into out_args */
@@ -298,6 +298,12 @@
if (direction == GI_DIRECTION_IN) {
g_assert(in_args_pos < expected_in_argc);
+ if (!gjs_g_arg_release_in_arg(context,
+ g_arg_info_get_ownership_transfer(arg_info),
+ arg_type_info,
+ &in_args[in_args_pos]))
+ failed = TRUE;
+
++in_args_pos;
} else {
/* INOUT or OUT */
Added: trunk/test/js/testGI.js
==============================================================================
--- (empty file)
+++ trunk/test/js/testGI.js Tue Nov 11 18:02:11 2008
@@ -0,0 +1,7 @@
+function testUTF8() {
+ const GLib = imports.gi.GLib;
+
+ assertEquals(0x2664, GLib.utf8_get_char("\u2664 utf8"));
+}
+
+gjstestRun();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]