close

昨天在解bug的時候,看到SWIG有個很奇異的行為,不知道是不是bug.

首先如果有兩個同名的class在不同的模組裡, 如下:

1.模組A

#include class TheClass { public: ~TheClass() { OutputDebugStringA("The Class in Module A");} };

2.模組B

#include class TheClass { public: ~TheClass() { OutputDebugStringA("The Class in Module B");} };

然後將這兩個模組放到同一份code裡面用,你會發現SWIG會叫錯解構式,如下:

improt A import B for i in range(4): obj = A.TheClass() del obj

debugger會看到(若每個物件都被python清理了):

"The Class in Module B" "The Class in Module B" "The Class in Module B" "The Class in Module B"

這真是個奇怪的問題,以我的理解應該是不會發生這樣的事才對,可惜這確實發生了,或許我對SWIG還理解不夠吧.

所以若要把很多的模組放在一起用的話,記得檢查有沒有重名啊,不然程式可是會在莫名其妙的地方死給你看的!

arrow
arrow
    全站熱搜

    Aion 發表在 痞客邦 留言(0) 人氣()