2011-07-15 6 views
4

私は非常にシンプルな処理をしようとしています。標準のPythonの範囲内に入ります。次の関数は、集合の集合をとり、2つ以上の集合に含まれるすべての項目を返します。Ironpython:関数はCPythonで動作し、IronPythonでは不思議なヌルポインタ例外が発生します。

これを行うには、集合の集合が空ではない間に、コレクションから1つの集合をポップし、それを残りの集合と交差させ、これらの交点の1つに入る項目の集合を更新する。

def cross_intersections(sets): 
    in_two = set() 
    sets_copy = copy(sets) 
    while sets_copy: 
     comp = sets_copy.pop() 
     for each in sets_copy: 
      new = comp & each 
      print new,   # Print statements to show that these references exist 
      print in_two 
      in_two |= new  #This is where the error occurs in IronPython 
    return in_two 

上記は私が使用している機能です。私はIronPythonの使用しようとすると、しかし

>>> a = set([1,2,3,4]) 
>>> b = set([3,4,5,6]) 
>>> c = set([2,4,6,8]) 

>>> cross = cross_intersections([a,b,c]) 
set([2, 4]) set([]) 
set([4, 6]) set([2, 4]) 
set([3, 4]) set([2, 4, 6]) 
>>> cross 
set([2, 3, 4, 6]) 

::、CPythonの中で、次のような作品を、それをテストするには、タイトルに

>>> b = cross_intersections([a,b,c]) 
set([2, 4]) set([]) 
set([4, 6]) set([2, 4]) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "c:/path/to/code.py", line 10, in cross_intersections 
SystemError: Object reference not set to an instance of an object. 

を私は、これは神秘的なnullポインタ例外であると言いました。私はおそらく、.NETがnullポインタを処理する方法(私はC言語に慣れたことがなく、IronPythonを1ヶ月間しか使用していませんでした)を理解していないかもしれませんが、わかっていれば、 nullを指すオブジェクトのプロパティにアクセスします。

この場合、エラーは私の関数の行10に発生します:in_two |= new。しかし、これらのオブジェクトのどちらもnullを指していないことを(少なくとも私にとっては)示すこの行の直前にprintという文を入れました。

どこが間違っていますか?

+0

http://ironpython.codeplex.com/workitem/30386と思われます。トランクにalredyを固定する必要があります。 –

+0

そのように見えます。私はこれが事実かどうか疑問に思っていましたが、私は環境を非難することは決してありません。それを答えに入れて、私はそれを受け入れます。 – Wilduck

答えて

3

It's a bug。 2.7.1で修正される予定ですが、修正は2.7.1 Beta 1リリースにはないと思います。

1

これは、まだ2.7.1 Beta 1リリースに存在するbugです。

masterで修正され、修正は次のリリースに含まれます。

IronPython 3.0 (3.0.0.0) on .NET 4.0.30319.235 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import copy 
>>> 
>>> def cross_intersections(sets): 
...  in_two = set() 
...  sets_copy = copy.copy(sets) 
...  while sets_copy: 
...   comp = sets_copy.pop() 
...   for each in sets_copy: 
...    new = comp & each 
...    print new,  # Print statements to show that these references exist 
...    print in_two 
...    in_two |= new # This is where the error occurs in IronPython 
...  return in_two 
... 
>>> 
>>> a = set([1,2,3,4]) 
>>> b = set([3,4,5,6]) 
>>> c = set([2,4,6,8]) 
>>> 
>>> cross = cross_intersections([a,b,c]) 
set([2, 4]) set([]) 
set([4, 6]) set([2, 4]) 
set([3, 4]) set([2, 4, 6]) 
関連する問題