XMLValueList support


git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@708 59561ff5-6e30-0410-9f3c-9617f08c8826
diff --git a/skeletons/NativeInteger.c b/skeletons/NativeInteger.c
index d6d1fd8..102372c 100644
--- a/skeletons/NativeInteger.c
+++ b/skeletons/NativeInteger.c
@@ -11,7 +11,6 @@
  */
 #include <asn_internal.h>
 #include <NativeInteger.h>
-#include <INTEGER.h>
 #include <assert.h>
 
 /*
@@ -45,17 +44,17 @@
 asn_dec_rval_t
 NativeInteger_decode_ber(asn_codec_ctx_t *opt_codec_ctx,
 	asn_TYPE_descriptor_t *td,
-	void **int_ptr, void *buf_ptr, size_t size, int tag_mode) {
-	int *Int = (int *)*int_ptr;
+	void **nint_ptr, void *buf_ptr, size_t size, int tag_mode) {
+	long *native = (long *)*nint_ptr;
 	asn_dec_rval_t rval;
 	ber_tlv_len_t length;
 
 	/*
 	 * If the structure is not there, allocate it.
 	 */
-	if(Int == NULL) {
-		Int = (int *)(*int_ptr = CALLOC(1, sizeof(*Int)));
-		if(Int == NULL) {
+	if(native == NULL) {
+		native = (long *)(*nint_ptr = CALLOC(1, sizeof(*native)));
+		if(native == NULL) {
 			rval.code = RC_FAIL;
 			rval.consumed = 0;
 			return rval;
@@ -88,7 +87,7 @@
 
 	/*
 	 * ASN.1 encoded INTEGER: buf_ptr, length
-	 * Fill the Int, at the same time checking for overflow.
+	 * Fill the native, at the same time checking for overflow.
 	 * If overflow occured, return with RC_FAIL.
 	 */
 	{
@@ -103,15 +102,15 @@
 			return rval;
 		}
 
-		*Int = l;
+		*native = l;
 
 		/*
-		 * Note that int might be shorter than long.
+		 * Note that native integer size might be other than long.
 		 * This expression hopefully will be optimized away
 		 * by compiler.
 		 */
-		if(sizeof(int) != sizeof(long) && ((long)*Int != l)) {
-			*Int = 0;	/* Safe value */
+		if(sizeof(*native) != sizeof(long) && ((long)*native != l)) {
+			*native = 0;	/* Safe value */
 			rval.code = RC_FAIL;
 			rval.consumed = 0;
 			return rval;
@@ -121,8 +120,8 @@
 	rval.code = RC_OK;
 	rval.consumed += length;
 
-	ASN_DEBUG("Took %ld/%ld bytes to encode %s (%d)",
-		(long)rval.consumed, (long)length, td->name, *Int);
+	ASN_DEBUG("Took %ld/%ld bytes to encode %s (%ld)",
+		(long)rval.consumed, (long)length, td->name, (long)*native);
 
 	return rval;
 }
@@ -134,22 +133,22 @@
 NativeInteger_encode_der(asn_TYPE_descriptor_t *sd, void *ptr,
 	int tag_mode, ber_tlv_tag_t tag,
 	asn_app_consume_bytes_f *cb, void *app_key) {
-	unsigned int Int = *(unsigned int *)ptr;	/* Disable sign ext. */
+	unsigned long native = *(unsigned long *)ptr;	/* Disable sign ext. */
 	asn_enc_rval_t erval;
 	INTEGER_t tmp;
 
 #ifdef	WORDS_BIGENDIAN		/* Opportunistic optimization */
 
-	tmp.buf = (uint8_t *)&Int;
-	tmp.size = sizeof(Int);
+	tmp.buf = (uint8_t *)&native;
+	tmp.size = sizeof(native);
 
 #else	/* Works even if WORDS_BIGENDIAN is not set where should've been */
-	uint8_t buf[sizeof(int)];
+	uint8_t buf[sizeof(native)];
 	uint8_t *p;
 
 	/* Prepare a fake INTEGER */
-	for(p = buf + sizeof(buf) - 1; p >= buf; p--, Int >>= 8)
-		*p = Int;
+	for(p = buf + sizeof(buf) - 1; p >= buf; p--, native >>= 8)
+		*p = native;
 
 	tmp.buf = buf;
 	tmp.size = sizeof(buf);
@@ -174,12 +173,12 @@
 	asn_dec_rval_t rval;
 	INTEGER_t *st = 0;
 	void *st_ptr = (void *)&st;
-	int *Int = (int *)*sptr;
+	long *native = (long *)*sptr;
 
-	if(!Int) {
+	if(!native) {
 		*sptr = CALLOC(1, sizeof(int));
-		Int = (int *)*sptr;
-		if(!Int) {
+		native = (long *)*sptr;
+		if(!native) {
 			rval.code = RC_FAIL;
 			rval.consumed = 0;
 			return rval;
@@ -194,17 +193,23 @@
 			rval.code = RC_FAIL;
 			rval.consumed = 0;
 		} else {
-			*Int = l;
+			*native = l;
 
-			/* int might be shorter than long */
-			if(sizeof(int) != sizeof(long) && ((long)*Int != l)) {
-				*Int = 0;	/* Safe value */
+			/* Native type might be shorter than long */
+			if(sizeof(*native) != sizeof(long)
+					&& ((long)*native != l)) {
+				*native = 0;	/* Safe value */
 				rval.code = RC_FAIL;
 				rval.consumed = 0;
 				return rval;
 			}
 		}
 	} else {
+		/*
+		 * Cannot restart from the middle;
+		 * there is no place to save state in the native type.
+		 * Request a continuation from the very beginning.
+		 */
 		rval.consumed = 0;
 	}
 	asn_DEF_INTEGER.free_struct(&asn_DEF_INTEGER, st, 0);
@@ -218,14 +223,14 @@
 		asn_app_consume_bytes_f *cb, void *app_key) {
 	char scratch[32];	/* Enough for 64-bit int */
 	asn_enc_rval_t er;
-	const int *Int = (const int *)sptr;
+	const long *native = (const long *)sptr;
 
 	(void)ilevel;
 	(void)flags;
 
-	if(!Int) _ASN_ENCODE_FAILED;
+	if(!native) _ASN_ENCODE_FAILED;
 
-	er.encoded = snprintf(scratch, sizeof(scratch), "%d", *Int);
+	er.encoded = snprintf(scratch, sizeof(scratch), "%ld", *native);
 	if(er.encoded <= 0 || (size_t)er.encoded >= sizeof(scratch)
 		|| cb(scratch, er.encoded, app_key) < 0)
 		_ASN_ENCODE_FAILED;
@@ -239,16 +244,16 @@
 int
 NativeInteger_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
 	asn_app_consume_bytes_f *cb, void *app_key) {
-	const int *Int = (const int *)sptr;
+	const long *native = (const long *)sptr;
 	char scratch[32];	/* Enough for 64-bit int */
 	int ret;
 
 	(void)td;	/* Unused argument */
 	(void)ilevel;	/* Unused argument */
 
-	if(Int) {
-		ret = snprintf(scratch, sizeof(scratch), "%d", *Int);
-		assert(ret > 0 && ret < (int)sizeof(scratch));
+	if(native) {
+		ret = snprintf(scratch, sizeof(scratch), "%ld", *native);
+		assert(ret > 0 && (size_t)ret < sizeof(scratch));
 		return (cb(scratch, ret, app_key) < 0) ? -1 : 0;
 	} else {
 		return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;