Added cout/cerr that output to Android log to STLPort, fixed broken compilation for NDK r4b

This commit is contained in:
pelya
2010-12-21 14:29:52 +00:00
parent 4d16a4dc88
commit ea051bb11f
5 changed files with 121 additions and 4 deletions

View File

@@ -16,9 +16,11 @@
#include "SDL.h"
#include "SDL_image.h"
#include "test.h"
#include "ballfield.h"
/*----------------------------------------------------------
General tool functions
----------------------------------------------------------*/
@@ -359,6 +361,8 @@ int main(int argc, char* argv[])
int fps_start = 0;
float x_speed, y_speed, z_speed;
__android_log_print(ANDROID_LOG_INFO, "==TEST==", "SDL_Main: test::initCount %d test::initCount2", test::initCount, test::initCount2);
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);

View File

@@ -1 +1 @@
ballfield
fheroes2

View File

@@ -57,6 +57,7 @@ using _STLP_VENDOR_CSTD::_streams;
// the stream objects by calling the init() member function.
#if defined (ANDROID_NO_COUT)
#include <android/log.h>
/* Outputting anything to cout/cerr WILL CRASH YOUR PROGRAM on specific devices -
x5a/x6d Android 2.1 tablet, and some other tablets,
however the same code runs on my HTC Evo without problem.
@@ -64,20 +65,130 @@ using _STLP_VENDOR_CSTD::_streams;
*/
long ios_base::Init::_S_count = 0;
// by default, those are synced
bool ios_base::_S_was_synced = true;
ios_base::Init::Init() {
if (_S_count++ == 0) {
_Locale_init();
//ios_base::_S_initialize();
_Filebuf_base::_S_initialize();
}
}
ios_base::Init::~Init() {
if (--_S_count == 0) {
//ios_base::_S_uninitialize();
_Locale_final();
}
}
class _android_debugbuf: public streambuf
{
public:
_android_debugbuf()
{
pos = 0;
buf[0] = 0;
}
protected:
virtual int overflow(int c = EOF)
{
if (EOF == c)
{
return '\0'; // returning EOF indicates an error
}
else
{
outputchar(c);
return c;
}
};
// we dont do input so always return EOF
virtual int uflow() {return EOF;}
// we dont do input so always return 0 chars read
virtual int xsgetn(char *, int) {return 0;}
// Calls outputchar() for each character.
virtual int xsputn(const char *s, int n)
{
for (int i = 0; i < n; ++i)
{
outputchar(s[i]);
}
return n;// we always process all of the chars
};
private:
// the buffer
char buf[256];
int pos;
void outputchar(char c)
{
// TODO: mutex
if( pos >= sizeof(buf)-1 || c == '\n' || c == '\r' || c == 0 )
{
buf[pos] = 0;
__android_log_print(ANDROID_LOG_INFO, "libSDL", "%s", buf);
pos = 0;
};
buf[pos] = c;
pos++;
};
};
class debugbufinit
{
static unsigned int count;
public:
debugbufinit();
// Our destructor is not virtual. It is important that objects of this class have no
// memory footprint. We will end up with one object of this class per translation
// unit (.cp file). If this class has any virtual member functions then objects of
// this class would have v tables in memory. Since this is not intended to be a
// base class for other class, there is no need to be virtual.
~debugbufinit();
};
static filebuf*
_Stl_create_filebuf(int f, ios_base::openmode mode ) {
basic_filebuf<char, char_traits<char> >* result =
new basic_filebuf<char, char_traits<char> >();
_STLP_TRY {
result->_M_open(f, mode);
}
_STLP_CATCH_ALL {}
if (!result->is_open()) {
delete result;
result = 0;
}
return result;
}
static ios_base::Init _IosInit;
bool _STLP_CALL ios_base::sync_with_stdio(bool sync)
{
}
_STLP_DECLSPEC istream cin(_Stl_create_filebuf(0, ios_base::in));
_STLP_DECLSPEC ostream cout(new _android_debugbuf());
_STLP_DECLSPEC ostream cerr(new _android_debugbuf());
_STLP_DECLSPEC ostream clog(new _android_debugbuf());
#else
#if defined (_STLP_USE_NOT_INIT_SEGMENT)

View File

@@ -579,7 +579,9 @@ static locale* _Stl_get_global_locale() {
# pragma init_seg(lib)
#endif
#if !defined(ANDROID) && !defined(__ANDROID__)
static ios_base::Init _IosInit;
#endif
void _Locale_impl::make_classic_locale() {
// This funcion will be called once: during build classic _Locale_impl

View File

@@ -70,15 +70,15 @@
#if defined(__ANDROID__) /* NDK r5 */
# define _STLP_NATIVE_CPP_C_INCLUDE_PATH ../../../cxx-stl/system/include
# define _STLP_NATIVE_CPP_RUNTIME_INCLUDE_PATH ../../../cxx-stl/system/include
#else /* NDK r4b */
# define _STLP_NATIVE_CPP_C_INCLUDE_PATH ../../usr/include
# define _STLP_NATIVE_CPP_RUNTIME_INCLUDE_PATH ../../usr/include
#endif
#ifdef __cplusplus
// Hack to prevent including buggy stl_pair.h system header, introduced in Android 1.6 NDK
#define _CPP_UTILITY 1
#define __SGI_STL_INTERNAL_PAIR_H 1
//#include <stddef.h>
//inline void* operator new(size_t, void* p) { return p; }
//inline void* operator new[](size_t, void* p) { return p; }
#endif
#endif /* __stl_config__android_h */