Commit 5ce11fde authored by Lev Walkin's avatar Lev Walkin

moving

parent d00657f6
...@@ -1058,26 +1058,27 @@ uper_put_open_type(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints ...@@ -1058,26 +1058,27 @@ uper_put_open_type(asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints
typedef struct uper_ugot_key { typedef struct uper_ugot_key {
asn_per_data_t oldpd; /* Old per data source */ asn_per_data_t oldpd; /* Old per data source */
size_t unclaimed; size_t unclaimed;
size_t ot_moved; /* Number of bits moved by OT processing */
int repeat; int repeat;
} uper_ugot_key; } uper_ugot_key;
static int static int
uper_ugot_refill(asn_per_data_t *pd) { uper_ugot_refill(asn_per_data_t *pd) {
uper_ugot_key *arg = pd->refill_key; uper_ugot_key *arg = pd->refill_key;
ssize_t next_chunk_bytes, next_chunk_bits; ssize_t next_chunk_bytes, next_chunk_bits;
ssize_t consumed;
ssize_t avail; ssize_t avail;
asn_per_data_t *oldpd = &arg->oldpd; asn_per_data_t *oldpd = &arg->oldpd;
/* Advance our position to where pd is */ ASN_DEBUG("REFILLING [from %d (%d->%d)] now [%d (%d->%d)] uncl %d",
consumed = (pd->buffer - oldpd->buffer) << 3;
ASN_DEBUG("REFILLING [consumed: %d bits from %d (%d->%d)] now [%d (%d->%d)] uncl %d",
consumed,
oldpd->nbits - oldpd->nboff, oldpd->nboff, oldpd->nbits, oldpd->nbits - oldpd->nboff, oldpd->nboff, oldpd->nbits,
pd->nbits - pd->nboff, pd->nboff, pd->nbits, arg->unclaimed); pd->nbits - pd->nboff, pd->nboff, pd->nbits, arg->unclaimed);
oldpd->nbits -= consumed;
/* Advance our position to where pd is */
oldpd->buffer = pd->buffer; oldpd->buffer = pd->buffer;
oldpd->nboff = pd->nboff; oldpd->nboff = pd->nboff;
oldpd->nbits -= pd->moved - arg->ot_moved;
oldpd->moved += pd->moved - arg->ot_moved;
arg->ot_moved = pd->moved;
if(arg->unclaimed) { if(arg->unclaimed) {
/* Refill the container */ /* Refill the container */
...@@ -1090,7 +1091,6 @@ uper_ugot_refill(asn_per_data_t *pd) { ...@@ -1090,7 +1091,6 @@ uper_ugot_refill(asn_per_data_t *pd) {
pd->buffer = oldpd->buffer; pd->buffer = oldpd->buffer;
pd->nboff = oldpd->nboff - 1; pd->nboff = oldpd->nboff - 1;
pd->nbits = oldpd->nbits; pd->nbits = oldpd->nbits;
pd->moved = oldpd->moved - 1;
ASN_DEBUG("===================="); ASN_DEBUG("====================");
return 0; return 0;
} }
...@@ -1104,13 +1104,13 @@ uper_ugot_refill(asn_per_data_t *pd) { ...@@ -1104,13 +1104,13 @@ uper_ugot_refill(asn_per_data_t *pd) {
ASN_DEBUG("Open type LENGTH %d bytes, old %d (%d->%d) repeat %d", ASN_DEBUG("Open type LENGTH %d bytes, old %d (%d->%d) repeat %d",
next_chunk_bytes, oldpd->nbits - oldpd->nboff, oldpd->nboff, oldpd->nbits, arg->repeat); next_chunk_bytes, oldpd->nbits - oldpd->nboff, oldpd->nboff, oldpd->nbits, arg->repeat);
if(next_chunk_bytes < 0) return -1; if(next_chunk_bytes < 0) return -1;
assert(next_chunk_bytes || !arg->repeat); if(next_chunk_bytes == 0) {
if(next_chunk_bytes == 0)
pd->refill = 0; /* No more refills, naturally */ pd->refill = 0; /* No more refills, naturally */
assert(!arg->repeat); /* Implementation guarantee */
}
pd->buffer = oldpd->buffer; pd->buffer = oldpd->buffer;
pd->nboff = oldpd->nboff; pd->nboff = oldpd->nboff;
pd->nbits = oldpd->nbits; pd->nbits = oldpd->nbits;
pd->moved = oldpd->moved;
next_chunk_bits = next_chunk_bytes << 3; next_chunk_bits = next_chunk_bytes << 3;
avail = pd->nbits - pd->nboff; avail = pd->nbits - pd->nboff;
ASN_DEBUG("now at %d bits, want %d, avail %d", ASN_DEBUG("now at %d bits, want %d, avail %d",
...@@ -1139,11 +1139,12 @@ uper_get_open_type(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -1139,11 +1139,12 @@ uper_get_open_type(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
ASN_DEBUG("Getting open type from %d bits (%d+%d), %p", pd->nbits - pd->nboff, pd->nboff, pd->nbits, pd->buffer); ASN_DEBUG("Getting open type from %d bits (%d+%d), %p", pd->nbits - pd->nboff, pd->nboff, pd->nbits, pd->buffer);
arg.oldpd = *pd; arg.oldpd = *pd;
arg.unclaimed = 0;
arg.ot_moved = 0;
arg.repeat = 1;
pd->refill = uper_ugot_refill; pd->refill = uper_ugot_refill;
pd->refill_key = &arg; pd->refill_key = &arg;
pd->nbits = pd->nboff; /* 0 bits at this point, wait for refill */ pd->nbits = pd->nboff; /* 0 bits at this point, wait for refill */
arg.unclaimed = 0;
arg.repeat = 1;
rv = td->uper_decoder(opt_codec_ctx, td, constraints, sptr, pd); rv = td->uper_decoder(opt_codec_ctx, td, constraints, sptr, pd);
...@@ -1163,6 +1164,7 @@ uper_get_open_type(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -1163,6 +1164,7 @@ uper_get_open_type(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
} }
ASN_DEBUG("nboff = %d, nbits %d, padding = %d, plus %d/%p", pd->nboff, pd->nbits, padding, pd->buffer - arg.oldpd.buffer, arg.oldpd.buffer); ASN_DEBUG("nboff = %d, nbits %d, padding = %d, plus %d/%p", pd->nboff, pd->nbits, padding, pd->buffer - arg.oldpd.buffer, arg.oldpd.buffer);
ASN_DEBUG("Getting padding of %d bits", padding);
switch(per_get_few_bits(pd, padding)) { switch(per_get_few_bits(pd, padding)) {
case -1: case -1:
ASN_DEBUG("Padding skip failed"); ASN_DEBUG("Padding skip failed");
...@@ -1177,7 +1179,7 @@ uper_get_open_type(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -1177,7 +1179,7 @@ uper_get_open_type(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
/* Skip data not consumed by the decoder */ /* Skip data not consumed by the decoder */
while(arg.unclaimed) { while(arg.unclaimed) {
int toget = 24; size_t toget = 24;
if(arg.unclaimed < toget) if(arg.unclaimed < toget)
toget = arg.unclaimed; toget = arg.unclaimed;
arg.unclaimed -= toget; arg.unclaimed -= toget;
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
void void
per_get_undo(asn_per_data_t *pd, int nbits) { per_get_undo(asn_per_data_t *pd, int nbits) {
if(pd->nboff < nbits) { if((ssize_t)pd->nboff < nbits) {
assert(pd->nboff < nbits); assert((ssize_t)pd->nboff < nbits);
} else { } else {
pd->nboff -= nbits; pd->nboff -= nbits;
pd->moved -= nbits; pd->moved -= nbits;
...@@ -389,7 +389,7 @@ uper_put_nslength(asn_per_outp_t *po, size_t length) { ...@@ -389,7 +389,7 @@ uper_put_nslength(asn_per_outp_t *po, size_t length) {
if(length == 0) return -1; if(length == 0) return -1;
return per_put_few_bits(po, length-1, 7) ? -1 : 0; return per_put_few_bits(po, length-1, 7) ? -1 : 0;
} else { } else {
if(uper_put_length(po, length) != length) { if(uper_put_length(po, length) != (ssize_t)length) {
/* This might happen in case of >16K extensions */ /* This might happen in case of >16K extensions */
return -1; return -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment