<p dir="ltr"><br>
On Apr 16, 2014 2:01 PM, "Jasper St. Pierre" <<a href="mailto:jstpierre@mecheye.net">jstpierre@mecheye.net</a>> wrote:<br>
><br>
><br>
><br>
><br>
> On Wed, Apr 16, 2014 at 2:27 PM, Pekka Paalanen <<a href="mailto:ppaalanen@gmail.com">ppaalanen@gmail.com</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I'm moving this conversation to where it belongs.<br>
>><br>
>> On Wed, 16 Apr 2014 11:25:26 +0000<br>
>> <a href="mailto:bugzilla-daemon@freedesktop.org">bugzilla-daemon@freedesktop.org</a> wrote:<br>
>><br>
>> > <a href="https://bugs.freedesktop.org/show_bug.cgi?id=77521">https://bugs.freedesktop.org/show_bug.cgi?id=77521</a><br>
>> ><br>
>> >           Priority: medium<br>
>> >             Bug ID: 77521<br>
>> >           Assignee: <a href="mailto:wayland-bugs@lists.freedesktop.org">wayland-bugs@lists.freedesktop.org</a><br>
>> >            Summary: cannot create opengl by dynamically loading wayland<br>
>> >                     symbols from library<br>
>> >           Severity: blocker<br>
>> >     Classification: Unclassified<br>
>> >                 OS: All<br>
>> >           Reporter: <a href="mailto:pulkitnandan@gmail.com">pulkitnandan@gmail.com</a><br>
>> >           Hardware: All<br>
>> >             Status: NEW<br>
>> >            Version: 1.3.0<br>
>> >          Component: wayland<br>
>> >            Product: Wayland<br>
>> ><br>
>> > I was trying to implement a window system agnostic library which will be used<br>
>> > in creating opengl apps with different windows systems. Lets name that library<br>
>> > as WSAL.Now to achieve this WSAL implements window system interfaces which is<br>
>> > used in creating native windows etc of specific window system while egl calls<br>
>> > are in main WSAL library.Consider wayland and X as examples of such two<br>
>> > libraries. As I separate several implementations of wayland and and X from<br>
>> > different team members.So to test them efficiently I have to create several<br>
>> > function pointers and object pointers that are present in those library<br>
>> > implementations and load them with symbols from libraries using dlsym utility<br>
>> > so that at compile time I donot have to link with any library.<br>
>> ><br>
>> > For X I was successfully in creating X backend.<br>
>> > For wayland I first got stuck at functions which are inline in<br>
>> > wayland_client_protocol.h. For them I cannot do the same.Instead I created a<br>
>> > function pointer which these functions actually calls in inline definition.<br>
>> ><br>
>> > Like when wl_display_get_registry is called wl_proxy_marshal_constructor is<br>
>> > ultimately called.<br>
>> ><br>
>> > The terrible fucntions are wl_proxy_marshal_constructor and wl_proxy_marshal as<br>
>> > they are defined with variable arguments.So I declared<br>
>> > new_wl_proxy_marshal_constructor a function pointer of same type as<br>
>> > wl_proxy_marshal_constructor and loaded the symbol from library using dlsym<br>
>> > into new_wl_proxy_marshal_constructor.<br>
>> ><br>
>> > But faced a fundamental problem of determing argument types as these terrible<br>
>> > functions (TFs) don't have constant argument signature i.e it may sometime pass<br>
>> > a int as its 4th aguments in one inline expansion while a char * in some other<br>
>> > inline function.<br>
>><br>
>> Why do you need to know the arguments?<br>
>> Why cannot you just use it as is, with variable arguments?<br>
>><br>
>> Btw. if the generated inline wrapper functions do not suit you, I<br>
>> think you could generate your own from the XML files, that end up<br>
>> calling the real functions exported from libwayland-client. That is<br>
>> how bindings to other programming languages are supposed work to my<br>
>> understanding.</p>
<p dir="ltr">You are more than welcome to write your own protocol parser that dumps out something that uses function pointers.  That should be a fine way to do it.  However, if you do so, you will want to use the wl_proxy_do_something_array versions such as wl_proxy_marshal_constructor_array.  These take an array of things of the type wl_argument instead of variable argument lists.  These should dlsym nicely.  If you want, you could write nice variable-argument wrappers that internally call your function pointers that call the _array version of the corresponding function.  (That's actually what libwayland does sans the function pointers part.)</p>

<p dir="ltr">> This won't work with EGL, as EGL expects libwayland-client. It's the same issue with X11: you can't just use XCB because GLX expects Xlib's Display / Window pointers.</p>
<p dir="ltr">As long as they're still using libwayland-client and passing around wl_proxy structures and not re-implementing the wire protocol, it should work fine.</p>
<p dir="ltr">>  <br>
>><br>
>> > So I explored this wl_proxy_marshal_constructor which actually calls<br>
>> > wl_proxy_marshal_array_constructor after forming a variable arguments to a<br>
>> > single argument using some wl_proxy object signature which I have no access to<br>
>> > in main wayland interface.<br>
>> ><br>
>> > dlsym option of using rtld_now doesnot work.<br>
>> ><br>
>> > How to implement such functionality in wayland or provide a way to create a app<br>
>> > with no linking at build time.<br>
>><br>
>> Have you looked at SDL2?<br>
>> <a href="http://hg.libsdl.org/SDL/file/tip/src/video/wayland">http://hg.libsdl.org/SDL/file/tip/src/video/wayland</a><br>
>><br>
>> To me it seems like it uses dlopen and dlsym equivalents to load<br>
>> Wayland libraries. I don't know if it is complete or in use yet,<br>
>> there seems to be also a non-dlopen path.</p>
<p dir="ltr">Thanks,<br>
--Jason Ekstrand<br>
</p>