- Timestamp:
- Oct 24, 2008, 9:02:48 PM (17 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/expand.c
r1929 r1931 60 60 }; 61 61 struct recycled_buffer *recycled_head; 62 static char * 63 allocated_variable_expand_3 (const char *line, unsigned int length, 64 unsigned int *value_lenp, 65 unsigned int *buffer_lengthp); 66 static void 67 recycle_variable_buffer (char *buffer, unsigned int length); 68 69 #endif 62 #endif /* CONFIG_WITH_VALUE_LENGTH */ 70 63 71 64 … … 1071 1064 } 1072 1065 1073 /* Handles a special case for variable_expand_string2 where the variable1074 name is expanded. This variant allows the variable_buffer to1075 be recycled and thus avoid bothering with a slow free implementation1076 (darwin is horrible here).*/1077 1078 staticchar *1066 /* Initially created for handling a special case for variable_expand_string2 1067 where the variable name is expanded and freed right afterwards. This 1068 variant allows the variable_buffer to be recycled and thus avoid bothering 1069 with a slow free implementation. (Darwin is horrible slow.) */ 1070 1071 char * 1079 1072 allocated_variable_expand_3 (const char *line, unsigned int length, 1080 1073 unsigned int *value_lenp, … … 1090 1083 1091 1084 value = variable_expand_string_2 (NULL, line, len, &eol); 1092 *value_lenp = eol - value; 1085 if (value_lenp) 1086 *value_lenp = eol - value; 1093 1087 *buffer_lengthp = variable_buffer_length; 1094 1088 … … 1100 1094 1101 1095 /* recycle a buffer. */ 1102 static void 1096 1097 void 1103 1098 recycle_variable_buffer (char *buffer, unsigned int length) 1104 1099 { … … 1133 1128 restore_variable_buffer (char *buf, unsigned int len) 1134 1129 { 1130 #ifndef CONFIG_WITH_VALUE_LENGTH 1135 1131 free (variable_buffer); 1132 #else 1133 if (variable_buffer) 1134 recycle_variable_buffer (variable_buffer, variable_buffer_length); 1135 #endif 1136 1136 1137 1137 variable_buffer = buf; -
trunk/src/kmk/read.c
r1930 r1931 905 905 cp = ap = allocated_variable_expand (p2); 906 906 #else 907 cp = ap = allocated_variable_expand_2 (p2, eol - p2, NULL); 907 unsigned int buf_len; 908 cp = ap = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len); 908 909 #endif 909 910 … … 917 918 } 918 919 920 #ifndef CONFIG_WITH_VALUE_LENGTH 919 921 free (ap); 922 #else 923 recycle_variable_buffer (ap, buf_len); 924 #endif 920 925 } 921 926 } … … 939 944 cp = ap = allocated_variable_expand (p2); 940 945 #else 941 cp = ap = allocated_variable_expand_2 (p2, eol - p2, NULL); 946 unsigned int buf_len; 947 cp = ap = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len); 942 948 #endif 943 949 … … 952 958 } 953 959 960 #ifndef CONFIG_WITH_VALUE_LENGTH 954 961 free (ap); 962 #else 963 recycle_variable_buffer (ap, buf_len); 964 #endif 955 965 } 956 966 goto rule_complete; … … 995 1005 ? incdep_queue : incdep_flush; 996 1006 char *free_me = NULL; 1007 unsigned int buf_len; 997 1008 char *name = p2; 998 1009 … … 1000 1011 { 1001 1012 unsigned int name_len; 1002 free_me = name = allocated_variable_expand_ 2 (name, eol - name, &name_len);1013 free_me = name = allocated_variable_expand_3 (name, eol - name, &name_len, &buf_len); 1003 1014 eol = name + name_len; 1004 1015 while (isspace ((unsigned char)*name)) … … 1013 1024 1014 1025 if (free_me) 1015 free (free_me);1026 recycle_variable_buffer (free_me, buf_len); 1016 1027 goto rule_complete; 1017 1028 } … … 1032 1043 p = allocated_variable_expand (p2); 1033 1044 #else 1034 p = allocated_variable_expand_2 (p2, eol - p2, NULL); 1045 unsigned int buf_len; 1046 p = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len); 1035 1047 #endif 1036 1048 … … 1038 1050 if (*p == '\0') 1039 1051 { 1052 #ifndef CONFIG_WITH_VALUE_LENGTH 1040 1053 free (p); 1054 #else 1055 recycle_variable_buffer (p, buf_len); 1056 #endif 1041 1057 continue; 1042 1058 } … … 1053 1069 &nameseq_cache); 1054 1070 #endif 1071 #ifndef CONFIG_WITH_VALUE_LENGTH 1055 1072 free (p); 1073 #else 1074 recycle_variable_buffer (p, buf_len); 1075 #endif 1056 1076 1057 1077 /* Save the state of conditionals and start -
trunk/src/kmk/variable.h
r1927 r1931 192 192 # define allocated_variable_expand(line) \ 193 193 allocated_variable_expand_2 (line, -1, NULL) 194 char *allocated_variable_expand_2(const char *line, unsigned int length, unsigned int *value_lenp); 194 char *allocated_variable_expand_2 (const char *line, unsigned int length, unsigned int *value_lenp); 195 char *allocated_variable_expand_3 (const char *line, unsigned int length, 196 unsigned int *value_lenp, unsigned int *buffer_lengthp); 197 void recycle_variable_buffer (char *buffer, unsigned int length); 195 198 #endif /* CONFIG_WITH_VALUE_LENGTH */ 196 199 char *expand_argument (const char *str, const char *end);
Note:
See TracChangeset
for help on using the changeset viewer.