Rev 143: Pyrex (at least 0.9.8.4) treats <int>val as casting the pointer in http://bazaar.launchpad.net/~jameinel/meliae/old_pyrex_casting

John Arbash Meinel john at arbash-meinel.com
Wed Jun 30 18:29:49 BST 2010


At http://bazaar.launchpad.net/~jameinel/meliae/old_pyrex_casting

------------------------------------------------------------
revno: 143
revision-id: john at arbash-meinel.com-20100630172931-vpep50nsi0qbsh9i
parent: john at arbash-meinel.com-20100520155812-hccxcwfu9z8u4u5a
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: old_pyrex_casting
timestamp: Wed 2010-06-30 12:29:31 -0500
message:
  Pyrex (at least 0.9.8.4) treats <int>val as casting the pointer
  Rather than wanting to use PyInt_AsLong(val).
  However, using
  cdef int foo
  foo = val
  Gives the proper cast.
  As does
  cdef func(int foo):
  ...
  func(val)
  
  Anyway, just avoid the explicit casts by turning them into assignments, and things
  seem to be working.
-------------- next part --------------
=== modified file 'meliae/_intset.pyx'
--- a/meliae/_intset.pyx	2010-01-29 22:19:38 +0000
+++ b/meliae/_intset.pyx	2010-06-30 17:29:31 +0000
@@ -112,7 +112,9 @@
             perturb = perturb >> 5 # PERTURB_SHIFT
 
     def __contains__(self, val):
-        return self._contains(<int_type>val)
+        cdef int_type i_val
+        i_val = val
+        return self._contains(i_val)
 
     cdef object _contains(self, int_type c_val):
         cdef int_type *entry
@@ -220,10 +222,14 @@
     """
 
     def add(self, val):
-        self._add(<int_type>(<unsigned long>val))
+        cdef unsigned long ul_val
+        ul_val = val
+        self._add(<int_type>(ul_val))
 
     def __contains__(self, val):
-        return self._contains(<int_type>(<unsigned long>val))
+        cdef unsigned long ul_val
+        ul_val = val
+        return self._contains(<int_type>(ul_val))
 
     # TODO: Consider that the code would probably be simpler if we just
     # bit-shifted before passing the value to self._add and self._contains,



More information about the bazaar-commits mailing list