Skip to content

Commit

Permalink
Minor: Clear compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cqjjjzr committed Jul 5, 2022
1 parent ce6cf98 commit d662f59
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 106 deletions.
3 changes: 3 additions & 0 deletions obs-source-old.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#pragma once
#include <obs-source.h>

/**
* This is for compatibility.
*/
struct obs_source_info_old {
/* ----------------------------------------------------------------- */
/* Required implementation*/
Expand Down
4 changes: 2 additions & 2 deletions obs-streamlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "obs-source-old.h"

#include <filesystem>
#include <windows.h>
#include <Windows.h>

#include "python-streamlink.h"

Expand All @@ -13,7 +13,7 @@ MODULE_EXPORT const char *obs_module_description(void)
return "Streamlink Source";
}

extern "C" struct obs_source_info_old streamlink_source_info;
extern "C" obs_source_info_old streamlink_source_info;

bool obs_module_load(void)
{
Expand Down
20 changes: 11 additions & 9 deletions python-streamlink.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// ReSharper disable CppMemberFunctionMayBeConst

#include "python-streamlink.h"
#include <obs-module.h>

#include <windows.h>
#include <Windows.h>
namespace streamlink {
bool loaded = false;
bool loadingFailed = false;
Expand Down Expand Up @@ -103,13 +105,13 @@ namespace streamlink {
return *this;
}

Stream::Stream(PyObject* underlying) : PyObjectHolder(underlying)
Stream::Stream(PyObject* u) : PyObjectHolder(u)
{
}
Stream::Stream(Stream&& another) noexcept : PyObjectHolder(std::move(another))
{
}
ssize_t Stream::Read(unsigned char* buf, const ssize_t len)
int Stream::Read(unsigned char* buf, const int len)
{
auto iucallable = PyObject_GetAttrString(underlying, "read");
if (iucallable == nullptr)
Expand All @@ -131,7 +133,7 @@ namespace streamlink {
std::memcpy(buf, buf1, readLen);

if (readLen == 0) throw stream_ended();
return readLen;
return static_cast<int>(readLen);
}
void Stream::Close()
{
Expand All @@ -147,7 +149,7 @@ namespace streamlink {
if (result == nullptr)
throw call_failure(GetExceptionInfo().c_str());
}
StreamInfo::StreamInfo(std::string name, PyObject* underlying) : PyObjectHolder(underlying), name(std::move(name))
StreamInfo::StreamInfo(std::string name, PyObject* u) : PyObjectHolder(u), name(std::move(name))
{

}
Expand Down Expand Up @@ -202,15 +204,15 @@ streamlink::Session::Session()
}

namespace streamlink {
std::map<std::string, StreamInfo> Session::GetStreamsFromUrl(std::string url)
std::map<std::string, StreamInfo> Session::GetStreamsFromUrl(const std::string& url)
{
auto streamsCallable = PyObject_GetAttrString(underlying, static_cast<const char*>("streams"));
if (streamsCallable == nullptr) throw call_failure(GetExceptionInfo().c_str());
auto streamsCallableGuard = PyObjectHolder(streamsCallable, false);
if (!PyCallable_Check(streamsCallable)) throw invalid_underlying_object();

if (!loaded) throw not_loaded();
auto urlStrObj = PyUnicode_FromStringAndSize(url.c_str(), url.size());
auto urlStrObj = PyUnicode_FromStringAndSize(url.c_str(), static_cast<ssize_t>(url.size()));
auto urlStrObjGuard = PyObjectHolder(urlStrObj, false);
auto args = PyTuple_Pack(1, urlStrObj);
auto argsGuard = PyObjectHolder(args, false);
Expand Down Expand Up @@ -243,7 +245,7 @@ namespace streamlink {
void streamlink::Session::SetOption(std::string const& name, PyObject* value)
{
if (!loaded) throw not_loaded();
auto nameObj = PyUnicode_FromStringAndSize(name.c_str(), name.size());
auto nameObj = PyUnicode_FromStringAndSize(name.c_str(), static_cast<ssize_t>(name.size()));
auto nameObjGuard = PyObjectHolder(nameObj, false);

auto args = PyTuple_Pack(2, nameObj, value);
Expand All @@ -257,7 +259,7 @@ void streamlink::Session::SetOption(std::string const& name, PyObject* value)

void streamlink::Session::SetOptionString(std::string const& name, std::string const& value)
{
auto valueObj = PyUnicode_FromStringAndSize(value.c_str(), value.size());
auto valueObj = PyUnicode_FromStringAndSize(value.c_str(), static_cast<ssize_t>(value.size()));
auto valueObjGuard = PyObjectHolder(valueObj, false);
SetOption(name, valueObj);
}
Expand Down
25 changes: 11 additions & 14 deletions python-streamlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
#define STREAMLINK_DEBUG
#endif

#undef _DEBUG
#undef _DEBUG // NOLINT(clang-diagnostic-reserved-macro-identifier)
#include <Python.h>

#ifdef STREAMLINK_DEBUG
#define _DEBUG
#endif

#include <iostream>
#include <functional>
#include <utility>
#include <fstream>

#include <map>
namespace streamlink {
Expand Down Expand Up @@ -70,16 +67,16 @@ namespace streamlink {

call_failure() = default;

explicit call_failure(char const* _Message)
: exception(_Message)
explicit call_failure(char const* message)
: exception(message)
{ }

call_failure(char const* _Message, int i)
: exception(_Message, i)
call_failure(char const* message, int i)
: exception(message, i)
{ }

explicit call_failure(exception const& _Other)
: exception(_Other)
explicit call_failure(exception const& other)
: exception(other)
{ }
};
class invalid_underlying_object : public std::exception {};
Expand All @@ -88,12 +85,12 @@ namespace streamlink {
class Stream : public PyObjectHolder
{
public:
Stream(PyObject* underlying);
Stream(PyObject* u);

Stream(Stream&) = delete;
Stream(Stream&& another) noexcept;

ssize_t Read(unsigned char* buf, const ssize_t len);
int Read(unsigned char* buf, const int len);
void Close();

};
Expand All @@ -102,7 +99,7 @@ namespace streamlink {
{
public:
std::string name;
StreamInfo(std::string name, PyObject* underlying);
StreamInfo(std::string name, PyObject* u);
StreamInfo(StreamInfo&& another) noexcept;

PyObject* Open();
Expand All @@ -115,7 +112,7 @@ namespace streamlink {
public:
Session();

std::map<std::string, StreamInfo> GetStreamsFromUrl(std::string url);
std::map<std::string, StreamInfo> GetStreamsFromUrl(std::string const& url);

void SetOption(std::string const& name, PyObject* value);
void SetOptionString(std::string const& name, std::string const& value);
Expand Down
Loading

0 comments on commit d662f59

Please sign in to comment.