473,490 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
Create 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_Check() 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 1827
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_Check() 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_Check().)

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
1806
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...
3
9349
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...
20
1796
by: Razvan | last post by:
Hi ! Is there any difference between new X and new X() ?! Regards, Razvan
2
7646
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 =...
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...
5
2361
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(...
2
2070
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...
15
4642
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...
7
2452
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...
3
1864
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
7108
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,...
0
6967
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...
0
7181
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...
1
6847
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...
0
7352
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...
1
4875
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...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
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 ...

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.