World: r3wp
[Red] Red language group
older newer | first last |
Kaj 17-Sep-2011 [3362] | On the callback matter, wouldn't it be better to always generate them as cdecl? |
Dockimbel 17-Sep-2011 [3363] | Maybe. |
Kaj 17-Sep-2011 [3364] | I don't see how a trampoline would work very well, because we're talking user written callbacks, so each would need its own trampoline |
Dockimbel 17-Sep-2011 [3365] | No, only your GTK dialect API would need them (one for button, one for window, ...). |
Kaj 17-Sep-2011 [3366] | The callbacks can have different numbers of arguments, and the widgets will eventually have multiple callbacks |
Dockimbel 17-Sep-2011 [3367x3] | Ah, I thought that "action" callback would all share the same definition. |
callbacks | |
Anyway, forcing cdecl for all callbacks might be a better option. I would need to check first if there's no internal compiler drawback on this option. | |
Kaj 17-Sep-2011 [3370] | Not always. You can for example pass gtk-quit without parameters, while the regular number of parameters is two |
Dockimbel 17-Sep-2011 [3371] | If I force the 'action callback in the GTK script to 'cdecl (by hardcoding it in the compiler), it's not crashing anymore. So the cause is confirmed. |
Kaj 17-Sep-2011 [3372] | Cool |
Dockimbel 17-Sep-2011 [3373] | Just thinking about a drawback for your proposition: Windows API expects callbacks using stdcall convention... |
Kaj 17-Sep-2011 [3374] | I'm falling apart here. I'm going to sleep |
Dockimbel 17-Sep-2011 [3375] | Same here. |
Kaj 17-Sep-2011 [3376x2] | :-) |
In C system programs it's common to specify the calling convention. It's probably reasonable to require an attribute, but I would say callbacks for Windows are the exception that would require one | |
Dockimbel 18-Sep-2011 [3378] | Red/System uses stdcall too internally, so forcing user to use a cdecl attribute for Red level callbacks is not natural. Need to think more about it to find a better option. |
Kaj 18-Sep-2011 [3379] | No, I mean to default to cdecl - which I thought was already implied by CALLBACK - and require to add stdcall only for Windows system callbacks |
Dockimbel 18-Sep-2011 [3380] | I don't think it is a good solution to put the burden on Windows users only. |
Kaj 18-Sep-2011 [3381x2] | It's only for Windows system callbacks. Most all other libraries on Windows use cdecl, and it is only for callbacks, not for general Windows system functions |
If stdcall would be the default, even Windows users would have to write it many more times than the other way around | |
Kaj 19-Sep-2011 [3383] | I've started on an SQLite binding |
Dockimbel 19-Sep-2011 [3384x3] | Ah, nice :-) |
I have documented the calling convention issue here: https://github.com/dockimbel/Red/issues/176 | |
I think it should be reasonable enough to choose cdecl when a function pointer is passed to a variadic function. | |
Pekr 19-Sep-2011 [3387] | Doc - I noticed (in your presentation), that port! dtype will be supported. I wondered how IO is going to be done,e.g. networking,or files. Will it be wrappers written in RED upon read-io, write-io Red/System functions? |
Dockimbel 19-Sep-2011 [3388] | I haven't decided yet on the implementation detail, but my current plan is to use a R3-like approach, passing messages to a lower-level layer wrote in Red/System. |
Kaj 19-Sep-2011 [3389] | Note that I'm only using variadic functions in the GTK binding so far. The issues in the other bindings are with regular functions |
Dockimbel 19-Sep-2011 [3390x2] | Are you using also function pointers only in GTK binding? |
Are you using function pointers only in GTK binding? | |
Kaj 19-Sep-2011 [3392x2] | No, there are callbacks in most bindings |
The crash on the older GTK on Syllable Server is gone | |
Dockimbel 19-Sep-2011 [3394] | Will it be wrappers written in RED upon read-io, write-io Red/System functions? Just to be sure there is no confusion: the read-io and write-io function mentioned in the slides have nothing to do with the REBOL homonyms. The Red/System ones are wrapper on CPU's IN and OUT instructions. |
Pekr 19-Sep-2011 [3395] | OK, thanks for the clarification ... |
Kaj 19-Sep-2011 [3396] | SDL audio still crashes |
Dockimbel 19-Sep-2011 [3397x2] | You should compile it in verbose mode (-v 6) and check the callbacks calling convention in the symbols block at the end of the compilation logs. |
It should be stdcall or cdecl. If you see ??, it means the compiler hasn't been able to solve it. | |
Kaj 19-Sep-2011 [3399] | Bingo, it says ?? for the audio callback |
Dockimbel 19-Sep-2011 [3400x3] | Ah! |
The ?? is the default value for cconv. When the compiler encounters a get-word!, it propagates the cconv from the function using it as argument. | |
How are you passing callbacks? Same way as with GTK binding through a variadic function? | |
Kaj 19-Sep-2011 [3403] | As I noted above, no variadic functions in the other bindings yet |
Dockimbel 19-Sep-2011 [3404] | Can you show me the code pattern you're using for the callbacks in SDL audio binding? |
Kaj 19-Sep-2011 [3405] | stream!: alias struct! [ ; data [binary!] index [binary!] rest [integer!] ] fetch-audio: function [ ; Read sound buffer to be played. [callback] source [stream!] sink [binary!] size [integer!] /local slice ][ slice: source/rest if slice > size [slice: size] ; copy-part source/index sink slice sdl-mix-audio sink source/index slice sdl-mix-max-volume source/index: source/index + slice source/rest: source/rest - slice ] |
Dockimbel 19-Sep-2011 [3406] | Ok, so how are you installing the fetch-audio callback? |
Kaj 19-Sep-2011 [3407x2] | desired/callback: as-integer :fetch-audio |
desired: declare sdl-audio-spec! | |
Dockimbel 19-Sep-2011 [3409x2] | Ok, so the cause is obvious, no way for the compiler to figure out the cconv in such case. |
I think that I will just accept both 'stdcall and 'cdecl attribute in cases like this where the compiler can't determine the right calling convention. I will also add a check at the end of the compilation to raise errors for unresolved calling conventions. | |
Kaj 19-Sep-2011 [3411] | That's nice, but why not default to cdecl? |
older newer | first last |