summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2016-01-10 11:03:50 -0700
committerCharles Harris <charlesr.harris@gmail.com>2016-01-10 11:03:50 -0700
commit81793fc67d5f34cef91797cbc07e98a3b9a6e97a (patch)
treedb4be2b8e94e1f89ed38fb751fe455100a89dbe7
parent3a92c549220807ce0a3e91b7e4441bff61a56384 (diff)
parent5fd70ba6bb82d0505ac677118e69ce93a623e2cb (diff)
downloadnumpy-81793fc67d5f34cef91797cbc07e98a3b9a6e97a.tar.gz
Merge pull request #6989 from jakirkham/sty_indent_doc_typos_floatint
STY, DOC: Fix indentation and typos in example
-rw-r--r--doc/newdtype_example/floatint.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/doc/newdtype_example/floatint.c b/doc/newdtype_example/floatint.c
index cf698a7f9..0cc198388 100644
--- a/doc/newdtype_example/floatint.c
+++ b/doc/newdtype_example/floatint.c
@@ -1,10 +1,10 @@
#include "Python.h"
-#include "structmember.h" /* for offsetof macro if needed */
+#include "structmember.h" /* for offset of macro if needed */
#include "numpy/arrayobject.h"
-/* Use a Python float as the cannonical type being added
+/* Use a Python float as the canonical type being added
*/
typedef struct _floatint {
@@ -14,10 +14,10 @@ typedef struct _floatint {
} PyFloatIntObject;
static PyTypeObject PyFloatInt_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "floatint.floatint", /*tp_name*/
- sizeof(PyFloatIntObject), /*tp_basicsize*/
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "floatint.floatint", /*tp_name*/
+ sizeof(PyFloatIntObject), /*tp_basicsize*/
};
static PyArray_ArrFuncs _PyFloatInt_Funcs;
@@ -45,17 +45,18 @@ static PyArray_Descr _PyFloatInt_Dtype = {
static void
twoint_copyswap(void *dst, void *src, int swap, void *arr)
{
- if (src != NULL)
- memcpy(dst, src, sizeof(double));
-
+ if (src != NULL) {
+ memcpy(dst, src, sizeof(double));
+ }
+
if (swap) {
- register char *a, *b, c;
- a = (char *)dst;
- b = a + 7;
- c = *a; *a++ = *b; *b-- = c;
- c = *a; *a++ = *b; *b-- = c;
- c = *a; *a++ = *b; *b-- = c;
- c = *a; *a++ = *b; *b = c;
+ register char *a, *b, c;
+ a = (char *)dst;
+ b = a + 7;
+ c = *a; *a++ = *b; *b-- = c;
+ c = *a; *a++ = *b; *b-- = c;
+ c = *a; *a++ = *b; *b-- = c;
+ c = *a; *a++ = *b; *b = c;
}
}
@@ -64,12 +65,11 @@ twoint_getitem(char *ip, PyArrayObject *ap) {
npy_int32 a[2];
if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) {
- a[0] = *((npy_int32 *)ip);
- a[1] = *((npy_int32 *)ip + 1);
+ a[0] = *((npy_int32 *)ip);
+ a[1] = *((npy_int32 *)ip + 1);
}
else {
- ap->descr->f->copyswap(a, ip, !PyArray_ISNOTSWAPPED(ap),
- ap);
+ ap->descr->f->copyswap(a, ip, !PyArray_ISNOTSWAPPED(ap), ap);
}
return Py_BuildValue("(ii)", a[0], a[1]);
}
@@ -79,17 +79,16 @@ twoint_setitem(PyObject *op, char *ov, PyArrayObject *ap) {
npy_int32 a[2];
if (!PyTuple_Check(op)) {
- PyErr_SetString(PyExc_TypeError, "must be a tuple");
- return -1;
+ PyErr_SetString(PyExc_TypeError, "must be a tuple");
+ return -1;
}
if (!PyArg_ParseTuple(op, "ii", a, a+1)) return -1;
if (ap == NULL || PyArray_ISBEHAVED(ap)) {
- memcpy(ov, a, sizeof(double));
+ memcpy(ov, a, sizeof(double));
}
else {
- ap->descr->f->copyswap(ov, a, !PyArray_ISNOTSWAPPED(ap),
- ap);
+ ap->descr->f->copyswap(ov, a, !PyArray_ISNOTSWAPPED(ap), ap);
}
return 0;
}
@@ -145,7 +144,7 @@ PyMODINIT_FUNC initfloatint(void) {
dtype = _register_dtype();
Py_XINCREF(dtype);
if (dtype != NULL) {
- PyDict_SetItemString(d, "floatint_type", (PyObject *)dtype);
+ PyDict_SetItemString(d, "floatint_type", (PyObject *)dtype);
}
Py_INCREF(&PyFloatInt_Type);
PyDict_SetItemString(d, "floatint", (PyObject *)&PyFloatInt_Type);