By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,742 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,742 IT Pros & Developers. It's quick & easy.

Python 2.2.1 DLL extension causes "abnormal program termination"

P: n/a
Hello,

Apologies if this has already been answered in here and I can't find
it, but can anyone help with this problem?
I hope the example code and comments state clearly enough what is
happening, but if not, please ask me for further information.
Thank in advance for any help.

:-)
Hugh

#!/usr/bin/python

# 1. DLL C++ source code
#
# #include <Python.h>
# static PyObject* dummy(PyObject* self, PyObject* args)
# {
# return Py_None;
# }
# static PyMethodDef py_dll_test_methods[] =
# {
# { "dummy", dummy, METH_VARARGS, "dummy" },
# { 0,0,0,0 }
# };
# extern "C" void _declspec(dllexport) initpy_dll_test(void)
# {
# (void) Py_InitModule("py_dll_test", py_dll_test_methods);
# }
#
# 2. Build release DLL using MSVC++ version 6.0, linking with
"python22.lib"
#
# 3. Copy DLL to "c:\python22\python\dll" directory
#
# 4. Python source

import py_dll_test
import time

while 1:

py_dll_test.dummy()

time.sleep(0.01)

# 5. Run python source
# c:\>c:\Python22\python console_test.py

# 6. Program runs for a while, but then crashes after 24 seconds with
# abnormal program termination
# Note. If I reduce the sleep time, the crash happens earlier.

Sep 1 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hugh wrote:
Apologies if this has already been answered in here and I can't find
it, but can anyone help with this problem?
I hope the example code and comments state clearly enough what is
happening, but if not, please ask me for further information.
Thank in advance for any help. # static PyObject* dummy(PyObject* self, PyObject* args)
# {
# return Py_None;
# }


C functions must return an "owned" reference. or in other words, since
Py_None is an existing object, you need to increment the reference count
before returning it:

Py_INCREF(Py_None);
return Py_None;

or, better, but only works in recent Pythons:

Py_RETURN_NONE;

for more on reference counting and object ownership, see:

http://docs.python.org/ext/refcounts.html

</F>

Sep 1 '05 #2

P: n/a
Thank you very much.

Sep 1 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.