diff --git a/cstore/py-datapackstore.h b/cstore/py-datapackstore.h --- a/cstore/py-datapackstore.h +++ b/cstore/py-datapackstore.h @@ -26,6 +26,7 @@ #include "cstore/key.h" #include "cstore/py-structs.h" #include "cstore/pythonutil.h" +#include "cstore/pythonkeyiterator.h" #include "cstore/uniondatapackstore.h" // --------- DatapackStore Implementation --------- @@ -109,35 +110,6 @@ } } -class PythonKeyIterator : public KeyIterator { - private: - PythonObj _input; - Key _current; - public: - PythonKeyIterator(PythonObj input) : - _input(input) {} - - Key *next() { - PyObject *item; - while ((item = PyIter_Next((PyObject*)_input)) != NULL) { - PythonObj itemObj = item; - - char *name; - Py_ssize_t namelen; - char *node; - Py_ssize_t nodelen; - if (!PyArg_ParseTuple(item, "s#s#", &name, &namelen, &node, &nodelen)) { - throw pyexception(); - } - - _current = Key(name, namelen, node, nodelen); - return &_current; - } - - return NULL; - } -}; - static PyObject *datapackstore_getmissing(py_datapackstore *self, PyObject *keys) { try { PythonObj result = PyList_New(0); diff --git a/cstore/pythonkeyiterator.h b/cstore/pythonkeyiterator.h new file mode 100644 --- /dev/null +++ b/cstore/pythonkeyiterator.h @@ -0,0 +1,44 @@ +// pythonkeyiterator.h - c++ implementation of python key iterator +// +// Copyright 2017 Facebook, Inc. +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. +// +// no-check-code + +#ifndef FBHGEXT_PYTHONKEYITERATOR_H +#define FBHGEXT_PYTHONKEYITERATOR_H + +#include "cstore/pythonutil.h" + +class PythonKeyIterator : public KeyIterator { + private: + PythonObj _input; + Key _current; + public: + PythonKeyIterator(PythonObj input) : + _input(input) {} + + Key *next() { + PyObject *item; + while ((item = PyIter_Next((PyObject*)_input)) != NULL) { + PythonObj itemObj = item; + + char *name; + Py_ssize_t namelen; + char *node; + Py_ssize_t nodelen; + if (!PyArg_ParseTuple(item, "s#s#", &name, &namelen, &node, &nodelen)) { + throw pyexception(); + } + + _current = Key(name, namelen, node, nodelen); + return &_current; + } + + return NULL; + } +}; + +#endif //FBHGEXT_PYTHONKEYITERATOR_H diff --git a/tests/test-check-code-hg.t b/tests/test-check-code-hg.t --- a/tests/test-check-code-hg.t +++ b/tests/test-check-code-hg.t @@ -72,6 +72,7 @@ Skipping cstore/py-datapackstore.h it has no-che?k-code (glob) Skipping cstore/py-structs.h it has no-che?k-code (glob) Skipping cstore/py-treemanifest.h it has no-che?k-code (glob) + Skipping cstore/pythonkeyiterator.h it has no-che?k-code (glob) Skipping cstore/pythonutil.cpp it has no-che?k-code (glob) Skipping cstore/pythonutil.h it has no-che?k-code (glob) Skipping cstore/store.h it has no-che?k-code (glob)