Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost-python minimalistic example throws malloc error on macOS #85

Closed
carsten-forty2 opened this issue Feb 22, 2020 · 9 comments
Closed

Comments

@carsten-forty2
Copy link

Issue:
This issue is a sequel to #81
I experience now a weird malloc problem for a minimalistic boost-python example using std::throw in conda environment on macosx.

The given example (see below) was tested on linux, windows and macos, and only the mac version for macos gives:

python(15723,0x109c09dc0) malloc: *** error for object 0x7f95c15011f8: pointer being freed was not allocated
python(15723,0x109c09dc0) malloc: *** set a breakpoint in malloc_error_break to debug

It would be great if you also know a solution or give me some hints to debug this problem.


Environment (conda list):

# Name                    Version                   Build  Channel
boost                     1.70.0           py36hbf1eeb5_1    conda-forge
boost-cpp                 1.70.0               h75728bb_2    conda-forge
bzip2                     1.0.8                h0b31af3_2    conda-forge
ca-certificates           2019.11.28           hecc5488_0    conda-forge
certifi                   2019.11.28               py36_0    conda-forge
icu                       64.2                 h6de7cb9_1    conda-forge
libblas                   3.8.0               14_openblas    conda-forge
libcblas                  3.8.0               14_openblas    conda-forge
libcxx                    9.0.1                         0    conda-forge
libcxxabi                 9.0.1                         0    conda-forge
libffi                    3.2.1             h6de7cb9_1006    conda-forge
libgfortran               4.0.0                         2    conda-forge
liblapack                 3.8.0               14_openblas    conda-forge
libopenblas               0.3.7                h3d69b6c_6    conda-forge
llvm-openmp               9.0.1                h40edb58_0    conda-forge
ncurses                   6.1               h0a44026_1002    conda-forge
numpy                     1.17.3           py36hde6bac1_0    conda-forge
openssl                   1.1.1d               h0b31af3_0    conda-forge
pip                       19.3.1                   py36_0    conda-forge
python                    3.6.7             h4285619_1006    conda-forge
readline                  8.0                  hcfe32e1_0    conda-forge
setuptools                44.0.0                   py36_0    conda-forge
sqlite                    3.30.1               h93121df_0    conda-forge
tk                        8.6.10               hbbe82c9_0    conda-forge
wheel                     0.33.6                   py36_0    conda-forge
xz                        5.2.4             h1de35cc_1001    conda-forge
zlib                      1.2.11            h0b31af3_1006    conda-forge

Details about conda and system ( conda info ):
active environment : base
    active env location : /Users/florian/opt/anaconda3
            shell level : 1
       user config file : /Users/florian/.condarc
 populated config files : /Users/florian/.condarc
          conda version : 4.8.0
    conda-build version : 3.18.11
         python version : 3.6.9.final.0
       virtual packages : __osx=10.15.1
       base environment : /Users/florian/opt/anaconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /Users/florian/opt/anaconda3/pkgs
                          /Users/florian/.conda/pkgs
       envs directories : /Users/florian/opt/anaconda3/envs
                          /Users/florian/.conda/envs
               platform : osx-64
             user-agent : conda/4.8.0 requests/2.22.0 CPython/3.6.9 Darwin/19.0.0 OSX/10.15.1
                UID:GID : 501:20
             netrc file : None
           offline mode : False

Steps to reproduce:

The minimalistic cpp example (save as bpt.cpp):

#include "boost/python.hpp"
#include <iostream>

void t(){
   std::cout << "test throw std::out_of_range" << std::endl;
   throw std::out_of_range ("std::out_of_range");
}

namespace bp = boost::python;
BOOST_PYTHON_MODULE(_bpt_){
    bp::def("t", t, "");
}

The python test file: (save as bpt.py )

import _bpt_

print(dir(_bpt_))

try:
    _bpt_.t()
except Exception as e:
    print("catched:", e) # Exception will not be catched but throws the malloc problem

A Makefile to build the bindings (save as Makefile ) and you probably need to correct the ENV variable

TARGET=_bpt_

ENV=/Users/florian/opt/anaconda3/envs/boost

PYINC=-I $(ENV)/include/python3.6m/
BPLIB=$(ENV)/lib/libboost_python36.dylib
BPINC=-I $(ENV)/include

CXX=clang++ 
AR=clang++ -bundle -undefined dynamic_lookup

default:

        $(CXX) -fPIC -c bpt.cpp $(PYINC) $(BPINC)
        $(AR) -o $(TARGET).so *.o $(BPLIB)

test:
        python bpt.py

clean:
        rm -f *.o *.so *~

Finally create the environment and test the problem.

conda create -c conda-forge -n boost boost python=3.6
conda activate boost
make
make test

The method t() should throw the exception but the uncatchable malloc problems occurs instead.

Best regards and thank you,
Carsten

@jschueller
Copy link
Contributor

Does not seem related to conda-forge, ask upstream

@isuruf
Copy link
Member

isuruf commented Feb 22, 2020

Can you remove the libcxxabi package?

@isuruf isuruf reopened this Feb 22, 2020
@carsten-forty2
Copy link
Author

how should I remove the libcxxabi package?

@isuruf
Copy link
Member

isuruf commented Feb 22, 2020

conda remove libcxxabi

@carsten-forty2
Copy link
Author

RemoveError: This operation will remove conda without replacing it with
another version of conda.

@isuruf
Copy link
Member

isuruf commented Feb 22, 2020

conda remove libcxxabi -n boost

@carsten-forty2
Copy link
Author

clang++  -fPIC -c bpt.cpp -I /Users/florian/opt/anaconda3/envs/boost/include/python3.6m/ -I /Users/florian/opt/anaconda3/envs/boost/include
bpt.cpp:1:10: fatal error: 'boost/python.hpp' file not found
#include "boost/python.hpp"
         ^~~~~~~~~~~~~~~~~~

no clue how this happen now

@carsten-forty2
Copy link
Author

okay fresh environment and the problem seems to be gone .. I need to check my tool chains now.

Thanks a lot.

@jakirkham
Copy link
Member

People often install the compilers package to do development in a Conda environment. Maybe this will work nicer for you 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants