From 2b546944a1f0c5646936f2ab047345769e3a2471 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 30 May 2014 15:06:59 -0400 Subject: python: Add simple global pool interface. --- libdimension-python/Makefile.am | 6 +++--- libdimension-python/dimension.pxd | 10 ++++++++++ libdimension-python/dimension.pyx | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) (limited to 'libdimension-python') diff --git a/libdimension-python/Makefile.am b/libdimension-python/Makefile.am index a4b28ad..629eb8b 100644 --- a/libdimension-python/Makefile.am +++ b/libdimension-python/Makefile.am @@ -1,5 +1,5 @@ ########################################################################### -## Copyright (C) 2011 Tavian Barnes ## +## Copyright (C) 2011-2014 Tavian Barnes ## ## ## ## This file is part of The Dimension Build Suite. ## ## ## @@ -25,9 +25,9 @@ AM_LDFLAGS = $(Python_LDFLAGS) dimension.c: dimension.pyx dimension.pxd if DEBUG - cython --line-directives dimension.pyx + cython --line-directives --cleanup 2 dimension.pyx else - cython dimension.pyx + cython --cleanup 2 dimension.pyx endif sed -i 's/initdimension/initwrapper/g' dimension.c sed -i 's/PyInit_dimension/PyInit_wrapper/g' dimension.c diff --git a/libdimension-python/dimension.pxd b/libdimension-python/dimension.pxd index fb02fbd..0d862ae 100644 --- a/libdimension-python/dimension.pxd +++ b/libdimension-python/dimension.pxd @@ -39,6 +39,16 @@ cdef extern from "../libdimension/dimension.h": double dmnsn_epsilon + ######### + # Pools # + ######### + + ctypedef struct dmnsn_pool + + dmnsn_pool *dmnsn_new_pool() + void *dmnsn_palloc(dmnsn_pool *pool, size_t size, dmnsn_callback_fn *callback) + void dmnsn_delete_pool(dmnsn_pool *pool) + ########## # Arrays # ########## diff --git a/libdimension-python/dimension.pyx b/libdimension-python/dimension.pyx index 98fc41d..24ec4bd 100644 --- a/libdimension-python/dimension.pyx +++ b/libdimension-python/dimension.pyx @@ -46,6 +46,24 @@ def terminal_width(): """Return the width of the terminal, if present.""" return dmnsn_terminal_width() +######### +# Pools # +######### + +cdef class _Pool: + cdef dmnsn_pool *_pool + + def __cinit__(self): + self._pool = dmnsn_new_pool() + + def __dealloc__(self): + dmnsn_delete_pool(self._pool) + +cdef _Pool _global_pool = _Pool() + +cdef dmnsn_pool *_get_pool(): + return _global_pool._pool + ########### # Futures # ########### -- cgit v1.2.3