[Xcb] [PATCH xpyb 01/10] conn.c: Delete explicit comparison with NULL

Tapasweni Pathak tapaswenipathak at gmail.com
Sun Oct 12 21:47:40 PDT 2014


if (pointer == NULL) is functionally equivalent to
if (!pointer).

Using the second will make it a bit obvious that there is a
pointer involved and not an integer or something.

This patch deletes explicit comaprison with NULL in conn.c file.

Signed-off-by: Tapasweni Pathak <tapaswenipathak at gmail.com>
---
 src/conn.c |   40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/conn.c b/src/conn.c
index 1b21d17..e5958f0 100644
--- a/src/conn.c
+++ b/src/conn.c
@@ -14,7 +14,7 @@
 int
 xpybConn_invalid(xpybConn *self)
 {
-    if (self->conn == NULL) {
+    if (!self->conn) {
 	PyErr_SetString(xpybExcept_base, "Invalid connection.");
 	return 1;
     }
@@ -49,15 +49,15 @@ int
 xpybConn_init_struct(xpybConn *self, PyObject *core_type)
 {
     self->core = PyObject_CallFunctionObjArgs(core_type, self, NULL);
-    if (self->core == NULL)
+    if (!self->core)
         return -1;
 
     self->dict = PyDict_New();
-    if (self->dict == NULL)
+    if (!self->dict)
         return -1;

    self->extcache = PyDict_New();
-    if (self->extcache == NULL)
+    if (!self->extcache)
         return -1;

     self->wrapped = 0;
@@ -78,7 +78,7 @@ xpybConn_init(xpybConn *self, PyObject *args, PyObject *kw)
     int authlen, fd = -1;

     /* Make sure core was set. */
-    if (xpybModule_core == NULL) {
+    if (!xpybModule_core) {
 	PyErr_SetString(xpybExcept_base, "No core protocol object has been set.  Did you import xcb.xproto?");
         return -1;
     }
@@ -89,7 +89,7 @@ xpybConn_init(xpybConn *self, PyObject *args, PyObject *kw)
         return -1;

     /* Set up authorization */
-    if (authstr != NULL) {
+    if (authstr) {
 	if (xpyb_parse_auth(authstr, authlen, &auth) < 0)
             return -1;
 	authptr = &auth;
@@ -127,17 +127,17 @@ xpybConn_load_ext(xpybConn *self, PyObject *key)
     ext = (xpybExt *)PyDict_GetItem(self->extcache, key);
     Py_XINCREF(ext);

-    if (ext == NULL) {
+    if (!ext) {
 	/* Look up the extension type in the global dictionary. */
 	type = PyDict_GetItem(xpybModule_extdict, key);
-	if (type == NULL) {
+	if (!type) {
 	    PyErr_SetString(xpybExcept_ext, "No extension found for that key.");
 	    return NULL;
 	}

 	/* Call the type object to get a new xcb.Extension object. */
 	ext = (xpybExt *)PyObject_CallFunctionObjArgs(type, self, key, NULL);
-	if (ext == NULL)
+	if (!ext)
 	    return NULL;

 	/* Get the opcode and base numbers. */
@@ -166,7 +166,7 @@ xpybConn_setup_helper(xpybConn *self, xpybExt *ext, PyObject *events, PyObject *
 	if (opcode >= self->events_len) {
 	    newlen = opcode + 1;
 	    newmem = realloc(self->events, newlen * sizeof(PyObject *));
-	    if (newmem == NULL)
+	    if (!newmem)
 		return -1;
 	    memset(newmem + self->events_len, 0, (newlen - self->events_len) * sizeof(PyObject *));
 	    self->events = newmem;
@@ -181,7 +181,7 @@ xpybConn_setup_helper(xpybConn *self, xpybExt *ext, PyObject *events, PyObject *
 	if (opcode >= self->errors_len) {
 	    newlen = opcode + 1;
 	    newmem = realloc(self->errors, newlen * sizeof(PyObject *));
-	    if (newmem == NULL)
+	    if (!newmem)
 		return -1;
 	    memset(newmem + self->errors_len, 0, (newlen - self->errors_len) * sizeof(PyObject *));
 	    self->errors = newmem;
@@ -210,12 +210,12 @@ xpybConn_setup(xpybConn *self)
     ext = NULL;
     while (PyDict_Next(xpybModule_ext_events, &i, &key, &events)) {
 	errors = PyDict_GetItem(xpybModule_ext_errors, key);
-	if (errors == NULL)
+	if (!errors)
 	    goto out;

 	Py_XDECREF(ext);
 	ext = xpybConn_load_ext(self, key);
-	if (ext == NULL)
+	if (!ext)
 	    goto out;
 	if (ext->present)
 	    if (xpybConn_setup_helper(self, ext, events, errors) < 0)
@@ -277,7 +277,7 @@ xpybConn_getattro(xpybConn *self, PyObject *obj)
 	    goto out2;
	
     Py_XINCREF(result = PyDict_GetItem(self->dict, obj));
-    if (result != NULL || PyErr_Occurred())
+    if (result || PyErr_Occurred())
 	return result;

     return xpybConn_type.tp_base->tp_getattro((PyObject *)self, obj);
@@ -319,7 +319,7 @@ xpybConn_call(xpybConn *self, PyObject *args, PyObject *kw)

     /* Check our dictionary of cached values */
     ext = xpybConn_load_ext(self, key);
-    if (ext != NULL && !ext->present) {
+    if (ext && !ext->present) {
 	PyErr_SetString(xpybExcept_ext, "Extension not present on server.");
 	Py_DECREF(ext);
 	return NULL;
@@ -363,7 +363,7 @@ static PyMemberDef xpybConn_members[] = {
 static PyObject *
 xpybConn_has_error(xpybConn *self, PyObject *args)
 {
-    if (self->conn == NULL) {
+    if (!self->conn) {
 	PyErr_SetString(xpybExcept_base, "Invalid connection.");
 	return NULL;
     }
@@ -408,10 +408,10 @@ xpybConn_get_setup(xpybConn *self, PyObject *args)
     if (xpybConn_invalid(self))
 	return NULL;

-    if (self->setup == NULL) {
+    if (!self->setup) {
 	s = xcb_get_setup(self->conn);
 	shim = PyBuffer_FromMemory((void *)s, 8 + s->length * 4);
-	if (shim == NULL)
+	if (!shim)
 	    return NULL;
 	type = (PyObject *)xpybModule_setup;
 	self->setup = PyObject_CallFunctionObjArgs(type, shim, Py_False, NULL);
@@ -432,7 +432,7 @@ xpybConn_wait_for_event(xpybConn *self, PyObject *args)

     data = xcb_wait_for_event(self->conn);

-    if (data == NULL) {
+    if (!data) {
 	PyErr_SetString(PyExc_IOError, "I/O error on X server connection.");
 	return NULL;
     }
@@ -455,7 +455,7 @@ xpybConn_poll_for_event(xpybConn *self, PyObject *args)

     data = xcb_poll_for_event(self->conn);

-    if (data == NULL) {
+    if (!data) {
         if (xpybConn_invalid(self))
             return NULL;
         else
--
1.7.9.5



More information about the Xcb mailing list