Skip to content

Commit

Permalink
Revert "Let the project work with gobject introspection lib < 1.7.0."
Browse files Browse the repository at this point in the history
Revert "Use lib property setters and getters instead of g_object_get/set_property when possible."

This reverts commit 94ed5fe.
This reverts commit 1bafa84.

getter/setter methods seems to return garbage sometimes... or I'm drunk.
  • Loading branch information
hugopl committed Oct 15, 2021
1 parent e074b07 commit b696535
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 70 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@ jobs:
run: ./bin/ameba
- name: Linter
run: crystal tool format --check
- name: Compile generator
run: shards build -Dold_libs
- name: Run tests
run: make test_binding just-test
run: make test
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ but at some point I decided to take a different approach on how to generate the
You are probably looking for the [GTK4](https://github.com/hugopl/gtk4.cr) shard, not this one, since this shard is only
useful if you are creating a binding to a GObject based library.

NOTE: If your gobject-introspection lib version is < 1.70, you need to compile with `-Dold_libs`, e.g.
`shards build -Dold_libs`

1. Add the dependency to your `shard.yml`:

```yaml
Expand Down
22 changes: 11 additions & 11 deletions ecr/property.ecr
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<% if prop.flags.writable? && !prop.has_setter? -%>
def <%= to_method_name(prop.name) %>=(value : <%= prop_type_name %>) : <%= prop_type_name %>
<% if prop.type_info.array? -%>
# handle array
<% else -%>
unsafe_value = value
<% end %>
LibGObject.g_object_set(self, "<%= prop.name %>", unsafe_value, Pointer(Void).null)
value
end
<% if prop.flags.writable? -%>
def <%= to_method_name(prop.name) %>=(value : <%= prop_type_name %>) : <%= prop_type_name %>
<% if prop.type_info.array? -%>
# handle array
<% else -%>
unsafe_value = value
<% end %>
LibGObject.g_object_set(self, "<%= prop.name %>", unsafe_value, Pointer(Void).null)
value
end
<% end %>

<% if prop.flags.readable? && !prop.has_getter? -%>
<% if prop.flags.readable? -%>
def <%= prop_getter_method_name %> : <%= prop_type_name %>
# Returns: <%= prop.ownership_transfer %>

Expand Down
5 changes: 0 additions & 5 deletions spec/libtest/test_subject.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,6 @@ void test_subject_set_str_list(TestSubject* self, const char** list) {
priv->str_list = g_strdupv((char **)list);
}

gboolean test_subject_get_boolean(TestSubject* self) {
TestSubjectPrivate *priv = test_subject_get_instance_private(self);
return priv->boolean;
}

TestSubject* test_subject_may_return_null(TestSubject* self, gboolean return_nil) {
return return_nil ? NULL : self;
}
Expand Down
17 changes: 1 addition & 16 deletions spec/libtest/test_subject.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ typedef struct _TestStruct {
#define TEST_TYPE_SUBJECT test_subject_get_type()
G_DECLARE_DERIVABLE_TYPE(TestSubject, test_subject, TEST, SUBJECT, GObject)

/**
* TestSubject:str_list: (setter test_subject_set_str_list)
*
* A string list property.
*/

struct _TestSubjectClass {
GObjectClass parent_class;

Expand Down Expand Up @@ -81,22 +75,13 @@ GObject *test_subject_new(void);
TestSubject *test_subject_new_from_string(const gchar *string);

/**
* test_subject_set_str_list: (set-property str-list)
* test_subject_set_str_list:
* @list: (array zero-terminated=1):
*
* Setter for str_list property.
* Used to test generation of properties with explicit settters
*/
void test_subject_set_str_list(TestSubject* self, const char** list);

/**
* test_subject_get_boolean:
*
* Getter for boolean property
* Used to test generation of properties with explicit gettters
*/
gboolean test_subject_get_boolean(TestSubject* self);

/**
* test_subject_may_return_null:
* @return_nil:
Expand Down
14 changes: 2 additions & 12 deletions src/generator/method_gen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Generator
super(@method.namespace)
end

def ignore? : Bool
def ignore?
config.ignore?(@method.symbol)
end

Expand All @@ -26,8 +26,7 @@ module Generator
identifier = if method_flags.constructor?
@method.name == "new" ? "initialize" : "self.#{identifier}"
elsif identifier.starts_with?("get_") && identifier.size > 4
name = identifier[4..]
boolean_getter? ? "#{name}?" : name
identifier[4..]
elsif @method.args.size == 1 && identifier.starts_with?("set_") && identifier.size > 4
"#{identifier[4..]}="
else
Expand All @@ -38,15 +37,6 @@ module Generator
identifier
end

private def boolean_getter? : Bool
return false if @method.args.any?

return_type = method_return_type
return_type = return_type.type_info if return_type.is_a?(ArgInfo)

return_type.as(TypeInfo).tag.boolean?
end

private def method_args : Array(ArgInfo)
@method_args ||= begin
args = @method.args.dup
Expand Down
2 changes: 0 additions & 2 deletions src/gobject_introspection/lib_gobject_introspection.cr
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ lib LibGIRepository
fun g_object_info_get_unref_function(info : BaseInfo*) : UInt8*
fun g_object_info_get_vfunc(info : BaseInfo*, n : Int32) : BaseInfo*
fun g_property_info_get_flags(info : BaseInfo*) : LibGObject::ParamFlags
fun g_property_info_get_getter(info : BaseInfo*) : BaseInfo*
fun g_property_info_get_setter(info : BaseInfo*) : BaseInfo*
fun g_property_info_get_ownership_transfer(info : BaseInfo*) : Transfer
fun g_property_info_get_type(info : BaseInfo*) : BaseInfo*
fun g_registered_type_info_get_g_type(info : BaseInfo*) : UInt64
Expand Down
18 changes: 0 additions & 18 deletions src/gobject_introspection/property_info.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,5 @@ module GObjectIntrospection
def flags : ParamFlags
ParamFlags.from_value(LibGIRepository.g_property_info_get_flags(self))
end

def has_getter? : Bool
{% if flag?(:old_libs) %}
false
{% else %}
ptr = LibGIRepository.g_property_info_get_getter(self)
!ptr.null?
{% end %}
end

def has_setter? : Bool
{% if flag?(:old_libs) %}
false
{% else %}
ptr = LibGIRepository.g_property_info_get_setter(self)
!ptr.null?
{% end %}
end
end
end

0 comments on commit b696535

Please sign in to comment.