File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -68,13 +68,16 @@ namespace pyjson
6868 }
6969 }
7070
71- inline nl::json to_json (const py::handle& obj, std::set<const PyObject*>& refs)
71+ inline void check_circular_ref (const py::handle& obj, std::set<const PyObject*>& refs)
7272 {
7373 auto insert_ret = refs.insert (obj.ptr ());
7474 if (!insert_ret.second ) {
7575 throw std::runtime_error (" Circular reference detected" );
7676 }
77+ }
7778
79+ inline nl::json to_json (const py::handle& obj, std::set<const PyObject*>& refs)
80+ {
7881 if (obj.ptr () == nullptr || obj.is_none ())
7982 {
8083 return nullptr ;
@@ -124,6 +127,7 @@ namespace pyjson
124127 }
125128 if (py::isinstance<py::tuple>(obj) || py::isinstance<py::list>(obj))
126129 {
130+ check_circular_ref (obj, refs);
127131 auto out = nl::json::array ();
128132 for (const py::handle value : obj)
129133 {
@@ -133,6 +137,7 @@ namespace pyjson
133137 }
134138 if (py::isinstance<py::dict>(obj))
135139 {
140+ check_circular_ref (obj, refs);
136141 auto out = nl::json::object ();
137142 for (const py::handle key : obj)
138143 {
You can’t perform that action at this time.
0 commit comments