scimem.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 /* Copyright INRIA */
00003 /*-----------------------------------------------------------------------------------*/
00004 #include "MALLOC.h"
00005 #include "stack-c.h"
00006 #include "scimem.h"
00007 #include "sciprint.h"
00008 /*-----------------------------------------------------------------------------------*/
00009 static char *the_p=NULL;
00010 static char *the_ps=NULL;
00011 static char *the_gp=NULL;
00012 static char *the_gps=NULL;
00013 /*-----------------------------------------------------------------------------------*/
00014 integer C2F(scimem)(integer *n, integer *ptr)
00015 {
00016   register char *p1 = NULL;
00017   if (*n > 0)
00018   {
00019         /* add 1 for alignment problems */
00020     p1 = (char *) SCISTACKMALLOC(((unsigned long) sizeof(double)) * (*n + 1));
00021                   
00022     if (p1 != NULL) 
00023         {
00024                 the_ps = the_p;
00025                 the_p = p1;
00026                 /* add 1 for alignment problems */
00027                 *ptr = ((int) (the_p - (char *)C2F(stack).Stk))/sizeof(double) + 1;
00028     }
00029     else 
00030     {
00031                 if (the_p == NULL) 
00032                 {
00033                         sciprint("No space to allocate Scilab stack\r\n");
00034                         exit(1); 
00035                 }
00036                 *ptr=0;
00037     }
00038   }
00039   return(0);
00040 }
00041 /*-----------------------------------------------------------------------------------*/
00042 integer C2F(scigmem)(integer *n, integer *ptr)
00043 {
00044   register char *p1=NULL;
00045   if (*n > 0)
00046   {
00047     /* add 1 for alignment problems */
00048     p1 = (char *) SCISTACKMALLOC((unsigned)sizeof(double) * (*n + 1));
00049     if (p1 != NULL) 
00050         {
00051                 the_gps = the_gp;
00052                 the_gp = p1;
00053                 /* add 1 for alignment problems */
00054                 *ptr = ((int) (the_gp - (char *)C2F(stack).Stk))/sizeof(double) + 1;
00055     }
00056     else 
00057     {
00058                 if (the_gp == NULL) 
00059                 {
00060                         sciprint("No space to allocate Scilab stack\r\n");
00061                         exit(1); 
00062                 }
00063                 *ptr=0;
00064     }
00065   }
00066   return(0);
00067 }
00068 /*-----------------------------------------------------------------------------------*/
00069 void C2F(freegmem)(void)
00070 {
00071   if (the_gps != NULL) SCISTACKFREE(the_gps);
00072 }
00073 /*-----------------------------------------------------------------------------------*/
00074 void C2F(freemem)(void)
00075 {
00076   if (the_ps != NULL) SCISTACKFREE(the_ps);
00077 }
00078 /*-----------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:47 2007 for Scilab [trunk] by  doxygen 1.5.1