Hey guys, sorry to ask another question of this nature, but I can't find
the answer or a single example of it anywhere. I'm sure it's been asked
before, but my google-fu isn't strong enough to find anything.

I have the following:

        struct MyType {
                PyObject_HEAD
                ...
        };

        PyTypeObject PyType_MyType = { ... }

Now, elsewhere in the code I want to create an instance of this custom
type in C/C++ (rather than in the Python interpreter, where this all
seems to happen magically) and return it from a method. What I'm trying
now is the following:

        PyObject* obj = _PyObject_New(&PyType_MyType);
        obj = PyObject_Init(obj, &PyType_MyType);
        
        ...

        return obj;

When "obj" gets back to the interpreter, Python sees it (or rather, it's
__repr__) in accordance with what it "should" be. However, any attempt
to USE the object results in a segfault. I feel my problem is simply
that I'm not allocating "obj" correctly in the C++ function.

If anyone has any advice, I would really appreciate it.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to