Subject: Changes for proplib to reduce kernel bloat
To: None <tech-kern@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-kern
Date: 05/08/2006 01:54:25
The patch below removes the XML conversion support from proplib when
it's built for the kernel, for which I can see no obvious use.  With
this patch, we get rid of a good chunk of the kernel bloat that new
proplib adds.  For an evbppc/WALNUT kernel the sizes before proplib,
with normal proplib, and with proplib with no XML import/export
functionality are:

	   text    data     bss     dec     hex filename
	3837324  452840  232444 4522608  450270 netbsd.devprop
	3856516  452968  234288 4543772  45551c netbsd.proplib
	3843576  452880  233888 4530344  4520a8 netbsd.no-xml-proplib

Anyone have any problems with applying this patch?

Simon.
--
Simon Burge                                   <simonb@wasabisystems.com>
NetBSD Development, Support and Service:   http://www.wasabisystems.com/


Index: lib/libprop/Makefile
===================================================================
RCS file: /cvsroot/src/lib/libprop/Makefile,v
retrieving revision 1.3
diff -d -p -u -r1.3 Makefile
--- lib/libprop/Makefile	27 Apr 2006 23:41:24 -0000	1.3
+++ lib/libprop/Makefile	7 May 2006 15:43:02 -0000
@@ -8,7 +8,7 @@ PROPLIBDIR=${NETBSDSRCDIR}/common/lib/li
 
 .include "${PROPLIBDIR}/Makefile.inc"
 
-CPPFLAGS+=-D_LIBPROP
+CPPFLAGS+=-D_LIBPROP -D_PROPLIB_XML_SUPPORT
 CPPFLAGS+=-D_REENTRANT -I${NETBSDSRCDIR}/lib/libc/include
 
 LIB=	prop
Index: common/lib/libprop/prop_array.c
===================================================================
RCS file: /cvsroot/src/common/lib/libprop/prop_array.c,v
retrieving revision 1.1
diff -d -p -u -r1.1 prop_array.c
--- common/lib/libprop/prop_array.c	27 Apr 2006 20:11:27 -0000	1.1
+++ common/lib/libprop/prop_array.c	7 May 2006 15:43:02 -0000
@@ -89,6 +89,7 @@ _prop_array_free(void *v)
 	_PROP_POOL_PUT(_prop_array_pool, pa);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 static boolean_t
 _prop_array_externalize(struct _prop_object_externalize_context *ctx,
 			void *v)
@@ -132,6 +133,7 @@ _prop_array_externalize(struct _prop_obj
 	
 	return (TRUE);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
 
 static prop_array_t
 _prop_array_alloc(unsigned int capacity)
@@ -153,7 +155,9 @@ _prop_array_alloc(unsigned int capacity)
 		_prop_object_init(&pa->pa_obj);
 		pa->pa_obj.po_type = PROP_TYPE_ARRAY;
 		pa->pa_obj.po_free = _prop_array_free;
+#ifdef _PROPLIB_XML_SUPPORT
 		pa->pa_obj.po_extern = _prop_array_externalize;
+#endif /* _PROPLIB_XML_SUPPORT */
 
 		pa->pa_array = array;
 		pa->pa_capacity = capacity;
@@ -482,6 +486,7 @@ prop_array_remove(prop_array_t pa, unsig
 	prop_object_release(po);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 /*
  * _prop_array_internalize --
  *	Parse an <array>...</array> and return the object created from the
@@ -533,3 +538,4 @@ _prop_array_internalize(struct _prop_obj
 	prop_object_release(array);
 	return (NULL);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
Index: common/lib/libprop/prop_bool.c
===================================================================
RCS file: /cvsroot/src/common/lib/libprop/prop_bool.c,v
retrieving revision 1.1
diff -d -p -u -r1.1 prop_bool.c
--- common/lib/libprop/prop_bool.c	27 Apr 2006 20:11:27 -0000	1.1
+++ common/lib/libprop/prop_bool.c	7 May 2006 15:43:02 -0000
@@ -55,6 +55,7 @@ _prop_bool_free(void *v)
 	_PROP_POOL_PUT(_prop_bool_pool, v);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 static boolean_t
 _prop_bool_externalize(struct _prop_object_externalize_context *ctx,
 		       void *v)
@@ -64,6 +65,7 @@ _prop_bool_externalize(struct _prop_obje
 	return (_prop_object_externalize_empty_tag(ctx,
 	    pb->pb_value ? "true" : "false"));
 }
+#endif /* _PROPLIB_XML_SUPPORT */
 
 static prop_bool_t
 _prop_bool_alloc(void)
@@ -75,7 +77,9 @@ _prop_bool_alloc(void)
 		_prop_object_init(&pb->pb_obj);
 		pb->pb_obj.po_type = PROP_TYPE_BOOL;
 		pb->pb_obj.po_free = _prop_bool_free;
+#ifdef _PROPLIB_XML_SUPPORT
 		pb->pb_obj.po_extern = _prop_bool_externalize;
+#endif /* _PROPLIB_XML_SUPPORT */
 	}
 
 	return (pb);
@@ -126,6 +130,7 @@ prop_bool_true(prop_bool_t pb)
 	return (pb->pb_value);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 /*
  * _prop_bool_internalize --
  *	Parse a <true/> or <false/> and return the object created from
@@ -150,3 +155,4 @@ _prop_bool_internalize(struct _prop_obje
 
 	return (prop_bool_create(val));
 }
+#endif /* _PROPLIB_XML_SUPPORT */
Index: common/lib/libprop/prop_data.c
===================================================================
RCS file: /cvsroot/src/common/lib/libprop/prop_data.c,v
retrieving revision 1.1
diff -d -p -u -r1.1 prop_data.c
--- common/lib/libprop/prop_data.c	27 Apr 2006 20:11:27 -0000	1.1
+++ common/lib/libprop/prop_data.c	7 May 2006 15:43:02 -0000
@@ -85,6 +85,7 @@ static const char _prop_data_base64[] =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 static const char _prop_data_pad64 = '=';
 
+#ifdef _PROPLIB_XML_SUPPORT
 static boolean_t
 _prop_data_externalize(struct _prop_object_externalize_context *ctx, void *v)
 {
@@ -159,6 +160,7 @@ _prop_data_externalize(struct _prop_obje
 	
 	return (TRUE);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
 
 static prop_data_t
 _prop_data_alloc(void)
@@ -170,7 +172,9 @@ _prop_data_alloc(void)
 		_prop_object_init(&pd->pd_obj);
 		pd->pd_obj.po_type = PROP_TYPE_DATA;
 		pd->pd_obj.po_free = _prop_data_free;
+#ifdef _PROPLIB_XML_SUPPORT
 		pd->pd_obj.po_extern = _prop_data_externalize;
+#endif /* _PROPLIB_XML_SUPPORT */
 
 		pd->pd_mutable = NULL;
 		pd->pd_size = 0;
@@ -347,6 +351,7 @@ prop_data_equals_data(prop_data_t pd, co
 	return (memcmp(pd->pd_immutable, v, size) == 0);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 static boolean_t
 _prop_data_internalize_decode(struct _prop_object_internalize_context *ctx,
 			     uint8_t *target, size_t targsize, size_t *sizep,
@@ -567,3 +572,4 @@ _prop_data_internalize(struct _prop_obje
 
 	return (data);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
Index: common/lib/libprop/prop_dictionary.c
===================================================================
RCS file: /cvsroot/src/common/lib/libprop/prop_dictionary.c,v
retrieving revision 1.2
diff -d -p -u -r1.2 prop_dictionary.c
--- common/lib/libprop/prop_dictionary.c	7 May 2006 06:25:49 -0000	1.2
+++ common/lib/libprop/prop_dictionary.c	7 May 2006 15:43:02 -0000
@@ -129,6 +129,7 @@ _prop_dict_entry_free(void *v)
 	prop_object_release(po);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 static boolean_t
 _prop_dict_entry_externalize(struct _prop_object_externalize_context *ctx,
 			     void *v)
@@ -147,6 +148,7 @@ _prop_dict_entry_externalize(struct _pro
 	
 	return (TRUE);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
 
 static prop_dictionary_keysym_t
 _prop_dict_entry_alloc(const char *key, prop_object_t obj)
@@ -169,7 +171,9 @@ _prop_dict_entry_alloc(const char *key, 
 		_prop_object_init(&pde->pde_obj);
 		pde->pde_obj.po_type = PROP_TYPE_DICT_KEYSYM;
 		pde->pde_obj.po_free = _prop_dict_entry_free;
+#ifdef _PROPLIB_XML_SUPPORT
 		pde->pde_obj.po_extern = _prop_dict_entry_externalize;
+#endif /* _PROPLIB_XML_SUPPORT */
 
 		strcpy(pde->pde_key, key);
 
@@ -203,6 +207,7 @@ _prop_dictionary_free(void *v)
 	_PROP_POOL_PUT(_prop_dictionary_pool, pd);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 static boolean_t
 _prop_dictionary_externalize(struct _prop_object_externalize_context *ctx,
 			     void *v)
@@ -253,6 +258,7 @@ _prop_dictionary_externalize(struct _pro
 	
 	return (TRUE);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
 
 static prop_dictionary_t
 _prop_dictionary_alloc(unsigned int capacity)
@@ -274,7 +280,9 @@ _prop_dictionary_alloc(unsigned int capa
 		_prop_object_init(&pd->pd_obj);
 		pd->pd_obj.po_type = PROP_TYPE_DICTIONARY;
 		pd->pd_obj.po_free = _prop_dictionary_free;
+#ifdef _PROPLIB_XML_SUPPORT
 		pd->pd_obj.po_extern = _prop_dictionary_externalize;
+#endif /* _PROPLIB_XML_SUPPORT */
 
 		pd->pd_array = array;
 		pd->pd_capacity = capacity;
@@ -720,6 +728,7 @@ prop_dictionary_keysym_cstring_nocopy(pr
 	return (pde->pde_key);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 /*
  * prop_dictionary_externalize --
  *	Externalize a dictionary, returning a NUL-terminated buffer
@@ -752,7 +761,9 @@ prop_dictionary_externalize(prop_diction
 
 	return (cp);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
 
+#ifdef _PROPLIB_XML_SUPPORT
 /*
  * _prop_dictionary_internalize --
  *	Parse a <dict>...</dict> and return the object created from the
@@ -889,3 +900,4 @@ prop_dictionary_internalize(const char *
  	_prop_object_internalize_context_free(ctx);
 	return (dict);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
Index: common/lib/libprop/prop_number.c
===================================================================
RCS file: /cvsroot/src/common/lib/libprop/prop_number.c,v
retrieving revision 1.1
diff -d -p -u -r1.1 prop_number.c
--- common/lib/libprop/prop_number.c	27 Apr 2006 20:11:27 -0000	1.1
+++ common/lib/libprop/prop_number.c	7 May 2006 15:43:02 -0000
@@ -67,6 +67,7 @@ _prop_number_free(void *v)
 	_PROP_POOL_PUT(_prop_number_pool, v);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 static boolean_t
 _prop_number_externalize(struct _prop_object_externalize_context *ctx,
 			 void *v)
@@ -83,6 +84,7 @@ _prop_number_externalize(struct _prop_ob
 	
 	return (TRUE);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
 
 static prop_number_t
 _prop_number_alloc(uintmax_t val)
@@ -94,7 +96,9 @@ _prop_number_alloc(uintmax_t val)
 		_prop_object_init(&pn->pn_obj);
 		pn->pn_obj.po_type = PROP_TYPE_NUMBER;
 		pn->pn_obj.po_free = _prop_number_free;
+#ifdef _PROPLIB_XML_SUPPORT
 		pn->pn_obj.po_extern = _prop_number_externalize;
+#endif /* _PROPLIB_XML_SUPPORT */
 
 		pn->pn_number = val;
 	}
@@ -183,6 +187,7 @@ prop_number_equals_integer(prop_number_t
 	return (pn->pn_number == val);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 /*
  * _prop_number_internalize --
  *	Parse a <number>...</number> and return the object created from
@@ -214,3 +219,4 @@ _prop_number_internalize(struct _prop_ob
 
 	return (_prop_number_alloc(val));
 }
+#endif /* _PROPLIB_XML_SUPPORT */
Index: common/lib/libprop/prop_object.c
===================================================================
RCS file: /cvsroot/src/common/lib/libprop/prop_object.c,v
retrieving revision 1.1
diff -d -p -u -r1.1 prop_object.c
--- common/lib/libprop/prop_object.c	27 Apr 2006 20:11:27 -0000	1.1
+++ common/lib/libprop/prop_object.c	7 May 2006 15:43:03 -0000
@@ -76,6 +76,7 @@ _prop_object_fini(struct _prop_object *p
 	/* Nothing to do, currently. */
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 /*
  * _prop_object_externalize_start_tag --
  *	Append an XML-style start tag to the externalize buffer.
@@ -648,6 +649,7 @@ _prop_object_internalize_context_free(
 
 	_PROP_FREE(ctx, M_TEMP);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
 
 /*
  * Retain / release serialization --
Index: common/lib/libprop/prop_object_impl.h
===================================================================
RCS file: /cvsroot/src/common/lib/libprop/prop_object_impl.h,v
retrieving revision 1.1
diff -d -p -u -r1.1 prop_object_impl.h
--- common/lib/libprop/prop_object_impl.h	27 Apr 2006 20:11:27 -0000	1.1
+++ common/lib/libprop/prop_object_impl.h	7 May 2006 15:43:03 -0000
@@ -39,6 +39,7 @@
 #ifndef _PROPLIB_PROP_OBJECT_IMPL_H_
 #define	_PROPLIB_PROP_OBJECT_IMPL_H_
 
+#ifdef _PROPLIB_XML_SUPPORT
 struct _prop_object_externalize_context {
 	char *		poec_buf;		/* string buffer */
 	size_t		poec_capacity;		/* capacity of buffer */
@@ -141,14 +142,17 @@ prop_object_t	_prop_number_internalize(
 				struct _prop_object_internalize_context *);
 prop_object_t	_prop_string_internalize(
 				struct _prop_object_internalize_context *);
+#endif /* _PROPLIB_XML_SUPPORT */
 
 struct _prop_object {
 	uint32_t	po_refcnt;		/* reference count */
 	uint32_t	po_type;		/* type indicator */
 	void		(*po_free)(void *);	/* func to free object */
+#ifdef _PROPLIB_XML_SUPPORT
 	boolean_t	(*po_extern)		/* func to externalize object */
 			    (struct _prop_object_externalize_context *,
 			     void *);
+#endif /* _PROPLIB_XML_SUPPORT */
 };
 
 void	_prop_object_init(struct _prop_object *);
Index: common/lib/libprop/prop_string.c
===================================================================
RCS file: /cvsroot/src/common/lib/libprop/prop_string.c,v
retrieving revision 1.1
diff -d -p -u -r1.1 prop_string.c
--- common/lib/libprop/prop_string.c	27 Apr 2006 20:11:27 -0000	1.1
+++ common/lib/libprop/prop_string.c	7 May 2006 15:43:03 -0000
@@ -71,6 +71,7 @@ _prop_string_free(void *v)
 	_PROP_POOL_PUT(_prop_string_pool, v);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 static boolean_t
 _prop_string_externalize(struct _prop_object_externalize_context *ctx,
 			 void *v)
@@ -88,6 +89,7 @@ _prop_string_externalize(struct _prop_ob
 	
 	return (TRUE);
 }
+#endif /* _PROPLIB_XML_SUPPORT */
 
 static prop_string_t
 _prop_string_alloc(void)
@@ -99,7 +101,9 @@ _prop_string_alloc(void)
 		_prop_object_init(&ps->ps_obj);
 		ps->ps_obj.po_type = PROP_TYPE_STRING;
 		ps->ps_obj.po_free = _prop_string_free;
+#ifdef _PROPLIB_XML_SUPPORT
 		ps->ps_obj.po_extern = _prop_string_externalize;
+#endif /* _PROPLIB_XML_SUPPORT */
 
 		ps->ps_mutable = NULL;
 		ps->ps_size = 0;
@@ -371,6 +375,7 @@ prop_string_equals_cstring(prop_string_t
 	return (strcmp(prop_string_contents(ps), cp) == 0);
 }
 
+#ifdef _PROPLIB_XML_SUPPORT
 /*
  * _prop_string_internalize --
  *	Parse a <string>...</string> and return the object created from the
@@ -424,3 +429,4 @@ _prop_string_internalize(struct _prop_ob
 
 	return (string);
 }
+#endif /* _PROPLIB_XML_SUPPORT */