operator::new[] overflow bug and Mac compilers

January 15, 2006

There’s a bug in the code generated operator new[] which causes potential overflow in VS C++ 2003 or previous versions. This seems to be fixed in VS C++ 2005. What about CodeWarrior and XCode (GCC 4.0):

struct Large {
char data[256*256];

void testlargeallloc(long num)
try {
Large* large = new Large[num] ();
for (int i = 0; i rlwinm r0,r0,16,0,15
0x0000daac mr r3,r0
0x0000dab0 bl 0xde80

The effect is a bit different from pre 2005 VisualC++ where the code crashes in new. Here the program crashes when trying to access the elements.


PyObjC vs PyDev: debugging/running PyObjC apps.

January 15, 2006
PyObjC is a Cocoa wrapper for python. PyDev is a python development environemnt for Eclipse. You can get debugging/running of a PyObjC appilication from eclipse.
Configuring a py2app builder:
First you have to create an OSX application with py2app. For me it looks something like:
python setup.py py2app --alias --dist-dir=Debug

This will create you an OSX bundle using links to refer resources and python sources (–alias flag). This is usefull since this allows you running uptodate version of the app without reexecuting setup.py.I usually add this thing to the Builders of the project:

  1. Right click on the project, select Builders
  2. Press New and select Program
  3. Fill in Edit launch configuration properties:
    1. Location: /usr/bin/python
    2. Working Directory: ${project_loc}
    3. Arguments: ${build_project:setup.py} py2app –alias –dist-dir=${project_loc}/Debug

To rerun setup.py, select Clean.. from Project menu.
Configuring a PyObjC application runner:

The next step is adding a pydev runner configuration to the project.

  1. From the Run menu select Run…
  2. Select Python Run and click New…
  3. In the main tab set the following:
    1. Project: click browse and select the project
    2. Main module: select the python file containing the main code for of the PyObjC app
  4. In the environment tab set the following:
    1. CFProcessPath: ${project_loc}/Debug/Foo.app/Contents/MacOS/Foo
      This is needed because the OS looks for nibs and other resources in the executable’s bundle. In this case the executable is the python interpreter /usr/bin/python – so  tell CoreFoundation to look for the resources in the Foo.app application package.
  5. Press apply to save the run configuration, then press Run to try it out. You should be able to debug with the same run configuration.