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
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2015-07-19 22:25:09 +0000
3+++ CMakeLists.txt 2015-08-15 23:41:09 +0000
4@@ -255,7 +255,19 @@
5 endif ()
6
7 # Explicitly add -fPIC for older toolchains
8-set(VALA_CFLAGS "-w -g -fPIC")
9+set(VALA_CFLAGS "-g -fPIC")
10+
11+# With compiler versions that can, enable exactly the non-spurious warnings
12+# in Vala-generated C, otherwise disable warnings
13+if ((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "5.0.0")
14+ OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "3.0.0"))
15+ set(VALA_CFLAGS "${VALA_CFLAGS} -Werror=implicit-function-declaration")
16+ set(VALA_CFLAGS "${VALA_CFLAGS} -Wno-incompatible-pointer-types")
17+ set(VALA_CFLAGS "${VALA_CFLAGS} -Wno-discarded-qualifiers")
18+ set(VALA_CFLAGS "${VALA_CFLAGS} -Wno-deprecated-declarations")
19+else ()
20+ set(VALA_CFLAGS "${VALA_CFLAGS} -w")
21+endif ()
22
23 set(LIBMIDORI "${CMAKE_PROJECT_NAME}-core")
24
25
26=== modified file 'midori/midori-searchaction.h'
27--- midori/midori-searchaction.h 2014-07-24 11:48:46 +0000
28+++ midori/midori-searchaction.h 2015-08-15 23:41:09 +0000
29@@ -63,6 +63,9 @@
30 midori_search_action_set_default_item (MidoriSearchAction* search_action,
31 KatzeItem* item);
32
33+gchar*
34+midori_search_action_token_for_uri (const gchar* uri);
35+
36 GtkWidget*
37 midori_search_action_get_dialog (MidoriSearchAction* search_action);
38
39
40=== modified file 'midori/midori-view.h'
41--- midori/midori-view.h 2014-07-26 22:57:50 +0000
42+++ midori/midori-view.h 2015-08-15 23:41:09 +0000
43@@ -259,6 +259,10 @@
44 GTlsCertificateFlags* tls_flags,
45 gchar** hostname);
46
47+MidoriContextAction*
48+midori_view_get_page_context_action (MidoriView* view,
49+ WebKitHitTestResult* hit_test_result);
50+
51 G_END_DECLS
52
53 #endif /* __MIDORI_VIEW_H__ */
54
55=== modified file 'tests/actions.vala'
56--- tests/actions.vala 2013-08-02 23:45:16 +0000
57+++ tests/actions.vala 2015-08-15 23:41:09 +0000
58@@ -20,13 +20,17 @@
59
60 var hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.DOCUMENT) as WebKit.HitTestResult;
61 var menu = view.get_page_context_action (hit_test_result);
62+ assert (menu != null);
63 assert (menu.name == "PageContextMenu");
64 assert (menu.get_by_name ("Back") != null);
65
66 #if !HAVE_WEBKIT2
67- hit_test_result = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.EDITABLE) as WebKit.HitTestResult;
68- menu = view.get_page_context_action (hit_test_result);
69- var copy = menu.get_by_name ("Copy");
70+ var hit_test_result2 = Object.new (typeof (WebKit.HitTestResult), "context", WebKit.HitTestResultContext.EDITABLE) as WebKit.HitTestResult;
71+ var menu2 = view.get_page_context_action (hit_test_result2);
72+ assert (menu2 != null);
73+ assert (menu2.name == "PageContextMenu");
74+ var copy = menu2.get_by_name ("Copy");
75+ assert (copy != null);
76 assert (!copy.sensitive);
77 assert (view.web_view.search_text ("flat", true, false, false));
78 menu = view.get_page_context_action (hit_test_result);

Subscribers

People subscribed via source and target branches

to all changes: