473,379 Members | 1,253 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

PyCheck for a classes defined in python and user data in PyObject_HEAD

q#1:
in C I want to check if a given PyObject is a xml.dom.minidom.Node (or
a derivative).
how do i extract a PyTypeObject for such a class?

issue #2
I'm in a situation when i don't really need to extend python with any
classes of my own but
i do have extra luggage for the python data structures such as tuples,
lists, dictionaries, etc
on the c++ side. I see no place in PyObject_HEAD where i can stick a
void* to my extra data.
If i enter a feature request into bugzilla for python do you think it
will be well received?
#ifdefed of course like the prev/next extras.
I'm surprised noone else is using evil twin approach.
The reason i'm asking is because while for dictionaries i can stick
weak pointer back to my c++
object in a key with an obscure name while in lists this would change
the list size and thus
is obviously not as easy to "hide" from the client code.
a placeholder in a pyobject would've been of help here

Nov 1 '07 #1
2 1816
En Fri, 16 Nov 2007 00:27:42 -0300, <sn****@gmail.comescribió:
On Nov 1, 11:04 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
>En Thu, 01 Nov 2007 22:13:35 -0300, <snd...@gmail.comescribió:
>I'm in a situation when i don't really need to extend python with any
classes of my own but
i do have extra luggage for the python data structures such as
tuples,
>lists, dictionaries, etc
on the c++ side. I see no place in PyObject_HEAD where i can stick a
void* to my extra data.

Assuming you can recompile all the extensions you use, you could insert
your void* into _PyObject_HEAD_EXTRA and _PyObject_EXTRA_INIT

i added two void pointers to head_extra and 0,0, to the extra_init.
For some reason i get garbage in them from PyEval_EvalCode :-(
(that's after i blew the build dir and rebuilt 2.4.4 from scratch
so i don't think i have a bad build)
Can't you use instead the other approaches suggested on this thread? Like
keeping a weakkey dictionary holding your additional attributes? Seems a
lot safer to do that way.

I've never changed that headers myself so I can't guarantee it works.
Perhaps there are some assumptions somewhere in the code about a specific
layout. But since _PyObject_HEAD_EXTRA is used in the debug build I think
you should be able to add your own fields, at least in principle...
Remember that this change invalidates ALL binaries for ANY library or
extension you may be using. An additional check might be to change the
Python release number to 2.9.9 or so, so none of your existing extensions
can inadvertidely be used.

--
Gabriel Genellina

Nov 16 '07 #2
On Nov 15, 10:00 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Fri, 16 Nov 2007 00:27:42 -0300, <snd...@gmail.comescribió:
On Nov 1, 11:04 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Thu, 01 Nov 2007 22:13:35 -0300, <snd...@gmail.comescribió:
I'm in a situation when i don't really need to extend python with any
classes of my own but
i do have extra luggage for the python data structures such as
tuples,
lists, dictionaries, etc
on the c++ side. I see no place in PyObject_HEAD where i can stick a
void* to my extra data.
Assuming you can recompile all the extensions you use, you could insert
your void* into _PyObject_HEAD_EXTRA and _PyObject_EXTRA_INIT
i added two void pointers to head_extra and 0,0, to the extra_init.
For some reason i get garbage in them from PyEval_EvalCode :-(
(that's after i blew the build dir and rebuilt 2.4.4 from scratch
so i don't think i have a bad build)

Can't you use instead the other approaches suggested on this thread? Like
keeping a weakkey dictionary holding your additional attributes? Seems a
lot safer to do that way.

I've never changed that headers myself so I can't guarantee it works.
Perhaps there are some assumptions somewhere in the code about a specific
layout. But since _PyObject_HEAD_EXTRA is used in the debug build I think
you should be able to add your own fields, at least in principle...
i finally found that i need to reset my fields in _Py_NewReference(op)
also.
weakref approach won't work for me because i need extra data in lists/
dictionaries/tuples in addition to instances of classes
(all instances of all classes: can't derive and essentially
make my own bloated psl to maintain)
Remember that this change invalidates ALL binaries for ANY library or
extension you may be using. An additional check might be to change the
that's not a problem since i build with a prefix other than /usr/local
and the target is an embedded system so i have full control over
the environment (until someone cracks it :-)

i finally got most of the code working after i figured out that
HEAD_INIT is ignored by tuple allocation code, etc
and _Py_NewReference has to be modified.

thank all of you for all the help. you got me unstuck.
Nov 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nikola Milutinovic | last post by:
Hi all. I'm not subscribed to the list, so all replies to me mail directly. I ran into a small problem, for which we have found a workaround. I was compiling PostgreSQL v7.4.1 and it's...
9
by: Zunbeltz Izaola | last post by:
Hi to all! I wonder if it possible (i'm sure python can do :-) ) to define classes on runtime. My problem (schematically) is the folowwin. The User can choise betwenn 3 property of an object....
7
by: Bo Peng | last post by:
Dear Python group: I am planning on an application that involves several complicated C++ classes. Basically, there will be one or two big data objects and some "action" objects that can act on...
2
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © # in Python, one can define a boxed set © # of data and functions, which are © # traditionally known as "class". © © # in the following, we define a...
4
by: Tuure Laurinolli | last post by:
Someone pasted the original version of the following code snippet on #python today. I started investigating why the new-style class didn't work as expected, and found that at least some instances...
0
by: Nikola Milutinovic | last post by:
Hi all. OS: Tru64 UNIX 4.0d PG: PostgreSQL v7.4.1 PY: Python v2.3.3 I just ran into a minor bug while compiling PL/Python module. It bombed outon lines 153 and 160 of...
14
by: pmclinn | last post by:
I've noticed that many programmers use classes to store data about such things like: Class Customers .....Phone ....ID ....Address End Class....
11
by: John Salerno | last post by:
From my brief experience with C#, I learned that it was pretty standard practice to put each class in a separate file. I assume this is a benefit of a compiled language that the files can then be...
2
by: Petter Haggholm | last post by:
For academic reasons, I'm hacking on the Python source trying to add some new capabilities. At present, I'm making minor changes mostly to familiarise myself with the code and gain awareness of...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.