Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
464c4351
Commit
464c4351
authored
Jul 08, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
further eval() improvements
parent
5130212d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
11 deletions
+32
-11
.appveyor.yml
+0
-3
include/pybind11/eval.h
+27
-8
include/pybind11/pytypes.h
+5
-0
No files found.
.appveyor.yml
View file @
464c4351
...
@@ -23,7 +23,4 @@ build_script:
...
@@ -23,7 +23,4 @@ build_script:
-
cd c:\projects\pybind11
-
cd c:\projects\pybind11
-
cmake -G "%CMAKE_PLATFORM%" -DPYTHON_EXECUTABLE:FILEPATH=%PYTHON_DIR%/python.exe
-
cmake -G "%CMAKE_PLATFORM%" -DPYTHON_EXECUTABLE:FILEPATH=%PYTHON_DIR%/python.exe
-
set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
-
set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
-
cmake --build . --config %Configuration% -- /v:m /logger:%MSBuildLogger%
-
set PATH=%PYTHON_DIR%;%PATH%
-
python example/example18.py
-
cmake --build . --config %Configuration% --target check -- /v:m /logger:%MSBuildLogger%
-
cmake --build . --config %Configuration% --target check -- /v:m /logger:%MSBuildLogger%
include/pybind11/eval.h
View file @
464c4351
...
@@ -29,7 +29,7 @@ enum eval_mode {
...
@@ -29,7 +29,7 @@ enum eval_mode {
};
};
template
<
eval_mode
mode
=
eval_expr
>
template
<
eval_mode
mode
=
eval_expr
>
object
eval
(
const
std
::
string
&
st
r
,
object
global
=
object
(),
object
local
=
object
())
{
object
eval
(
str
exp
r
,
object
global
=
object
(),
object
local
=
object
())
{
if
(
!
global
)
{
if
(
!
global
)
{
global
=
object
(
PyEval_GetGlobals
(),
true
);
global
=
object
(
PyEval_GetGlobals
(),
true
);
if
(
!
global
)
if
(
!
global
)
...
@@ -38,6 +38,10 @@ object eval(const std::string& str, object global = object(), object local = obj
...
@@ -38,6 +38,10 @@ object eval(const std::string& str, object global = object(), object local = obj
if
(
!
local
)
if
(
!
local
)
local
=
global
;
local
=
global
;
/* PyRun_String does not accept a PyObject / encoding specifier,
this seems to be the only alternative */
std
::
string
buffer
=
"# -*- coding: utf-8 -*-
\n
"
+
(
std
::
string
)
expr
;
int
start
;
int
start
;
switch
(
mode
)
{
switch
(
mode
)
{
case
eval_expr
:
start
=
Py_eval_input
;
break
;
case
eval_expr
:
start
=
Py_eval_input
;
break
;
...
@@ -46,7 +50,7 @@ object eval(const std::string& str, object global = object(), object local = obj
...
@@ -46,7 +50,7 @@ object eval(const std::string& str, object global = object(), object local = obj
default
:
pybind11_fail
(
"invalid evaluation mode"
);
default
:
pybind11_fail
(
"invalid evaluation mode"
);
}
}
object
result
(
PyRun_String
(
st
r
.
c_str
(),
start
,
global
.
ptr
(),
local
.
ptr
()),
false
);
object
result
(
PyRun_String
(
buffe
r
.
c_str
(),
start
,
global
.
ptr
(),
local
.
ptr
()),
false
);
if
(
!
result
)
if
(
!
result
)
throw
error_already_set
();
throw
error_already_set
();
...
@@ -54,7 +58,7 @@ object eval(const std::string& str, object global = object(), object local = obj
...
@@ -54,7 +58,7 @@ object eval(const std::string& str, object global = object(), object local = obj
}
}
template
<
eval_mode
mode
=
eval_statements
>
template
<
eval_mode
mode
=
eval_statements
>
object
eval_file
(
const
std
::
string
&
fname
,
object
global
=
object
(),
object
local
=
object
())
{
object
eval_file
(
str
fname
,
object
global
=
object
(),
object
local
=
object
())
{
if
(
!
global
)
{
if
(
!
global
)
{
global
=
object
(
PyEval_GetGlobals
(),
true
);
global
=
object
(
PyEval_GetGlobals
(),
true
);
if
(
!
global
)
if
(
!
global
)
...
@@ -71,12 +75,27 @@ object eval_file(const std::string& fname, object global = object(), object loca
...
@@ -71,12 +75,27 @@ object eval_file(const std::string& fname, object global = object(), object loca
default
:
pybind11_fail
(
"invalid evaluation mode"
);
default
:
pybind11_fail
(
"invalid evaluation mode"
);
}
}
FILE
*
f
=
fopen
(
fname
.
c_str
(),
"r"
);
int
closeFile
=
1
;
if
(
!
f
)
std
::
string
fname_str
=
(
std
::
string
)
fname
;
pybind11_fail
(
"File
\"
"
+
fname
+
"
\"
could not be opened!"
);
#if PY_VERSION_HEX >= 0x03040000
FILE
*
f
=
_Py_fopen_obj
(
fname
.
ptr
(),
"r"
);
#elif PY_VERSION_HEX >= 0x03000000
FILE
*
f
=
_Py_fopen
(
fname
.
ptr
(),
"r"
);
#else
/* No unicode support in open() :( */
object
fobj
(
PyFile_FromString
(
fname_str
.
c_str
(),
const_cast
<
char
*>
(
"r"
)),
false
);
FILE
*
f
=
nullptr
;
if
(
fobj
)
f
=
PyFile_AsFile
(
fobj
.
ptr
());
closeFile
=
0
;
#endif
if
(
!
f
)
{
PyErr_Clear
();
pybind11_fail
(
"File
\"
"
+
fname_str
+
"
\"
could not be opened!"
);
}
object
result
(
PyRun_FileEx
(
f
,
fname
.
c_str
(),
Py_file_inpu
t
,
global
.
ptr
(),
object
result
(
PyRun_FileEx
(
f
,
fname
_str
.
c_str
(),
star
t
,
global
.
ptr
(),
local
.
ptr
(),
1
),
local
.
ptr
(),
closeFile
),
false
);
false
);
if
(
!
result
)
if
(
!
result
)
...
...
include/pybind11/pytypes.h
View file @
464c4351
...
@@ -343,6 +343,11 @@ public:
...
@@ -343,6 +343,11 @@ public:
if
(
!
m_ptr
)
pybind11_fail
(
"Could not allocate string object!"
);
if
(
!
m_ptr
)
pybind11_fail
(
"Could not allocate string object!"
);
}
}
str
(
const
char
*
c
)
:
object
(
PyUnicode_FromString
(
c
),
false
)
{
if
(
!
m_ptr
)
pybind11_fail
(
"Could not allocate string object!"
);
}
operator
std
::
string
()
const
{
operator
std
::
string
()
const
{
object
temp
=
*
this
;
object
temp
=
*
this
;
if
(
PyUnicode_Check
(
m_ptr
))
{
if
(
PyUnicode_Check
(
m_ptr
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment