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

Feature/1796 reflection #2960

Merged
merged 101 commits into from
Sep 19, 2018
Merged

Feature/1796 reflection #2960

merged 101 commits into from
Sep 19, 2018

Conversation

davidnich
Copy link
Contributor

@davidnich davidnich commented Aug 26, 2018

provides a new binary module for reflection called reflection.

Minor API and ABI changes were made; some modules will need to be patched to build against develop after this change, and all modules will need to be rebuilt after the ABI change.

Builds work with cmake & autotools, binary module documentation works with the reflection and astparser modules now and has been integrated into the Qore documentation.

Jenkins has been updated to run tests for binary modules delivered with Qore now.

Has been extensively tested with valgrind as well.

…ists of strings for domains + parse options
…pace; renamed AbstractFunction -> AbstractReflectionFunction in order to avoid conflicts with SqlUtil::AbstractFunction
DLLEXPORT const QoreNamespace* get() const;

private:
class qore_namespace_namespace_iterator* priv;
Copy link
Contributor

Choose a reason for hiding this comment

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

why the PImpl idiom is used here?
also, let's use std::unique_ptr instead of explicitly allocating and deleting the pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why the PImpl idiom is used here?

to abstract the implementation of namespaces from the ABI - is there a better way to do this?

also, let's use std::unique_ptr instead of explicitly allocating and deleting the pointer.

we cannot do that without making the private implementation public, since the size of the object being allocated must be known at compile time

//! allows local namespaces to be iterated
/** @since %Qore 0.8.13
*/
class QoreNamespaceNamespaceIterator {
Copy link
Contributor

Choose a reason for hiding this comment

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

this class has implicit copy ctor and =operator, and the will do just a shallow copy and it will lead to undefined behavior, let's =delete them. Also let's =default the move ctor and =operator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok done

DLLEXPORT QoreNamespaceNamespaceIterator(const QoreNamespace* ns);

//! destroys the iterator
DLLEXPORT ~QoreNamespaceNamespaceIterator();
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the rule where destructor is virtual, or class is final, so no one can inherit a class and take a pointer to its ancestor and then the destructor is not called, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I made all the destructors virtual

class QoreNamespaceNamespaceIterator {
public:
//! creates the iterator
DLLEXPORT QoreNamespaceNamespaceIterator(const QoreNamespace* ns);
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we taking pointer, if it cannot be null, why not reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok fixed

DLLEXPORT bool next();

//! returns the namespace
DLLEXPORT const QoreNamespace* get() const;
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we returning pointer, if it cannot be null, why not reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok done

else {
++i;
}
return (i != ns->nsl.nsmap.end());
Copy link
Contributor

Choose a reason for hiding this comment

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

this will (almost) always return true, right? because when it reaches end, it will go over again except for the case when begin==end. It's not documented that the iterator is cyclic, why do we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because this is how all Qore iterators work in Qore and in C++, for consistency's sake

@davidnich
Copy link
Contributor Author

@sejvlond updated according to the latest feedback

delete i->second;
free(i->first);
delete i.second;
free(i.first);
Copy link
Contributor

Choose a reason for hiding this comment

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

this is really confusing, the class doesn't create any of the members, but it deallocates them and in the way that one was malloced, second was created with new. For better readability I would say either let the class to create them, so it's clear how they were allocated or use them as unique_ptr<char[]> and <unique_ptr>` so they will be deallocated automatically... what do u think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done except the char* issue, because this is allocated by the scanner, and changing this would require massive changes all over Qore - this needs to be changed, but in a major overhaul of memory management in the scanner

@sejvlond sejvlond merged commit f4940ff into develop Sep 19, 2018
@sejvlond sejvlond deleted the feature/1796_Reflection branch September 19, 2018 11:34
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

Successfully merging this pull request may close these issues.

2 participants