[C++-sig] Overloading & keyword args bug?

David Abrahams dave at boost-consulting.com
Mon Jun 12 16:12:57 CEST 2006


Alex Mohr <amohr at pixar.com> writes:

> Hi folks,
>
> Can someone tell me what's wrong with this?  As is, this code crashes in 
> the example below (anytime I try to pass keyword arguments to the first 
> overload).  If I reverse the order of the lines marked with ########, 
> everything seems to work fine.
>
> Thanks!
>
> Alex
>
>
> #include <boost/python.hpp>
> #include <string>
> #include <cstdio>
>
> using namespace boost::python;
> using std::string;
>
> static void f1(string const &a1, int x, int y) {
>      printf("f1 with %s, %d, %d\n", a1.c_str(), x, y);
> }
>
> static void f2(string const &a1, string const &a2, int x, int y) {
>      printf("f2 with %s, %s, %d, %d\n", a1.c_str(), a2.c_str(), x, y);
> }
>
> BOOST_PYTHON_MODULE(overload_kw) {
>      def("f", f1, (arg("x")=3, arg("y")=4)); // ########
>      def("f", f2, (arg("x")=5, arg("y")=6)); // ########
> }
>
> ---------------------------------------
>
>  >>> from overload_kw import *
>  >>> f('hello')
> f1 with hello, 3, 4
>  >>> f('hello', 'goodbye')
> f2 with hello, goodbye, 5, 6
>  >>> f('hello', 1, 2)
> f1 with hello, 1, 2
>  >>> f('hello', x=1)
> Segmentation fault

Broken compiler code generation?  The enclosed works for me without
errors.  Got a stack backtrace?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: alex_mohr.zip
Type: application/zip
Size: 1875 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060612/fccb8840/attachment.zip>
-------------- next part --------------

myjam -sTOOLS=vc-8_0 --verbose-test test
...found 1671 targets...
...updating 6 targets...
vc-C++ c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack.obj
quack.cpp
vc-Link c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack_ext.pyd c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack_ext.lib
   Creating library c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack_ext.lib and object c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack_ext.exp
Microsoft (R) Manifest Tool version 5.2.3790.2014.
Copyright (c) Microsoft Corporation 2005. .
All rights reserved..
execute-test c:\tmp\build\bin\boost\libs\python\user\quack.test\vc-8_0\debug\threading-multi\quack.run
        1 file(s) copied.
====== BEGIN OUTPUT ======
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# c:\Python24\lib\site.pyc matches c:\Python24\lib\site.py
import site # precompiled from c:\Python24\lib\site.pyc
# c:\Python24\lib\os.pyc matches c:\Python24\lib\os.py
import os # precompiled from c:\Python24\lib\os.pyc
import nt # builtin
# c:\Python24\lib\ntpath.pyc matches c:\Python24\lib\ntpath.py
import ntpath # precompiled from c:\Python24\lib\ntpath.pyc
# c:\Python24\lib\stat.pyc matches c:\Python24\lib\stat.py
import stat # precompiled from c:\Python24\lib\stat.pyc
# c:\Python24\lib\UserDict.pyc matches c:\Python24\lib\UserDict.py
import UserDict # precompiled from c:\Python24\lib\UserDict.pyc
# c:\Python24\lib\copy_reg.pyc matches c:\Python24\lib\copy_reg.py
import copy_reg # precompiled from c:\Python24\lib\copy_reg.pyc
# c:\Python24\lib\types.pyc matches c:\Python24\lib\types.py
import types # precompiled from c:\Python24\lib\types.pyc
# c:\Python24\lib\locale.pyc matches c:\Python24\lib\locale.py
import locale # precompiled from c:\Python24\lib\locale.pyc
import _locale # builtin
# c:\Python24\lib\codecs.pyc matches c:\Python24\lib\codecs.py
import codecs # precompiled from c:\Python24\lib\codecs.pyc
import _codecs # builtin
import encodings # directory c:\Python24\lib\encodings
# c:\Python24\lib\encodings\__init__.pyc matches c:\Python24\lib\encodings\__init__.py
import encodings # precompiled from c:\Python24\lib\encodings\__init__.pyc
# c:\Python24\lib\encodings\aliases.pyc matches c:\Python24\lib\encodings\aliases.py
import encodings.aliases # precompiled from c:\Python24\lib\encodings\aliases.pyc
# c:\Python24\lib\encodings\cp1252.pyc matches c:\Python24\lib\encodings\cp1252.py
import encodings.cp1252 # precompiled from c:\Python24\lib\encodings\cp1252.pyc
# c:\Python24\lib\warnings.pyc matches c:\Python24\lib\warnings.py
import warnings # precompiled from c:\Python24\lib\warnings.pyc
# c:\Python24\lib\linecache.pyc matches c:\Python24\lib\linecache.py
import linecache # precompiled from c:\Python24\lib\linecache.pyc
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import quack_ext # dynamically loaded from c:\tmp\build\bin\boost\libs\python\user\quack_ext.pyd\vc-8_0\debug\threading-multi\quack_ext.pyd
# clear __builtin__._
# clear sys.path
# clear sys.argv
# clear sys.ps1
# clear sys.ps2
# clear sys.exitfunc
# clear sys.exc_type
# clear sys.exc_value
# clear sys.exc_traceback
# clear sys.last_type
# clear sys.last_value
# clear sys.last_traceback
# clear sys.path_hooks
# clear sys.path_importer_cache
# clear sys.meta_path
# restore sys.stdin
# restore sys.stdout
# restore sys.stderr
# cleanup __main__
# cleanup[1] locale
# cleanup[1] site
# cleanup[1] encodings
# cleanup[1] quack_ext
# cleanup[1] nt
# cleanup[1] zipimport
# cleanup[1] warnings
# cleanup[1] _codecs
# cleanup[1] encodings.cp1252
# cleanup[1] codecs
# cleanup[1] types
# cleanup[1] _locale
# cleanup[1] signal
# cleanup[1] linecache
# cleanup[1] encodings.aliases
# cleanup[1] exceptions
# cleanup[2] copy_reg
# cleanup[2] os.path
# cleanup[2] ntpath
# cleanup[2] UserDict
# cleanup[2] stat
# cleanup[2] os
# cleanup sys
# cleanup __builtin__
# cleanup ints: 7 unfreed ints in 1 out of 5 blocks
# cleanup floats
f1 with hello, 3, 4
f2 with hello, goodbye, 5, 6
f1 with hello, 1, 2
f1 with hello, 1, 4
 
EXIT STATUS: 0 
====== END OUTPUT ======
**passed** c:\tmp\build\bin\boost\libs\python\user\quack.test\vc-8_0\debug\threading-multi\quack.test
...updated 6 targets...



-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com


More information about the Cplusplus-sig mailing list