Skip to content

Commit

Permalink
feat: compiles (not links) on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
djpiper28 committed Feb 19, 2024
1 parent d93c212 commit 8835d90
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 27 deletions.
47 changes: 30 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,30 @@ add_definitions("-DMSE_PROJECT_VERSION=\"${CMAKE_PROJECT_VERSION}\"")
add_definitions("-DMSE_PROJECT_NAME=\"${CMAKE_PROJECT_NAME}\"")
add_definitions("-DMSE_BINARY_VERSION=1")

# __FILENAME__
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}")
add_definitions("-D__FILENAME__=(&__FILE__[SOURCE_PATH_SIZE])")
# Platform stuff
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
endif()

set(MAC_FLAGS "")
if(MACOSX)
add_definitions("-D__FILENAME__=__FILE__")
set(MAC_FLAGS "-Wno-strict-prototypes -Wno-deprecated-declarations -Wno-newline-eof -Wno-logical-not-parentheses")
else()
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}")
add_definitions("-D__FILENAME__=(&__FILE__[SOURCE_PATH_SIZE])")
endif()

if(NOT WIN32)
set(CMAKE_C_FLAGS "-Wpedantic -Werror -Wno-unused-parameter -g -Ofast")
set(LIBS)
if(WIN32)
set(ADDITIONAL_FLEX_FLAGS "--wincompat")
else()
set(ADDITIONAL_FLEX_FLAGS "")
set(LIBS ${LIBS} m)
set(CMAKE_C_FLAGS
"-Wpedantic -Werror -Wno-unused-parameter -Wno-unused-value ${MAC_FLAGS} -g -Ofast"
)
endif()

# Generated sources
Expand Down Expand Up @@ -88,22 +105,15 @@ set(ABSL_LIBS

add_subdirectory(./re2)

# Parser generators
find_package(BISON)
find_package(FLEX)

option(USE_JEMALLOC OFF)
set(LIBS jansson CURL::libcurl pthread ${ABSL_LIBS} re2)
set(LIBS ${LIBS} CURL::libcurl jansson pthread ${ABSL_LIBS} re2)
if(USE_JEMALLOC)
set(LIBS ${LIBS} jemalloc)
endif()

if(WIN32)
set(ADDITIONAL_FLEX_FLAGS "--wincompat")
else()
set(ADDITIONAL_FLEX_FLAGS "")
set(LIBS ${LIBS} m)
endif()
# Parser generators
find_package(BISON)
find_package(FLEX)

flex_target(
query_lexer mse/query_parser.l ${CMAKE_CURRENT_BINARY_DIR}/mse_query_lexer.c
Expand Down Expand Up @@ -231,6 +241,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake)

if(UNIX)
add_definitions(-D__UNIX)

# Setup docs
option(MSE_DOXYGEN OFF)
if(MSE_DOXYGEN)
Expand All @@ -239,6 +251,7 @@ if(UNIX)
"Generate documentation pages for ${REPO_URL}")
endif()

# Setup code coverage
include(CodeCoverage)

set(GCOVR_EXCLUDE "build/*" "tests/*" "mse/main.c")
Expand Down
22 changes: 15 additions & 7 deletions mse/query_parser.y
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%{
#pragma once
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
Expand All @@ -7,15 +8,22 @@
#include "mse/query_parser.h"
#include "mse_query_lexer.h"
#include "mse_query_parser.h"

#define MSE_PASER_FILE_NAME "mse/query_parser.y"

#undef ___FNANE
#define ___FNANE MSE_PASER_FILE_NAME

#undef lprintf
#define lprintf fprintf(LOG_STREAM, "(" ANSI_YELLOW "%s" ANSI_RESET \
":" ANSI_YELLOW "%d" ANSI_RESET ") \t", __FILE__, __LINE__ ),\
__lprintf
#define PARSE_ASSERT(x) if (!(x)) \
{ \
lprintf(LOG_ERROR, "Parse Error: Assertion failure, line " \
ANSI_RED "%d" ANSI_RESET " in " ANSI_RED "%s" ANSI_RESET "\n", \
__LINE__, ___FNANE); \
ANSI_RED "%d" ANSI_RESET " in " ANSI_RED \
MSE_PASER_FILE_NAME ANSI_RESET "\n", \
__LINE__); \
YYABORT; \
}

Expand All @@ -25,14 +33,15 @@ static void yyerror(mse_parser_status_t *__ret, const char *s)
{
lprintf(LOG_ERROR, "Parse error: %s\n", s);
}

extern int yywrap();

#define YY_DO_BEFORE_ACTION
#define YY_NEW_FILE
%}

%code requires {
#include "mse/query_parser.h"
}
%parse-param {mse_parser_status_t *ret}
%glr-parser
%define parse.error verbose

%right LT LT_INC GT GT_INC INCLUDES EQUALS
%right AND OR
Expand Down Expand Up @@ -229,7 +238,6 @@ input: query
| WHITESPACE query
| query WHITESPACE
| WHITESPACE query WHITESPACE
| %empty
;

op_operator : LT_INC { ret->parser_op_type = MSE_SET_GENERATOR_OP_LT_INC; }
Expand Down
5 changes: 2 additions & 3 deletions mse/thread_pool.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include "./thread_pool.h"
#include "../testing_h/testing.h"

#ifdef __WINDOWS
#include <windows.h>
#endif

#ifdef __unix
#ifdef __UNIX
#include <unistd.h>
#endif

Expand Down Expand Up @@ -183,7 +182,7 @@ int mse_init_pool(mse_thread_pool_t *p)
int cpus = sysinfo.dwNumberOfProcessors;
#endif

#ifdef __unix
#ifdef __UNIX
int cpus = sysconf(_SC_NPROCESSORS_ONLN);
#endif

Expand Down
2 changes: 2 additions & 0 deletions tests/test_re2.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ static int test_good_case()
ASSERT(mse_re_init(&re, "ma?s{2}ive\\scar."));
ASSERT(mse_re_matches(&re, "massive cars"));
mse_re_free(&re);
return 1;
}

static int test_bad_case()
{
mse_re_t re;
ASSERT(!mse_re_init(&re, "(ashdaskjdhasjkd"));
mse_re_free(&re);
return 1;
}

SUB_TEST(test_re2, {&test_good_case, "Test re2 good case"},
Expand Down

0 comments on commit 8835d90

Please sign in to comment.