proxygen
SafeAssert.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2013-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <folly/lang/SafeAssert.h>
18 
19 #include <folly/Conv.h>
20 #include <folly/FileUtil.h>
21 
22 namespace folly {
23 namespace detail {
24 
25 namespace {
26 void writeStderr(const char* s, size_t len) {
27  writeFull(STDERR_FILENO, s, len);
28 }
29 void writeStderr(const char* s) {
30  writeStderr(s, strlen(s));
31 }
32 } // namespace
33 
35  const char* expr,
36  const char* msg,
37  const char* file,
38  unsigned int line,
39  const char* function) {
40  writeStderr("\n\nAssertion failure: ");
41  writeStderr(expr + 1, strlen(expr) - 2);
42  writeStderr("\nMessage: ");
43  writeStderr(msg);
44  writeStderr("\nFile: ");
45  writeStderr(file);
46  writeStderr("\nLine: ");
47  char buf[20];
48  uint32_t n = uint64ToBufferUnsafe(line, buf);
49  writeFull(STDERR_FILENO, buf, n);
50  writeStderr("\nFunction: ");
51  writeStderr(function);
52  writeStderr("\n");
53  fsyncNoInt(STDERR_FILENO);
54  abort();
55 }
56 
57 } // namespace detail
58 } // namespace folly
uint32_t uint64ToBufferUnsafe(uint64_t v, char *const buffer)
Definition: Conv.h:383
void assertionFailure(const char *expr, const char *msg, const char *file, unsigned int line, const char *function)
Definition: SafeAssert.cpp:34
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
int fsyncNoInt(int fd)
Definition: FileUtil.cpp:64
ssize_t writeFull(int fd, const void *buf, size_t count)
Definition: FileUtil.cpp:134
static set< string > s