« first day (1681 days earlier)      last day (3269 days later) » 

10:00 PM
I don't know what it does yet.
 
Xeo
Why are you poking in shared pointer internals?
 
11 hours ago, by milleniumbug
I wonder if an implementation of enable_shared_from_this that returns shared_ptr if the object is owned, and nullptr if it's not is possible.
As far as I understand it, it's UB if it's not owned.
 
user1804599
Your code is incomprehensible.
 
Who is "you"
 
user1804599
You.
 
Xeo
10:03 PM
@milleniumbug Just check the internal weak pointer?
 
> The shared_ptr constructors that create unique pointers can detect the presence of an enable_shared_from_this base and assign the newly created shared_ptr to its __weak_this member
(§ 20.8.2.5/11)
 
user1804599
template<typename T>
using actually_reasonable_shared_ptr = std::shared_ptr<T const>;
 
user1804599
D const > C++ const.
 
user1804599
D const(T****) is C++ T const* const* const* const* const.
 
10:06 PM
@AndyProwl I see. That's tightly coupled.
 
yep
 
user1804599
std::enable_shared_from_this is bad and you should feel bad.
 
user1804599
Try writing good code instead.
 
Ell
@rightfold why is it bad?
 
Xeo
10:08 PM
> Major change
 
Ell
@Columbo be better at git
 
Xeo
So informative!
 
I fucking hate Git.
Because I can't fucking do it.
 
user1804599
@Ell you're coupling a type to the way objects of it are referred to.
 
I suck so bad at it. Sometimes I just want to delete the repo and create a new one
 
10:09 PM
I don't get the point of std::enable_shared_from_this
 
@Jefffrey I didn't get it at first either.
 
user1804599
Memory leak in Perl: { my $x = {}; $x->{x} = $x; }. :D
 
@Columbo And then...?
 
@Jefffrey I got it.
 
And...? What's the point?
 
10:11 PM
@Jefffrey it's in the name
 
No, the question is in what scenarios would I use it. Not what it does.
 
@Jefffrey There can be multiple shared_ptr's referring to an object. Sometimes you want to provide a shared_ptr to this, because you know that this is hold by some shared_ptr. But just returning a shared_ptr to this does not synchronize with the counter of that initial shared_ptr
 
I'm so glad Debian 8 allows apt-get install libboost-all-dev
 
user1804599
I'm not. Fuck Debian.
 
@rightfold Yeah, fuck that guy.
 
user1804599
10:13 PM
Install Gentoo.
 
@rightfold No, install Arch.
 
@Columbo Why would a class know it's always shared to something? What if someone doesn't put it in a std::shared_ptr but in a std::unique_ptr? It doesn't seem like a class should know if it's used in anything.
 
what's wrong with Debian?
 
user1804599
Installing recent versions of software is too difficult.
 
@Jefffrey The user calls shared_from_this. He has to know shit, not the class.
 
10:14 PM
It's almost like when a class decides that there's only gonna be a single instance. It's one of those decisions that the class cannot possibly make at the point it's declared.
 
The class solely anticipates that this scenario pops up sometime.
 
it took 2 years for Debian 8
 
@Columbo Why can't the user use std::shared_ptr<T>(ptr)?
 
user1804599
@Jefffrey You're wrong once again.
 
user1804599
() is my favourite singleton.
 
10:16 PM
Hmmm, g++, clang++ and Visual C++ throw std::bad_weak_ptr in this scenario. I wonder if it's standard behaviour.
(probably isn't)
 
Xeo
UB, so anything goes.
> Requires: [...] There shall be at least one shared_ptr instance p that owns &t.
 
@rightfold Again, you intentionally use "singleton" with another connotation other than this. And then when I tell you everybody is talking about the singleton patten you are going to say that it's perfectly fine as long as it's immutable, and when I tell you that it's often mutable, then you are going to say that global mutable objects are terrible anyway. We had this discussion like 4 times now.
 
Xeo
for shared_from_this()
 
Dang it
 
user1804599
I should write software named nasald.
 
user1804599
10:18 PM
So you can spawn the nasal daemon.
 
user1804599
> In software engineering, the singleton pattern is a design pattern that restricts the instantiation of a class to one object.
 
user1804599
Sounds just about like ().
 
user1804599
There's only one object of type ().
 
user1804599
Fun-fact: Go optimises zero-field structs to singletons.
 
@rightfold Thankfully it's immutable so the distinction between "one object" and "multiple object that compare equal" is moot.
 
Ell
10:20 PM
@Jefffrey its about allowing the class to create shared ptrs from this
 
@Jefffrey Because the two shared_ptr's that then exist would think they're the only owners. That's bad. coliru.stacked-crooked.com/a/039e2834c67f4766
 
Ell
Not about determining what smart ptr it can be held by
 
@Columbo I meant from outside the class. ptr in std::shared_ptr<T>(ptr) is the original std::shared_ptr<T>.
 
user1804599
Does the JVM trap SIGSEGV or does it perform null checks all over the place?
 
I see that it's useful for returning an std::shared_ptr<T> to this, but I don't see why you would do that in the first place. I understand that std::shared_ptr<T>(this) is bad because it fucks up the referencing counting.
 
10:21 PM
@Jefffrey std::shared_ptr<Obj>(new Obj) is never a problem.
 
Ell
Basically, if you do return std::make_shared(this); things break
 
@milleniumbug Only for finite values.
 
user1804599
@Columbo wrong.
 
user1804599
f(std::shared_ptr<Obj>(new Obj), std::shared_ptr<Obj>(new Obj)) leaks.
 
@rightfold -.-
 
user1804599
10:22 PM
vOv
 
Ell
@Jefffrey that is the only reason it exists though
 
user1804599
@Ell wrong.
 
Ell
To enable created shared ptrs from this
 
The question is why would I do it
 
@Columbo You are not following. What I'm saying is that if you have a shared pointer ptr, and you want a copy... instead of doing ptr->shared_from_this() you can simply do std::shared_ptr<T>(ptr).
 
10:23 PM
@Jefffrey Alright, and if you don't have that initial ptr?
 
Ell
@rightfold oh
 
Then you're fucked.
 
What do you mean?
What.
 
user1804599
@Ell It breaks when the dtor of the last shared pointer is called.
 
user1804599
If it never gets called, nothing will break.
 
10:24 PM
@Jefffrey How do you get a second shared_ptr to an object from which you know that it is held by some shared_ptr already
 
It's official: enable_shared_from_this is broken.
 
But you don't have that shared_ptr
 
Ell
Wait idk what the reply was to :v
 
@Columbo That makes no sense. Can you make an example of where this would make sense?
@rightfold You are getting boring man.
 
@Jefffrey No. I can barely make examples where shared_ptr makes sense in the first place. Just keep in mind that this happened often enough for the LWG to introduce this.
 
user1804599
10:25 PM
No, I'm doing my duty.
 
user1804599
 
user1804599
The flagger is also wrong here.
 
user1804599
And again.
 
No, you are being intentionally pedantic in a discussion where everybody knows what they are talking about, for no reason at all.
 
this-^
 
user1804599
10:26 PM
DUTY, CALL OF
 
And it's Jefffreys Birthday! Jesus man!
 
My birthday is over since 26 minutes ago.
 
user1804599
Happy birthday Jeff Frey.
 
Thanks
 
I don't get how enable_shared_from_this is broken
I didn't bother scrolling up though.
 
10:27 PM
@Rapptz It's not.
 
user1804599
@Jefffrey I think there's a pretty good reason people know what they're talking about.
 
Yeah it probably isn't.
 
user1804599
It's because they have a lot of experience with and interest in the topic at hand.
 
@Rapptz Btw., I heared you're a virgin - don't ask from where. Is that true?
 
@rightfold I'm going to kill you someday. :)
 
10:28 PM
@Columbo no
 
user1804599
@Jefffrey Terrorist.
 
@Rapptz So, who was it? Templates?
 
user1804599
Misogynist!
 
@Rapptz Doing A nonown; auto p = nonown.shared_from_this(); is UB, although it could be checked pretty much for free.
 
@Rapptz People simply don't get the point of it.
 
10:29 PM
@Jefffrey Speak for yourself.
 
user1804599
@Rapptz It isn't.
 
user1804599
Code that uses it is broken.
 
Gratuitous UB is gratuitous.
 
user1804599
I'm gonna get instant noodles.
 
The point is pretty clear, idk what are you confused about
 
10:29 PM
@rightfold Fuck off.
Son of a noodle.
 
Ell
I'm not sure where the confusion is also
 
@Rapptz @milleniumbug, @Columbo and I simply don't get the point of it.
 
Ell
If uou want to return a shared pointer to this
 
Those are "people". Plural of "person".
 
I know what it does, I don't know where would I use it.
 
Ell
10:31 PM
You have to use it to prevent double destruction
Or ref counting problems
 
@Ell Why would I want to return an std::shared_ptr from this?
 
@milleniumbug Suppose the interface reported the error. What would you do then?
 
How can you say you know what it does if you're using it incorrectly?
 
Why would I want to do whatever
 
@LucDanton Return std::shared_ptr to null.
 
Ell
10:31 PM
@Jefffrey suppose you have some data that needs to be persisted until some callback
That wasn't a good sentence
 
@Jefffrey Look: You have an object that is owned by some shared_ptr. This is e.g. (not necessarily) by design. Now you just have a reference to that object, and want an owning shared_ptr that ensures that this object is alive throughout the rest of your operations. But getting the shared_ptr that is currently pointing to it is impractical. So shared_from_this gets you a second one without UB.
 
IF you need to make shared_ptr from this, you use enable_shared_from_this
If not, you can just ignore its existence
 
Ell
Look at the boos::asio examples, there is a use case there
 
The fuck is the point of inventing use cases right now
 
@milleniumbug Suppose you have a null pointer. What do you do then?
 
10:32 PM
@CatPlusPlus I get it. But why would I want that? If I'm looking at this, it means I'm inside some class. And I'm making the assumption that this class will be used with an std::shared_ptr. Why?
 
It either exists, or you can't ever do shared_ptr(this) safely
 
@LucDanton I don't see how is that relevant in discussion about shared_from_this(). Could you clarify?
 
So that instead of calling std::shared_ptr<T>(ptr) I use ptr->shared_from_this()?
 
@Jefffrey NO
You could just copy in that case
 
@Jefffrey Because you might idk who cares
 
10:33 PM
@milleniumbug If your premise is that an error-reporting interface is preferable, then I have to inquire what it is preferable for.
 
@CatPlusPlus I care. That's the whole point of the discussion.
 
Okay, you’ve got an error. Now what?
 
It's there to enable use cases, not because some pervasive common one exists
 
@Jefffrey So your confusion is with its application, not its raison d'être.
 
Yes
 
Ell
10:34 PM
@Jefffrey you have no ptr I'd you are inside T, right?
 
> std::enable_shared_from_this allows an object t that is currently managed by a std::shared_ptr named pt to safely generate additional std::shared_ptr instances pt1, pt2, ... that all share ownership of t with pt.
thatsit
 
yeah
 
I understand that it solves the problem of returning an std::shared_ptr from this. Got it. I don't get why would anyone do that.
 
that's it
 
I don't understand the use case.
 
10:35 PM
then don't
it'll come to you if you need it
 
That's not a use case, that's just a foundation if you have a use case that requires that
 
you're not forced to use it
it's not going to kill your family if you don't use it
the use cases are sort of niche
but when they pop up you'll be glad it's there
 
I simply wanted to know an example of a use case. That's it. If you don't have it, it's fine. Just say "I don't know any use case".
 
Did that 5 minutes ago
 
Ell
@Jefffrey I will show you a use case
See tcp_connection
 
10:39 PM
@LucDanton I'm still not sure why would I need it (the enable_shared_from_this), but I'm assuming the object being usable when you don't use shared pointers is a plus.
 
Goblin Camp was a mess of shared_ptrs, so it was used to create copies to send off to other parts of the system
src\Construction.cpp:226: StockManager::Inst()->UpdateWorkshops(boost::static_pointer_cast<Construction>(s‌​hared_from_this()), true);
That'll probably be the primary use case
 
otherwise there is glaring shared_from_this() method in your interface that calls in goblins nasal demons.
So you either use factory methods exclusively for such objects, or you use private/protected inheritance from enable_shared_from_this.
 
(if you're using shared_ptrs that much then you probably want a less primitive GC anyway)
 
user1804599
Tracing GC best GC.
 
Ell
Is there a good GC for c++?
 
10:42 PM
No GC is good for C++
 
Yeah, it's called CLR
 
You have to call destructors anyway, and GC won't know which destructors and when to call them.
 
Ell
The CLR isn't a GC
 
boost::bind(&tcp_connection::handle_write, shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)
 
user1804599
It is.
 
10:43 PM
Nope I don't get it.
 
Ell
The CLR is a virtual machine
 
Yes, that's the point
 
user1804599
Which does garbage collection.
 
user1804599
Hence it's a GC.
 
@Ell It isn't a GC, but it certainly includes a GC.
 
Ell
10:43 PM
@rightfold it provides a GC
It isn't a GC itself
 
Why can't you use: boost::bind(&tcp_connection::handle_write, *this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)?
 
@milleniumbug That's nonsense
 
Ell
You can write non gc code for the CLR I thought
 
user1804599
You can disable the garbage collector.
 
@Jefffrey Lifetime
 
10:44 PM
@CatPlusPlus Which part?
 
@milleniumbug GC not knowing which destructors to call
 
Yeah, now that you mention it.
 
@CatPlusPlus It's inside a method of tcp_connection, which calls handle_write on it.
The object will live long enough there.
 
delete knows which destructors to call.
 
@Jefffrey It's asynchronous, it will be called in unspecified future
 
10:46 PM
Whenever it's called, it's called on an existing object. So I don't see your point.
 
Ell
@Jefffrey just try kr
It
 
This is a callback that's passed further down into asio
 
user1804599
Use stackful coroutines and automatic storage duration, async problem solved.
 
Oh, it doesn't know which to call when the destructor is non-virtual.
 
Ell
Try writing the example without using shared_from_this
 
10:47 PM
shared_ptr is there to ensure that the object will live when the callback needs to be called
 
I see
 
user1804599
I don't like my penis.
 
user1804599
I want rightfold's vagina.
 
Buy one
 
user1804599
Health insurance does that.
 
10:49 PM
Download one
 
user1804599
Instant goodles.
 
user1804599
So bad for your health.
 
user1804599
Why I eat bad food: die earlier so less time suffering from Alzheimer's.
 
you're not even 18 and you have Alzheimers....ok.......
 
user1804599
I'm 20, you fool.
 
10:50 PM
@rightfold And yet you don't visit McDonalds...
 
@rightfold You won't suffer from Alzheimer's. You'll enjoy every minute of it (though you won't remember enjoying it).
 
Oh cool me too!
 
user1804599
@milleniumbug No.
 
Ell
@Jefffrey I feel like you're still not convinced
 
user1804599
Look, instant noodles don't taste particularly well.
 
user1804599
10:51 PM
But McDonald's tastes just awful.
 
@Ell Nah. I got it.
 
Ell
Seriously I think you should try wrjtjng that example without it
 
I'm guessing sometimes it will segfault or something.
UB anyway.
Specifically when the callback is called and the object has been deallocated.
 
user1804599
The only non-moronic way to use Boost.Asio's async facilities is by first writing a wrapper based on boost::coroutines::asymmetric_coroutine<void> to make them synchronous.
 
Ell
I agree
 
user1804599
10:53 PM
The only good async API is the one that spawns a (lightweight) thread and forgets about it.
 
The only good rightfold is leftfold.
 
unfold
my USB cable stopped working
can't charge my phone ... although I have another one in my car
 
user1804599
Any API that isn't fire-and-forget should block.
 
@rightfold Conversations like this warm my heart--reminds me that in spite of my age, I'm a long ways from being the narrow minded person around here.
 
user1804599
@AlexM. certain groups in the Netherlands also say bad things about your mother in order to offend you, which is pretty hilarious, since other people typically don't give a shit about people saying bad things about their mothers.
 
10:58 PM
@rightfold ..and if the thread that initiates the operation is the sole owner of a resource, (eg. GUI), that is to receive completion/error notification later?
 
user1804599
@MartinJames use queues for communicating between threads.
 
@rightfold Well, sure, the thread that requires the completion notification would usually need an input queue.
 
user1804599
Then have one thread on which all GUI operations take place, using an agent. clojure.org/agents and elixir-lang.org/docs/stable/elixir/Agent.html
 
user1804599
Submit to that agent all operations you want to perform on the GUI.
 
user1804599
You can do that from any thread since agents do synchronisation.
 
user1804599
11:02 PM
Agent is pretty much a thread that has a message queue and does this:
 
user1804599
T state;
for (;;) {
    auto operation = message_queue.dequeue();
    state = operation(state);
}
 
@milleniumbug Inherit protected/private.
 
user1804599
In case of GUI, state = operation(state); would update the screen as well.
 
@milleniumbug But the operation doesn’t make sense if the object is not shared. It would need to perform something different entirely.
It’s a good separation of concerns.
 
@rightfold React does it that way.
 
user1804599
11:05 PM
Then, for each control, spawn a thread which handles the events for that control, for example:
 
user1804599
button([] (queue<click_event>& clicks) {
    for (;;) {
        auto click = clicks.dequeue();
        // do something with click, such as sending an operation to the GUI agent
    }
});
 
Ell
One thread per control?
Feels like overkill
But what do I know
 
user1804599
Sure, why not?
 
user1804599
Threads are not necessarily heavyweight.
 
user1804599
Use a decent threading implementation (such as Erlang) and they'll be cheap.
 
11:07 PM
my phone indicates that it's not charging using this USB, but the battery sign has changed from red to normal
 
@chmod711telkitty that sucks!
 
Who here is good with locales and codecvt?
 
driving out soon, will use the charger in the car
 
user1804599
C++ certainly isn't.
 
@chmod711telkitty i'll be ready at 8
my time
 
11:09 PM
robot maybe?
 
this is amazingly bad
 
Are there good TV shows nowadays?
 
there is so little support for char16_t and char32_t in the stdlib
it feels so tacked on and last minute
 
user1804599
@Jefffrey Studio PowNed is sometimes funny.
 
want unicode, use external library
 
user1804599
11:12 PM
But not too good.
 
user1804599
PowNews was better.
 
I don't want unicode
 
then why bother with char16_t and char32_t
 
Ell
@Jefffrey GoT, Better Call Saul
 
Seeing them already
 
Ell
11:14 PM
Hmm
 
convert the hr, min, sec into int
 
Ell
Does ogonek just do Unicode?
Or other encodings?
 
user1804599
It supports ASCII.
 
@LucDanton That's a good argument. So we're putting it in the same category as OOB array access (as in, doing it is a programmer bug, don't bother catching it), which is understandable. OTOH I can check bounds manually, but I can't check if it's shared. So if I'll ever find a use case for a checking interface, I won't be able to implement it on top anyway.
 
user3010322
11:30 PM
So I think luajit has its own Coroutine library that opens on the base.
 
user3010322
@Rapptz I got luajit working with sol
 
user3010322
And the tests compile.
 
neat
 
user3010322
It took me forever to get things going.
 
user3010322
I had to made some ugliness in the state.hpp code.
 
user3010322
11:31 PM
But the rest is actually perfectly intact.
 
fold expressions so good
 
user3010322
... Buuut there's some segfaults!
 
user3010322
Yay, segfaults!
 
user3010322
Time to figure it out.
 
I find that a bit weird from a class that's supposedly "we haven't found much use cases for it, but we're assuming a person will do this, so we're providing you this functionality you couldn't write yourself otherwise"
 
11:34 PM
boost::enable_shared_from_this existed you know
and it's used by Boost
scroll up for a use case
 
Really, you could do it yourself, it's mostly for convenience
It's implemented as weak_ptr field
+ some stuff in shared_ptr itself to recognise it and call shared_from_this for you
 
@milleniumbug Yeah it’s a precondition thing. I agree that enable_shared_from_this is barebones, too.
 
@CatPlusPlus Don't these extra stuff make it impossible?
 
@milleniumbug Use cases are straightforward and common.
 
No, you don't really need it, you'd just need to be careful to never construct shared_ptr yourself and always call shared_from_this
Copying shared_ptrs that already own that object is fine
 
user3010322
11:40 PM
... I have the lua source
 
user3010322
why is this crashi- oooh...
 
user3010322
luajit has hand-crafted ASM.
 
Ok, I'll try messing with it more tomorrow.
Gotta sleep.
 
user3010322
Shit
 
user3010322
Something going wrong with the edi register
 
user3010322
11:41 PM
I can't read this, I don't know ASM.
 
user3010322
JFC.
 
@ThePhD Primo time to learn
 
user3010322
@CatPlusPlus u.u
 
user3010322
Acess reading violation: reading from 0x0000000010
 
Access through null pointer
 
user3010322
11:44 PM
Wtf
 
user3010322
Why is luajit accessing this pointer + 0x10
 
Because it's some struct field
And the pointer is null
 
user3010322
It's not a struct I have access to at all.
 
user3010322
luajit's doing something stupid.
 
Ell
11:47 PM
What?
 
I didn't know this existed.
 
Been there forever
 
user3010322
lj_BC
 
user3010322
Some ridiculous ASM function
 
user3010322
I can't read.
 
11:50 PM
Look at the stack trace, that function is unlikely to be the source of the error
 
user3010322
There is no stack trace.
 
user3010322
 
user3010322
That's my stack trace.
 
user3010322
It's some ASM-defined thing.
 
Get a debug version
 
user3010322
11:52 PM
I did build this on debug.
 
Of LuaJIT
 
Ell
Lol
 
It's probably using frame pointer optimisation
 
user3010322
I went through painstaking steps to build this as debug. Luajit uses 60k lines of ASm or w/e.
 
You won't learn anything from poking inside of JIT, get a real stacktrace
 
user3010322
11:53 PM
I can-
 
user3010322
Okay.
 
Ell
60k lines of ASM doesn't sound very debug
Able
 
It's really unlikely to be the cause
 

« first day (1681 days earlier)      last day (3269 days later) »