@@ -64,9 +64,9 @@ typedef char *(*PFN_PyTypeToUTF8)(JSOBJ obj, JSONTypeContext *ti,
64
64
typedef struct __NpyArrContext {
65
65
PyObject * array ;
66
66
char * dataptr ;
67
- int curdim ; // current dimension in array's order
68
- int stridedim ; // dimension we are striding over
69
- int inc ; // stride dimension increment (+/- 1)
67
+ int curdim ; // current dimension in array's order
68
+ int stridedim ; // dimension we are striding over
69
+ int inc ; // stride dimension increment (+/- 1)
70
70
npy_intp dim ;
71
71
npy_intp stride ;
72
72
npy_intp ndim ;
@@ -83,8 +83,8 @@ typedef struct __PdBlockContext {
83
83
int ncols ;
84
84
int transpose ;
85
85
86
- int * cindices ; // frame column -> block column map
87
- NpyArrContext * * npyCtxts ; // NpyArrContext for each column
86
+ int * cindices ; // frame column -> block column map
87
+ NpyArrContext * * npyCtxts ; // NpyArrContext for each column
88
88
} PdBlockContext ;
89
89
90
90
typedef struct __TypeContext {
@@ -346,7 +346,6 @@ static char *NpyTimeDeltaToIsoCallback(JSOBJ Py_UNUSED(unused),
346
346
/* JSON callback */
347
347
static char * PyDateTimeToIsoCallback (JSOBJ obj , JSONTypeContext * tc ,
348
348
size_t * len ) {
349
-
350
349
if (!PyDate_Check (obj )) {
351
350
PyErr_SetString (PyExc_TypeError , "Expected date object" );
352
351
return NULL ;
@@ -1108,7 +1107,7 @@ void Series_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
1108
1107
PyObjectEncoder * enc = (PyObjectEncoder * )tc -> encoder ;
1109
1108
GET_TC (tc )-> index = 0 ;
1110
1109
GET_TC (tc )-> cStr = PyObject_Malloc (20 * sizeof (char ));
1111
- enc -> outputFormat = VALUES ; // for contained series
1110
+ enc -> outputFormat = VALUES ; // for contained series
1112
1111
if (!GET_TC (tc )-> cStr ) {
1113
1112
PyErr_NoMemory ();
1114
1113
}
@@ -1164,7 +1163,7 @@ void DataFrame_iterBegin(JSOBJ Py_UNUSED(obj), JSONTypeContext *tc) {
1164
1163
PyObjectEncoder * enc = (PyObjectEncoder * )tc -> encoder ;
1165
1164
GET_TC (tc )-> index = 0 ;
1166
1165
GET_TC (tc )-> cStr = PyObject_Malloc (20 * sizeof (char ));
1167
- enc -> outputFormat = VALUES ; // for contained series & index
1166
+ enc -> outputFormat = VALUES ; // for contained series & index
1168
1167
if (!GET_TC (tc )-> cStr ) {
1169
1168
PyErr_NoMemory ();
1170
1169
}
@@ -1364,7 +1363,7 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
1364
1363
} else {
1365
1364
if (PyDelta_Check (item )) {
1366
1365
nanosecVal = total_seconds (item ) *
1367
- 1000000000LL ; // nanoseconds per second
1366
+ 1000000000LL ; // nanoseconds per second
1368
1367
} else {
1369
1368
// datetime.* objects don't follow above rules
1370
1369
nanosecVal = PyDateTimeToEpoch (item , NPY_FR_ns );
@@ -1395,13 +1394,14 @@ char **NpyArr_encodeLabels(PyArrayObject *labels, PyObjectEncoder *enc,
1395
1394
break ;
1396
1395
}
1397
1396
} else {
1398
- cLabel = PyObject_Malloc (21 ); // 21 chars for int64
1399
- sprintf (cLabel , "%" NPY_DATETIME_FMT ,
1397
+ int size_of_cLabel = 21 ; // 21 chars for int 64
1398
+ cLabel = PyObject_Malloc (size_of_cLabel );
1399
+ snprintf (cLabel , size_of_cLabel , "%" NPY_DATETIME_FMT ,
1400
1400
NpyDateTimeToEpoch (nanosecVal , base ));
1401
1401
len = strlen (cLabel );
1402
1402
}
1403
1403
}
1404
- } else { // Fallback to string representation
1404
+ } else { // Fallback to string representation
1405
1405
// Replace item with the string to keep it alive.
1406
1406
Py_SETREF (item , PyObject_Str (item ));
1407
1407
if (item == NULL ) {
@@ -1502,7 +1502,6 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1502
1502
if (longVal == get_nat ()) {
1503
1503
tc -> type = JT_NULL ;
1504
1504
} else {
1505
-
1506
1505
if (enc -> datetimeIso ) {
1507
1506
if (enc -> npyType == NPY_TIMEDELTA ) {
1508
1507
pc -> PyTypeToUTF8 = NpyTimeDeltaToIsoCallback ;
@@ -1521,7 +1520,8 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1521
1520
}
1522
1521
}
1523
1522
1524
- // TODO: this prevents infinite loop with mixed-type DataFrames;
1523
+ // TODO(username): this prevents infinite loop with
1524
+ // mixed-type DataFrames;
1525
1525
// refactor
1526
1526
enc -> npyCtxtPassthru = NULL ;
1527
1527
enc -> npyType = -1 ;
@@ -1608,7 +1608,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1608
1608
if (PyObject_HasAttrString (obj , "value" )) {
1609
1609
value = get_long_attr (obj , "value" );
1610
1610
} else {
1611
- value = total_seconds (obj ) * 1000000000LL ; // nanoseconds per second
1611
+ value = total_seconds (obj ) * 1000000000LL ; // nanoseconds per sec
1612
1612
}
1613
1613
1614
1614
if (value == get_nat ()) {
@@ -1620,7 +1620,7 @@ void Object_beginTypeContext(JSOBJ _obj, JSONTypeContext *tc) {
1620
1620
} else {
1621
1621
unit = ((PyObjectEncoder * )tc -> encoder )-> datetimeUnit ;
1622
1622
if (scaleNanosecToUnit (& value , unit ) != 0 ) {
1623
- // TODO: Add some kind of error handling here
1623
+ // TODO(username) : Add some kind of error handling here
1624
1624
}
1625
1625
1626
1626
exc = PyErr_Occurred ();
@@ -2039,7 +2039,7 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args,
2039
2039
PyObject * newobj ;
2040
2040
PyObject * oinput = NULL ;
2041
2041
PyObject * oensureAscii = NULL ;
2042
- int idoublePrecision = 10 ; // default double precision setting
2042
+ int idoublePrecision = 10 ; // default double precision setting
2043
2043
PyObject * oencodeHTMLChars = NULL ;
2044
2044
char * sOrient = NULL ;
2045
2045
char * sdateFormat = NULL ;
@@ -2052,7 +2052,7 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args,
2052
2052
Object_endTypeContext ,
2053
2053
Object_getStringValue ,
2054
2054
Object_getLongValue ,
2055
- NULL , // getIntValue is unused
2055
+ NULL , // getIntValue is unused
2056
2056
Object_getDoubleValue ,
2057
2057
Object_getBigNumStringValue ,
2058
2058
Object_iterBegin ,
@@ -2064,11 +2064,11 @@ PyObject *objToJSON(PyObject *Py_UNUSED(self), PyObject *args,
2064
2064
PyObject_Malloc ,
2065
2065
PyObject_Realloc ,
2066
2066
PyObject_Free ,
2067
- -1 , // recursionMax
2067
+ -1 , // recursionMax
2068
2068
idoublePrecision ,
2069
- 1 , // forceAscii
2070
- 0 , // encodeHTMLChars
2071
- 0 , // indent
2069
+ 1 , // forceAscii
2070
+ 0 , // encodeHTMLChars
2071
+ 0 , // indent
2072
2072
}};
2073
2073
JSONObjectEncoder * encoder = (JSONObjectEncoder * )& pyEncoder ;
2074
2074
0 commit comments