Fix const correctness warnings
This commit is contained in:
parent
0d78599a57
commit
021c54308a
7 changed files with 28 additions and 27 deletions
|
@ -74,7 +74,7 @@ typedef struct st_r3_buffer_prototype_t r3_buffer_prototype_t;
|
||||||
* buffer structure compatible with iovec
|
* buffer structure compatible with iovec
|
||||||
*/
|
*/
|
||||||
typedef struct st_r3_iovec_t {
|
typedef struct st_r3_iovec_t {
|
||||||
char *base;
|
const char *base;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
} r3_iovec_t;
|
} r3_iovec_t;
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,11 @@ extern "C" {
|
||||||
|
|
||||||
char * r3_slug_compile(const char * str, unsigned int len);
|
char * r3_slug_compile(const char * str, unsigned int len);
|
||||||
|
|
||||||
char * r3_slug_find_pattern(const char *s1, unsigned int str_len, unsigned int *len);
|
const char * r3_slug_find_pattern(const char *s1, unsigned int str_len, unsigned int *len);
|
||||||
|
|
||||||
char * r3_slug_find_name(const char *s1, unsigned int str_len, unsigned int *len);
|
const char * r3_slug_find_name(const char *s1, unsigned int str_len, unsigned int *len);
|
||||||
|
|
||||||
char * r3_slug_find_placeholder(const char *s1, unsigned int str_len, unsigned int *len);
|
const char * r3_slug_find_placeholder(const char *s1, unsigned int str_len, unsigned int *len);
|
||||||
|
|
||||||
int r3_slug_count(const char * needle, int len, char **errstr);
|
int r3_slug_count(const char * needle, int len, char **errstr);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ bool str_array_slugs_full(const str_array * l);
|
||||||
|
|
||||||
// bool str_array_append_slug(str_array * l, char * slug);
|
// bool str_array_append_slug(str_array * l, char * slug);
|
||||||
|
|
||||||
bool str_array_append(str_array * l, char * token, unsigned int len);
|
bool str_array_append(str_array * l, const char * token, unsigned int len);
|
||||||
|
|
||||||
void str_array_free(str_array *l);
|
void str_array_free(str_array *l);
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ R3Node * r3_edge_branch(R3Edge *e, int dl) {
|
||||||
R3Edge * new_edge;
|
R3Edge * new_edge;
|
||||||
|
|
||||||
// the rest string
|
// the rest string
|
||||||
char * s1 = e->pattern.base + dl;
|
const char * s1 = e->pattern.base + dl;
|
||||||
int s1_len = e->pattern.len - dl;
|
int s1_len = e->pattern.len - dl;
|
||||||
|
|
||||||
// the suffix edge of the leaf
|
// the suffix edge of the leaf
|
||||||
|
|
16
src/node.c
16
src/node.c
|
@ -28,8 +28,8 @@
|
||||||
// String value as the index http://judy.sourceforge.net/doc/JudySL_3x.htm
|
// String value as the index http://judy.sourceforge.net/doc/JudySL_3x.htm
|
||||||
|
|
||||||
|
|
||||||
static int strndiff(char * d1, char * d2, unsigned int n) {
|
static int strndiff(const char * d1, const char * d2, unsigned int n) {
|
||||||
char * o = d1;
|
const char * o = d1;
|
||||||
while ( *d1 == *d2 && n-- > 0 ) {
|
while ( *d1 == *d2 && n-- > 0 ) {
|
||||||
d1++;
|
d1++;
|
||||||
d2++;
|
d2++;
|
||||||
|
@ -505,7 +505,7 @@ void r3_route_free(R3Route * route) {
|
||||||
// return route->slugs != NULL;
|
// return route->slugs != NULL;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
static r3_iovec_t* router_append_slug(R3Route * route, char * slug, unsigned int len) {
|
static r3_iovec_t* router_append_slug(R3Route * route, const char * slug, unsigned int len) {
|
||||||
r3_iovec_t *temp;
|
r3_iovec_t *temp;
|
||||||
r3_vector_reserve(NULL, &route->slugs, route->slugs.size + 1);
|
r3_vector_reserve(NULL, &route->slugs, route->slugs.size + 1);
|
||||||
temp = route->slugs.entries + route->slugs.size++;
|
temp = route->slugs.entries + route->slugs.size++;
|
||||||
|
@ -515,10 +515,10 @@ static r3_iovec_t* router_append_slug(R3Route * route, char * slug, unsigned int
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_slugs(R3Route * route, const char * path, int path_len) {
|
static void get_slugs(R3Route * route, const char * path, int path_len) {
|
||||||
char *plh = (char*)path;
|
const char *plh = path;
|
||||||
unsigned int l, namel;
|
unsigned int l, namel;
|
||||||
l = 0;
|
l = 0;
|
||||||
char *name;
|
const char *name;
|
||||||
while (plh < (path + path_len)) {
|
while (plh < (path + path_len)) {
|
||||||
plh = r3_slug_find_placeholder(plh+l, path_len, &l);
|
plh = r3_slug_find_placeholder(plh+l, path_len, &l);
|
||||||
if (!plh) break;
|
if (!plh) break;
|
||||||
|
@ -681,7 +681,7 @@ R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, unsigned int pa
|
||||||
info("slug_cnt: %d\n",slug_cnt);
|
info("slug_cnt: %d\n",slug_cnt);
|
||||||
if ( slug_cnt > 1 ) {
|
if ( slug_cnt > 1 ) {
|
||||||
unsigned int slug_len;
|
unsigned int slug_len;
|
||||||
char *p = r3_slug_find_placeholder(path, path_len, &slug_len);
|
const char *p = r3_slug_find_placeholder(path, path_len, &slug_len);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
assert(p);
|
assert(p);
|
||||||
|
@ -707,9 +707,9 @@ R3Node * r3_tree_insert_pathl_ex(R3Node *tree, const char *path, unsigned int pa
|
||||||
if (slug_cnt == 1) {
|
if (slug_cnt == 1) {
|
||||||
// there is one slug, let's see if it's optimiz-able by opcode
|
// there is one slug, let's see if it's optimiz-able by opcode
|
||||||
unsigned int slug_len = 0;
|
unsigned int slug_len = 0;
|
||||||
char *slug_p = r3_slug_find_placeholder(path, path_len, &slug_len);
|
const char *slug_p = r3_slug_find_placeholder(path, path_len, &slug_len);
|
||||||
unsigned int slug_pattern_len = 0;
|
unsigned int slug_pattern_len = 0;
|
||||||
char *slug_pattern = r3_slug_find_pattern(slug_p, slug_len, &slug_pattern_len);
|
const char *slug_pattern = r3_slug_find_pattern(slug_p, slug_len, &slug_pattern_len);
|
||||||
|
|
||||||
int opcode = 0;
|
int opcode = 0;
|
||||||
// if there is a pattern defined.
|
// if there is a pattern defined.
|
||||||
|
|
25
src/str.c
25
src/str.c
|
@ -15,7 +15,7 @@
|
||||||
#include "slug.h"
|
#include "slug.h"
|
||||||
#include "zmalloc.h"
|
#include "zmalloc.h"
|
||||||
|
|
||||||
static char * strnchr(const char* str, unsigned int len, int ch) {
|
static const char * strnchr(const char* str, unsigned int len, int ch) {
|
||||||
for (unsigned int i = 0; i < len; i++) {
|
for (unsigned int i = 0; i < len; i++) {
|
||||||
if (str[i] == ch) return str + i;
|
if (str[i] == ch) return str + i;
|
||||||
}
|
}
|
||||||
|
@ -86,9 +86,9 @@ char * r3_inside_slug(const char * needle, int needle_len, char *offset, char **
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * r3_slug_find_placeholder(const char *s1, unsigned int str_len, unsigned int *len) {
|
const char * r3_slug_find_placeholder(const char *s1, unsigned int str_len, unsigned int *len) {
|
||||||
char *c;
|
const char *c;
|
||||||
char *s2;
|
const char *s2;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
if (c = strnchr(s1, str_len, '{')) {
|
if (c = strnchr(s1, str_len, '{')) {
|
||||||
// find closing '}'
|
// find closing '}'
|
||||||
|
@ -119,9 +119,9 @@ char * r3_slug_find_placeholder(const char *s1, unsigned int str_len, unsigned i
|
||||||
/**
|
/**
|
||||||
* given a slug string, duplicate the pattern string of the slug
|
* given a slug string, duplicate the pattern string of the slug
|
||||||
*/
|
*/
|
||||||
char * r3_slug_find_pattern(const char *s1, unsigned int str_len, unsigned int *len) {
|
const char * r3_slug_find_pattern(const char *s1, unsigned int str_len, unsigned int *len) {
|
||||||
char *c;
|
const char *c;
|
||||||
char *s2;
|
const char *s2;
|
||||||
unsigned int cnt = 1;
|
unsigned int cnt = 1;
|
||||||
if ( (c = strnchr(s1, str_len, ':')) ) {
|
if ( (c = strnchr(s1, str_len, ':')) ) {
|
||||||
c++;
|
c++;
|
||||||
|
@ -152,9 +152,9 @@ char * r3_slug_find_pattern(const char *s1, unsigned int str_len, unsigned int *
|
||||||
/**
|
/**
|
||||||
* given a slug string, duplicate the parameter name string of the slug
|
* given a slug string, duplicate the parameter name string of the slug
|
||||||
*/
|
*/
|
||||||
char * r3_slug_find_name(const char *s1, unsigned int str_len, unsigned int *len) {
|
const char * r3_slug_find_name(const char *s1, unsigned int str_len, unsigned int *len) {
|
||||||
char * c;
|
const char * c;
|
||||||
char * s2;
|
const char * s2;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
unsigned int plholder;
|
unsigned int plholder;
|
||||||
if (c = r3_slug_find_placeholder(s1, str_len, &plholder)) {
|
if (c = r3_slug_find_placeholder(s1, str_len, &plholder)) {
|
||||||
|
@ -177,8 +177,9 @@ char * r3_slug_find_name(const char *s1, unsigned int str_len, unsigned int *len
|
||||||
*/
|
*/
|
||||||
char * r3_slug_compile(const char * str, unsigned int len)
|
char * r3_slug_compile(const char * str, unsigned int len)
|
||||||
{
|
{
|
||||||
char *s1 = NULL, *o = NULL;
|
const char *s1 = NULL;
|
||||||
char *pat = NULL;
|
char *o = NULL;
|
||||||
|
const char *pat = NULL;
|
||||||
char sep = '/';
|
char sep = '/';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ void str_array_free(str_array *l) {
|
||||||
free(l->tokens.entries);
|
free(l->tokens.entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool str_array_append(str_array * l, char * token, unsigned int len) {
|
bool str_array_append(str_array * l, const char * token, unsigned int len) {
|
||||||
R3_VECTOR(r3_iovec_t) *tks = &l->tokens;
|
R3_VECTOR(r3_iovec_t) *tks = &l->tokens;
|
||||||
r3_vector_reserve(NULL, tks, tks->size + 1);
|
r3_vector_reserve(NULL, tks, tks->size + 1);
|
||||||
r3_iovec_t *temp = tks->entries + tks->size++;
|
r3_iovec_t *temp = tks->entries + tks->size++;
|
||||||
|
|
Loading…
Reference in a new issue