* Problem with C function pointers @ 2003-12-19 22:13 Andrew Skiba 2003-12-20 2:07 ` Stephen Leake 0 siblings, 1 reply; 7+ messages in thread From: Andrew Skiba @ 2003-12-19 22:13 UTC (permalink / raw) Hello. I'm writing a thin interface library to DirectFB. This library uses structures with pointers to functions, emulating C++ vtables in C. The addresses of those functions are set inside DirectFB, so those are not valid Ada addresses. So, when I try to call such function (or assign it to an access function variable), I get raised CONSTRAINT_ERROR : dfb.adb:171 access check failed The question is how do I eliminate the check? I'm using GNAT and the declarations of relevant objects are: type SetCooperativeLevel_func is access function (thiz:IDirectFBCore_ptr; level:CooperativeLevel) return DFBResult; pragma Convention (C, SetCooperativeLevel_func); -- this does not help type IDirectFBCore is record ... SetCooperativeLevel:SetCooperativeLevel_func; -- this field -- points to some C function inside DirectFB library ... end record; pragma Convention (C, IDirectFBCore); -- this does not help, too :-( thiz:IDirectFBCore; f:SetCooperativeLevel_func; f:=thiz.SetCooperativeLevel; -- here exception is raised thiz.SetCooperativeLevel (...); -- or here exception is raised The situation remains the same if I make Unchecked_Conversion, still I have to call a function some time, and then the exception will be raised anyway. Any suggests will be appreciated. Regards, Andrew Skiba ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with C function pointers 2003-12-19 22:13 Problem with C function pointers Andrew Skiba @ 2003-12-20 2:07 ` Stephen Leake 2003-12-21 13:06 ` Andrew Skiba 0 siblings, 1 reply; 7+ messages in thread From: Stephen Leake @ 2003-12-20 2:07 UTC (permalink / raw) To: Andrew Skiba; +Cc: comp.lang.ada skibochka@yahoo.com (Andrew Skiba) writes: > The question is how do I eliminate the check? You don't want to eliminate the check! but you do want to solve the problem. > type SetCooperativeLevel_func is access function > (thiz:IDirectFBCore_ptr; level:CooperativeLevel) return DFBResult; > pragma Convention (C, SetCooperativeLevel_func); -- this does not help > type IDirectFBCore is record > ... > SetCooperativeLevel:SetCooperativeLevel_func; -- this field > -- points to some C function inside DirectFB library > ... > end record; > pragma Convention (C, IDirectFBCore); -- this does not help, too :-( > thiz:IDirectFBCore; > f:SetCooperativeLevel_func; > > f:=thiz.SetCooperativeLevel; -- here exception is raised Hmm. At this point "thiz" has the value "null". What do you expect? I suspect you left out some code, that sets "thiz". please post a small compilable example, if possible. Have you tried running under gdb, and examining "thiz"? Just out of curiosity, what does DirectFB do? -- -- Stephe ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with C function pointers 2003-12-20 2:07 ` Stephen Leake @ 2003-12-21 13:06 ` Andrew Skiba 2003-12-21 14:04 ` Stephen Leake 0 siblings, 1 reply; 7+ messages in thread From: Andrew Skiba @ 2003-12-21 13:06 UTC (permalink / raw) > Hmm. At this point "thiz" has the value "null". What do you expect? Well, you guessed! :-) > I suspect you left out some code, that sets "thiz". please post a > small compilable example, if possible. Obviously, the code I left out passed the pointer to "thiz" to a C function, which filled the rest of the structure, including the pointers to the functions. But I did an error in passing the pointer to "thiz", so "thiz" remained "null". > Have you tried running under gdb, and examining "thiz"? No, I printed it instead :-) It was "null", as you said. > Just out of curiosity, what does DirectFB do? This is a substitution for Windows DirectX on Linux. The FB stands for Frame Buffer, but DirectFB takes care not only of the screen (frame buffer), but also sound, keybord, mouse, as you might expect from DirectX. An interesting example of it is "links" web browser, which was originally text based, but with DirectFB you can see the graphics on linux console. Good thing for embedded and mini-distributions, which have no X. Thanks again, Andrew Skiba. P/S still waiting for someone to tell me "hey, this library was ported to Ada!" ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with C function pointers 2003-12-21 13:06 ` Andrew Skiba @ 2003-12-21 14:04 ` Stephen Leake 2003-12-22 9:37 ` Andrew Skiba 0 siblings, 1 reply; 7+ messages in thread From: Stephen Leake @ 2003-12-21 14:04 UTC (permalink / raw) To: Andrew Skiba; +Cc: comp.lang.ada skibochka@yahoo.com (Andrew Skiba) writes: > > I suspect you left out some code, that sets "thiz". please post a > > small compilable example, if possible. > Obviously, Well, I have learned from many years of posting here never to assume the "obvious", but instead to ask for precise details. Often the problem is that the poster is assuming something they shouldn't (which was the case here :). > > Have you tried running under gdb, and examining "thiz"? > No, I printed it instead :-) It was "null", as you said. Learn gdb; it's much better than Put_Line. > > Just out of curiosity, what does DirectFB do? > This is a substitution for Windows DirectX on Linux. The FB stands for > Frame Buffer, but DirectFB takes care not only of the screen (frame > buffer), but also sound, keybord, mouse, as you might expect from > DirectX. An interesting example of it is "links" web browser, which > was originally text based, but with DirectFB you can see the graphics > on linux console. Good thing for embedded and mini-distributions, > which have no X. Hmm. So it _doesn't_ run under X Windows? then it is _not_ a "substitution" for DirectX, since that runs under the equivalent of X for Windows (which doesn't really have a separate name). How big is it, compared to X Windows? Now we have a third target for GtkAda :). -- -- Stephe ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with C function pointers 2003-12-21 14:04 ` Stephen Leake @ 2003-12-22 9:37 ` Andrew Skiba 2003-12-22 23:10 ` Stephen Leake 0 siblings, 1 reply; 7+ messages in thread From: Andrew Skiba @ 2003-12-22 9:37 UTC (permalink / raw) After I wrote all answers, I saw the whole message became off-topic. I'm sorry for that, and I'm ready to continue the duscussion in any other place, if there are further questions. > Well, I have learned from many years of posting here never to assume > the "obvious", but instead to ask for precise details. Often the > problem is that the poster is assuming something they shouldn't (which > was the case here :). I would never have such problem with C++, I mean, I would immediately know what the problem is, but with Ada I tried to find a black cat in a dark room, when it wasn't there :) > > > Have you tried running under gdb, and examining "thiz"? > > No, I printed it instead :-) It was "null", as you said. > > Learn gdb; it's much better than Put_Line. I use it for a very long time, may be you heard, that it works for C, too :) The problem is, DirectFB has issues with debugging on the same monitor, because it OBVIOUSLY (:-) has exclusive control of the video card. Usually they are debugging via ssh, or a com-port. For simple cases put_line isn't that bad. > Hmm. So it _doesn't_ run under X Windows? Did I say that? Of course, it runs under X Windows. Try tuxrunner game for an example what it is. And, there is http://directfb.org/ to find other cute projects. > How big is it, compared to X Windows? Very small. That's the point, after all :-) It does not have to do much, linux kernel has device /dev/fb (if you configure it right), so the library only makes memcopy to it. Well, it's oversimplified, but the principle is right, I hope. > Now we have a third target for GtkAda :). Sorry, I did not understand that joke. If you meant to run GTK on DirectFB, that's done already, as well as mplayer, SDL, FreeVO and so on. I need it for a project, similar to FreeVO. Regards, Andrew Skiba. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with C function pointers 2003-12-22 9:37 ` Andrew Skiba @ 2003-12-22 23:10 ` Stephen Leake 2003-12-23 16:04 ` Ad Buijsen 0 siblings, 1 reply; 7+ messages in thread From: Stephen Leake @ 2003-12-22 23:10 UTC (permalink / raw) To: Andrew Skiba; +Cc: comp.lang.ada skibochka@yahoo.com (Andrew Skiba) writes: > > > > Have you tried running under gdb, and examining "thiz"? > > > No, I printed it instead :-) It was "null", as you said. > > > > Learn gdb; it's much better than Put_Line. > I use it for a very long time, may be you heard, that it works for C, > too :) The problem is, DirectFB has issues with debugging on the same > monitor, because it OBVIOUSLY (:-) has exclusive control of the video > card. Usually they are debugging via ssh, or a com-port. For simple > cases put_line isn't that bad. Ok, that makes sense. But it might be worth setting up a serial line terminal so you can run gdb for DirectFB programs. > > Hmm. So it _doesn't_ run under X Windows? > Did I say that? Of course, it runs under X Windows. Try tuxrunner > game for an example what it is. And, there is http://directfb.org/ > to find other cute projects. Well now I'm confused. If DirectXB runs under X Windows, why can't you run gdb in one window, with DirectXB in another? > > Now we have a third target for GtkAda :). > Sorry, I did not understand that joke. If you meant to run GTK on > DirectFB, that's done already, as well as mplayer, SDL, FreeVO and so > on. I need it for a project, similar to FreeVO. Ok. Have you tried GtkAda? I'm not sure it's a given that if Gtk works, GtkAda works. That would be nice to know. -- -- Stephe ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Problem with C function pointers 2003-12-22 23:10 ` Stephen Leake @ 2003-12-23 16:04 ` Ad Buijsen 0 siblings, 0 replies; 7+ messages in thread From: Ad Buijsen @ 2003-12-23 16:04 UTC (permalink / raw) Stephen Leake wrote: > skibochka@yahoo.com (Andrew Skiba) writes: > > > >>Did I say that? Of course, it runs under X Windows. Try tuxrunner >>game for an example what it is. And, there is http://directfb.org/ >>to find other cute projects. > > > Well now I'm confused. If DirectXB runs under X Windows, why can't > you run gdb in one window, with DirectXB in another? > Ah, semantic confusion... DirectFB controls the hardware directly, and there is a special XServer that runs on (top of) DirectFB, so , yes, DirectFB can run under X. Ad ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2003-12-23 16:04 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2003-12-19 22:13 Problem with C function pointers Andrew Skiba 2003-12-20 2:07 ` Stephen Leake 2003-12-21 13:06 ` Andrew Skiba 2003-12-21 14:04 ` Stephen Leake 2003-12-22 9:37 ` Andrew Skiba 2003-12-22 23:10 ` Stephen Leake 2003-12-23 16:04 ` Ad Buijsen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox