Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to change a PyObject passed to the C extension

Reply
Thread Tools

How to change a PyObject passed to the C extension

 
 
MD
Guest
Posts: n/a
 
      08-11-2007
Hi,
I have a Python C extension which is passed a PyObject containing
an integer value. Is it possible to change this same PyObject so that
now the integer is of a different value?

Thanks and Regards,
-MD

 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      08-11-2007
On Sat, 11 Aug 2007 09:43:19 -0700, MD wrote:

> I have a Python C extension which is passed a PyObject containing
> an integer value. Is it possible to change this same PyObject so that
> now the integer is of a different value?


No it is not. Even if you poke around in the object ``struct`` this would
have severe consequences for cached/shared objects. Just imagine:

from your_module import bzzzt

def f():
print 2 + 2

bzzzt(2) # This changes the value of 2 to 3.
f() # This prints '6'!

Ciao,
Marc 'BlackJack' Rintsch
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Set PyObject value from C extension Allen Python 1 06-12-2007 04:08 AM
How properly manage memory of this PyObject* array?? (C extension) seberino@spawar.navy.mil Python 11 07-19-2006 05:39 PM
what are PyObject *globals and PyObject *locals ? Olivier Sessink Python 0 02-24-2005 02:06 PM
in c extension what is easiest way to build a (PyObject) list from an array of doubles? Christian Seberino Python 5 02-10-2004 08:51 PM



Advertisments