Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit d29c505

Browse files
committed
refinements, additional tests
1 parent 95d47db commit d29c505

2 files changed

Lines changed: 25 additions & 31 deletions

File tree

arraymap.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,37 +123,18 @@ typedef enum ViewKind{
123123

124124

125125
// NOTE: would like to use strchr(str, '\0') instead of this routine, but some buffers might not have a null terminator and stread by full to the the dt_size.
126-
// static inline Py_UCS4*
127-
// ucs4_get_end_p(Py_UCS4* p, Py_ssize_t dt_size) {
128-
// Py_UCS4* p_end = p + dt_size; // invalid
129-
// while (p < p_end && *p != '\0') {
130-
// p++;
131-
// }
132-
// return p; // this might point to null, or point to one after end
133-
// }
134-
135-
// 5 start, length of 4, valid values are (5, 6, 7, 8)
136-
// last valid is start + len - 1
137-
138-
// Return a pointer to the last valid character in the field.
139126
static inline Py_UCS4*
140127
ucs4_get_end_p(Py_UCS4* p_start, Py_ssize_t dt_size) {
141-
Py_UCS4* p = p_start + dt_size - 1;
142-
while (p > p_start) {
128+
Py_UCS4* p;
129+
for (p = p_start + dt_size - 1; p >= p_start; p--) {
143130
if (*p != '\0') {
144-
return p + 1;
131+
return p + 1; // return 1 more than the first non-null from the right
145132
}
146-
p--;
147133
}
148-
// p is start; it may or may not be null; if its not null, return 1 more
149-
if (*p != '\0') {
150-
return p + 1;
151-
}
152-
return p;
134+
return p; // p is equal to p_start
153135
}
154136

155137

156-
157138
static inline char*
158139
char_get_end_p(char* p, Py_ssize_t dt_size) {
159140
char* p_end = p + dt_size;

test/test_unit.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,7 @@ def test_fam_constructor_array_unicode_c():
137137
fam = FrozenAutoMap(a1)
138138

139139

140-
def test_fam_constructor_array_unicode_d():
141-
a1 = np.array(["", "\x000"], dtype="U2")
142-
a1.flags.writeable = False
143-
fam = FrozenAutoMap(a1)
144-
assert len(fam) == 2
145-
assert list(fam) == ["", "\x000"]
146-
147-
140+
# NOTE
148141
# >>> u = "\x000\x00"
149142
# >>> len(u)
150143
# 3
@@ -156,6 +149,26 @@ def test_fam_constructor_array_unicode_d():
156149
# 2
157150

158151

152+
def test_fam_constructor_array_unicode_d1():
153+
a1 = np.array(["", "\x000"], dtype="U2")
154+
a1.flags.writeable = False
155+
fam = FrozenAutoMap(a1)
156+
assert len(fam) == 2
157+
assert list(fam) == ["", "\x000"]
158+
assert "" in fam
159+
assert "\x000" in fam
160+
161+
162+
def test_fam_constructor_array_unicode_d2():
163+
a1 = np.array(["", "\x000\x00"], dtype="U3")
164+
a1.flags.writeable = False
165+
fam = FrozenAutoMap(a1)
166+
assert len(fam) == 2
167+
assert list(fam) == ["", "\x000"] # we lost the last null
168+
assert "" in fam
169+
assert "\x000" in fam
170+
171+
159172
def test_fam_copy_array_unicode_a():
160173
a1 = np.array(("a", "ccc", "bb"))
161174
a1.flags.writeable = False

0 commit comments

Comments
 (0)