Browse Source

Merge branch 'new_makefile' into python_rpnifs5

Yann Weber 1 year ago
parent
commit
80a107f16a
4 changed files with 29 additions and 40 deletions
  1. 20
    37
      Makefile
  2. 4
    0
      rpn_if_default.c
  3. 4
    2
      rpn_jit.c
  4. 1
    1
      rpn_parse.c

+ 20
- 37
Makefile View File

@@ -19,44 +19,25 @@ PYTHON_CONFIG=$(PYTHON)-config
19 19
 PYTHON_CFLAGS=`$(PYTHON_CONFIG) --includes` `$(PYTHON_CONFIG) --cflags`
20 20
 PYTHON_LDFLAGS=-shared  -fPIC `$(PYTHON_CONFIG) --libs` `$(PYTHON_CONFIG) --ldflags|cut -d' ' -f1,2`
21 21
 
22
-all: .deps pyrpn.so
23
-
24
-pyrpn.so: python_pyrpn.o python_rpnexpr.o python_if.o python_const.o rpn_lib.o rpn_jit.o rpn_parse.o rpn_mutation.o rpn_if.o rpn_if_default.o rpn_ifs.o
25
-	$(LD) $(LDFLAGS) $(PYTHON_LDFLAGS) -o $@ $^
26
-
27
-python_pyrpn.o: python_pyrpn.c python_rpnexpr.h python_rpnexpr.o rpn_jit.o
28
-	$(CC) $(PYTHON_CFLAGS) $(CFLAGS) -c $<
29
-
30
-python_rpnexpr.o: python_rpnexpr.c python_rpnexpr.h rpn_jit.o
31
-	$(CC) $(PYTHON_CFLAGS) $(CFLAGS) -c $<
32
-
33
-python_if.o: python_if.c python_if.h
34
-	$(CC) $(PYTHON_CFLAGS) $(CFLAGS) -c $<
35
-
36
-python_const.o: python_const.c python_const.h
37
-	$(CC) $(PYTHON_CFLAGS) $(CFLAGS) -c $<
22
+C_SOURCES=$(wildcard *.c)
23
+C_OBJS=$(patsubst %.c,%.o,$(C_SOURCES))
24
+HEADERS=$(wildcard *.h)
25
+ASM_SOURCES=$(wildcard *.asm)
26
+ASM_OBJS=$(patsubst %.asm,%.o,$(ASM_SOURCES))
27
+OBJS=$(ASM_OBJS) $(C_OBJS)
28
+LIB=pyrpn.so
38 29
 
39
-rpn_jit.o: rpn_jit.c rpn_jit.h rpn_parse.o rpn_lib.o
40
-	$(CC) $(CFLAGS) -c $<
41
-
42
-rpn_parse.o: rpn_parse.c rpn_parse.h rpn_lib.o
43
-	$(CC) $(CFLAGS) -c $<
44
-
45
-rpn_mutation.o: rpn_mutation.c rpn_mutation.h rpn_parse.o
46
-	$(CC) $(CFLAGS) -c $<
47
-
48
-rpn_if.o: rpn_if.c rpn_if.h rpn_jit.o
49
-	$(CC) $(CFLAGS) -c $<
50
-
51
-rpn_if_default.o: rpn_if_default.c rpn_if_default.h rpn_if.o
52
-	$(CC) $(CFLAGS) -c $<
30
+all: .deps pyrpn.so
53 31
 
54
-rpn_ifs.o: rpn_ifs.c rpn_ifs.h rpn_if.o
55
-	$(CC) $(CFLAGS) -c $<
32
+$(C_OBJS): %.o: %.c $(HEADERS)
33
+	$(CC) $(PYTHON_CFLAGS) $(CFLAGS) -c -o $@ $<
56 34
 
57
-rpn_lib.o: rpn_lib.asm rpn_lib.h
35
+$(ASM_OBJS): %.o: %.asm $(HEADERS)
58 36
 	$(NASM) $(NASMCFLAGS) -o $@ $<
59 37
 
38
+$(LIB): $(OBJS)
39
+	$(LD) $(LDFLAGS) $(PYTHON_LDFLAGS) -o $@ $^
40
+
60 41
 # Doxygen documentation
61 42
 doc: doc/.doxygen.stamp
62 43
 
@@ -77,17 +58,19 @@ doc/.doxygen.stamp: $(wildcard *.c) $(wildcard *.h) Doxyfile
77 58
 
78 59
 checks: runtest unittest benchmark
79 60
 
80
-benchmark: pyrpn.so
81
-	PYTHONPATH=`pwd` $(PYTHON) tests/benchmark.py 0x200 0x3000
61
+benchmark: $(LIB)
62
+	PYTHONPATH=`pwd` $(PYTHON) tests/benchmark.py 0x500 0x2000;  \
63
+		PYTHONPATH=`pwd` $(PYTHON) tests/benchmark.py 0x500 0x4000;
64
+		   
82 65
 
83
-unittest: pyrpn.so
66
+unittest: $(LIB)
84 67
 	PYTHONPATH=`pwd` $(PYTHON) -m unittest -v -f
85 68
 
86 69
 runtest:
87 70
 	make -C tests
88 71
 
89 72
 clean:
90
-	-rm -fv *.o pyrpn.so test;\
73
+	-rm -fv $(OBJS) $(LIB) test;\
91 74
 	rm -fRv doc/.doxygen.stamp doc/* Doxyfile;\
92 75
 	make -C tests clean
93 76
 

+ 4
- 0
rpn_if_default.c View File

@@ -143,6 +143,8 @@ int rpn_if_getarg_default(rpn_if_t *rif, size_t pos)
143 143
 			rpn_if_argf_xdim(rif, pos, args);
144 144
 			cur_arg = *(data->size_lim);
145 145
 			break;
146
+		default:
147
+			return -1;
146 148
 	}
147 149
 	if(cur_arg > rif->params->rpn_argc)
148 150
 	{
@@ -205,6 +207,8 @@ int rpn_if_setres_default(rpn_if_t *rif, size_t *pos)
205 207
 			rpn_if_resf_xdim(rif, pos, res);
206 208
 			cur_arg = *(data->size_lim);
207 209
 			break;
210
+		default:
211
+			return -1;
208 212
 	}
209 213
 	if(cur_arg > rif->params->rpn_argc)
210 214
 	{

+ 4
- 2
rpn_jit.c View File

@@ -173,6 +173,8 @@ int rpn_expr_untokenize(rpn_expr_t *expr, rpn_tokenized_t *tokens, char long_op)
173 173
 
174 174
 char* rpn_random(size_t op_sz, size_t args_count)
175 175
 {
176
+	const int BUFF_ALLOC = 4096;
177
+
176 178
 	double step;
177 179
 	size_t i, buff_sz, offset, rnd;
178 180
 	char *buff, *cur;
@@ -195,9 +197,9 @@ char* rpn_random(size_t op_sz, size_t args_count)
195 197
 
196 198
 	for(i=0; i<op_sz; i++)
197 199
 	{
198
-		if(buff_sz - offset < 21)
200
+		if(buff_sz - offset < BUFF_ALLOC / 4)
199 201
 		{
200
-			buff_sz += 40;
202
+			buff_sz += BUFF_ALLOC;
201 203
 			cur = realloc(buff, sizeof(char) * buff_sz);
202 204
 			if(!cur)
203 205
 			{

+ 1
- 1
rpn_parse.c View File

@@ -244,7 +244,7 @@ char* rpn_tokenized_expr(rpn_tokenized_t *tokens, char long_op)
244 244
 	for(i=0; i<tokens->tokens_sz; i++)
245 245
 	{
246 246
 		token = &(tokens->tokens[i]);
247
-		if(cur - expr >= expr_sz - ALLOC_CHUNK)
247
+		if((size_t)(cur - expr) >= (expr_sz - ALLOC_CHUNK))
248 248
 		{
249 249
 			expr_sz += 128;
250 250
 			tmp = realloc(expr, sizeof(char) * expr_sz);

Loading…
Cancel
Save