/* After this call, the stack will contain an Any_Type object */ static int anytype_push (SLtype type, VOID_STAR ptr) { SLang_Any_Type *obj; /* Push the object onto the stack, then pop it back off into our anytype * container. That way, any memory managing associated with the type * will be performed automatically. Another way to think of it is that * pushing an Any_Type onto the stack will create another copy of the * object represented by it. */ if (-1 == _pSLpush_slang_obj (*(SLang_Object_Type **)ptr)) return -1; if (-1 == SLang_pop_anytype (&obj)) return -1; /* There is no need to reference count the anytype objects since every * push results in a new anytype container. */ if (-1 == SLclass_push_ptr_obj (type, (VOID_STAR) obj)) { SLang_free_anytype (obj); return -1; } return 0; }
static int test_type_sput (SLtype type, SLFUTURE_CONST char *name) { Test_Type *t; int status; (void) type; if (-1 == pop_test_type (&t)) return -1; status = -1; if (0 == strcmp (name, "field1")) status = SLang_pop_int (&t->field1); else if (0 == strcmp (name, "field2")) status = SLang_pop_int (&t->field2); else if (0 == strcmp (name, "any")) { SLang_Any_Type *any; if (0 == (status = SLang_pop_anytype (&any))) { SLang_free_anytype (t->any); t->any = any; } } else SLang_verror (SL_INVALID_PARM, "Test_Type.%s is invalid", name); free_test_type (t); return status; }
/* AnyType */ int _pSLanytype_typecast (SLtype a_type, VOID_STAR ap, unsigned int na, SLtype b_type, VOID_STAR bp) { SLang_Class_Type *cl; SLang_Any_Type **any; unsigned int i; unsigned int sizeof_type; (void) b_type; any = (SLang_Any_Type **) bp; cl = _pSLclass_get_class (a_type); sizeof_type = cl->cl_sizeof_type; for (i = 0; i < na; i++) { if ((-1 == (*cl->cl_apush) (a_type, ap)) || (-1 == SLang_pop_anytype (&any[i]))) { while (i != 0) { i--; SLang_free_anytype (any[i]); any[i] = NULL; } return -1; } ap = (VOID_STAR)((char *)ap + sizeof_type); } return 1; }
static int transfer_element (SLang_Class_Type *cl, VOID_STAR dest_data, SLang_Object_Type *obj) { unsigned int sizeof_type; VOID_STAR src_data; #if USE_NEW_ANYTYPE_CODE if (cl->cl_data_type == SLANG_ANY_TYPE) { SLang_Any_Type *any; if ((-1 == _pSLpush_slang_obj (obj)) || (-1 == SLang_pop_anytype (&any))) return -1; *(SLang_Any_Type **)dest_data = any; return 0; } #endif /* Optimize for scalar */ if (cl->cl_class_type == SLANG_CLASS_TYPE_SCALAR) { sizeof_type = cl->cl_sizeof_type; memcpy ((char *) dest_data, (char *)&obj->v, sizeof_type); return 0; } src_data = _pSLclass_get_ptr_to_value (cl, obj); if (-1 == (*cl->cl_acopy) (cl->cl_data_type, src_data, dest_data)) return -1; return 0; }
void jed_set_blocal_var (char *name) /*{{{*/ { Jed_BLocal_Type *lv; lv = find_blocal_var (name, 1); if (lv == NULL) return; SLang_free_anytype (lv->value); lv->value = NULL; (void) SLang_pop_anytype (&lv->value); }
static void set_rline_update_hook (void) { Rline_CB_Type *cb; SLrline_Type *rli; if (NULL == (cb = (Rline_CB_Type *)SLmalloc(sizeof(Rline_CB_Type)))) return; memset ((char *)cb, 0, sizeof(Rline_CB_Type)); switch (SLang_Num_Function_Args) { default: SLang_verror (SL_Usage_Error, "Usage: rline_set_update_hook (rli [,&hook [,clientdata]]);"); return; case 3: if (-1 == SLang_pop_anytype (&cb->cd)) return; /* drop */ case 2: if (NULL == (cb->update_hook = SLang_pop_function ())) goto free_and_return; /* drop */ case 1: if (NULL == (cb->mmt = pop_sri_type (&cb->sri))) goto free_and_return; } cb->sri->output_newline = 0; rli = cb->sri->rli; SLrline_set_update_clear_cb (rli, rline_update_clear_cb); SLrline_set_update_preread_cb (rli, rline_update_preread_cb); SLrline_set_update_postread_cb (rli, rline_update_postread_cb); SLrline_set_update_width_cb (rli, rline_update_width_cb); if (0 == SLrline_set_update_hook (rli, rline_call_update_hook, (VOID_STAR)cb)) { SLrline_set_free_update_cb (rli, free_rli_update_data_cb); return; } /* drop */ free_and_return: free_cb_info (cb); }
/* Usage: obj = cvs_decoder_new (&read_callback, callback_data, delim, quote, flags) */ static void new_csv_decoder_intrin (void) { CSV_Type *csv; SLang_MMT_Type *mmt; if (NULL == (csv = (CSV_Type *)SLmalloc(sizeof(CSV_Type)))) return; memset ((char *)csv, 0, sizeof(CSV_Type)); if ((-1 == SLang_pop_int (&csv->flags)) ||(-1 == SLang_pop_char (&csv->quotechar)) || (-1 == SLang_pop_char (&csv->delimchar)) || (-1 == SLang_pop_anytype (&csv->callback_data)) || (NULL == (csv->read_callback = SLang_pop_function ())) || (NULL == (mmt = SLang_create_mmt (CSV_Type_Id, (VOID_STAR)csv)))) { free_csv_type (csv); return; } if (-1 == SLang_push_mmt (mmt)) SLang_free_mmt (mmt); }