Re: [AD] microscopic issues compiling 4.1.13 with latest MinGW packages |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
> Oh, I see. I'm not too good with pointers or windows programming, so was
> probably not a good idea for me to make a patch, but anyway, I have made
> one (against 4.1.13). It seems to work. I've run a few of the examples,
> and the demo game, in Windows. Is there a definitive set of tests to run
> to make sure it is ok?
I think this is sufficient. The patch can be simplified a bit though, by
directly defining unions holding objects instead of pointers to objects.
This has the nice side-effect to be completely transparent from the
compiler's point-of-view.
And I was slightly inaccurate: the cast in wdsound.c is unsafe (cast from
base to derived structure, one field has no reserved storage; this worked
because the missing field is ignored, so presumably not accessed). I've
rewritten the chunk of code to let it use the derived structure.
> Hmm, maybe I should've named the LPVOID temporaries something other than
> 'temp'.
'temp' sounds fine.
I've attached the revised patch. Could you verify that it still compiles
with WARNMODE=1?
--
Eric Botcazou
diff -up /cvs/allegro/src/win/wddraw.c allegro/src/win/wddraw.c
--- /cvs/allegro/src/win/wddraw.c Tue Sep 24 20:56:34 2002
+++ allegro/src/win/wddraw.c Mon Mar 15 09:01:42 2004
@@ -42,6 +42,7 @@ int init_directx(void)
{
LPDIRECTDRAW directdraw1;
HRESULT hr;
+ LPVOID temp;
/* first we have to set up the DirectDraw1 interface... */
hr = DirectDrawCreate(NULL, &directdraw1, NULL);
@@ -49,10 +50,11 @@ int init_directx(void)
return -1;
/* ...then query the DirectDraw2 interface */
- hr = IDirectDraw_QueryInterface(directdraw1, &IID_IDirectDraw2, (LPVOID *)&directdraw);
+ hr = IDirectDraw_QueryInterface(directdraw1, &IID_IDirectDraw2, &temp);
if (FAILED(hr))
return -1;
+ directdraw = temp;
IDirectDraw_Release(directdraw1);
/* set the default cooperation level */
diff -up /cvs/allegro/src/win/wddwin.c allegro/src/win/wddwin.c
--- /cvs/allegro/src/win/wddwin.c Mon Nov 24 17:29:18 2003
+++ allegro/src/win/wddwin.c Mon Mar 15 09:47:24 2004
@@ -208,9 +208,12 @@ static void paint_win(RECT *rect)
/* update_matching_window:
* Updates a portion of the window when the color depths match.
*/
-static void update_matching_window(RECT* rect)
+static void update_matching_window(RECT *rect)
{
- RECT dest_rect;
+ union {
+ POINT p;
+ RECT r;
+ } dest_rect;
_enter_gfx_critical();
@@ -220,19 +223,19 @@ static void update_matching_window(RECT*
}
if (rect)
- dest_rect = *rect;
+ dest_rect.r = *rect;
else {
- dest_rect.left = 0;
- dest_rect.right = gfx_directx_win.w;
- dest_rect.top = 0;
- dest_rect.bottom = gfx_directx_win.h;
+ dest_rect.r.left = 0;
+ dest_rect.r.right = gfx_directx_win.w;
+ dest_rect.r.top = 0;
+ dest_rect.r.bottom = gfx_directx_win.h;
}
- ClientToScreen(allegro_wnd, (LPPOINT)&dest_rect);
- ClientToScreen(allegro_wnd, (LPPOINT)&dest_rect + 1);
+ ClientToScreen(allegro_wnd, &dest_rect.p);
+ ClientToScreen(allegro_wnd, &dest_rect.p + 1);
/* blit offscreen backbuffer to the window */
- IDirectDrawSurface2_Blt(primary_surface->id, &dest_rect,
+ IDirectDrawSurface2_Blt(primary_surface->id, &dest_rect.r,
offscreen_surface->id, rect, 0, NULL);
_exit_gfx_critical();
@@ -307,9 +310,13 @@ static int ddsurf_blit_ex(LPDIRECTDRAWSU
/* update_colorconv_window:
* Updates a portion of the window when the color depths don't match.
*/
-static void update_colorconv_window(RECT* rect)
+static void update_colorconv_window(RECT *rect)
{
- RECT src_rect, dest_rect;
+ RECT src_rect;
+ union {
+ POINT p;
+ RECT r;
+ } dest_rect;
HDC src_dc, dest_dc;
HRESULT hr;
int direct;
@@ -339,17 +346,17 @@ static void update_colorconv_window(RECT
src_rect.bottom = gfx_directx_win.h;
}
- dest_rect = src_rect;
- ClientToScreen(allegro_wnd, (LPPOINT)&dest_rect);
- ClientToScreen(allegro_wnd, (LPPOINT)&dest_rect + 1);
+ dest_rect.r = src_rect;
+ ClientToScreen(allegro_wnd, &dest_rect.p);
+ ClientToScreen(allegro_wnd, &dest_rect.p + 1);
direct = (direct_updating_mode_on &&
- is_contained(&dest_rect, &working_area) &&
+ is_contained(&dest_rect.r, &working_area) &&
GetForegroundWindow() == allegro_wnd);
if (direct) {
/* blit directly to the primary surface without clipping */
- ddsurf_blit_ex(primary_surface->id, &dest_rect,
+ ddsurf_blit_ex(primary_surface->id, &dest_rect.r,
offscreen_surface->id, &src_rect);
}
else {
diff -up /cvs/allegro/src/win/wdsinput.c allegro/src/win/wdsinput.c
--- /cvs/allegro/src/win/wdsinput.c Wed Jun 11 19:38:14 2003
+++ allegro/src/win/wdsinput.c Mon Mar 15 09:12:32 2004
@@ -263,6 +263,7 @@ int digi_directsound_capture_init(LPGUID
DSCCAPS dsCaps;
WAVEFORMATEX wfx;
HRESULT hr;
+ LPVOID temp;
/* the DirectSoundCapture interface is not part of DirectX 3 */
if (_dx_ver < 0x0500)
@@ -272,14 +273,16 @@ int digi_directsound_capture_init(LPGUID
* we use CoCreateInstance() instead of DirectSoundCaptureCreate() to avoid
* the dll loader blocking the start of Allegro under DirectX 3.
*/
- hr = CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
- &IID_IDirectSoundCapture, (LPVOID *)&ds_capture);
+ hr = CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
+ &IID_IDirectSoundCapture, &temp);
if (FAILED(hr)) {
_TRACE("Can't create DirectSoundCapture interface (%s).\n", ds_err(hr));
goto Error;
}
+ ds_capture = temp;
+
/* initialize the device */
hr = IDirectSoundCapture_Initialize(ds_capture, guid);
@@ -341,6 +344,7 @@ void digi_directsound_capture_exit(void)
int digi_directsound_capture_detect(LPGUID guid)
{
HRESULT hr;
+ LPVOID temp;
/* the DirectSoundCapture interface is not part of DirectX 3 */
if (_dx_ver < 0x500)
@@ -351,14 +355,16 @@ int digi_directsound_capture_detect(LPGU
* we use CoCreateInstance() instead of DirectSoundCaptureCreate() to avoid
* the dll loader blocking the start of Allegro under DirectX 3.
*/
- hr = CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
- &IID_IDirectSoundCapture, (LPVOID *)&ds_capture);
-
+ hr = CoCreateInstance(&CLSID_DirectSoundCapture, NULL,
+ CLSCTX_INPROC_SERVER, &IID_IDirectSoundCapture,
+ &temp);
if (FAILED(hr)) {
_TRACE("DirectSoundCapture interface creation failed during detect (%s).\n", ds_err(hr));
return 0;
}
+ ds_capture = temp;
+
/* initialize the device */
hr = IDirectSoundCapture_Initialize(ds_capture, guid);
@@ -515,6 +521,7 @@ int digi_directsound_rec_read(void *buf)
unsigned long int capture_pos;
HRESULT hr;
BOOL buffer_filled = FALSE;
+ LPVOID temp1, temp2;
if (!ds_capture || !ds_capture_buf || !input_wave_data)
return 0;
@@ -535,12 +542,15 @@ int digi_directsound_rec_read(void *buf)
}
hr = IDirectSoundCaptureBuffer_Lock(ds_capture_buf, last_capture_pos,
- bytes_to_lock, (LPVOID *)&input_ptr1,
- &input_bytes1, (LPVOID *)&input_ptr2,
+ bytes_to_lock, &temp1,
+ &input_bytes1, &temp2,
&input_bytes2, 0);
if (FAILED(hr))
return 0;
+ input_ptr1 = temp1;
+ input_ptr2 = temp2;
+
/* let's get the data aligned linearly */
linear_input_ptr = malloc(bytes_to_lock);
memcpy(linear_input_ptr, input_ptr1, input_bytes1);
diff -up /cvs/allegro/src/win/wdsound.c allegro/src/win/wdsound.c
--- /cvs/allegro/src/win/wdsound.c Sat Sep 13 16:35:40 2003
+++ allegro/src/win/wdsound.c Mon Mar 15 09:39:54 2004
@@ -557,19 +557,19 @@ static int digi_directsound_mixer_volume
static LPDIRECTSOUNDBUFFER create_dsound_buffer(int len, int freq, int bits, int stereo, int vol, int pan)
{
LPDIRECTSOUNDBUFFER snd_buf;
- PCMWAVEFORMAT pcmwf;
+ WAVEFORMATEX wf;
DSBUFFERDESC dsbdesc;
HRESULT hr;
int switch_mode;
/* setup wave format structure */
- memset(&pcmwf, 0, sizeof(PCMWAVEFORMAT));
- pcmwf.wf.wFormatTag = WAVE_FORMAT_PCM;
- pcmwf.wf.nChannels = stereo ? 2 : 1;
- pcmwf.wf.nSamplesPerSec = freq;
- pcmwf.wBitsPerSample = bits;
- pcmwf.wf.nBlockAlign = bits * (stereo ? 2 : 1) / 8;
- pcmwf.wf.nAvgBytesPerSec = pcmwf.wf.nSamplesPerSec * pcmwf.wf.nBlockAlign;
+ memset(&wf, 0, sizeof(WAVEFORMATEX));
+ wf.wFormatTag = WAVE_FORMAT_PCM;
+ wf.nChannels = stereo ? 2 : 1;
+ wf.nSamplesPerSec = freq;
+ wf.wBitsPerSample = bits;
+ wf.nBlockAlign = bits * (stereo ? 2 : 1) / 8;
+ wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
/* setup DSBUFFERDESC structure */
memset(&dsbdesc, 0, sizeof(DSBUFFERDESC));
@@ -583,7 +583,7 @@ static LPDIRECTSOUNDBUFFER create_dsound
dsbdesc.dwFlags |= DSBCAPS_GLOBALFOCUS;
dsbdesc.dwBufferBytes = len * (bits / 8) * (stereo ? 2 : 1);
- dsbdesc.lpwfxFormat = (LPWAVEFORMATEX)&pcmwf;
+ dsbdesc.lpwfxFormat = &wf;
/* create buffer */
hr = IDirectSound_CreateSoundBuffer(directsound, &dsbdesc, &snd_buf, NULL);
diff -up /cvs/allegro/src/win/wdxver.c allegro/src/win/wdxver.c
--- /cvs/allegro/src/win/wdxver.c Tue Nov 6 20:37:30 2001
+++ allegro/src/win/wdxver.c Mon Mar 15 09:28:46 2004
@@ -81,6 +81,7 @@ int get_dx_ver(void)
#endif
DDSURFACEDESC ddraw_surf_desc;
+ LPVOID temp;
int dx_version = 0;
/* first get the Windows platform */
@@ -154,12 +155,14 @@ int get_dx_ver(void)
dx_version = 0x100;
/* let's see if IDirectDraw2 exists */
- hr = IDirectDraw_QueryInterface(directdraw, &IID_IDirectDraw2, (LPVOID *) & directdraw2);
+ hr = IDirectDraw_QueryInterface(directdraw, &IID_IDirectDraw2, &temp);
if (FAILED(hr)) {
/* no IDirectDraw2 exists... must be DX1 */
goto End;
}
+ directdraw2 = temp;
+
/* IDirectDraw2 exists... must be at least DX2 */
IDirectDraw2_Release(directdraw2);
dx_version = 0x200;
@@ -205,10 +208,12 @@ int get_dx_ver(void)
}
/* try for the IDirectDrawSurface3 interface; if it works, we're on DX5 at least */
- hr = IDirectDrawSurface_QueryInterface(ddraw_surf, &IID_IDirectDrawSurface3, (LPVOID *) &ddraw_surf3);
+ hr = IDirectDrawSurface_QueryInterface(ddraw_surf, &IID_IDirectDrawSurface3, &temp);
if (FAILED(hr))
goto End;
+ ddraw_surf3 = temp;
+
/* QI for IDirectDrawSurface3 succeeded; we must be at least DX5 */
dx_version = 0x500;
diff -up /cvs/allegro/src/win/wjoydx.c allegro/src/win/wjoydx.c
--- /cvs/allegro/src/win/wjoydx.c Sun Feb 29 07:51:10 2004
+++ allegro/src/win/wjoydx.c Mon Mar 15 09:29:34 2004
@@ -327,6 +327,7 @@ static BOOL CALLBACK joystick_enum_callb
LPDIRECTINPUTDEVICE _dinput_device1;
LPDIRECTINPUTDEVICE2 dinput_device = NULL;
HRESULT hr;
+ LPVOID temp;
DIPROPRANGE property_range =
{
@@ -368,11 +369,13 @@ static BOOL CALLBACK joystick_enum_callb
goto Error;
/* query the DirectInputDevice2 interface needed for the poll() method */
- hr = IDirectInputDevice_QueryInterface(_dinput_device1, &IID_IDirectInputDevice2, (LPVOID *)&dinput_device);
+ hr = IDirectInputDevice_QueryInterface(_dinput_device1, &IID_IDirectInputDevice2, &temp);
IDirectInputDevice_Release(_dinput_device1);
if (FAILED(hr))
goto Error;
+ dinput_device = temp;
+
/* set cooperative level */
hr = IDirectInputDevice2_SetCooperativeLevel(dinput_device, allegro_wnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (FAILED(hr))
diff -up /cvs/allegro/src/win/wwnd.c allegro/src/win/wwnd.c
--- /cvs/allegro/src/win/wwnd.c Sun Feb 15 18:34:44 2004
+++ allegro/src/win/wwnd.c Mon Mar 15 09:38:42 2004
@@ -464,7 +464,10 @@ static void wnd_thread_proc(HANDLE setup
*/
int init_directx_window(void)
{
- RECT win_rect;
+ union {
+ POINT p;
+ RECT r;
+ } win_rect;
HANDLE events[2];
long result;
@@ -484,13 +487,13 @@ int init_directx_window(void)
allegro_wnd = user_wnd;
/* retrieve the window dimensions */
- GetWindowRect(allegro_wnd, &win_rect);
- ClientToScreen(allegro_wnd, (LPPOINT)&win_rect);
- ClientToScreen(allegro_wnd, (LPPOINT)&win_rect + 1);
- wnd_x = win_rect.left;
- wnd_y = win_rect.top;
- wnd_width = win_rect.right - win_rect.left;
- wnd_height = win_rect.bottom - win_rect.top;
+ GetWindowRect(allegro_wnd, &win_rect.r);
+ ClientToScreen(allegro_wnd, &win_rect.p);
+ ClientToScreen(allegro_wnd, &win_rect.p + 1);
+ wnd_x = win_rect.r.left;
+ wnd_y = win_rect.r.top;
+ wnd_width = win_rect.r.right - win_rect.r.left;
+ wnd_height = win_rect.r.bottom - win_rect.r.top;
}
else {
/* initializes input module without dedicated thread */