* xmlHashCopySafe: * @hash: hash table * @copyFunc: copier function for items in the hash * @deallocFunc: deallocation function in case of errors * * Copy the hash table using @copyFunc to copy payloads. * * Available since 2.13.0. * * Returns the new table or NULL if a memory allocation failed. */
| 1146 | * Returns the new table or NULL if a memory allocation failed. |
| 1147 | */ |
| 1148 | xmlHashTablePtr |
| 1149 | xmlHashCopySafe(xmlHashTablePtr hash, xmlHashCopier copyFunc, |
| 1150 | xmlHashDeallocator deallocFunc) { |
| 1151 | const xmlHashEntry *entry, *end; |
| 1152 | xmlHashTablePtr ret; |
| 1153 | |
| 1154 | if ((hash == NULL) || (copyFunc == NULL)) |
| 1155 | return(NULL); |
| 1156 | |
| 1157 | ret = xmlHashCreate(hash->size); |
| 1158 | if (ret == NULL) |
| 1159 | return(NULL); |
| 1160 | |
| 1161 | if (hash->size == 0) |
| 1162 | return(ret); |
| 1163 | |
| 1164 | end = &hash->table[hash->size]; |
| 1165 | |
| 1166 | for (entry = hash->table; entry < end; entry++) { |
| 1167 | if (entry->hashValue != 0) { |
| 1168 | void *copy; |
| 1169 | |
| 1170 | copy = copyFunc(entry->payload, entry->key); |
| 1171 | if (copy == NULL) |
| 1172 | goto error; |
| 1173 | if (xmlHashAdd3(ret, entry->key, entry->key2, entry->key3, |
| 1174 | copy) <= 0) { |
| 1175 | if (deallocFunc != NULL) |
| 1176 | deallocFunc(copy, entry->key); |
| 1177 | goto error; |
| 1178 | } |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | return(ret); |
| 1183 | |
| 1184 | error: |
| 1185 | xmlHashFree(ret, deallocFunc); |
| 1186 | return(NULL); |
| 1187 | } |
| 1188 | |
| 1189 | /* |
| 1190 | * xmlHashCopy: |
no test coverage detected