"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "jv.c" between
jq-1.5.tar.gz and jq-1.6.tar.gz

About: jq is a lightweight and flexible command-line JSON processor.

jv.c  (jq-1.5):jv.c  (jq-1.6)
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <limits.h> #include <limits.h>
#include <math.h>
#include "jv_alloc.h" #include "jv_alloc.h"
#include "jv.h" #include "jv.h"
#include "jv_unicode.h" #include "jv_unicode.h"
#include "util.h" #include "util.h"
/* /*
* Internal refcounting helpers * Internal refcounting helpers
*/ */
skipping to change at line 298 skipping to change at line 299
assert(jv_get_kind(a) == JV_KIND_ARRAY); assert(jv_get_kind(a) == JV_KIND_ARRAY);
int len = jvp_array_length(a); int len = jvp_array_length(a);
jvp_clamp_slice_params(len, &start, &end); jvp_clamp_slice_params(len, &start, &end);
assert(0 <= start && start <= end && end <= len); assert(0 <= start && start <= end && end <= len);
// FIXME: maybe slice should reallocate if the slice is small enough // FIXME: maybe slice should reallocate if the slice is small enough
if (start == end) { if (start == end) {
jv_free(a); jv_free(a);
return jv_array(); return jv_array();
} }
// FIXME FIXME FIXME large offsets
a.offset += start; if (a.offset + start >= 1 << (sizeof(a.offset) * CHAR_BIT)) {
a.size = end - start; jv r = jv_array_sized(end - start);
return a; for (int i = start; i < end; i++)
r = jv_array_append(r, jv_array_get(jv_copy(a), i));
jv_free(a);
return r;
} else {
a.offset += start;
a.size = end - start;
return a;
}
} }
/* /*
* Arrays (public interface) * Arrays (public interface)
*/ */
jv jv_array_sized(int n) { jv jv_array_sized(int n) {
return jvp_array_new(n); return jvp_array_new(n);
} }
skipping to change at line 1104 skipping to change at line 1113
if (slot) { if (slot) {
val = jv_copy(*slot); val = jv_copy(*slot);
} else { } else {
val = jv_invalid(); val = jv_invalid();
} }
jv_free(object); jv_free(object);
jv_free(key); jv_free(key);
return val; return val;
} }
int jv_object_has(jv object, jv key) {
assert(jv_get_kind(object) == JV_KIND_OBJECT);
assert(jv_get_kind(key) == JV_KIND_STRING);
jv* slot = jvp_object_read(object, key);
int res = slot ? 1 : 0;
jv_free(object);
jv_free(key);
return res;
}
jv jv_object_set(jv object, jv key, jv value) { jv jv_object_set(jv object, jv key, jv value) {
assert(jv_get_kind(object) == JV_KIND_OBJECT); assert(jv_get_kind(object) == JV_KIND_OBJECT);
assert(jv_get_kind(key) == JV_KIND_STRING); assert(jv_get_kind(key) == JV_KIND_STRING);
// copy/free of object, key, value coalesced // copy/free of object, key, value coalesced
jv* slot = jvp_object_write(&object, key); jv* slot = jvp_object_write(&object, key);
jv_free(*slot); jv_free(*slot);
*slot = value; *slot = value;
return object; return object;
} }
skipping to change at line 1301 skipping to change at line 1320
|| a.size != b.size) { || a.size != b.size) {
r = 0; r = 0;
} else { } else {
switch (jv_get_kind(a)) { switch (jv_get_kind(a)) {
case JV_KIND_ARRAY: case JV_KIND_ARRAY:
case JV_KIND_STRING: case JV_KIND_STRING:
case JV_KIND_OBJECT: case JV_KIND_OBJECT:
r = a.u.ptr == b.u.ptr; r = a.u.ptr == b.u.ptr;
break; break;
case JV_KIND_NUMBER: case JV_KIND_NUMBER:
r = a.u.number == b.u.number; r = memcmp(&a.u.number, &b.u.number, sizeof(a.u.number)) == 0;
break; break;
default: default:
r = 1; r = 1;
break; break;
} }
} }
jv_free(a); jv_free(a);
jv_free(b); jv_free(b);
return r; return r;
} }
 End of changes. 4 change blocks. 
5 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)