methodpool.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. #
  4. #
  5. # Copyright (C) 2006 Holger Hans Peter Freyther
  6. #
  7. # SPDX-License-Identifier: GPL-2.0-only
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License version 2 as
  11. # published by the Free Software Foundation.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. from bb.utils import better_compile, better_exec
  22. def insert_method(modulename, code, fn, lineno):
  23. """
  24. Add code of a module should be added. The methods
  25. will be simply added, no checking will be done
  26. """
  27. comp = better_compile(code, modulename, fn, lineno=lineno)
  28. better_exec(comp, None, code, fn)
  29. compilecache = {}
  30. def compile_cache(code):
  31. h = hash(code)
  32. if h in compilecache:
  33. return compilecache[h]
  34. return None
  35. def compile_cache_add(code, compileobj):
  36. h = hash(code)
  37. compilecache[h] = compileobj