logo       

Re: Re: Attempted a typeid of NULL pointer!: msg#00362

python.c++

Subject: Re: Re: Attempted a typeid of NULL pointer!

I've run into the same issue yesterday. I'm using boost 1.30 with MSVC 6.

This problem arise when trying to obtain a default constructed shared_ptr in
python. It seems that the conversion of a null shared_ptr to None is not
handled. Though, I don't know if this feature is supported (the unit-test
for shared_ptr is too complicated for me to understand).


Here is the python code. It only fail when 'statement.elseStatement' is a
NULL shared_ptr.
def visitIfStatement( self, statement ):
self._visitScopedSubstatement( statement.thenStatement )

if statement.elseStatement: # C++ property which is a
shared_ptr
self._visitScopedSubstatement( statement.elseStatement )
---
File "C:\prg\vc\Rfta\src\pyrfta\test\rfta\codeanalysis.py", line 39, in
visitIfStatement
if statement.elseStatement:
RuntimeError: Attempted a typeid of NULL pointer!
---

Notes that using explicit comparison against None also fail:
if None != statement.elseStatement:


The IfStatement C++ class.

typedef boost::shared_ptr<Statement> StatementPtr;
typedef boost::shared_ptr<IfStatement> IfStatementPtr;

class RFTA_API IfStatement : public ConditionStatement
{
public:
// ...
StatementPtr getElseStatement() const;

private:
StatementPtr elseStatement_;
};

The code used to expose the IfStatement:
class_<IfStatement, IfStatementPtr, bases<ConditionStatement>,
boost::noncopyable>( "IfStatement",

init<ExpressionPtr, StatementPtr>() )
.def( init<ExpressionPtr, StatementPtr, StatementPtr>() )
// ...
.add_property( "elseStatement", &IfStatement::getElseStatement,
&IfStatement::setElseStatement )
;

Baptiste.

----- Original Message -----
From: "David Abrahams" <dave@xxxxxxxxxxxxxxxxxxxx>
To: <c++-sig@xxxxxxxxxx>
Sent: Saturday, May 31, 2003 4:15 AM
Subject: [C++-sig] Re: Attempted a typeid of NULL pointer!


> "Marcelo A. Camelo" <camelo@xxxxxxxxxxx> writes:
>
> > Hi!
> >
> > A simple one: I'm trying to wrap a function that returns
> > a shared_ptr of a wrapped type (this type has been wrapped
> > with shared_ptr as its held_type). Everything goes fine
> > as long as the shared_ptr holds a valid pointer. If its
> > value is NULL (which is a valid value within the wrapped
> > C++ context), it raises the following exception:
> >
> > RuntimeError: Attempted a typeid of NULL pointer!
> >
> > Shouldn't it return None?
>
> Boost Version? CVS? Code for reproducing the problem?
>
> --
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise