Mercurial > hg
view contrib/python-zstandard/zstd/common/error_private.h @ 47305:33e7508b0ae9
hg-cpython: fix new occuring TypeError
dd339191f2dc introduced a minor refactoring of error types that highlighted
a fragile error creation mechanism that was in place in the Rust `MixedIndex`.
`PyErr::from_instance` also accepts a Python class, as long as it's an
`Exception` class. Before the aforementioned commit, we never ran into a case
where this duck-typing mechanism failed. We rectify this behavior by doing the
instantiation ourselves.
Differential Revision: https://phab.mercurial-scm.org/D10764
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Fri, 21 May 2021 17:37:53 +0200 |
parents | b1fb341d8a61 |
children |
line wrap: on
line source
/* * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. * All rights reserved. * * This source code is licensed under both the BSD-style license (found in the * LICENSE file in the root directory of this source tree) and the GPLv2 (found * in the COPYING file in the root directory of this source tree). * You may select, at your option, one of the above-listed licenses. */ /* Note : this module is expected to remain private, do not expose it */ #ifndef ERROR_H_MODULE #define ERROR_H_MODULE #if defined (__cplusplus) extern "C" { #endif /* **************************************** * Dependencies ******************************************/ #include <stddef.h> /* size_t */ #include "zstd_errors.h" /* enum list */ /* **************************************** * Compiler-specific ******************************************/ #if defined(__GNUC__) # define ERR_STATIC static __attribute__((unused)) #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) # define ERR_STATIC static inline #elif defined(_MSC_VER) # define ERR_STATIC static __inline #else # define ERR_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ #endif /*-**************************************** * Customization (error_public.h) ******************************************/ typedef ZSTD_ErrorCode ERR_enum; #define PREFIX(name) ZSTD_error_##name /*-**************************************** * Error codes handling ******************************************/ #undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */ #define ERROR(name) ZSTD_ERROR(name) #define ZSTD_ERROR(name) ((size_t)-PREFIX(name)) ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); } ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); } /*-**************************************** * Error Strings ******************************************/ const char* ERR_getErrorString(ERR_enum code); /* error_private.c */ ERR_STATIC const char* ERR_getErrorName(size_t code) { return ERR_getErrorString(ERR_getErrorCode(code)); } #if defined (__cplusplus) } #endif #endif /* ERROR_H_MODULE */