Version 4 of Fixing C Access to Bignums

Updated 2009-09-30 16:05:52 by dgp

The following routines in Tcl's public interface, tcl.h, make use of the mp_int type:

  • Tcl_NewBignumObj(mp_int *)
  • Tcl_DbNewBignumObj(mp_int *, const char *, int)
  • Tcl_SetBignumObj(Tcl_Obj *, mp_int *)
  • Tcl_GetBignumFromObj(Tcl_Interp *, Tcl_Obj *, mp_int *)
  • Tcl_TakeBignumFromObj(Tcl_Interp *, Tcl_Obj *, mp_int *)
  • Tcl_InitBignumFromDouble(Tcl_Interp *, double, mp_int *)

Tcl's public header, tcl.h also includes these declarations:

#ifndef MP_INT_DECLARED
typedef struct mp_int mp_int;
#define MP_INT_DECLARED
#endif
#ifndef MP_DIGIT_DECLARED
typedef unsigned long mp_digit;
#define MP_DIGIT_DECLARED
#endif

which allows the compiler to make sense of the function declarations.

Callers of those functions must be able to allocate an mp_int struct so they can pass its address in. In order to do this a definition of the mp_int struct has to be in scope, but Tcl's public header tcl.h does not provide one.

Q1: What header file are callers of these routines expected to #include to get a suitable mp_int definition in scope?

Q2: