Skip to content

Commit 3c8541b

Browse files
committed
init cython
1 parent 288e683 commit 3c8541b

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

cpyr3.c

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#error Do not use this file, it is the result of a failed Cython compilation.

cpyr3.pxd

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
cdef extern from "r3.h":
3+
ctypedef struct node:
4+
pass
5+
6+
ctypedef struct edge:
7+
pass
8+
9+
ctypedef struct match_entry:
10+
pass
11+
12+
node * r3_tree_create(int cap)
13+
void r3_tree_free(node * tree)
14+
node * r3_tree_insert_path(node *tree, const char *path, void * data)
15+
16+
int r3_tree_compile(node *n, char** errstr)
17+
node * r3_tree_match(const node * n, const char * path, match_entry * entry)
18+
19+
20+
21+

cpyr3.pyx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cimport cpyr3
2+
3+
cdef class R3Tree:
4+
cdef cpyr3.node* root
5+
def __cinit__(self, cap=10):
6+
self.root = cpyr3.r3_tree_create(cap)
7+
8+
cpdef insert_path(self, path, data):
9+
cpyr3.r3_tree_insert_path(self.root, path, <void*>data)
10+
11+
cpdef compile(self):
12+
cpyr3.r3_tree_compile(self.root, NULL)
13+
14+
cpdef match(self, path):
15+
m = cpyr3.r3_tree_match(self.root, path, NULL)
16+
17+
if m:
18+
return <object><void*>(m.data)
19+
20+
def __dealloc__(self):
21+
if self.root is not NULL:
22+
cpyr3.r3_tree_free(self.root)

setup_cython.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from distutils.core import setup
2+
from distutils.extension import Extension
3+
from Cython.Distutils import build_ext
4+
5+
import os
6+
fs = ['./r3/src/%s'%k for k in os.listdir('./r3/src') if k.endswith('.c') and 'gvc' not in k and 'json' not in k]
7+
8+
setup(
9+
cmdclass = {'build_ext': build_ext},
10+
ext_modules = [Extension(
11+
"pyr3",
12+
["cpyr3.pyx"] + fs + ['./r3/3rdparty/zmalloc.c'],
13+
libraries=["pcre"],
14+
include_dirs=['./r3/include', './r3', '/opt/local/include', './r3/3rdparty'],
15+
library_dirs=['/usr/local/lib', '/opt/local/lib'],
16+
extra_compile_args=['-std=c99'],
17+
extra_link_args=['-std=c99']
18+
)]
19+
)

0 commit comments

Comments
 (0)