Boost logo

Boost :

From: Norman Shelley (rrdn60) (rrdn60_at_[hidden])
Date: 2001-04-16 17:38:20


When I compile the included file and run it works "right" for the null
constructor cases but seg faults for the <string> input case

% python2.1
Python 2.1b2 (#2, Apr 5 2001, 11:37:45)
[GCC 2.95.3 20010315 (release)] on hp-uxB
Type "copyright", "credits" or "license" for more information.
>>> from tst import *
>>> dir()
['__builtins__', '__doc__', '__name__', 'world']
>>> world()
World creation 'VOID'
<world object at 400961c0>
>>> world("abc")
Segmentation fault

If I comment out the NULL constructor then it works for the <string>
input case, and seg faults, instead of telling me there is not such
class constructor, for the NULL input case.
% !!
python2.1
Python 2.1b2 (#2, Apr 5 2001, 11:37:45)
[GCC 2.95.3 20010315 (release)] on hp-uxB
Type "copyright", "credits" or "license" for more information.
>>> from tst import *
>>> world("abc")
World creation 'abc'
<world object at 400961a8>
>>> world()
Segmentation fault

any ideas why this doesn't work "correctly" for overloaded
constructors?

Norman Shelley

% g++ -I../apikit/include -I/usr/local/include/python2.1
-ftemplate-depth-21 -fpic -g -c tst.cpp
% g++ -o tst.sl -shared -fpic -L../apikit/lib/hppa8000 -lMica
-lboost_python -lcl -lm tst.o

vvvvv tst.cpp vvvv
#include <string>
#include <boost/python/classes.hpp>
#include <boost/python/class_builder.hpp>
#include <boost/python/module_builder.hpp>

namespace python = boost::python;

namespace { // Avoid cluttering the global namespace.

  // A friendly class.
  class world
  {
    public:
      world() {
  fprintf(stderr, "World creation 'VOID'\n");
      }
       world(const std::string& country) {
  fprintf(stderr, "World creation '%s'\n", country.c_str());
      }
 };
}

// Python requires an exported function called init<module-name> in
every
// extension module. This is where we build the module contents.
BOOST_PYTHON_MODULE_INIT(tst)
{
 try
 {
  // Create an object representing this extension module
  python::module_builder this_module("tst");

  // Create the Python type object for our extension class.
  python::class_builder<world> world_class(this_module, "world");

  // Add the __init__ function.
  world_class.def(python::constructor<>());
  world_class.def(python::constructor<std::string>());
 }
 catch(...)
 {
  python::handle_exception(); // Deal with the exception for Python
 }
}

Boost 1.21.1

[564] % g++ --version
2.95.3
[565] % uname -a
HP-UX wvenus B.10.20 A 9000/782 2009382447 two-user license


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk