<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/gjs.git/gi/function.cpp, branch includes</title>
<subtitle>gitlab.gnome.org: GNOME/gjs.git
</subtitle>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/'/>
<entry>
<title>CI: Fix IWYU includes</title>
<updated>2020-09-20T19:24:08+00:00</updated>
<author>
<name>Philip Chimento</name>
<email>philip.chimento@gmail.com</email>
</author>
<published>2020-09-20T05:14:52+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/commit/?id=19e519aad8ffc65e39c6095575ed66ff8d257cca'/>
<id>19e519aad8ffc65e39c6095575ed66ff8d257cca</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'ewlsh/fix-leak' into 'master'</title>
<updated>2020-09-10T05:40:35+00:00</updated>
<author>
<name>Philip Chimento</name>
<email>philip.chimento@gmail.com</email>
</author>
<published>2020-09-10T05:40:35+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/commit/?id=99116181449771f3a86c634c45760a9d26e869c1'/>
<id>99116181449771f3a86c634c45760a9d26e869c1</id>
<content type='text'>
Fix leak when virtual function is unimplemented.

See merge request GNOME/gjs!498</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Fix leak when virtual function is unimplemented.

See merge request GNOME/gjs!498</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'remove-gslice' into 'master'</title>
<updated>2020-09-10T05:33:19+00:00</updated>
<author>
<name>Philip Chimento</name>
<email>philip.chimento@gmail.com</email>
</author>
<published>2020-09-10T05:33:19+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/commit/?id=8836e6ce41f8774cc571239f4a34f77d648f1f6f'/>
<id>8836e6ce41f8774cc571239f4a34f77d648f1f6f</id>
<content type='text'>
cleanup: Don't use GSlice anywhere

See merge request GNOME/gjs!488</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
cleanup: Don't use GSlice anywhere

See merge request GNOME/gjs!488</pre>
</div>
</content>
</entry>
<entry>
<title>function: Assert the presency of function info only if we've arguments</title>
<updated>2020-09-09T23:36:47+00:00</updated>
<author>
<name>Marco Trevisan (Treviño)</name>
<email>mail@3v1n0.net</email>
</author>
<published>2020-09-07T18:09:21+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/commit/?id=b126a333fd7ece37308c339ad1c68daa9d51b64c'/>
<id>b126a333fd7ece37308c339ad1c68daa9d51b64c</id>
<content type='text'>
In case the function initialization fails for some reason, we only need
the info function to be set in case we have defined arguments, otherwise
we might have just failed at the early stages of the cache-init function
and nor the GI info or the arguments are set.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In case the function initialization fails for some reason, we only need
the info function to be set in case we have defined arguments, otherwise
we might have just failed at the early stages of the cache-init function
and nor the GI info or the arguments are set.
</pre>
</div>
</content>
</entry>
<entry>
<title>function: Early-initialize arguments cache or we won't ever release them</title>
<updated>2020-09-09T23:36:33+00:00</updated>
<author>
<name>Marco Trevisan (Treviño)</name>
<email>mail@3v1n0.net</email>
</author>
<published>2020-09-07T17:42:49+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/commit/?id=072444c69ffe83993ca351a5b7d9752ba5694086'/>
<id>072444c69ffe83993ca351a5b7d9752ba5694086</id>
<content type='text'>
If we throw during the arguments cache creation as we fail during an early
stage of init_cached_function_data, we don't save the function GICallableInfo
or the already allocated parameters, but we'd just return loosing
track of allocated data.

This is not just a potential leak, but also wrong as if a method
introspection is malformed or not fully supported by gjs, we'd just
assert crashing badly during function unallocation because no function
info is set, instead of just throwing as expected.

As per this, let's save the function private informations (such as the
callable info and the arguments cache) as soon as we allocate them,
and update the number of initialized arguments in real time, so that
we can partially de-allocate the arguments cache in case of errors.
This also implies that during function de-init we must ensure that
we don't overflow using the marshallers pointer to check if we've ever
initialized such argument cache and to figure out how many we've allocated
other than of the total number of the introspected function arguments.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If we throw during the arguments cache creation as we fail during an early
stage of init_cached_function_data, we don't save the function GICallableInfo
or the already allocated parameters, but we'd just return loosing
track of allocated data.

This is not just a potential leak, but also wrong as if a method
introspection is malformed or not fully supported by gjs, we'd just
assert crashing badly during function unallocation because no function
info is set, instead of just throwing as expected.

As per this, let's save the function private informations (such as the
callable info and the arguments cache) as soon as we allocate them,
and update the number of initialized arguments in real time, so that
we can partially de-allocate the arguments cache in case of errors.
This also implies that during function de-init we must ensure that
we don't overflow using the marshallers pointer to check if we've ever
initialized such argument cache and to figure out how many we've allocated
other than of the total number of the introspected function arguments.
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix leak when virtual function is unimplemented.</title>
<updated>2020-09-08T19:29:30+00:00</updated>
<author>
<name>Evan Welsh</name>
<email>noreply@evanwelsh.com</email>
</author>
<published>2020-09-08T19:29:30+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/commit/?id=293e2082b878969cd5269fff5b05931cc494702d'/>
<id>293e2082b878969cd5269fff5b05931cc494702d</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>cleanup: Don't use GSlice anywhere</title>
<updated>2020-09-03T22:53:18+00:00</updated>
<author>
<name>Marco Trevisan (Treviño)</name>
<email>mail@3v1n0.net</email>
</author>
<published>2020-09-02T15:17:07+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/commit/?id=e54ba8eb11bb652e2b9b4126dacc5ccad4752dbb'/>
<id>e54ba8eb11bb652e2b9b4126dacc5ccad4752dbb</id>
<content type='text'>
GSlice API is going to be deprecated [1] and marked as such for some
years now, even if this change didn't happen yet, there's no point to
keep GSlice usage in gjs, considering that we can semplificate it with
calls to system allocator using g_new/g_malloc and g_free.

Once I applied this change, I've noticed that the memory sanitzer found
some leaks in the trampoline code that for some reason GSlice was hiding
and that this commit underlines.

[1] https://gitlab.gnome.org/GNOME/glib/-/issues/1079
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
GSlice API is going to be deprecated [1] and marked as such for some
years now, even if this change didn't happen yet, there's no point to
keep GSlice usage in gjs, considering that we can semplificate it with
calls to system allocator using g_new/g_malloc and g_free.

Once I applied this change, I've noticed that the memory sanitzer found
some leaks in the trampoline code that for some reason GSlice was hiding
and that this commit underlines.

[1] https://gitlab.gnome.org/GNOME/glib/-/issues/1079
</pre>
</div>
</content>
</entry>
<entry>
<title>function: Unref the allocated trampoline if returning early</title>
<updated>2020-09-03T17:02:38+00:00</updated>
<author>
<name>Marco Trevisan (Treviño)</name>
<email>mail@3v1n0.net</email>
</author>
<published>2020-09-02T18:18:25+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/commit/?id=392828eec4824b335e6050db4b3167184da341ea'/>
<id>392828eec4824b335e6050db4b3167184da341ea</id>
<content type='text'>
When creating the trampoline, if we have an early return, we need to
cleanup the allocated memory or we'd leak.

This happens for example during the GObjectClass test "gracefully bails out
when overriding an unsupported vfunc type", where the trampoline
creation fails, but in such case we never free the allocated memory
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When creating the trampoline, if we have an early return, we need to
cleanup the allocated memory or we'd leak.

This happens for example during the GObjectClass test "gracefully bails out
when overriding an unsupported vfunc type", where the trampoline
creation fails, but in such case we never free the allocated memory
</pre>
</div>
</content>
</entry>
<entry>
<title>function: Don't assume FFI argument always matches GIArgument</title>
<updated>2020-08-24T11:03:46+00:00</updated>
<author>
<name>Simon McVittie</name>
<email>smcv@debian.org</email>
</author>
<published>2020-08-23T17:13:17+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/commit/?id=75b9f37136f12ead90d3373ac03fa42e1e394a17'/>
<id>75b9f37136f12ead90d3373ac03fa42e1e394a17</id>
<content type='text'>
Everywhere else in gjs_callback_closure() that writes into result
does so by first converting the JavaScript object into a GIArgument
according to GIArgument conventions, and then copying the GIArgument
into result according to FFI conventions. In particular, for small
integers like enums and flags, the value copied into the GIArgument
is 32-bit, but the value pointed to by result is typically
pointer-sized, which is larger on 64-bit platforms.

However, the code path for vfuncs that fail at the JavaScript level, but
have to return *something* at the C level, was instead treating result as
being a pointer to a GIArgument. Writing a small integer to a GIArgument
only sets the first few bits (the first 32 for enums and flags),
leaving the next 32 bits of a pointer-sized quantity on a 64-bit
platform uninitialized. On little-endian CPUs, if the next 32 bits
happen to already be all-zeroes, the right thing would happen anyway,
but we can't count on that.

In particular, this resulted in the test-case
"Wrong virtual functions marshals an enum return value" in GIMarshalling
failing on big-endian LP64 architectures like s390x, after I fixed the
other code paths involving GArgument and enums/flags for s390x in
commit 1ba19d63 "function: Use GIArgument.v_int for enum and flags types".

This change requires initialization of ret_type_is_void to be moved
further up, so that it occurs before the first "goto out".

Resolves: https://gitlab.gnome.org/GNOME/gjs/-/issues/319
Signed-off-by: Simon McVittie &lt;smcv@debian.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Everywhere else in gjs_callback_closure() that writes into result
does so by first converting the JavaScript object into a GIArgument
according to GIArgument conventions, and then copying the GIArgument
into result according to FFI conventions. In particular, for small
integers like enums and flags, the value copied into the GIArgument
is 32-bit, but the value pointed to by result is typically
pointer-sized, which is larger on 64-bit platforms.

However, the code path for vfuncs that fail at the JavaScript level, but
have to return *something* at the C level, was instead treating result as
being a pointer to a GIArgument. Writing a small integer to a GIArgument
only sets the first few bits (the first 32 for enums and flags),
leaving the next 32 bits of a pointer-sized quantity on a 64-bit
platform uninitialized. On little-endian CPUs, if the next 32 bits
happen to already be all-zeroes, the right thing would happen anyway,
but we can't count on that.

In particular, this resulted in the test-case
"Wrong virtual functions marshals an enum return value" in GIMarshalling
failing on big-endian LP64 architectures like s390x, after I fixed the
other code paths involving GArgument and enums/flags for s390x in
commit 1ba19d63 "function: Use GIArgument.v_int for enum and flags types".

This change requires initialization of ret_type_is_void to be moved
further up, so that it occurs before the first "goto out".

Resolves: https://gitlab.gnome.org/GNOME/gjs/-/issues/319
Signed-off-by: Simon McVittie &lt;smcv@debian.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Prevent unimplemented vfuncs from crashing.</title>
<updated>2020-08-22T23:10:30+00:00</updated>
<author>
<name>Evan Welsh</name>
<email>noreply@evanwelsh.com</email>
</author>
<published>2020-08-22T23:09:22+00:00</published>
<link rel='alternate' type='text/html' href='http://git.baserock.org/cgit/delta/gjs.git/commit/?id=dd2139a6f12b781ce9ff50ec46d33f7eb071a62d'/>
<id>dd2139a6f12b781ce9ff50ec46d33f7eb071a62d</id>
<content type='text'>
It is common for a base class to not implement a virtual
function and leave is as NULL, this currently causes GJS
to crash if subclasses chain up. This change makes it a
recoverable JS-level error.

Fixes #313
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
It is common for a base class to not implement a virtual
function and leave is as NULL, this currently causes GJS
to crash if subclasses chain up. This change makes it a
recoverable JS-level error.

Fixes #313
</pre>
</div>
</content>
</entry>
</feed>
