Next Previous Contents

78. SLang_push_malloced_string

Synopsis

Push a malloced string onto the stack

Usage

int SLang_push_malloced_string (char *s);

Description

SLang_push_malloced_string may be used to push a malloced string onto the interpreter's run-time stack. It returns zero upon success, or -1 upon error setting SLang_Error accordingly.

Example

The following example illustrates that it is up to the calling routine to free the string if SLang_push_malloced_string fails:

      int push_hello (void)
      {
         char *s = malloc (6);
         if (s == NULL) return -1;
         strcpy (s, "hello");
         if (-1 == SLang_push_malloced_string (s))
           {
              free (s);
              return -1;
           }
         return 0;
      }
Example

The function SLang_create_slstring returns a hashed string. Such a string may not be malloced and should not be passed to SLang_push_malloced_string.

Notes

If s is NULL, this function pushes NULL (SLANG_NULL_TYPE) onto the stack.

See Also

SLang_push_string, SLmake_string


Next Previous Contents