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

[For discussion purpose] - Used unique_ptr instead of auto_ptr when c++11 is used. #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Bertram25
Copy link

Hey @Oberon00 :D

(CC @endoalir for info.)

After some fiddling and some research, I manage to obtain a luabind version capable to compile without any warnings when using c++11, and that seems to run Valyria Tear rather fine, according to my latest tests... You can see the changes I made in this PR.

YET, (because nice things never comes free), it seems those changes aren't perfect according to the following issue: HoverRace/HoverRace#260

It seems the following adapted commit is also needed: halmd-org@1853787 because otherwise the following issue may happen: HoverRace/HoverRace#259

However, it seems HoverRace is using the main luabind repository and that other bugs may come into game, though. So I made this PR mainly to know what to do next in order to get a c++11-warning-free-and-functional luabind PR. Do you think my PR is enough, or do you have hints anywhere at how I should handle the issue around boost::shared_ptr vs std::shared_ptr?

Thanks a lot for your repository in any case and for your help, and best regards,

@fhoefling
Copy link

Am 24.08.2015, 00:05 Uhr, schrieb Yohann Ferreira
[email protected]:

Hey @Oberon00 :D

(CC @endoalir for info.)

After some fiddling and some research, I manage to obtain a luabind
version capable to compile without any warnings when using c++11, and
that seems to run Valyria Tear rather fine, according to my latest
tests... You can see the changes I made in this PR.

YET, (because nice things never comes free), it seems those changes
aren't perfect according to the following issue:
HoverRace/HoverRace#260

It seems the following adapted commit is also needed:
halmd-org@1853787
because otherwise the following issue may happen:
HoverRace/HoverRace#259

In HALMD, we've been using luabind (=luaponte) with C++11 since long
without any issues. Our version is perhaps a bit out-dated since I didn't
have time to follow the recent developments in luabind, but it brings all
the functionality we need (as of luabind 0.9.1) and works with the most
recent Boost releases.

I'd love to revert from luaponte to luabind and to use a library which is
supported by a (small) community. Still I'm not sure which luabind branch
to start with, build-improvements seemed to be the most useful one for me
but it hasn't been continued. I think the most urgent need is a kind of
release schedule and finally a new release of luabind (following the old
0.9.1). Featurewise, the various master branches (from different people)
are in a good shape as far as I can tell. However, just adding commits to
"master" is not enough, it does not tell how stable the current tip of the
branch is. And stability is one of the most important criteria to make a
large project depend on a certain library.

BTW, there is at least one failing test concerning "out_value" vs.
"pure_out_value", see commit a1199b5.

Regards,

Felix

@Bertram25
Copy link
Author

Hey @fhoefling :)

In HALMD, we've been using luabind (=luaponte) with C++11 since long without any issues. Our version is perhaps a bit out-dated since I didn't have time to follow the recent developments in luabind, but it brings all the functionality we need (as of luabind 0.9.1) and works with the most recent Boost releases.

It's good to know. The only thing to consider though is that it seems required to keep the former C++ norm supported (or keep std::auto_ptr and don't use nullptr) optionally.
Maybe @Oberon00 will be able to tell more about this.

I'd love to revert from luaponte to luabind and to use a library which is supported by a (small) community. Still I'm not sure which luabind branch to start with, build-improvements seemed to be the most useful one for me but it hasn't been continued. I think the most urgent need is a kind of release schedule and finally a new release of luabind (following the old 0.9.1).

Here you're speaking about the mother luabind, which many are considering a dead upstream.
The small community you're speaking about is IMHO either around @rpavlik or @Oberon00 's forks.
So, I wonder: Do you have access to luabind to start and make it live again, for instance? Also, see below.

Featurewise, the various master branches (from different people) are in a good shape as far as I can tell. However, just adding commits to "master" is not enough, it does not tell how stable the current tip of the branch is. And stability is one of the most important criteria to make a large project depend on a certain library.

IMHO, @Oberon00 has done a good job in trying to keep the lib clean and import mostly bug fixes and taking care of not doing anything too experimental. So, would luabind's authors be away for good, I would rather focus on bringing improvements here. (As I'm trying to do with this current PR).

In your opinion, what features would be lacking here before you would consider adoption, for instance?
Could we have a common effort on a alive fork and IMO achieve what everyone wants to achieve: A good common new reference release, even from a fork? (After all, it's the way Open Source work sometimes.)

BTW, there is at least one failing test concerning "out_value" vs. "pure_out_value", see commit a1199b5.

k, created issue: #30

@Oberon00
Copy link
Owner

Since C++17 will probably remove auto_ptr entirely and MSVC 14 (2015) already allows users to disable it, I consider this pull request a quite reasonable idea.

However, your approach of using #ifdef everywhere is suboptimal: Better use a typedef ??? luabind::detail::unique_ptr + a luabind::detail::move function and define that conditionally in one place (probably a new detail header).

Also do not make this configurable in the CMake file (or if an issue arises that forces the offering of a user configurable "override switch" this should be done via a #cmakedefine in build_information.hpp) but instead rely on Boost.Config's BOOST_NO_CXX11_SMART_PTR. Because older versions of Boost that did not have this macro should also be supported, an additional check for LUABIND_NO_RVALUE_REFERENCES would be good too. See config.hpp and std_shared_ptr_converter.hpp for examples.

When that is done, the -Wno-deprecated-declarations flag can be removed from the CMakeLists.txt.

[…] do you have hints anywhere at how I should handle the issue around boost::shared_ptr vs std::shared_ptr?

Do you mean unique_ptr? Or what issue around shared_ptr do you mean?

@Bertram25
Copy link
Author

@Oberon00 I'm overwhelmed by other tasks but I'll come back here to upgrade PR eventually. Thanks for your patience! :)

@akien-mga
Copy link

Hey guys, what's the status of this PR?

@Oberon00
Copy link
Owner

I won't merge the pull request until the many #ifdefs are replaced with a typedef & wrapper move function, as I commented above. Also, because it seems that this pull request is just a cosmetic improvement, I don't plan to allocate time for doing so myself though.

@Bertram25
Copy link
Author

Bertram25 commented Apr 24, 2016

I won't merge the pull request until the many #ifdefs are replaced with a typedef & wrapper move function, as I commented above

Yeah, I've got some job left on this one. I didn't forget about it, but there is quite some things on my plate atm, sorry. :)

Also, because it seems that this pull request is just a cosmetic improvement, I don't plan to allocate time for doing so myself though.

Here, I disagree, removing deprecation warnings is no cosmetic thing, especially when the c++14 norm will be the standard.

@Oberon00
Copy link
Owner

Here, I disagree, removing deprecation warnings is no cosmetic thing, especially when the c++14 norm will be the standard.

Good point, I haven't thought about that. luabind is compiled with -Wno-deprecated, but you are right that forcing user code to also disable this (generally useful) warning is a problem.

Yohann Ferreira added 2 commits May 24, 2020 13:10
Move instead of copy smart pointers, using std::move.

Add overload to get_pointer() to retrieve raw pointer.

Based on Peter Colberg's patch:
halmd-org@19d9a14
@@ -105,6 +105,10 @@ if(LUABIND_NO_STD_SHARED_PTR)
add_definitions(-DLUABIND_NO_STD_SHARED_PTR)
endif()

if(LUABIND_USE_CXX11)
Copy link
Owner

Choose a reason for hiding this comment

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

Can you instead use LUABIND_NO_STD_UNIQUE_PTR to mirror LUABIND_NO_STD_SHARED_PTR? Ideally, this should also try to use BOOST_NO_CXX11_SMART_PTR and a CMake option should only be necessary as a fallback.

Also, I think this should be in build_information.hpp instead of being added via add_definitions, but it's been too long ago, so I'm not completely sure.

Copy link

@kaetemi kaetemi Sep 28, 2021

Choose a reason for hiding this comment

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

Yes, this needs to be in build_information.hpp. This PR is somehow live in Ubuntu 20.04 LTS though the ValyriaTear/luabind repo. It broke our ryzom/ryzomcore build, since luabind is built with the option, but the headers get included without LUABIND_USE_CXX11 (unless we hardcode the option in our own repo).

Copy link

Choose a reason for hiding this comment

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

The alternative is of course auto-detecting, and not giving the option to users.

@@ -96,7 +96,11 @@ namespace luabind { namespace detail
template <class T>
struct pointer_or_default<void, T>
{
#ifdef LUABIND_USE_CXX11
Copy link
Owner

Choose a reason for hiding this comment

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

You have this #ifdef in multiple places. I'd prefer placing it in a central header, like luabind_memory.hpp or similar with a single namespace luabind { typedef unique_auto_ptr ...; }.

@@ -54,7 +57,11 @@ struct construct_aux<0, T, Pointer, Signature>
void* storage = self->allocate(sizeof(holder_type));

self->set_instance(new (storage) holder_type(
#ifdef LUABIND_USE_CXX11
std::move(ptr), registered_class<T>::id, naked_ptr));
Copy link
Owner

Choose a reason for hiding this comment

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

Similarly to the centralized typedef a centralized ifdefed LUABIND_MOVE macro would be useful. Maybe it could also be a luabind::move function, but that might be overkill.

scope(scope const& other_);
~scope();

scope& operator=(scope const& other_);

scope& operator,(scope s);
scope& operator,(const scope& s);
Copy link
Owner

Choose a reason for hiding this comment

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

Reading the implementation in scope.cpp of this, I'm concerned. Was a simple def("foo", &foo), def("bar", &bar) previously causing a double-delete?

Would scope& without const work here, similar to https://en.cppreference.com/w/cpp/memory/auto_ptr/auto_ptr ?

Choose a reason for hiding this comment

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

I naively tried scope& and the unit tests blew up on me. It looks like scope is trying to implement its own homebrew unique_ptr mechanism and that is all tied up in using const scope& to trigger the complemented copy constructors to orchestrate the proper ownership transfer.

It felt like fixing this for c++03 would require some serious plumbing work. However, under c++11, implementing the proper move semantics seems to address the major use cases.

@Oberon00
Copy link
Owner

Hi @Bertram25! It seems this PR comes from your master branch? Do you still intend to merge this? If so, please see the comments above. I think you address some important things here, so I would be glad 😃

@kchang718
Copy link

Hi guys, we've been looking at these patches and have applied @Bertram25 's changes along with @Oberon00 's comments to support unique_ptr. These changes are on PR #47. @jameslee5656 and I have looked over these changes to our best abilities and they run ok in our codebase.

We've also did some work to address the operator,() issues in scope.hpp for c++11.

Please take a look when time allows.

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.

6 participants