fcea0f51d94f
authorDebian Games Team <pkg-games-devel@lists.alioth.debian.org>
Wed, 7 Sep 2022 05:25:07 +0000 (06:25 +0100)
committerGianfranco Costamagna <locutusofborg@debian.org>
Wed, 7 Sep 2022 05:25:07 +0000 (06:25 +0100)
# HG changeset patch
# User S.D.
# Date 1662491307 -10800
# Node ID fcea0f51d94f11bd327af582c78a781740e8786a
# Parent  8fd36e1b66edcbab60b5feb6e1dae3366f1e2ad9
Fix the sound issues and crashes on some platforms

This commit updates misc/libphyslayer/physfsrwops.* files to the latest versions
provided by PhysFS project (https://github.com/icculus/physfs/tree/main/extras/).

Gbp-Pq: Name fcea0f51d94f.patch

misc/libphyslayer/physfsrwops.c
misc/libphyslayer/physfsrwops.h

index 9b56390709d0afd240efd75e0a6417a1d549141c..ad38f25c5dbcb814a868aa9a2c3e1d9ad7136bba 100644 (file)
@@ -16,7 +16,7 @@
  *  Please see LICENSE.txt in the root of the source tree.
  *
  * SDL 1.2 falls under the LGPL license. SDL 1.3+ is zlib, like PhysicsFS.
- *  You can get SDL at http://www.libsdl.org/
+ *  You can get SDL at https://www.libsdl.org/
  *
  *  This file was written by Ryan C. Gordon. (icculus@icculus.org).
  */
 #include <stdio.h>  /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */
 #include "physfsrwops.h"
 
-/* SDL's RWOPS interface changed a little in SDL 1.3... */
+/* SDL's RWOPS interface changed a little in SDL 2.0... */
 #if defined(SDL_VERSION_ATLEAST)
-#if SDL_VERSION_ATLEAST(1, 3, 0)
-#define TARGET_SDL13 1
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+#define TARGET_SDL2 1
 #endif
 #endif
 
-#if TARGET_SDL13
+#if !TARGET_SDL2
+#ifndef RW_SEEK_SET
+#define RW_SEEK_SET SEEK_SET
+#endif
+#ifndef RW_SEEK_CUR
+#define RW_SEEK_CUR SEEK_CUR
+#endif
+#ifndef RW_SEEK_END
+#define RW_SEEK_END SEEK_END
+#endif
+#endif
+
+#if TARGET_SDL2
 static Sint64 SDLCALL physfsrwops_size(struct SDL_RWops *rw)
 {
     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
-    return PHYSFS_fileLength(handle);
-}
+    return (Sint64) PHYSFS_fileLength(handle);
+} /* physfsrwops_size */
 #endif
 
-#if TARGET_SDL13
+
+#if TARGET_SDL2
 static Sint64 SDLCALL physfsrwops_seek(struct SDL_RWops *rw, Sint64 offset, int whence)
 #else
 static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
@@ -48,9 +61,10 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
     PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
     PHYSFS_sint64 pos = 0;
 
-    if (whence == SEEK_SET)
+    if (whence == RW_SEEK_SET)
         pos = (PHYSFS_sint64) offset;
-    else if (whence == SEEK_CUR)
+
+    else if (whence == RW_SEEK_CUR)
     {
         const PHYSFS_sint64 current = PHYSFS_tell(handle);
         if (current == -1)
@@ -62,8 +76,8 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
 
         if (offset == 0)  /* this is a "tell" call. We're done. */
         {
-            #if TARGET_SDL13
-            return (long) current;
+            #if TARGET_SDL2
+            return (Sint64) current;
             #else
             return (int) current;
             #endif
@@ -72,7 +86,7 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
         pos = current + ((PHYSFS_sint64) offset);
     } /* else if */
 
-    else if (whence == SEEK_END)
+    else if (whence == RW_SEEK_END)
     {
         const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
         if (len == -1)
@@ -95,22 +109,22 @@ static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
         SDL_SetError("Attempt to seek past start of file.");
         return -1;
     } /* if */
-
+    
     if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
     {
         SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
         return -1;
     } /* if */
 
-    #if TARGET_SDL13
-    return (long) pos;
+    #if TARGET_SDL2
+    return (Sint64) pos;
     #else
     return (int) pos;
     #endif
 } /* physfsrwops_seek */
 
 
-#if TARGET_SDL13
+#if TARGET_SDL2
 static size_t SDLCALL physfsrwops_read(struct SDL_RWops *rw, void *ptr,
                                        size_t size, size_t maxnum)
 #else
@@ -123,18 +137,26 @@ static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
     if (rc != ((PHYSFS_sint64) readlen))
     {
         if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
+        {
             SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
+
+            #if TARGET_SDL2
+            return 0;
+            #else
+            return -1;
+            #endif
+        } /* if */
     } /* if */
 
-    #if TARGET_SDL13
-    return (size_t) rc;
+    #if TARGET_SDL2
+    return (size_t) rc / size;
     #else
-    return (int) rc;
+    return (int) rc / size;
     #endif
 } /* physfsrwops_read */
 
 
-#if TARGET_SDL13
+#if TARGET_SDL2
 static size_t SDLCALL physfsrwops_write(struct SDL_RWops *rw, const void *ptr,
                                         size_t size, size_t num)
 #else
@@ -147,7 +169,7 @@ static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
     if (rc != ((PHYSFS_sint64) writelen))
         SDL_SetError("PhysicsFS error: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
 
-    #if TARGET_SDL13
+    #if TARGET_SDL2
     return (size_t) rc;
     #else
     return (int) rc;
@@ -180,9 +202,9 @@ static SDL_RWops *create_rwops(PHYSFS_File *handle)
         retval = SDL_AllocRW();
         if (retval != NULL)
         {
-#if TARGET_SDL13 && !defined(EMSCRIPTEN)
+            #if TARGET_SDL2
             retval->size  = physfsrwops_size;
-#endif
+            #endif
             retval->seek  = physfsrwops_seek;
             retval->read  = physfsrwops_read;
             retval->write = physfsrwops_write;
index 6f35461181364e4ee534275fb9a7b679234e7c6c..54b08a7ec5c8a79afe78e1ae402b88d6601c31d8 100644 (file)
@@ -15,7 +15,8 @@
  * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
  *  Please see LICENSE.txt in the root of the source tree.
  *
- * SDL falls under the LGPL license. You can get SDL at http://www.libsdl.org/
+ * SDL 1.2 falls under the LGPL license. SDL 1.3+ is zlib, like PhysicsFS.
+ *  You can get SDL at https://www.libsdl.org/
  *
  *  This file was written by Ryan C. Gordon. (icculus@icculus.org).
  */
 #define _INCLUDE_PHYSFSRWOPS_H_
 
 #include "physfs.h"
-
 #include "SDL.h"
 
-#include "physfscompat.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -41,7 +39,7 @@ extern "C" {
  *
  *   @param filename File to open in platform-independent notation.
  *  @return A valid SDL_RWops structure on success, NULL on error. Specifics
- *           of the error can be gleaned from PHYSFS_getLastErrorCode().
+ *           of the error can be gleaned from PHYSFS_getLastError().
  */
 PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openRead(const char *fname);
 
@@ -53,7 +51,7 @@ PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openRead(const char *fname);
  *
  *   @param filename File to open in platform-independent notation.
  *  @return A valid SDL_RWops structure on success, NULL on error. Specifics
- *           of the error can be gleaned from PHYSFS_getLastErrorCode().
+ *           of the error can be gleaned from PHYSFS_getLastError().
  */
 PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname);
 
@@ -65,7 +63,7 @@ PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname);
  *
  *   @param filename File to open in platform-independent notation.
  *  @return A valid SDL_RWops structure on success, NULL on error. Specifics
- *           of the error can be gleaned from PHYSFS_getLastErrorCode().
+ *           of the error can be gleaned from PHYSFS_getLastError().
  */
 PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname);
 
@@ -77,7 +75,7 @@ PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname);
  *
  *   @param handle a valid PhysicsFS file handle.
  *  @return A valid SDL_RWops structure on success, NULL on error. Specifics
- *           of the error can be gleaned from PHYSFS_getLastErrorCode().
+ *           of the error can be gleaned from PHYSFS_getLastError().
  */
 PHYSFS_DECL SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle);