Skip to content

Deprecate object::borrowed/object::stolen - #771

Merged
wjakob merged 1 commit into
pybind:masterfrom
jagerman:borrowed-stolen-definition
Mar 28, 2017
Merged

Deprecate object::borrowed/object::stolen#771
wjakob merged 1 commit into
pybind:masterfrom
jagerman:borrowed-stolen-definition

Conversation

@jagerman

@jagermanjagerman commented Mar 28, 2017

Copy link
Copy Markdown
Member

Provides (via a dummy template parameter hack) inline definitions of object::borrowed/object::stolen.

The constexpr static instances can cause linking failures if the compiler doesn't optimize away the reference, as reported in #770.

There's no particularly nice way of fixing this in C++11/14: we can't inline definitions to match the declaration aren't permitted for non-templated static variables (C++17 does allows "inline" on variables, but that obviously doesn't help us.)

One solution that could work around it is to add an extra inherited subclass to object's hierarchy, but that's a bit of a messy solution and was decided against in #771 in favour of just deprecating (and eventually dropping) the constexpr statics.

Fixes#770.

@jagerman

Copy link
Copy Markdown
MemberAuthor

(Awaiting confirmation from #770 that this actually fixes it).

@jagerman

Copy link
Copy Markdown
MemberAuthor

One comment: In C++17 this could be fixed by adding just:

inlineconstexpr object::borrowed_t object::borrowed;
inlineconstexpr object::stolen_t object::stolen;

which is, of course, much nicer than the template hack, but seeing as we need the hack for 14/11 already, I don't see much advantage in using #ifdefs to provide the alternative in C++17 mode.

@dean0x7ddean0x7d left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks too heavyweight. I would just replace all usages of borrowed with borrowed_t{}. The borrowed definition itself might need to stay for backward compatibility (to be removed in v3.0 with other breaking changes).

@jagerman

Copy link
Copy Markdown
MemberAuthor

I'm fine with that. Do you mean heavyweight in terms of added compiler complexity, or something else? (I did check that this doesn't change sizeof(object)).

@dean0x7d

Copy link
Copy Markdown
Member

I mean complex both for the compiler and for humans. The only advantage is avoiding _t{} in the syntax, but the cost is multiple + private inheritance, template tricks, and a separate C++17 version. Definitely not worth it when the goal is simple-as-can-be tag dispatch.

The constexpr static instances can cause linking failures if the
compiler doesn't optimize away the reference, as reported in pybind#770.
There's no particularly nice way of fixing this in C++11/14: we can't
inline definitions to match the declaration aren't permitted for
non-templated static variables (C++17 *does* allows "inline" on
variables, but that obviously doesn't help us.)
One solution that could work around it is to add an extra inherited
subclass to `object`'s hierarchy, but that's a bit of a messy solution
and was decided against in pybind#771 in favour of just deprecating (and
eventually dropping) the constexpr statics.
Fixespybind#770.
@jagerman
jagermanforce-pushed the borrowed-stolen-definition branch from c1c5586 to 4a29ba8CompareMarch 28, 2017 19:09
@jagermanjagerman changed the title Provide definitions of borrowed/stolenDeprecated object::borrowed/object::stolenMar 28, 2017
@jagermanjagerman changed the title Deprecated object::borrowed/object::stolenDeprecate object::borrowed/object::stolenMar 28, 2017
@jagerman

Copy link
Copy Markdown
MemberAuthor

Okay; updated the PR to deprecate borrowed/stolen and replace all internal use with borrowed_t{}/stolen_t{}.

@dean0x7d

Copy link
Copy Markdown
Member

Looks good to me.

@wjakob

Copy link
Copy Markdown
Member

Looks good -- merged!

@wjakob
wjakob merged commit 6db60cd into pybind:masterMar 28, 2017
jagerman added a commit that referenced this pull request Apr 6, 2017
PR #771 deprecated them as they can cause linking failures (#770), but
the deprecation tags cause warnings on GCC 5.x through 6.2.x. Removing
them entirely will break backwards-compatibility consequences, but the
effects should be minimal (only code that was inheriting from `object`
could get at them at all as they are protected).
Fixes#777
@dean0x7ddean0x7d modified the milestone: v2.2Aug 13, 2017
@rwgkrwgk mentioned this pull request Feb 9, 2023
Sign up for freeto 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.

Unedfined symbol pybind11::object::borrowed

3 participants

@jagerman@dean0x7d@wjakob