martedì 22 maggio 2018

Cammino quindi penso - 2018-05-22 - La flat tax è una boiata pazzesca!



Dubito che gli elettori del movimento 5 stelle, ma anche quelli della stessa Lega, siano pienamente consapevoli di cosa sia la flat tax.

domenica 20 maggio 2018

Pensatas in interlingua - 2018-05-20 - Un dominica primaveril al "dacia"



Un typic "dacia" russe, in le region de Sancte Petroburgo.

giovedì 17 maggio 2018

Cammino quindi penso - 2018-05-16 - Togliere le sanzioni alla Russia? Scommettiamo!



Nonostante Movimento5Stelle e Lega dichiarino la volontà di togliere le sanzioni alla Russia, sono pronto a scommettere che si ritireranno con la coda fra le gambe e non lo faranno. Se però siete convinti che invece l'Italia toglierà tutte le sanzioni alla Russia e volete guadagnare soldi facili, contattatemi: organizziamo la scommessa, io ci sto! :-)

martedì 15 maggio 2018

Cammino quindi penso - 2018-05-15 - Palestina, gli stragisti senza nome



Più di 60 morti e circa 2000 feriti tra manifestanti armati soltanto di pietre e fionde, che lottano contro un muro. Uccisi dai proiettili dei soldati israeliani, sotto il silenzio dei politici, e coperti da molti mezzi di informazione compiacenti.

Qui potete vedere come Il Corriere della Sera descriveva questo sterminio questa mattina.

venerdì 11 maggio 2018

Cammino quindi penso - 2018-05-11 - Iran, cosa ci gira intorno



Trump ritira gli Stati Uniti dall'accordo con l'Iran sul nucleare; provo a cercarne una spiegazione.

mercoledì 9 maggio 2018

Can you spot the error? (C++ lambda function)

Yesterday evening a spent several minutes debugging this code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
    FtpInterface *backend = createBackend(nextBackend);
                             
    qDebug() << "trying login with backend" << backend;
    QMetaObject::Connection connection =   
        QObject::connect(backend, &FtpInterface::stateChanged,
                         [=](FtpInterface::State state) {
            if (state == FtpInterface::Connected) {
                qDebug() << "Connected to backend" << backend;
                QObject::disconnect(connection);   
                useBackend(backend);           
                Q_EMIT q->stateChanged(state);                
            } else if (state == FtpInterface::Unconnected) {
                backend->deleteLater();                             
                tryNextBackend(host, port, username, password);
            }                                                                 
        });                                                                   
                                                                   
    backend->login(host, port, username, password);

It was crashing when the lambda function was invoked (though, sometimes, much later than that), and valgrind was reporting errors in the constructor of the connection variable, claiming that it was trying to use some memory which had been already deallocated by... roll of drums ...by the qDebug() on line 3!

I quickly assumed that the error had to be some memory corruption happening well before the call to qDebug, and that valgrind was for some reason not detecting the real error. And indeed, even by commenting out the qDebug() statement, the crash would still occur, just with a different cause.

Well, can you spot the error? I'll add a few blank lines here not to immediately give out the answer, so scroll down if you want to reveal it:

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

Well, the problem is that in the lambda function we are using the QMetaObject::Connection which was returned by the QObject::connect() call, except that by the time that the lambda captures the scope variables the connection variable hasn't been assigned yet! That's because, of course, first the compiler captures the local variables for the lambda, then the lambda is generated, then QObject::connect() is called, and only once it returns we have a properly initialized QMetaObject::Connection. It's obvious when you think about it, but it might not be as obvious when you read the code line by line.

And is this silly mistake of mine really worth writing a blog post about? Well, if you consider that I had encountered (and solved) the same exact issue just a few months before, in the very same project, then yes, putting it on words might definitely help my poor memory! :-)

For the sake of completeness, here's how the issue can be solved (if you know of more elegant solutions, please comment!):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    FtpInterface *backend = createBackend(nextBackend);                                                
    
    qDebug() << "trying login with backend" << backend;
    QSharedPointer<QMetaObject::Connection> connection(new QMetaObject::Connection);                   
    *connection =
        QObject::connect(backend, &FtpInterface::stateChanged,                                         
                         [=](FtpInterface::State state) {                                              
            if (state == FtpInterface::Connected) {
                qDebug() << "Connected to backend" << backend;                                         
                QObject::disconnect(*connection);
                useBackend(backend);
                Q_EMIT q->stateChanged(state);
            } else if (state == FtpInterface::Unconnected) {                                           
                backend->deleteLater();
                tryNextBackend(host, port, username, password);                                        
            }                                                                                          
        });                                                                                            
    
    backend->login(host, port, username, password);                                                    

In this way, while it's true that the QMetaObject::Connection object is still unitialized by the time we invoke QObject::connect(), the connection variable now refers to a fully initialized QSharedPointer that wraps our connection and that can be safely captured by the lambda.

I hope that you have a better memory than mine, so that this piece of advice might come useful the next time you are playing with QMetaObject::Connections and lambdas. :-)

Etichette: , ,

lunedì 7 maggio 2018

Cammino quindi penso - 2018-05-07 - Libertà di parola



La libertà di parola, quanto è tutelata dalla nostra costituzione e perché questo, secondo me, non basta.



Ecco il link al video del giornalista americano Tim Pool a proposito della situazione in USA.


Etichette: , ,

sabato 5 maggio 2018

Pensatas in interlingua - 2018-05-04 - Le problema del calculationes electoral



Si le candidato o le partito politic que vos supporta ha nulle chance practic de obtener un placia in le arena politic, esque vos lo vota in omne caso, o vos decide de votar pro un altere, minus simile a vostre ideas, ma con plus possibilitate de vincer?

Etichette: , ,