473,809 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Newstyle Types Confounding!

I've been spending the last few night upgrading some 'classic' type
objects to the more modern 'newstyle' types. Unless I am not finding
some important page, this entire process is almost entirely
undocumented. I've found the "Noddy" example, which was a helping start.
But Noddy only gets you halfway there, and where it leaves off there is
no further assistance.

I've been using the builtin Python types source as example, but this
isn't answering most of my larger problems. Especially as the builtin
types seem inconsistent in how they do thing. I have a few questions and
am hoping to get a little guidance from those who understand this
process better.
First, I have found no comfortable way to create new type instances from
the C api. My types are wrappers for existing C structures. Originally
my code called PyObject_New and filled out the structure data. This
appears to be invalid with newstyle types, but I cannot discover the new
method. It appears there is no standard since all the builtin types do
this differently. I've ended up with something like this..

self = (PyMineObject*) PyMine_Type.tp_ new(&PyMine_Typ e, NULL, NULL);

Can this be serious? This is the first time I've ever had to dig into
the big Type structure to access function pointers. I find this to be
disturbing, but I can learn to accept it if someone confirms this is the
way to allocate newstyle type instances.
My second problem has to do with weakrefs. Again I cannot locate actual
documentation on this, and the Noddy example ends before discussing
weakrefs. I've created the PyObject* weakreflist in my structure, set
the offset in tp_weaklistoffs et, and initialized it to NULL. It took
many hours to figure out how this all works, mainly referring to
funcobject.c for examples. I believe I have this correct now, but I have
a lot of unexplained crashes that i suspect have to do with the weakref
list handling.
My third question comes to creating types that are inherited from other
types. I need the new subtype to add several of its own data fields to
its own structure. There are no examples of this in the Python source,
and there is no documentation referring to this. How can my new type
instances access structure data from its base. My only solution so far
is to duplicate all the structure members from the parent into the
child? Then duplicate all the code from the parent into the child. At
this point my child is actually a standalone type, except it refers to
the parent in tp_base.
Creating custom types in Python has become very difficult, if you intend
to support all the recent features of Python. Adding some documentation
and/or simple examples would go a long way towards a solution. I'm
wondering if some thought should be put into simplifying the interface.
Perhaps more macros and generic functions to help manage the new
features. It shocks me to find nearly every single "PyXXX_From XXX"
implements object allocation in entirely independent ways, and none of
the methods seem very clean to me.

At this point I'm really shooting into the dark. I assume I'll have it
right when things stop crashing.

If I were to collect a narrowed, specific list of problem topics, would
the documentation team be interested in looking?
Jul 18 '05 #1
0 1176

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

Similar topics

2
1347
by: Daniel Bickett | last post by:
I was reading the "Pickling and inheritance are making me hurt" thread, and the latest suggestion (as of this posting) was to do with the __setstate__ and __getstate__ methods. They caught my attention because I hadn't encountered them before, and it reminded me that in the past I've never been able to very good, definitive documentation on newstyle classes. Googling for it gives little python tutorials on various sites, and even searching...
3
4543
by: John Dibling | last post by:
Could somebody please direct me to a location in the standard where POD types are defined? That is, where in the standard is it defined what attributes a POD type has that a non-POD hasn't? Also, what does the acronym stand for? Thanks, </dib> John Dibling Witty banter omitted for your protection
8
2347
by: Shailesh | last post by:
One problem I've been wrestling with for a long time is how to use the C++ integral data types, vis-a-vis their size. The C++ rules guarantee that a char is at least 1 bytes, a short and int at least 2 bytes, and a long at least 4 bytes. The rules also define a size precedence to the types. In Stroustrup's book, it says that all type sizes are multiples of char, "so by definition the size of a char is 1." According to the rules, that...
8
2655
by: Martin Stettner | last post by:
Hi, I would like to use covariant return types in mutual dependent classes like: class IB; class IA { virtual IB* getIB() = 0; }; class IB{ virtual IA* getIA() = 0;
188
17471
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
5
2102
by: Zach | last post by:
When it is being said that, "value types are created on the stack or inline as part of an object". If a value type is created in an object, and that object is being called, the value type in that object, is still created on the stack, I would say, so I don't understand this inline business. Apart from the fact that it is my understanding that "inline" as it exists in C++ doesn't exist in C#. Could someone please shed some light on this...
58
3488
by: jacob navia | last post by:
Hi people I have been working again in my tutorial, and I have finished the "types" chapter. If you feel like "jacob bashing" this is the occasion! I am asking for criticisms, or for things I may have said wrong. Keep in mind that this is a tutorial, and I donot want to overwhelm the reader with little details. -------------------------------------------------------------------------* Types
14
2314
by: Lane Straatman | last post by:
I would like to write a 'struct'. I have a library that is all but completely inappropriate for this task. So I'm looking for C code that fills in the gaps between: #undef whateverkeithsaysfor99compliance #define whateverkeithsays for99compliance int main(void { struct foo
159
6355
by: Bob Timpkinson | last post by:
Hi, I have a 32-bit machine... Is there anyway I can get gcc to use the following integer sizes? char: 8 bits short: 16 bits int: 32 bits long: 64 bits long long: 128 bits
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.