64 bit support required

Issue #11 new
Joseba Echevarria García repo owner created an issue

The code does not yet work correctly in 64bit OSes.

This is a dealbreaker for supporting iOS (Apple won't accept any apps in the iOS Store which is not compiled in both 32bits and 64bits modes) and is certainly not acceptable in 2015.

Part of the problem is because PixTudio relies heavily in converting pointers to 32 bit integers, which will not work in many cases in a 64bit computer.

The following code from modules/mod_file/mod_file.c illustrates the problem:

static int modfile_fopen( INSTANCE * my, int * params )
{
    static char * ops[] = { "rb0", "r+b0", "wb0", "rb", "wb6" } ;
    int r ;

    if ( params[1] < 0 || params[1] > 4 )
        params[0] = 0 ;

    r = ( int ) file_open( string_get( params[0] ), ops[params[1]] ) ;     // <--- PROBLEM
    string_discard( params[0] ) ;
    return r ;
}

The code could instead be storing a table of valid FILE objects and return the index of the pointer in the table.

Comments (2)

  1. Joseba Echevarria García reporter

    Instead of creating an in-memory table, we could also define a new data type mapping uintptr_t whose size would be machine-dependant and make sure that all pointers are returned in this fashion.

    This approach is simpler than creating tables, but we should find some consistent way of implementing it, since some loading functions return an integer (an ID in a table) whereas others return an integer masquerading a pointer...

  2. Joseba Echevarria García reporter

    TYPE_POINTER is assumed to be of size 4 (32bits) in lots of places in the code.

    It should be changed to type uintprt_t, defined in <stdint.h> and the size should be computed dynamically (it will probably be 4 for 32bit programs and 8 for 64 bit ones).

  3. Log in to comment