473,718 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with adding a new built-in data type

Evening all,

I'm trying to add a new built-in number data type to Python with its own
syntax, so I'm working directly with the interpreter rather than
creating my own extension module (side note: I've appended something
extra to the version thing in the Makefile - I doubt this is relevant to
the problem but it's probably best you have all the info). The complex
data type is similar to what I'm trying to do so I've been following
that as an example. I've successfully extended the tokenizer and the
parsenumber() function in compile.c to do what I want and written the
data type in my two new files Objects/mynewobject.c and
Include/mynewobject.h. I've included mynewobject.h in Python.h and added
the two files to the Makefile.

However, when I tried to run the code by typing in the syntax to produce
my data type, Python suffers a segmentation fault. I traced this to an
attempt to get the hash of a null pointer when adding the new instance
of my type after parsenumber() was called. For completeness, here's the
backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x08080e9a in PyObject_Hash (v=0x81486c0) at Objects/object.c:1162
1162 if (tp->tp_hash != NULL)
(gdb) bt
#0 0x08080e9a in PyObject_Hash (v=0x81486c0) at Objects/object.c:1162
#1 0x0808e199 in tuplehash (v=0x40324574) at Objects/tupleobject.c:2 44
#2 0x08080eae in PyObject_Hash (v=0x40324574) at Objects/object.c:1163
#3 0x0807b46c in PyDict_GetItem (op=0x40319c14, key=0x40324574) at
Objects/dictobject.c:49 2
#4 0x080c72c7 in com_add (c=0xbfffed60, list=0x40326114 ,
dict=0x40319c14 , v=0x40326290) at Python/compile.c:975
#5 0x080c74ac in com_addconst (c=0xbfffed60, v=0x40326290) at
Python/compile.c:1001
#6 0x080c90e3 in com_atom (c=0xbfffed60, n=0x4028d500) at
Python/compile.c:1689

The crash appears to be caused because while v exists, v's members are
all 0 and so tp becomes 0 when it is made equal to v->ob_type and you
get a NULL pointer exception. As far as I can tell, this v is the second
object in the tuple created in com_add() and is supposed to be the type
of the object being added to the dictionary in a tuple. Not knowing why
it was coming out as zero, I did some more poking around (been doing a
lot of that over the past 5 days...) and found that there is a file
called bltinmodule.c with a bunch of lines, one of which mentions the
complex data type that I am using as a guide:

SETBUILTIN("com plex", &PyComplex_Type );

So I made one of these for mynewobject and added it. I figured from this
bit of code that the reason I was getting NULL pointer exceptions was
because my type hadn't been initialised in some way and that this would
do it. But here's the problem: despite trying for longer than I've slept
in the past week, I can't get it to work. With that line in the Python
interpreter segfaults as soon as it starts (while trying to import the
os module) and so it can't even finish compiling the extension modules.
If I comment out the SETBUILTIN line I added it will compile fine but
then I go back to the first problem.

I have structured my object identically to the complex object as far as
I can tell, which works. So the question is, what's broken? What have I
missed when adding a new builtin?

(This mess is all happening on Linux tillinshir 2.6.7-gentoo-r11-gb #1
Wed Aug 4 11:13:14 NZST 2004 i686 mobile AMD Athlon(tm) XP 2000+
AuthenticAMD GNU/Linux, if that matters.)

Thanks in advance,
Geoff Biggs
Jul 18 '05 #1
1 2254
No need to worry anymore, I've fixed the problem. If you're making a
built-in type, remember to define your PyTypeObject with something other
than NULL in the PyObject_HEAD_I NIT. Non-built-ins don't need to worry
about this because it gets filled in later for them (as in the example
in the docs), but built-ins appear to need to fill it in themselves.

Geoff Biggs

Geoff Biggs wrote:
Evening all,

I'm trying to add a new built-in number data type to Python with its own
syntax, so I'm working directly with the interpreter rather than
creating my own extension module (side note: I've appended something
extra to the version thing in the Makefile - I doubt this is relevant to
the problem but it's probably best you have all the info). The complex
data type is similar to what I'm trying to do so I've been following
that as an example. I've successfully extended the tokenizer and the
parsenumber() function in compile.c to do what I want and written the
data type in my two new files Objects/mynewobject.c and
Include/mynewobject.h. I've included mynewobject.h in Python.h and added
the two files to the Makefile.

However, when I tried to run the code by typing in the syntax to produce
my data type, Python suffers a segmentation fault. I traced this to an
attempt to get the hash of a null pointer when adding the new instance
of my type after parsenumber() was called. For completeness, here's the
backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x08080e9a in PyObject_Hash (v=0x81486c0) at Objects/object.c:1162
1162 if (tp->tp_hash != NULL)
(gdb) bt
#0 0x08080e9a in PyObject_Hash (v=0x81486c0) at Objects/object.c:1162
#1 0x0808e199 in tuplehash (v=0x40324574) at Objects/tupleobject.c:2 44
#2 0x08080eae in PyObject_Hash (v=0x40324574) at Objects/object.c:1163
#3 0x0807b46c in PyDict_GetItem (op=0x40319c14, key=0x40324574) at
Objects/dictobject.c:49 2
#4 0x080c72c7 in com_add (c=0xbfffed60, list=0x40326114 ,
dict=0x40319c14 , v=0x40326290) at Python/compile.c:975
#5 0x080c74ac in com_addconst (c=0xbfffed60, v=0x40326290) at
Python/compile.c:1001
#6 0x080c90e3 in com_atom (c=0xbfffed60, n=0x4028d500) at
Python/compile.c:1689

The crash appears to be caused because while v exists, v's members are
all 0 and so tp becomes 0 when it is made equal to v->ob_type and you
get a NULL pointer exception. As far as I can tell, this v is the second
object in the tuple created in com_add() and is supposed to be the type
of the object being added to the dictionary in a tuple. Not knowing why
it was coming out as zero, I did some more poking around (been doing a
lot of that over the past 5 days...) and found that there is a file
called bltinmodule.c with a bunch of lines, one of which mentions the
complex data type that I am using as a guide:

SETBUILTIN("com plex", &PyComplex_Type );

So I made one of these for mynewobject and added it. I figured from this
bit of code that the reason I was getting NULL pointer exceptions was
because my type hadn't been initialised in some way and that this would
do it. But here's the problem: despite trying for longer than I've slept
in the past week, I can't get it to work. With that line in the Python
interpreter segfaults as soon as it starts (while trying to import the
os module) and so it can't even finish compiling the extension modules.
If I comment out the SETBUILTIN line I added it will compile fine but
then I go back to the first problem.

I have structured my object identically to the complex object as far as
I can tell, which works. So the question is, what's broken? What have I
missed when adding a new builtin?

(This mess is all happening on Linux tillinshir 2.6.7-gentoo-r11-gb #1
Wed Aug 4 11:13:14 NZST 2004 i686 mobile AMD Athlon(tm) XP 2000+
AuthenticAMD GNU/Linux, if that matters.)

Thanks in advance,
Geoff Biggs

Jul 18 '05 #2

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

Similar topics

4
3908
by: PyUser | last post by:
Hello, Just downloaded the 2.3.2 bzip2 package and trying to install. When I run 'make', I get the following error: ..... ..... running build running build_ext make: *** Error 139 $ uname -a
2
14871
by: V. Srinivas | last post by:
Hi, I tried to install my strong named assembly to GAC. But I get the following error message - 1. If I drag and drop the assembly to GAC using windows explorer --------------------------- The check of the signature failed for assembly 'MyUtils.dll'. --------------------------- OK ---------------------------
19
5235
by: Bill Davidson | last post by:
My wife's friend had a website built for his company, and it looks great using a PC. When viewed on a Mac using either Safari or Explorer the formatting is terrible. The home page is not too bad, however, any of the other pages selected have large spaces between paragraphs. I know to compare different browers when building a website but what can I suggest to him for PC/Mac problems.
1
2191
by: Randy | last post by:
I built and employment report from the employment table. I then had to add a field to the table. I now need to add that field to the report. I can't seem to be able to do that by clicking on table icon and adding the field as it is not listed. How am I able to add the new field to the report?
7
5426
by: Wysiwyg | last post by:
Is there any way to add an embedded resource to a project without copying it to the project's directory? I have shared resources and don't want each project using the images, xml files, etc. to need to be updated with the current copy before being built. I also don't want projects being built with the old copy. Thanks! Bill
0
1047
by: Wysiwyg | last post by:
Is there any way to add an embedded resource to a project without copying it to the project's directory? I have shared resources and don't want each project using the images, xml files, etc. to need to be updated with the current copy before being built. I also don't want projects being built with the old copy. Thanks! Bill
33
3021
by: wespvp | last post by:
When I try to run thread_test.c from the CVS tip, it hangs in an infinite CPU loop on both linux (RedHat AS 3.0, gcc 3.2.3) and Mac OS X 10.3.3 (gcc 3.3). I've also tried down to gcc 2.96 on Mac OS X. If I compile it with -g instead of -O2 on linux, it runs to completion and gives me: Add this to your template/$port file: STRERROR_THREADSAFE=yes
1
1290
by: Andy26 | last post by:
Hello: I currently have an Access2000 form that is built on a query that is using a table that is linked via ODBC connection. The table pulls down a list of project numbers from my company's database and shows what account they will be charged to. I would like to add a field to my form that allows me to input the project description for the project number. Is there anyway to do this? It seems simple, but I have not been able to find...
5
3650
by: Jonathan Boivin | last post by:
Hi, I've got some problems with loading bills using a bill usercontrol I built. If I load all current bills in my test environment (156) everything is fine once, but repeating the operation (which clear all the bills and reshow all of them) four to five times and I get a Error creating window handle. I investigated on all of this, a lot, and still I'm not able to find where this problem come from. I know that the GDI objects column in...
5
1792
by: royals | last post by:
Hello Access gurus, I am a self-taught Access “developer” and have a ton to learn so please allow me to sound stupid. I am using 2003 on a XP platform. I manage properties for an organization. At times it is necessary to pay an individual to stay in a house so that it isn’t vacant for an extended period of time. The organization pays the entire utility cost but deducts the individual’s usage cost. In other words, they receive...
0
8722
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
9206
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
7985
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
6652
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
5971
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
4481
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3180
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
2550
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2122
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.