<commit_before>// Floating Temple
// Copyright 2015 <NAME>
//
// 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.

#include "python/peer_module.h"

#include "third_party/Python-3.4.2/Include/Python.h"

#include "python/interpreter_impl.h"

namespace floating_temple {
namespace python {
namespace {

PyObject* peer_BeginTransaction(PyObject* self, PyObject* unused) {
  InterpreterImpl::instance()->BeginTransaction();
  Py_RETURN_NONE;
}

PyObject* peer_EndTransaction(PyObject* self, PyObject* unused) {
  InterpreterImpl::instance()->EndTransaction();
  Py_RETURN_NONE;
}

PyMethodDef g_module_methods[] = {
  { "begin_tran",
    peer_BeginTransaction,
    METH_NOARGS,
    "TODO(dss): Write this doc string."
  },
  { "end_tran",
    peer_EndTransaction,
    METH_NOARGS,
    "TODO(dss): Write this doc string."
  },
  { nullptr, nullptr, 0, nullptr }
};

PyModuleDef g_module_def = {
  PyModuleDef_HEAD_INIT,
  "peer",                               // m_name
  "TODO(dss): Write this doc string.",  // m_doc
  -1,                                   // m_size
  g_module_methods,                     // m_methods
  nullptr,                              // m_reload
  nullptr,                              // m_traverse
  nullptr,                              // m_clear
  nullptr                               // m_free
};

}  // namespace

PyMODINIT_FUNC PyInit_peer() {
  return PyModule_Create(&g_module_def);
}

}  // namespace python
}  // namespace floating_temple<commit_msg>Add a shared dictionary object named "shared" to the "peer" module in Floating Python.<commit_after>// Floating Temple
// Copyright 2015 <NAME>
//
// 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.

#include "python/peer_module.h"

#include "third_party/Python-3.4.2/Include/Python.h"

#include <string>

#include "base/logging.h"
#include "python/dict_local_object.h"
#include "python/interpreter_impl.h"

namespace floating_temple {

class PeerObject;

namespace python {
namespace {

PyObject* peer_BeginTransaction(PyObject* self, PyObject* unused) {
  InterpreterImpl::instance()->BeginTransaction();
  Py_RETURN_NONE;
}

PyObject* peer_EndTransaction(PyObject* self, PyObject* unused) {
  InterpreterImpl::instance()->EndTransaction();
  Py_RETURN_NONE;
}

PyMethodDef g_module_methods[] = {
  { "begin_tran",
    peer_BeginTransaction,
    METH_NOARGS,
    "TODO(dss): Write this doc string."
  },
  { "end_tran",
    peer_EndTransaction,
    METH_NOARGS,
    "TODO(dss): Write this doc string."
  },
  { nullptr, nullptr, 0, nullptr }
};

PyModuleDef g_module_def = {
  PyModuleDef_HEAD_INIT,
  "peer",                               // m_name
  "TODO(dss): Write this doc string.",  // m_doc
  -1,                                   // m_size
  g_module_methods,                     // m_methods
  nullptr,                              // m_reload
  nullptr,                              // m_traverse
  nullptr,                              // m_clear
  nullptr                               // m_free
};

}  // namespace

PyMODINIT_FUNC PyInit_peer() {
  InterpreterImpl* const interpreter = InterpreterImpl::instance();

  PyObject* const py_module = PyModule_Create(&g_module_def);
  CHECK(py_module != nullptr);

  PyObject* const py_dict = PyDict_New();
  CHECK(py_dict != nullptr);
  PeerObject* const dict_peer_object =
      interpreter->CreateNamedPeerObject<DictLocalObject>("shared", py_dict);
  PyObject* const py_dict_proxy_object = interpreter->PeerObjectToPyProxyObject(
      dict_peer_object);
  CHECK_EQ(PyModule_AddObject(py_module, "shared", py_dict_proxy_object), 0);

  return py_module;
}

}  // namespace python
}  // namespace floating_temple
{'fraction_non_alphanumeric': 0.1052067709449325, 'fraction_numerical': 0.005785301049925006, 'mean_word_length': 2.758454106280193, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4784868', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1382, 'n_words': 376}