File: gmpy2.h

package info (click to toggle)
python-gmpy2 2.1.0~a4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,048 kB
  • sloc: ansic: 24,051; python: 325; makefile: 117
file content (591 lines) | stat: -rw-r--r-- 20,719 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * gmpy2.h                                                                 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Python interface to the GMP or MPIR, MPFR, and MPC multiple precision   *
 * libraries.                                                              *
 *                                                                         *
 * Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,               *
 *           2008, 2009 Alex Martelli                                      *
 *                                                                         *
 * Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014,                     *
 *           2015, 2016, 2017, 2018 Case Van Horsen                        *
 *                                                                         *
 * This file is part of GMPY2.                                             *
 *                                                                         *
 * GMPY2 is free software: you can redistribute it and/or modify it under  *
 * the terms of the GNU Lesser General Public License as published by the  *
 * Free Software Foundation, either version 3 of the License, or (at your  *
 * option) any later version.                                              *
 *                                                                         *
 * GMPY2 is distributed in the hope that it will be useful, but WITHOUT    *
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or   *
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public    *
 * License for more details.                                               *
 *                                                                         *
 * You should have received a copy of the GNU Lesser General Public        *
 * License along with GMPY2; if not, see <http://www.gnu.org/licenses/>    *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


/*
  gmpy C API extension header file.
  Part of Python's gmpy module since version 0.4

  Created by Pearu Peterson <pearu@cens.ioc.ee>, November 2000.
  Edited by A. Martelli <aleaxit@yahoo.com>, December 2000.
  Edited by Case Van Horsen <casevh@gmail.com>, 2009, 2010, 2011.

  Version 1.02, February 2007.
  Version 1.03, June 2008
  Version 1.04, June 2008 (no changes)
  Version 1.05, February 2009 (support MPIR)
  Version 1.20, January 2010 (remove obsolete MS hacks) casevh
  Version 2.00, April 2010 (change to gmpy2) casevh
                October 2010 (added Py_hash_t) casevh
                December 2010 (added mpfr, mpc) casevh
                January 2011 (add Pygmpy_context) casevh
                April 2011 (split into multiple files) casevh
  Version 2.10  August 2014 (reflect major rewrite during 2013/2014) casevh
 */

#ifndef Py_GMPYMODULE_H
#define Py_GMPYMODULE_H

#ifdef __cplusplus
extern "C" {
#endif

/* Structure of gmpy2.h
 *
 * Revised 17-APR-2017 casevh
 *
 * 1. Checks for specific Python versions.
 * 2. Include headers for GMP/MPIR, MPFR, and MPC.
 * 3. Define public C-API.
 *    1. Define gmpy2 types.
 *    2. Define the public API.
 *
 */

/* Check for minimum Python version requirements. */

#if PY_VERSION_HEX < 0x02060000
#  error "GMPY2 requires Python 2.6 or later."
#endif

/* Include headers for GMP/MPIR, MPFR, and MPC. */

#ifdef MPIR
#  include <mpir.h>
#else
#  include <gmp.h>
#endif

#include <mpfr.h>
#include <mpc.h>

#if PY_VERSION_HEX < 0x030200A4
typedef long Py_hash_t;
typedef unsigned long Py_uhash_t;
#  define _PyHASH_IMAG 1000003
#endif

/* The native_si and native_ui types correspond to long long on Windows 64. They
 * should only be used with the MPIR library (not MPFR/MPC).
 */

#if defined(MPIR) && defined(_WIN64)
typedef long long native_si;
typedef unsigned long long native_ui;
#define GMPy_Integer_AsNative_siAndError GMPy_Integer_AsLongLongAndError
#define GMPy_Integer_AsNative_uiAndError GMPy_Integer_AsUnsignedLongLongAndError
#else
typedef long native_si;
typedef unsigned long native_ui;
#define GMPy_Integer_AsNative_siAndError GMPy_Integer_AsLongAndError
#define GMPy_Integer_AsNative_uiAndError GMPy_Integer_AsUnsignedLongAndError
#endif

/* GMPY2 Public API */

/* Types
 *    MPZ_Object
 *    XMPZ_Object        (mutable version of MPZ_Object)
 *    MPQ_Object
 *    XMPQ_Object        (mutable version of MPQ_Object)
 *    MPFR_Object
 *    XMPFR_Object       (mutable version of MPFR_Object)
 *    MPC_Object
 *    XMPC_Object        (mutable version of MPC_Object)
 *    CTXT_Object
 *    CTXT_Manager_Object
 *    RandomState_Object
 */

typedef struct {
    PyObject_HEAD
    mpz_t z;
    Py_hash_t hash_cache;
} MPZ_Object;

typedef struct {
    PyObject_HEAD
    mpz_t z;
} XMPZ_Object;

typedef struct {
    PyObject_HEAD
    mpq_t q;
    Py_hash_t  hash_cache;
} MPQ_Object;

typedef struct {
    PyObject_HEAD
    mpfr_t f;
    Py_hash_t hash_cache;
    int rc;
} MPFR_Object;

typedef struct {
    PyObject_HEAD
    mpc_t c;
    Py_hash_t hash_cache;
    int rc;
} MPC_Object;

typedef struct {
    PyObject_HEAD
    gmp_randstate_t state;
} RandomState_Object;

typedef struct {
    mpfr_prec_t mpfr_prec;   /* current precision in bits, for MPFR */
    mpfr_rnd_t mpfr_round;   /* current rounding mode for float (MPFR) */
    mpfr_exp_t emax;         /* maximum exponent */
    mpfr_exp_t emin;         /* minimum exponent */
    int subnormalize;        /* if 1, subnormalization is performed */
    int underflow;           /* did an underflow occur? */
    int overflow;            /* did an overflow occur? */
    int inexact;             /* was the result inexact? */
    int invalid;             /* invalid operation (i.e. NaN)? */
    int erange;              /* did a range error occur? */
    int divzero;             /* divided by zero? */
    int traps;               /* if 0, do not trap any exceptions */
                             /* if not 0, then raise traps per bits above  */
    mpfr_prec_t real_prec;   /* current precision in bits, for Re(MPC) */
    mpfr_prec_t imag_prec;   /* current precision in bits, for Im(MPC) */
    mpfr_rnd_t real_round;   /* current rounding mode for Re(MPC) */
    mpfr_rnd_t imag_round;   /* current rounding mode for Im(MPC) */
    int allow_complex;       /* if 1, allow mpfr functions to return an mpc */
    int rational_division;   /* if 1, mpz/mpz returns an mpq result */
} gmpy_context;

typedef struct {
    PyObject_HEAD
    gmpy_context ctx;
#ifndef WITHOUT_THREADS
    PyThreadState *tstate;
#endif
} CTXT_Object;

typedef struct {
    PyObject_HEAD
    CTXT_Object *new_context; /* Context that will be returned when
                               * __enter__ is called. */
    CTXT_Object *old_context; /* Context that will restored when
                               * __exit__ is called. */
} CTXT_Manager_Object;

#define MPZ(obj)  (((MPZ_Object*)(obj))->z)
#define MPQ(obj)  (((MPQ_Object*)(obj))->q)
#define MPFR(obj) (((MPFR_Object*)(obj))->f)
#define MPC(obj)  (((MPC_Object*)(obj))->c)

/* Start of the C-API definitions */

#define MPZ_Type_NUM          0
#define XMPZ_Type_NUM         1
#define MPQ_Type_NUM          2
#define XMPQ_Type_NUM         3
#define MPFR_Type_NUM         4
#define XMPFR_Type_NUM        5
#define MPC_Type_NUM          6
#define XMPC_Type_NUM         7
#define CTXT_Type_NUM         8
#define CTXT_Manager_Type_NUM 9
#define RandomState_Type_NUM  10

/* The following functions are found in gmpy2_cache. */

#define GMPy_MPZ_New_NUM            11
#define GMPy_MPZ_New_RETURN         MPZ_Object *
#define GMPy_MPZ_New_PROTO          (CTXT_Object *context)

#define GMPy_MPZ_NewInit_NUM        12
#define GMPy_MPZ_NewInit_RETURN     PyObject *
#define GMPy_MPZ_NewInit_PROTO      (PyTypeObject *type, PyObject *args, PyObject *keywds)

#define GMPy_MPZ_Dealloc_NUM        13
#define GMPy_MPZ_Dealloc_RETURN     void
#define GMPy_MPZ_Dealloc_PROTO      (MPZ_Object *self)

/* The following function is found in gmpy2_convert_gmp. */

#define GMPy_MPZ_ConvertArg_NUM     14
#define GMPy_MPZ_ConvertArg_RETURN  int
#define GMPy_MPZ_ConvertArg_PROTO   (PyObject *arg, PyObject **ptr)

/* The following functions are found in gmpy2_cache. */

#define GMPy_XMPZ_New_NUM           15
#define GMPy_XMPZ_New_RETURN        XMPZ_Object *
#define GMPy_XMPZ_New_PROTO         (CTXT_Object *context)

#define GMPy_XMPZ_NewInit_NUM       16
#define GMPy_XMPZ_NewInit_RETURN    PyObject *
#define GMPy_XMPZ_NewInit_PROTO     (PyTypeObject *type, PyObject *args, PyObject *keywds)

#define GMPy_XMPZ_Dealloc_NUM       17
#define GMPy_XMPZ_Dealloc_RETURN    void
#define GMPy_XMPZ_Dealloc_PROTO     (XMPZ_Object *self)

/* The following functions are found in gmpy2_cache. */

#define GMPy_MPQ_New_NUM            18
#define GMPy_MPQ_New_RETURN         MPQ_Object *
#define GMPy_MPQ_New_PROTO          (CTXT_Object *context)

#define GMPy_MPQ_NewInit_NUM        19
#define GMPy_MPQ_NewInit_RETURN     PyObject *
#define GMPy_MPQ_NewInit_PROTO      (PyTypeObject *type, PyObject *args, PyObject *keywds)

#define GMPy_MPQ_Dealloc_NUM        20
#define GMPy_MPQ_Dealloc_RETURN     void
#define GMPy_MPQ_Dealloc_PROTO      (MPQ_Object *self)

/* The following function is found in gmpy2_convert_gmp. */

#define GMPy_MPQ_ConvertArg_NUM     21
#define GMPy_MPQ_ConvertArg_RETURN  int
#define GMPy_MPQ_ConvertArg_PROTO   (PyObject *arg, PyObject **ptr)

/* The following functions are found in gmpy2_cache. */

#define GMPy_MPFR_New_NUM           22
#define GMPy_MPFR_New_RETURN        MPFR_Object *
#define GMPy_MPFR_New_PROTO         (mpfr_prec_t bits, CTXT_Object *context)

#define GMPy_MPFR_NewInit_NUM       23
#define GMPy_MPFR_NewInit_RETURN    PyObject *
#define GMPy_MPFR_NewInit_PROTO     (PyTypeObject *type, PyObject *args, PyObject *keywds)

#define GMPy_MPFR_Dealloc_NUM       24
#define GMPy_MPFR_Dealloc_RETURN    void
#define GMPy_MPFR_Dealloc_PROTO     (MPFR_Object *self)

/* The following function is found in gmpy2_convert_gmp. */

#define GMPy_MPFR_ConvertArg_NUM    25
#define GMPy_MPFR_ConvertArg_RETURN int
#define GMPy_MPFR_ConvertArg_PROTO  (PyObject *arg, PyObject **ptr)

/* The following functions are found in gmpy2_cache. */

#define GMPy_MPC_New_NUM             26
#define GMPy_MPC_New_RETURN          MPC_Object *
#define GMPy_MPC_New_PROTO           (mpfr_prec_t rprec, mpfr_prec_t iprec, CTXT_Object *context)

#define GMPy_MPC_NewInit_NUM         27
#define GMPy_MPC_NewInit_RETURN      PyObject *
#define GMPy_MPC_NewInit_PROTO       (PyTypeObject *type, PyObject *args, PyObject *keywds)

#define GMPy_MPC_Dealloc_NUM        28
#define GMPy_MPC_Dealloc_RETURN     void
#define GMPy_MPC_Dealloc_PROTO      (MPC_Object *self)

/* The following function is found in gmpy2_convert_gmp. */

#define GMPy_MPC_ConvertArg_NUM     29
#define GMPy_MPC_ConvertArg_RETURN  int
#define GMPy_MPC_ConvertArg_PROTO   (PyObject *arg, PyObject **ptr)

/* Total number of C-API pointers. */

#define GMPy_API_pointers 30

/* End of C-API definitions. */

#ifdef GMPY2_MODULE

/* Define various macros to deal with differences between Python 2 and 3. */

#if (PY_MAJOR_VERSION == 3)
#define PY3
#define Py2or3String_FromString     PyUnicode_FromString
#define Py2or3String_FromFormat     PyUnicode_FromFormat
#define Py2or3String_Check          PyUnicode_Check
#define Py2or3String_Format         PyUnicode_Format
#define Py2or3String_AsString       PyUnicode_AS_DATA
#define PyStrOrUnicode_Check(op)    (PyBytes_Check(op) || PyUnicode_Check(op))
#define PyIntOrLong_FromLong        PyLong_FromLong
#define PyIntOrLong_Check(op)       PyLong_Check(op)
#define PyIntOrLong_FromSize_t      PyLong_FromSize_t
#define PyIntOrLong_FromSsize_t     PyLong_FromSsize_t
#define PyIntOrLong_AsSsize_t       PyLong_AsSsize_t
#define PyIntOrLong_AsLong          PyLong_AsLong
#else
#define PY2
#define Py2or3String_FromString     PyString_FromString
#define Py2or3String_FromFormat     PyString_FromFormat
#define Py2or3String_Check          PyString_Check
#define Py2or3String_Format         PyString_Format
#define Py2or3String_AsString       PyString_AsString
#define PyStrOrUnicode_Check(op)    (PyString_Check(op) || PyUnicode_Check(op))
#define PyIntOrLong_FromLong        PyInt_FromLong
#define PyIntOrLong_Check(op)       (PyInt_Check(op) || PyLong_Check(op))
#define PyIntOrLong_FromSize_t      PyInt_FromSize_t
#define PyIntOrLong_FromSsize_t     PyInt_FromSsize_t
#define PyIntOrLong_AsSsize_t       PyInt_AsSsize_t
#define PyIntOrLong_AsLong          PyInt_AsLong
#endif

#ifndef ABS
#  define ABS(a)  (((a) < 0) ? -(a) : (a))
#endif

#if defined(MS_WIN32) && defined(_MSC_VER)
   /* so one won't need to link explicitly to gmp.lib...: */
#  if defined(MPIR)
#    pragma comment(lib,"mpir.lib")
#  else
#    pragma comment(lib,"gmp.lib")
#  endif
#  define USE_ALLOCA 1
#  define inline __inline
#endif

#ifdef __GNUC__
#  define USE_ALLOCA 1
#endif

#ifndef alloca
# ifdef __GNUC__
#  define alloca __builtin_alloca
# else
#   ifdef _MSC_VER
#    include <malloc.h>
#    define alloca _alloca
#   else
#    if HAVE_ALLOCA_H
#     include <alloca.h>
#    else
       char *alloca ();
#    endif
#   endif
# endif
#endif

#define ALLOC_THRESHOLD 8192

#define INDEX_ERROR(msg)    PyErr_SetString(PyExc_IndexError, msg)
#define TYPE_ERROR(msg)     PyErr_SetString(PyExc_TypeError, msg)
#define VALUE_ERROR(msg)    PyErr_SetString(PyExc_ValueError, msg)
#define ZERO_ERROR(msg)     PyErr_SetString(PyExc_ZeroDivisionError, msg)
#define SYSTEM_ERROR(msg)   PyErr_SetString(PyExc_SystemError, msg)
#define OVERFLOW_ERROR(msg) PyErr_SetString(PyExc_OverflowError, msg)
#define RUNTIME_ERROR(msg)  PyErr_SetString(PyExc_RuntimeError, msg)

#define GMPY_DEFAULT -1

/* To prevent excessive memory usage, we don't want to save very large
 * numbers in the cache. The default value specified in the options
 * structure is 128 words (512 bytes on 32-bit platforms, 1024 bytes on
 * 64-bit platforms).
 */
#define MAX_CACHE_LIMBS 16384

/* The maximum number of objects that can be saved in a cache is specified
 * here. The default value is 100.*/
#define MAX_CACHE 1000

#ifdef USE_ALLOCA
#  define TEMP_ALLOC(B, S)     \
    if(S < ALLOC_THRESHOLD) {  \
        B = alloca(S);         \
    } else {                   \
        if(!(B = malloc(S))) { \
            PyErr_NoMemory();  \
            return NULL;       \
        }                      \
    }
#  define TEMP_FREE(B, S) if(S >= ALLOC_THRESHOLD) free(B)
#else
#  define TEMP_ALLOC(B, S)     \
    if(!(B = malloc(S)))  {    \
        PyErr_NoMemory();      \
        return NULL;           \
    }
#  define TEMP_FREE(B, S) free(B)
#endif

/* Various defs to mask differences between Python versions. */

#define Py_RETURN_NOTIMPLEMENTED \
    return Py_INCREF(Py_NotImplemented), Py_NotImplemented

#ifndef Py_SIZE
#  define Py_SIZE(ob)     (((PyVarObject*)(ob))->ob_size)
#endif

#ifndef Py_TYPE
#  define Py_TYPE(ob)     (((PyObject*)(ob))->ob_type)
#endif

/* Import a collection of general purpose macros. */

#include "gmpy2_macros.h"

/* Import the files that complete the definition of the types defined above. */

#include "gmpy2_mpz.h"
#include "gmpy2_xmpz.h"
#include "gmpy2_mpq.h"
#include "gmpy2_mpfr.h"
#include "gmpy2_mpc.h"
#include "gmpy2_context.h"
#include "gmpy2_random.h"

/* Import the header files that provide the various functions. */

/* Support object caching, creation, and deletion. */

#include "gmpy2_cache.h"

/* Suport for miscellaneous functions (ie. version, license, etc.). */

#include "gmpy2_misc.h"

/* Support conversion to/from binary format. */

#include "gmpy2_binary.h"

/* Support for mpz/xmpz specific functions. */

#include "gmpy2_convert.h"
#include "gmpy2_convert_utils.h"
#include "gmpy2_convert_gmp.h"
#include "gmpy2_convert_mpfr.h"
#include "gmpy2_convert_mpc.h"

#include "gmpy2_mpz_divmod.h"
#include "gmpy2_mpz_divmod2exp.h"
#include "gmpy2_mpz_pack.h"
#include "gmpy2_mpz_bitops.h"
#include "gmpy2_mpz_inplace.h"
#include "gmpy2_mpz_misc.h"

#include "gmpy2_xmpz_inplace.h"
#include "gmpy2_xmpz_misc.h"

/* Support for mpq specific functions. */

#include "gmpy2_mpq_misc.h"

/* Support for mpfr specific functions. */

#include "gmpy2_mpfr_misc.h"

/* Support for mpc specific functions. */

#include "gmpy2_mpc_misc.h"

/* Support Lucas sequences. */

#include "gmpy_mpz_lucas.h"

/* Support probable-prime tests. */

#include "gmpy_mpz_prp.h"

/* Support higher-level Python methods and functions; generally not
 * specific to a single type.
 */

#include "gmpy2_abs.h"
#include "gmpy2_add.h"
#include "gmpy2_divmod.h"
#include "gmpy2_floordiv.h"
#include "gmpy2_minus.h"
#include "gmpy2_mod.h"
#include "gmpy2_mul.h"
#include "gmpy2_plus.h"
#include "gmpy2_pow.h"
#include "gmpy2_sub.h"
#include "gmpy2_truediv.h"
#include "gmpy2_math.h"
#include "gmpy2_const.h"
#include "gmpy2_square.h"
#include "gmpy2_format.h"
#include "gmpy2_hash.h"
#include "gmpy2_fused.h"
#include "gmpy2_muldiv_2exp.h"
#include "gmpy2_predicate.h"
#include "gmpy2_sign.h"
#include "gmpy2_richcompare.h"

#ifdef VECTOR
#  include "gmpy2_vector.h"
#endif /* defined(VECTOR) */

#else /* defined(GMPY2_MODULE) */

/* This section is used for other C-coded modules that use gmpy2's API. */

static void **GMPy_C_API;

#define MPZ_Check(op)    ((op)->ob_type == (PyTypeObject*)GMPy_C_API[MPZ_Type_NUM])
#define XMPZ_Check(op)   ((op)->ob_type == (PyTypeObject*)GMPy_C_API[XMPZ_Type_NUM])
#define MPQ_Check(op)    ((op)->ob_type == (PyTypeObject*)GMPy_C_API[MPQ_Type_NUM])
#define XMPQ_Check(op)   ((op)->ob_type == (PyTypeObject*)GMPy_C_API[XMPQ_Type_NUM])
#define MPFR_Check(op)   ((op)->ob_type == (PyTypeObject*)GMPy_C_API[MPFR_Type_NUM])
#define XMPFR_Check(op)  ((op)->ob_type == (PyTypeObject*)GMPy_C_API[XMPFR_Type_NUM])
#define MPC_Check(op)    ((op)->ob_type == (PyTypeObject*)GMPy_C_API[MPC_Type_NUM])
#define XMPC_Check(op)   ((op)->ob_type == (PyTypeObject*)GMPy_C_API[XMPC_Type_NUM])

#define GMPy_MPZ_New         (*(GMPy_MPZ_New_RETURN         (*)GMPy_MPZ_New_PROTO)         GMPy_C_API[GMPy_MPZ_New_NUM])
#define GMPy_MPZ_NewInit     (*(GMPy_MPZ_NewInit_RETURN     (*)GMPy_MPZ_NewInit_PROTO)     GMPy_C_API[GMPy_MPZ_NewInit_NUM])
#define GMPy_MPZ_Dealloc     (*(GMPy_MPZ_Dealloc_RETURN     (*)GMPy_MPZ_Dealloc_PROTO)     GMPy_C_API[GMPy_MPZ_Dealloc_NUM])
#define GMPy_MPZ_ConvertArg  (*(GMPy_MPZ_ConvertArg_RETURN  (*)GMPy_MPZ_ConvertArg_PROTO)  GMPy_C_API[GMPy_MPZ_ConvertArg_NUM])

#define GMPy_XMPZ_New        (*(GMPy_XMPZ_New_RETURN        (*)GMPy_XMPZ_New_PROTO)        GMPy_C_API[GMPy_XMPZ_New_NUM])
#define GMPy_XMPZ_NewInit    (*(GMPy_XMPZ_NewInit_RETURN    (*)GMPy_XMPZ_NewInit_PROTO)    GMPy_C_API[GMPy_XMPZ_NewInit_NUM])
#define GMPy_XMPZ_Dealloc    (*(GMPy_XMPZ_Dealloc_RETURN    (*)GMPy_XMPZ_Dealloc_PROTO)    GMPy_C_API[GMPy_XMPZ_Dealloc_NUM])

#define GMPy_MPQ_New         (*(GMPy_MPQ_New_RETURN         (*)GMPy_MPQ_New_PROTO)         GMPy_C_API[GMPy_MPQ_New_NUM])
#define GMPy_MPQ_NewInit     (*(GMPy_MPQ_NewInit_RETURN     (*)GMPy_MPQ_NewInit_PROTO)     GMPy_C_API[GMPy_MPQ_NewInit_NUM])
#define GMPy_MPQ_Dealloc     (*(GMPy_MPQ_Dealloc_RETURN     (*)GMPy_MPQ_Dealloc_PROTO)     GMPy_C_API[GMPy_MPQ_Dealloc_NUM])
#define GMPy_MPQ_ConvertArg  (*(GMPy_MPQ_ConvertArg_RETURN  (*)GMPy_MPQ_ConvertArg_PROTO)  GMPy_C_API[GMPy_MPQ_ConvertArg_NUM])

#define GMPy_MPFR_New        (*(GMPy_MPFR_New_RETURN        (*)GMPy_MPFR_New_PROTO)        GMPy_C_API[GMPy_MPFR_New_NUM])
#define GMPy_MPFR_NewInit    (*(GMPy_MPFR_NewInit_RETURN    (*)GMPy_MPFR_NewInit_PROTO)    GMPy_C_API[GMPy_MPFR_NewInit_NUM])
#define GMPy_MPFR_Dealloc    (*(GMPy_MPFR_Dealloc_RETURN    (*)GMPy_MPFR_Dealloc_PROTO)    GMPy_C_API[GMPy_MPFR_Dealloc_NUM])
#define GMPy_MPFR_ConvertArg (*(GMPy_MPFR_ConvertArg_RETURN (*)GMPy_MPFR_ConvertArg_PROTO) GMPy_C_API[GMPy_MPFR_ConvertArg_NUM])

#define GMPy_MPC_New         (*(GMPy_MPC_New_RETURN         (*)GMPy_MPC_New_PROTO)         GMPy_C_API[GMPy_MPC_New_NUM])
#define GMPy_MPC_NewInit     (*(GMPy_MPC_NewInit_RETURN     (*)GMPy_MPC_NewInit_PROTO)     GMPy_C_API[GMPy_MPC_NewInit_NUM])
#define GMPy_MPC_Dealloc     (*(GMPy_MPC_Dealloc_RETURN     (*)GMPy_MPC_Dealloc_PROTO)     GMPy_C_API[GMPy_MPC_Dealloc_NUM])
#define GMPy_MPC_ConvertArg  (*(GMPy_MPC_ConvertArg_RETURN  (*)GMPy_MPC_ConvertArg_PROTO)  GMPy_C_API[GMPy_MPC_ConvertArg_NUM])

static int
import_gmpy2(void)
{
    GMPy_C_API = (void **)PyCapsule_Import("gmpy2._C_API", 0);
    return (GMPy_C_API != NULL) ? 0 : -1;
}

#endif /* defined(GMPY2_MODULE) */

#ifdef __cplusplus
}
#endif /* defined(__cplusplus */
#endif /* !defined(Py_GMPYMODULE_H */