using GLib;
public class Vala.GAsyncModule : GtkModule {
- bool needs_dummy_object (Method m) {
- var t = m.parent_symbol as TypeSymbol;
- return (t == null || !t.is_subtype_of (gobject_type) || m is CreationMethod || m.binding != MemberBinding.INSTANCE)
- && !context.require_glib_version (2, 20);
- }
-
CCodeStruct generate_data_struct (Method m) {
string dataname = Symbol.lower_case_to_camel_case (get_ccode_name (m)) + "Data";
var data = new CCodeStruct ("_" + dataname);
data.add_field ("int", "_state_");
- if (needs_dummy_object (m)) {
- data.add_field ("GObject*", "_dummy_object_");
- }
data.add_field ("GObject*", "_source_object_");
data.add_field ("GAsyncResult*", "_res_");
data.add_field ("GSimpleAsyncResult*", "_async_result");
}
}
- if (needs_dummy_object (m)) {
- // free dummy object being created in g_simple_async_result_new
- var dummy_object = new CCodeMemberAccess.pointer (new CCodeIdentifier ("_data_"), "_dummy_object_");
- var free_dummy_object = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
- free_dummy_object.add_argument (dummy_object);
-
- ccode.add_expression (free_dummy_object);
- }
-
var freecall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
freecall.add_argument (new CCodeIdentifier (dataname));
freecall.add_argument (new CCodeIdentifier ("_data_"));
create_result.add_argument (gobject_cast);
} else {
- if (context.require_glib_version (2, 20)) {
- create_result.add_argument (new CCodeConstant ("NULL"));
- } else {
- // needs dummy object
- var object_creation = new CCodeFunctionCall (new CCodeIdentifier ("g_object_newv"));
- object_creation.add_argument (new CCodeConstant ("G_TYPE_OBJECT"));
- object_creation.add_argument (new CCodeConstant ("0"));
- object_creation.add_argument (new CCodeConstant ("NULL"));
-
- ccode.add_assignment (new CCodeMemberAccess.pointer (data_var, "_dummy_object_"), object_creation);
-
- create_result.add_argument (new CCodeMemberAccess.pointer (data_var, "_dummy_object_"));
- }
+ create_result.add_argument (new CCodeConstant ("NULL"));
}
create_result.add_argument (new CCodeIdentifier ("_callback_"));
if (is_gtypeinstance) {
if (cl.has_class_private_fields || has_class_locks) {
decl_space.add_type_declaration (new CCodeTypeDefinition ("struct %s".printf (type_priv_struct.name), new CCodeVariableDeclarator ("%sClassPrivate".printf (get_ccode_name (cl)))));
- if (!context.require_glib_version (2, 24)) {
- var cdecl = new CCodeDeclaration ("GQuark");
- cdecl.add_declarator (new CCodeVariableDeclarator ("_vala_%s_class_private_quark".printf (get_ccode_lower_case_name (cl)), new CCodeConstant ("0")));
- cdecl.modifiers = CCodeModifiers.STATIC;
- decl_space.add_type_declaration (cdecl);
- }
}
/* only add the *Private struct if it is not empty, i.e. we actually have private data */
if (cl.has_class_private_fields || has_class_locks) {
decl_space.add_type_member_declaration (type_priv_struct);
- string macro;
- if (context.require_glib_version (2, 24)) {
- macro = "(G_TYPE_CLASS_GET_PRIVATE (klass, %s, %sClassPrivate))".printf (get_ccode_type_id (cl), get_ccode_name (cl));
- } else {
- macro = "((%sClassPrivate *) g_type_get_qdata (G_TYPE_FROM_CLASS (klass), _vala_%s_class_private_quark))".printf (get_ccode_name (cl), get_ccode_lower_case_name (cl));
- }
+ string macro = "(G_TYPE_CLASS_GET_PRIVATE (klass, %s, %sClassPrivate))".printf (get_ccode_type_id (cl), get_ccode_name (cl));
decl_space.add_type_member_declaration (new CCodeMacroReplacement ("%s_GET_CLASS_PRIVATE(klass)".printf (get_ccode_upper_case_name (cl, null)), macro));
}
decl_space.add_type_member_declaration (prop_enum);
}
- if (cl.class_constructor != null || (!context.require_glib_version (2, 24) && cl.has_class_private_fields)) {
+ if (cl.class_constructor != null) {
add_base_init_function (cl);
}
add_class_init_function (cl);
- if (cl.class_destructor != null || (!context.require_glib_version (2, 24) && cl.has_class_private_fields)) {
+ if (cl.class_destructor != null) {
add_base_finalize_function (cl);
}
push_function (base_init);
- if (!context.require_glib_version (2, 24) && cl.has_class_private_fields) {
- ccode.add_declaration ("%sClassPrivate *".printf (get_ccode_name (cl)), new CCodeVariableDeclarator ("priv"));
- ccode.add_declaration ("%sClassPrivate *".printf (get_ccode_name (cl)), new CCodeVariableDeclarator ("parent_priv", new CCodeConstant ("NULL")));
- ccode.add_declaration ("GType", new CCodeVariableDeclarator ("parent_type"));
-
- var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_parent"));
- var ccall2 = new CCodeFunctionCall (new CCodeIdentifier ("G_TYPE_FROM_CLASS"));
- ccall2.add_argument (new CCodeIdentifier ("klass"));
- ccall.add_argument (ccall2);
- ccode.add_assignment (new CCodeIdentifier ("parent_type"), ccall);
-
- ccode.open_if (new CCodeIdentifier ("parent_type"));
- ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_CLASS_PRIVATE".printf (get_ccode_upper_case_name (cl, null))));
- ccall2 = new CCodeFunctionCall (new CCodeIdentifier ("g_type_class_peek"));
- ccall2.add_argument (new CCodeIdentifier ("parent_type"));
- ccall.add_argument (ccall2);
- ccode.add_assignment (new CCodeIdentifier ("parent_priv"), ccall);
- ccode.close ();
-
- ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_new0"));
- ccall.add_argument (new CCodeIdentifier ("%sClassPrivate".printf(get_ccode_name (cl))));
- ccode.add_assignment (new CCodeIdentifier ("priv"), ccall);
-
- cfile.add_include ("string.h");
-
- ccode.open_if (new CCodeIdentifier ("parent_priv"));
- ccall = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
- ccall.add_argument (new CCodeIdentifier ("priv"));
- ccall.add_argument (new CCodeIdentifier ("parent_priv"));
- ccall.add_argument (new CCodeIdentifier ("sizeof (%sClassPrivate)".printf(get_ccode_name (cl))));
- ccode.add_expression (ccall);
- ccode.close ();
-
- ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_type_set_qdata"));
- ccall2 = new CCodeFunctionCall (new CCodeIdentifier ("G_TYPE_FROM_CLASS"));
- ccall2.add_argument (new CCodeIdentifier ("klass"));
- ccall.add_argument (ccall2);
- ccall.add_argument (new CCodeIdentifier ("_vala_%s_class_private_quark".printf (get_ccode_lower_case_name (cl))));
- ccall.add_argument (new CCodeIdentifier ("priv"));
- ccode.add_expression (ccall);
- }
-
pop_context ();
}
private void add_base_finalize_function (Class cl) {
push_context (base_finalize_context);
- if (!context.require_glib_version (2, 24) && cl.has_class_private_fields) {
- ccode.open_block ();
-
- var cdecl = new CCodeDeclaration ("%sClassPrivate *".printf (get_ccode_name (cl)));
- cdecl.add_declarator (new CCodeVariableDeclarator ("priv"));
- ccode.add_statement (cdecl);
-
- var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_CLASS_PRIVATE".printf (get_ccode_upper_case_name (cl, null))));
- ccall.add_argument (new CCodeConstant ("klass"));
- ccode.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("priv"), ccall)));
-
- ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
- ccall.add_argument (new CCodeIdentifier ("%sClassPrivate".printf (get_ccode_name (cl))));
- ccall.add_argument (new CCodeIdentifier ("priv"));
- ccode.add_statement (new CCodeExpressionStatement (ccall));
-
- ccode.close ();
- }
-
cfile.add_function_declaration (ccode);
cfile.add_function (ccode);
type_init.add_statement (get_type_interface_init_declaration ());
- if (cl != null && cl.has_class_private_fields && !context.require_glib_version (2, 24)) {
- CCodeFunctionCall quark_reg_call;
-
- if (plugin) {
- quark_reg_call = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_string"));
- } else {
- quark_reg_call = new CCodeFunctionCall (new CCodeIdentifier ("g_quark_from_static_string"));
- }
-
- quark_reg_call.add_argument (new CCodeConstant ("\"Vala%sClassPrivate\"".printf (CCodeBaseModule.get_ccode_name (get_type_declaration ()))));
-
- type_init.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("_vala_%s_class_private_quark".printf (CCodeBaseModule.get_ccode_lower_case_name (get_type_declaration ()))), quark_reg_call)));
- }
-
CCodeFunctionCall reg_call;
if (get_type_declaration () is Struct) {
reg_call = new CCodeFunctionCall (new CCodeIdentifier ("g_boxed_type_register_static"));
type_init.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier (type_id_name), reg_call)));
}
- if (cl != null && cl.has_class_private_fields && context.require_glib_version (2, 24)) {
+ if (cl != null && cl.has_class_private_fields) {
CCodeFunctionCall add_class_private_call;
add_class_private_call = new CCodeFunctionCall (new CCodeIdentifier ("g_type_add_class_private"));