FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bigflow/bigflow_python/python_interpreter.h at master · himdd/bigflow · GitHub
himdd
bigflow
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
bigflow
/
bigflow_python
/
python_interpreter.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
117 lines (90 loc) · 3.93 KB
Breadcrumbs
bigflow
/
bigflow_python
/
python_interpreter.h
Copy path
File metadata and controls
executable file
·
117 lines (90 loc) · 3.93 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
**************************************************************************
*
* Copyright (c) 2015 Baidu, Inc. 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.
*
*************************************************************************
*/
//
Author: Wang Cong (wangcong09@baidu.com)
//
#
ifndef
BIGFLOW_PYTHON_PYTHON_INTERPRETER_H
#
define
BIGFLOW_PYTHON_PYTHON_INTERPRETER_H
#
include
<
cstdio
>
#
include
<
iostream
>
#
include
"
boost/python/object_fwd.hpp
"
#
include
"
boost/serialization/singleton.hpp
"
#
include
"
glog/logging.h
"
#
include
"
toft/base/singleton.h
"
#
include
"
toft/base/scoped_array.h
"
//
#include "flume/util/singleton.h"
namespace
baidu
{
namespace
bigflow
{
namespace
python
{
/*
A singleton that wraps CPython Interpreter.
*/
class
PythonInterpreter
:
public
toft
::SingletonBase<PythonInterpreter> {
friend
class
toft
::SingletonBase<PythonInterpreter>;
public:
PythonInterpreter
();
virtual
~PythonInterpreter
();
public:
typedef
void
(*ExceptionHandlerFunc)(
const
char
* file,
const
char
* function,
int
line_num);
typedef
void
(*ExceptionHandlerWithMsgFunc)(
const
std::string&,
const
char
* file,
const
char
* function,
int
line_num);
void
set_exception_handler
(ExceptionHandlerFunc handler);
const
void
handle_exception
(
const
char
* file,
const
char
* function,
int
line_num);
void
set_exception_handler_with_error_msg
(ExceptionHandlerWithMsgFunc handler_with_msg);
const
void
handle_exception_with_error_msg
(
const
std::string& err_msg,
const
char
* file,
const
char
* function,
int
line_num);
void
initialize_interpreter
();
bool
is_interpreter_initialized
();
void
finalize_interpreter
();
private:
void
set_python_home
();
void
__set_python_home
(
const
std::string& path);
void
apply_initialize_hooks
();
void
apply_finalize_hooks
();
void
apply
(
const
std::string& file_name);
private:
toft::scoped_array<
char
> _python_home_chars;
toft::scoped_array<
char
> _python_prog_chars;
toft::scoped_array<
char
> _python_path_chars;
ExceptionHandlerFunc _handler;
ExceptionHandlerWithMsgFunc _handler_with_error_msg;
};
}
//
namespace python
}
//
namespace bigflow
}
//
namespace baidu
namespace
boost
{
namespace
python
{
//
for gtest output
std::ostream&
operator
<<(std::ostream& out,
const
boost::python::object& obj);
}
//
namespace python
}
//
namespace boost
#
define
BIGFLOW_HANDLE_PYTHON_EXCEPTION
() \
PythonInterpreter::Instance
()->handle_exception(__FILE__, __PRETTY_FUNCTION__, __LINE__)
#
define
BIGFLOW_HANDLE_PYTHON_EXCEPTION_WITH_ERROR_MESSAGE
(
ERR_MSG
) \
PythonInterpreter::Instance
()->handle_exception_with_error_msg(
ERR_MSG
, __FILE__, __PRETTY_FUNCTION__, __LINE__)
#
define
BIGFLOW_PYTHON_RAISE_EXCEPTION
(
ERR_MSG
)
BIGFLOW_HANDLE_PYTHON_EXCEPTION_WITH_ERROR_MESSAGE
(
ERR_MSG
)
#
define
BIGFLOW_PYTHON_RAISE_EXCEPTION_IF
(
condition, msg
)
do
{ \
if
(condition) { \
std::string errmsg =
"
Condition [
"
+
std::string
(#condition) +
"
] return true, so raise exception
\n
"
+ msg; \
BIGFLOW_HANDLE_PYTHON_EXCEPTION_WITH_ERROR_MESSAGE
(errmsg); \
} \
}
while
(
0
)
#
endif
//
BIGFLOW_PYTHON_PYTHON_INTERPRETER_H
Back
|
FazBrowse Home
|
New Git URL