Skip to content

Commit

Permalink
refactor: fix compiler and clang-tidy warnings
Browse files Browse the repository at this point in the history
- processed osdep directory
- reduce warnings from compiler and clang-tidy
- minor code improvements and modernization
  • Loading branch information
midwan committed Jan 3, 2025
1 parent b9c5e60 commit 82b5da5
Show file tree
Hide file tree
Showing 69 changed files with 1,647 additions and 1,663 deletions.
4 changes: 2 additions & 2 deletions src/cfgfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,10 @@ static void cfg_dowrite(struct zfile *f, const TCHAR *option, const TCHAR *optio
char *opt = ua(optionp);
if (target) {
char *tna = ua(TARGET_NAME);
sprintf(tmpa, "%s.%s.utf8=%s", tna, opt, tmp2);
_sntprintf(tmpa, sizeof tmpa, "%s.%s.utf8=%s", tna, opt, tmp2);
xfree(tna);
} else {
sprintf(tmpa, "%s.utf8=%s", opt, tmp2);
_sntprintf(tmpa, sizeof tmpa, "%s.utf8=%s", opt, tmp2);
}
xfree(opt);
zfile_fwrite(tmpa, strlen (tmpa), 1, f);
Expand Down
4 changes: 2 additions & 2 deletions src/include/fsdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ extern int fsdb_fill_file_attrs (a_inode *, a_inode *);
extern int fsdb_set_file_attrs (a_inode *);
extern int fsdb_mode_representable_p (const a_inode *, int);
extern int fsdb_mode_supported (const a_inode *);
extern TCHAR *fsdb_create_unique_nname (a_inode *base, const TCHAR *);
extern TCHAR *fsdb_create_unique_nname (const a_inode *base, const TCHAR *);

struct my_opendir_s;
struct my_openfile_s;
Expand Down Expand Up @@ -168,7 +168,7 @@ extern bool my_existsdir (const TCHAR *name);
extern FILE *my_opentext (const TCHAR*);

extern bool my_stat (const TCHAR *name, struct mystat *ms);
extern bool my_utime (const TCHAR *name, struct mytimeval *tv);
extern bool my_utime (const TCHAR *name, const struct mytimeval *tv);
extern bool my_chmod (const TCHAR *name, uae_u32 mode);
extern bool my_resolveshortcut(TCHAR *linkfile, int size);
extern bool my_resolvessymboliclink(TCHAR *linkfile, int size);
Expand Down
2 changes: 1 addition & 1 deletion src/include/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extern void uaeser_clearbuffers (void*);
extern void enet_writeser (uae_u16);
extern int enet_readseravail (void);
extern int enet_readser (uae_u16 *buffer);
extern int enet_open (TCHAR *name);
extern int enet_open (const TCHAR *name);
extern void enet_close (void);

#endif /* UAE_SERIAL_H */
2 changes: 1 addition & 1 deletion src/include/uae/mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct uae_shmid_ds {

void *uae_shmat(addrbank *ab, int shmid, void *shmaddr, int shmflg, struct uae_mman_data *md);
int uae_shmdt(const void *shmaddr);
int uae_shmget(uae_key_t key, addrbank *ab, int shmflg);
int uae_shmget(uae_key_t key, const addrbank *ab, int shmflg);
int uae_shmctl(int shmid, int cmd, struct uae_shmid_ds *buf);

#define UAE_IPC_PRIVATE 0x01
Expand Down
2 changes: 1 addition & 1 deletion src/include/uae/uae.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Clipboard functions

char* uae_clipboard_get_text(void);
void uae_clipboard_free_text(char* text);
void uae_clipboard_free_text(const char* text);
void uae_clipboard_put_text(const char* text);

#endif // LIBAMIGA_LIBAMIGA_H_
20 changes: 10 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#include "keyboard.h"

// Special version string so that AmigaOS can detect it
static const char __ver[40] = "$VER: Amiberry v6.3.5 (2024-09-20)";
static constexpr char __ver[40] = "$VER: Amiberry v7.0 (2025-01-02)";

long int version = 256 * 65536L * UAEMAJOR + 65536L * UAEMINOR + UAESUBREV;

Expand All @@ -96,7 +96,7 @@ static TCHAR optionsfile[MAX_DPATH];
static uae_u32 randseed;

static uae_u32 xorshiftstate;
static uae_u32 xorshift32(void)
static uae_u32 xorshift32()
{
uae_u32 x = xorshiftstate;
x ^= x << 13;
Expand All @@ -106,7 +106,7 @@ static uae_u32 xorshift32(void)
return xorshiftstate;
}

uae_u32 uaerand(void)
uae_u32 uaerand()
{
if (xorshiftstate == 0) {
xorshiftstate = randseed;
Expand All @@ -119,7 +119,7 @@ uae_u32 uaerand(void)
return r;
}

uae_u32 uaerandgetseed(void)
uae_u32 uaerandgetseed()
{
if (!randseed) {
randseed = 1;
Expand Down Expand Up @@ -879,7 +879,7 @@ void usage()

static void parse_cmdline_2 (int argc, TCHAR **argv)
{
cfgfile_addcfgparam (0);
cfgfile_addcfgparam (nullptr);
for (auto i = 1; i < argc; i++) {
if (_tcsncmp(argv[i], _T("-cfgparam="), 10) == 0) {
cfgfile_addcfgparam(argv[i] + 10);
Expand Down Expand Up @@ -917,7 +917,7 @@ static void parse_diskswapper (const TCHAR *s)
p2 = _tcstok(p1, delim);
if (!p2)
break;
p1 = NULL;
p1 = nullptr;
if (num >= MAX_SPARE_DRIVES)
break;
if (!zfile_zopen (p2, diskswapper_cb, &num)) {
Expand Down Expand Up @@ -946,7 +946,7 @@ static TCHAR *parsetext (const TCHAR *s)
static TCHAR *parsetextpath (const TCHAR *s)
{
auto* const s2 = parsetext (s);
auto* const s3 = target_expand_environment (s2, NULL, 0);
auto* const s3 = target_expand_environment (s2, nullptr, 0);
xfree(s2);
return s3;
}
Expand Down Expand Up @@ -1201,9 +1201,9 @@ static void parse_cmdline (int argc, TCHAR **argv)
std::string filename = p.filename().string();

std::string config_extension = "uae";
const std::size_t pos = filename.find_last_of(".");
const std::size_t pos = filename.find_last_of('.');
if (pos != std::string::npos) {
filename = filename.substr(0, pos) + "." + config_extension;
filename = filename.substr(0, pos).append(".").append(config_extension);
}
else {
// No extension found
Expand Down Expand Up @@ -1538,7 +1538,7 @@ static int real_main2 (int argc, TCHAR **argv)
#ifdef NATMEM_OFFSET
if (!init_shm ()) {
if (currprefs.start_gui)
uae_restart(&currprefs, -1, NULL);
uae_restart(&currprefs, -1, nullptr);
return 0;
}
#endif
Expand Down
54 changes: 25 additions & 29 deletions src/osdep/ahi_v1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

#if defined(AHI)

#include <ctype.h>
#include <assert.h>
#include <cctype>
#include <cassert>

#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <cstdlib>
#include <cstdarg>
#include <cstdio>

#include "options.h"
#include "audio.h"
Expand Down Expand Up @@ -75,7 +75,7 @@ struct winuae //this struct is put in a6 if you call
};
static struct winuae uaevar;

void ahi_close_sound(void)
void ahi_close_sound()
{
if (!ahi_on)
return;
Expand Down Expand Up @@ -146,7 +146,7 @@ void ahi_updatesound(int force)

if (currprefs.sound_stereo_swap_ahi) {
int i;
uae_s16 *p = (uae_s16*)ahisndbuffer;
auto p = reinterpret_cast<uae_s16*>(ahisndbuffer);
for (i = 0; i < dwBytes1 / 2; i += 2) {
uae_s16 tmp;
tmp = p[i + 0];
Expand All @@ -173,13 +173,13 @@ void ahi_updatesound(int force)
}


void ahi_finish_sound_buffer (void)
void ahi_finish_sound_buffer ()
{
sound_flushes2++;
ahi_updatesound(2);
}

static int ahi_init_record (void)
static int ahi_init_record ()
{
#ifdef _WIN32
HRESULT hr;
Expand Down Expand Up @@ -219,9 +219,9 @@ static int ahi_init_record (void)
desired.format = AUDIO_S16SYS;
desired.channels = sound_channels_ahi;
desired.samples = amigablksize * 4 * RECORDBUFFER;
desired.callback = NULL; // We'll use SDL_QueueAudio and SDL_DequeueAudio instead of a callback
desired.callback = nullptr; // We'll use SDL_QueueAudio and SDL_DequeueAudio instead of a callback

ahi_dev_rec = SDL_OpenAudioDevice(NULL, 1, &desired, &obtained, 0);
ahi_dev_rec = SDL_OpenAudioDevice(nullptr, 1, &desired, &obtained, 0);
if (ahi_dev_rec == 0) {
write_log(_T("AHI: SDL_OpenAudioDevice() failure: %s\n"), SDL_GetError());
record_enabled = -1;
Expand Down Expand Up @@ -254,7 +254,7 @@ void setvolume_ahi (int vol)
#endif
}

static int ahi_init_sound(void)
static int ahi_init_sound()
{
if (ahi_dev)
return 0;
Expand Down Expand Up @@ -301,7 +301,7 @@ static int ahi_init_sound(void)
return sound_freq_ahi;
}

int ahi_open_sound (void)
int ahi_open_sound ()
{
int rate;

Expand Down Expand Up @@ -390,10 +390,9 @@ uae_u32 REGPARAM2 ahi_demux (TrapContext *context)

case 2:
{
int i;
uaecptr addr = m68k_areg (regs, 0);
for (i = 0; i < amigablksize * 4; i += 4)
*ahisndbufpt++ = get_long (addr + i);
for (int i = 0; i < amigablksize * 4; i += 4)
*ahisndbufpt++ = static_cast<int>(get_long(addr + i));
ahi_finish_sound_buffer();
}
return amigablksize;
Expand Down Expand Up @@ -454,9 +453,7 @@ uae_u32 REGPARAM2 ahi_demux (TrapContext *context)
lpDSB2r->Unlock(pos1, byte1, pos2, byte2);
return (todo - t) / t;
#else
uaecptr addr;
int i, todo;
Uint32 byte1, byte2;
Uint32 byte1, byte2;

if (!ahi_on)
return -2;
Expand All @@ -465,16 +462,16 @@ uae_u32 REGPARAM2 ahi_demux (TrapContext *context)
if (record_enabled < 0)
return -2;

todo = SDL_GetQueuedAudioSize(ahi_dev_rec);
auto todo = SDL_GetQueuedAudioSize(ahi_dev_rec);
if (todo < amigablksize * 4) //if no complete buffer ready exit
return -1;

addr = m68k_areg(regs, 0);
uae_u16* sndbufrecpt = (uae_u16*)malloc(todo);
uaecptr addr = m68k_areg(regs, 0);
auto* sndbufrecpt = static_cast<uae_u16*>(malloc(todo));
SDL_DequeueAudio(ahi_dev_rec, sndbufrecpt, todo);

todo /= 4;
for (i = 0; i < todo; i++) {
for (int i = 0; i < todo; i++) {
uae_u32 s1, s2;
if (currprefs.sound_stereo_swap_ahi) {
s1 = sndbufrecpt[1];
Expand All @@ -496,10 +493,9 @@ uae_u32 REGPARAM2 ahi_demux (TrapContext *context)

case 4:
{
int i;
if (!ahi_on)
return -2;
i = intcount;
int i = intcount;
intcount = 0;
return i;
}
Expand Down Expand Up @@ -536,7 +532,7 @@ uae_u32 REGPARAM2 ahi_demux (TrapContext *context)

case 12:
{
TCHAR* s = au((char*)get_real_address(m68k_areg(regs, 0)));
TCHAR* s = au(reinterpret_cast<char*>(get_real_address(m68k_areg(regs, 0))));
if (SDL_SetClipboardText(s) != 0) {
// handle error
write_log("Unable to set clipboard text: %s\n", SDL_GetError());
Expand Down Expand Up @@ -608,9 +604,9 @@ uae_u32 REGPARAM2 ahi_demux (TrapContext *context)
{
struct timespec ts {};
clock_gettime(CLOCK_MONOTONIC, &ts);
const auto time = int64_t(ts.tv_sec) * 1000000000 + ts.tv_nsec;
put_long(m68k_areg(regs, 0), uae_u32(time & 0xffffffff));
put_long(m68k_areg(regs, 0) + 4, uae_u32(time >> 32));
const auto time = static_cast<int64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec;
put_long(m68k_areg(regs, 0), static_cast<uae_u32>(time & 0xffffffff));
put_long(m68k_areg(regs, 0) + 4, static_cast<uae_u32>(time >> 32));
}
return 1;

Expand Down
7 changes: 4 additions & 3 deletions src/osdep/ahi_v1.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#pragma once
extern void ahi_updatesound(int force);
extern uae_u32 REGPARAM2 ahi_demux (TrapContext*);
extern int ahi_open_sound (void);
extern void ahi_close_sound (void);
extern void ahi_finish_sound_buffer (void);
extern int ahi_open_sound ();
extern void ahi_close_sound ();
extern void ahi_finish_sound_buffer ();
extern void init_ahi();
extern void ahi_hsync();

Expand Down
Loading

0 comments on commit 82b5da5

Please sign in to comment.