Add type confusion protection to the default memory provider.

This commit is contained in:
David Chisnall
2019-08-13 15:01:30 +01:00
committed by David Chisnall
parent 6dbe24da2e
commit d56201e28d
6 changed files with 29 additions and 14 deletions

View File

@@ -42,6 +42,25 @@ namespace snmalloc
}
};
/**
* A singleton global. Used to allow globals in headers. Precisely one
* instance of the static field will exist in the final program, irrespective
* of the number of compilation units that reference the field.
*
* C++ globals do not have their types as part of the name mangling, so this
* allows a singleton instance of a specific type that won't be confused with
* other template instantiations of the same type.
*/
template<class T>
struct TypedSingleton
{
/**
* The global variable, which will have a mangled name that includes the
* type of `T`.
*/
static inline T global;
};
/**
* Wrapper for wrapping values.
*