Commit a92ac340 authored by Vysheng's avatar Vysheng

many fixes. Autogenerated code probably works

parent 811df367
......@@ -7,3 +7,6 @@ config.log
config.status
.idea/
nbproject/
auto.c
auto-header.h
scheme.tlo
......@@ -4,40 +4,71 @@ CFLAGS=@CFLAGS@
LDFLAGS=@LDFLAGS@
CPPFLAGS=@CPPFLAGS@
DEFS=@DEFS@
COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb
COMPILE_FLAGS=${CFLAGS} ${CPPFLAGS} ${DEFS} -Wall -Wextra -Werror -Wno-deprecated-declarations -fno-strict-aliasing -fno-omit-frame-pointer -ggdb -Wno-unused-parameter
EXTRA_LIBS=@LIBS@ @EXTRA_LIBS@
LOCAL_LDFLAGS=-rdynamic -ggdb ${EXTRA_LIBS}
LINK_FLAGS=${LDFLAGS} ${LOCAL_LDFLAGS}
HEADERS= ${srcdir}/constants.h ${srcdir}/include.h ${srcdir}/interface.h ${srcdir}/LICENSE.h ${srcdir}/loop.h ${srcdir}/mtproto-client.h ${srcdir}/mtproto-common.h ${srcdir}/net.h ${srcdir}/no-preview.h ${srcdir}/queries.h ${srcdir}/structures.h ${srcdir}/telegram.h ${srcdir}/tree.h ${srcdir}/config.h ${srcdir}/binlog.h ${srcdir}/tools.h ${srcdir}/lua-tg.h
DEP=${srcdir}/dep
AUTO=${srcdir}/auto
EXE=${srcdir}/bin
OBJ=${srcdir}/objs
DIR_LIST=${DEP} ${AUTO} ${EXE} ${OBJ} ${DEP}/auto ${OBJ}/auto
EXE_LIST=${EXE}/generate ${EXE}/tlc ${EXE}/telegram-cli
TG_OBJECTS=${OBJ}/main.o ${OBJ}/loop.o ${OBJ}/interface.o ${OBJ}/net.o ${OBJ}/mtproto-common.o ${OBJ}/mtproto-client.o ${OBJ}/queries.o ${OBJ}/structures.o ${OBJ}/binlog.o ${OBJ}/lua-tg.o ${OBJ}/auto/auto.o
TLC_OBJECTS=${OBJ}/tlc.o ${OBJ}/tl-parser.o ${OBJ}/crc32.o
GENERATE_OBJECTS=${OBJ}/generate.o
COMMON_OBJECTS=${OBJ}/tools.o
OBJ_LIST=${TG_OBJECTS} ${TLC_OBJECTS} ${GENERATE_OBJECTS} ${COMMON_OBJECTS}
OBJ_C=${TLC_OBJECTS} ${GENERATE_OBJECTS} ${COMMON_OBJECTS}
DEPENDENCE_C=$(subst ${OBJ_C}/,${DEP}/,$(patsubst %.o,%.d,${OBJ_C}))
DEPENDENCE=$(subst ${OBJ_LIST}/,${DEP}/,$(patsubst %.o,%.d,${OBJ_LIST}))
DEPENDENCE_LIST=${DEPENDENCE_C} ${DEPENDENCE}
INCLUDE=-I. -I${srcdir}
CC=@CC@
OBJECTS=main.o loop.o interface.o net.o mtproto-common.o mtproto-client.o queries.o structures.o binlog.o tools.o lua-tg.o
TLC_OBJECTS=tlc.o tl-parser.o tools.o crc32.o
GENERATE_OBJECTS=generate.o tools.o
.SUFFIXES:
.SUFFIXES: .c .h .o
all: telegram tlc generate
all: ${EXE_LIST} ${DIR_LIST}
create_dirs_and_headers: ${DIR_LIST} ${AUTO}/auto.c ${AUTO}/auto-header.h
create_dirs: ${DIR_LIST}
${DIR_LIST}:
@test -d $@ || mkdir -p $@
-include ${DEPENDENCE_LIST}
${TG_OBJECTS}: ${OBJ}/%.o: %.c | create_dirs_and_headers
${CC} ${INCLUDE} ${COMPILE_FLAGS} -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<
${OBJ_C}: ${OBJ}/%.o: %.c | create_dirs
${CC} ${INCLUDE} ${COMPILE_FLAGS} -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<
${OBJECTS} ${TLC_OBJECTS}: ${HEADERS}
${EXE}/tlc: ${TLC_OBJECTS} ${COMMON_OBJECTS}
${CC} ${TLC_OBJECTS} ${COMMON_OBJECTS} ${LINK_FLAGS} -o $@
telegram: ${OBJECTS}
${CC} ${OBJECTS} ${LINK_FLAGS} -o $@
${EXE}/telegram-cli: ${TG_OBJECTS} ${COMMON_OBJECTS}
${CC} ${TG_OBJECTS} ${COMMON_OBJECTS} ${LINK_FLAGS} -o $@
tlc: ${TLC_OBJECTS}
${CC} ${TLC_OBJECTS} ${LINK_FLAGS} -o $@
${EXE}/generate: ${GENERATE_OBJECTS} ${COMMON_OBJECTS}
${CC} ${GENERATE_OBJECTS} ${COMMON_OBJECTS} ${LINK_FLAGS} -o $@
.c.o :
${CC} ${COMPILE_FLAGS} ${INCLUDE} -c $< -o $@
${AUTO}/scheme.tlo: ${srcdir}/scheme.tl ${EXE}/tlc
${EXE}/tlc -e $@ ${srcdir}/scheme.tl
tlc: ${GENERATE_OBJECTS}
${CC} ${GENERATE_OBJECTS} ${LINK_FLAGS} -o $@
${AUTO}/auto.c: ${AUTO}/scheme.tlo ${EXE}/generate
${EXE}/generate ${AUTO}/scheme.tlo > $@
${AUTO}/auto-header.h: ${AUTO}/scheme.tlo ${EXE}/generate
${EXE}/generate -H ${AUTO}/scheme.tlo > $@
clean:
rm -rf *.o telegram config.log config.status > /dev/null || echo "all clean"
rm -rf ${DIR_LIST} config.log config.status > /dev/null || echo "all clean"
......@@ -19,6 +19,6 @@ struct paramed_type {
#define INT2PTR(x) (void *)(long)(((long)x) * 2 + 1)
#define PTR2INT(x) ((((long)x) - 1) / 2)
#include "auto-header.h"
#include "auto/auto-header.h"
#endif
scheme12.tl
\ No newline at end of file
......@@ -37,6 +37,7 @@
#include "crc32.h"
#include "tl-tl.h"
#include "tools.h"
#include "config.h"
extern int verbosity;
extern int schema_version;
......@@ -1013,6 +1014,7 @@ struct tl_var *tl_get_var (char *_id, int len) {
return w;
}
}
tfree (id, len + 1);
return 0;
}
......@@ -1133,6 +1135,7 @@ struct tl_constructor *tl_add_constructor (struct tl_type *a, const char *_id, i
assert (magic && magic != (unsigned)-1);
}
len = x;
if (*id != '_') {
struct tl_constructor _t = {.id = id};
if (tree_lookup_tl_constructor (tl_constructor_tree, &_t)) {
......
......@@ -36,7 +36,7 @@
#include <signal.h>
#include "config.h"
#include <execinfo.h>
#include <stdarg.h>
int verbosity;
int output_expressions;
......@@ -62,6 +62,10 @@ int vkext_write (const char *filename) {
void logprintf (const char *format, ...) __attribute__ ((format (printf, 1, 2)));
void logprintf (const char *format __attribute__ ((unused)), ...) {
va_list ap;
va_start (ap, format);
vfprintf (stderr, format, ap);
va_end (ap);
}
void hexdump (int *in_ptr, int *in_end) {
......
......@@ -138,6 +138,8 @@ void *talloc (size_t size) {
*(int *)(p + RES_PRE + size) = size ^ 0x7bed7bed;
*(int *)(p + RES_AFTER + 4 + size) = used_blocks;
blocks[used_blocks ++] = p;
tcheck ();
return p + 8;
#else
void *p = malloc (size);
......@@ -227,9 +229,12 @@ void tcheck (void) {
for (i = 0; i < used_blocks; i++) {
void *ptr = blocks[i];
int size = (*(int *)ptr) ^ 0xbedabeda;
assert (*(int *)(ptr + 4) == size);
assert (*(int *)(ptr + RES_PRE + size) == (size ^ 0x7bed7bed));
assert (*(int *)(ptr + RES_PRE + 4 + size) == i);
if (!(*(int *)(ptr + 4) == size) ||
!(*(int *)(ptr + RES_PRE + size) == (size ^ 0x7bed7bed)) ||
!(*(int *)(ptr + RES_PRE + 4 + size) == i)) {
logprintf ("Bad block at address %p (size %d, num %d)\n", ptr, size, i);
assert (0 && "Bad block");
}
}
for (i = 0; i < free_blocks_cnt; i++) {
void *ptr = free_blocks[i];
......@@ -243,7 +248,7 @@ void tcheck (void) {
}
}
}
logprintf ("ok. Used_blocks = %d. Free blocks = %d\n", used_blocks, free_blocks_cnt);
//logprintf ("ok. Used_blocks = %d. Free blocks = %d\n", used_blocks, free_blocks_cnt);
}
void texists (void *ptr, int size) {
......
......@@ -21,8 +21,8 @@
#include <stdio.h>
#include <memory.h>
#include <tools.h>
#include <assert.h>
#include "tools.h"
#pragma pack(push,4)
#define DEFINE_TREE(X_NAME, X_TYPE, X_CMP, X_UNSET) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment