diff options
-rw-r--r-- | numpy/core/src/multiarray/datetime.c | 16 | ||||
-rw-r--r-- | numpy/core/src/multiarray/dtype_transfer.c | 11 |
2 files changed, 15 insertions, 12 deletions
diff --git a/numpy/core/src/multiarray/datetime.c b/numpy/core/src/multiarray/datetime.c index 332eb29fd..2d2370b08 100644 --- a/numpy/core/src/multiarray/datetime.c +++ b/numpy/core/src/multiarray/datetime.c @@ -3557,7 +3557,7 @@ find_string_array_datetime64_type(PyObject *obj, char **dataptr; npy_intp *strideptr, *innersizeptr; PyArray_Descr *string_dtype; - int maxlen, len; + int maxlen; char *tmp_buffer = NULL; npy_datetimestruct dts; @@ -3609,18 +3609,20 @@ find_string_array_datetime64_type(PyObject *obj, char* data = *dataptr; npy_intp stride = *strideptr; npy_intp count = *innersizeptr; + char *tmp; /* The inner loop */ while (count--) { - len = strnlen(data, maxlen); + /* Replicating strnlen with memchr, because Mac OS X lacks it */ + tmp = memchr(data, '\0', maxlen); /* If the string is all full, use the buffer */ - if (len == maxlen) { - memcpy(tmp_buffer, data, len); - tmp_buffer[len] = '\0'; + if (tmp == NULL) { + memcpy(tmp_buffer, data, maxlen); + tmp_buffer[maxlen] = '\0'; tmp_meta.base = -1; - if (parse_iso_8601_datetime(tmp_buffer, len, -1, + if (parse_iso_8601_datetime(tmp_buffer, maxlen, -1, NPY_UNSAFE_CASTING, &dts, NULL, &tmp_meta.base, NULL) < 0) { goto fail; @@ -3629,7 +3631,7 @@ find_string_array_datetime64_type(PyObject *obj, /* Otherwise parse the data in place */ else { tmp_meta.base = -1; - if (parse_iso_8601_datetime(data, len, -1, + if (parse_iso_8601_datetime(data, tmp - data, -1, NPY_UNSAFE_CASTING, &dts, NULL, &tmp_meta.base, NULL) < 0) { goto fail; diff --git a/numpy/core/src/multiarray/dtype_transfer.c b/numpy/core/src/multiarray/dtype_transfer.c index f2dd39141..9b1ba4aa7 100644 --- a/numpy/core/src/multiarray/dtype_transfer.c +++ b/numpy/core/src/multiarray/dtype_transfer.c @@ -899,17 +899,18 @@ _strided_to_strided_string_to_datetime(char *dst, npy_intp dst_stride, npy_int64 dt; npy_datetimestruct dts; char *tmp_buffer = d->tmp_buffer; - npy_intp len; + char *tmp; while (N > 0) { - len = strnlen(src, src_itemsize); + /* Replicating strnlen with memchr, because Mac OS X lacks it */ + tmp = memchr(src, '\0', src_itemsize); /* If the string is all full, use the buffer */ - if (len == src_itemsize) { + if (tmp == NULL) { memcpy(tmp_buffer, src, src_itemsize); tmp_buffer[src_itemsize] = '\0'; - if (parse_iso_8601_datetime(tmp_buffer, len, + if (parse_iso_8601_datetime(tmp_buffer, src_itemsize, d->dst_meta.base, NPY_SAME_KIND_CASTING, &dts, NULL, NULL, NULL) < 0) { dt = NPY_DATETIME_NAT; @@ -917,7 +918,7 @@ _strided_to_strided_string_to_datetime(char *dst, npy_intp dst_stride, } /* Otherwise parse the data in place */ else { - if (parse_iso_8601_datetime(src, len, + if (parse_iso_8601_datetime(src, tmp - src, d->dst_meta.base, NPY_SAME_KIND_CASTING, &dts, NULL, NULL, NULL) < 0) { dt = NPY_DATETIME_NAT; |