Skip to content

updated MethodCallback unit: now it don't work on FPC ARM64 #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Alexey-T opened this issue Nov 5, 2022 · 15 comments
Closed

updated MethodCallback unit: now it don't work on FPC ARM64 #387

Alexey-T opened this issue Nov 5, 2022 · 15 comments

Comments

@Alexey-T
Copy link

Alexey-T commented Nov 5, 2022

I sync'ed this unit (in python4lazarus) and now CudaText ARM64 don't work. it shows py error on start.
ValueError: module functions cannot set METH_CLASS or METH_STATIC

I am comparing the new unit with old one (in Python4Lazarus before sync with you).
old unit did not have all variants of function GetCallBack.
attached this old unit.
MethodCallBack.zip

can you please make sure FPC ARM64 works now?

My device: Raspberry Pi-3, OS: Manjaro ARM.

@Alexey-T
Copy link
Author

Alexey-T commented Nov 5, 2022

Seems old version did not have this variant of func:

{$IFDEF CPUARM64}
function  GetCallBack(Self: TObject; Method: Pointer; ArgNum: Integer;
  CallType: TCallType): Pointer;

@Alexey-T Alexey-T changed the title updated MethodCallback unit: now don't work on FPC ARM64 updated MethodCallback unit: now it don't work on FPC ARM64 Nov 5, 2022
@pyscripter
Copy link
Owner

pyscripter commented Nov 5, 2022

The contributed changes in MethodCallback.pas provided Delphi support for Andoid and the Apple M2 chip.
Before there was no support whatsoever for ARM processors.
They have been tested extensively with Delphi on Android.

I do not use CPUARM so I am not in a position to test with either fpc or Delphi, so I cannot help. But if you, or anybody else, can make work with fpc, that would be great.

@Alexey-T
Copy link
Author

Alexey-T commented Nov 5, 2022

My situation: I compile app for Linux aarch64. I guess it must work because it works for you on Adroid(==Linux). but it doesn't.

EDIT
Can the author of patch help here?

@pyscripter
Copy link
Owner

@Alexey-T Is it picking the correct GetCallBack? {$IFDEF CPUARM64} What is your target CPU? Is it the Apple M2?
@lmbelo Any ideas why GetCallBack is not working on fpc?

@Alexey-T
Copy link
Author

Alexey-T commented Nov 5, 2022

Yes, it is picking GetCallback from CPUARM64, I added 'dd' and then it cannot compile.
No, it is not Apple M2, it is Raspberry Pi-3 with OS Manjaro ARM (arm64).

@pyscripter
Copy link
Owner

I added 'dd'

What do you mean?

@Alexey-T
Copy link
Author

Alexey-T commented Nov 5, 2022

I mean I added some 'crap' inside the block


{$IFDEF CPUARM64}
function  GetCallBack(Self: TObject; Method: Pointer; ArgNum: Integer;
  CallType: TCallType): Pointer;
const                            

and crap breaks the compiling for CPU ARM64. so this block is used!

@lmbelo
Copy link
Contributor

lmbelo commented Nov 5, 2022

@Alexey-T arm support was introduced as part of the Android support by Embarcadero. P4D does not support ARM processors before this exension. So, I'm not sure what you meant with "it is now broken after sync...".

@pyscripter
Copy link
Owner

pyscripter commented Nov 5, 2022

Raspberry Pi-3

This not a Delphi target, so I do not think you will get much help on this, but it would be nice to get it working.

Would be good to know whether it works with the Apple M2.

Both Delphi and fpc now support TMethodImplementation (see https://wiki.freepascal.org/FPC_New_Features_3.2.0#Rtti_unit). This would allow to create callbacks without using assembly (see https://en.delphipraxis.net/topic/7143-tmethodimplementation-and-its-uses/). But the announcement says that it is not supported on all platforms. Can you find out for which platforms it is supported?

@pyscripter
Copy link
Owner

@lmbelo

So, I'm not sure what you meant with "it is now broken after sync...".

Indeed. I have made the same point above.

Lucas. has the code been tested with the Apple M2? Would you expect the code to work with any ARM64 processor?

@pyscripter
Copy link
Owner

pyscripter commented Nov 5, 2022

@Alexey-T

ValueError: module functions cannot set METH_CLASS or METH_STATIC

This is coming from python. (see for instance pandas-dev/pandas#23040) . Why do you think methodcallback.pas is at fault? METH_CLASS and METH_STATIC (see https://docs.python.org/3/c-api/structures.html) are flags that P4D never uses.

You could try the MethodCallback tests to see whether it works correctly on your platform. Also you could try and run a simple console application with P4D, executing some simple code (e.g. "print('Hi') to see whether it works.

now CudaText ARM64 don't work

Did it ever work? Is it using MethodCallBack?
I had a look at the CudaText code and it appears that you are not using MethodCallback! Please confirm.

@Alexey-T
Copy link
Author

Alexey-T commented Nov 6, 2022

Did it ever work?

Yes, with the old version of Python4Lazarus (latter I tried to sync with P4D, and maybe I made mistake) CudaText 1.172 worked on R-Pi-3.

Is it using MethodCallBack?

It is used in PythonEngine unit:

      if tpfBaseType in TypeFlags then
      begin
        tp_init             := TPythonType_InitSubtype;
        tp_alloc            := TPythonType_AllocSubtypeInst;
        tp_new              := GetCallBack( Self, @TPythonType.NewSubtypeInst, 3, DEFAULT_CALLBACK_TYPE);
        tp_free             := FreeSubtypeInst;
        tp_methods          := MethodsData;
        tp_members          := MembersData;
        tp_getset           := GetSetData;
      end;
  1. 3 places with GetOfObjectCallBack.

@Alexey-T
Copy link
Author

Alexey-T commented Nov 6, 2022

You could try the MethodCallback tests to see whether it works correctly on your platform. Also you could try and run a simple console application with P4D, executing some simple code (e.g. "print('Hi') to see whether it works.

Will try !

@pyscripter
Copy link
Owner

pyscripter commented Nov 6, 2022

It is used in PythonEngine unit:

It is, but you don't use it in CudaText. You don't create new types and you only use TPythonModule.AddMethod. Put a breakpoint in GetMethodCallback and see whether you hit it.

@Alexey-T
Copy link
Author

Alexey-T commented Nov 6, 2022

Right, IDE don't stop inside GetCallback. False alarm. my mistake is aother one. Closing.

@Alexey-T Alexey-T closed this as completed Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants