Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-05

Armel problems

10 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Den Jean

Hi,

I am investigating why Qt on armel has problems.

I think that one of the problems is
that when c-functions are called from
pascal that the parameters are not passed
correctly (or not as I expected and accommodated for).

I noticed that when the parameter is a
"<procedure variable type of procedure of object;CDecl>" like @MyMethod (method of a class, with a cdecl decoration) that the c-functions do not get the correct addresses.

When I change the pascal definition of the external c-function and replace the "procedure () of object cdecl;" with 2 pointer parameters (MethodFunc,MethodData:Pointer) and use (@TClass.MyMethod,Self) ... well then it works fine.

In the C-library I expect to receive a struct
that I declared like this:
typedef struct {
  void *func;
  void *data;
} QHook;
Pascal:
type QAbstractButton_clicked2_Event = procedure () of object cdecl;
// when c-function declared like this
procedure QAbstractButton_hook_hook_clicked2(handle: QAbstractButton_hookH; hook: QAbstractButton_clicked2_Event); cdecl; external Qt4PasLib name 'QAbstractButton_hook_hook_clicked2';
// then this call does not work
QAbstractButton_hook_hook_clicked2(Hook,@MyMethod);
// when c-function declared like this
procedure testhook(handle: QAbstractButton_hookH; HookFunc,HookData:Pointer); cdecl; external Qt4PasLib name 'QAbstractButton_hook_hook_clicked2';
// then this works in constructor of TMyClass
testhook(Hook,@TMyClass.MyMethod,self)

fpc: latest svn, compiled with -dFPC_ARMEL
Code:{$mode objfpc}{$H+}

kind regards,

Den Jean

Reply by email

Michael Schnell
to Den Jean
Den Jean wrote
"<procedure variable type of procedure of object;CDecl>"

Does the compiler digest this ?

Up till now I thought it's impossible to use any common object ABI between Pascal and C++, so that any C function needs to be called by Pascal using a "flattened" non-Object based interface, because the Pascal and C++ object models are too different to use common objects with both languages.

-Michael

Reply by email

Den Jean
to Michael Schnell
Den Jean wrote 9 lines
Hi, I am investigating why Qt on armel has problems. I think that one of the problems is that when c-functions are called from pascal that the parameters are not passed correctly (or not as I expected and accommodated for).
Michael Schnell wrote 8 lines
Does the compiler digest this ? Up till now I thought it's impossible to use any common object ABI between Pascal and C++, so that any C function needs to be called by Pascal using a "flattened" non-Object based interface, because the Pascal and C++ object models are too different to use common objects with both languages.

Note how I say c-functions and not c++ functions. Only a C ABI is guaranteed, this is why all languages can interface with C but not with C++ or Java. I lack detailed knowledge of that ABI so the FPC devels may have to correct me on how that method struct will be passed, but I guess it should be by value. The alignment is probably not an issue with 2 struct members with the size of a pointer.

Reply by email

Michael Schnell
to Den Jean
Den Jean wrote
Note how I say c-functions and not c++ functions.

OK, But your code is

procedure of object;CDecl;

i.e. using a C ABI for a class function.

If the compiler does digest this, the meaning supposedly is that the procedure gets an additional, supposedly first, parameter (hidden in Object Pascal, open in C, that is the self pointer of the instance. If the C programmer knows how to deal with the Pascal object model which of course he can, as FPC is open source, he in fact can make use of this.

A variable of this type in fact consists of two pointers (code and self). This is part of the FPC Object model and ABI, so again, the C programmer can use this kind of variables if he wants to. The representation in C for such a variable would be a struct of the two pointers.

But of course all this is only relevant if the C code (e.g. a shared object) is done with the FPC object model in mind, but not usable to handle foreign objects (done in C) with FPC code.

-Michael

Reply by email

Den Jean
to Michael Schnell
Michael Schnell wrote 6 lines
If the compiler does digest this, the meaning supposedly is that the procedure gets an additional, supposedly first, parameter (hidden in Object Pascal, open in C, that is the self pointer of the instance. If the C programmer knows how to deal with the Pascal object model which of course he can, as FPC is open source, he in fact can make use of this.

The FPC Qt4 binding is made to let FPC interface with Qt4 via flattened c-functions. C++ signals can be hooked to FPC object method. I choose to support methods, because if you support methods, you also support simple procedures, just provide zero for the self parameter when installing the hook.

I made a demo program of the bug,
using the style of one of the fpc test suite program tcalext2.pp

http://bugs.freepascal.org/view.php?id=16520

kind regards,

Den Jean

Reply by email

Michael Schnell
to Den Jean
Den Jean wrote 5 lines

Congrats !

Do I understand correctly that you can use Lazarus to cross-Compile a project that can be loaded onto the N900 and decently run there ?

The GUI of the program is done using QT bindings ?

Is the N900 modified in any way to allow for loading and running native Linux applications ? Do Linux command line tools easily run on the N900 ?

The "[Qt] Draft Free Pascal Maemo binding" seems to describe how to install QT on the N900. Correct ?

Do you think it's possible to create a new "Maemo-QT" "Widget-Type" for Lazarus from your "intrusive" Patches (for practical reasons, the "powers" prefer independently coded "interfaces" instead of using common code used by multiple interfaces, so I suppose this should be quite easy to do and viable to be integrated in the common distribution.)

Did you already test "advanced" things like TTimer, TThread, inter-thread communication by PostMessage and "procedure...message", external communication via channels like serial, USB, TCP/IP, ... ?

Is it possible to set up a remote debugger via TCP/IP to allow debugging maemo applications from the Lazarus GUI ?

Thanks a lot for letting us know about this very interesting stuff ! -Michael

Reply by email

Luca Olivetti
to Michael Schnell

En/na Michael Schnell ha escrit:

Is the N900 modified in any way to allow for loading and running native Linux applications ? Do Linux command line tools easily run on the N900 ?

I don't have an n900, but previous maemo devices don't need any modification to run native Linux applications (maemo *is* native Linux, with command line tools either provided by the stock distribution or in the repos), there's an xterm and you can easily become root (no special hacks needed for that).

Do you think it's possible to create a new "Maemo-QT" "Widget-Type" for

Note that maemo is almost dead, due to the switch to meego (not that it will change that much, since Qt will be natively supported instead of being an add-on).

Bye

Luca

Reply by email

Michael Schnell
to Luca Olivetti
Luca Olivetti wrote
Note that maemo is almost dead, due to the switch to meego (not that it will change that much, since Qt will be natively supported instead of being an add-on).

Sounds great !

Looking forward to the meego "Widget Set" selection in Lazarus :)

-Michael

Reply by email