my own type, print function

T

Torsten Mohr

Hi,

i have created an own type in C and have implemented
the print function for it.

static int mytype_print(mytype_obj* self, FILE* fp, int flags) {
printf("[%p]", fp);
fprintf(fp, "Hello, world\n");
}

At the moment i ignore "flags". The first line "printf" is
executed, fp is NOT Null. But i haven't yet explored the memory
at that location. At the moment it points to 7803BB68.

The second line "fprintf" crashes the program.
The command at 0x77f88216 points to 0x00000010. The action
"written" could not be executed. (I translated that from german).


If i delete the second line, the program runs normally,
as i'd expect it.


Can anybody give me a hint what could be wrong here?


Best regards,
Torsten.
 
M

Michael Hudson

Torsten Mohr said:
Hi,

i have created an own type in C and have implemented
the print function for it.

I'm not sure what your problem is, but my advice is: don't do that :)

I.e. don't fill out the tp_print slot of your type object unless your
object type has such a long printed representation that going via a
string representation is grossly inefficent.

Cheers,
mwh
 
T

Torsten Mohr

Hi,
I'm not sure what your problem is, but my advice is: don't do that :)

I.e. don't fill out the tp_print slot of your type object unless your
object type has such a long printed representation that going via a
string representation is grossly inefficent.

Ok, i'll try that, but i still wonder why it crashes my python
interpreter. I'd like to understand that, also, i can't see what
COULD be wrong, i just do a normal fprintf() on the FILE* that
i get as a parameter.


Best regards,
Torsten.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,675
Latest member
RollandKna

Latest Threads

Top