Replying to myself: On Fri, Mar 25, 2011 at 1:08 AM, Sean McNamara <smc...@gmail.com> wrote: > Hi, > > On Thu, Mar 24, 2011 at 10:37 PM, Alexander Kurtz > <kurtz.a...@googlemail.com> wrote: >> Hi, >> >> I have a problem with Pulseaudio (0.9.21) + Vala (0.10.4). I've written >> this small demonstration program: >> >> $ cat test.vala >> class MyClass : Object { >> static void main(){ >> PulseAudio.SampleSpec spec = PulseAudio.SampleSpec() { >> format = PulseAudio.SampleFormat.S32NE, >> channels = 2, >> rate = 44100 >> }; >> PulseAudio.MainLoop loop = >> new PulseAudio.MainLoop(); >> PulseAudio.Context context = >> new PulseAudio.Context(loop.get_api(), null); >> PulseAudio.Stream stream = >> new PulseAudio.Stream(context, "", spec); >> int32[] data = new int32[10]; >> stream.write(data, sizeof(int32) * data.length); >> } >> } >> $ >> >> I know that this program won't work (i.e. "run") but it should compile >> just fine. However, I get this: >> >> $ valac --vapidir=. --pkg=libpulse --pkg=posix test.vala >> /home/alexander/test/test.vala.c: In function ‘myclass_main’: >> /home/alexander/test/test.vala.c:61: warning: passing argument 5 of >> ‘pa_stream_write’ makes integer from pointer without a cast >> /usr/include/pulse/stream.h:503: note: expected ‘int64_t’ but >> argument is of type ‘void *’ >> /home/alexander/test/test.vala.c:61: error: too many arguments to >> function ‘pa_stream_write’ >> error: cc exited with status 256 >> Compilation failed: 1 error(s), 0 warning(s) >> $ >> >> Looking at the generated C-Code reveals this: >> >> $ valac --vapidir=. --pkg=libpulse --pkg=posix --ccode test.vala >> $ cat test.c >> [...] >> pa_stream_write (stream, data, (gsize) (sizeof (gint32) * >> data_length1), NULL, NULL, 0, PA_SEEK_RELATIVE); >> [...] >> $ >> >> This is obviously wrong, since pa_stream_write takes 6 arguments not 7, >> see[1]. >> >> Is this a bug in PA's Vala bindings or in Vala itself? > > Look at the PulseAudio bindings in > /usr/share/vala*/vapi/pulseaudio.vapi, or in git: > http://git.0pointer.de/?p=pulseaudio.git;a=blob_plain;f=vala/libpulse.vapi;hb=refs/heads/master-tx > > [Vala]: > public int write(void *data, size_t bytes, FreeCb? free_cb = null, > int64 offset = 0, SeekMode mode = SeekMode.RELATIVE); > > Compared to [C]: > int pa_stream_write (pa_stream *p, const void *data, size_t nbytes, > pa_free_cb_t free_cb, int64_t offset, pa_seek_mode_t seek) > > It seems that the parameters match up in the vapi, but it compiles > down to two NULLs instead of just one for the FreeCb. But if you look > at the signature of FreeCb, it tries to accept a void* as a parameter: > > [Vala] > public delegate void FreeCb(void *p); > > Maybe the extra parameter that Vala compiles in is supposed to be the > void* that the callback would then get passed? I think this is the > default behavior of a delegate. Maybe there is an annotation to tell > the Vala compiler not to supply a parameter to the call for the formal > parameters of the delegate? > > Try the following > > [CCode (has_target = false)] > public delegate void FreeCb(void *p);
Yep, this works! $ valac --pkg=libpulse --pkg=posix test.vala $ file test test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped Attached is a patch HTH, Sean > > Just a guess though -- it may not work as intended! There's virtually > no documentation on this attribute; I'm just guessing from the Vala > sources. > > HTH, > > Sean > >> >> Best regards >> >> Alexander Kurtz >> >> [1] >> http://0pointer.de/lennart/projects/pulseaudio/doxygen/stream_8h.html#a4fc69dec0cc202fcc174125dc88dada7 >> >> _______________________________________________ >> pulseaudio-discuss mailing list >> pulseaudio-discuss@mail.0pointer.de >> https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss >> >> >
From 93d9b6bad80c5112b5ff63189abad10bc56cf79e Mon Sep 17 00:00:00 2001 From: Sean McNamara <smc...@gmail.com> Date: Fri, 25 Mar 2011 01:28:10 -0400 Subject: [PATCH] Vala: delegate FreeCb does not have a target. --- vala/libpulse.vapi | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/vala/libpulse.vapi b/vala/libpulse.vapi index aed526a..8304911 100644 --- a/vala/libpulse.vapi +++ b/vala/libpulse.vapi @@ -49,7 +49,7 @@ namespace PulseAudio { [CCode (cname="PA_INVALID_INDEX")] public const uint32 INVALID_INDEX; - [CCode (cname="pa_free_cb_t")] + [CCode (cname="pa_free_cb_t", has_target=false)] public delegate void FreeCb(void *p); [CCode (cname="pa_sample_format_t", cprefix="PA_SAMPLE_")] -- 1.7.4.1
_______________________________________________ pulseaudio-discuss mailing list pulseaudio-discuss@mail.0pointer.de https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss