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

Callbacks can cause segv's #8

Closed
GoogleCodeExporter opened this issue Feb 3, 2016 · 5 comments
Closed

Callbacks can cause segv's #8

GoogleCodeExporter opened this issue Feb 3, 2016 · 5 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Use callbacks
2. See if it's a GC "bad hair day"

PySWIP creates a wrapper function around the foreign callback, and then wraps 
it in the CFUNCTYPE callback wrapper.  The problem is that it passes this down 
to the Prolog implementation, but does not keep a local ref.  It thus becomes a 
collectable object in Python, and can be written over by subsequent uses.

Meanwhile the memory is still registered by Prolog for a callback, and it when 
invoked will jump into memory whose contents might have been arbitrarily 
rewritten.

So you need to keep a ref on your callback wrapper at the Python level.  
Otherwise callbacks will cause segv's or other such craziness at random times.

Original issue reported on code.google.com by vandy...@gmail.com on 30 Jun 2010 at 11:01

@GoogleCodeExporter
Copy link
Author

Can you give a small example and the work around?

Thanks,
dksr

Original comment by dksre...@gmail.com on 3 Aug 2010 at 3:02

@GoogleCodeExporter
Copy link
Author

Really, all you have to do is invoke a foreign function.  But I'll attach what 
I have to help you get started.  Note we've moved on from SWI and PySwip, and 
are using a Prolog interpreter written in Python, which (obviously) obviates 
the whole issue.

nondet.py is some code which hooks SWI into Python generators; a very 
convenient way to interface to the Prolog engine.

easy.py has changes to try and keep the Python GC aware of data structure 
references.

try2.py is the only test code I could find.

Original comment by vandy...@gmail.com on 12 Sep 2010 at 10:15

Attachments:

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

Issue 16 has been merged into this issue.

Original comment by rodrigo....@gmail.com on 28 Dec 2012 at 5:56

@GoogleCodeExporter
Copy link
Author

jpthompson23 patch in r119 solved this issue.

Original comment by rodrigo....@gmail.com on 29 Dec 2012 at 12:21

  • Changed state: Verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant