From 387fb72ee084aca883b35d37d177958715bffab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sun, 22 Aug 2021 03:18:03 +0200 Subject: l and h get args, no logmem, embed css, php dep --- src/structs.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/structs.c') diff --git a/src/structs.c b/src/structs.c index dce460e..83d19b9 100644 --- a/src/structs.c +++ b/src/structs.c @@ -19,6 +19,8 @@ } while (0); #define SC_OPT_TYPE unsigned char #define SC_OPT_IMAGE (1 << 0) +#define SC_STR(x) #x +#ifdef SC_LOGMEM struct sc_logentry { unsigned char type; /* SC_LOG_ERROR, SC_LOG_WARNING, SC_LOG_INFO, SC_LOG_DEBUG */ size_t line; @@ -29,7 +31,7 @@ struct sc_logentry { }; int sc_logentry_free (struct sc_logentry * l); /* defined in log.c */ struct sc_logentry * sc_logentry_init (); /* defined in log.c */ - +#endif struct sc_result { struct sc_query * query; /* nofree - free from sc_cache */ char * url; /* yesfree - url of referer page when image searching */ @@ -90,38 +92,41 @@ int sc_query_free (struct sc_query * q) { struct sc_cache { SC_IN_STRUCT_ARRAY(struct sc_query, queries); /* yesfree */ pthread_rwlock_t * queries_lock; +#ifdef SC_LOGMEM SC_IN_STRUCT_ARRAY(struct sc_logentry, logentries); /* yesfree */ pthread_rwlock_t * logentries_lock; +#endif }; struct sc_cache * sc_cache_init() { +#define SC_CILI(name) do { name##_lock = malloc(sizeof(pthread_rwlock_t)); pthread_rwlock_init(name##_lock, NULL); } while (0) struct sc_cache * c = calloc(1, sizeof(struct sc_cache)); c->queries_sizeof = SC_ALLOC_CHUNK; - c->logentries_sizeof = SC_ALLOC_CHUNK; c->queries = calloc(c->queries_sizeof, sizeof(struct sc_query *)); +#ifdef SC_LOGMEM + c->logentries_sizeof = SC_ALLOC_CHUNK; c->logentries = calloc(c->logentries_sizeof, sizeof(struct sc_logentry *)); - for (size_t i = 0; i < c->logentries_sizeof; i++) { - /* c->queries[i] = sc_query_init(); */ /* queries are not inited for performance reasons, they are inited by query function */ - /* c->queries[i]->cache = c; */ + for (size_t i = 0; i < c->logentries_sizeof; i++) c->logentries[i] = sc_logentry_init(); - } -#define SC_CILI(name) do { name##_lock = malloc(sizeof(pthread_rwlock_t)); pthread_rwlock_init(name##_lock, NULL); } while (0) - SC_CILI(c->queries); SC_CILI(c->logentries); +#endif + SC_CILI(c->queries); return c; } int sc_cache_free(struct sc_cache * c) { + #define SC_CFLD(name) do { pthread_rwlock_destroy(name##_lock); free(name##_lock); } while(0) if (!c) return -1; - fprintf(stderr, "c->queries_sizeof = %lu\n", c->queries_sizeof); + fprintf(stderr, "c->queries_sizeof = %zu\n", c->queries_sizeof); for (size_t i = 0; i < c->queries_sizeof; i++) sc_query_free(c->queries[i]); free(c->queries); +#ifdef SC_LOGMEM for (size_t i = 0; i < c->logentries_sizeof; i++) sc_logentry_free(c->logentries[i]); + SC_CFLD(c->logentries); free(c->logentries); - #define SC_CFLD(name) do { pthread_rwlock_destroy(name##_lock); free(name##_lock); } while(0) +#endif SC_CFLD(c->queries); - SC_CFLD(c->logentries); free(c); return 1; } -- cgit v1.2.3