;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; Includes information derived from the GSL (Gnu Scientific Library)
;;;   header files which are copyrighted and distributed under the GPL
;;;   by their respective authors.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program 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 General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(libload "python/python-config")


#? *** pylong

;; dummy function that adds Python C header files in C file
(eval `(de dummy_pylong () ,python-cpheader-cmd ()))

#? * (dummy_pylong)
#? * (pylong_fromlong <s>)
#? * (pylong_fromunsignedlong <s>)
#? * (pylong_fromlonglong <s>)
#? * (pylong_fromunsignedlonglong <s>)
#? * (pylong_fromdouble <s>)
#? * (pylong_fromvoidptr <om>)
#? * (pylong_fromstring <o1> <o2> <im>)
#? * (pylong_fromunicode <o1> <s> <im>)
#? * (_pylong_frombytearray <bytes> <n> <little_endian> <is_signed>)
#? * (pylong_aslong <om>)
#? * (pylong_asunsignedlong <om>)
#? * (pylong_aslonglong <om>)
#? * (pylong_asunsignedlonglong <om>)
#? * (_pylong_asscaleddouble <vv> <e>)
#? * (pylong_asdouble <om>)
#? * (pylong_asvoidptr <om>)
#? * (_pylong_asbytearray <v> <bytes> <n> <little_endian> <is_signed>)

;; ********************************************************

(de PyLong_FromLong ( s )
    ((-int-) s)      ;; long -> int
    (gptr  #{  PyLong_FromLong( (long) $s )  #} ))        ;; PyObject * -> gptr

(de PyLong_FromUnsignedLong ( s )
    ((-int-) s)      ;; unsigned long -> int
    (gptr  #{  PyLong_FromUnsignedLong( (unsigned long) $s )  #} ))        ;; PyObject * -> gptr

(de PyLong_FromLongLong ( s )
    ((-int-) s)        ;; LONG_LONG -> int
    (gptr  #{  PyLong_FromLongLong( (LONG_LONG) $s )  #} ))        ;; PyObject * -> gptr

(de PyLong_FromUnsignedLongLong ( s )
    ((-int-) s)         ;; unsigned LONG_LONG -> int
    (gptr  #{  PyLong_FromUnsignedLongLong( (unsigned LONG_LONG)$s )  #} ))     ;; PyObject * -> gptr

(de PyLong_FromDouble ( s )
    ((-double-) s)   
    (gptr  #{  PyLong_FromDouble( $s )  #} ))        ;; PyObject * -> gptr

(de PyLong_FromVoidPtr ( om )
    ((-gptr-) om)   
    (gptr  #{  PyLong_FromVoidPtr( $om )  #} ))        ;; PyObject * -> gptr

(de PyLong_FromString ( o1  o2  im )
    ((-gptr-"char *") o1)  
    ((-gptr-"char **") o2)  
    ((-int-) im)   
    (gptr  #{  PyLong_FromString( $o1   ,$o2   ,$im )  #} ))        ;; PyObject * -> gptr

(de PyLong_FromUnicode ( o1  s  im )
    ((-gptr- "Py_UNICODE *") o1)  
    ((-int-) s)
    ((-int-) im)   
    (gptr  #{  PyLong_FromUnicode( $o1 ,$s ,$im )  #} ))        ;; PyObject * -> gptr

(de _PyLong_FromByteArray ( bytes  n  little_endian  is_signed )
    ((-gptr-"const unsigned char*") bytes)  
    ((-int-) n)   ;; size_t -> int
    ((-int-) little_endian)  
    ((-int-) is_signed)   
    (gptr  #{ _PyLong_FromByteArray( $bytes   ,$n   ,$little_endian   ,$is_signed )  #} ))        ;; PyObject * -> gptr

(de PyLong_AsLong ( om )
    ((-gptr-"PyObject *") om)   
    (int  #{  PyLong_AsLong( $om )  #} ))      ;; long -> int

(de PyLong_AsUnsignedLong ( om )
    ((-gptr-"PyObject *") om)   
    (int  #{  PyLong_AsUnsignedLong( $om )  #} ))    ;; unsigned long -> int

(de PyLong_AsLongLong ( om )
    ((-gptr-"PyObject *") om)   
    (int  #{  PyLong_AsLongLong( $om )  #} ))       ;; LONG_LONG -> int

(de PyLong_AsUnsignedLongLong ( om )
    ((-gptr-"PyObject *") om)   
    (int  #{  PyLong_AsUnsignedLongLong( $om )  #} ))       ;; unsigned LONG_LONG -> int

(de _PyLong_AsScaledDouble ( vv  e )
    ((-gptr-"PyObject *") vv)  
    ((-gptr-"int *") e)   
    (double  #{ _PyLong_AsScaledDouble( $vv  ,$e )  #} ))

(de PyLong_AsDouble ( om )
    ((-gptr-"PyObject *") om)   
    (double  #{  PyLong_AsDouble( $om )  #} ))

(de PyLong_AsVoidPtr ( om )
    ((-gptr-"PyObject *") om)   
    (gptr  #{  PyLong_AsVoidPtr( $om )  #} ))   ;; void * -> gptr

(de _PyLong_AsByteArray ( v  bytes  n  little_endian  is_signed )
    ((-gptr-"PyLongObject *") v)  
    ((-gptr-"unsigned char*") bytes)  
    ((-int-) n)   ;; size_t -> int
    ((-int-) little_endian)  
    ((-int-) is_signed)   
    (int  #{ _PyLong_AsByteArray( $v   ,$bytes   ,$n   ,$little_endian   ,$is_signed )  #} ))


;; ********************************************************

(dhc-make () 
  dummy_pylong
  pylong_fromlong
  pylong_fromunsignedlong
  pylong_fromlonglong
  pylong_fromunsignedlonglong
  pylong_fromdouble
  pylong_fromvoidptr
  pylong_fromstring
  pylong_fromunicode
  _pylong_frombytearray
  pylong_aslong
  pylong_asunsignedlong
  pylong_aslonglong
  pylong_asunsignedlonglong
  _pylong_asscaleddouble
  pylong_asdouble
  pylong_asvoidptr
  _pylong_asbytearray
)
