library/src/datastructures/BP-HashTable.cc
// duplicates a string and stores it in the hash table
duplicates a string and stores it in the hash table
duplicates a string and stores it in the hash table
char * ht_strdup_real
(
		P_BP_HASH_TABLE_REGISTRY hreg,
		char *dup,
		BPLN_PARMS
)
{
	BP_GLOBAL_HASH_TABLE_OVERRIDE(NULL);
	if(!hreg)
		return NULL;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(hreg);
	 to alloc from
	if(!hreg)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	if(!dup)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	size_t str_len = bpstrlen(dup);
	if(!str_len)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	if(!BP_StringIsReasonablePrintableString(dup, str_len, BP_TRUE, BP_TRUE))
	{
	 	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	}
	char * new_string = (char *) BP_HashRegAddMemoryEntry
	(
			hreg,
			BP_HASH_REG_MEM_ENTRY_TYPE_GENERIC_ALLOCATION,
			str_len+1,
			BPLN_PARMS_PASSTHROUGH
	);
	if(new_string)
		memcpy(new_string, dup, str_len);
	if(!new_string)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(hreg, NULL);
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION(hreg);
	return new_string;
}
char * ht_strdup_real ( P_BP_HASH_TABLE_REGISTRY hreg , char * dup , BPLN_PARMS ) { BP_GLOBAL_HASH_TABLE_OVERRIDE ( NULL ) ; if ( ! hreg ) return NULL ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( hreg ) ; if ( ! hreg ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( hreg , NULL ) ; if ( ! dup ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( hreg , NULL ) ; size_t str_len = bpstrlen ( dup ) ; if ( ! str_len ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( hreg , NULL ) ; if ( ! BP_StringIsReasonablePrintableString ( dup , str_len , BP_TRUE , BP_TRUE ) ) { BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( hreg , NULL ) ; } char * new_string = ( char * ) BP_HashRegAddMemoryEntry ( hreg , BP_HASH_REG_MEM_ENTRY_TYPE_GENERIC_ALLOCATION , str_len + 1 , BPLN_PARMS_PASSTHROUGH ) ; if ( new_string ) memcpy ( new_string , dup , str_len ) ; if ( ! new_string ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( hreg , NULL ) ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION ( hreg ) ; return new_string ; }
duplicates a string and stores it in the hash table
duplicates a string and stores it in the hash table
// macro to override hreg on null // ensure we have a registry // enter critical section // ensure we have a registry to alloc from // ensure we have a string to dup // ensure we can calc length without faulting // run basic string checks (newlines/cr ok) // attempt to allocate the entry within the hash registry // copy in the string // exit if we haven't allocated a new string // leave critical section // return indicating success