best "void" return of a member function

Andreas Otto aotto1968 at onlinehome.de
Mon Apr 20 11:08:50 EDT 2009


Propable you can help me with an other problem ...

the following code crash with:

==31431== Process terminating with default action of signal 11 (SIGSEGV)
==31431==  General Protection Fault
==31431==    at 0x4EA5151: PyObject_GenericGetAttr (object.c:982)
==31431==    by 0x4EF1FBD: PyEval_EvalFrameEx (ceval.c:1941)
==31431==    by 0x4EF5261: PyEval_EvalCodeEx (ceval.c:2869)
==31431==    by 0x4E91618: function_call (funcobject.c:628)
==31431==    by 0x4E6C7AC: PyObject_Call (abstract.c:2161)
==31431==    by 0x4E8055A: method_call (classobject.c:323)
==31431==    by 0x4E6C7AC: PyObject_Call (abstract.c:2161)
==31431==    by 0x4E6DFFE: PyObject_CallFunctionObjArgs (abstract.c:2392)
==31431==    by 0x6B8A43B: Python_pymsgque_pCallVoidMethod (pymisc.c:36)
==31431==    by 0x6B8991D: PythonChildCreate (pymsgque.c:89)
==31431==    by 0x6D9E15F: pTokenCheckSystem (token.c:547)
==31431==    by 0x6DA5110: pReadHDR (read.c:385)

with the following scenario

1. I have an object on an class
2. this object has a callable method context->config
3. I create an additional object of the same class
4. now I want to bind the context->config to the new object
5. I use: 
context->config = PyMethod_New(PyMethod_GET_FUNCTION(context->config),
(PyObject*)context->self);
6. but call this object with "PyObject_CallFunctionObjArgs" create a crash

this is my C code with some helper

  if (context->self == NULL) {
    context->self = PyObject_New(PyMqS_Obj,(PyTypeObject*)context->class);
M0
printO(PyMethod_Function(context->config))
    if (context->config != NULL)
      context->config = PyMethod_New(PyMethod_GET_FUNCTION(context->config),
(PyObject*)context->self);
M1
    if (context->create != NULL)
      context->create = PyMethod_New(PyMethod_GET_FUNCTION(context->create),
(PyObject*)context->self);
M2
printO(context->config)
printO(PyObject_Type(context->config))
  }

  // 4. set the 'hdl'
  context->self->msgque = msgque;

  // 5. init the new object
M3
  if (msgque->config.server == MQ_YES && context->config != NULL) {
    switch (NS(pCallVoidMethod)(msgque, context->config, NULL)) {
      case MQ_OK:           break;
      case MQ_CONTINUE:
      case MQ_ERROR:        goto error;
    }
  }
M4

this is the output:

output from the first object without error:
configO -> <bound method Server.config of <__main__.Server object at
0x2acee8eb7830>>
PyObject_Type(configO) -> <class 'method'>
PythonChildCreate(pymsgque.c:87) -> 33333333333333333
PythonChildCreate(pymsgque.c:95) -> 44444444444444444

output from the second object with the crash:
PythonChildCreate(pymsgque.c:71) -> 00000000000000000
PyMethod_Function(context->config) -> <function config at 0x2acee8ead8d0>
PythonChildCreate(pymsgque.c:75) -> 11111111111111111
PythonChildCreate(pymsgque.c:78) -> 22222222222222222
context->config -> <bound method Server.config of <__main__.Server object at
0x2acee8a67b20>>
PyObject_Type(context->config) -> <class 'method'>
PythonChildCreate(pymsgque.c:87) -> 33333333333333333




More information about the Python-list mailing list