From d8b24cf10fae4388afc320d69f9ff21a76d84870 2014-10-15 19:23:33 From: MinRK Date: 2014-10-15 19:23:33 Subject: [PATCH] unsigned ints for offsets because signed ints for sizes is icky --- diff --git a/IPython/html/base/zmqhandlers.py b/IPython/html/base/zmqhandlers.py index 0287502..d0b77a1 100644 --- a/IPython/html/base/zmqhandlers.py +++ b/IPython/html/base/zmqhandlers.py @@ -54,7 +54,7 @@ def serialize_binary_message(msg): offsets = [4 * (nbufs + 1)] for buf in buffers[:-1]: offsets.append(offsets[-1] + len(buf)) - offsets_buf = struct.pack('!' + 'i' * (nbufs + 1), nbufs, *offsets) + offsets_buf = struct.pack('!' + 'I' * (nbufs + 1), nbufs, *offsets) buffers.insert(0, offsets_buf) return b''.join(buffers) @@ -75,7 +75,7 @@ def deserialize_binary_message(bmsg): message dictionary """ nbufs = struct.unpack('!i', bmsg[:4])[0] - offsets = list(struct.unpack('!' + 'i' * nbufs, bmsg[4:4*(nbufs+1)])) + offsets = list(struct.unpack('!' + 'I' * nbufs, bmsg[4:4*(nbufs+1)])) offsets.append(None) bufs = [] for start, stop in zip(offsets[:-1], offsets[1:]): diff --git a/IPython/html/static/services/kernels/js/serialize.js b/IPython/html/static/services/kernels/js/serialize.js index 4f0d48c..7ba0fe0 100644 --- a/IPython/html/static/services/kernels/js/serialize.js +++ b/IPython/html/static/services/kernels/js/serialize.js @@ -9,11 +9,11 @@ define([ var _deserialize_array_buffer = function (buf) { var data = new DataView(buf); // read the header: 1 + nbufs 32b integers - var nbufs = data.getInt32(0); + var nbufs = data.getUint32(0); var offsets = []; var i; for (i = 1; i <= nbufs; i++) { - offsets.push(data.getInt32(i * 4)); + offsets.push(data.getUint32(i * 4)); } var json_bytes = new Uint8Array(buf.slice(offsets[0], offsets[1])); var msg = $.parseJSON( @@ -81,13 +81,13 @@ define([ var msg_buf = new Uint8Array( offsets[offsets.length-1] + buffers[buffers.length-1].byteLength ); - // use DataView.setInt32 for network byte-order + // use DataView.setUint32 for network byte-order var view = new DataView(msg_buf.buffer); // write nbufs to first 4 bytes - view.setInt32(0, nbufs); + view.setUint32(0, nbufs); // write offsets to next 4 * nbufs bytes for (i = 0; i < offsets.length; i++) { - view.setInt32(4 * (i+1), offsets[i]); + view.setUint32(4 * (i+1), offsets[i]); } // write all the buffers at their respective offsets for (i = 0; i < buffers.length; i++) {