This is an automated email from the ASF dual-hosted git repository.
haibin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new 44c21bd Add extra header file to export for error checking (#13795)
44c21bd is described below
commit 44c21bd3a21b7b3f3ebdd2f54bc1da612fa538df
Author: Lin Yuan <[email protected]>
AuthorDate: Tue Jan 8 22:00:39 2019 -0800
Add extra header file to export for error checking (#13795)
* add extra header file to include
* fix sanity check
* fix sanity
* move c_api_common.h to include folder
* fix build error
* keep c_api_common.h internal
* strip out error handling API into a separate header
* consolidate comment into one paragraph per review
* remove unnecessary include
---
include/mxnet/c_api_error.h | 56 +++++++++++++++++++++++++++++++++++++++++++++
src/c_api/c_api_common.h | 42 ++++++++++++----------------------
2 files changed, 71 insertions(+), 27 deletions(-)
diff --git a/include/mxnet/c_api_error.h b/include/mxnet/c_api_error.h
new file mode 100644
index 0000000..0c6ea03
--- /dev/null
+++ b/include/mxnet/c_api_error.h
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2018 by Contributors
+ * \file c_api_error.h
+ * \brief Error handling for C API.
+ */
+#ifndef MXNET_C_API_ERROR_H_
+#define MXNET_C_API_ERROR_H_
+
+/*!
+ * \brief Macros to guard beginning and end section of all functions
+ * every function starts with API_BEGIN()
+ * and finishes with API_END() or API_END_HANDLE_ERROR()
+ * The finally clause contains procedure to cleanup states when an error
happens.
+ */
+#define MX_API_BEGIN() try { on_enter_api(__FUNCTION__);
+#define MX_API_END() } catch(dmlc::Error &_except_) { on_exit_api(); return
MXAPIHandleException(_except_); } on_exit_api(); return 0; // NOLINT(*)
+#define MX_API_END_HANDLE_ERROR(Finalize) } catch(dmlc::Error &_except_) {
Finalize; on_exit_api(); return MXAPIHandleException(_except_); }
on_exit_api(); return 0; // NOLINT(*)
+/*!
+ * \brief Set the last error message needed by C API
+ * \param msg The error message to set.
+ */
+void MXAPISetLastError(const char* msg);
+/*!
+ * \brief handle exception throwed out
+ * \param e the exception
+ * \return the return value of API after exception is handled
+ */
+inline int MXAPIHandleException(const dmlc::Error &e) {
+ MXAPISetLastError(e.what());
+ return -1;
+}
+
+namespace mxnet {
+extern void on_enter_api(const char *function);
+extern void on_exit_api();
+}
+#endif // MXNET_C_API_ERROR_H_
diff --git a/src/c_api/c_api_common.h b/src/c_api/c_api_common.h
index 079b587..ecb05bc 100644
--- a/src/c_api/c_api_common.h
+++ b/src/c_api/c_api_common.h
@@ -29,37 +29,29 @@
#include <dmlc/logging.h>
#include <dmlc/thread_local.h>
#include <mxnet/c_api.h>
+#include <mxnet/c_api_error.h>
#include <mxnet/base.h>
#include <nnvm/graph.h>
#include <vector>
#include <string>
-/*! \brief macro to guard beginning and end section of all functions */
-#define API_BEGIN() try { on_enter_api(__FUNCTION__);
-/*! \brief every function starts with API_BEGIN();
- and finishes with API_END() or API_END_HANDLE_ERROR */
-#define API_END() } catch(dmlc::Error &_except_) { on_exit_api(); return
MXAPIHandleException(_except_); } on_exit_api(); return 0; // NOLINT(*)
/*!
- * \brief every function starts with API_BEGIN();
- * and finishes with API_END() or API_END_HANDLE_ERROR
- * The finally clause contains procedure to cleanup states when an error
happens.
+ * \brief Macros to guard beginning and end section of all functions
+ * every function starts with API_BEGIN()
+ * and finishes with API_END() or API_END_HANDLE_ERROR()
+ * The finally clause contains procedure to cleanup states when an error
happens.
*/
-#define API_END_HANDLE_ERROR(Finalize) } catch(dmlc::Error &_except_) {
Finalize; on_exit_api(); return MXAPIHandleException(_except_); }
on_exit_api(); return 0; // NOLINT(*)
+#ifndef API_BEGIN
+#define API_BEGIN MX_API_BEGIN
+#endif
-/*!
- * \brief Set the last error message needed by C API
- * \param msg The error message to set.
- */
-void MXAPISetLastError(const char* msg);
-/*!
- * \brief handle exception throwed out
- * \param e the exception
- * \return the return value of API after exception is handled
- */
-inline int MXAPIHandleException(const dmlc::Error &e) {
- MXAPISetLastError(e.what());
- return -1;
-}
+#ifndef API_END
+#define API_END MX_API_END
+#endif
+
+#ifndef API_END_HANDLE_ERROR
+#define API_END_HANDLE_ERROR MX_API_END_HANDLE_ERROR
+#endif
using namespace mxnet;
@@ -137,10 +129,6 @@ inline void CopyAttr(const nnvm::IndexedGraph& idx,
// stores keys that will be converted to __key__
extern const std::vector<std::string> kHiddenKeys;
-
-extern void on_enter_api(const char *function);
-extern void on_exit_api();
-
} // namespace mxnet
#endif // MXNET_C_API_C_API_COMMON_H_