;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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")


#? *** aux_convert

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

#? * (dummy_aux_convert)
#? * (pyaux_parsescalar <o> <s>)
#? * (pyaux_buildscalar <s> <p>)

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

(de PyAux_ParseScalar (o s)
    ((-gptr- "PyObject *") o)
    ((-str-) s)
    (let ((a (gptr ())))
      #{ {
	  switch(*((char*)$s->data))
	  {
	  case 'b':  $a = malloc(sizeof(char));   break;
	  case 'c':  $a = malloc(sizeof(char));   break;
	  case 'h':  $a = malloc(sizeof(short));  break;
	  case 'i':  $a = malloc(sizeof(int));    break;
	  case 'l':  $a = malloc(sizeof(long));   break;
	  case 'f':  $a = malloc(sizeof(float));  break;
	  case 'd':  $a = malloc(sizeof(double)); break;
	  case 's':  
	  case 'z':  $a = malloc(sizeof(char *)); break;
	  default: break;
	  }
	  PyArg_Parse($o,$s->data,$a);
	  } #}
	  a))


(de PyAux_BuildScalar (s p)
    ((-str-) s)
    ((-gptr-) p)
    (let ((a (gptr ())))
      #{ {
      switch(*((char*)$s->data))
      {
      case 'b':  $a = (void *) Py_BuildValue($s->data,*((char *)$p  )); break;
      case 'c':  $a = (void *) Py_BuildValue($s->data,*((char *)$p  )); break;
      case 'h':  $a = (void *) Py_BuildValue($s->data,*((short *)$p )); break;
      case 'i':  $a = (void *) Py_BuildValue($s->data,*((int *)$p   )); break;
      case 'l':  $a = (void *) Py_BuildValue($s->data,*((long *)$p  )); break;
      case 'f':  $a = (void *) Py_BuildValue($s->data,*((float *)$p )); break;
      case 'd':  $a = (void *) Py_BuildValue($s->data,*((double *)$p)); break;
      case 's':  
      case 'z':  $a = (void *) Py_BuildValue($s->data, (char *)$p); break;
      default: break;
      }
      } #}
      a))


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

(dhc-make () 
  dummy_aux_convert
  pyaux_parsescalar
  pyaux_buildscalar
)
