ucx/ucx.h

Sun, 21 Jan 2018 12:13:09 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 21 Jan 2018 12:13:09 +0100
changeset 152
62921b370c60
parent 124
80609f9675f1
permissions
-rw-r--r--

fixes use after free when a GtkTreeView was destroyed

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2016 Olaf Wintermann. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
/**
 * Main UCX Header providing most common definitions.
 * 
 * @file   ucx.h
 * @author Mike Becker
 * @author Olaf Wintermann
 */

#ifndef UCX_H
#define	UCX_H

/** Major UCX version as integer constant. */
#define UCX_VERSION_MAJOR   0

/** Minor UCX version as integer constant. */
#define UCX_VERSION_MINOR   12

#include <stdlib.h>
#include <stdint.h>

#ifdef _WIN32
#if !(defined __ssize_t_defined || defined _SSIZE_T_)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#define __ssize_t_defined
#define _SSIZE_T_
#endif /* __ssize_t_defined and _SSIZE_T */
#else /* !_WIN32 */
#include <sys/types.h>
#endif /* _WIN32 */

#ifdef	__cplusplus
#ifndef _Bool
#define _Bool bool
#define restrict
#endif
/** Use C naming even when compiling with C++.  */
#define UCX_EXTERN extern "C"
extern "C" {
#else
/** Pointless in C. */
#define UCX_EXTERN
#endif
    

/**
 * A function pointer to a destructor function.
 * @see ucx_mempool_setdestr()
 * @see ucx_mempool_regdestr()
 */
typedef void(*ucx_destructor)(void*);

/**
 * Function pointer to a compare function.
 * 
 * The compare function shall take three arguments: the two values that shall be
 * compared and optional additional data.
 * The function shall then return -1 if the first argument is less than the
 * second argument, 1 if the first argument is greater than the second argument
 * and 0 if both arguments are equal. If the third argument is
 * <code>NULL</code>, it shall be ignored.
 */
typedef int(*cmp_func)(const void*,const void*,void*);

/**
 * Function pointer to a distance function.
 * 
 * The distance function shall take three arguments: the two values for which
 * the distance shall be computed and optional additional data.
 * The function shall then return the signed distance as integer value.
 */
typedef intmax_t(*distance_func)(const void*,const void*,void*);

/**
 * Function pointer to a copy function.
 * 
 * The copy function shall create a copy of the first argument and may use
 * additional data provided by the second argument. If the second argument is
 * <code>NULL</code>, it shall be ignored.

 * <b>Attention:</b> if pointers returned by functions of this type may be
 * passed to <code>free()</code> depends on the implementation of the
 * respective <code>copy_func</code>.
 */
typedef void*(*copy_func)(const void*,void*);

/**
 * Function pointer to a write function.
 * 
 * The signature of the write function shall be compatible to the signature
 * of standard <code>fwrite</code>, though it may use arbitrary data types for
 * source and destination.
 * 
 * The arguments shall contain (in ascending order): a pointer to the source,
 * the length of one element, the element count and a pointer to the
 * destination.
 */
typedef size_t(*write_func)(const void*, size_t, size_t, void*);

/**
 * Function pointer to a read function.
 * 
 * The signature of the read function shall be compatible to the signature
 * of standard <code>fread</code>, though it may use arbitrary data types for
 * source and destination.
 * 
 * The arguments shall contain (in ascending order): a pointer to the
 * destination, the length of one element, the element count and a pointer to
 * the source.
 */
typedef size_t(*read_func)(void*, size_t, size_t, void*);

#ifdef	__cplusplus
}
#endif

#endif	/* UCX_H */

mercurial