This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyObject_Str() and PyObject_Repr() corrupt object type
Type: Stage:
Components: None Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: janusfury
Priority: normal Keywords:

Created on 2004-06-29 15:23 by janusfury, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg21349 - (view) Author: Kevin Gadd (janusfury) Date: 2004-06-29 15:23
For background: I am working on a modification to a
game engine that uses Python for automation. I am
trying to expose a few new objects to python scripts.
The engine already exposes a dozen or so different
objects to scripts, and I am exposing these new objects
the exact same way.

I am unable to override str() or repr() for my objects.
If I set the appropriate member in the type structure
(tp_str or tp_repr), PyObject_Str()/PyObject_Repr()
mangle the object when trying to convert it. If I leave
the structure member empty, everything works (except
for the str()/repr() override not working, naturally.)

I've gone over all my code multiple times, and can't
find anything that could possibly cause this. When I
step through the code in the VC++ debugger, I can see
the ob_type member of my object become corrupted at a
certain point in PyObject_Str()'s execution.

This block of code:
	if (v->ob_type->tp_str == NULL)
		return PyObject_Repr(v);

	res = (*v->ob_type->tp_str)(v);
Is apparently the culprit. If tp_str is NULL, the line
following the if is never reached. If it is set,
however, that line is executed, and for some reason
(one which I cannot determine, since tp_str isn't
documented at all), that line calls a method of
std::string, and once that function pointer call
returns, my object's ob_type member has been changed to
an invalid pointer (usually something like 0x00000032.)
msg21350 - (view) Author: Kevin Gadd (janusfury) Date: 2004-06-29 15:54
Logged In: YES 
user_id=313047

Sorry, this issue turned out to be a global scope problem.
My tp_str method had the same name and signature as a method
defined globally by a library I'm currently using, and for
some reason the debugger couldn't jump into it.

Sorry for the trouble.
History
Date User Action Args
2022-04-11 14:56:05adminsetgithub: 40477
2004-06-29 15:23:15janusfurycreate