Jump to content

  • Log In with Google      Sign In   
  • Create Account

TheComet

Member Since 02 Oct 2013
Offline Last Active Today, 01:08 PM

Topics I've Started

Trying to write a startup script for sympy

24 October 2015 - 09:37 AM

Hey guys

 

I have the following script:

 

#!/usr/bin/env python3


from numpy import *
from matplotlib.pyplot import *
from sympy import init_session


if __name__ == '__main__':
    init_session(auto_int_to_Integer=True, ipython=True, pretty_print=True)
This will drop you to a CLI once it completes. Here's the problem: It seems none of the functions from numpy or matplotlib.pyplot were imported. If I use one, say linspace, I get:
 
In [1]: linspace
NameError: name 'linspace' is not defined
How can I import custom things into the command line environment?

Worst Hotfixes

11 August 2015 - 05:26 AM

In this thread we share stories of some of the worst hotfixes we've seen and/or applied.

 

In a game I had to present I was experiencing an extremely obscure bug where after some time pointers would randomly point to garbage values, crashing the game. I had an hour to get it working before the presentation.

 

I spent 45 minutes trying to reproduce it with no success. It happened at seemingly random times, but for some reason it was always the same two pointers that were modified.

 

Seeing as I was running out of time, I ended up inserting checks which would replace the garbage value (when it occurred) with the correct value again - the correct value I knew because I saw it in the debugger and it seemed to remain consistent.

if(game->settings_doc != 0x63e1b0)
    game->settings_doc = 0x63e1b0; /* from debugger */

After the presentation I sat down with valgrind and found the problem. A buffer overrun was writing into memory it wasn't supposed to.


Breaking out of a nested loop

25 July 2015 - 12:13 PM

I'm a little disappointed to say the least that breaking from a nested loop feels this dirty in C/C++. It's not an uncommon occurrence, and yet, the "cleanest" solution we have is to use a label and a goto statement. 

 

(Obligatory xkcd joke)

 

In C/C++ the "cleanest" code for breaking from an inner loop:

int i, j;
for(i = 0; i < 10; i++) {
    for(j = 0; j < 10; j++) {
        if(i - 1 == j + 1)
            goto outer;
    }
}
outer:

I feel like we need a new keyword. Perhaps a break_harder or combo_break keyword to break from 2 loops or something?

 

Turns out PHP has this feature. In PHP:

<?php
for($i = 0; $i < 10; $i++) {
    for($j = 0; $j < 10; $j++) {
        if($i - 1 == $j + 1)
            break 2;
    }
}
?>

In Java you can use named blocks to achieve the same result:

outer: {
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j < 10; j++) {
            if(i - 1 == j + 1)
                break outer;
        }
    }
}

How do you guys do this in C/C++? Do you think having a break statement like in PHP would be beneficial in C/C++?

 

People have told me to extract the loops into a separate static function and use return instead of a goto. Do you think this is better practice?


Java Integer and Double memory question

01 July 2015 - 04:14 PM

public class Test {
    public static void main(String[] args) {
        Double d11 = 12.45;
        Double d12 = 12.45;


        Double d21 = 12.45;
        Double d22 = new Double(12.45);


        Integer i11 = 10;
        Integer i12 = 10;


        Integer i21 = 10;
        Integer i22 = new Integer(10);


        System.out.println((d11 == d12 ? "true" : "false"));
        System.out.println((d21 == d22 ? "true" : "false"));
        System.out.println((i11 == i12 ? "true" : "false"));
        System.out.println((i21 == i22 ? "true" : "false"));
    }
}
 

Can someone explain to me why the output is this?

false
false
true
false

Why are the integers implicitly referencing the same Integer object but the doubles are not? This can be seen when looking at the memory locations:

 

zxBjQWv.jpg


Buildbot - "no changes detected"

01 June 2015 - 04:37 AM

I'm using Buildbot for integration testing and deployment for my project and I'm having trouble with a specific case.

 

I've configured it to run all unit tests when pushing to branch "devel", and I've configured it to cross compile and deploy to all platforms when pushing to branch "master".

 

Here's an excerpt from my config file:

# schedulers for push events to devel and master branches
c['schedulers'].append(basic.SingleBranchScheduler(name="checkin-devel",
        change_filter=filter.ChangeFilter(branch="devel"),
        treeStableTimer=2,
        builderNames=["test-gameserver", "test-applebloom"]))


c['schedulers'].append(basic.SingleBranchScheduler(name="checkin-master",
        change_filter=filter.ChangeFilter(branch="master"),
        treeStableTimer=2,
        builderNames=["deploy-gameserver", "deploy-applebloom"]))






# when pushing to master, checkout, cross compile for all platforms, test, and upload to /www/game/lightship
# gameserver ###################
factory = util.BuildFactory()
factory.addStep(step_checkout_master)
factory.addStep(step_test_build_linux)
factory.addStep(step_test_linux)
factory.addStep(step_compile_x86_64_linux)
factory.addStep(step_cross_x86_64_windows)
factory.addStep(step_cross_i686_windows)
factory.addStep(step_upload_dist)
factory.addStep(step_clean_dist)
c['builders'].append(util.BuilderConfig(
        name="deploy-gameserver",
        slavenames=["slave-lightship-gameserver"],
        factory=factory))
# applebloom ###################
factory = util.BuildFactory()
factory.addStep(step_checkout_master)
factory.addStep(step_test_build_macosx)
factory.addStep(step_test_macosx)
factory.addStep(step_compile_x86_64_macosx)
factory.addStep(step_upload_dist)
factory.addStep(step_clean_dist)
c['builders'].append(util.BuilderConfig(
        name="deploy-applebloom",
        slavenames=["slave-lightship-applebloom"],
        factory=factory))


# when pushing to devel, checkout and test
# gameserver ###################
factory = util.BuildFactory()
factory.addStep(step_checkout_devel)
factory.addStep(step_test_build_linux)
factory.addStep(step_test_linux)
c['builders'].append(util.BuilderConfig(
        name="test-gameserver",
        slavenames=["slave-lightship-gameserver"],
        factory=factory))
# applebloom ###################
factory = util.BuildFactory()
factory.addStep(step_checkout_devel)
factory.addStep(step_test_build_macosx)
factory.addStep(step_test_macosx)
c['builders'].append(util.BuilderConfig(
        name="test-applebloom",
        slavenames=["slave-lightship-applebloom"],
        factory=factory))

The problem occurs when merging branch "devel" into "master" and pushing master. Because the HEAD of both branches have the same commit hash at this point, Buildbot decides to not build master even though I want it to. Here's the log file for this exact case:

2015-06-01 12:40:34+0200 [HTTPChannel,0,127.0.0.1] X-GitHub-Event: 'push'
2015-06-01 12:40:34+0200 [HTTPChannel,0,127.0.0.1] Commit `7ce18ba601b0ee69973a64b73e25bcf5fe8ff0c6` is a non-distinct commit, ignoring...
2015-06-01 12:40:34+0200 [HTTPChannel,0,127.0.0.1] Commit `3db1b8da4997c9cf1389acfe394b73d3ddc21072` is a non-distinct commit, ignoring...
2015-06-01 12:40:34+0200 [HTTPChannel,0,127.0.0.1] Commit `af4ddab0b4db92ca3b40bc4a0df7ea7598ae490b` is a non-distinct commit, ignoring...
2015-06-01 12:40:34+0200 [HTTPChannel,0,127.0.0.1] Received 0 changes from github
2015-06-01 12:40:34+0200 [HTTPChannel,0,127.0.0.1] Got the following changes []
2015-06-01 12:40:34+0200 [HTTPChannel,0,127.0.0.1] Payload: {}
2015-06-01 12:40:34+0200 [HTTPChannel,0,127.0.0.1] No changes found

 

How can I force Buildbot to build every push that goes to master?


PARTNERS