Commits

Lenard Lindstrom committed fb1a302

Apply issue #109 suggested bug fixes.

Use the submitted patches as a guide to making x86_64 compatibility fixes.
I decided to make font_index the correct type, long, rather than just
correct the format string. For bufferproxy, use conditional compilation
to choose the correct format string based on Python version.

Thanks lifning and cgohlke.

  • Participants
  • Parent commits 2b17654

Comments (0)

Files changed (5)

File src/_freetype.c

     };
 
     PyObject *file, *original_file;
-    int font_index = 0;
+    long font_index = 0;
     int ptsize;
     int style;
     int ucs4;
     vertical = self->render_flags & FT_RFLAG_VERTICAL ? 1 : 0;
     origin = self->render_flags & FT_RFLAG_ORIGIN ? 1 : 0;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iiIiiIi", kwlist,
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|iiliiIi", kwlist,
                                      &file, &ptsize, &style, &font_index,
                                      &vertical, &ucs4, &resolution, &origin)) {
         return -1;
  * C API CALLS
  ****************************************************/
 static PyObject *
-PgFont_New(const char *filename, int font_index)
+PgFont_New(const char *filename, long font_index)
 {
     PgFontObject *font;
 

File src/bufferproxy.c

 
 #define PYGAMEAPI_BUFFERPROXY_INTERNAL
 
+#define PY_SSIZE_T_CLEAN
 #define NO_PYGAME_C_API
 #include "pygame.h"
 #include "pgcompat.h"
     Py_ssize_t length;
     char *buf;
 
-    if (!PyArg_ParseTuple (args, "s#i", &buf, &length, &offset))
+#if PY_VERSION_HEX < 0x02050000
+#define FORMAT_STRING "s#i"
+#else
+#define FORMAT_STRING "s#n"
+#endif
+
+    if (!PyArg_ParseTuple (args, FORMAT_STRING, &buf, &length, &offset))
         return NULL;
 
     if (offset + length > buffer->length)
     memcpy (((Uint8 *)buffer->buffer) + offset, buf, (size_t) length);
 
     Py_RETURN_NONE;
+
+#undef FORMAT_STRING
 }   
 
 /**** Buffer interfaces ****/

File src/freetype.h

  **********************************************************/
 
 typedef struct {
-    int font_index;
+    FT_Long font_index;
     FT_Open_Args open_args;
 } PgFontId;
 
 
 #define PgFont_Check(x) ((x)->ob_type == (PyTypeObject*)PgFREETYPE_C_API[0])
 #define PgFont_Type (*(PyTypeObject*)PgFREETYPE_C_API[1])
-#define PgFont_New (*(PyObject*(*)(const char*, int))PgFREETYPE_C_API[1])
+#define PgFont_New (*(PyObject*(*)(const char*, long))PgFREETYPE_C_API[1])
 
 #define import_pygame_freetype() \
     _IMPORT_PYGAME_MODULE(freetype, FREETYPE, PgFREETYPE_C_API)

File src/freetype/ft_wrap.c

 _PGFT_TryLoadFont_Filename(FreeTypeInstance *ft,
     PgFontObject *fontobj,
     const char *filename,
-    int font_index)
+    long font_index)
 {
     char *filename_alloc;
     size_t file_len;
     strcpy(filename_alloc, filename);
     filename_alloc[file_len] = 0;
 
-    fontobj->id.font_index = font_index;
+    fontobj->id.font_index = (FT_Long) font_index;
     fontobj->id.open_args.flags = FT_OPEN_PATHNAME;
     fontobj->id.open_args.pathname = filename_alloc;
 
 
 int
 _PGFT_TryLoadFont_RWops(FreeTypeInstance *ft, PgFontObject *fontobj,
-                        SDL_RWops *src, int font_index)
+                        SDL_RWops *src, long font_index)
 {
     FT_Stream stream;
     int position;
     stream->size = (unsigned long)(SDL_RWtell(src) - position);
     SDL_RWseek(src, position, SEEK_SET);
 
-    fontobj->id.font_index = font_index;
+    fontobj->id.font_index = (FT_Long) font_index;
     fontobj->id.open_args.flags = FT_OPEN_STREAM;
     fontobj->id.open_args.stream = stream;
 

File src/freetype/ft_wrap.h

 int _PGFT_Font_IsFixedWidth(FreeTypeInstance *, PgFontObject *);
 const char *_PGFT_Font_GetName(FreeTypeInstance *, PgFontObject *);
 int _PGFT_TryLoadFont_Filename(FreeTypeInstance *,
-                               PgFontObject *, const char *, int);
+                               PgFontObject *, const char *, long);
 #ifdef HAVE_PYGAME_SDL_RWOPS
 int _PGFT_TryLoadFont_RWops(FreeTypeInstance *,
-                            PgFontObject *, SDL_RWops *, int);
+                            PgFontObject *, SDL_RWops *, long);
 #endif
 void _PGFT_UnloadFont(FreeTypeInstance *, PgFontObject *);