From a1bfb35dd692a506628416e33ac1b58f91b5a867 Mon Sep 17 00:00:00 2001 From: Xin Pan Date: Sat, 12 Jan 2019 22:06:57 +0800 Subject: [PATCH] try fix py2 test=develop --- paddle/fluid/framework/python_headers.h | 27 +++++++++++++++++++++++++ paddle/fluid/imperative/layer.h | 11 ++++++---- paddle/fluid/imperative/tracer.h | 10 ++++----- paddle/fluid/operators/py_func_op.cc | 2 +- paddle/fluid/operators/py_func_op.h | 3 +-- 5 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 paddle/fluid/framework/python_headers.h diff --git a/paddle/fluid/framework/python_headers.h b/paddle/fluid/framework/python_headers.h new file mode 100644 index 00000000000..6ebc4236197 --- /dev/null +++ b/paddle/fluid/framework/python_headers.h @@ -0,0 +1,27 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed 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. */ + +#pragma once + +// workaround for Python 2 issue: https://bugs.python.org/issue17120 +#pragma push_macro("_XOPEN_SOURCE") +#pragma push_macro("_POSIX_C_SOURCE") +#undef _XOPEN_SOURCE +#undef _POSIX_C_SOURCE + +#include +#include "pybind11/pybind11.h" + +#pragma pop_macro("_XOPEN_SOURCE") +#pragma pop_macro("_POSIX_C_SOURCE") diff --git a/paddle/fluid/imperative/layer.h b/paddle/fluid/imperative/layer.h index 86c2dc3fa4a..daf56a52108 100644 --- a/paddle/fluid/imperative/layer.h +++ b/paddle/fluid/imperative/layer.h @@ -14,15 +14,18 @@ #pragma once -#include -#include -#include +// clang-format off +#include "paddle/fluid/framework/python_headers.h" +// clang-format on + +#include // NOLINT +#include // NOLINT +#include // NOLINT #include "paddle/fluid/framework/op_desc.h" #include "paddle/fluid/framework/operator.h" #include "paddle/fluid/framework/var_desc.h" #include "paddle/fluid/platform/enforce.h" -#include "pybind11/pybind11.h" #include "paddle/fluid/imperative/type_defs.h" diff --git a/paddle/fluid/imperative/tracer.h b/paddle/fluid/imperative/tracer.h index 664cb5ec1c9..f225d8abe6c 100644 --- a/paddle/fluid/imperative/tracer.h +++ b/paddle/fluid/imperative/tracer.h @@ -14,6 +14,7 @@ #pragma once +#include #include #include @@ -39,11 +40,10 @@ class Tracer { virtual ~Tracer() {} - void Trace( - OpBase* op, - const std::map>& inputs, // NOLINT - const std::map>& outputs, // NOLINT - framework::BlockDesc* block, const bool stop_gradient = false); + void Trace(OpBase* op, + const std::map>& inputs, + const std::map>& outputs, + framework::BlockDesc* block, const bool stop_gradient = false); std::vector PyTrace(OpBase* op, const std::vector& inputs, bool stop_gradient = false); diff --git a/paddle/fluid/operators/py_func_op.cc b/paddle/fluid/operators/py_func_op.cc index a6b1c738af1..53eff2de3e3 100644 --- a/paddle/fluid/operators/py_func_op.cc +++ b/paddle/fluid/operators/py_func_op.cc @@ -13,10 +13,10 @@ // limitations under the License. #include "paddle/fluid/operators/py_func_op.h" + #include #include #include -#include "Python.h" #include "paddle/fluid/framework/op_registry.h" namespace paddle { diff --git a/paddle/fluid/operators/py_func_op.h b/paddle/fluid/operators/py_func_op.h index 4ba06bf5985..5cebcd8dc0d 100644 --- a/paddle/fluid/operators/py_func_op.h +++ b/paddle/fluid/operators/py_func_op.h @@ -13,8 +13,7 @@ // limitations under the License. #pragma once - -#include "pybind11/pybind11.h" +#include "paddle/fluid/framework/python_headers.h" namespace paddle { namespace operators { -- GitLab