static inline byte *
decode_attributes(byte *ptr, byte *end, struct odes *o, uns can_overwrite)
{
- while (ptr < end)
- {
- uns len;
- GET_UTF8(ptr, len);
- if (!len--)
- break;
- byte type = ptr[len];
- if (can_overwrite == 2)
+ if (can_overwrite >= 2)
+ while (ptr < end)
{
+ uns len;
+ GET_UTF8(ptr, len);
+ if (!len--)
+ break;
+ byte type = ptr[len];
+
ptr[len] = 0;
obj_add_attr_ref(o, type, ptr);
+
+ ptr += len + 1;
}
- else if (can_overwrite == 1)
+ else if (can_overwrite == 1)
+ while (ptr < end)
{
+ uns len;
+ GET_UTF8(ptr, len);
+ if (!len--)
+ break;
+ byte type = ptr[len];
+
ptr[len] = 0;
obj_add_attr(o, type, ptr);
ptr[len] = type;
+
+ ptr += len + 1;
}
- else
+ else
+ while (ptr < end)
{
- byte *dup = mp_alloc(o->pool, len+1);
+ uns len;
+ GET_UTF8(ptr, len);
+ if (!len--)
+ break;
+ byte type = ptr[len];
+
+ byte *dup = mp_alloc_fast_noalign(o->pool, len+1);
memcpy(dup, ptr, len);
dup[len] = 0;
- obj_add_attr_ref(o, type, ptr);
+ obj_add_attr_ref(o, type, dup);
+
+ ptr += len + 1;
}
- ptr += len + 1;
- }
return ptr;
}
bsetpos(body, 0);
/* Read all the bucket into 1 buffer, 0-copy if possible. */
- int can_overwrite = MAX(bconfig(body, BCONFIG_CAN_OVERWRITE, 0), 0);
+ int can_overwrite = bconfig(body, BCONFIG_CAN_OVERWRITE, 0);
+ if (can_overwrite < 0)
+ can_overwrite = 0;
uns overwritten;
byte *ptr, *end;
uns len = bdirect_read_prepare(body, &ptr);
if (ptr != end)
RET_ERR(EINVAL);
- if (overwritten)
- bflush(body);
+ /* If (overwritten), bflush(body) might be needed. */
}
return o;
}
struct buck2obj_buf *buck2obj_alloc(uns max_len, struct mempool *mp);
void buck2obj_free(struct buck2obj_buf *buf);
struct odes *buck2obj_convert(struct buck2obj_buf *buf, uns buck_type, struct fastbuf *body);
+ /* If BCONFIG_CAN_OVERWRITE(body)==2, then the buffer of body has probably
+ * been tampered (unless the bucket is larger than the buffer). In such a
+ * case, you must call bflush(body) before you do anything else than
+ * sequential read. */