summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-30 15:06:59 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-30 15:06:59 -0400
commit2b546944a1f0c5646936f2ab047345769e3a2471 (patch)
treed169d8d61e56c3f5bfc75ae0a505f8667ceedfe3
parent2edfa06a011307c9e3b8aa6b84c418cb70c0ec7c (diff)
downloaddimension-2b546944a1f0c5646936f2ab047345769e3a2471.tar.xz
python: Add simple global pool interface.
-rw-r--r--libdimension-python/Makefile.am6
-rw-r--r--libdimension-python/dimension.pxd10
-rw-r--r--libdimension-python/dimension.pyx18
3 files changed, 31 insertions, 3 deletions
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 <tavianator@tavianator.com> ##
+## Copyright (C) 2011-2014 Tavian Barnes <tavianator@tavianator.com> ##
## ##
## 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 #
###########