Skip to content

Commit

Permalink
Fix errors & reduce diff
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Švagelj <[email protected]>
  • Loading branch information
Caellian committed May 4, 2024
1 parent 6f43619 commit d467576
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 20 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ configure_file(${CMAKE_MODULE_PATH}/build.h.in ${CMAKE_BINARY_DIR}/build.h)
set(conky_sources ${CMAKE_BINARY_DIR}/config.h ${CMAKE_BINARY_DIR}/build.h)

# Finally, add some code
add_subdirectory(lua)
add_subdirectory(data)
add_subdirectory(doc)

Expand All @@ -67,8 +68,6 @@ endif()

add_subdirectory(src)

add_subdirectory(lua)

if(BUILD_TESTS)
add_subdirectory(tests)
enable_testing()
Expand Down
12 changes: 5 additions & 7 deletions lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ if(BUILD_LUA_IMLIB2)
add_library(conky-imlib2 MODULE ${luaimlib2_src})
set_target_properties(conky-imlib2 PROPERTIES OUTPUT_NAME "imlib2")

target_link_libraries(conky-imlib2 ${luaimlib2_libs} toluapp_lib_static )
target_link_libraries(conky-imlib2 ${luaimlib2_libs} toluapp_lib_static)
set(lua_libs ${lua_libs} conky-imlib2)

print_target_properties(conky-imlib2)
Expand All @@ -83,16 +83,14 @@ if(BUILD_LUA_CAIRO AND BUILD_LUA_IMLIB2)
${CMAKE_CURRENT_SOURCE_DIR})
wrap_tolua(luacairo_imlib2_helper_src cairo_imlib2_helper.pkg)

set(imlib_helper_libs ${luacairo_libs} ${luaimlib2_libs} toluapp_lib_static)
# if(BUILD_I18N)
# set(imlib_helper_libs ${imlib_helper_libs} -lintl)
# endif()

add_library(conky-cairo_imlib2_helper MODULE ${luacairo_imlib2_helper_src})
set_target_properties(conky-cairo_imlib2_helper
PROPERTIES OUTPUT_NAME "cairo_imlib2_helper")

target_link_libraries(conky-cairo_imlib2_helper ${imlib_helper_libs})
target_link_libraries(conky-cairo_imlib2_helper
${luacairo_libs}
${luaimlib2_libs}
toluapp_lib_static)
set(lua_libs ${lua_libs} conky-cairo_imlib2_helper)
endif(BUILD_LUA_CAIRO AND BUILD_LUA_IMLIB2)

Expand Down
7 changes: 5 additions & 2 deletions lua/libcairo_imlib2_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
#define gettext
#endif

#define NORM_ERR(Format, ...) \
fprintf(stderr, gettext(Format), ##__VA_ARGS__);
// TODO: inject reference to conky logger
// Lua allows modifying .so loading, so for each loaded library check if it has
// some hardcoded set_logger function symbol, and call it to set per-library
// reference to the global logger.
#define NORM_ERR(Format, ...) fprintf(stderr, gettext(Format), ##__VA_ARGS__);

void cairo_place_image(const char *file, cairo_t *cr, int x, int y, int width,
int height, double alpha) {
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ execute_process(

set(conky_sources
${conky_sources}
logging.cc
c++wrap.cc
c++wrap.hh
colour-settings.cc
Expand Down
5 changes: 1 addition & 4 deletions src/darwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@
#include <time.h>
#endif

/* debugging defines */
#undef NDEBUG

/* (E)nhanced printf */
#ifndef NDEBUG
#if true // ifdef NDEBUG
#include <cstdarg>
void eprintf(const char *fmt, ...) {
va_list args;
Expand Down
1 change: 1 addition & 0 deletions src/logger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <ctime>
#include <optional>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>

Expand Down
3 changes: 3 additions & 0 deletions src/logging.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "logging.h"

conky::log::logger DEFAULT_LOGGER("conky");
12 changes: 9 additions & 3 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#include "logger.hh"

#include <string>

class fork_throw : public std::runtime_error {
public:
fork_throw() : std::runtime_error("Fork happened") {}
Expand Down Expand Up @@ -92,9 +94,9 @@ namespace _priv_error_print {
template <typename... Args>
inline std::string alloc_printf(const char *format, Args &&...args) {
auto size = std::snprintf(nullptr, 0, format, args...);
std::string output(size + 1, '\0');
std::sprintf(&output[0], format, args...);
return output;
char output[size + 1];
std::snprintf(output, sizeof(output), format, args...);
return std::string(&output[0]);
}
inline std::string alloc_printf(const char *format) {
return std::string(format);
Expand All @@ -103,6 +105,10 @@ inline std::string alloc_printf(const char *format) {

class error : public std::runtime_error {
public:
/// @brief Construct a new error object.
///
/// @param Msg Already localized error message.
error(const std::string &msg) : std::runtime_error(msg) {}
error(const char *msg) : std::runtime_error(_(msg)) {}
template <typename... Args>
error(const char *format, Args &&...args)
Expand Down
2 changes: 0 additions & 2 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,6 @@ inline void reset_optind() {
#endif
}

conky::log::logger DEFAULT_LOGGER("conky");

int main(int argc, char **argv) {
std::set_terminate(&handle_terminate);

Expand Down

0 comments on commit d467576

Please sign in to comment.