Skip to content

Commit

Permalink
Replace direct use of preprocessor symbol _WIN32 with defined(_WIN32) as
Browse files Browse the repository at this point in the history
_WIN32 is undefined on Unix which causes warnings with gcc's -Wundef.
Also prefer #if defined() to #ifdef.
  • Loading branch information
nyamatongwe committed Jan 13, 2023
1 parent d939cfb commit 557d750
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions access/LexillaAccess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <vector>
#include <set>

#if !_WIN32
#if !defined(_WIN32)
#include <dlfcn.h>
#else
#include <windows.h>
Expand All @@ -29,7 +29,7 @@

namespace {

#if _WIN32
#if defined(_WIN32)
typedef FARPROC Function;
typedef HMODULE Module;
constexpr const char *pathSeparator = "\\";
Expand All @@ -49,7 +49,7 @@ T FunctionPointer(Function function) noexcept {
return fp;
}

#if _WIN32
#if defined(_WIN32)

std::wstring WideStringFromUTF8(std::string_view sv) {
const int sLength = static_cast<int>(sv.length());
Expand Down Expand Up @@ -85,7 +85,7 @@ std::vector<std::string> lexers;
std::vector<std::string> libraryProperties;

Function FindSymbol(Module m, const char *symbol) noexcept {
#if _WIN32
#if defined(_WIN32)
return ::GetProcAddress(m, symbol);
#else
return dlsym(m, symbol);
Expand Down Expand Up @@ -149,7 +149,7 @@ bool Lexilla::Load(std::string_view sharedLibraryPaths) {
// No '.' in name so add extension
path.append(LEXILLA_EXTENSION);
}
#if _WIN32
#if defined(_WIN32)
// Convert from UTF-8 to wide characters
std::wstring wsPath = WideStringFromUTF8(path);
Module lexillaDL = ::LoadLibraryW(wsPath.c_str());
Expand Down Expand Up @@ -246,7 +246,7 @@ Scintilla::ILexer5 *Lexilla::MakeLexer(std::string_view languageName) {
if (pCreateLexerDefault) {
return pCreateLexerDefault(sLanguageName.c_str());
}
#ifdef LEXILLA_STATIC
#if defined(LEXILLA_STATIC)
Scintilla::ILexer5 *pLexer = CreateLexer(sLanguageName.c_str());
if (pLexer) {
return pLexer;
Expand Down
12 changes: 6 additions & 6 deletions examples/CheckLexilla/CheckLexilla.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@ GCC or Clang or as C++.

#include <stdio.h>

#if _WIN32
#if defined(_WIN32)
#include <windows.h>
#else
#include <dlfcn.h>
#endif

#ifdef __cplusplus
#if defined(__cplusplus)
#include "ILexer.h"
#endif

#include "Lexilla.h"

#ifdef __cplusplus
#if defined(__cplusplus)
using namespace Lexilla;
#endif

#if _WIN32
#if defined(_WIN32)
typedef FARPROC Function;
typedef HMODULE Module;
#else
Expand All @@ -64,7 +64,7 @@ typedef void *Module;
#endif

static Function FindSymbol(Module m, const char *symbol) {
#if _WIN32
#if defined(_WIN32)
return GetProcAddress(m, symbol);
#else
return dlsym(m, symbol);
Expand All @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) {
if (argc > 1) {
libPath = argv[1];
}
#if _WIN32
#if defined(_WIN32)
Module lexillaLibrary = LoadLibraryA(libPath);
#else
Module lexillaLibrary = dlopen(libPath, RTLD_LAZY);
Expand Down
2 changes: 1 addition & 1 deletion examples/SimpleLexer/SimpleLexer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class LexerSimple : public LexerBase {
}
};

#if _WIN32
#if defined(_WIN32)
#define EXPORT_FUNCTION __declspec(dllexport)
#define CALLING_CONVENTION __stdcall
#else
Expand Down
16 changes: 8 additions & 8 deletions include/Lexilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define LEXILLA_H

// Define the default Lexilla shared library name for each platform
#if _WIN32
#if defined(_WIN32)
#define LEXILLA_LIB "lexilla"
#define LEXILLA_EXTENSION ".dll"
#else
Expand All @@ -23,7 +23,7 @@
#endif

// On Win32 use the stdcall calling convention otherwise use the standard calling convention
#if _WIN32
#if defined(_WIN32)
#define LEXILLA_CALL __stdcall
#else
#define LEXILLA_CALL
Expand All @@ -41,7 +41,7 @@
#define DEPRECATE_DEFINITION
#endif

#ifdef __cplusplus
#if defined(__cplusplus)
// Must have already included ILexer.h to have Scintilla::ILexer5 defined.
using Scintilla::ILexer5;
#else
Expand All @@ -50,7 +50,7 @@ typedef void ILexer5;

typedef ILexer5 *(*LexerFactoryFunction)();

#ifdef __cplusplus
#if defined(__cplusplus)
namespace Lexilla {
#endif

Expand All @@ -63,7 +63,7 @@ typedef const char *(LEXILLA_CALL *GetLibraryPropertyNamesFn)();
typedef void(LEXILLA_CALL *SetLibraryPropertyFn)(const char *key, const char *value);
typedef const char *(LEXILLA_CALL *GetNameSpaceFn)();

#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

Expand All @@ -80,7 +80,7 @@ typedef const char *(LEXILLA_CALL *GetNameSpaceFn)();

// Static linking prototypes

#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#endif

Expand All @@ -93,11 +93,11 @@ const char * LEXILLA_CALL GetLibraryPropertyNames();
void LEXILLA_CALL SetLibraryProperty(const char *key, const char *value);
const char *LEXILLA_CALL GetNameSpace();

#ifdef __cplusplus
#if defined(__cplusplus)
}
#endif

#ifdef __cplusplus
#if defined(__cplusplus)
namespace Lexilla {
class LexerModule;
}
Expand Down
2 changes: 1 addition & 1 deletion lexlib/LexerModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ constexpr int Maximum(int a, int b) noexcept {
}

// Shut up annoying Visual C++ warnings:
#ifdef _MSC_VER
#if defined(_MSC_VER)
#pragma warning(disable: 4244 4456 4457)
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/Lexilla.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <vector>
#include <initializer_list>

#if _WIN32
#if defined(_WIN32)
#define EXPORT_FUNCTION __declspec(dllexport)
#define CALLING_CONVENTION __stdcall
#else
Expand Down
2 changes: 1 addition & 1 deletion test/TestDocument.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void TestDocument::Set(std::string_view sv) {
lineLevels.resize(lineStarts.size(), 0x400);
}

#if _MSC_VER
#if defined(_MSC_VER)
// IDocument interface does not specify noexcept so best to not add it to implementation
#pragma warning(disable: 26440)
#endif
Expand Down
2 changes: 1 addition & 1 deletion test/TestLexers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ int main() {
const std::filesystem::path baseDirectory = FindLexillaDirectory(std::filesystem::current_path());
if (!baseDirectory.empty()) {
const std::filesystem::path examplesDirectory = baseDirectory / "test" / "examples";
#ifdef LEXILLA_STATIC
#if defined(LEXILLA_STATIC)
success = AccessLexilla(examplesDirectory);
#else
const std::filesystem::path sharedLibrary = baseDirectory / "bin" / LEXILLA_LIB;
Expand Down

0 comments on commit 557d750

Please sign in to comment.