Added cout/cerr that output to Android log to STLPort, fixed broken compilation for NDK r4b
This commit is contained in:
@@ -16,9 +16,11 @@
|
|||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include "SDL_image.h"
|
#include "SDL_image.h"
|
||||||
|
|
||||||
|
#include "test.h"
|
||||||
#include "ballfield.h"
|
#include "ballfield.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------
|
/*----------------------------------------------------------
|
||||||
General tool functions
|
General tool functions
|
||||||
----------------------------------------------------------*/
|
----------------------------------------------------------*/
|
||||||
@@ -359,6 +361,8 @@ int main(int argc, char* argv[])
|
|||||||
int fps_start = 0;
|
int fps_start = 0;
|
||||||
float x_speed, y_speed, z_speed;
|
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);
|
SDL_Init(SDL_INIT_VIDEO);
|
||||||
|
|
||||||
atexit(SDL_Quit);
|
atexit(SDL_Quit);
|
||||||
@@ -1 +1 @@
|
|||||||
ballfield
|
fheroes2
|
||||||
@@ -57,6 +57,7 @@ using _STLP_VENDOR_CSTD::_streams;
|
|||||||
// the stream objects by calling the init() member function.
|
// the stream objects by calling the init() member function.
|
||||||
|
|
||||||
#if defined (ANDROID_NO_COUT)
|
#if defined (ANDROID_NO_COUT)
|
||||||
|
#include <android/log.h>
|
||||||
/* Outputting anything to cout/cerr WILL CRASH YOUR PROGRAM on specific devices -
|
/* Outputting anything to cout/cerr WILL CRASH YOUR PROGRAM on specific devices -
|
||||||
x5a/x6d Android 2.1 tablet, and some other tablets,
|
x5a/x6d Android 2.1 tablet, and some other tablets,
|
||||||
however the same code runs on my HTC Evo without problem.
|
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;
|
long ios_base::Init::_S_count = 0;
|
||||||
|
// by default, those are synced
|
||||||
|
bool ios_base::_S_was_synced = true;
|
||||||
|
|
||||||
ios_base::Init::Init() {
|
ios_base::Init::Init() {
|
||||||
if (_S_count++ == 0) {
|
if (_S_count++ == 0) {
|
||||||
_Locale_init();
|
_Locale_init();
|
||||||
|
//ios_base::_S_initialize();
|
||||||
_Filebuf_base::_S_initialize();
|
_Filebuf_base::_S_initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ios_base::Init::~Init() {
|
ios_base::Init::~Init() {
|
||||||
if (--_S_count == 0) {
|
if (--_S_count == 0) {
|
||||||
|
//ios_base::_S_uninitialize();
|
||||||
_Locale_final();
|
_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 don’t do input so always return EOF
|
||||||
|
virtual int uflow() {return EOF;}
|
||||||
|
|
||||||
|
// we don’t 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
|
#else
|
||||||
|
|
||||||
#if defined (_STLP_USE_NOT_INIT_SEGMENT)
|
#if defined (_STLP_USE_NOT_INIT_SEGMENT)
|
||||||
|
|||||||
@@ -579,7 +579,9 @@ static locale* _Stl_get_global_locale() {
|
|||||||
# pragma init_seg(lib)
|
# pragma init_seg(lib)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(ANDROID) && !defined(__ANDROID__)
|
||||||
static ios_base::Init _IosInit;
|
static ios_base::Init _IosInit;
|
||||||
|
#endif
|
||||||
|
|
||||||
void _Locale_impl::make_classic_locale() {
|
void _Locale_impl::make_classic_locale() {
|
||||||
// This funcion will be called once: during build classic _Locale_impl
|
// This funcion will be called once: during build classic _Locale_impl
|
||||||
|
|||||||
@@ -70,15 +70,15 @@
|
|||||||
#if defined(__ANDROID__) /* NDK r5 */
|
#if defined(__ANDROID__) /* NDK r5 */
|
||||||
# define _STLP_NATIVE_CPP_C_INCLUDE_PATH ../../../cxx-stl/system/include
|
# define _STLP_NATIVE_CPP_C_INCLUDE_PATH ../../../cxx-stl/system/include
|
||||||
# define _STLP_NATIVE_CPP_RUNTIME_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
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
// Hack to prevent including buggy stl_pair.h system header, introduced in Android 1.6 NDK
|
// Hack to prevent including buggy stl_pair.h system header, introduced in Android 1.6 NDK
|
||||||
#define _CPP_UTILITY 1
|
#define _CPP_UTILITY 1
|
||||||
#define __SGI_STL_INTERNAL_PAIR_H 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
|
||||||
|
|
||||||
#endif /* __stl_config__android_h */
|
#endif /* __stl_config__android_h */
|
||||||
|
|||||||
Reference in New Issue
Block a user