473,394 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

PyTuple_Check and other type check functions didn't check the NULLpointer

I was writing some C extensions for Python and use PyTupleType_Check
extensively. I found that all the PySomeType_Check macros directly
delegate the job to PyObject_TypeCheck(op, &PyType_Type). The
PyObject_TypeCheck(op, &PyType_Type) is again a macro and defined as
((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp)))

in object.h.

My questions is: is it necessary to check the null pointer in the
macro or it's a job for the user? Semantically all the type check
should report a false if a null pointer is encountered. I've already
had the patch to this issue but I am not sure if I think this problem
right. I don't know if there are some python core developers around
but I would like to hear all opinions towards this.

BTW, if the user didn't check null pointer before call the function, a
segmentation fault might occur.

Mar 23 '08 #1
2 2105
On Mar 24, 10:01 am, NotGuru <xu.math...@gmail.comwrote:
I was writing some C extensions for Python and use PyTupleType_Check
extensively. I found that all the PySomeType_Check macros directly
delegate the job to PyObject_TypeCheck(op, &PyType_Type). The
PyObject_TypeCheck(op, &PyType_Type) is again a macro and defined as
((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp)))

in object.h.

My questions is: is it necessary to check the null pointer in the
macro or it's a job for the user? Semantically all the type check
should report a false if a null pointer is encountered. I've already
had the patch to this issue but I am not sure if I think this problem
right. I don't know if there are some python core developers around
but I would like to hear all opinions towards this.

BTW, if the user didn't check null pointer before call the function, a
segmentation fault might occur.
You should check for null pointer returned by any C-API function that
is meant to return an object pointer; this indicates that an exception
has happened; your code should clean up and exit. See section 1.3 of
the Python/C API Reference Manual.
Mar 23 '08 #2
NotGuru schrieb:
My questions is: is it necessary to check the null pointer in the
macro or it's a job for the user? Semantically all the type check
should report a false if a null pointer is encountered. I've already
had the patch to this issue but I am not sure if I think this problem
right. I don't know if there are some python core developers around
but I would like to hear all opinions towards this.

Unless stated otherwise no Py* or PY* function is NULL safe. You have to
check for NULL unless the docs *explicitly* say it's safe to call it
with a NULL argument.

Christian

Mar 24 '08 #3

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Catherine Lynn Smith | last post by:
I'm looking through the client side javascript reference and there's some mighty useful information in here, but it is not very specific on 'reading' information from event handlers. In the...
5
by: Rick | last post by:
Hi, Another question for today, it's about structs refering to each other. I tried this code struct List; struct child { struct List parent; };
10
by: Giovanni Bajo | last post by:
Hello, given the ongoing work on struct (which I thought was a dead module), I was wondering if it would be possible to add an API to register custom parsing codes for struct. Whenever I use it...
20
by: elderic | last post by:
Hi there, are there other ways than the ones below to check for <type 'function'> in a python script? (partly inspired by wrapping Tkinter :P) def f(): print "This is f(). Godspeed!" 1.:...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
10
by: strife | last post by:
Hey everyone, I was making a program for a class, and I ran into a problem that is driving me crazy. I first suspected Vista, and since I am not home I cannot verify if it just my Vista...
5
by: Fei Liu | last post by:
Hello, I just hit a strange problem regarding SFINAE. The following code causes compile error (void cannot be array element type), I thought SFINA should match test(...) version instead and not...
19
by: zz12 | last post by:
Hello, is there a setting in IIS 5.0 that would quickly fix the following error?: Microsoft VBScript runtime (0x800A000D) Type mismatch It's strange because some of our .asp pages were...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...

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.