Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(14646)

Delta Between Two Patch Sets: Modules/mmapmodule.c

Issue 26335: Make mmap.write return the number of bytes written like other write methods
Left Patch Set: Created 3 years, 3 months ago
Right Patch Set: Created 3 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_mmap.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 / Author: Sam Rushing <rushing@nightmare.com> 2 / Author: Sam Rushing <rushing@nightmare.com>
3 / Hacked for Unix by AMK 3 / Hacked for Unix by AMK
4 / $Id$ 4 / $Id$
5 5
6 / Modified to support mmap with offset - to map a 'window' of a file 6 / Modified to support mmap with offset - to map a 'window' of a file
7 / Author: Yotam Medini yotamm@mellanox.co.il 7 / Author: Yotam Medini yotamm@mellanox.co.il
8 / 8 /
9 / mmapmodule.cpp -- map a view of a file into memory 9 / mmapmodule.cpp -- map a view of a file into memory
10 / 10 /
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 "mmap can't resize a readonly or copy-on-write memory map."); 382 "mmap can't resize a readonly or copy-on-write memory map.");
383 return 0; 383 return 0;
384 } 384 }
385 385
386 386
387 static PyObject * 387 static PyObject *
388 mmap_write_method(mmap_object *self, 388 mmap_write_method(mmap_object *self,
389 PyObject *args) 389 PyObject *args)
390 { 390 {
391 Py_buffer data; 391 Py_buffer data;
392 PyObject *result;
392 393
393 CHECK_VALID(NULL); 394 CHECK_VALID(NULL);
394 if (!PyArg_ParseTuple(args, "y*:write", &data)) 395 if (!PyArg_ParseTuple(args, "y*:write", &data))
395 return(NULL); 396 return(NULL);
396 397
397 if (!is_writable(self)) { 398 if (!is_writable(self)) {
398 PyBuffer_Release(&data); 399 PyBuffer_Release(&data);
399 return NULL; 400 return NULL;
400 } 401 }
401 402
402 if ((self->pos + data.len) > self->size) { 403 if ((self->pos + data.len) > self->size) {
403 PyErr_SetString(PyExc_ValueError, "data out of range"); 404 PyErr_SetString(PyExc_ValueError, "data out of range");
404 PyBuffer_Release(&data); 405 PyBuffer_Release(&data);
405 return NULL; 406 return NULL;
406 } 407 }
407 memcpy(self->data + self->pos, data.buf, data.len); 408 memcpy(self->data + self->pos, data.buf, data.len);
408 self->pos = self->pos + data.len; 409 self->pos = self->pos + data.len;
410 result = PyLong_FromSsize_t(data.len);
409 PyBuffer_Release(&data); 411 PyBuffer_Release(&data);
410 Py_INCREF(Py_None); 412 return result;
411 return PyLong_FromSsize_t(data.len);
berkerpeksag 2016/02/23 00:57:52 We need to save the value of ``data.len`` before t
412 } 413 }
413 414
414 static PyObject * 415 static PyObject *
415 mmap_write_byte_method(mmap_object *self, 416 mmap_write_byte_method(mmap_object *self,
416 PyObject *args) 417 PyObject *args)
417 { 418 {
418 char value; 419 char value;
419 420
420 CHECK_VALID(NULL); 421 CHECK_VALID(NULL);
421 if (!PyArg_ParseTuple(args, "b:write_byte", &value)) 422 if (!PyArg_ParseTuple(args, "b:write_byte", &value))
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 1528
1528 setint(dict, "PAGESIZE", (long)my_getpagesize()); 1529 setint(dict, "PAGESIZE", (long)my_getpagesize());
1529 1530
1530 setint(dict, "ALLOCATIONGRANULARITY", (long)my_getallocationgranularity()); 1531 setint(dict, "ALLOCATIONGRANULARITY", (long)my_getallocationgranularity());
1531 1532
1532 setint(dict, "ACCESS_READ", ACCESS_READ); 1533 setint(dict, "ACCESS_READ", ACCESS_READ);
1533 setint(dict, "ACCESS_WRITE", ACCESS_WRITE); 1534 setint(dict, "ACCESS_WRITE", ACCESS_WRITE);
1534 setint(dict, "ACCESS_COPY", ACCESS_COPY); 1535 setint(dict, "ACCESS_COPY", ACCESS_COPY);
1535 return module; 1536 return module;
1536 } 1537 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+