473,408 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Custom type: PyObject_IS_GC access violation

I'm extending my C++ app by embedding Python 2.4.1 in it. The app is
multithreaded and split into several DLL's. The main EXE calls
Py_Initialize and Py_Finalize and each DLL gets a seperate interpreter
with Py_NewInterpreter.

The problem comes when I try to add a new type. I've been following the
"Extending and Embedding the Python Interpreter" tutorial. I've created a
PyTypeObject struct like so:

struct SA_PyVector {
PyObject_HEAD
int herman;
};

static PyTypeObject SA_PyVector_Type = {
PyObject_HEAD_INIT( 0 )
0,
"vector.Vector",
sizeof(SA_PyVector),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Py_TPFLAGS_DEFAULT,
"Vector objects",
};

But if I call

SA_PyVector_Type.tp_new = PyType_GenericNew;
PyType_Ready( &SA_PyVector_Type );

then, when Py_Finalize is called, PyObject_IS_GC(op) in visit_decref() in
gcmodule.c causes an access violation. If I don't call PyType_Ready, then
the access violation doesn't occure, but then the type can't be used...

So, the question is, does anyone have any idea about what could be
causing this?

/Bue
Jul 19 '05 #1
1 1828
Bue Krogh Vedel-Larsen wrote:
But if I call

SA_PyVector_Type.tp_new = PyType_GenericNew;
PyType_Ready( &SA_PyVector_Type );

then, when Py_Finalize is called, PyObject_IS_GC(op) in visit_decref() in
gcmodule.c causes an access violation. If I don't call PyType_Ready, then
the access violation doesn't occure, but then the type can't be used...

So, the question is, does anyone have any idea about what could be
causing this?


Most likely some code that you haven't shown. Here is the expansion
of PyObject_IS_GC(op)

#define PyObject_IS_GC(o) (PyType_IS_GC((o)->ob_type) && \
((o)->ob_type->tp_is_gc == NULL || (o)->ob_type->tp_is_gc(o)))

so it becomes

PyType_IS_GC(op->type) && (op->ob_type->tp_is_gc==NULL ||
op->ob_type->tp_is_gc(op))

Then, PyType_IS_GC(op->type) becomes

PyType_HasFeature((op->type), Py_TPFLAGS_HAVE_GC)

which in turn becomes

(op->tp_flags & Py_TPFLAGS_HAVE_GC) != 0

So typically, PyObject_IS_GC goes to the type of the object,
which should never crash, and then looks into the flags of
the type, which cannot crash - unless somebody messed with
ob_type of the object, and unless this isn't a Python
object in the first place.

You did not say what kind of object op was in the crash - this
is something you should investigate further. Does it point to
a Python object? If so, what is the type of the Python object?

Regards,
Martin
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access...
0
by: Microsoft News | last post by:
I'm getting the following error when I shut down my C# .NET v1.1 application: 0xC0000005: Access violation reading location 0x73bc0000 This error didn't occur until I added a...
5
by: Graham | last post by:
I have created a custom MembershipProvider called "LassieMembershipProvider" that derives from "MembershipProvider". This providor is located in a Businesslogic layer dll called...
39
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.