struct object *subtract(struct object *a, struct object *b) { if (a->type != b->type) error("TypeError: subtraction of incompatible types"); if (a->type == TYPE_NONE) error("TypeError: subtraction is not defined on null objects"); else if (a->type == TYPE_CODE) error("TypeError: subtraction is not defined on code objects"); else if (a->type == TYPE_STRING) error("TypeError: subtraction is not defined on strings"); else if (a->type == TYPE_INT) { long long result = (long long)*(int *)a->value - *(int *)b->value; int value = (int)result; if (result > INT_MAX || result < INT_MIN) error("OverflowError: integer subtraction result out of bounds"); return new_object(TYPE_INT, &value); } else if (a->type == TYPE_FLOAT) { double value = *(double *)a->value - *(double *)b->value; if (isinf(value)) error("OverflowError: floating-point subtraction result out of bounds"); return new_object(TYPE_FLOAT, &value); } }
struct object *multiply(struct object *a, struct object *b) { if (a->type == TYPE_STRING && b->type == TYPE_INT) { struct object *temp = a; a = b, b = temp; } if (a->type == TYPE_INT && b->type == TYPE_STRING) { int i = *(int *)a->value; if (i > 0) { struct object *object; char *value = safe_malloc(i * strlen(b->value) + 1); *value = '\0'; while (i--) strcat(value, b->value); object = new_object(TYPE_STRING, value); free(value); return object; } else // return empty string if integer is negative { char value = '\0'; return new_object(TYPE_STRING, &value); } } else if (a->type != b->type) error("TypeError: multiplication of incompatible types"); else if (a->type == TYPE_NONE) error("TypeError: multiplication is not defined on null objects"); else if (a->type == TYPE_CODE) error("TypeError: multiplication is not defined on code objects"); else if (a->type == TYPE_INT) { long long result = (long long)*(int *)a->value * *(int *)b->value; int value = (int)result; if (result > INT_MAX || result < INT_MIN) error("OverflowError: integer multiplication result out of bounds"); return new_object(TYPE_INT, &value); } else if (a->type == TYPE_FLOAT) { double value = *(double *)a->value * *(double *)b->value; if (isinf(value)) error("OverflowError: floating-point multiplication result out of bounds"); return new_object(TYPE_FLOAT, &value); } }
void load_scene5_objects(t_scene *scene) { add_object(scene, new_object(CONE, new_cone(new_vector(0, 1, -0.5), new_vector(8, 4, -5), 30), new_color(LIGHT_BLUE), 100)); add_object(scene, new_object(CYLINDER, new_cylinder(new_vector(0, 1, -0.3), new_vector(-10, 0, -5), 2), new_color(PASTEL_BLUE), 100)); add_object(scene, new_object(SPHERE, new_sphere(-1, 3, 2, 2), new_color(BLUE), 100)); add_object(scene, new_object(PLANE, new_plane(0, -1, 0, 0), new_color(DARK_GREY), 100)); }
obj eval_internal (obj expr) { switch (get_type (expr)) { case cons_type: { obj car, cdr; decons (expr, &car, &cdr); if (car == obj_LAMBDA) { objhdr *p; obj res = new_object (closure_type, &p); p -> u.closure_val.environment = current_environment; p -> u.closure_val.code = expr; return (res); } return (apply_internal (car, cdr)); } case symbol_type: case rom_symbol_type: return (symbol_value (expr)); default: return (expr); } }
/* * A radiogroup separates radiobuttons from each other. */ object newradiogroup(void) { object obj; ensure_window(); obj = new_object(RadiogroupObject, NULL, current_window); return obj; }
/* smooth != 0 gives continuous not segmented bar */ progressbar newprogressbar(rect r, int pbmin, int pbmax, int incr, int smooth) { HWND hwnd; progressbar obj; int sm; ensure_window(); r = rcanon(r); sm = smooth ? PBS_SMOOTH : 0 ; hwnd = CreateWindowEx(0, PROGRESS_CLASS, NULL, (WS_CHILD | WS_VISIBLE | sm), r.x, r.y, r.width, r.height, current_window->handle, (HMENU) child_id, this_instance, NULL); obj = new_object(ControlObject, hwnd, current_window); if (! obj) { DestroyWindow(hwnd); return NULL; } obj->die = private_delcontrol; obj->rect = r; obj->id = child_id++; obj->action = NULL; obj->state = (Visible | Enabled); obj->flags = ChildWindow; set_new_winproc(obj); /* set custom winproc */ settextfont(obj, SystemFont); obj->kind = ListboxObject; SendMessage(hwnd, PBM_SETRANGE32, (WPARAM) pbmin, (LPARAM) pbmax); SendMessage(hwnd, PBM_SETSTEP, (WPARAM) incr, 0); return obj; }
/** * new_type() * etch_type constructor */ etch_type* new_type(const wchar_t* name) { etch_type_impl* impl = NULL; etchparentinfo* inheritlist = NULL; etch_type* newtype = new_id_name(name); if (NULL == newtype) return NULL; ((etch_object*)newtype)->obj_type = ETCHTYPEB_TYPE; ((etch_object*)newtype)->class_id = CLASSID_ID_TYPE; /* ensure parent type keys exist in (one-based) inheritance list */ inheritlist = get_vtab_inheritance_list((etch_object*)newtype, 2, 1, CLASSID_VTAB_FIELD); inheritlist[1].o.obj_type = ETCHTYPEB_ID_NAME; inheritlist[1].c.class_id = CLASSID_ID_NAME; /* instantiate instance data */ impl = (etch_type_impl*) new_object(sizeof(etch_type_impl), ETCHTYPEB_IDNAMEIMPL, CLASSID_TYPEIMPL); ((etch_object*)impl)->destroy = destroy_type_impl; impl->async_mode = ETCH_ASYNCMODE_NONE; /* where is this default reset? */ impl->fieldmap = new_etchtype_fieldmap(); impl->vtormap = new_etchtype_vtormap(); newtype->impl = (etch_object*) impl; ((etch_object*)newtype)->destroy = destroy_type; ((etch_object*)newtype)->clone = clone_type; return newtype; }
void * RexxCode::operator new(size_t size) /******************************************************************************/ /* Function: Create a new rexx method code instance */ /******************************************************************************/ { return new_object(size, T_RexxCode); /* Get new object */ }
/* * call-seq: * sub(val[,mask]) * * Return new CvScalar if <i>val</i> is CvScalar or compatible object. * self[I] - val[I] * Or return new CvMat if <i>val</i> is CvMat or subclass. */ VALUE rb_sub(int argc, VALUE *argv, VALUE self) { VALUE val, mask; rb_scan_args(argc, argv, "11", &val, &mask); if (rb_obj_is_kind_of(val, cCvMat::rb_class())) { CvArr *val_ptr = CVARR(val); VALUE dest = Qnil; try { dest = cCvMat::new_object(cvGetSize(val_ptr), cvGetElemType(val_ptr)); cvSubRS(val_ptr, *CVSCALAR(self), CVARR(dest), MASK(mask)); } catch (cv::Exception& e) { raise_cverror(e); } return dest; } else { CvScalar *src = CVSCALAR(self); CvScalar scl = VALUE_TO_CVSCALAR(val); return new_object(cvScalar(src->val[0] - scl.val[0], src->val[1] - scl.val[1], src->val[2] - scl.val[2], src->val[3] - scl.val[3])); } }
static void create(varargs int clone) { TestRunner runner; COMPILE(HTTP_LOGD); /* Log daemon */ COMPILE(DAV_HOME + "initd"); /* Initialize DAV objects */ COMPILE(HTTP_AUTHENTICATE); /* Authentication daemon */ COMPILE(HTTP_AUTHORIZE); /* Authorization daemon */ #if 0 COMPILE(HTTP_STATUSD_400_500); /* Error-page handler */ #endif COMPILE(HTTP_SERVER); /* The web-server */ COMPILE(HTTP_APP); /* Web-application container */ COMPILE(HTTP_MIME); /* Mime container */ COMPILE(HTTP_COOKIE); /* Cookie container */ COMPILE(HTTP_SESSION); /* Session container */ COMPILE(HTTP_USER); /* http user object */ COMPILE(HTTP_CONTENT); /* Content container */ COMPILE(HTTP_REQUEST); /* Request object */ COMPILE(HTTP_RESPONSE); /* Response object */ COMPILE(HTTP_URI); /* URI object */ /* Run the TestAll test-suite */ runner = new_object(JORINDE_LUNIT + "data/runner"); runner->initialize( HTTP_HOME + "tests/TestAll" ); runner->silent_on_success(TRUE); runner->error_on_failure(TRUE); runner->run(); /* Done initializing */ server = find_object(HTTP_SERVER); /* ... keep reference to this */ if(server->is_started()) { DGDSYSLOG(server->get_server_string() + " started.\n"); DGDSYSLOG("Log: " + (SERVER_LOG)[1..] + "\n"); } else {
object get_wiztool(string user) { object wiztool; int firstchar; string creator; ACCESS_CHECK(PRIVILEGED() || INTERFACE()); creator = DRIVER->creator(previous_program()); CHECKARG(user && user != "" && STRINGD->is_valid_username(user), 1, "get_proxy"); check_security(user, creator); wiztool = new_object("~/lwo/wiztool", user); if (audit) { INITD->message("Wiztool being issued to " + creator + " for " + user); } return wiztool; }
object get_proxy(string user) { object proxy; int firstchar; string creator; ACCESS_CHECK(PRIVILEGED() || INTERFACE()); creator = DRIVER->creator(previous_program()); CHECKARG(user && user != "" && STRINGD->is_valid_username(user), 1, "get_proxy"); check_security(user, creator); proxy = new_object("~/lwo/proxy", user); /* only the object who requested a proxy is allowed to use it */ proxy->set_client(previous_object()); if (audit) { INITD->message("User access proxy being issued to " + creator + " for " + user + ", assigned to " + object_name(previous_object())); } return proxy; }
int lua_apr_dir_open(lua_State *L) { apr_status_t status; const char *filepath; lua_apr_dir *directory; filepath = luaL_checkstring(L, 1); directory = new_object(L, &lua_apr_dir_type); if (directory == NULL) return push_error_memory(L); /* Create a memory pool for the lifetime of the directory object. */ status = apr_pool_create(&directory->memory_pool, NULL); if (APR_SUCCESS != status) { directory->memory_pool = NULL; return push_error_status(L, status); } /* Try to open a handle to the directory. */ status = apr_dir_open(&directory->handle, filepath, directory->memory_pool); if (APR_SUCCESS != status) { directory->handle = NULL; return push_error_status(L, status); } /* Initialize and return the directory object. */ directory->filepath = apr_pstrdup(directory->memory_pool, filepath); return 1; }
struct object *modulo(struct object *a, struct object *b) { if (a->type != b->type) error("TypeError: modulo operation on incompatible types"); if (a->type == TYPE_NONE) error("TypeError: modulo operation is not defined on null objects"); else if (a->type == TYPE_CODE) error("TypeError: modulo operation is not defined on code objects"); else if (a->type == TYPE_STRING) error("TypeError: modulo operation is not defined on strings"); else if (a->type == TYPE_FLOAT) error("TypeError: modulo operation is not defined on floating-point numbers"); else if (a->type == TYPE_INT) { int value = *(int *)b->value; if (!value) error("ValueError: integer division by zero"); value = *(int *)a->value % value; return new_object(TYPE_INT, &value); } }
void cpp_typecheckt::new_temporary( const source_locationt &source_location, const typet &type, const exprt::operandst &ops, exprt &temporary) { // create temporary object exprt tmp_object_expr=exprt(ID_side_effect, type); tmp_object_expr.set(ID_statement, ID_temporary_object); tmp_object_expr.add_source_location()= source_location; exprt new_object(ID_new_object); new_object.add_source_location()=tmp_object_expr.source_location(); new_object.set(ID_C_lvalue, true); new_object.type()=tmp_object_expr.type(); already_typechecked(new_object); codet new_code = cpp_constructor(source_location, new_object, ops); if(new_code.is_not_nil()) { if(new_code.get(ID_statement)==ID_assign) tmp_object_expr.move_to_operands(new_code.op1()); else tmp_object_expr.add(ID_initializer)=new_code; } temporary.swap(tmp_object_expr); }
/*------------------------------------------------------------------------- * Function: test_create * * Purpose: Creates a named object that refers to indexed storage of raw * data. No raw data is stored. * * Return: Success: SUCCEED * * Failure: FAIL * * Programmer: Robb Matzke * Wednesday, October 15, 1997 * * Modifications: * *------------------------------------------------------------------------- */ static herr_t test_create(hid_t f, const char *prefix) { hid_t dataset; /* Dataset ID */ hsize_t dims[H5O_LAYOUT_NDIMS+1]; /* Dimensions of dataset */ hsize_t my_chunk_dims[H5O_LAYOUT_NDIMS+1]; /* Dimensions of chunks */ char name[256]; /* Dataset name */ unsigned u; /* Local index variable */ TESTING("istore create"); dims[0] = my_chunk_dims[0] = 1; for (u = 1; u <= H5S_MAX_RANK; u++) { /* Initialize the dimension size in this new dimension */ dims[u] = my_chunk_dims[u] = 2; /* Create chunked dataset of this dimensionality */ HDsnprintf(name, sizeof name, "%s_%02u", prefix, u); if ((dataset=new_object(f, name, (int)u, dims, my_chunk_dims)) < 0) return FAIL; /* Close dataset created */ if(H5Dclose(dataset) < 0) return FAIL; } PASSED(); return SUCCEED; }
void recv_create_object(void) { /* Unpack the object header. */ int i = new_object(); int n = recv_index(); int j, k; struct object *o = get_object(i); struct object_mesh *m = NULL; o->count = 1; /* Unpack the vertices and meshes. */ o->vv = recv_vector(); o->mv = vecnew(n, sizeof (struct object_mesh)); for (j = 0; j < n; ++j) if ((k = vecadd(o->mv)) >= 0) { m = (struct object_mesh *) vecget(o->mv, k); m->brush = recv_index(); m->fv = recv_vector(); m->ev = recv_vector(); } /* Encapsulate this object in an entity. */ recv_create_entity(); }
PROTECTED font new_font_object(HFONT hf) { TEXTMETRIC tm; HDC dc; HFONT old; object obj; obj = new_object(FontObject, hf, get_font_base()); if (! obj) { DeleteObject(hf); return NULL; } obj->die = private_delfont; dc = GetDC(0); old = SelectObject(dc, hf); GetTextMetrics(dc, &tm); obj->depth = 1; obj->rect.width = tm.tmAveCharWidth; obj->rect.height = tm.tmHeight; obj->rect.x = tm.tmAscent - tm.tmInternalLeading; obj->rect.y = tm.tmDescent; SelectObject(dc, old); ReleaseDC(0, dc); return (font) obj; }
static dbref make_player(const char *name, const char *password, const char *host, const char *ip) { dbref player; char temp[SBUF_LEN]; char *flaglist, *flagname; char flagbuff[BUFFER_LEN]; player = new_object(); /* initialize everything */ set_name(player, name); Location(player) = PLAYER_START; Home(player) = PLAYER_START; Owner(player) = player; Parent(player) = NOTHING; Type(player) = TYPE_PLAYER; Flags(player) = new_flag_bitmask("FLAG"); strcpy(flagbuff, options.player_flags); flaglist = trim_space_sep(flagbuff, ' '); if (*flaglist != '\0') { while (flaglist) { flagname = split_token(&flaglist, ' '); twiddle_flag_internal("FLAG", player, flagname, 0); } } if (Suspect_Site(host, player) || Suspect_Site(ip, player)) set_flag_internal(player, "SUSPECT"); set_initial_warnings(player); /* Modtime tracks login failures */ ModTime(player) = (time_t) 0; (void) atr_add(player, pword_attr, password_hash(password, NULL), GOD, 0); giveto(player, START_BONUS); /* starting bonus */ (void) atr_add(player, "LAST", show_time(mudtime, 0), GOD, 0); (void) atr_add(player, "LASTSITE", host, GOD, 0); (void) atr_add(player, "LASTIP", ip, GOD, 0); (void) atr_add(player, "LASTFAILED", " ", GOD, 0); snprintf(temp, sizeof temp, "%d", START_QUOTA); (void) atr_add(player, "RQUOTA", temp, GOD, 0); (void) atr_add(player, "MAILCURF", "0", GOD, AF_LOCKED | AF_NOPROG | AF_WIZARD); add_folder_name(player, 0, "inbox"); /* link him to PLAYER_START */ PUSH(player, Contents(PLAYER_START)); add_player(player); add_lock(GOD, player, Basic_Lock, parse_boolexp(player, "=me", Basic_Lock), LF_DEFAULT); add_lock(GOD, player, Enter_Lock, parse_boolexp(player, "=me", Basic_Lock), LF_DEFAULT); add_lock(GOD, player, Use_Lock, parse_boolexp(player, "=me", Basic_Lock), LF_DEFAULT); current_state.players++; local_data_create(player); return player; }
static D_OBJ *load_object( lua_State *L ) { D_OBJ *o; if( !L ) return NULL; if( ( o = new_object() ) == NULL ) return NULL; lua_pushstring( L, "name" ); lua_gettable( L, -2 ); o->name = strdup( luaL_checkstring( L, -1 ) ); lua_pop( L, 1 ); lua_pushstring( L, "sDesc" ); lua_gettable( L, -2 ); o->sDesc = strdup( luaL_checkstring( L, -1 ) ); lua_pop( L, 1 ); lua_pushstring( L, "lDesc" ); lua_gettable( L, -2 ); o->lDesc = strdup( luaL_checkstring( L, -1 ) ); lua_pop( L, 1 ); lua_pushstring( L, "vnum" ); lua_gettable( L, -2 ); o->vnum = luaL_checknumber( L, -1 ); lua_pop( L, 1 ); return o; }
Object* create_int_obj(int data) { Object* o = new_object(T_INT); set_int_val(o, data); log("creating int object with value :%d %p\n", data, o); return o; }
static object newchildwin(char *kind, char *text, unsigned long style, rect r, actionfn fn) { HWND hwnd; object obj; ensure_window(); r = rcanon(r); hwnd = CreateWindow(kind, text, (WS_CHILD | WS_VISIBLE) | style, r.x, r.y, r.width, r.height, current_window->handle, (HMENU) child_id, this_instance, NULL); obj = new_object(ControlObject, hwnd, current_window); if (! obj) { DestroyWindow(hwnd); return NULL; } obj->die = private_delcontrol; obj->rect = r; obj->id = child_id++; obj->action = fn; obj->state = (Visible | Enabled); obj->flags = ChildWindow; obj->text = new_string(text); set_new_winproc(obj); /* set custom winproc */ settextfont(obj, SystemFont); return obj; }
void * RexxInstruction::operator new(size_t size) /******************************************************************************/ /* Function: Create a new translator object */ /******************************************************************************/ { return new_object(size, T_Instruction); /* Get new object */ }
dbref create_player(const char *name, const char *password) { dbref player; if (!ok_player_name(name) || !ok_password(password)) return NOTHING; /* else he doesn't already exist, create him */ player = new_object(); /* initialize everything */ NAME(player) = alloc_string(name); DBFETCH(player)->location = tp_player_start; /* home */ FLAGS(player) = TYPE_PLAYER | PCREATE_FLAGS; OWNER(player) = player; DBFETCH(player)->sp.player.home = tp_player_start; DBFETCH(player)->exits = NOTHING; DBFETCH(player)->sp.player.pennies = tp_start_pennies; DBFETCH(player)->sp.player.password = NULL; // handle this last DBFETCH(player)->sp.player.curr_prog = NOTHING; DBFETCH(player)->sp.player.insert_mode = 0; /* link him to tp_player_start */ PUSH(player, DBFETCH(tp_player_start)->contents); add_player(player); DBDIRTY(player); DBDIRTY(tp_player_start); set_password(player, password); return player; }
ScriptObject* TypeDescriber::describeMetadataInfo(PoolObject* pool, uint32_t metadata_index) { AvmCore* core = m_toplevel->core(); const uint8_t* metadata_pos = pool->metadata_infos[metadata_index]; const uint32_t name_index = (metadata_pos) ? AvmCore::readU30(metadata_pos) : 0; // A bit of a hack: if the pool is builtin, always omit metadata chunks with names of "Version" // or "native", since these are used for reserved purposes internally. Stringp name = poolstr(pool, name_index); AvmAssert(name->isInterned() && core->kVersion->isInterned() && str(kstrid_native)->isInterned()); if (pool->isBuiltin && (name == core->kVersion || name == str(kstrid_native))) return NULL; const uint32_t val_count = (metadata_pos) ? AvmCore::readU30(metadata_pos) : 0; ScriptObject* o = new_object(); ArrayObject* a = new_array(); if (val_count > 0) { GC* gc = core->GetGC(); List<uint32_t> key_indexes(gc); List<uint32_t> val_indexes(gc); read_u30_list(key_indexes, val_count, metadata_pos); read_u30_list(val_indexes, val_count, metadata_pos); for (uint32_t i = 0; i < val_count; ++i) { ScriptObject* v = new_object(); const KVPair props[] = { { kstrid_key, strAtom(poolstr(pool, key_indexes.get(i))) }, { kstrid_value, strAtom(poolstr(pool, val_indexes.get(i))) }, }; setpropmulti(v, props, elem_count(props)); pushobj(a, v); } } const KVPair props[] = { { kstrid_name, strAtom(name) }, { kstrid_value, objAtom(a) }, }; setpropmulti(o, props, elem_count(props)); return o; }
/* * Create/return the base printer object. */ static object get_printer_base(void) { static object printer_base = NULL; if (! printer_base) printer_base = new_object(BaseObject, 0, NULL); return printer_base; }
/* * Private object constructor. */ static object get_font_base(void) { static object font_base = NULL; if (! font_base) font_base = new_object(BaseObject, 0, NULL); return font_base; }
/* * Create/return the base printer object. */ static object get_metafile_base(void) { static object metafile_base = NULL; if (! metafile_base) metafile_base = new_object(BaseObject, 0, NULL); return metafile_base; }
void *RexxSupplier::operator new(size_t size) /****************************************************************************/ /* Function: Create a new supplier object */ /****************************************************************************/ { /* Get new object */ return new_object(size, T_Supplier); }
void *RexxEnvelope::operator new(size_t size) /******************************************************************************/ /* Function: Create a new translator object */ /******************************************************************************/ { /* Get new object */ return new_object(sizeof(RexxEnvelope), T_Envelope); }