Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #48 #49

Closed
wants to merge 1 commit into from
Closed

Fix #48 #49

wants to merge 1 commit into from

Conversation

BlobCodes
Copy link
Contributor

@BlobCodes BlobCodes commented Jun 26, 2022

Closes #48

This seems to fix the issue.
Newly generated code:

  # Prototype of the function called to create new child models when
  # gtk_tree_list_row_set_expanded() is called.
  #
  # This function can return %NULL to indicate that @item is guaranteed to be
  # a leaf node and will never have children. If it does not have children but
  # may get children later, it should return an empty model that is filled once
  # children arrive.
  alias TreeListModelCreateModelFunc = Proc(GObject::Object, Gio::ListModel?)

@hugopl
Copy link
Owner

hugopl commented Jun 26, 2022

nice, I’ll add a test before merge in the next few days when I sit down in front of a computer again.

@hugopl
Copy link
Owner

hugopl commented Jun 28, 2022

Interesting... adding just:

--- a/spec/libtest/test_subject.h
+++ b/spec/libtest/test_subject.h
@@ -66,6 +66,17 @@ typedef struct _TestSubjectClass {
  */
 typedef void (*TestSubjectSimpleFunc)(TestSubject* subject, int number, gpointer user_data);
 
+/**
+ * TestSubjectCallbackReturningNullFunc:
+ * @subject: The subject
+ * @obj: An object
+ * @user_data:
+ *
+ * Used to test callback code generation with nullable return type.
+ *
+ * Returns: (nullable) (transfer full): A nullable object
+ */
+typedef TestSubject* (*TestSubjectCallbackReturningNullFunc)(TestSubject* subject, TestSubject* obj, gpointer user_data);
+
 /**
  * test_subject_new_from_whatever:
  * @value:

that correctly generates:

  # Used to test callback code generation with nullable return type.
  alias SubjectCallbackReturningNullFunc = Proc(Test::Subject, Test::Subject, Test::Subject?)

Crashes the compiler on make test, or at least I think it's the compiler, since the crash pass through libLLVM-13.

Invalid memory access (signal 11) at address 0x0
[0x55fed15ae5f6] ?? +94552922449398 in crystal
[0x55fed15ae5c1] ?? +94552922449345 in crystal
[0x7f3c3123e8e0] ?? +139896499202272 in /usr/lib/libc.so.6
[0x7f3c32762f08] _ZN4llvm11PointerType3getEPNS_4TypeEj +24 in /usr/lib/libLLVM-13.so
[0x7f3c3263391f] LLVMBuildInBoundsGEP +287 in /usr/lib/libLLVM-13.so
[0x55fed124f05d] ?? +94552918913117 in crystal
[0x55fed1259adb] ?? +94552918956763 in crystal
[0x55fed12670bd] ?? +94552919011517 in crystal
[0x55fed1266ead] ?? +94552919010989 in crystal
[0x55fed1264e1c] ?? +94552919002652 in crystal
[0x55fed12a960a] ?? +94552919283210 in crystal
[0x55fed126e6a4] ?? +94552919041700 in crystal
[0x55fed128228f] ?? +94552919122575 in crystal
[0x55fed126ff5d] ?? +94552919048029 in crystal
[0x55fed129078e] ?? +94552919181198 in crystal
[0x55fed127103b] ?? +94552919052347 in crystal
[0x55fed126e748] ?? +94552919041864 in crystal
[0x55fed128228f] ?? +94552919122575 in crystal
[0x55fed126ff5d] ?? +94552919048029 in crystal
[0x55fed129078e] ?? +94552919181198 in crystal
[0x55fed127103b] ?? +94552919052347 in crystal
[0x55fed126e748] ?? +94552919041864 in crystal
[0x55fed128228f] ?? +94552919122575 in crystal
[0x55fed126ff5d] ?? +94552919048029 in crystal
[0x55fed129078e] ?? +94552919181198 in crystal
[0x55fed127103b] ?? +94552919052347 in crystal
[0x55fed126fae2] ?? +94552919046882 in crystal
[0x55fed126eaf5] ?? +94552919042805 in crystal
[0x55fed126e748] ?? +94552919041864 in crystal
[0x55fed121a0b5] ?? +94552918696117 in crystal
[0x55fed15dfc7b] ?? +94552922651771 in crystal
[0x55fed1665fda] ?? +94552923201498 in crystal
[0x55fed0c792fb] __crystal_main +27403 in crystal
[0x55fed0c7e4ca] main +74 in crystal
[0x7f3c31229290] ?? +139896499114640 in /usr/lib/libc.so.6
[0x7f3c3122934a] __libc_start_main +138 in /usr/lib/libc.so.6
[0x55fed0c72715] _start +37 in crystal
[0x0] ???

@BlobCodes
Copy link
Contributor Author

I also just tested the code, it is a compiler error.
It's probably a good idea to minimize it and send the bug report to crystal-lang.

@hugopl
Copy link
Owner

hugopl commented Jul 8, 2022

This patch is fine, I'm just afraid of merge it right now and get bite by this compiler bug, so once I have more time I'll try to reduce this code to be able to file a bug report to crystal-lang.

@hugopl
Copy link
Owner

hugopl commented Jan 4, 2023

The bug persists with crystal 1.6.2, I think now is time to try to reduce this compiler crash 😁

@hugopl
Copy link
Owner

hugopl commented Jan 4, 2023

Not a minimal code, but I get the crash doing:
./bin/spec spec/properties_spec.cr spec/signals_spec.cr

@hugopl
Copy link
Owner

hugopl commented Jan 4, 2023

The compiler issue was reduced to:

class Foo
end

def crash(&block : Proc(Enumerable(Foo), Nil))
  crash(block)
end

def crash(handler : Proc(Enumerable(Foo), Nil))
  0
end

alias SubjectCallbackReturningNullFunc = Proc(Foo, Foo?)

foo = nil
crash do |bar|
  foo = bar
end

@hugopl
Copy link
Owner

hugopl commented Jan 4, 2023

Issue filed, this can be merged only when crystal-lang/crystal#12894 gets fixed and released.

@hugopl hugopl added the blocked PR resolution blocked by something. label Feb 8, 2023
@hugopl hugopl deleted the branch hugopl:master July 6, 2023 20:21
@hugopl hugopl closed this Jul 6, 2023
@hugopl
Copy link
Owner

hugopl commented Jul 6, 2023

GitHub closed this one because I removed the master branch, since we already had some releases using main branch instead... and I'm not able to edit the PR.

@BlobCodes BlobCodes mentioned this pull request Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PR resolution blocked by something.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Function prototypes cannot return nil, even if stated in the docs
2 participants