{"action":"created","issue":{"url":"https://api.github.com/repos/mvz/gir_ffi/issues/77","repository_url":"https://api.github.com/repos/mvz/gir_ffi","labels_url":"https://api.github.com/repos/mvz/gir_ffi/issues/77/labels{/name}","comments_url":"https://api.github.com/repos/mvz/gir_ffi/issues/77/comments","events_url":"https://api.github.com/repos/mvz/gir_ffi/issues/77/events","html_url":"https://github.com/mvz/gir_ffi/issues/77","id":177573179,"number":77,"title":"User-defined class property assume integer","user":{"login":"kugel-","id":564520,"avatar_url":"https://avatars.githubusercontent.com/u/564520?v=3","gravatar_id":"","url":"https://api.github.com/users/kugel-","html_url":"https://github.com/kugel-","followers_url":"https://api.github.com/users/kugel-/followers","following_url":"https://api.github.com/users/kugel-/following{/other_user}","gists_url":"https://api.github.com/users/kugel-/gists{/gist_id}","starred_url":"https://api.github.com/users/kugel-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kugel-/subscriptions","organizations_url":"https://api.github.com/users/kugel-/orgs","repos_url":"https://api.github.com/users/kugel-/repos","events_url":"https://api.github.com/users/kugel-/events{/privacy}","received_events_url":"https://api.github.com/users/kugel-/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-17T12:30:43Z","updated_at":"2016-09-19T08:55:57Z","closed_at":null,"body":"When defining properties for user-defined classes, gir_ffi assumes the property is an integer type. But properties can be arbitrary, including object and boxed types. The assumption can be seen here:\r\n\r\n```\r\n      def layout_specification\r\n        parent_spec = [:parent, superclass::Struct, 0]\r\n        offset = superclass::Struct.size\r\n        fields_spec = properties.flat_map do |pinfo|\r\n          spec = [pinfo.name.to_sym, :int32, offset]\r\n          offset += FFI.type_size(:int32)\r\n          spec\r\n        end\r\n        parent_spec + fields_spec\r\n      end\r\n```\r\n\r\nThis leads to the following error:\r\n```\r\n(eval):5:in `[]=': no implicit conversion of Gtk::Window into Integer (TypeError)\r\n\tfrom (eval):5:in `object='\r\n\tfrom /home/kugel/.gem/ruby/2.3.0/gems/gir_ffi-0.10.2/lib/gir_ffi/builders/user_defined_builder.rb:118:in `block in property_setter'\r\n```"},"comment":{"url":"https://api.github.com/repos/mvz/gir_ffi/issues/comments/247941456","html_url":"https://github.com/mvz/gir_ffi/issues/77#issuecomment-247941456","issue_url":"https://api.github.com/repos/mvz/gir_ffi/issues/77","id":247941456,"user":{"login":"kugel-","id":564520,"avatar_url":"https://avatars.githubusercontent.com/u/564520?v=3","gravatar_id":"","url":"https://api.github.com/users/kugel-","html_url":"https://github.com/kugel-","followers_url":"https://api.github.com/users/kugel-/followers","following_url":"https://api.github.com/users/kugel-/following{/other_user}","gists_url":"https://api.github.com/users/kugel-/gists{/gist_id}","starred_url":"https://api.github.com/users/kugel-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kugel-/subscriptions","organizations_url":"https://api.github.com/users/kugel-/orgs","repos_url":"https://api.github.com/users/kugel-/repos","events_url":"https://api.github.com/users/kugel-/events{/privacy}","received_events_url":"https://api.github.com/users/kugel-/received_events","type":"User","site_admin":false},"created_at":"2016-09-19T08:55:57Z","updated_at":"2016-09-19T08:55:57Z","body":"The following diff is better, it doesn't create corrupt pointers anymore (offset was still wrong). But I still get only the generic FFI::Pointer when using the accessors.\r\n\r\n```diff\r\ndiff --git a/lib/gir_ffi/builders/user_defined_builder.rb b/lib/gir_ffi/builders/user_defined_builder.rb\r\nindex 5ad0992..731bd0f 100644\r\n--- a/lib/gir_ffi/builders/user_defined_builder.rb\r\n+++ b/lib/gir_ffi/builders/user_defined_builder.rb\r\n@@ -86,8 +86,9 @@ module GirFFI\r\n \r\n       def instance_size\r\n         size = parent_gtype.instance_size\r\n-        properties.each do\r\n-          size += FFI.type_size(:int32)\r\n+        properties.each do |param_spec|\r\n+          ffi_type = param_spec.class.to_ffi_type\r\n+          size += FFI.type_size(ffi_type)\r\n         end\r\n         size\r\n       end\r\n@@ -170,9 +171,10 @@ module GirFFI\r\n         parent_spec = [:parent, superclass::Struct, 0]\r\n         offset = superclass::Struct.size\r\n         fields_spec = properties.flat_map do |param_spec|\r\n+          ffi_type = param_spec.class.to_ffi_type\r\n           field_name = param_spec.accessor_name.to_sym\r\n-          spec = [field_name, :int32, offset]\r\n-          offset += FFI.type_size(:int32)\r\n+          spec = [field_name, ffi_type, offset]\r\n+          offset += FFI.type_size(ffi_type)\r\n           spec\r\n         end\r\n         parent_spec + fields_spec\r\n```"}}
{"actor":{"display_login":"kugel-"}}