[PATCH] OS X python framework issue

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
Vezzra
Release Manager, Design
Posts: 6090
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

[PATCH] OS X python framework issue

#1 Post by Vezzra »

Ok, looks like I just succeeded in my first attempt to fix a FO bug 8)

The problem was that on OS X you had to install the python 2.7 package, although the python 2.7 framework is included in the FO app bundle and the code is set up to to use the bundled framework. Nevertheless, when the python 2.7 package has not been installed separately, the game hang when trying to set up the ai clients. Attached to this post is the patch I came up with to work around the issue - it's a rather crude hack, but now everything should work just fine on OS X.

I won't elaborate in detail on what I found to be the problem, or how I found out how to solve it, unless someone really wants to know - it's a rather lengthy story. All I'm going to say for now is, it has been a very strange journey, and probably one of the nastiest bugs I had to track down since I first laid hands on a computer... :? The culprit turned out to be the dynamic linker.

More important are these issues i ran into when I tried to fix this beast of a bug:

I first worked with a working copy at revision 4502. I tried several things, modifying a few pieces of code, reverting back, trying different things, and producing some failed builds in the process. Finally I found a solution that worked - at least, as far as the issue itself was concerned. Unfortunately, when I played a quick test game, every time a combat had to be resolved, apparently the server crashed (got the message "connection to server lost"). I tried to find out which of my changes (which happen to be just 3 lines of code!) could have triggered the problem, and finally reverted my working copy back to unmodified svn rev 4502 - but the issue persisted?!?!?!?!

Interestingly enough another 4502 build I produced earlier didn't show this issue - combats were resolved just fine. So that ruled out the possibility that I maybe might have messed up something on my system.

So I finally came up with the idea to apply my patch to a working copy at rev 4471. Et voila - it worked like a charm! AI clients started up just fine, regardless if a python 2.7 framework was available or not besides the one bundled with the app. Also the AI log files showed that the python library from the app bundle was used in every case - this I could tell because in the AI log files the version of the python library used is reported, and the python package I installed on my system is 2.7.2 while the one bundled with the FO app is 2.7.1.

Can anyone give me a hint what is going on here...? And what I could do to solve this strange issue? I'd really like to continue to work with the head revision...

The patch itself seems to be okay, it doesn't do anything besides setting an environment variable anyway. Unfortunately I can't test it on recent revisions for obvious reasons, so if someone an a Mac could test it, that would be great - night? :wink:

EDIT: Attention! Patch has been revised, please don't use the file attached to this post (contains unsafe code!), revised patch has been attached to post below.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]

Last edited by Vezzra on Fri Dec 02, 2011 12:02 am, edited 1 time in total.

User avatar
Vezzra
Release Manager, Design
Posts: 6090
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: [PATCH] OS X python framework issue

#2 Post by Vezzra »

Ok, a complete rebuild of the project solved the issues. Combat seems to work fine again. The new parser seems to push the compiler really to it's limits though - not only that some of the parser source files need to be build separately, there were even one or two that only build successfully after the 2nd try... :?

User avatar
Vezzra
Release Manager, Design
Posts: 6090
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: [PATCH] OS X python framework issue

#3 Post by Vezzra »

I have revised my python patch. I placed a setenv() call between fork() and the subsequent execv() in the child process (to set an environment variable which would cause the dynamic linker to look for the python library in the python framework folder bundled with the app). According to the fork() man pages this is not save. In the child process fork() should be immediately followed by one of the exec() calls. So I moved my code into ServerApp::CreateAIClients.

Run a quick test, fix worked.

Patch attached. Please use this patch and not the one attached to OP.
Attachments

[The extension patch has been deactivated and can no longer be displayed.]


Post Reply