473,782 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C API for new-style classes

Hi,

By new-style classes, I'm referring to the changes which came into 2.2 as
a result of PEP 252 and 253. I discovered this problem when trying to
use the Perl Inline::Python module with a python class that was
inheriting from the new builting 'object' class like so:

class MyClass(object) :

The problem is in detecting that this class should be treated as a class
from C. With old-style classes, PyClass_Check() returns true, but it
doesn't work with new-style classes. With those, apparently we have to
use PyType_Check(), but I cannot find this in the extension
documentation.

Another problem comes in identifying instances of this type of
type-class, where PyInstance_Chec k() no longer returns true.

Does anyone know of any documentation for the API for new-style classes?
(It must work somehow or the python interpreter couldn't do it.)

Thanks,
Eric
Jul 18 '05 #1
1 1839
On Thu, 10 Jun 2004 18:24:35 -0400, Aahz wrote:
With old-style classes, PyClass_Check() returns true, but it
doesn't work with new-style classes. With those, apparently we have to
use PyType_Check(), but I cannot find this in the extension
documentation .

Another problem comes in identifying instances of this type of
type-class, where PyInstance_Chec k() no longer returns true.

Does anyone know of any documentation for the API for new-style classes?
(It must work somehow or the python interpreter couldn't do it.)
I'm no expert on this, but since nobody else has stepped up to the
plate...

New-style classes make things both easier and harder. Fundamentally,
there's no longer any difference between a type and an instance --
that's how you get metaclasses that generate classes as their instances.
Unfortunately, your best bet is to look at the source of the new builtin
objects to see how they work.


What I have figured out so far (above) is from looking at the source.
Let's turn this around a bit: what problem are you trying to solve?


It's somewhat of a generic problem. I was trying to use the perl module
Inline::Python, which connects python code to perl via the C api's of both
of them. Thus, the python code is executed within C, and bindings are
created for each method of each class found. Thus, the return value of a
constructor is a reference to a python object.

For this whole scheme to work, the Inline::Python backend has to be able
to identify classes (it was using PyClass_Check() ) and it has to verify
that the object being used is an instance of a class (PyInstance_Che ck().)

From the work I have done with it (including lots of digging in the
Inline::Python C and Perl source, along with lots of digging in the python
source and documentation), it basically looks like new-style classes have
broken the C API, or that the "right way" to ask objects if they are
classes or instances has not been documented.

So, I guess the problem is "what is the right way to query objects which
are using the new-style class functionality from the C API?"

--Eric

Jul 18 '05 #2

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

Similar topics

4
1828
by: Madestro | last post by:
Hi guys, I am making a small program to retrieve e-mails from POP accounts. I got all the e-mail parsing stuff figured out, but I cannot seem to come up with a way to find out which e-mails are NEW so I don't have to retrieve them all. If you have experience with this kind of thing, you know that the server creates unique IDs for all the messages, but this IDs are not guaranteed to be unique, since they can be reused once a message is...
3
9417
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am presenting below a summary of what I have gathered. I would appreciate if someone could point out to something that is specific to Borland C++ and is not supported by the ANSI standard. I am also concerned that some of the information may be outdated...
20
1845
by: Razvan | last post by:
Hi ! Is there any difference between new X and new X() ?! Regards, Razvan
2
7673
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray = (data_type**)malloc(widht*height*sizeof(data_type)+ height* sizeof(data_type*)); //allocate individual addresses for row pointers. Now that I am moving to C++,am looking for something by which I can
11
912
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have nice and working allocation deallocation routines. However, I don't want to loose the nice extras of new operator, like - constructor calling, typecasting the result, keeping the array size, etc. For another bunch of reasons, outside this scope I...
5
2402
by: kUfa.scoopex | last post by:
Hi there! I have a small problem, and i really dont see any convenient way to fix it. Basically, i'd like to overload global new operators, into something like this: void *operator new( size_t size ); void *operator new( size_t size, AllocationType allocType ); void *operator new( size_t size, MemoryHandler* memHandler ); void *operator new( size_t size, MemoryHandler* memHandler, AllocationType
2
2091
by: Dave | last post by:
Hello all, I'd like to find a source on the web that discusses, in a comprehensive manner and in one place, everything about new / delete. It should include overloading operator new, the new operator, placement, nothrow, arrays, etc... My books cover the topic, I've found FAQs on the web that cover the topic, and so on, but all the sources I've found are disjointed. There's a bit on this page, a bit on that page, and so on. The...
15
4662
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any field to start. If I edit that field and then click on the new record button in the navigation buttons, the form goes to a new record and each field has the default value of the previous record. If I put the focus in any field to start, edit that...
7
2479
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls each with a couple of controls in them I then rebuilt my project and my new panels and all controls they contained are gone... I've looked through the Auto generated code but don't see anything that looks wrong Any body have any idea why this...
3
1891
by: Grizlyk | last post by:
Hi, people. Can anybody explain me "multiple 'new' at single line" behavior. Consider: p::p(void*); p::p(void*,void*); new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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
10313
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
10146
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...
0
8968
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
7494
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.