Add a .clang-format file for automatically formatting .cc/.h files.

Reformatted core/platform/posix/port.cc as a test.
Change: 144368934
This commit is contained in:
Jonathan Hseu 2017-01-12 14:05:38 -08:00 committed by TensorFlower Gardener
parent 5ccc994e7e
commit b808afd76b
2 changed files with 19 additions and 15 deletions
tensorflow
.clang-format
core/platform/posix

4
tensorflow/.clang-format Normal file
View File

@ -0,0 +1,4 @@
# Run manually to reformat a file:
# clang-format -i --style=file <file>
BasedOnStyle: Google
DerivePointerAlignment: false

View File

@ -38,7 +38,7 @@ limitations under the License.
namespace tensorflow { namespace tensorflow {
namespace port { namespace port {
void InitMain(const char *usage, int *argc, char ***argv) {} void InitMain(const char* usage, int* argc, char*** argv) {}
string Hostname() { string Hostname() {
char hostname[1024]; char hostname[1024];
@ -65,15 +65,15 @@ int NumSchedulableCPUs() {
return kDefaultCores; return kDefaultCores;
} }
void *AlignedMalloc(size_t size, int minimum_alignment) { void* AlignedMalloc(size_t size, int minimum_alignment) {
#if defined(__ANDROID__) #if defined(__ANDROID__)
return memalign(minimum_alignment, size); return memalign(minimum_alignment, size);
#else // !defined(__ANDROID__) #else // !defined(__ANDROID__)
void *ptr = NULL; void* ptr = NULL;
// posix_memalign requires that the requested alignment be at least // posix_memalign requires that the requested alignment be at least
// sizeof(void*). In this case, fall back on malloc which should return // sizeof(void*). In this case, fall back on malloc which should return
// memory aligned to at least the size of a pointer. // memory aligned to at least the size of a pointer.
const int required_alignment = sizeof(void *); const int required_alignment = sizeof(void*);
if (minimum_alignment < required_alignment) return Malloc(size); if (minimum_alignment < required_alignment) return Malloc(size);
#ifdef TENSORFLOW_USE_JEMALLOC #ifdef TENSORFLOW_USE_JEMALLOC
int err = jemalloc_posix_memalign(&ptr, minimum_alignment, size); int err = jemalloc_posix_memalign(&ptr, minimum_alignment, size);
@ -88,9 +88,9 @@ void *AlignedMalloc(size_t size, int minimum_alignment) {
#endif #endif
} }
void AlignedFree(void *aligned_memory) { Free(aligned_memory); } void AlignedFree(void* aligned_memory) { Free(aligned_memory); }
void *Malloc(size_t size) { void* Malloc(size_t size) {
#ifdef TENSORFLOW_USE_JEMALLOC #ifdef TENSORFLOW_USE_JEMALLOC
return jemalloc_malloc(size); return jemalloc_malloc(size);
#else #else
@ -98,7 +98,7 @@ void *Malloc(size_t size) {
#endif #endif
} }
void *Realloc(void *ptr, size_t size) { void* Realloc(void* ptr, size_t size) {
#ifdef TENSORFLOW_USE_JEMALLOC #ifdef TENSORFLOW_USE_JEMALLOC
return jemalloc_realloc(ptr, size); return jemalloc_realloc(ptr, size);
#else #else
@ -106,7 +106,7 @@ void *Realloc(void *ptr, size_t size) {
#endif #endif
} }
void Free(void *ptr) { void Free(void* ptr) {
#ifdef TENSORFLOW_USE_JEMALLOC #ifdef TENSORFLOW_USE_JEMALLOC
jemalloc_free(ptr); jemalloc_free(ptr);
#else #else
@ -118,13 +118,13 @@ void MallocExtension_ReleaseToSystem(std::size_t num_bytes) {
// No-op. // No-op.
} }
std::size_t MallocExtension_GetAllocatedSize(const void *p) { return 0; } std::size_t MallocExtension_GetAllocatedSize(const void* p) { return 0; }
void AdjustFilenameForLogging(string *filename) { void AdjustFilenameForLogging(string* filename) {
// Nothing to do // Nothing to do
} }
bool Snappy_Compress(const char *input, size_t length, string *output) { bool Snappy_Compress(const char* input, size_t length, string* output) {
#ifdef SNAPPY #ifdef SNAPPY
output->resize(snappy::MaxCompressedLength(length)); output->resize(snappy::MaxCompressedLength(length));
size_t outlen; size_t outlen;
@ -136,8 +136,8 @@ bool Snappy_Compress(const char *input, size_t length, string *output) {
#endif #endif
} }
bool Snappy_GetUncompressedLength(const char *input, size_t length, bool Snappy_GetUncompressedLength(const char* input, size_t length,
size_t *result) { size_t* result) {
#ifdef SNAPPY #ifdef SNAPPY
return snappy::GetUncompressedLength(input, length, result); return snappy::GetUncompressedLength(input, length, result);
#else #else
@ -145,7 +145,7 @@ bool Snappy_GetUncompressedLength(const char *input, size_t length,
#endif #endif
} }
bool Snappy_Uncompress(const char *input, size_t length, char *output) { bool Snappy_Uncompress(const char* input, size_t length, char* output) {
#ifdef SNAPPY #ifdef SNAPPY
return snappy::RawUncompress(input, length, output); return snappy::RawUncompress(input, length, output);
#else #else
@ -153,7 +153,7 @@ bool Snappy_Uncompress(const char *input, size_t length, char *output) {
#endif #endif
} }
string Demangle(const char *mangled) { return mangled; } string Demangle(const char* mangled) { return mangled; }
} // namespace port } // namespace port
} // namespace tensorflow } // namespace tensorflow