Add non-null and unused-result warnings for the external API.

GCC (and clang) supports extensions to annotate functions so that their
 results must be used and so that their arguments can't be statically
 provable to be null. If a caller violates these requirements they
 get a warning, so this helps them write correct code.

I deployed this in libopus a couple years ago with good success, and
 the implementation here is basically copied straight from that.

One consideration is that the non-null annotation teaches the optimizer
 and will actually compile out runtime non-nullness checks as dead-code.
 Since this is usually not whats wanted, the non-null annotations are
 disabled when compiling the library itself.

The commit also removes some dead inclusions of assert.h and introduces
 compatibility macros for restrict and inline in preparation for some
 portability improvements.
This commit is contained in:
Gregory Maxwell
2014-11-12 12:05:42 -08:00
parent 8ed7c33cd6
commit 8563713a4f
7 changed files with 131 additions and 42 deletions

View File

@@ -5,7 +5,6 @@
#ifndef _SECP256K1_ECMULT_GEN_IMPL_H_
#define _SECP256K1_ECMULT_GEN_IMPL_H_
#include <assert.h>
#include "scalar.h"
#include "group.h"
#include "ecmult_gen.h"

View File

@@ -5,7 +5,6 @@
#ifndef _SECP256K1_ECMULT_IMPL_H_
#define _SECP256K1_ECMULT_IMPL_H_
#include <assert.h>
#include "num.h"
#include "group.h"
#include "ecmult.h"

View File

@@ -6,7 +6,6 @@
#define _SECP256K1_FIELD_REPR_IMPL_H_
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "util.h"
#include "num.h"

View File

@@ -9,7 +9,6 @@
#include "libsecp256k1-config.h"
#endif
#include <assert.h>
#include <string.h>
#include "util.h"
#include "num.h"

View File

@@ -5,7 +5,6 @@
#ifndef _SECP256K1_NUM_REPR_IMPL_H_
#define _SECP256K1_NUM_REPR_IMPL_H_
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <gmp.h>

View File

@@ -2,9 +2,10 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#define SECP256K1_BUILD (1)
#include "include/secp256k1.h"
#include <assert.h>
#include "util.h"
#include "num_impl.h"
#include "field_impl.h"