[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Py C/API - Using METH_O vs METH_VARARGS
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Py C/API - Using METH_O vs METH_VARARGS
- From: "Campbell Barton" <ideasman42@xxxxxxxxx>
- Date: Fri, 12 Dec 2008 09:47:35 +1100
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Thu, 11 Dec 2008 17:47:38 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=f2XrHlbRSBVTO/xY6b1WpA2KcWrM4f8Sgx/tvnUmMAc=; b=PkGP8SgNz6Ir49ksHergybuOpw0t5tvjD1vN879qZwLy+eeFemK0OWaxgZSFNjTbjk pSbuKr/YoK9vAGuAGL2WyL5TNqtap3oaTpwqerwMaljKh/v9Ici+9ruLkI0XC6t/E6bc tEjMDK0JOwCGxOL+46VGGmcdTVRnQm6QXBgXk=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=dJfz2O1C1nqXG+5nOj+YdchtpCAGY/kZArsxhFKcSdsLSUD5uNDZ6ILzOYUZlL2HFm qfd4rU6ZGNdRU390RwuJxSuw8eEFDxYeCU+EVNNBiS2kiSXdbIvK5+yl+W+l3Yxvz/f0 fEyvyJp30kbvNWpZYPQiCu7ng7OwatXrvr8PQ=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Noticed METH_O isnt used anywhere in pygame, this avoids creating a
tuple only to get a single PyObject back out with PyArg_ParseTuple().
Attached an example patch below.
Heres a list of places this could be changed (from svn trunk).
functions that are not likely to be called often don't matter with
this so much.
./src/base.c:102: if (!PyArg_ParseTuple (arg, "O", &quitfunc))
./src/font.c:359: if (!PyArg_ParseTuple (args, "O", &text))
./src/font.c:398: if (!PyArg_ParseTuple (args, "O", &textobj))
./src/mixer.c:919: if (!PyArg_ParseTuple (arg, "O", &file))
./src/movie.c:440: if (!PyArg_ParseTuple (arg, "O", &file))
./src/movieext.c:548: if(!PyArg_ParseTuple(arg, "O", &file))
./src/music.c:251: if(!PyArg_ParseTuple(args, "O", &file))
./src/music.c:303: if (!PyArg_ParseTuple (args, "O", &file))
./src/rect.c:291: if (!PyArg_ParseTuple (args, "O", &list))
./src/rect.c:333: if (!PyArg_ParseTuple (args, "O", &list))
./src/rect.c:408: if (!PyArg_ParseTuple (args, "O", &list))
./src/rect.c:449: if (!PyArg_ParseTuple (args, "O", &list))
./src/rect.c:499: if (!PyArg_ParseTuple (args, "O", &dict))
./src/rect.c:534: if (!PyArg_ParseTuple (args, "O", &dict))
./src/surface.c:810: if (!PyArg_ParseTuple (args, "O", &list))
cases with type checks...
./src/_numericsndarray.c:38: if (!PyArg_ParseTuple (arg, "O!",
&PySound_Type, &chunkobj))
./src/_numericsndarray.c:104: if (!PyArg_ParseTuple (arg, "O!",
&PyArray_Type, &arrayobj))
./src/_numericsurfarray.c:40: if (!PyArg_ParseTuple (arg, "O!",
&PySurface_Type, &surfobj))
./src/_numericsurfarray.c:110: if (!PyArg_ParseTuple (arg, "O!",
&PySurface_Type, &surfobj))
./src/_numericsurfarray.c:152: if (!PyArg_ParseTuple(arg, "O!",
&PySurface_Type, &surfobj))
./src/_numericsurfarray.c:198: if (!PyArg_ParseTuple (arg, "O!",
&PySurface_Type, &surfobj))
./src/_numericsurfarray.c:302: if (!PyArg_ParseTuple (arg, "O!",
&PySurface_Type, &surfobj))
./src/_numericsurfarray.c:442: if (!PyArg_ParseTuple (arg, "O!",
&PySurface_Type, &surfobj))
./src/_numericsurfarray.c:546: if (!PyArg_ParseTuple (arg, "O!",
&PySurface_Type, &surfobj))
./src/_numericsurfarray.c:1067: if (!PyArg_ParseTuple (arg, "O!",
&PyArray_Type, &arrayobj))
./src/display.c:952: if (!PyArg_ParseTuple (arg, "O!",
&PySurface_Type, &surface))
./src/event.c:774: if (!PyArg_ParseTuple (args, "O!", &PyEvent_Type, &e))
./src/fastevent.c:220: if (!PyArg_ParseTuple (args, "O!", &PyEvent_Type, &e))
./src/mixer.c:530: if (!PyArg_ParseTuple (args, "O!", &PySound_Type, &sound))
./src/pixelarray.c:267: if (!PyArg_ParseTuple (args, "O!",
&PySurface_Type, &surfobj))
Heres an example patch.
Index: src/event.c
===================================================================
--- src/event.c (revision 1744)
+++ src/event.c (working copy)
@@ -765,15 +765,14 @@
}
static PyObject*
-event_post (PyObject* self, PyObject* args)
+event_post (PyObject* self, PyEventObject* e)
{
- PyEventObject* e;
SDL_Event event;
int isblocked = 0;
-
- if (!PyArg_ParseTuple (args, "O!", &PyEvent_Type, &e))
- return NULL;
-
+
+ if (!PyObject_TypeCheck((PyObject *)e, &PyEvent_Type))
+ return RAISE (PyExc_ValueError, "post requires 1 event argument");
+
VIDEO_INIT_CHECK ();
@@ -933,7 +932,7 @@
{ "clear", event_clear, METH_VARARGS, DOC_PYGAMEEVENTCLEAR },
{ "get", event_get, METH_VARARGS, DOC_PYGAMEEVENTGET },
{ "peek", event_peek, METH_VARARGS, DOC_PYGAMEEVENTPEEK },
- { "post", event_post, METH_VARARGS, DOC_PYGAMEEVENTPOST },
+ { "post", event_post, METH_O, DOC_PYGAMEEVENTPOST },
{ "set_allowed", set_allowed, METH_VARARGS, DOC_PYGAMEEVENTSETALLOWED },
{ "set_blocked", set_blocked, METH_VARARGS, DOC_PYGAMEEVENTSETBLOCKED },