Util/Macros: replacement for GLib's G_N_ELEMENTS()

This commit is contained in:
Max Kellermann
2013-10-15 22:04:17 +02:00
parent 77429b6dd3
commit 509f8dab89
19 changed files with 100 additions and 58 deletions
+6 -5
View File
@@ -24,6 +24,7 @@
#include "system/fd_util.h"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/Macros.hxx"
#include "Log.hxx"
#include <glib.h>
@@ -133,7 +134,7 @@ oss_output_test_default_device(void)
{
int fd, i;
for (i = G_N_ELEMENTS(default_devices); --i >= 0; ) {
for (i = ARRAY_SIZE(default_devices); --i >= 0; ) {
fd = open_cloexec(default_devices[i], O_WRONLY, 0);
if (fd >= 0) {
@@ -152,11 +153,11 @@ oss_output_test_default_device(void)
static struct audio_output *
oss_open_default(Error &error)
{
int err[G_N_ELEMENTS(default_devices)];
enum oss_stat ret[G_N_ELEMENTS(default_devices)];
int err[ARRAY_SIZE(default_devices)];
enum oss_stat ret[ARRAY_SIZE(default_devices)];
const config_param empty;
for (int i = G_N_ELEMENTS(default_devices); --i >= 0; ) {
for (int i = ARRAY_SIZE(default_devices); --i >= 0; ) {
ret[i] = oss_stat_device(default_devices[i], &err[i]);
if (ret[i] == OSS_STAT_NO_ERROR) {
OssOutput *od = new OssOutput();
@@ -170,7 +171,7 @@ oss_open_default(Error &error)
}
}
for (int i = G_N_ELEMENTS(default_devices); --i >= 0; ) {
for (int i = ARRAY_SIZE(default_devices); --i >= 0; ) {
const char *dev = default_devices[i];
switch(ret[i]) {
case OSS_STAT_NO_ERROR:
+6 -5
View File
@@ -24,6 +24,7 @@
#include "MixerList.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/Macros.hxx"
#include <glib.h>
@@ -183,7 +184,7 @@ winmm_output_open(struct audio_output *ao, AudioFormat &audio_format,
return false;
}
for (unsigned i = 0; i < G_N_ELEMENTS(wo->buffers); ++i) {
for (unsigned i = 0; i < ARRAY_SIZE(wo->buffers); ++i) {
memset(&wo->buffers[i].hdr, 0, sizeof(wo->buffers[i].hdr));
}
@@ -197,7 +198,7 @@ winmm_output_close(struct audio_output *ao)
{
WinmmOutput *wo = (WinmmOutput *)ao;
for (unsigned i = 0; i < G_N_ELEMENTS(wo->buffers); ++i)
for (unsigned i = 0; i < ARRAY_SIZE(wo->buffers); ++i)
wo->buffers[i].buffer.Clear();
waveOutClose(wo->handle);
@@ -285,7 +286,7 @@ winmm_output_play(struct audio_output *ao, const void *chunk, size_t size, Error
/* mark our buffer as "used" */
wo->next_buffer = (wo->next_buffer + 1) %
G_N_ELEMENTS(wo->buffers);
ARRAY_SIZE(wo->buffers);
return size;
}
@@ -293,7 +294,7 @@ winmm_output_play(struct audio_output *ao, const void *chunk, size_t size, Error
static bool
winmm_drain_all_buffers(WinmmOutput *wo, Error &error)
{
for (unsigned i = wo->next_buffer; i < G_N_ELEMENTS(wo->buffers); ++i)
for (unsigned i = wo->next_buffer; i < ARRAY_SIZE(wo->buffers); ++i)
if (!winmm_drain_buffer(wo, &wo->buffers[i], error))
return false;
@@ -309,7 +310,7 @@ winmm_stop(WinmmOutput *wo)
{
waveOutReset(wo->handle);
for (unsigned i = 0; i < G_N_ELEMENTS(wo->buffers); ++i) {
for (unsigned i = 0; i < ARRAY_SIZE(wo->buffers); ++i) {
WinmmBuffer *buffer = &wo->buffers[i];
waveOutUnprepareHeader(wo->handle, &buffer->hdr,
sizeof(buffer->hdr));