Wednesday, 15 June 2011

python - Returning from __len__() when >64 bits -


In this problem, I am working with IPv6 network address spaces, therefore the length is 2 ^ (128 - subnet) .

It appears that the dragon (at least on this machine) will face a 64 bit signed number from __en () lane (IP ('2001 :: / 66')) works , but lane fails (IP ('2001 :: / 65')) . From the IPI import IP lane (IP ('2001 :: / 64')) Traceback (most recent call final): File "test.py", line 2, & lt; Module & gt; To convert overflow error: int int

to LAN (IP ('2001 :: / 64')), long int is too large to be questioned on the IPy library.

Any suggestions on how to handle it, or the sign that it might be a limitation? I

The issue you're killing is that one of the containers in the Python's C API There is a system-dependent limit. That is, the C function PyObject_Size returns a Py_ssize_t value, which is a signed version of standard C size_t type. This size is dependent on the system, but 32-bit systems have 64 bits on 32 bits and 64-bit systems.

The builtin len function is used by PyObject_Size , so it has its own limitations here: Fixed PyObject * Builtin_len (PyObject * self, PyObject * v) {Py_ssize_t res; Res = PyObject_Size (v); If (RAS & lt; 0 & amp; amp; amp;; PyErr_Occurred ()) return; Return PIINT_From SSIID_T (RAC); }

Instead of calling builtin you work around this limit using the len method on the IP object You can. Len :

  IP ('2001 :: / 64'). Len ()   

This is a pure python, so this is no limit on the integer shape.

No comments:

Post a Comment