Opened 19 years ago

Closed 19 years ago

#184 closed Bugs (Fixed)

raw_function with no keywords calls Py_INCREF on NULL

Reported by: conanbrink Owned by: david_abrahams
Milestone: Component: python USE GITHUB
Version: None Severity:
Keywords: Cc:

Description

In the 1.30.0 release, as well as in the latest CVS, the 
following code (using the very example presented in the 
documentation for raw_function.hpp) results in a 
segfault:

C++:
#include <boost/python/def.hpp>
#include <boost/python/tuple.hpp>
#include <boost/python/dict.hpp>
#include <boost/python/module.hpp>
#include <boost/python/raw_function.hpp>

using namespace boost::python;

tuple raw(tuple args, dict kw)
{
    return make_tuple(args, kw);
}

BOOST_PYTHON_MODULE(raw_test)
{
    def("raw", raw_function(raw));
}

Python:
>>> from raw_test import *
>>> def pyraw(*args, **kw):
...    return (args, kw)
... 
>>> pyraw(3, 4, foo = 'bar', baz = 42)
((3, 4), {'foo': 'bar', 'baz': 42})
>>> raw(3, 4, foo = 'bar', baz = 42)
((3, 4), {'foo': 'bar', 'baz': 42})
>>> pyraw(3,4)
((3, 4), {})
>>> raw(3, 4)
Segmentation fault


The problem is that the "keywords" parameter passed to 
boost::python::detail::raw_dispatcher's operator() is 
NULL.  This NULL pointer then gets wrapped in a 
borrowed_reference and passed to dict's constructor, 
which proceeds to make an attempt to Py_INCREF it.

do_call() from Python/eval.c passes a NULL pointer for 
the keyword dictionary in Python releases 2.2.2, 2.2.3, 
and 2.3b2.  I can't vouch for earlier releases.

Note that the Python version of this function (pyraw, 
defined above) receives an empty dict for its keywords 
when no keywords are passed, and I would expect the 
Boost Python Library to give me the same.

Change History (1)

comment:1 by david_abrahams, 19 years ago

Status: assignedclosed
Logged In: YES 
user_id=52572

Fixed now in CVS.  Thanks for the excellent bug report.
I'm backporting the fix to 1.30.1
Note: See TracTickets for help on using tickets.