-
Notifications
You must be signed in to change notification settings - Fork 23
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
Move to a class structure #121
base: master
Are you sure you want to change the base?
Conversation
@gocarlos I have no idea if the way that I have done things in this PR make any sense. Can you comment? |
@@ -27,21 +82,80 @@ typedef struct CounterSign1 COSE_CounterSign1; | |||
#define _countof(x) (sizeof(x) / sizeof(x[0])) | |||
#endif | |||
|
|||
typedef struct _COSE_KEY { | |||
#ifdef __cplusplus | |||
class COSE_KEY { |
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'd say that all internal source code is cpp, so no check needed, public headers should have either a C api or (better) both, modern cpp and ABI stable C api
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 did this rather than do the conversion on dumper from c to cpp. Otherwise I agree withyou
|
||
~COSE_KEY(); | ||
|
||
int AddRef() { return m_refCount += 1; } |
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.
why no using shared pointers? this has issues with multi threading, shared pointers solved this already
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 was not sure how I could use shared pointers. The problem is that we are returning the pointer to C code and then having it call back. I thought that the shared-pointer code was designed for only having the pointer in the class and not moving it back and forth.
static COSE_KEY *KeysRoot; | ||
|
||
public: | ||
COSE_KEY() |
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.
from the naming: I'd keep UPPERCASE_VARS
to macros
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.
Left some comments, i think that we should evtl. starting to put some classes and memory mngm inside those classes... doing this with those new operators seems to me in the long run not like improving the existing structure and not well maintanable
@@ -45,63 +45,53 @@ HCOSE_KEY COSE_KEY_FromCbor(cn_cbor *pcborKey, | |||
{ | |||
COSE_KEY *pkey = nullptr; | |||
|
|||
pkey = (COSE_KEY *)COSE_CALLOC(1, sizeof(COSE_KEY), context); | |||
|
|||
pkey = new (std::nothrow, context) COSE_KEY(); |
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 dont think thia is the way forward...
Better create something like a factory patter which returns a shared ptr.
KeysRoot = pkey; | ||
|
||
return (HCOSE_KEY)pkey; | ||
return reinterpret_cast<HCOSE_KEY>(pkey); |
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.
We should get rid of all those casts
Using classes will make it easier to figure out inheritance issues.