Skip to content

Commit 430ca86

Browse files
committed
Add function cpp2py::to_string(PyObject *)
1 parent 9f0a880 commit 430ca86

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

c++/cpp2py/misc.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22
#include <vector>
3+
#include <string>
34
#include "./exceptions.hpp"
5+
#include "./pyref.hpp"
46
#include <time.h>
57

68
// silence warning on intel
@@ -11,6 +13,11 @@
1113

1214
namespace cpp2py {
1315

16+
inline std::string to_string(PyObject * ob){
17+
pyref py_str = PyObject_Str(ob);
18+
return PyUnicode_AsUTF8(py_str);
19+
}
20+
1421
inline char *get_current_time() { // helper function to print the time in the CATCH_AND_RETURN macro
1522
time_t rawtime;
1623
time(&rawtime);

0 commit comments

Comments
 (0)