Skip to content
This repository has been archived by the owner on Feb 16, 2025. It is now read-only.

Remove error code generation #2976

Merged
merged 41 commits into from Nov 8, 2019
Merged

Remove error code generation #2976

merged 41 commits into from Nov 8, 2019

Conversation

ghost
Copy link

@ghost ghost commented Sep 18, 2019

Basics

Check relevant points but please do not remove entries.
Do not describe the purpose of this PR in the PR description but:

  • Short descriptions should be in the release notes (added as entry in
    doc/news/_preparation_next_release.md which contains _(my name)_)
    Please always add something to the the release notes.
  • Longer descriptions should be in documentation or in design decisions.
  • Describe details of how you changed the code in commit messages
    (first line should have module: short statement syntax)
  • References to issues, e.g. close #X, should be in the commit messages.

Checklist

Check relevant points but please do not remove entries.
For docu fixes, spell checking, and similar none of these points below
need to be checked.

  • I added unit tests for my code
  • I fixed all affected documentation
  • I added code comments, logging, and assertions as appropriate (see Coding Guidelines)
  • I updated all meta data (e.g. README.md of plugins and METADATA.ini)
  • I mentioned every code not directly written by me in THIRD-PARTY-LICENSES

Review

Reviewers will usually check the following:

Labels

  • Add the "work in progress" label if you do not want the PR to be reviewed yet.
  • Add the "ready to merge" label if the build server is happy and also you
    say that everything is ready to be merged.

@ghost ghost added the work in progress label Sep 18, 2019
@ghost
Copy link
Author

ghost commented Sep 18, 2019

@kodebach @markus2330 Can you please help me with the Cmake fixing? I try to remove the code generation but I cannot fix the Cmake dependencies correctly (without probably severe time investment)

Currently I receive the following error message:

In file included from /home/michiz/UniRepos/elektra/src/include/kdbprivate.h:12:0,
                 from /home/michiz/UniRepos/elektra/src/libs/elektra/global.c:10:
/home/michiz/UniRepos/elektra/src/include/elektra.h:13:10: fatal error: elektra/errors.h: No such file or directory
 #include <elektra/errors.h>
          ^~~~~~~~~~~~~~~~~~

@kodebach
Copy link
Member

AFAIK the stuff that is generated from specification_highlevel (including elektra/errors.h) is not used anywhere and can be removed completely.

@kodebach
Copy link
Member

Similarly elektra/errorcodes.h (those codes shouldn't be used, we decided to use the same codes everywhere) and elektra/errorsprivate.h (already part of kdbprivate.h) should be removed.

@@ -170,6 +170,7 @@ install (FILES kdbextension.h
"${CMAKE_CURRENT_BINARY_DIR}/kdbtypes.h"
kdbhelper.h
"${CMAKE_CURRENT_BINARY_DIR}/kdb.h"
"${CMAKE_CURRENT_BINARY_DIR}/kdberrors.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kdberrors.h should not be installed, it shouldn't be used outside of Elektra. Why did you add it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it. I was not aware that this should not be installed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kodebach are you sure about that? The file might be helpful for out-of-source-tree development of plugins. As this is currently not a priority, I think it is a good thing to not install any private files.

If we install private files, we should install in a subdirectory (private).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old version of kdberrors.h wasn't suitable for installation IMO. The new version could be installed, but we should first decide, whether or not we want to remove the F variants of the macros (see #2490 (comment)).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see how the new header file looks like.

@@ -190,7 +191,7 @@ install (FILES kdbextension.h

add_custom_target (elektra_config_headers ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/kdb.h ${CMAKE_CURRENT_BINARY_DIR}/kdbconfig.h
${CMAKE_CURRENT_BINARY_DIR}/kdbversion.h)
${CMAKE_CURRENT_BINARY_DIR}/kdbversion.h ${CMAKE_CURRENT_BINARY_DIR}/kdberrors.h)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, what this custom target is, but I'm pretty sure kdberrors.h shouldn't be in here. Even if it was included, the ${CMAKE_CURRENT_BINARY_DIR}/ part is wrong, since that is not where the header is located anymore.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it

@markus2330
Copy link
Contributor

There is some formatting problem in "function (add_lib name)". which makes the PR hard to read.

The error message is very clear, it cannot find elektra/errors.h. This most likely has nothing to do with CMake as no deps are needed for non-generated header files.

#include <string.h>

#ifdef __cplusplus
using namespace ckdb;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markus2330 I just saw this line... We really should remove that, using directives in headers are very much not good practice. I suspect however, some files already rely on this line being here, so this could be a rather big change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this definitely need to be removed. Thanks for the hint. I did not look so far into the PR.

I think also some other things will come up as kdberrors.h will be much easier to read in the non-generated way.

@kodebach
Copy link
Member

The error message is very clear, it cannot find elektra/errors.h. This most likely has nothing to do with CMake as no deps are needed for non-generated header files.

No part of the header is actually used anywhere, so the #includes as well as the file itself, can be removed. All elektraError* functions for creating errors are manually implemented in elektra_error.c and declared either in elektra/error.h or kdbprivate.h. It has been this way, since we switched to the new error codes.

@ghost
Copy link
Author

ghost commented Sep 19, 2019

There is some formatting problem in "function (add_lib name)". which makes the PR hard to read.

I upgraded my cmake-format. It should be easier to read now.

@kodebach was so kind and sent me his version of refactoring from the generation which he had done a time ago. Big thanks!
Unfortunately I now run into the following problem which is very confusing as I have not touched anything there:

.../libelektra/src/plugins/ccode/ccode.cpp: In function ‘KeySet* {anonymous}::contract()’:
.../libelektra/src/plugins/ccode/ccode.cpp:30:116: error: ‘keyNew’ was not declared in this scope
  return ksNew (30, keyNew ("system/elektra/modules/ccode", KEY_VALUE, "ccode plugin waits for your orders", KEY_END),
                                                                                                                    ^
.../libelektra/src/plugins/ccode/ccode.cpp:30:116: note: suggested alternative:
In file included from .../libelektra/src/include/kdbplugin.h:12:0,
                 from .../libelektra/src/plugins/ccode/ccode.hpp:12,
                 from .../libelektra/src/plugins/ccode/ccode.cpp:9:
.../libelektra/build/src/include/kdb.h:140:6: note:   ‘ckdb::keyNew’
 Key *keyNew(const char *keyname, ...);

Do you have a clue there?

@kodebach
Copy link
Member

Do you have a clue there?

Ah, that is probably what happens, when we remove using namespace ckdb from kdberrors.h...
Basically, there will be a few files that (maybe unknowingly) relied on the fact that kdberrors.h imports the ckdb namespace.

gcc actually tells you the solution already:

[...] note: suggested alternative:
[...]
[...] note:   ‘ckdb::keyNew’

But for .cpp files it should be possible to add using namespace ckdb; to the top of the file. That is probably easier than adding ckdb:: in all the places.

For headers, we shouldn't do that (same reason why kdberror.h shouldn't contain the line). Most likely you just need to replace Key with ckdb::Key (or KeySet with ckdb::KeySet) in a declarations. If there are any headers that cause more complicated problems, I'll need more specific infos.

@ghost
Copy link
Author

ghost commented Sep 20, 2019

It looks like I could fix most of those problems on my own with your help (thank you!) but now ran into a problem concerning the highlevel files:

make[2]: *** No rule to make target 'src/error/elektra_errors.c', needed by 'src/libs/highlevel/CMakeFiles/elektra-highlevel-objects.dir/__/__/error/elektra_errors.c.o'.  Stop.
CMakeFiles/Makefile2:16577: recipe for target 'src/libs/highlevel/CMakeFiles/elektra-highlevel-objects.dir/all' failed
make[1]: *** [src/libs/highlevel/CMakeFiles/elektra-highlevel-objects.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2

@kodebach
Copy link
Member

These lines should be remove:

set_source_files_properties (${PROJECT_BINARY_DIR}/src/error/elektra_errors.c
PROPERTIES
GENERATED
ON)

${PROJECT_BINARY_DIR}/src/error/elektra_errors.c

@ghost
Copy link
Author

ghost commented Sep 28, 2019

@kodebach I receive some warnings in the jenkins build which I think causes it to fail:

error: argument to ‘sizeof’ in ‘strncpy’ call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]

  strncpy (bufferEnd, "/module", sizeof ("/module"));

do I need to change this to
strncpy (bufferEnd, "/module", buffer);?
At least this is what I have seen in similar PRs from other projects

@ghost
Copy link
Author

ghost commented Oct 1, 2019

@markus2330 did I understand strncpy correctly in the upper comment? I am rarely that unsure about fixing something but since @kodebach is that proficient in C I assume a fix from me on his code is more likely another bug than a fix.

@kodebach
Copy link
Member

kodebach commented Oct 1, 2019

Sorry, i missed this.

do I need to change this to
strncpy (bufferEnd, "/module", buffer);

That won't work, buffer is a pointer not a size.

I always found this GCC warning somewhat annoying. It warns you about perfectly correct code...
The easiest solution is to just use strcpy instead of strncpy. It should be safe in this case. I think you can also replace the sizeof(...)s with integers, i.e. replace sizeof("/module") with 8 etc.

@ghost
Copy link
Author

ghost commented Oct 2, 2019

Thank you for your help!

i.e. replace sizeof("/module") with 8 etc.

why 8 and not 7? is it for /0?

@kodebach
Copy link
Member

kodebach commented Oct 2, 2019

is it for \0?

Yes

@kodebach
Copy link
Member

diff --git a/src/plugins/crypto/botan_operations.h b/src/plugins/crypto/botan_operations.h
index e2b66e22a..108f941ea 100644
--- a/src/plugins/crypto/botan_operations.h
+++ b/src/plugins/crypto/botan_operations.h
@@ -13,6 +13,11 @@
 #include <kdb.h>
 #include <kdbtypes.h>
 
+#ifdef __cplusplus
+extern "C" {
+using namespace ckdb;
+#endif
+
 #define ELEKTRA_CRYPTO_BOTAN_KEYSIZE (32)
 #define ELEKTRA_CRYPTO_BOTAN_BLOCKSIZE (16)
 #define ELEKTRA_CRYPTO_BOTAN_ALGORITHM "AES-256/CBC"
@@ -22,4 +27,8 @@ int elektraCryptoBotanInit (Key * errorKey);
 int elektraCryptoBotanEncrypt (KeySet * pluginConfig, Key * k, Key * errorKey, Key * masterKey);
 int elektraCryptoBotanDecrypt (KeySet * pluginConfig, Key * k, Key * errorKey, Key * masterKey);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif

Applying this diff should fix the namespace problems for Botan.

@ghost
Copy link
Author

ghost commented Nov 6, 2019

jenkins build libelektra please

1 similar comment
@ghost
Copy link
Author

ghost commented Nov 7, 2019

jenkins build libelektra please

@ghost
Copy link
Author

ghost commented Nov 7, 2019

@markus2330 please take a look through the PR, all I am left to do is restart the jenkins until it finally gives green light to merge

@ghost
Copy link
Author

ghost commented Nov 7, 2019

jenkins build libelektra please

@mpranj
Copy link
Member

mpranj commented Nov 7, 2019

The current build has been running for 9h 34m 56s. Can we kill/restart that?

@ghost
Copy link
Author

ghost commented Nov 7, 2019

The current build has been running for 9h 34m 56s. Can we kill/restart that?

yes please, I tried to restart it already with the restart command here

Copy link
Contributor

@markus2330 markus2330 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a lot of code removed!

/**
* @file
*
* @brief
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write a sentence what this file is for.


#ifdef __cplusplus
extern "C" {
using Key = ckdb::Key;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using should not be used in header files. Did you have any luck with completely removing ckdb?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I have tried it but failed due to my insufficient lack of C/C++ skills.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the ckdb namespace should be pretty easy, but it should be a separate PR since it affects many files. I can do it after #3115, if no one else has the time/knowledge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @Piankero can try again, 90% of the effort should be to simply remove all occurrences of the text string "ckdb".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sure, I can write that regex remove those occurrences and open a PR for @kodebach to continue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be nice if you could start the PR. Just using a regex won't work since you cannot correctly remove the closing brackets corresponding to namespace ckdb { declarations. But that shouldn't be too much effort to do manually.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem, I will create it in your repository tomorrow morning.
Just to be sure:
I should remove all ckdb:: as well as all namespace ckdb { + } occurrences?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should remove all ckdb:: as well as all namespace ckdb { + } occurrences?

The safest thing would be too replace ckdb:: with just ::, e.g. replacing ckdb::Key to ::Key. That way we explicitly refer to the global namespace and shouldn't run into any problems, if someone used for example using namespace kdb; and then ckdb::Key.

#endif

#ifndef ELEKTRA_MODULE_NAME
#define ELEKTRA_MODULE_NAME kdb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if we set the modules at the appropriate places and not having a catch-all here. Which places do not set the ELEKTRA_MODULE_NAME?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I implemented the new error codes I was not able to implement this for the core of elektra. Every plugin sets it correctly (guaranteed via the cmake LibAddPlugin). I remember also a longer discussion with @kodebach why this was difficult/ not possible but cannot remember the actual reasons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you cannot remember, please remove and find out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module name should be set in CMake (as a compiler argument), whenever we want something other than "kdb". AFAIK this is currently done in add_plugin and maybe also add_lib.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the question was if we need this default "kdb". Which module does not have any name set? We should fix that to not get the possibly wrong module name "kdb".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think elektra-core and elektra-kdb don't set a module name. In any case we should either have a default set or replace the #define with an error, otherwise the module name will be set to ELEKTRA_MODULE_NAME since the macro is simply not replaced.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good objection. Of course it should be an error and not simply removed.

@@ -132,6 +132,29 @@ libelektra_0.8 {
elektraKeySetName;
};

libelektra_1.0 {
# kdberrors.h
ELEKTRA_ERROR_RESOURCE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are macros and not symbols? Why are they added here?

Copy link
Author

@ghost ghost Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After various frustrating attempts I asked @kodebach for help despite I wanted to implement it myself. He added those lines

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually didn't add those lines I just moved them from the private part below since they should be accessible by applications. However, you are right they are macros we should be able to remove those lines.

@@ -13,6 +13,12 @@
#include <kdb.h>
#include <kdbtypes.h>

#ifdef __cplusplus
extern "C" {
using Key = ckdb::Key;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here using should be avoided.

@ghost
Copy link
Author

ghost commented Nov 8, 2019

As the PR already passed the build server, maybe we should merge it and make a follow-up PR?

It had a conflict so I needed to rebase. After the build servers passes please merge it

@ghost
Copy link
Author

ghost commented Nov 8, 2019

jenkins build libelektra please

@markus2330 markus2330 merged commit 4b5c0d5 into ElektraInitiative:master Nov 8, 2019
@markus2330
Copy link
Contributor

Thank you, I am looking forward to the follow-up.

@ghost ghost deleted the remove-error-code-generation branch December 4, 2019 09:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants