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

Side by Side Diff: Objects/exceptions.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 10 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:
View unified diff | Download patch
« no previous file with comments | « Objects/abstract.c ('k') | Objects/frameobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * New exceptions.c written in Iceland by Richard Jones and Georg Brandl. 2 * New exceptions.c written in Iceland by Richard Jones and Georg Brandl.
3 * 3 *
4 * Thanks go to Tim Peters and Michael Hudson for debugging. 4 * Thanks go to Tim Peters and Michael Hudson for debugging.
5 */ 5 */
6 6
7 #define PY_SSIZE_T_CLEAN 7 #define PY_SSIZE_T_CLEAN
8 #include <Python.h> 8 #include <Python.h>
9 #include "structmember.h" 9 #include "structmember.h"
10 #include "osdefs.h" 10 #include "osdefs.h"
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 /* 480 /*
481 * TypeError extends Exception 481 * TypeError extends Exception
482 */ 482 */
483 SimpleExtendsException(PyExc_Exception, TypeError, 483 SimpleExtendsException(PyExc_Exception, TypeError,
484 "Inappropriate argument type."); 484 "Inappropriate argument type.");
485 485
486 486
487 /* 487 /*
488 * StopIteration extends Exception 488 * StopIteration extends Exception
489 */ 489 */
490 SimpleExtendsException(PyExc_Exception, StopIteration, 490
491 "Signal the end from iterator.__next__()."); 491 //SimpleExtendsException(PyExc_Exception, StopIteration,
492 // "Signal the end from iterator.__next__().");
493
494 static PyMemberDef StopIteration_members[] = {
495 {"value", T_OBJECT, offsetof(PyStopIterationObject, value), 0,
496 PyDoc_STR("generator return value")},
497 {NULL} /* Sentinel */
498 };
499
500 static int
501 StopIteration_init(PyStopIterationObject *self, PyObject *args, PyObject *kwds)
502 {
503 Py_ssize_t size = PyTuple_GET_SIZE(args);
504 PyObject *value;
505
506 if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)
507 return -1;
508 Py_CLEAR(self->value);
509 if (size > 0)
510 value = PyTuple_GET_ITEM(args, 0);
511 else
512 value = Py_None;
513 Py_INCREF(value);
514 self->value = value;
515 return 0;
516 }
517
518 static int
519 StopIteration_clear(PyStopIterationObject *self)
520 {
521 Py_CLEAR(self->value);
522 return BaseException_clear((PyBaseExceptionObject *)self);
523 }
524
525 static void
526 StopIteration_dealloc(PyStopIterationObject *self)
527 {
528 _PyObject_GC_UNTRACK(self);
529 StopIteration_clear(self);
530 Py_TYPE(self)->tp_free((PyObject *)self);
531 }
532
533 static int
534 StopIteration_traverse(PyStopIterationObject *self, visitproc visit, void *arg)
535 {
536 Py_VISIT(self->value);
537 return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);
538 }
539
540 PyObject *
541 PyStopIteration_Create(PyObject *value)
542 {
543 return PyObject_CallFunctionObjArgs(PyExc_StopIteration, value, NULL);
544 }
545
546 ComplexExtendsException(
547 PyExc_Exception, /* base */
548 StopIteration, /* name */
549 StopIteration, /* prefix for *_init, etc */
550 0, /* new */
551 0, /* methods */
552 StopIteration_members, /* members */
553 0, /* getset */
554 0, /* str */
555 "Signal the end from iterator.__next__()."
556 );
492 557
493 558
494 /* 559 /*
495 * GeneratorExit extends BaseException 560 * GeneratorExit extends BaseException
496 */ 561 */
497 SimpleExtendsException(PyExc_BaseException, GeneratorExit, 562 SimpleExtendsException(PyExc_BaseException, GeneratorExit,
498 "Request that a generator exit."); 563 "Request that a generator exit.");
499 564
500 565
501 /* 566 /*
(...skipping 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after
2294 Py_DECREF(bltinmod); 2359 Py_DECREF(bltinmod);
2295 } 2360 }
2296 2361
2297 void 2362 void
2298 _PyExc_Fini(void) 2363 _PyExc_Fini(void)
2299 { 2364 {
2300 Py_CLEAR(PyExc_RecursionErrorInst); 2365 Py_CLEAR(PyExc_RecursionErrorInst);
2301 free_preallocated_memerrors(); 2366 free_preallocated_memerrors();
2302 Py_CLEAR(errnomap); 2367 Py_CLEAR(errnomap);
2303 } 2368 }
OLDNEW
« no previous file with comments | « Objects/abstract.c ('k') | Objects/frameobject.c » ('j') | no next file with comments »

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