Bug 2252635 - (regression) 0.0.19.20170219gita59fd76 FTBFS patch broke webkit2-sharp
Summary: (regression) 0.0.19.20170219gita59fd76 FTBFS patch broke webkit2-sharp
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: webkit2-sharp
Version: 39
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Timotheus Pokorra
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-12-03 08:51 UTC by Hin-Tak Leung
Modified: 2023-12-13 01:25 UTC (History)
1 user (show)

Fixed In Version: webkit2-sharp-0-0.20.20170219gita59fd76.fc39
Clone Of:
Environment:
Last Closed: 2023-12-13 01:25:17 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Hin-Tak Leung 2023-12-03 08:51:20 UTC
Since upgrading to fc39 with webkit2-sharp-0-0.19.20170219gita59fd76.fc39.x86_64 , it broke.


The error message is:

$ ./webkit-example 
System.TypeInitializationException: The type initializer for 'WebKit2.WebView' threw an exception. ---> System.TypeInitializationException: The type initializer
 for 'WebKit2.WebViewBase' threw an exception. ---> System.EntryPointNotFoundException: webkit2sharp_webkit2_webviewbase_get_parentInstance_offset
  at (wrapper managed-to-native) WebKit2.WebViewBase.webkit2sharp_webkit2_webviewbase_get_parentInstance_offset()
  at WebKit2.WebViewBase..cctor () [0x00000] in <b7fd2452acb547808c87a62620fac859>:0 
   --- End of inner exception stack trace ---
  at GtkSharp.Webkit2Sharp.ObjectManager.Initialize () [0x002b9] in <b7fd2452acb547808c87a62620fac859>:0 
  at WebKit2.WebView..cctor () [0x0000c] in <b7fd2452acb547808c87a62620fac859>:0 
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
  at <InteractiveExpressionClass>.Host (System.Object& $retval) [0x00000] in <d1fa9ed7f32b41dbb190c24bf7eb360b>:0 
  at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x0003e] in <0cf4b81a98f0434f95ede2022cd42383>:0 
  at Mono.CSharpShell.Evaluate (System.String input) [0x00000] in <445efc3aa14a4c44bc4de07e0f68cd4d>:0 
System.NullReferenceException: Object reference not set to an instance of an object
  at <InteractiveExpressionClass>.Host (System.Object& $retval) [0x00000] in <16332b3dc8e14133bd46f07f3fa7e4be>:0 
  at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x0003e] in <0cf4b81a98f0434f95ede2022cd42383>:0 
  at Mono.CSharpShell.Evaluate (System.String input) [0x00000] in <445efc3aa14a4c44bc4de07e0f68cd4d>:0 

(csharp:4351): Gtk-CRITICAL **: 02:00:13.892: gtk_container_add: assertion 'GTK_IS_WIDGET (widget)' failed


Then I examine /usr/lib64/libwebkit2sharpglue-2.10.9.so and found the symbol name the C# code looks for does not match the one in the shared library.
C# looks for "webkit2sharp_webkit2_webviewbase_get_parentInstance_offset" as in the P/Invoke error message above, but the glue library provides "webkit2sharp_webkit2_webviewbase_get_parent_offset" which does not match.

Then I looked at the changelog, and found what I looked for:



$ rpm -q --changelog webkit2-sharp
* Mon Aug 14 2023 Timotheus Pokorra <timotheus.pokorra> - 0.0.19.20170219gita59fd76
- fix FTBFS: apply patch to generated file replacing parentinstance with parent


Somebody applied a patch blindly without testing afterwards... 





Reproducible: Always

Steps to Reproduce:
1. upgrade from webkit2-sharp from 0-0.17.20170219gita59fd76.fc38.x86_64 to 0.19.20170219gita59fd76.fc39.x86_64
2. launch csharp program

Actual Results:  
It breaks so horribly:

$ ./webkit-example 
System.TypeInitializationException: The type initializer for 'WebKit2.WebView' threw an exception. ---> System.TypeInitializationException: The type initializer
 for 'WebKit2.WebViewBase' threw an exception. ---> System.EntryPointNotFoundException: webkit2sharp_webkit2_webviewbase_get_parentInstance_offset
  at (wrapper managed-to-native) WebKit2.WebViewBase.webkit2sharp_webkit2_webviewbase_get_parentInstance_offset()
  at WebKit2.WebViewBase..cctor () [0x00000] in <b7fd2452acb547808c87a62620fac859>:0 
   --- End of inner exception stack trace ---
  at GtkSharp.Webkit2Sharp.ObjectManager.Initialize () [0x002b9] in <b7fd2452acb547808c87a62620fac859>:0 
  at WebKit2.WebView..cctor () [0x0000c] in <b7fd2452acb547808c87a62620fac859>:0 
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_generic_class_init(intptr)
  at <InteractiveExpressionClass>.Host (System.Object& $retval) [0x00000] in <d1fa9ed7f32b41dbb190c24bf7eb360b>:0 
  at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x0003e] in <0cf4b81a98f0434f95ede2022cd42383>:0 
  at Mono.CSharpShell.Evaluate (System.String input) [0x00000] in <445efc3aa14a4c44bc4de07e0f68cd4d>:0 
System.NullReferenceException: Object reference not set to an instance of an object
  at <InteractiveExpressionClass>.Host (System.Object& $retval) [0x00000] in <16332b3dc8e14133bd46f07f3fa7e4be>:0 
  at Mono.CSharp.Evaluator.Evaluate (System.String input, System.Object& result, System.Boolean& result_set) [0x0003e] in <0cf4b81a98f0434f95ede2022cd42383>:0 
  at Mono.CSharpShell.Evaluate (System.String input) [0x00000] in <445efc3aa14a4c44bc4de07e0f68cd4d>:0 

(csharp:4351): Gtk-CRITICAL **: 02:00:13.892: gtk_container_add: assertion 'GTK_IS_WIDGET (widget)' failed



Expected Results:  
It should launch a browser window.

downgrading fixes it:

# dnf downgrade https://kojipkgs.fedoraproject.org//packages/webkit2-sharp/0/0.17.20170219gita59fd76.fc38/x86_64/webkit2-sharp-0-0.17.20170219gita59fd76.fc38.x86_64.rpm https://kojipkgs.fedoraproject.org//packages/webkit2-sharp/0/0.17.20170219gita59fd76.fc38/x86_64/webkit2-sharp-devel-0-0.17.20170219gita59fd76.fc38.x86_64.rpm

BTW, there is no 0.18 build on koji. don't know why.

Comment 1 Hin-Tak Leung 2023-12-03 08:53:54 UTC
Please remove the offending FTBFS patch, or correct it. It is just wrong changing the C glue code without correcting the C# code, or vice versa.

Comment 2 Hin-Tak Leung 2023-12-04 03:13:51 UTC
I got hold of the patch itself from https://src.fedoraproject.org/rpms/webkit2-sharp.git - it is as I thought, a bit daft to change only the C glue code without correcting the C# P/Invoke code also...


--- a/sources/Makefile.am	2023-08-12 21:24:16.266564059 +0200
+++ b/sources/Makefile.am	2023-08-12 21:25:33.461760068 +0200
@@ -52,6 +52,7 @@
 		--glue-includes=webkit2/webkit2.h, --gapidir=$(gapidir) \
 	 	--assembly-name=$(ASSEMBLY_NAME) && \
 	find $(srcdir)/generated/ -type f -name "*.cs" > $(GEN_SOURCES)
+	sed -i "s/parentInstance/parent/g" $(GLUEDIR)/generated.c
 
 $(SRC_FILES_XML): $(GEN_SOURCES) $(CUSTOM_SOURCES)
 	echo "<SourceFiles>" > $(SRC_FILES_XML)


besides 'sed -i "s/parentInstance/parent/g" $(GLUEDIR)/generated.c', you need to do exactly the same thing to
some of the 'find $(srcdir)/generated/ -type f -name "*.cs"' file too.

And preferably, with a longer string for exact match as in "s/very_long_very_long_very_long_parentInstance/very_long_very_long_very_long_parent/g", rather than just "s/parentInstance/parent/g" .

Comment 3 Hin-Tak Leung 2023-12-04 03:32:32 UTC
Okay, I have looked at the generated C# code. Strictly speaking, you only need to change 1 line in $(GLUEDIR)/generated.c:

	return (guint)G_STRUCT_OFFSET (WebKitWebViewBase, parentInstance);

But you ended up changing 3 - 

$ grep -n -R parent glue/generated.c 
6:guint webkit2sharp_webkit2_webviewbase_get_parent_offset (void);
9:webkit2sharp_webkit2_webviewbase_get_parent_offset (void)
11:	return (guint)G_STRUCT_OFFSET (WebKitWebViewBase, parent);

And it is the fact that you have changed the other two to cause the P/Invoke signature to mis-match:

$ grep -R -n parentInstance generated/WebKit2/
generated/WebKit2/WebViewBase.cs:22:		extern static uint webkit2sharp_webkit2_webviewbase_get_parentInstance_offset ();
generated/WebKit2/WebViewBase.cs:24:		static uint parentInstance_offset = webkit2sharp_webkit2_webviewbase_get_parentInstance_offset ();
generated/WebKit2/WebViewBase.cs:28:					IntPtr* raw_ptr = (IntPtr*)(((byte*)Handle) + parentInstance_offset);


If you change the function signature on the C-side (which you don't need to), you should change the P/Invoke signature on the C# side too, the "extern static" line at line 22 of the C# code.


Changing all 7 (3 on the C side and 4 on the side) of *parentInstance* to *parent* might be simplest and more future proof, but strictly speaking you only need to change 1 line one the C side, line 11. webkit2-sharp broke because you change the other two line too.

Comment 4 Hin-Tak Leung 2023-12-04 03:39:05 UTC
So, strictly speaking, the correct way to patch webkit2-sharp is this line:

    sed -i "s/WebKitWebViewBase, parentInstance/WebKitWebViewBase, parent/g" $(GLUEDIR)/generated.c

So that it is specific to modifying exactly one line in generated.c, instead of 3.


If you want a simpler but strictly-speaking changing more than necessary, you need to do:

    sed -i "s/parentInstance/parent/g" $(GLUEDIR)/generated.c $(srcdir)/generated/*/*.cs

instead.

I really would rather you do the first one.

Comment 5 Timotheus Pokorra 2023-12-04 05:27:35 UTC
That somebody was me.
I am sorry, that I did not test the patch. That was daft, you are correct.

I probably will have to orphan my packages soon, because I do not have the time to maintain them properly.
I am not using Fedora or CentOS anymore myself, so there is not much point in maintaining packages anymore.

Comment 6 Timotheus Pokorra 2023-12-04 14:11:17 UTC
Thank you for looking into this issue in detail.
I have now applied your solution in rawhide and F39.
https://src.fedoraproject.org/rpms/webkit2-sharp/commits/rawhide
https://src.fedoraproject.org/rpms/webkit2-sharp/c/e67ef2133dc8bb4abb2a20895b2f221a867df4c5?branch=f39

I did not test it, because I don't know which csharp program is using webkit.

Please confirm in Bodhi if this update resolves the problem.

Comment 7 Fedora Update System 2023-12-04 14:11:52 UTC
FEDORA-2023-f1eebd1caa has been submitted as an update to Fedora 39. https://bodhi.fedoraproject.org/updates/FEDORA-2023-f1eebd1caa

Comment 8 Fedora Update System 2023-12-05 03:19:13 UTC
FEDORA-2023-f1eebd1caa has been pushed to the Fedora 39 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-f1eebd1caa`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2023-f1eebd1caa

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 9 Hin-Tak Leung 2023-12-05 04:05:51 UTC
I upgraded to https://bodhi.fedoraproject.org/updates/FEDORA-2023-f1eebd1caa and it now works. Thanks. I think I did have login to bodhi at some point in the past, but seems to have lost it... (it is not the same as redhat bugzilla, I think?). Anyway, you have the confirmation here that it works.

I have done a bit more digging and created https://github.com/hbons/webkit2-sharp/pull/7 - I think the true problem here is that webkit people are being naughty to modified already published fields. Re-generating the api.raw file should result in strict additions and additional annotations like this:


-    <enum name="ProcessModel" cname="WebKitProcessModel" type="enum" gtype="webkit_process_model_get_type" version="2.4">
+    <enum name="ProcessModel" cname="WebKitProcessModel" type="enum" gtype="webkit_process_model_get_type" version="2.4" deprecated="true" deprecated-version="2.40">

or this

-        <parameter closure="1" name="user_data" type="gpointer"/>
+        <parameter allow-none="1" closure="1" name="user_data" type="gpointer"/>


According to the old api file, the field used to be called "parentInstance" and is now called "parent".

The webkit2-sharp.metadata file (which is more what the personal preference of webkit2-sharp's author) to hide any c field "parent_instance" or any C# field 'Parent' (which is from the c field converted to camel case, i.e. a c field "parent"), but the old name has falling through the crack between these two.

I am okay if you want to just stop at 0.20 ; if you want to do https://github.com/hbons/webkit2-sharp/pull/7 instead (as 0.21?), it is equivalent to 0.20 but also hiding the field altogether because of the metadata file. The "generated.c" with pull/7 is completely empty, and you don't even need to ship libwebkit2sharpglue-2.10.9.so any more.


The csharp script I use (a variant of the oldest webkit-sharp example) is this:

===
#!/usr/bin/env -S csharp -lib:/usr/lib/mono/webkit2-sharp -lib:/usr/lib/mono/GtkSharp-3.0/ -r:gtk-sharp -r:webkit2-sharp -s

///*
//  Adapted to gtk3 and webkit2-sharp, and to run in scripting form with
//  Mono's Interactive C# Shell and Scripting REPL by
//  Hin-Tak Leung, 2015-2021.
//*/

///*
//  This was originally written by Andreia Gaita, perhaps around 2009?
//
//  A version of this is still at http://shana.worldofcoding.com/en/browser.html,
//  the webpage itself dated back to at least 2012.
//*/

using Gtk;
using WebKit2;

string url = "https://www.google.com";

if (Args.Length > 0)
    url = Args[0];

Application.Init ();
Window window = new Window (url);
window.SetDefaultSize(1200,600);
window.Destroyed += delegate (object sender, EventArgs e) {
    Application.Quit ();
};
ScrolledWindow scrollWindow = new ScrolledWindow ();
WebView webView = new WebView ();
webView.LoadUri (url);
scrollWindow.Add (webView);
window.Add (scrollWindow);
window.ShowAll ();
Application.Run ();
===

Comment 10 Fedora Update System 2023-12-13 01:25:17 UTC
FEDORA-2023-f1eebd1caa has been pushed to the Fedora 39 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.