Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Rework CFCppBase to remove Impl classes and the Details namespace.#1313

Merged
DHowett-MSFT merged 3 commits into
microsoft:developfrom
DHowett-MSFT:201611-cppbase
Nov 3, 2016
Merged

Rework CFCppBase to remove Impl classes and the Details namespace.#1313
DHowett-MSFT merged 3 commits into
microsoft:developfrom
DHowett-MSFT:201611-cppbase

Conversation

@DHowett-MSFT

@DHowett-MSFT DHowett-MSFT commented Nov 3, 2016

Copy link
Copy Markdown
  • Adds support for calling non-nullary constructors on the new CF Type.
  • Removes the _CFFinalize chain.
  • Removes the _CFInitialize chain.
  • Uses some dodgy methods to work around the undefined behaviour
    inherent in placement-newing a block of partially-initialized memory

This change is Reviewable

* Adds support for calling non-nullary constructors on the new CF Type.
* Removes the _CFFinalize chain.
* Removes the _CFInitialize chain.
* Uses some dodgy methods to work around the undefined behaviour
  inherent in placement-newing a block of partially-initialized memory

@bbowman bbowman 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 is super awesome nifty sauce.

};

struct __CFSubLifetimeCounter : CoreFoundation::CppBase<__CFSubLifetimeCounter, __CFLifetimeCounter> {
__CFSubLifetimeCounter(int& ctorCounter, int& dtorCounter) : Parent(ctorCounter, dtorCounter) {

@bbowman bbowman Nov 3, 2016

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.

Seems a little silly to be using int references here #ByDesign

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.

I guess it makes sense for the dtor count.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This tests a few things: Members expressible only through C++ semantics work properly, constructors and destructors get called properly, and inherited members do not lose their magic.


new (ret) T(std::forward<Args>(args)...);

// This, however, may be ill-defined.

@bbowman bbowman Nov 3, 2016

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.

can this be a static_cast? Every T here should work out for that and we should maybe static_assert or enable_if with is_base_of to validate that CreateInstance only gets called on __CFRuntimeBase things. (Would be super nifty to know it was the root base (not a multi inheritance weirdness) which is maybe doable with template magic?) #WontFix

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You shouldn't be able to call T::CreateInstance with anything but T; and I'd like to use reinterpret to circumvent any chicanery the compiler may pull on layout adjustment. I don't expect it to do any, but the block of memory we get back from _CFRuntimeCreateInstance is definitely normally a __CFRuntimeBase first and foremost.

//
// To work around that, we save the __CFRuntimeBase at the head of ret, call the constructor, and replace/reinitialize
// it. As no constructor has been invoked on ret by the time we save temp, this is not ill-defined.
__CFRuntimeBase temp = *reinterpret_cast<__CFRuntimeBase*>(ret);

@jaredhms jaredhms Nov 3, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

__CFRuntimeBase temp = *re [](start = 8, length = 26)

what all are we copying here, and then again below? #Resolved

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

cfisa, cfinfo.

@jaredhms

jaredhms commented Nov 3, 2016

Copy link
Copy Markdown
Contributor

:shipit:

2 similar comments
@msft-Jeyaram

Copy link
Copy Markdown

:shipit:

@ms-jihua

ms-jihua commented Nov 3, 2016

Copy link
Copy Markdown
Contributor

:shipit:

@DHowett-MSFT DHowett-MSFT merged commit e7e2862 into microsoft:develop Nov 3, 2016
@DHowett-MSFT DHowett-MSFT deleted the 201611-cppbase branch November 21, 2016 18:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants