Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Styleguide completely mishandles ifdefs containing functions. #222

Open
ThadHouse opened this issue Dec 19, 2021 · 0 comments
Open

Styleguide completely mishandles ifdefs containing functions. #222

ThadHouse opened this issue Dec 19, 2021 · 0 comments

Comments

@ThadHouse
Copy link
Member

ThadHouse commented Dec 19, 2021

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#include "camerasupport.h"

#ifdef _WIN32
#include "Windows.h"
#include "delayimp.h"
#endif

#ifdef _WIN32
static int CheckDelayException(int exception_value) {
  if (exception_value ==
          VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND) ||
      exception_value ==
          VcppException(ERROR_SEVERITY_ERROR, ERROR_PROC_NOT_FOUND)) {
    // This example just executes the handler.
    return EXCEPTION_EXECUTE_HANDLER;
  }
  // Don't attempt to handle other errors
  return EXCEPTION_CONTINUE_SEARCH;
}

static bool TryDelayLoadAllImports(LPCSTR szDll) {
  __try {
    HRESULT hr = __HrLoadAllImportsForDll(szDll);
    if (FAILED(hr)) {
      return false;
    }
  } __except (CheckDelayException(GetExceptionCode())) {
    return false;
  }
  return true;
}

namespace glass {
bool HasCameraSupport() {
  bool hasCameraSupport = false;

  hasCameraSupport = TryDelayLoadAllImports("MF.dll");
  if (hasCameraSupport) {
    hasCameraSupport = TryDelayLoadAllImports("MFPlat.dll");
  }
  if (hasCameraSupport) {
    hasCameraSupport = TryDelayLoadAllImports("MFReadWrite.dll");
  }
  return hasCameraSupport;
}
}  // namespace glass
#else
namespace glass {
bool HasCameraSupport() {
  return true;
}
}  // namespace glass
#endif

The format it attemts on this file is 100% incorrect, and breaks semantically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant