noddy example, writing C modules for python

T

Torsten Mohr

Hi,

based on the example module "noddy" i wrote an own one
and i have problems accessing the elements in the python
objects. I defined the example object:

typedef struct {
PyObject_HEAD
int num;
} pmod_obj;


static PyMemberDef pmod_members[] = {
{"number", T_INT, offsetof(pmod_obj, num), 0, /* LINE 143 */
"pmod number"},
{NULL}
};



When i compile this under Win32, i get this (in german):
pmod.cc(143) : error C2552: 'pmod_members': Initialisierung nicht
zusammengesetzter Typen mit Initialisierungsliste ist nicht möglich
'PyMemberDef' : Typen mit benutzerdefinierten Konstruktoren sind
nicht 'aggregate'
pmod.cc(143) : error C2065: 'T_INT': nichtdeklarierter Bezeichner
pmod.cc(143) : error C2275: 'pmod_obj': Ungültige Verwendung dieses Typs als
Ausdruck
pmod.cc(10): Siehe Deklaration von 'pmod_obj'
pmod.cc(143) : error C2065: 'num': nichtdeklarierter Bezeichner
pmod.cc(143) : error C3861: 'offsetof': Bezeichner wurde auch mit einer
argumentbezogenen Suche nicht gefunden


Has anybody got a hint for me? It is not obvious to me why this
does not compile.


Best regards,
Torsten.
 
F

fishboy

pmod.cc(143) : error C2065: 'T_INT': nichtdeklarierter Bezeichner

hmmm, looking at this makes me wonder if you need a:

#include "structmember.h"

since T_INT is defined there.
 
T

Torsten Mohr

hmmm, looking at this makes me wonder if you need a:
#include "structmember.h"

Hi,

you are right. I did not expect that. I thought that
this would be included from Python.h, but obviously i
was wrong.


Thanks for that hint,
Torsten.
 
B

Bernd Nawothnig

Hi Torsten,

based on the example module "noddy" i wrote an own one
and i have problems accessing the elements in the python
objects. I defined the example object:
typedef struct {
PyObject_HEAD
int num;
} pmod_obj;

static PyMemberDef pmod_members[] = {
{"number", T_INT, offsetof(pmod_obj, num), 0, /* LINE 143 */
"pmod number"},
{NULL}
};

When i compile this under Win32, i get this (in german):
pmod.cc(143) : error C2552: 'pmod_members': Initialisierung nicht
zusammengesetzter Typen mit Initialisierungsliste ist nicht möglich
'PyMemberDef' : Typen mit benutzerdefinierten Konstruktoren sind
nicht 'aggregate'

The explanation is shown quite clear in plain German - where is your
problem? :) One is sure: your problem has nothing to do with Python
but with C++. Only for short, look at this example:

#v+
class A {
public:
char *s;
A(): s("") {}
} a = {"Hallo"};
#v-

That cannot compile too because there are two different
initializations: one via constructor and the second via initialization
list. So, of course, Gnu g++ also complains:

test.cc:24: error: `a' must be initialized by constructor, not by `{...}'



HTH & f'up2

Bernd
 

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top