Skip to content
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

my application using ctypes crashes on Kivy 1.9.2 and not on 1.8 #858

Closed
gued100x12 opened this issue Aug 1, 2016 · 4 comments
Closed

Comments

@gued100x12
Copy link

gued100x12 commented Aug 1, 2016

Hi,

I would like to share an issue i am getting while building an APK using the latest python-for-android package (1.9.x). The same code works fine on an old version of Kivy (1.8.).

I will try to describe how i get to this and please let me know if more clarification is needed:

  1. So, I am a C code where i am calling a callback function defined in python.
    Basically the code consists of (mydll.c):

`
typedef int (*callback_type)(float, float);

DLLEXPORT int our_callback(callback_type callbackHandler)
{
float a = 10;
float b = 50;
float count = 0;

for (count=0; count<60;count=count+10)
{
(*(callbackHandler))((a+count),b);
}

return 0;
`

  1. The python code consists of (main.py):

`
callback_type = CFUNCTYPE(c_int, c_float, c_float)

if name == 'main':

def greater_than(a,b):
    if a > b:
        Logger.info(u"GUED case1 {} is greater than {}".format(a,b))
        return 1
    else:
        Logger.info(u"GUED case1 {} is lower than {}".format(a,b))          
        return 0

    my_ctype_lib = cdll.LoadLibrary(os.path.join("my_clibrary"))
my_ctype_lib.our_callback.argtypes = [callback_type]

ret = my_ctype_lib.our_callback(callback_type(greater_than))
Logger.info(u"GUED ret= {}".format(ret))

`

Find attached the complete files:
python_ctype.zip

This works perfectly on PC (win32) and on android when using Kivy 1.8.
But when i build an APK using Kivy 1.9, i am getting a crash in the c library when referring to the callback (see the attached log file retrieved from logcat).
log_python4android_Kivy1.9_crash.txt

  1. How did i create the 1.9 Kivy distribution?
    I used the following command:
    python-for-android create --dist_name=batch2 --bootstrap=pygame -- requirements=hostpython2,python2,pyjnius,sdl,pygame,android,kivy

I am running out of ideas here and wondering what could have changed between 1.8 and 1.9?
Am i doing something wrong? or could it be that i am missing some modules?
I've checked the Cython version, i am using 0.23.

Let me know if you need more info.

Any help would be highly appreciated:-).
Thanks in advance.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@gued100x12
Copy link
Author

Additional info:
I found another reported issue similar to mine (looks like closed because of lake of info):
#401.
The behaviour seems to be the same.

@uberwoozle
Copy link

This may be an issue with the python distribution itself. It is likely the python distribution being used is using 'malloc' instead of 'mmap' for its 'ffi_closure_alloc/free' function which is called by '_ctypes_alloc_callback'. Android's malloc does not grant PROT_EXEC to allocated memory, which is necessary for the python code to be called. It may be as easy as using the implementation in the file 'malloc_closure.c'.

@gued100x12
Copy link
Author

Thanks for your comment. Does it be mean that I will need to update the python distribution for android? I am quite new in the Kivy world, so i will likely need step by step help here:-). In past we could build the distribution with the build script. Now it seems that we can get the hole package through an exe. I don't see how the modify a particular file. Any idea why to update a exiting python distribution for android?

@inclement
Copy link
Member

Closing as stale, I'm not aware of any issue like this on the master branch.

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