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
)
SET(MAIN_HEADERS_DARWIN
MacPool.h
)
SET(MAIN_SOURCES
Core.cpp
ColorText.cpp
@ -94,7 +98,10 @@ Console-darwin.cpp
Hooks-darwin.cpp
PlugLoad-darwin.cpp
Process-darwin.cpp
#MacPool.m
)
SET(OBJC_SOURCES_DARWIN
MacPool.mm
)
SET(MAIN_SOURCES_LINUX_EGGY
@ -165,6 +172,11 @@ IF(UNIX)
LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX_EGGY})
ELSEIF(APPLE)
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()
LIST(APPEND PROJECT_SOURCES ${MAIN_SOURCES_LINUX})
ENDIF()
@ -219,6 +231,23 @@ ELSE(WIN32)
PROPERTIES COMPILE_FLAGS "/O1 /bigobj")
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
@ -271,6 +300,7 @@ SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
IF(APPLE)
SET(SDL_LIBRARY ${CMAKE_INSTALL_PREFIX}/libs/SDL.framework)
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 SOVERSION 1.0.0)
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)
{
fprintf(stderr,"Inside runCommand");
fprintf(stderr," with command %s\n",command.c_str());
if (!command.empty())
{
fprintf(stderr,"Command is not empty, tokenizing\n");
vector <string> parts;
Core::cheap_tokenise(command,parts);
fprintf(stderr,"Tokenized, got %d parts\n",parts.size());
if(parts.size() == 0)
return CR_NOT_IMPLEMENTED;
string first = parts[0];
fprintf(stderr,"Erasing beginning\n");
parts.erase(parts.begin());
fprintf(stderr,"I think we're about there\n");
if (first[0] == '#')
return CR_OK;
cerr << "Invoking: " << command << endl;
fprintf(stderr,"Returning with the next recursion\n");
return runCommand(out, first, parts);
}
else
@ -674,6 +682,7 @@ void fIOthread(void * iodata)
{
string command = "";
int ret = con.lineedit("[DFHack]# ",command, main_history);
fprintf(stderr,"Command: [%s]\n",command.c_str());
if(ret == -2)
{
cerr << "Console is shutting down properly." << endl;
@ -687,9 +696,13 @@ void fIOthread(void * iodata)
else if(ret)
{
// a proper, non-empty command was entered
fprintf(stderr,"Adding command to history\n");
main_history.add(command);
fprintf(stderr,"Saving history\n");
main_history.save("dfhack.history");
}
fprintf(stderr,"Running command\n");
auto rv = core->runCommand(con, command);

@ -49,8 +49,6 @@ distribution.
#include "Hooks.h"
#include <iostream>
#include "MacPool.h"
/*static const interpose_t interposers[] __attribute__ ((section("__DATA, __interpose"))) =
{
{ (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 *
*******************************************************************************/
@ -81,7 +82,7 @@ DFhackCExport void SDL_Quit(void)
_SDL_Quit();
}*/
// destroy_pool();
destroy_pool();
_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
// See: Console-linux.cpp
// create_pool();
create_pool();
// find real functions
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)
{
std::ofstream outfile (filename);
fprintf(stderr,"Save: Initialized stream\n");
if(outfile.bad())
return false;
fprintf(stderr,"Save: Iterating...\n");
for(auto iter = history.begin();iter < history.end(); iter++)
{
fprintf(stderr,"Save: Dumping %s\n",(*iter).c_str());
outfile << *iter << std::endl;
fprintf(stderr,"Save: Flushing\n");
outfile.flush();
}
fprintf(stderr,"Save: Closing\n");
outfile.close();
fprintf(stderr,"Save: Done\n");
return true;
}
/// add a command to the history