Skip to content

Commit

Permalink
test compile fail
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jun 2, 2014
1 parent fd1e5f7 commit 9441f97
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 47 deletions.
2 changes: 1 addition & 1 deletion include/r3.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ node * r3_tree_matchl(const node * n, const char * path, int path_len, match_ent

bool r3_node_has_slug_edges(const node *n);

edge * r3_edge_create(const char * pattern, int pattern_len, node * child);
edge * r3_edge_createl(const char * pattern, int pattern_len, node * child);

node * r3_edge_branch(edge *e, int dl);

Expand Down
4 changes: 2 additions & 2 deletions src/edge.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "slug.h"
#include "zmalloc.h"

edge * r3_edge_create(const char * pattern, int pattern_len, node * child) {
edge * r3_edge_createl(const char * pattern, int pattern_len, node * child) {
edge * e = (edge*) zmalloc( sizeof(edge) );
e->pattern = (char*) pattern;
e->pattern_len = pattern_len;
Expand Down Expand Up @@ -54,7 +54,7 @@ node * r3_edge_branch(edge *e, int dl) {
// the suffix edge of the leaf
new_child = r3_tree_create(3);
s1_len = e->pattern_len - dl;
e1 = r3_edge_create(zstrndup(s1, s1_len), s1_len, new_child);
e1 = r3_edge_createl(zstrndup(s1, s1_len), s1_len, new_child);

// Migrate the child edges to the new edge we just created.
for ( int i = 0 ; i < e->child->edge_len ; i++ ) {
Expand Down
31 changes: 9 additions & 22 deletions src/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ edge * r3_node_connectl(node * n, const char * pat, int len, int dupl, node *chi
if (dupl) {
pat = zstrndup(pat, len);
}
e = r3_edge_create(pat, len, child);
e = r3_edge_createl(pat, len, child);
CHECK_PTR(e);
r3_node_append_edge(n, e);
return e;
Expand Down Expand Up @@ -520,7 +520,7 @@ edge * r3_node_find_common_prefix(node *n, char *path, int path_len, int *prefix
slug = r3_slug_new(path, path_len);

do {
ret = r3_slug_parse(slug, path, path_len, path, NULL);
ret = r3_slug_parse(slug, path, path_len, offset, NULL);
// found slug
if (ret == 1) {
// inside slug, backtrace to the begin of the slug
Expand All @@ -529,13 +529,15 @@ edge * r3_node_find_common_prefix(node *n, char *path, int path_len, int *prefix
break;
} else if ( p < slug->begin ) {
break;
} else if ( p > slug->end && p < (path + path_len) ) {
offset = slug->end;
} else if ( p >= slug->end && p < (path + path_len) ) {
offset = slug->end + 1;
prefix = p - path;
continue;
// XXX: see if it's in another slug
} else {
break;
}
} else {
break;
}
} while(ret == 1);
}
Expand All @@ -558,25 +560,10 @@ node * r3_tree_insert_pathl_(node *tree, const char *path, int path_len, route *
// common edge
edge * e = NULL;


/* length of common prefix */
int prefix_len = 0;
for( int i = 0 ; i < n->edge_len ; i++ ) {
// ignore all edges with slug
prefix_len = strndiff( (char*) path, n->edges[i]->pattern, n->edges[i]->pattern_len);

// no common, consider insert a new edge
if ( prefix_len > 0 ) {
e = n->edges[i];
break;
}
}


// branch the edge at correct position (avoid broken slugs)
const char *slug_s;
if ( (slug_s = inside_slug(path, path_len, ((char*) path + prefix_len), NULL)) != NULL ) {
prefix_len = slug_s - path;
}
e = r3_node_find_common_prefix(tree, path, path_len, &prefix_len);

const char * subpath = path + prefix_len;
const int subpath_len = path_len - prefix_len;
Expand Down
7 changes: 3 additions & 4 deletions src/slug.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int r3_slug_parse(r3_slug_t *s, char *needle, int needle_len, char *offset, char
s->path = needle;
s->path_len = needle_len;

if (!offset) {
if (offset == NULL) {
offset = (char*) needle; // from the begining of the needle
}

Expand All @@ -90,7 +90,6 @@ int r3_slug_parse(r3_slug_t *s, char *needle, int needle_len, char *offset, char
char * p = offset;

while( (p-needle) < needle_len) {

// escape one character
if (*p == '\\' ) {
p++; p++;
Expand Down Expand Up @@ -133,13 +132,13 @@ int r3_slug_parse(r3_slug_t *s, char *needle, int needle_len, char *offset, char
p++;
};

if (state > 0) {
if (state != 0) {
if (errstr) {
asprintf(errstr, "Incomplete slug pattern. PATH (%d): '%s', OFFSET: %ld, STATE: %d", needle_len, needle, p - needle, state);
}
return -1;
}
// found slug
info("found slug\n");
return 1;
}

Expand Down
Loading

0 comments on commit 9441f97

Please sign in to comment.