File: 01_fix-gobject-class-implement.patch

package info (click to toggle)
glib-d 2.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 456 kB
  • sloc: makefile: 5
file content (110 lines) | stat: -rw-r--r-- 4,483 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
From 68a943299e6f5923a69045bbf6c034bf3112a5d7 Mon Sep 17 00:00:00 2001
From: Mike Wey <mike@mikewey.eu>
Date: Sat, 27 Mar 2021 22:11:17 -0400
Subject: [PATCH] Fix implementing a gobject class with ImplementClass.

Fixes: #gtkD/325
Fixes: #gtkD/326
---
 src/gtkd/Implement.d | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/src/gtkd/Implement.d b/src/gtkd/Implement.d
index a55c273..1c3cbd9 100644
--- a/src/gtkd/Implement.d
+++ b/src/gtkd/Implement.d
@@ -87,6 +87,7 @@ template ImplementClassImpl(Klass, Impl)
 		string result;
 
 		result ~= "import glib.Str;\n"~
+		          "import gobject.ObjectG;\n"~
 		          "import gobject.Type : Type;\n"~
 		          "import gobject.c.functions : g_type_class_peek_parent, g_object_get_data;\n";
 
@@ -105,8 +106,7 @@ template ImplementClassImpl(Klass, Impl)
 			          "\t"~ Klass.stringof ~"Class parentClass;\n"~
 			          "}\n\n";
 
-			result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n"~
-			          "protected static "~ Klass.stringof ~"Class* parentClass = null;\n\n";
+			result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n\n";
 
 			result ~= "protected override void* getStruct()\n"~
 			          "{\n"~
@@ -144,7 +144,7 @@ template ImplementClassImpl(Klass, Impl)
 		{
 			result ~= "static void "~ toCamelCase!Impl() ~"ClassInit (void* klass)\n"~
 			          "{\n"~
-			          "\tparentClass = cast("~ Klass.stringof ~"Class*) g_type_class_peek_parent(klass);\n";
+			          "\t"~ fullyQualifiedName!(getClass!Klass) ~"* "~ toCamelCase!(getClass!Klass)() ~" = cast("~ fullyQualifiedName!(getClass!Klass) ~"*)klass;\n";
 
 			result ~= setFunctionPointers!(getClass!Klass)();
 
@@ -205,16 +205,6 @@ template ImplementClassImpl(Klass, Impl)
 
 		return result;
 	}
-
-	template getClass(Instance)
-	{
-		mixin("import "~ getClassImport!Instance() ~"; alias getClass = "~ Instance.stringof ~"Class;");
-	}
-
-	private string getClassImport(Klass)()
-	{
-		return fullyQualifiedName!Klass.replace("."~ Klass.stringof, "");
-	}
 }
 
 template ImplementInterfaceImpl(Base, Klass, Impl)
@@ -244,8 +234,7 @@ template ImplementInterfaceImpl(Base, Klass, Impl)
 			          "\t"~ Base.stringof ~"Class parentClass;\n"~
 			          "}\n\n";
 
-			result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n"~
-			          "protected static "~ Base.stringof ~"Class* parentClass = null;\n\n";
+			result ~= "protected "~ toPascalCase!Impl() ~"* "~ toCamelCase!Impl() ~";\n\n";
 
 			result ~= "protected override void* getStruct()\n"~
 			          "{\n"~
@@ -302,7 +291,7 @@ template ImplementInterfaceImpl(Base, Klass, Impl)
 		{
 			result ~= "static void "~ toCamelCase!Impl() ~"ClassInit (void* klass)\n"~
 			          "{\n"~
-			          "\tparentClass = cast("~ Base.stringof ~"Class*) g_type_class_peek_parent(klass);\n"~
+			          "\t"~ fullyQualifiedName!(getClass!Base) ~"* "~ toCamelCase!(getClass!Base)() ~" = cast("~ fullyQualifiedName!(getClass!Base) ~"*)klass;\n"~
 			          "}\n\n";
 		}
 
@@ -366,6 +355,16 @@ private string getTypeImport(Iface)()
 	return fullyQualifiedName!Iface.replace("types."~ Iface.stringof, "functions");
 }
 
+template getClass(Instance)
+{
+	mixin("import "~ getClassImport!Instance() ~"; alias getClass = "~ Instance.stringof ~"Class;");
+}
+
+private string getClassImport(Klass)()
+{
+	return fullyQualifiedName!Klass.replace("."~ Klass.stringof, "");
+}
+
 private string getWrapFunction(Impl, Member, string name)()
 {
 	string result;
@@ -433,12 +432,12 @@ private string getWrapFunction(Impl, Member, string name)()
 			if ( (ParamStorage[i] == STC.out_ || ParamStorage[i] == STC.ref_) && isGtkdType!(DParamTypes[i]) )
 			{
 				result ~= "\tif ( d_"~ ParamNames[i] ~" !is null )\n"~
-				          "\t\t"~ ParamNames[i] ~" = d_"~ ParamNames[i] ~".get"~ DParamTypes[i].stringof ~"Struct();\n";
+				          "\t\t*"~ ParamNames[i] ~" = *d_"~ ParamNames[i] ~".get"~ DParamTypes[i].stringof ~"Struct();\n";
 			}
 		}
 
 		if ( isGtkdType!(ReturnType!(__traits(getMember, Impl, name))) && isPointer!(ReturnType!Member) )
-			result ~= "\treturn ret.get"~ (ReturnType!(__traits(getMember, Impl, name))).stringof ~"Struct();\n";
+			result ~= "\treturn ret ? ret.get"~ (ReturnType!(__traits(getMember, Impl, name))).stringof ~"Struct() : null;\n";
 		else if ( !is(ReturnType!Member == void) )
 			result ~= "\treturn ret;\n";