Trying to set up an autorelease pool, but not yet succeeding.

develop
Timothy Collett 2012-05-26 16:08:15 -04:00
parent 1dd4cc5667
commit 7ec0fd6fc0
6 changed files with 90 additions and 5 deletions

@ -49,6 +49,10 @@ SET(MAIN_HEADERS_WINDOWS
include/wdirent.h include/wdirent.h
) )
SET(MAIN_HEADERS_DARWIN
MacPool.h
)
SET(MAIN_SOURCES SET(MAIN_SOURCES
Core.cpp Core.cpp
ColorText.cpp ColorText.cpp
@ -94,7 +98,10 @@ Console-darwin.cpp
Hooks-darwin.cpp Hooks-darwin.cpp
PlugLoad-darwin.cpp PlugLoad-darwin.cpp
Process-darwin.cpp Process-darwin.cpp
#MacPool.m )
SET(OBJC_SOURCES_DARWIN
MacPool.mm
) )
SET(MAIN_SOURCES_LINUX_EGGY SET(MAIN_SOURCES_LINUX_EGGY
@ -165,6 +172,11 @@ IF(UNIX)
LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX_EGGY}) LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX_EGGY})
ELSEIF(APPLE) ELSEIF(APPLE)
LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_DARWIN}) LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_DARWIN})
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -m32 -march=i686 -mtune=generic")
SET(CPP_SOURCES)
LIST(APPEND CPP_SOURCES ${PROJECT_SOURCES})
LIST(APPEND PROJECT_SOURCES ${OBJC_SOURCES_DARWIN})
LIST(APPEND PROJECT_HEADERS ${MAIN_HEADERS_DARWIN})
ELSE() ELSE()
LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX}) LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX})
ENDIF() ENDIF()
@ -219,6 +231,23 @@ ELSE(WIN32)
PROPERTIES COMPILE_FLAGS "/O1 /bigobj") PROPERTIES COMPILE_FLAGS "/O1 /bigobj")
ENDIF() ENDIF()
if(APPLE)
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden -m32 -mtune=generic" )
foreach(f ${PROJECT_SOURCES})
if(f MATCHES MacPool.mm)
MESSAGE(STATUS "Not setting properties for ${f}")
SET_SOURCE_FILES_PROPERTIES(${f} PROPERTIES COMPILE_FLAGS "-arch i386 -framework Foundation -x objective-c")
else()
if(f MATCHES MacPool.h)
else()
SET_SOURCE_FILES_PROPERTIES(${f} PROPERTIES COMPILE_FLAGS "-std=c++0x -march=i686")
MESSAGE(STATUS "Setting properties for ${f}")
endif()
endif()
endforeach()
SET_SOURCE_FILES_PROPERTIES(dfhack-run.cpp PROPERTIES COMPILE_FLAGS "-std=c++0x -march=i686")
SET(CMAKE_SHARED_LINKER_FLAGS "-arch i386")
endif()
# Compilation # Compilation
@ -271,6 +300,7 @@ SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
IF(APPLE) IF(APPLE)
SET(SDL_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/SDL.framework) SET(SDL_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/SDL.framework)
TARGET_LINK_LIBRARIES(dfhack ${SDL_LIBRARY}) TARGET_LINK_LIBRARIES(dfhack ${SDL_LIBRARY})
TARGET_LINK_LIBRARIES(dfhack /System/Library/Frameworks/Foundation.framework)
SET_TARGET_PROPERTIES(dfhack PROPERTIES VERSION 1.0.0) SET_TARGET_PROPERTIES(dfhack PROPERTIES VERSION 1.0.0)
SET_TARGET_PROPERTIES(dfhack PROPERTIES SOVERSION 1.0.0) SET_TARGET_PROPERTIES(dfhack PROPERTIES SOVERSION 1.0.0)
ENDIF() ENDIF()

@ -279,21 +279,29 @@ static command_result runLuaScript(color_ostream &out, std::string filename, vec
command_result Core::runCommand(color_ostream &out, const std::string &command) command_result Core::runCommand(color_ostream &out, const std::string &command)
{ {
fprintf(stderr,"Inside runCommand");
fprintf(stderr," with command %s\n",command.c_str());
if (!command.empty()) if (!command.empty())
{ {
fprintf(stderr,"Command is not empty, tokenizing\n");
vector <string> parts; vector <string> parts;
Core::cheap_tokenise(command,parts); Core::cheap_tokenise(command,parts);
fprintf(stderr,"Tokenized, got %d parts\n",parts.size());
if(parts.size() == 0) if(parts.size() == 0)
return CR_NOT_IMPLEMENTED; return CR_NOT_IMPLEMENTED;
string first = parts[0]; string first = parts[0];
fprintf(stderr,"Erasing beginning\n");
parts.erase(parts.begin()); parts.erase(parts.begin());
fprintf(stderr,"I think we're about there\n");
if (first[0] == '#') if (first[0] == '#')
return CR_OK; return CR_OK;
cerr << "Invoking: " << command << endl; cerr << "Invoking: " << command << endl;
fprintf(stderr,"Returning with the next recursion\n");
return runCommand(out, first, parts); return runCommand(out, first, parts);
} }
else else
@ -674,6 +682,7 @@ void fIOthread(void * iodata)
{ {
string command = ""; string command = "";
int ret = con.lineedit("[DFHack]# ",command, main_history); int ret = con.lineedit("[DFHack]# ",command, main_history);
fprintf(stderr,"Command: [%s]\n",command.c_str());
if(ret == -2) if(ret == -2)
{ {
cerr << "Console is shutting down properly." << endl; cerr << "Console is shutting down properly." << endl;
@ -687,10 +696,14 @@ void fIOthread(void * iodata)
else if(ret) else if(ret)
{ {
// a proper, non-empty command was entered // a proper, non-empty command was entered
fprintf(stderr,"Adding command to history\n");
main_history.add(command); main_history.add(command);
fprintf(stderr,"Saving history\n");
main_history.save("dfhack.history"); main_history.save("dfhack.history");
} }
fprintf(stderr,"Running command\n");
auto rv = core->runCommand(con, command); auto rv = core->runCommand(con, command);
if (rv == CR_NOT_IMPLEMENTED) if (rv == CR_NOT_IMPLEMENTED)

@ -49,8 +49,6 @@ distribution.
#include "Hooks.h" #include "Hooks.h"
#include <iostream> #include <iostream>
#include "MacPool.h"
/*static const interpose_t interposers[] __attribute__ ((section("__DATA, __interpose"))) = /*static const interpose_t interposers[] __attribute__ ((section("__DATA, __interpose"))) =
{ {
{ (void *)DFH_SDL_Init, (void *)SDL_Init }, { (void *)DFH_SDL_Init, (void *)SDL_Init },
@ -60,6 +58,9 @@ distribution.
};*/ };*/
extern "C" int create_pool();
extern "C" int destroy_pool();
/******************************************************************************* /*******************************************************************************
* SDL part starts here * * SDL part starts here *
*******************************************************************************/ *******************************************************************************/
@ -81,7 +82,7 @@ DFhackCExport void SDL_Quit(void)
_SDL_Quit(); _SDL_Quit();
}*/ }*/
// destroy_pool(); destroy_pool();
_SDL_Quit(); _SDL_Quit();
} }
@ -140,7 +141,7 @@ DFhackCExport int SDL_Init(uint32_t flags)
// we don't reroute stdout until we figure out if this should be done at all // we don't reroute stdout until we figure out if this should be done at all
// See: Console-linux.cpp // See: Console-linux.cpp
// create_pool(); create_pool();
// find real functions // find real functions
fprintf(stderr,"dfhack: saving real SDL functions\n"); fprintf(stderr,"dfhack: saving real SDL functions\n");

@ -0,0 +1,12 @@
/*
* MacPool.h
* Handles creation and destruction of autorelease pool for DFHack on the Mac
*/
#ifndef MACPOOL_H
#define MACPOOL_H
int create_pool();
int destroy_pool();
#endif

@ -0,0 +1,22 @@
/*
* MacPool.m
*
*/
#import <Foundation/Foundation.h>
#import "MacPool.h"
NSAutoreleasePool *thePool;
int create_pool() {
fprintf(stderr,"Creating autorelease pool\n");
thePool = [[NSAutoreleasePool alloc] init];
return 1;
}
int destroy_pool() {
fprintf(stderr,"Draining and releasing autorelease pool\n");
[thePool drain];
[thePool release];
return 0;
}

@ -65,13 +65,20 @@ namespace DFHack
bool save (const char * filename) bool save (const char * filename)
{ {
std::ofstream outfile (filename); std::ofstream outfile (filename);
fprintf(stderr,"Save: Initialized stream\n");
if(outfile.bad()) if(outfile.bad())
return false; return false;
fprintf(stderr,"Save: Iterating...\n");
for(auto iter = history.begin();iter < history.end(); iter++) for(auto iter = history.begin();iter < history.end(); iter++)
{ {
fprintf(stderr,"Save: Dumping %s\n",(*iter).c_str());
outfile << *iter << std::endl; outfile << *iter << std::endl;
fprintf(stderr,"Save: Flushing\n");
outfile.flush();
} }
fprintf(stderr,"Save: Closing\n");
outfile.close(); outfile.close();
fprintf(stderr,"Save: Done\n");
return true; return true;
} }
/// add a command to the history /// add a command to the history