Changeset 33b8d024 in mainline for uspace/srv


Ignore:
Timestamp:
2018-01-16T20:38:46Z (8 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2467b41
Parents:
d39c46e0
Message:

Remove const qualifier from the argument of free() and realloc(),
as well as in numerous other variables that hold ownership of memory.

By convention, a pointer that holds ownership is _never_ qualified by const.
This is reflected in the standard type signature of free() and realloc().
Allowing const pointers to hold ownership may seem superficially convenient,
but is actually quite confusing to experienced C programmers.

Location:
uspace/srv
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/audio/hound/audio_data.c

    rd39c46e0 r33b8d024  
    3636#include <macros.h>
    3737#include <stdlib.h>
     38#include <str.h>
    3839
    3940#include "audio_data.h"
     
    5051    pcm_format_t format)
    5152{
    52         audio_data_t *adata = malloc(sizeof(audio_data_t));
     53        audio_data_t *adata = malloc(sizeof(audio_data_t) + size);
    5354        if (adata) {
    5455                unsigned overflow = size % pcm_format_frame_size(&format);
     
    5657                        log_warning("Data not a multiple of frame size, "
    5758                            "clipping.");
    58 
    59                 adata->data = data;
     59                uint8_t *d = ((uint8_t *)adata) + offsetof(audio_data_t, data);
     60                memcpy(d, data, size);
    6061                adata->size = size - overflow;
    6162                adata->format = format;
     
    8687        atomic_count_t refc = atomic_predec(&adata->refcount);
    8788        if (refc == 0) {
    88                 free(adata->data);
    8989                free(adata);
    9090        }
  • uspace/srv/audio/hound/audio_data.h

    rd39c46e0 r33b8d024  
    4545/** Reference counted audio buffer */
    4646typedef struct {
    47         /** Audio data */
    48         const void *data;
    4947        /** Size of the buffer pointer to by data */
    5048        size_t size;
     
    5351        /** Reference counter */
    5452        atomic_t refcount;
     53        /** Audio data */
     54        const uint8_t data[];
    5555} audio_data_t;
    5656
  • uspace/srv/audio/hound/audio_sink.h

    rd39c46e0 r33b8d024  
    5454        list_t connections;
    5555        /** Sink's name */
    56         const char *name;
     56        char *name;
    5757        /** Consumes data in this format */
    5858        pcm_format_t format;
  • uspace/srv/audio/hound/audio_source.c

    rd39c46e0 r33b8d024  
    9696 * @return Error code.
    9797 */
    98 errno_t audio_source_push_data(audio_source_t *source, const void *data,
     98errno_t audio_source_push_data(audio_source_t *source, void *data,
    9999    size_t size)
    100100{
  • uspace/srv/audio/hound/audio_source.h

    rd39c46e0 r33b8d024  
    4949        list_t connections;
    5050        /** String identifier */
    51         const char *name;
     51        char *name;
    5252        /** audio data format */
    5353        pcm_format_t format;
     
    7575    const pcm_format_t *f);
    7676void audio_source_fini(audio_source_t *source);
    77 errno_t audio_source_push_data(audio_source_t *source, const void *data,
     77errno_t audio_source_push_data(audio_source_t *source, void *data,
    7878    size_t size);
    7979static inline const pcm_format_t *audio_source_format(const audio_source_t *s)
  • uspace/srv/audio/hound/hound.c

    rd39c46e0 r33b8d024  
    414414 * @return Error code.
    415415 */
    416 errno_t hound_list_sources(hound_t *hound, const char ***list, size_t *size)
     416errno_t hound_list_sources(hound_t *hound, char ***list, size_t *size)
    417417{
    418418        assert(hound);
     
    428428                return EOK;
    429429        }
    430         const char **names = calloc(count, sizeof(char *));
     430        char **names = calloc(count, sizeof(char *));
    431431        errno_t ret = names ? EOK : ENOMEM;
    432432        for (unsigned long i = 0; i < count && ret == EOK; ++i) {
     
    456456 * @return Error code.
    457457 */
    458 errno_t hound_list_sinks(hound_t *hound, const char ***list, size_t *size)
     458errno_t hound_list_sinks(hound_t *hound, char ***list, size_t *size)
    459459{
    460460        assert(hound);
     
    470470                return EOK;
    471471        }
    472         const char **names = calloc(count, sizeof(char *));
     472        char **names = calloc(count, sizeof(char *));
    473473        errno_t ret = names ? EOK : ENOMEM;
    474474        for (size_t i = 0; i < count && ret == EOK; ++i) {
  • uspace/srv/audio/hound/hound.h

    rd39c46e0 r33b8d024  
    7373errno_t hound_add_source(hound_t *hound, audio_source_t *source);
    7474errno_t hound_add_sink(hound_t *hound, audio_sink_t *sink);
    75 errno_t hound_list_sources(hound_t *hound, const char ***list, size_t *size);
    76 errno_t hound_list_sinks(hound_t *hound, const char ***list, size_t *size);
     75errno_t hound_list_sources(hound_t *hound, char ***list, size_t *size);
     76errno_t hound_list_sinks(hound_t *hound, char ***list, size_t *size);
    7777errno_t hound_list_connections(hound_t *hound, const char ***sources,
    7878    const char ***sinks, size_t *size);
  • uspace/srv/audio/hound/iface.c

    rd39c46e0 r33b8d024  
    8686}
    8787
    88 static errno_t iface_get_list(void *server, const char ***list, size_t *size,
     88static errno_t iface_get_list(void *server, char ***list, size_t *size,
    8989    const char *connection, int flags)
    9090{
  • uspace/srv/devman/devman.h

    rd39c46e0 r33b8d024  
    8080        char *name;
    8181        /** Path to the driver's binary. */
    82         const char *binary_path;
     82        char *binary_path;
    8383        /** List of device ids for device-to-driver matching. */
    8484        match_id_list_t match_ids;
Note: See TracChangeset for help on using the changeset viewer.