Keyboard Shortcuts

File
u :up to issue
m :publish + mail comments
M :edit review message
j / k :jump to file after / before current file
J / K :jump to next file with a comment after / before current file
Side-by-side diff
i :toggle intra-line diffs
e :expand all comments
c :collapse all comments
s :toggle showing all comments
n / p :next / previous diff chunk or comment
N / P :next / previous comment
<Up> / <Down> :next / previous line
<Enter> :respond to / edit current comment
d :mark current comment as done
Issue
u :up to list of issues
m :publish + mail comments
j / k :jump to patch after / before current patch
o / <Enter> :open current patch in side-by-side view
i :open current patch in unified diff view
Issue List
j / k :jump to issue after / before current issue
o / <Enter> :open current issue
# : close issue
Comment/message editing
<Ctrl> + s or <Ctrl> + Enter :save comment
<Esc> :cancel edit
Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(42)
Issues Repositories Search
Open Issues | Closed Issues | All Issues | Sign in with your Google Account to create issues and add comments

Delta Between Two Patch Sets: Objects/memoryobject.c

Issue 3004: (not quite finished) memoryview implementation (Closed) Base URL: http://svn.python.org/view/*checkout*/python/branches/py3k/
Left Patch Set: Created 17 years, 4 months ago
Right Patch Set: Fix some small exception bugs Created 17 years, 4 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_memoryview.py ('k') | no next file » | no next file with change/comment »
('i') | ('e') | ('c') | ('s')
LEFTRIGHT
1 1
2 /* Memoryview object implementation */ 2 /* Memoryview object implementation */
3 3
4 #include "Python.h" 4 #include "Python.h"
5 5
6 static int 6 static int
7 memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags) 7 memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags)
8 { 8 {
9 if (view != NULL) { 9 if (view != NULL) {
10 if (self->view.obj) 10 if (self->view.obj)
(...skipping 395 matching lines...) | | Loading...
406 PyObject *res, *item; 406 PyObject *res, *item;
407 char *buf; 407 char *buf;
408 408
409 if (strcmp(view->format, "B") || view->itemsize != 1) { 409 if (strcmp(view->format, "B") || view->itemsize != 1) {
410 PyErr_SetString(PyExc_NotImplementedError,· 410 PyErr_SetString(PyExc_NotImplementedError,·
411 "tolist() only supports byte views"); 411 "tolist() only supports byte views");
412 return NULL; 412 return NULL;
413 } 413 }
414 if (view->ndim != 1) { 414 if (view->ndim != 1) {
415 PyErr_SetString(PyExc_NotImplementedError,· 415 PyErr_SetString(PyExc_NotImplementedError,·
416 » » » "tolist() only accepts one-dimensional objects"); 416 » » » "tolist() only supports one-dimensional objects");
Benjamin 2008年08月19日 19:59:52 "accepts" should be "supports"
"accepts" should be "supports"
Antoine Pitrou 2008年08月19日 20:12:48 Ok.
On 2008年08月19日 19:59:52, Benjamin wrote: > "accepts" should be "supports"
Ok.
417 return NULL; 417 return NULL;
418 } 418 }
419 res = PyList_New(view->len); 419 res = PyList_New(view->len);
420 if (res == NULL) 420 if (res == NULL)
421 return NULL; 421 return NULL;
422 buf = view->buf; 422 buf = view->buf;
423 for (i = 0; i < view->len; i++) { 423 for (i = 0; i < view->len; i++) {
424 item = PyLong_FromUnsignedLong((unsigned char) *buf); 424 item = PyLong_FromUnsignedLong((unsigned char) *buf);
425 if (item == NULL) { 425 if (item == NULL) {
426 Py_DECREF(res); 426 Py_DECREF(res);
(...skipping 169 matching lines...) | | Loading...
596 } 596 }
597 newview.buf = newbuf; 597 newview.buf = newbuf;
598 newview.len = slicelength; 598 newview.len = slicelength;
599 newview.format = view->format; 599 newview.format = view->format;
600 if (view->shape == &(view->len)) 600 if (view->shape == &(view->len))
601 newview.shape = &(newview.len); 601 newview.shape = &(newview.len);
602 if (view->strides == &(view->itemsize)) 602 if (view->strides == &(view->itemsize))
603 newview.strides = &(newview.itemsize); 603 newview.strides = &(newview.itemsize);
604 return PyMemoryView_FromBuffer(&newview); 604 return PyMemoryView_FromBuffer(&newview);
605 } 605 }
606 PyErr_SetNone(PyExc_NotImplementedError); 606 » » PyErr_SetNone(PyExc_NotImplementedError);
607 » » return NULL;
607 } 608 }
608 PyErr_Format(PyExc_TypeError, 609 PyErr_Format(PyExc_TypeError,
609 "cannot index memory using \"%.200s\"",· 610 "cannot index memory using \"%.200s\"",·
610 key->ob_type->tp_name); 611 key->ob_type->tp_name);
611 return NULL; 612 return NULL;
612 } 613 }
613 614
614 615
615 /* Need to support assigning memory if we can */ 616 /* Need to support assigning memory if we can */
616 static int 617 static int
(...skipping 84 matching lines...) | | Loading...
701 return 0; 702 return 0;
702 703
703 _error: 704 _error:
704 PyBuffer_Release(&srcview); 705 PyBuffer_Release(&srcview);
705 return -1; 706 return -1;
706 } 707 }
707 708
708 static PyObject * 709 static PyObject *
709 memory_richcompare(PyObject *v, PyObject *w, int op) 710 memory_richcompare(PyObject *v, PyObject *w, int op)
710 { 711 {
711 Py_buffer vv, ww; 712 » Py_buffer vv, ww;
712 int equal = 0; 713 » int equal = 0;
713 PyObject *res; 714 » PyObject *res;
714 715
715 vv.obj = NULL; 716 » vv.obj = NULL;
716 ww.obj = NULL; 717 » ww.obj = NULL;
717 if (op != Py_EQ && op != Py_NE) 718 » if (op != Py_EQ && op != Py_NE)
718 goto _notimpl; 719 » » goto _notimpl;
719 if (PyObject_GetBuffer(v, &vv, PyBUF_CONTIG_RO) == -1) 720 » if (PyObject_GetBuffer(v, &vv, PyBUF_CONTIG_RO) == -1) {
720 goto _notimpl; 721 » » PyErr_Clear();
721 if (PyObject_GetBuffer(w, &ww, PyBUF_CONTIG_RO) == -1) 722 » » goto _notimpl;
722 goto _notimpl; 723 » }
723 724 » if (PyObject_GetBuffer(w, &ww, PyBUF_CONTIG_RO) == -1) {
724 if (vv.itemsize != ww.itemsize || vv.len != ww.len) 725 » » PyErr_Clear();
725 goto _end; 726 » » goto _notimpl;
726 727 » }
727 equal = !memcmp(vv.buf, ww.buf, vv.len * vv.itemsize); 728
729 » if (vv.itemsize != ww.itemsize || vv.len != ww.len)
730 » » goto _end;
731
732 » equal = !memcmp(vv.buf, ww.buf, vv.len * vv.itemsize);
728 733
729 _end: 734 _end:
730 PyBuffer_Release(&vv); 735 » PyBuffer_Release(&vv);
731 PyBuffer_Release(&ww); 736 » PyBuffer_Release(&ww);
732 if ((equal && op == Py_EQ) || (!equal && op == Py_NE)) 737 » if ((equal && op == Py_EQ) || (!equal && op == Py_NE))
733 res = Py_True; 738 » » res = Py_True;
734 else 739 » else
735 res = Py_False; 740 » » res = Py_False;
736 Py_INCREF(res); 741 » Py_INCREF(res);
737 return res; 742 » return res;
738 743
739 _notimpl: 744 _notimpl:
740 PyBuffer_Release(&vv); 745 » PyBuffer_Release(&vv);
741 PyBuffer_Release(&ww); 746 » PyBuffer_Release(&ww);
742 Py_INCREF(Py_NotImplemented); 747 » Py_INCREF(Py_NotImplemented);
743 return Py_NotImplemented; 748 » return Py_NotImplemented;
744 } 749 }
745 750
746 751
747 /* As mapping */ 752 /* As mapping */
748 static PyMappingMethods memory_as_mapping = { 753 static PyMappingMethods memory_as_mapping = {
749 (lenfunc)memory_length, /*mp_length*/ 754 (lenfunc)memory_length, /*mp_length*/
750 (binaryfunc)memory_subscript, /*mp_subscript*/ 755 (binaryfunc)memory_subscript, /*mp_subscript*/
751 (objobjargproc)memory_ass_sub, /*mp_ass_subscript*/ 756 (objobjargproc)memory_ass_sub, /*mp_ass_subscript*/
752 }; 757 };
753 758
(...skipping 23 matching lines...) Loading...
777 0, /* tp_hash */ 782 0, /* tp_hash */
778 0, /* tp_call */ 783 0, /* tp_call */
779 (reprfunc)memory_str, /* tp_str */ 784 (reprfunc)memory_str, /* tp_str */
780 PyObject_GenericGetAttr, /* tp_getattro */ 785 PyObject_GenericGetAttr, /* tp_getattro */
781 0, /* tp_setattro */ 786 0, /* tp_setattro */
782 &memory_as_buffer, /* tp_as_buffer */ 787 &memory_as_buffer, /* tp_as_buffer */
783 Py_TPFLAGS_DEFAULT, /* tp_flags */ 788 Py_TPFLAGS_DEFAULT, /* tp_flags */
784 memory_doc, /* tp_doc */ 789 memory_doc, /* tp_doc */
785 0, /* tp_traverse */ 790 0, /* tp_traverse */
786 0, /* tp_clear */ 791 0, /* tp_clear */
787 » memory_richcompare,» » /* tp_richcompare */ 792 » memory_richcompare, /* tp_richcompare */
Benjamin 2008年08月19日 19:59:52 Looks like /* tp_richcompare */ needs to be reinde
Looks like /* tp_richcompare */ needs to be reindented.
Antoine Pitrou 2008年08月19日 20:12:48 Indeed.
On 2008年08月19日 19:59:52, Benjamin wrote: > Looks like /* tp_richcompare */ needs to be reindented.
Indeed.
GvR 2008年08月19日 20:20:18 please use spaces here.
please use spaces here.
788 0, /* tp_weaklistoffset */ 793 0, /* tp_weaklistoffset */
789 0, /* tp_iter */ 794 0, /* tp_iter */
790 0, /* tp_iternext */ 795 0, /* tp_iternext */
791 memory_methods, /* tp_methods */ 796 memory_methods, /* tp_methods */
792 0, /* tp_members */ 797 0, /* tp_members */
793 memory_getsetlist, /* tp_getset */ 798 memory_getsetlist, /* tp_getset */
794 0, /* tp_base */ 799 0, /* tp_base */
795 0, /* tp_dict */ 800 0, /* tp_dict */
796 0, /* tp_descr_get */ 801 0, /* tp_descr_get */
797 0, /* tp_descr_set */ 802 0, /* tp_descr_set */
798 0, /* tp_dictoffset */ 803 0, /* tp_dictoffset */
799 0, /* tp_init */ 804 0, /* tp_init */
800 0, /* tp_alloc */ 805 0, /* tp_alloc */
801 memory_new, /* tp_new */ 806 memory_new, /* tp_new */
802 }; 807 };
LEFTRIGHT
« Lib/test/test_memoryview.py ('k') | no next file » | ('i') | ('e') | ('c') | ('s')
Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b

AltStyle によって変換されたページ (->オリジナル) /