Merge lp:~gue5t/midori/64-bit-vala-decl into lp:midori

Proposed by gue5t gue5t
Status: Merged
Approved by: Paweł Forysiuk
Approved revision: 6984
Merged at revision: 7023
Proposed branch: lp:~gue5t/midori/64-bit-vala-decl
Merge into: lp:midori
Diff against target: 78 lines (+27/-4)
4 files modified
CMakeLists.txt (+13/-1)
midori/midori-searchaction.h (+3/-0)
midori/midori-view.h (+4/-0)
tests/actions.vala (+7/-3)
To merge this branch: bzr merge lp:~gue5t/midori/64-bit-vala-decl
Reviewer Review Type Date Requested Status
Paweł Forysiuk Approve
Cris Dywan Needs Fixing
Review via email: mp+267466@code.launchpad.net

Commit message

Ensure vala knows the prototypes of functions it calls, fixing pointer truncation in tests

Description of the change

I was getting segfaults when running the 'actions' test despite code that looked perfectly sane. When I investigated in gdb, everything looked good until the function returned--at which point the pointer was getting manged! In the disassembly, I saw a "zero-extend" instruction being used on the pointer, which made no sense. Then I realized that the function being called in Vala, 263midori_view_get_page_context_action, was not declared in a header. This means that in the generated C, the function was implicitly declared. In C, implicit declarations have "int" return type, which is 4 bytes instead of 8 on x86_64. Thus the pointer was converted to an int and back to a pointer, shaving off the top 4 bytes.

Adding a declaration in the header stopped the segfaults. Can we get valac to ask the C compiler to disallow implicit declarations?

To post a comment you must log in.
Revision history for this message
Cris Dywan (kalikiana) wrote :

How about adding -Werror=implicit-function-declaration to VALA_CFLAGS in CmakeLists.txt?

It seems a little odd to me to be asserting the name of the menhu, but I'm guressing you're doing this to dare the pointer to get corrupted... so maybe a sensible resort

review: Needs Information
lp:~gue5t/midori/64-bit-vala-decl updated
6983. By gue5t <email address hidden>

Forbid implicit declarations in valac-generated C and enable non-superfluous warnings; declare midori_search_action_token_for_uri

Revision history for this message
Cris Dywan (kalikiana) wrote :

I'm getting a ton of warnings building this:

./katze/midori-paths.vala:333:10 warning: assignment from incompatible pointer type
 if (strcmp (Environment.get_variable ("MIDORI_DEBUG"), "paths") == 0) {
 ^

cc1: warning: unrecognized command line option "-Wno-discarded-qualifiers"
cc1: warning: unrecognized command line option "-Wno-incompatible-pointer-types"

review: Needs Fixing
Revision history for this message
gue5t gue5t (gue5t) wrote :

Ah, looks like those are new in GCC 5. I'll have to make them conditional on that compiler+version, then.

lp:~gue5t/midori/64-bit-vala-decl updated
6984. By gue5t <email address hidden>

Only enable warnings for Vala with recent versions of GCC and Clang

Revision history for this message
gue5t gue5t (gue5t) wrote :

I've changed it to only enable warnings with recent versions of GCC and Clang; other versions/compilers will just have no warnings from Valac-generated C.

Revision history for this message
Paweł Forysiuk (tuxator) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-07-19 22:25:09 +0000
+++ CMakeLists.txt 2015-08-15 23:41:09 +0000
@@ -255,7 +255,19 @@
255endif ()255endif ()
256256
257# Explicitly add -fPIC for older toolchains257# Explicitly add -fPIC for older toolchains
258set(VALA_CFLAGS "-w -g -fPIC")258set(VALA_CFLAGS "-g -fPIC")
259
260# With compiler versions that can, enable exactly the non-spurious warnings
261# in Vala-generated C, otherwise disable warnings
262if ((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "5.0.0")
263 OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "3.0.0"))
264 set(VALA_CFLAGS "${VALA_CFLAGS} -Werror=implicit-function-declaration")
265 set(VALA_CFLAGS "${VALA_CFLAGS} -Wno-incompatible-pointer-types")
266 set(VALA_CFLAGS "${VALA_CFLAGS} -Wno-discarded-qualifiers")
267 set(VALA_CFLAGS "${VALA_CFLAGS} -Wno-deprecated-declarations")
268else ()
269 set(VALA_CFLAGS "${VALA_CFLAGS} -w")
270endif ()
259271
260set(LIBMIDORI "${CMAKE_PROJECT_NAME}-core")272set(LIBMIDORI "${CMAKE_PROJECT_NAME}-core")
261273
262274
=== modified file 'midori/midori-searchaction.h'
--- midori/midori-searchaction.h 2014-07-24 11:48:46 +0000
+++ midori/midori-searchaction.h 2015-08-15 23:41:09 +0000
@@ -63,6 +63,9 @@
63midori_search_action_set_default_item (MidoriSearchAction* search_action,63midori_search_action_set_default_item (MidoriSearchAction* search_action,
64 KatzeItem* item);64 KatzeItem* item);
6565
66gchar*
67midori_search_action_token_for_uri (const gchar* uri);
68
66GtkWidget*69GtkWidget*
67midori_search_action_get_dialog (MidoriSearchAction* search_action);70midori_search_action_get_dialog (MidoriSearchAction* search_action);
6871
6972
=== modified file 'midori/midori-view.h'
--- midori/midori-view.h 2014-07-26 22:57:50 +0000
+++ midori/midori-view.h 2015-08-15 23:41:09 +0000
@@ -259,6 +259,10 @@
259 GTlsCertificateFlags* tls_flags,259 GTlsCertificateFlags* tls_flags,
260 gchar** hostname);260 gchar** hostname);
261261
262MidoriContextAction*
263midori_view_get_page_context_action (MidoriView* view,
264 WebKitHitTestResult* hit_test_result);
265
262G_END_DECLS266G_END_DECLS
263267
264#endif /* __MIDORI_VIEW_H__ */268#endif /* __MIDORI_VIEW_H__ */
265269
=== modified file 'tests/actions.vala'
--- tests/actions.vala 2013-08-02 23:45:16 +0000
+++ tests/actions.vala 2015-08-15 23:41:09 +0000
@@ -20,13 +20,17 @@
2020
21 var hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.DOCUMENT) as WebKit.HitTestResult;21 var hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.DOCUMENT) as WebKit.HitTestResult;
22 var menu = view.get_page_context_action (hit_test_result);22 var menu = view.get_page_context_action (hit_test_result);
23 assert (menu != null);
23 assert (menu.name == "PageContextMenu");24 assert (menu.name == "PageContextMenu");
24 assert (menu.get_by_name ("Back") != null);25 assert (menu.get_by_name ("Back") != null);
2526
26#if !HAVE_WEBKIT227#if !HAVE_WEBKIT2
27 hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.EDITABLE) as WebKit.HitTestResult;28 var hit_test_result2 = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.EDITABLE) as WebKit.HitTestResult;
28 menu = view.get_page_context_action (hit_test_result);29 var menu2 = view.get_page_context_action (hit_test_result2);
29 var copy = menu.get_by_name ("Copy");30 assert (menu2 != null);
31 assert (menu2.name == "PageContextMenu");
32 var copy = menu2.get_by_name ("Copy");
33 assert (copy != null);
30 assert (!copy.sensitive);34 assert (!copy.sensitive);
31 assert (view.web_view.search_text ("flat", true, false, false));35 assert (view.web_view.search_text ("flat", true, false, false));
32 menu = view.get_page_context_action (hit_test_result);36 menu = view.get_page_context_action (hit_test_result);

Subscribers

People subscribed via source and target branches

to all changes: