From 0c11d8f170ad13d8eb83cc67c59d7c1623782787 Mon Sep 17 00:00:00 2001 From: "elias.bachaalany" Date: Mon, 22 Mar 2010 14:22:17 +0000 Subject: [PATCH] minor code style modification --- examples/ex_graph.py | 6 ++++- swig/diskio.i | 52 ++++++++++++++++++++++---------------------- swig/fpro.i | 34 ++++++++++++++--------------- 3 files changed, 48 insertions(+), 44 deletions(-) diff --git a/examples/ex_graph.py b/examples/ex_graph.py index 7582020..a640747 100644 --- a/examples/ex_graph.py +++ b/examples/ex_graph.py @@ -1,3 +1,7 @@ +# ----------------------------------------------------------------------- +# This is an example illustrating how to use the graphing functionality in Python +# (c) Hex-Rays +# from idaapi import GraphViewer class MyGraph(GraphViewer): @@ -26,7 +30,7 @@ def main(): # Iterate through all function instructions and take only call instructions result = {} for x in [x for x in FuncItems(f.startEA) if idaapi.is_call_insn(x)]: - for xref in XrefsFrom(x, idaapi.XREF_FAR): + for xref in XrefsFrom(x, idaapi.XREF_FAR): if not xref.iscode: continue t = GetFunctionName(xref.to) if not t: diff --git a/swig/diskio.i b/swig/diskio.i index 59ad06f..82ebabf 100644 --- a/swig/diskio.i +++ b/swig/diskio.i @@ -100,19 +100,19 @@ public: //-------------------------------------------------------------------------- loader_input_t(PyObject *pycobject = NULL): li(NULL), own(OWN_NONE), __idc_cvt_id__(PY_ICID_OPAQUE) { - if (pycobject != NULL && PyCObject_Check(pycobject)) + if ( pycobject != NULL && PyCObject_Check(pycobject) ) _from_cobject(pycobject); } //-------------------------------------------------------------------------- void close() { - if (li == NULL) + if ( li == NULL ) return; - if (own == OWN_CREATE) + if ( own == OWN_CREATE ) close_linput(li); - else if (own == OWN_FROM_FP) + else if ( own == OWN_FROM_FP ) unmake_linput(li); li = NULL; @@ -130,7 +130,7 @@ public: { close(); li = open_linput(filename, remote); - if (li == NULL) + if ( li == NULL ) Py_RETURN_FALSE; // Save file name @@ -160,7 +160,7 @@ public: // This method can be used to pass a linput_t* from C code static loader_input_t *from_cobject(PyObject *pycobject) { - if (!PyCObject_Check(pycobject)) + if ( !PyCObject_Check(pycobject) ) return NULL; loader_input_t *l = new loader_input_t(); l->_from_cobject(pycobject); @@ -171,7 +171,7 @@ public: static loader_input_t *from_fp(FILE *fp) { linput_t *fp_li = make_linput(fp); - if (fp_li == NULL) + if ( fp_li == NULL ) return NULL; loader_input_t *l = new loader_input_t(); @@ -191,7 +191,7 @@ public: PyObject *open_memory(ea_t start, asize_t size = 0) { linput_t *l = create_memory_linput(start, size); - if (l == NULL) + if ( l == NULL ) Py_RETURN_FALSE; close(); li = l; @@ -218,13 +218,13 @@ public: do { char *buf = (char *) malloc(sz + 5); - if (buf == NULL) + if ( buf == NULL ) break; qlgetz(li, fpos, buf, sz); PyObject *ret = PyString_FromString(buf); free(buf); return ret; - } while (false); + } while ( false ); Py_RETURN_NONE; } @@ -234,9 +234,9 @@ public: do { char *buf = (char *) malloc(len + 5); - if (buf == NULL) + if ( buf == NULL ) break; - if (qlgets(buf, len, li) == NULL) + if ( qlgets(buf, len, li) == NULL ) { free(buf); break; @@ -244,7 +244,7 @@ public: PyObject *ret = PyString_FromString(buf); free(buf); return ret; - } while (false); + } while ( false ); Py_RETURN_NONE; } @@ -254,10 +254,10 @@ public: do { char *buf = (char *) malloc(size + 5); - if (buf == NULL) + if ( buf == NULL ) break; ssize_t r = qlread(li, buf, size); - if (r == -1) + if ( r == -1 ) { free(buf); break; @@ -265,7 +265,7 @@ public: PyObject *ret = PyString_FromStringAndSize(buf, r); free(buf); return ret; - } while (false); + } while ( false ); Py_RETURN_NONE; } @@ -274,17 +274,17 @@ public: { return li != NULL; } - + //-------------------------------------------------------------------------- PyObject *readbytes(size_t size, bool big_endian) { do { char *buf = (char *) malloc(size + 5); - if (buf == NULL) + if ( buf == NULL ) break; int r = lreadbytes(li, buf, size, big_endian); - if (r == -1) + if ( r == -1 ) { free(buf); break; @@ -292,7 +292,7 @@ public: PyObject *ret = PyString_FromStringAndSize(buf, r); free(buf); return ret; - } while (false); + } while ( false ); Py_RETURN_NONE; } @@ -318,7 +318,7 @@ public: PyObject *get_char() { int ch = qlgetc(li); - if (ch == EOF) + if ( ch == EOF ) Py_RETURN_NONE; return Py_BuildValue("c", ch); } @@ -328,20 +328,20 @@ public: //-------------------------------------------------------------------------- PyObject *py_enumerate_files(PyObject *path, PyObject *fname, PyObject *callback) { - do + do { - if (!PyString_Check(path) || !PyString_Check(fname) || !PyCallable_Check(callback)) + if ( !PyString_Check(path) || !PyString_Check(fname) || !PyCallable_Check(callback) ) break; const char *_path = PyString_AsString(path); const char *_fname = PyString_AsString(fname); - if (_path == NULL || _fname == NULL) + if ( _path == NULL || _fname == NULL ) break; char answer[MAXSTR]; answer[0] = '\0'; int r = enumerate_files(answer, sizeof(answer), _path, _fname, py_enumerate_files_cb, callback); return Py_BuildValue("(is)", r, answer); - } while (false); - Py_RETURN_NONE; + } while ( false ); + Py_RETURN_NONE; } // %} diff --git a/swig/fpro.i b/swig/fpro.i index 2b00f4d..3e32851 100644 --- a/swig/fpro.i +++ b/swig/fpro.i @@ -17,7 +17,7 @@ private: //-------------------------------------------------------------------------- bool _from_fp(FILE *fp) { - if (fp == NULL) + if ( fp == NULL ) return false; own = false; fn.sprnt("", fp); @@ -43,7 +43,7 @@ public: own = true; fn.qclear(); __idc_cvt_id__ = PY_ICID_OPAQUE; - if (pycobject != NULL && PyCObject_Check(pycobject)) + if ( pycobject != NULL && PyCObject_Check(pycobject) ) _from_cobject(pycobject); } @@ -56,9 +56,9 @@ public: //-------------------------------------------------------------------------- void close() { - if (fp == NULL) + if ( fp == NULL ) return; - if (own) + if ( own ) qfclose(fp); fp = NULL; own = true; @@ -75,7 +75,7 @@ public: { close(); fp = qfopen(filename, mode); - if (fp == NULL) + if ( fp == NULL ) Py_RETURN_FALSE; // Save file name fn = filename; @@ -86,7 +86,7 @@ public: //-------------------------------------------------------------------------- static qfile_t *from_fp(FILE *fp) { - if (fp == NULL) + if ( fp == NULL ) return NULL; qfile_t *qf = new qfile_t(); qf->own = false; @@ -132,10 +132,10 @@ public: do { char *buf = (char *) malloc(size + 5); - if (buf == NULL) + if ( buf == NULL ) break; int r = freadbytes(fp, buf, size, big_endian); - if (r != 0) + if ( r != 0 ) { free(buf); break; @@ -143,7 +143,7 @@ public: PyObject *ret = PyString_FromStringAndSize(buf, r); free(buf); return ret; - } while (false); + } while ( false ); Py_RETURN_NONE; } @@ -153,10 +153,10 @@ public: do { char *buf = (char *) malloc(size + 5); - if (buf == NULL) + if ( buf == NULL ) break; int r = qfread(fp, buf, size); - if (r <= 0) + if ( r <= 0 ) { free(buf); break; @@ -164,7 +164,7 @@ public: PyObject *ret = PyString_FromStringAndSize(buf, r); free(buf); return ret; - } while (false); + } while ( false ); Py_RETURN_NONE; } @@ -174,9 +174,9 @@ public: do { char *buf = (char *) malloc(size + 5); - if (buf == NULL) + if ( buf == NULL ) break; - if (qfgets(buf, size, fp) == NULL) + if ( qfgets(buf, size, fp) == NULL ) { free(buf); break; @@ -184,7 +184,7 @@ public: PyObject *ret = PyString_FromString(buf); free(buf); return ret; - } while (false); + } while ( false ); Py_RETURN_NONE; } @@ -199,7 +199,7 @@ public: //-------------------------------------------------------------------------- int write(PyObject *py_buf) { - if (!PyString_Check(py_buf)) + if ( !PyString_Check(py_buf) ) return 0; return qfwrite(fp, (void *)PyString_AS_STRING(py_buf), PyString_GET_SIZE(py_buf)); } @@ -235,7 +235,7 @@ public: PyObject *get_char() { int ch = qfgetc(fp); - if (ch == EOF) + if ( ch == EOF ) Py_RETURN_NONE; return Py_BuildValue("c", ch); }