-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Enforce code deprecation and virtual methods #1629
Conversation
Ensure base virtual classes have virtual destructors Remove `virtual` from overriden destructors Remove empty overridden destructors Ensure consistent ordering of constructors/destructor in header
…ult to `nullptr` not `0`
@slaff As this PR deals with coding style changes I've gone further and updated all the core files to standardise comment headers and that #include guards are named correctly. It affects unrelated files though so I'll assume it's a separate PR; I can commit here if you want. |
As long as the |
|
Separate PR please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work! Only small indentation changes needed.
Sming/SmingCore/HardwarePWM.h
Outdated
@@ -64,8 +68,14 @@ class HardwarePWM | |||
* @param duty Value of duty cycle to set pin to | |||
* @param update Update PWM output | |||
* @retval bool True on success | |||
* @note This function is used to set the pwm duty cycle for a given pin. If parameter 'update' is false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, indent the next two lines with the one above.
Sming/Wiring/Printable.h
Outdated
class Printable | ||
{ | ||
public: | ||
virtual ~Printable() { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation needs fixing.
Sming/system/include/esp_systemapi.h
Outdated
@@ -32,6 +32,9 @@ | |||
*/ | |||
#define SMING_UNUSED __attribute__((unused)) | |||
|
|||
/* Flags a compiler warning when Sming framework methods, functions or types are changed */ | |||
#define __deprecated __attribute__((deprecated)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other definitions of attributes are uppercase. Can you make also this one to be __DEPRECATED or SMING_DEPRECATED ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like SMING_DEPRECATED, it's specific
@@ -121,9 +120,10 @@ class WebsocketConnection | |||
void* getUserData(); | |||
|
|||
// @deprecated | |||
bool operator==(const WebsocketConnection& rhs) const; | |||
bool operator==(const WebsocketConnection& rhs) const __deprecated; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@slaff You deprecated this method on 04/05/2017, and enforcing deprecation means there's a corresponding change in the HttpServer_WebSockets
sample and possibly user apps; Keep it deprecated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You deprecated this method on 04/05/2017, and enforc ....
Hm... cannot remember why. You can un-deprecate it if needed.
Rename `__deprecated` to `SMING_DEPRECATED` Fix indenting Tidy #includes for all files modified by this PR Revert include guard renaming (separate PR) Revert changes to files not related to deprecate/override (separate PR) Revert deprecation of `WebsocketConnection::operator==` Ensure `@deprecated` usage resides within doxygen comment Fix doxygen error and include SSL in output
@mikee47 Ready to merge? |
{ | ||
} | ||
}; | ||
|
||
class HttpBasicAuth : public AuthAdapter | ||
{ | ||
public: | ||
HttpBasicAuth(const String& username, const String& password); | ||
HttpBasicAuth(const String& username, const String& password) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikee47 You can initialize the variables in initialization list
@@ -47,9 +50,16 @@ class HttpBasicAuth : public AuthAdapter | |||
class HttpDigestAuth : public AuthAdapter | |||
{ | |||
public: | |||
HttpDigestAuth(const String& username, const String& password); | |||
HttpDigestAuth(const String& username, const String& password) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too: variables in initialization list
11ddb12
to
b18982a
Compare
@@ -56,7 +56,8 @@ class HttpRequest | |||
return new HttpRequest(*this); | |||
} | |||
|
|||
HttpRequest& operator=(const HttpRequest& rhs); | |||
/** @deprecated Please use `clone()` instead */ | |||
HttpRequest& operator=(const HttpRequest& rhs) SMING_DEPRECATED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copy operator provided is actually unsafe as it doesn't take copies of allocated member variables so I've marked it deprecated. I could go further and make it private, which would prevent applications building if it's used.
See also #1601 (comment). I think probably get rid of the warning in the code and document the copy constructor instead.
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could go further and make it private, which would prevent applications building if it's used.
For now deprecate it only.
I think probably get rid of the warning in the code and document the copy constructor instead.
Sounds good.
Remove code from copy operator
Just noticed there's a bunch of overrides missing. Will add those. |
@slaff I'm inclined to revert the last change relating to HttpRequest copy constructor, deal with it separately. It's a whole issue with copying HashMap objects. |
The build is failing: SmingCore/Network/Http/HttpRequest.cpp: In copy constructor 'HttpRequest::HttpRequest(const HttpRequest&)':
SmingCore/Network/Http/HttpRequest.cpp:19:93: error: use of deleted function 'HttpParams::HttpParams(const HttpParams&)'
ri), method(value.method), headers(value.headers), postParams(value.postParams)
^
In file included from SmingCore/Network/Http/HttpRequest.h:24:0,
from SmingCore/Network/Http/HttpRequest.cpp:13:
SmingCore/Network/Http/HttpParams.h:30:7: note: 'HttpParams::HttpParams(const HttpParams&)' is implicitly deleted because the default definition would be ill-formed:
class HttpParams : public HashMap<String, String>, public Printable
^
In file included from SmingCore/Network/Http/HttpHeaders.h:23:0,
from SmingCore/Network/Http/HttpResponse.h:18,
from SmingCore/Network/Http/HttpRequestAuth.h:16,
from SmingCore/Network/Http/HttpRequest.h:18,
from SmingCore/Network/Http/HttpRequest.cpp:13:
Wiring/WHashMap.h:321:5: error: 'HashMap<K, V>::HashMap(const HashMap<K, V>&) [with K = String; V = String]' is private
HashMap(const HashMap<K, V>& that);
^
In file included from SmingCore/Network/Http/HttpRequest.h:24:0,
from SmingCore/Network/Http/HttpRequest.cpp:13:
SmingCore/Network/Http/HttpParams.h:30:7: error: within this context
class HttpParams : public HashMap<String, String>, public Printable
^
make[3]: *** [out/build/SmingCore/Network/Http//HttpRequest.o] Error 1
make[3]: Leaving directory `/home/travis/build/SmingHub/Sming/Sming'
Yes, do it like this. This PR is already quite big. |
…- requires separate PR
Yes, and there shouldn't be any functional changes in this PR. (Well, intentionally anyway!) |
Coding style rules updated |
Thanks for the changes. I have read the new text and all looks very good to me. |
* Fix memory leaks in `HttpConnection` Change `waitingQueue` from un-owned `RequestQueue*` to `RequestQueue` Free request if queue is full in `send(HttpRequest*)` * Tidy up * Code out of header * Merge `HttpClientConnection` into `HttpConnection` * HttpConnection -> HttpClientConnection * HttpConnectionBase -> HttpConnection * Move `isActive()` from `HttpClientConnection` into `HttpConnection` - applicable to both server and client * Resolve `HttpClientConnection` methods temporarily un-deprecated in #1629 * Revise `HttpConnection` so it can be used with either client or server Move `response` member variable into `HttpConnection` as both client and server have this. Move `getResponse()` method from `HttpClientConnection` into `HttpConnection` Add virtual `getRequest()` method to HttpConnection Move applicable methods from `HttpClientConnection` into `HttpConnection` Note: `send(HttpRquest*)` made virtual in previous commit * Fix comments * Fix deprecated method calls * Don't initialise `userData` in `WebsocketConnection` constructor * Un-deprecate `WebsocketConnection::getActiveWebsockets()` and make `static`, returning `const WebsocketList` to prevent dangerous modifications. See #1469
SMING_DEPRECATED
attribute to ensure marked code not referenced within frameworkoverride
to all inherited virtual methodsvirtual
from overriden destructorsSome samples use deprecated methods. If no suitable alternative has yet been provided, those methods have been un-deprecated and noted in the method comment using
@todo
. The follow methods have been un-deprecated completely:Additional style changes:
nullptr
instead ofNULL
or0
where appropriate__forceinline
orinline
where there is no specific need#include <SmingCore/*>
to#include <*>
Closes #1620