Python 1.5.2/2.0 C extension type differences

RCS rcstadheim at scarabweb.com
Sat Jan 13 12:16:23 EST 2001


Have there been implemented some major changes in the way the extension API
works in Python 2.0 compared to Python 1.5?

I'm interested in developing C extension type Python objects, and as a
preliminary test I have tried to compile (for Python 2.0) the example given
in Mark Lutz's book "Programming Python" in chapter 14 (stacktyp.c),
and my compiler (Visual C++ 5) complains at the following:

static PyTypeObject Stacktype = {      /* main python type-descriptor */
  /* type header */                    /* shared by all instances */
      PyObject_HEAD_INIT(&PyType_Type)
      0,                               /* ob_size */
      "stack",                         /* tp_name */
      sizeof(stackobject),             /* tp_basicsize */
      0,                               /* tp_itemsize */

  /* standard methods */
      (destructor)  stack_dealloc,   /* tp_dealloc  ref-count==0  */
      (printfunc)   stack_print,     /* tp_print    "print x"     */
      (getattrfunc) stack_getattr,   /* tp_getattr  "x.attr"      */
      (setattrfunc) 0,               /* tp_setattr  "x.attr=v"    */
      (cmpfunc)     stack_compare,   /* tp_compare  "x > y"       */
      (reprfunc)    0,               /* tp_repr     `x`, print x  */

  /* type categories */
      0,                             /* tp_as_number
+,-,*,/,%,&,>>,pow...*/
      &stack_as_sequence,            /* tp_as_sequence +,[i],[i:j],len,
...*/
      0,                             /* tp_as_mapping  [key], len, ...*/

  /* more methods */
      (hashfunc)   0,                /* tp_hash    "dict[x]" */
      (binaryfunc) 0,                /* tp_call    "x()"     */
      (reprfunc)   0,                /* tp_str     "str(x)"  */

};  /* plus others: see Include/object.h */

where an error is reported at the  PyObject_HEAD_INIT(&PyType_Type) : error
C2099: initializer is not a constant,
and in addition a bunch of warnings for the rest of the entries.

Any comments/hints/help greatly appreciated!!!!

Regards,
Rolf C Stadheim
r-stadhe at online.no






More information about the Python-list mailing list