2011/9/20 Thomas Paviot <tpav...@gmail.com> > 2011/9/20 D. Barbier <bou...@gmail.com> > >> On 2011/9/1 D. Barbier wrote: >> [...] >> > $ LD_LIBRARY_PATH=$HOME/oce-dev/lib python test_all.py >> > Traceback (most recent call last): >> > File "test_all.py", line 29, in <module> >> > import topology_operations_unittest >> > File >> "/home/barbier/Projects/pythonocc/src/unittest/topology_operations_unittest.py", >> > line 34, in <module> >> > from OCC.Utils.Construct import * >> > File >> "/home/barbier/.local/lib/python2.6/site-packages/OCC/Utils/Construct.py", >> > line 50, in <module> >> > from OCC.GEOMAlgo import GEOMAlgo_Splitter >> > ImportError: No module named GEOMAlgo >> >> I modified Construct.py to not import GEOM, > > > You're right, the depency of Construct.py with GEOM should be removed. It's > a recent commit that is not consistent with the optional GEOM wrapper. > > >> but get now a segmentation fault: >> testHash (wrapper_features_unittest.TestWrapperFeatures) ... Test: >> __hash__ overloading >> Segmentation fault >> >> More precisely: >> $ python >> Python 2.6.7 (r267:88850, Aug 3 2011, 11:33:52) >> [GCC 4.6.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import OCC.Standard >> >>> s = OCC.Standard.Standard_Transient() >> >>> hash1_s = s.__hash__() >> >>> hash2_s = s.HashCode(pow(2,31)-1) >> Segmentation fault >> >> But also: >> $ python >> Python 2.6.7 (r267:88850, Aug 3 2011, 11:33:52) >> [GCC 4.6.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import OCC.Standard >> >>> s = OCC.Standard.Standard_Transient() >> >>> hash2_s = s.HashCode(pow(2,31)-1) >> >>> hash1_s = s.__hash__() >> Segmentation fault >> >> and even >> >> $ python >> Python 2.6.7 (r267:88850, Aug 3 2011, 11:33:52) >> [GCC 4.6.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> import OCC.Standard >> >>> s = OCC.Standard.Standard_Transient() >> >>> hash1_s = s.__hash__() >> >>> hash1_s = s.__hash__() >> Segmentation fault >> >> Any idea about what is going on? >> > > When compiling pythonocc, you must pass -D__PYTHONOCCOCC_MAXINT__ integer. > It's equal to 2^32-1 on 32bit platforms, 2^64-1 on 64bit. This is computed > from the file environment.py ( > https://github.com/tpaviot/pythonocc/blob/master/src/wrapper/environment.py) > called when compiling pythonocc from the setup.py script. > > The __hash__() method does not take any argument. It is a wrapper for the > HashCode method and is is defined in the SWIG file as: > > %extend Standard_Transient { > > Standard_Integer __hash__() { > return $self->HashCode(__PYTHONOCC_MAXINT__); > } > }; > > (see for instance the file Standard.i at > https://github.com/tpaviot/pythonocc/blob/master/src/wrapper/SWIG/linux_darwin/Standard.i > ). > > >> Denis >> > > Thomas > > Sorry, it's 2^31-1 or 2^63-1 (not 2^32-1 and 2^64-1)
You can use the hash python builtin function to test that the __hash__ method works: $ python Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from OCC.Standard import * >>> s = Standard_Transient() >>> hash(s) 105437969 >>> The __hash__ method was introduced to allow OCC objects be dict keys, or use the 'in' list feature. For example : $ python Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from OCC.Standard import * >>> s1 = Standard_Transient() >>> s2 = Standard_Transient() >>> s3 = Standard_Transient() >>> s4 = Standard_Transient() >>> l = [s1,s2,s3] >>> l = [s1,s2,s3] >>> s1 in l True >>> s2 in l True >>> s4 in l False or >>> d = {} >>> d[s1]= "A first transient" >>> d[s2]= "A second transient" >>> d {<OCC.Standard.Standard_Transient; proxy of <Swig Object of type 'Standard_Transient *' at 0x10054a0c0> >: 'A first transient', <OCC.Standard.Standard_Transient; proxy of <Swig Object of type 'Standard_Transient *' at 0x100545e70> >: 'A second transient'} >>> d[s1] 'A first transient' >>> d[s2] 'A second transient' >>> Thomas
_______________________________________________ Pythonocc-users mailing list Pythonocc-users@gna.org https://mail.gna.org/listinfo/pythonocc-users