cvs commit: ALFS/nALFS/src/handlers stage.c

kpfleming at linuxfromscratch.org kpfleming at linuxfromscratch.org
Mon Feb 23 10:16:21 PST 2004


kpfleming    04/02/23 11:16:21

  Modified:    nALFS/src handlers.h parser.c
               nALFS/src/handlers stage.c
  Log:
  provide handler support for freeing private data when element is freed
  
  Revision  Changes    Path
  1.16      +5 -1      ALFS/nALFS/src/handlers.h
  
  Index: handlers.h
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers.h,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- handlers.h	21 Feb 2004 23:09:17 -0000	1.15
  +++ handlers.h	23 Feb 2004 18:16:21 -0000	1.16
  @@ -56,6 +56,7 @@
   typedef int (*handler_f)(element_s * const element);
   typedef int (*handler_test)(element_s * const element, int * const result);
   typedef int (*handler_setup)(element_s * const element);
  +typedef void (*handler_free)(const element_s * const element);
   typedef int (*handler_parse)(const element_s * const element,
   			     const char * const name,
   			     const char * const value);
  @@ -88,11 +89,14 @@
   				   <shell> element if present in a containing
   				   element */
   
  -	/* The following five functions are used during profile parsing, to
  +	/* The following functions are used during profile parsing, to
   	   allow handler to store private data in the element_s structure,
   	   and to validate the provided parameters, attributes and content.
  +	   The handler_free function is called when an element is freed,
  +	   so the handler can free any private data it may have stored.
   	*/
   	handler_setup setup;	/* Function to setup handler private data. */
  +	handler_free free;
   	handler_invalid_data invalid_data; /* Validate private data. */
   	handler_invalid_child invalid_child; /* Validate potential child. */
   	handler_parse parse_attribute;
  
  
  
  1.9       +3 -0      ALFS/nALFS/src/parser.c
  
  Index: parser.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/parser.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- parser.c	21 Feb 2004 19:03:32 -0000	1.8
  +++ parser.c	23 Feb 2004 18:16:21 -0000	1.9
  @@ -89,6 +89,9 @@
   		child = tmp;
   	}
   
  +	if (el->handler->free)
  +		el->handler->free(el);
  +
   	xfree(el->name);
   	xfree(el->content);
   
  
  
  
  1.22      +53 -0     ALFS/nALFS/src/handlers/stage.c
  
  Index: stage.c
  ===================================================================
  RCS file: /home/cvsroot/ALFS/nALFS/src/handlers/stage.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- stage.c	21 Feb 2004 23:09:17 -0000	1.21
  +++ stage.c	23 Feb 2004 18:16:21 -0000	1.22
  @@ -306,6 +306,14 @@
   	return 0;
   }
   
  +static void stage_free(const element_s * const element)
  +{
  +	struct stage_data *data = (struct stage_data *) element->handler_data;
  +	
  +	xfree(data->name);
  +	xfree(element->handler_data);
  +}
  +
   static int stage_attribute(const element_s * const element,
   			   const char * const attribute,
   			   const char * const value)
  @@ -442,6 +450,17 @@
   	return 0;
   }
   
  +static void stageinfo_free(const element_s * const element)
  +{
  +	struct stageinfo_data *data = (struct stageinfo_data *) element->handler_data;
  +	
  +	xfree(data->base);
  +	xfree(data->root);
  +	xfree(data->user);
  +	xfree(data->shell);
  +	xfree(element->handler_data);
  +}
  +
   static int stageinfo_parameter(const element_s * const element,
   			       const char * const parameter,
   			       const char * const value)
  @@ -559,6 +578,15 @@
   	return 0;
   }
   
  +static void variable_free(const element_s * const element)
  +{
  +	struct variable_data *data = (struct variable_data *) element->handler_data;
  +	
  +	xfree(data->name);
  +	xfree(data->value);
  +	xfree(element->handler_data);
  +}
  +
   static int variable_attribute(const element_s * const element,
   			      const char * const attribute,
   			      const char * const value)
  @@ -648,6 +676,7 @@
   		.data = HDATA_BASE,
   		.alloc_data = stage_data,
   		.setup = stage_setup,
  +		.free = stage_free,
   		.attributes = stage_attributes,
   		.parse_attribute = stage_attribute,
   	},
  @@ -659,6 +688,7 @@
   		.main = stageinfo_main,
   		.alloc_data = stageinfo_data,
   		.setup = stageinfo_setup,
  +		.free = stageinfo_free,
   		.parameters = stageinfo_parameters,
   		.parse_parameter = stageinfo_parameter,
   	},
  @@ -676,6 +706,7 @@
   		.type = HTYPE_NORMAL,
   		.main = variable_main,
   		.setup = variable_setup,
  +		.free = variable_free,
   		.attributes = variable_attributes,
   		.parse_attribute = variable_attribute,
   		.parse_content = variable_content,
  @@ -692,6 +723,7 @@
   		.data = HDATA_BASE,
   		.alloc_data = stage_data,
   		.setup = stage_setup,
  +		.free = stage_free,
   		.attributes = stage_attributes,
   		.parse_attribute = stage_attribute,
   	},
  @@ -703,6 +735,10 @@
   		.main = then_main,
   		.data = HDATA_BASE,
   		.alloc_data = stage_data,
  +		.setup = stage_setup,
  +		.free = stage_free,
  +		.attributes = stage_attributes,
  +		.parse_attribute = stage_attribute,
   	},
   	{
   		.name = "else",
  @@ -712,6 +748,10 @@
   		.main = else_main,
   		.data = HDATA_BASE,
   		.alloc_data = stage_data,
  +		.setup = stage_setup,
  +		.free = stage_free,
  +		.attributes = stage_attributes,
  +		.parse_attribute = stage_attribute,
   	},
   	{
   		.name = "stageinfo",
  @@ -721,6 +761,7 @@
   		.main = stageinfo_main,
   		.alloc_data = stageinfo_data,
   		.setup = stageinfo_setup,
  +		.free = stageinfo_free,
   		.parameters = stageinfo_parameters,
   		.parse_parameter = stageinfo_parameter,
   	},
  @@ -738,6 +779,7 @@
   		.type = HTYPE_NORMAL,
   		.main = variable_main,
   		.setup = variable_setup,
  +		.free = variable_free,
   		.attributes = variable_attributes,
   		.parse_attribute = variable_attribute,
   		.parse_content = variable_content,
  @@ -754,6 +796,7 @@
   		.data = HDATA_BASE | HDATA_SHELL,
   		.alloc_data = stage_data,
   		.setup = stage_setup,
  +		.free = stage_free,
   		.attributes = stage_attributes,
   		.parse_attribute = stage_attribute,
   	},
  @@ -765,6 +808,10 @@
   		.main = then_main,
   		.data = HDATA_BASE | HDATA_SHELL,
   		.alloc_data = stage_data,
  +		.setup = stage_setup,
  +		.free = stage_free,
  +		.attributes = stage_attributes,
  +		.parse_attribute = stage_attribute,
   	},
   	{
   		.name = "else",
  @@ -774,6 +821,10 @@
   		.main = else_main,
   		.data = HDATA_BASE | HDATA_SHELL,
   		.alloc_data = stage_data,
  +		.setup = stage_setup,
  +		.free = stage_free,
  +		.attributes = stage_attributes,
  +		.parse_attribute = stage_attribute,
   	},
   	{
   		.name = "stageinfo",
  @@ -782,6 +833,7 @@
   		.type = HTYPE_STAGEINFO,
   		.main = stageinfo_main,
   		.setup = stageinfo_setup,
  +		.free = stageinfo_free,
   		.alloc_data = stageinfo_data,
   		.parameters = stageinfo_parameters_3_2,
   		.parse_parameter = stageinfo_parameter,
  @@ -800,6 +852,7 @@
   		.type = HTYPE_NORMAL,
   		.main = variable_main,
   		.setup = variable_setup,
  +		.free = variable_free,
   		.attributes = variable_attributes,
   		.parse_attribute = variable_attribute,
   		.parse_content = variable_content,
  
  
  



More information about the alfs-log mailing list