473,785 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

malloc'ed PyTypeObject

Hi,

I'm doing my first project on embedding and then extending Python in
an application. The idea is to import a set of C++ plug-ins into Python
and then be able to run a script that uses these plug-ins. Please note
that what I'm importing into Python are the plug-in classes in order to
be able to instanciate as many objects as needed.

As usual, all the plug-ins derive from a base class. But two
important things differ for each plug-in, its name and a set of
parameters.

For instance, the C++ class

class SNRFilter : public BaseFilter
{
...
};

can be instanciated in a Python script as

snr = SNRFilter()

(This is a quite simplified example as there is also a quite trivial
SNRFilterClass class deriving fron BaseFilterClass . But those are
implementation details).

So, everything works OK, but there will probably be a memory issue.
Each time I add a plug-in class into Python, I malloc a PyTypeObject
and copy its contents from a template static PyTypeObject. Then I
malloc and assign its tp_name and its tp_getset (array of PyGetSetDef).

Now the question is, how can I be sure that all this memory will be
properly free'd after calling Py_Finalize()? Is it enough to add
Py_TPFLAGS_HEAP TYPE? Can I safely free tp_getset after calling
PyType_Ready()? What will the weather be for the next week-end?

Thank you for reading.

--
Gabriel de Dietrich

Apr 6 '06 #1
0 1253

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

Similar topics

3
13623
by: Woodster | last post by:
I knoew that free is usually paired with malloc and delete is usually paired with malloc, alloc or similar. Can I use delete with malloc? The main reason I ask is for using the strdup function. If I have a char *, I have no real way of knowing whether that char * had memory allocated for it using new or malloc (as used by strdup). Thanks in advance
0
443
by: Simon Nickerson | last post by:
I have a function which looks like this: void rho(matrix_t *out, matrix_t *in) { static int firsttime = 1; static matrix_t *words; /* ... other variables ... */ if (firsttime) { firsttime = 0
14
8484
by: dam_fool_2003 | last post by:
Friends, cannot we malloc a array? So, I tried the following code: int main(void) { unsigned int y={1,3,6},i,j; for(i=0;i<3;i++) printf("before =%d\n",y); *y = 7; /* 1*/
11
1946
by: Sushil | last post by:
Hi Gurus I've tried to come up with a small logical example of my problem. The problem is platform specific (MIPS) which I understand should not be discussed here. So here goes my example: Code is doing malloc of variable sizes. The last byte of malloc.ed memory is written a magic.
33
2977
by: apropo | last post by:
what is wrong with this code? someone told me there is a BAD practice with that strlen in the for loop, but i don't get it exactly. Could anyone explain me in plain english,please? char *reverse(char *s) { int i; char *r; if(!s) return NULL;//ERROR r=calloc(strlen(s)+1,sizeof(char));
5
2767
by: Bidule | last post by:
Hi, I'm trying to sort structs defined as follows: struct combinationRec { float score; char* name; }; The number of structs and the length of the "name" field are not known
3
4889
by: Khookie | last post by:
Hi everyone I'm not sure whether this is good practice or not, so I thought I'll ask. I've got a function that returns a char pointer, which is malloc'ed in the function itself, as per below code. It's basically a singly linked list of strings that are concatenated into a big string. My question is - since you have to know to free it yourself (usage
2
1580
by: Khookie | last post by:
Hi all I was wondering whether there was a way to know whether a pointer (in my case, I'm using a char pointer) has been allocated memory through malloc or not, thus needing to be freed at a later stage? BTW, I thought this would be a common question - so either I'm just plain ignorant (coming from a C# and Python background) or my google skills need to improve.
0
9647
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
10356
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
10161
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
9958
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
8986
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
7506
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
6743
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
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

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.