[Python-checkins] python/dist/src/Modules _hotshot.c,1.19,1.20

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Wed, 17 Jul 2002 09:15:37 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv12160

Modified Files:
	_hotshot.c 
Log Message:
Some modernization.  Get rid of the redundant next() method.  Always
assume tp_iter and later fields exist.  Use PyObject_GenericGetAttr
instead of providing our own tp_getattr hook.


Index: _hotshot.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_hotshot.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** _hotshot.c	30 Jun 2002 15:26:09 -0000	1.19
--- _hotshot.c	17 Jul 2002 16:15:35 -0000	1.20
***************
*** 121,129 ****
  }
  
- #if Py_TPFLAGS_HAVE_ITER
- /* This is only used if the interpreter has iterator support; the
-  * iternext handler is also used as a helper for other functions, so
-  * does not need to be included in this conditional section.
-  */
  static PyObject *
  logreader_tp_iter(LogReaderObject *self)
--- 121,124 ----
***************
*** 132,136 ****
      return (PyObject *) self;
  }
- #endif
  
  
--- 127,130 ----
***************
*** 523,547 ****
  }
  
- PyDoc_STRVAR(next__doc__,
- "next() -> event-info\n"
- "Return the next event record from the log file.");
- 
- static PyObject *
- logreader_next(LogReaderObject *self, PyObject *args)
- {
-     PyObject *result = NULL;
- 
-     if (PyArg_ParseTuple(args, ":next")) {
-         result = logreader_tp_iternext(self);
-         /* XXX return None if there's nothing left */
-         /* tp_iternext does the right thing, though */
-         if (result == NULL && !PyErr_Occurred()) {
-             result = Py_None;
-             Py_INCREF(result);
-         }
-     }
-     return result;
- }
- 
  static void
  do_stop(ProfilerObject *self);
--- 517,520 ----
***************
*** 1182,1189 ****
  }
  
- /* Always use METH_VARARGS even though some of these could be METH_NOARGS;
-  * this allows us to maintain compatibility with Python versions < 2.2
-  * more easily, requiring only the changes to the dispatcher to be made.
-  */
  static PyMethodDef profiler_methods[] = {
      {"addinfo", (PyCFunction)profiler_addinfo, METH_VARARGS, addinfo__doc__},
--- 1155,1158 ----
***************
*** 1196,1204 ****
  };
  
! /* Use a table even though there's only one "simple" member; this allows
!  * __members__ and therefore dir() to work.
!  */
! static struct memberlist profiler_members[] = {
!     {"closed",       T_INT,  -1, READONLY},
      {"frametimings", T_LONG, offsetof(ProfilerObject, linetimings), READONLY},
      {"lineevents",   T_LONG, offsetof(ProfilerObject, lineevents), READONLY},
--- 1165,1169 ----
  };
  
! static PyMemberDef profiler_members[] = {
      {"frametimings", T_LONG, offsetof(ProfilerObject, linetimings), READONLY},
      {"lineevents",   T_LONG, offsetof(ProfilerObject, lineevents), READONLY},
***************
*** 1208,1228 ****
  
  static PyObject *
! profiler_getattr(ProfilerObject *self, char *name)
  {
!     PyObject *result;
!     if (strcmp(name, "closed") == 0) {
!         result = (self->logfp == NULL) ? Py_True : Py_False;
!         Py_INCREF(result);
!     }
!     else {
!         result = PyMember_Get((char *)self, profiler_members, name);
!         if (result == NULL) {
!             PyErr_Clear();
!             result = Py_FindMethod(profiler_methods, (PyObject *)self, name);
!         }
!     }
      return result;
  }
  
  
  PyDoc_STRVAR(profiler_object__doc__,
--- 1173,1188 ----
  
  static PyObject *
! profiler_get_closed(ProfilerObject *self, void *closure)
  {
!     PyObject *result = (self->logfp == NULL) ? Py_True : Py_False;
!     Py_INCREF(result);
      return result;
  }
  
+ static PyGetSetDef profiler_getsets[] = {
+     {"closed", (getter)profiler_get_closed, NULL},
+     {NULL}
+ };
+ 
  
  PyDoc_STRVAR(profiler_object__doc__,
***************
*** 1252,1256 ****
      (destructor)profiler_dealloc,	/* tp_dealloc		*/
      0,					/* tp_print		*/
!     (getattrfunc)profiler_getattr,	/* tp_getattr		*/
      0,					/* tp_setattr		*/
      0,					/* tp_compare		*/
--- 1212,1216 ----
      (destructor)profiler_dealloc,	/* tp_dealloc		*/
      0,					/* tp_print		*/
!     0,					/* tp_getattr		*/
      0,					/* tp_setattr		*/
      0,					/* tp_compare		*/
***************
*** 1262,1270 ****
      0,					/* tp_call		*/
      0,					/* tp_str		*/
!     0,					/* tp_getattro		*/
      0,					/* tp_setattro		*/
      0,					/* tp_as_buffer		*/
      Py_TPFLAGS_DEFAULT,			/* tp_flags		*/
      profiler_object__doc__,		/* tp_doc		*/
  };
  
--- 1222,1243 ----
      0,					/* tp_call		*/
      0,					/* tp_str		*/
!     PyObject_GenericGetAttr,		/* tp_getattro		*/
      0,					/* tp_setattro		*/
      0,					/* tp_as_buffer		*/
      Py_TPFLAGS_DEFAULT,			/* tp_flags		*/
      profiler_object__doc__,		/* tp_doc		*/
+     0,					/* tp_traverse		*/
+     0,					/* tp_clear		*/
+     0,					/* tp_richcompare	*/
+     0,					/* tp_weaklistoffset	*/
+     0,					/* tp_iter		*/
+     0,					/* tp_iternext		*/
+     profiler_methods,			/* tp_methods		*/
+     profiler_members,			/* tp_members		*/
+     profiler_getsets,			/* tp_getset		*/
+     0,					/* tp_base		*/
+     0,					/* tp_dict		*/
+     0,					/* tp_descr_get		*/
+     0,					/* tp_descr_set		*/
  };
  
***************
*** 1273,1290 ****
      {"close",   (PyCFunction)logreader_close,  METH_VARARGS,
       logreader_close__doc__},
-     {"next",    (PyCFunction)logreader_next,   METH_VARARGS,
-      next__doc__},
      {NULL, NULL}
  };
  
! static PyObject *
! logreader_getattr(LogReaderObject *self, char *name)
! {
!     if (strcmp(name, "info") == 0) {
!         Py_INCREF(self->info);
!         return self->info;
!     }
!     return Py_FindMethod(logreader_methods, (PyObject *)self, name);
! }
  
  
--- 1246,1256 ----
      {"close",   (PyCFunction)logreader_close,  METH_VARARGS,
       logreader_close__doc__},
      {NULL, NULL}
  };
  
! static PyMemberDef logreader_members[] = {
!     {"info", T_OBJECT, offsetof(LogReaderObject, info), RO},
!     {NULL}
! };
  
  
***************
*** 1314,1318 ****
      (destructor)logreader_dealloc,	/* tp_dealloc		*/
      0,					/* tp_print		*/
!     (getattrfunc)logreader_getattr,	/* tp_getattr		*/
      0,					/* tp_setattr		*/
      0,					/* tp_compare		*/
--- 1280,1284 ----
      (destructor)logreader_dealloc,	/* tp_dealloc		*/
      0,					/* tp_print		*/
!     0,					/* tp_getattr		*/
      0,					/* tp_setattr		*/
      0,					/* tp_compare		*/
***************
*** 1324,1333 ****
      0,					/* tp_call		*/
      0,					/* tp_str		*/
!     0,					/* tp_getattro		*/
      0,					/* tp_setattro		*/
      0,					/* tp_as_buffer		*/
      Py_TPFLAGS_DEFAULT,			/* tp_flags		*/
      logreader__doc__,			/* tp_doc		*/
- #if Py_TPFLAGS_HAVE_ITER
      0,					/* tp_traverse		*/
      0,					/* tp_clear		*/
--- 1290,1298 ----
      0,					/* tp_call		*/
      0,					/* tp_str		*/
!     PyObject_GenericGetAttr,		/* tp_getattro		*/
      0,					/* tp_setattro		*/
      0,					/* tp_as_buffer		*/
      Py_TPFLAGS_DEFAULT,			/* tp_flags		*/
      logreader__doc__,			/* tp_doc		*/
      0,					/* tp_traverse		*/
      0,					/* tp_clear		*/
***************
*** 1336,1340 ****
      (getiterfunc)logreader_tp_iter,	/* tp_iter		*/
      (iternextfunc)logreader_tp_iternext,/* tp_iternext		*/
! #endif
  };
  
--- 1301,1311 ----
      (getiterfunc)logreader_tp_iter,	/* tp_iter		*/
      (iternextfunc)logreader_tp_iternext,/* tp_iternext		*/
!     logreader_methods,			/* tp_methods		*/
!     logreader_members,			/* tp_members		*/
!     0,					/* tp_getset		*/
!     0,					/* tp_base		*/
!     0,					/* tp_dict		*/
!     0,					/* tp_descr_get		*/
!     0,					/* tp_descr_set		*/
  };