PyObject * Repository_revparse_single(Repository *self, PyObject *py_spec) { git_object *c_obj; char *c_spec; char *encoding = "ascii"; int err; /* 1- Get the C revision spec */ c_spec = py_str_to_c_str(py_spec, encoding); if (c_spec == NULL) return NULL; /* 2- Lookup */ err = git_revparse_single(&c_obj, self->repo, c_spec); if (err < 0) { PyObject *err_obj = Error_set_str(err, c_spec); free(c_spec); return err_obj; } free(c_spec); return wrap_object(c_obj, self); }
PyObject * Repository_revparse_single(Repository *self, PyObject *py_spec) { git_object *c_obj; const char *c_spec; PyObject *tspec; int err; /* 1- Get the C revision spec */ c_spec = py_str_borrow_c_str(&tspec, py_spec, NULL); if (c_spec == NULL) return NULL; /* 2- Lookup */ err = git_revparse_single(&c_obj, self->repo, c_spec); if (err < 0) { PyObject *err_obj = Error_set_str(err, c_spec); Py_DECREF(tspec); return err_obj; } Py_DECREF(tspec); return wrap_object(c_obj, self); }
/* Creates a new instance based on the type object. */ static PMC * instance_of(PARROT_INTERP, PMC *WHAT) { KnowHOWREPRInstance *obj = mem_allocate_zeroed_typed(KnowHOWREPRInstance); obj->common.stable = STABLE_PMC(WHAT); obj->methods = pmc_new(interp, enum_class_Hash); obj->attributes = pmc_new(interp, enum_class_ResizablePMCArray); return wrap_object(interp, obj); }
/* Clones the current object. This involves cloning the method and * attribute lists and copying the (immutable string) name. */ static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) { KnowHOWREPRInstance *obj = mem_allocate_zeroed_typed(KnowHOWREPRInstance); obj->common.stable = STABLE_PMC(to_clone); obj->methods = VTABLE_clone(interp, ((KnowHOWREPRInstance *)PMC_data(to_clone))->methods); obj->attributes = VTABLE_clone(interp, ((KnowHOWREPRInstance *)PMC_data(to_clone))->attributes); obj->name = ((KnowHOWREPRInstance *)PMC_data(to_clone))->name; return wrap_object(interp, obj); }
/* Creates a new instance based on the type object. */ static PMC * instance_of(PARROT_INTERP, PMC *WHAT) { HashAttrStoreInstance *obj; /* Allocate and set up object instance. */ obj = (HashAttrStoreInstance *) Parrot_gc_allocate_fixed_size_storage(interp, sizeof(HashAttrStoreInstance)); obj->common.stable = STABLE_PMC(WHAT); obj->store = pmc_new(interp, enum_class_Hash); return wrap_object(interp, obj); }
/* Clone. Clone object body and the attribute storage hash. */ static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) { HashAttrStoreInstance *obj; /* Allocate and set up object instance. */ obj = (HashAttrStoreInstance *) Parrot_gc_allocate_fixed_size_storage(interp, sizeof(HashAttrStoreInstance)); obj->common.stable = STABLE_PMC(to_clone); obj->store = VTABLE_clone(interp, ((HashAttrStoreInstance *)PMC_data(to_clone))->store); return wrap_object(interp, obj); }
int LuaIOLib::io_open(lua_State *lua) { const char *filename = luaL_checkstring(lua, 1); const char *mode = luaL_optstring(lua, 2, "r"); int i = 0; /* check whether 'mode' matches '[rwa]%+?b?' */ auto file_mode = FileHandle::NONE; while (mode[i] != '\0') { auto m = mode[i++]; if (m == 'r') { file_mode |= FileHandle::READ; } else if (m == 'w') { file_mode |= FileHandle::WRITE; } else if (m == 'a') { file_mode |= FileHandle::APPEND; } else if (m == '+') { file_mode |= FileHandle::READ | FileHandle::WRITE; } else { return luaL_error(lua, "invalid mode " LUA_QS " (should match " LUA_QL("[rwa]%%+?b?") ")", mode); } } auto process = proc(lua); auto &info = process->info(); auto &vfs = info.kernel()->virtual_file_system(); FileHandle *handle = nullptr; vfs.open(info.id(), filename, file_mode, handle); if (handle == nullptr) { return luaL_fileresult(lua, 0, filename); } auto result = new LuaFile(); result->file(handle); wrap_object(lua, result); return 1; }
/** * <h1>map.GetPlayers()</h1> * * Get all the players on a specified map. * @return Python list containing pointers to player objects on the * map. */ static PyObject *Atrinik_Map_GetPlayers(Atrinik_Map *map, PyObject *args) { PyObject *list = PyList_New(0); object *tmp; (void) args; for (tmp = map->map->player_first; tmp; tmp = CONTR(tmp)->map_above) { PyList_Append(list, wrap_object(tmp)); } return list; }
PyObject * lookup_object_prefix(Repository *repo, const git_oid *oid, size_t len, git_otype type) { int err; git_object *obj; err = git_object_lookup_prefix(&obj, repo->repo, oid, (unsigned int)len, type); if (err < 0) return Error_set_oid(err, oid, len); return wrap_object(obj, repo); }
/* Creates a new type object of this representation, and associates it with * the given HOW. */ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) { /* Create new type object instance. */ UninstantiableInstance *obj = mem_allocate_zeroed_typed(UninstantiableInstance); /* Build an STable. */ PMC *st_pmc = create_stable(interp, this_repr, HOW); STable *st = STABLE_STRUCT(st_pmc); /* Create type object and point it back at the STable. */ obj->common.stable = st_pmc; st->WHAT = wrap_object(interp, obj); PARROT_GC_WRITE_BARRIER(interp, st_pmc); return st->WHAT; }
PyObject * Object_peel(Object *self, PyObject *py_type) { int type = -1, err; git_object *peeled; type = py_object_to_object_type(py_type); if (type == -1) return NULL; err = git_object_peel(&peeled, self->obj, (git_otype)type); if (err < 0) return Error_set(err); return wrap_object(peeled, self->repo); }
/* Creates a new type object of this representation, and associates it with * the given HOW. */ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) { /* Create new object instance. */ HashAttrStoreInstance *obj = mem_allocate_zeroed_typed(HashAttrStoreInstance); /* Build an STable. */ PMC *st_pmc = create_stable(interp, this_repr, HOW); STable *st = STABLE_STRUCT(st_pmc); /* Create type object and point it back at the STable. We leave the * hash store pointer null to flag it's the type object. */ obj->common.stable = st_pmc; st->WHAT = wrap_object(interp, obj); PARROT_GC_WRITE_BARRIER(interp, st_pmc); return st->WHAT; }
/* Clones the current object. */ static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) { P6opaqueInstance *obj; P6opaqueREPRData *repr_data = (P6opaqueREPRData *)STABLE(to_clone)->REPR_data; if (defined(interp, to_clone)) { obj = (P6opaqueInstance *)Parrot_gc_allocate_fixed_size_storage(interp, repr_data->allocation_size); memcpy(obj, PMC_data(to_clone), repr_data->allocation_size); if (!PMC_IS_NULL(obj->spill)) obj->spill = VTABLE_clone(interp, obj->spill); } else { obj = mem_allocate_zeroed_typed(P6opaqueInstance); memcpy(obj, PMC_data(to_clone), sizeof(P6opaqueInstance)); } return wrap_object(interp, obj); }
/** * <h1>player.GetEquipment(\<int\> slot)</h1> * Get a player's current equipment for a given slot. * @param slot One of @ref PLAYER_EQUIP_xxx constants. * @throws ValueError if 'slot' is lower than 0 or higher than @ref PLAYER_EQUIP_MAX. * @return The equipment for the given slot, can be None. */ static PyObject *Atrinik_Player_GetEquipment(Atrinik_Player *pl, PyObject *args) { int slot; if (!PyArg_ParseTuple(args, "i", &slot)) { return NULL; } if (slot < 0 || slot >= PLAYER_EQUIP_MAX) { PyErr_SetString(PyExc_ValueError, "Invalid slot number."); return NULL; } return wrap_object(pl->pl->equipment[slot]); }
/* Creates a new instance based on the type object. */ static PMC * allocate(PARROT_INTERP, STable *st) { P6opaqueInstance * obj; /* Compute allocation strategy if we've not already done so. */ P6opaqueREPRData * repr_data = (P6opaqueREPRData *) st->REPR_data; if (!repr_data->allocation_size) { compute_allocation_strategy(interp, st->WHAT, repr_data); PARROT_GC_WRITE_BARRIER(interp, st->stable_pmc); } /* Allocate and set up object instance. */ obj = (P6opaqueInstance *) Parrot_gc_allocate_fixed_size_storage(interp, repr_data->allocation_size); memset(obj, 0, repr_data->allocation_size); obj->common.stable = st->stable_pmc; return wrap_object(interp, obj); }
PyObject * Object_peel(Object *self, PyObject *py_type) { int err; git_otype otype; git_object *peeled; otype = py_object_to_otype(py_type); if (otype == GIT_OBJ_BAD) return NULL; err = git_object_peel(&peeled, self->obj, otype); if (err < 0) return Error_set(err); return wrap_object(peeled, self->repo); }
PyObject * Commit_parents__get__(Commit *self) { Repository *py_repo; unsigned int i, parent_count; const git_oid *parent_oid; git_commit *parent; int err; PyObject *py_parent; PyObject *list; parent_count = git_commit_parentcount(self->commit); list = PyList_New(parent_count); if (!list) return NULL; py_repo = self->repo; for (i=0; i < parent_count; i++) { parent_oid = git_commit_parent_id(self->commit, i); if (parent_oid == NULL) { Py_DECREF(list); Error_set(GIT_ENOTFOUND); return NULL; } err = git_commit_lookup(&parent, py_repo->repo, parent_oid); if (err < 0) { Py_DECREF(list); return Error_set_oid(err, parent_oid, GIT_OID_HEXSZ); } py_parent = wrap_object((git_object*)parent, py_repo); if (py_parent == NULL) { Py_DECREF(list); return NULL; } PyList_SET_ITEM(list, i, py_parent); } return list; }
/** * <h1>map.GetFirstObject(<i>\<int\></i> x, <i>\<int\></i> y)</h1> * * Gets the first object on the tile. Use object::below to browse * objects. * @param x X position on the map. * @param y Y position on the map. * @return The object if found. */ static PyObject *Atrinik_Map_GetFirstObject(Atrinik_Map *map, PyObject *args) { int x, y; object *val = NULL; mapstruct *m = map->map; if (!PyArg_ParseTuple(args, "ii", &x, &y)) { return NULL; } if ((m = hooks->get_map_from_coord(m, &x, &y))) { /* Since map objects are loaded in reverse mode, the last one in * in the list is actually the first. */ val = GET_MAP_OB_LAST(m, x, y); } return wrap_object(val); }
/* Creates a new instance based on the type object. */ static PMC * instance_of(PARROT_INTERP, PMC *WHAT) { P6opaqueInstance * obj; /* Compute allocation strategy if we've not already done so. */ P6opaqueREPRData * repr_data = (P6opaqueREPRData *) STABLE(WHAT)->REPR_data; if (!repr_data->allocation_size) { compute_allocation_strategy(interp, WHAT, repr_data); PARROT_GC_WRITE_BARRIER(interp, STABLE_PMC(WHAT)); } /* Allocate and set up object instance. */ obj = (P6opaqueInstance *) Parrot_gc_allocate_fixed_size_storage(interp, repr_data->allocation_size); memset(obj, 0, repr_data->allocation_size); obj->common.stable = STABLE_PMC(WHAT); /* The spill slot gets set to PMCNULL; it not being (C) NULL is what * lets us know it's actually a real instance, not a type object. */ obj->spill = PMCNULL; return wrap_object(interp, obj); }
PyObject * Repository_git_object_lookup_prefix(Repository *self, PyObject *key) { int err; size_t len; git_oid oid; git_object *obj; len = py_oid_to_git_oid(key, &oid); if (len == 0) return NULL; err = git_object_lookup_prefix(&obj, self->repo, &oid, len, GIT_OBJ_ANY); if (err == 0) return wrap_object(obj, self); if (err == GIT_ENOTFOUND) Py_RETURN_NONE; return Error_set_oid(err, &oid, len); }
/* Creates a new type object of this representation, and associates it with * the given HOW. */ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) { /* Create new object instance. */ P6opaqueInstance *obj = mem_allocate_zeroed_typed(P6opaqueInstance); /* Build an STable. */ PMC *st_pmc = create_stable(interp, this_repr, HOW); STable *st = STABLE_STRUCT(st_pmc); /* Create REPR data structure and hand it off the STable. */ st->REPR_data = mem_allocate_zeroed_typed(P6opaqueREPRData); /* Create type object and point it back at the STable. */ obj->common.stable = st_pmc; st->WHAT = wrap_object(interp, obj); PARROT_GC_WRITE_BARRIER(interp, st_pmc); /* Flag it as a type object. */ MARK_AS_TYPE_OBJECT(st->WHAT); return st->WHAT; }
/* Creates a new type object of this representation, and associates it with * the given HOW. */ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) { /* Create new object instance. */ P6opaqueInstance *obj = mem_allocate_zeroed_typed(P6opaqueInstance); /* Build an STable. */ PMC *st_pmc = create_stable(interp, this_repr, HOW); STable *st = STABLE_STRUCT(st_pmc); /* Create REPR data structure and hand it off the STable. */ st->REPR_data = mem_allocate_zeroed_typed(P6opaqueREPRData); /* Create type object and point it back at the STable. Note that we * do *not* populate the spill pointer at all, we leave it null. A * non-null value (even PMCNULL) is what indicates we have a defined * object. Yes, I know, it's sick. */ obj->common.stable = st_pmc; st->WHAT = wrap_object(interp, obj); PARROT_GC_WRITE_BARRIER(interp, st_pmc); return st->WHAT; }
PyObject * Reference_peel(Reference *self, PyObject *args) { int err, type; git_object *obj; PyObject *py_type = Py_None; CHECK_REFERENCE(self); if (!PyArg_ParseTuple(args, "|O", &py_type)) return NULL; type = py_object_to_object_type(py_type); if (type == -1) return NULL; err = git_reference_peel(&obj, self->reference, type); if (err < 0) return Error_set(err); return wrap_object(obj, self->repo); }
/* Creates a new type object of this representation, and associates it with * the given HOW. */ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) { /* Create new object instance. */ P6numInstance *obj = mem_allocate_zeroed_typed(P6numInstance); P6numREPRData *repr_data = mem_allocate_zeroed_typed(P6numREPRData); /* Build an STable. */ PMC *st_pmc = create_stable(interp, this_repr, HOW); STable *st = STABLE_STRUCT(st_pmc); /* Set default bit width value in the REPR data and attach it to the * STable. */ repr_data->bits = sizeof(FLOATVAL)*8; st->REPR_data = repr_data; /* Create type object and point it back at the STable. */ obj->common.stable = st_pmc; st->WHAT = wrap_object(interp, obj); PARROT_GC_WRITE_BARRIER(interp, st_pmc); /* Flag it as a type object. */ MARK_AS_TYPE_OBJECT(st->WHAT); return st->WHAT; }
/** * <h1>map.CreateObject(<i>\<string\></i> arch_name, <i>\<int\></i> x, * <i>\<int\></i> y)</h1> * * Create an object on map. * @param arch_name Arch name of the object to create * @param x X position on the map * @param y Y position on the map * @warning Not tested. */ static PyObject *Atrinik_Map_CreateObject(Atrinik_Map *map, PyObject *args) { char *txt; int x, y; archetype *arch; object *newobj; if (!PyArg_ParseTuple(args, "sii", &txt, &x, &y)) { return NULL; } if (!(arch = hooks->find_archetype(txt)) || !(newobj = hooks->arch_to_object(arch))) { return NULL; } newobj->x = x; newobj->y = y; newobj = hooks->insert_ob_in_map(newobj, map->map, NULL, 0); return wrap_object(newobj); }
/* Creates a new instance based on the type object. */ static PMC * allocate(PARROT_INTERP, STable *st) { P6strInstance *obj = mem_allocate_zeroed_typed(P6strInstance); obj->common.stable = st->stable_pmc; return wrap_object(interp, obj); }
/* Clones the current object. */ static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) { UninstantiableInstance *obj = mem_allocate_zeroed_typed(UninstantiableInstance); obj->common.stable = STABLE_PMC(to_clone); return wrap_object(interp, obj); }
/* Creates a new instance based on the type object. */ static PMC * allocate(PARROT_INTERP, STable *st) { KnowHOWREPRInstance *obj = mem_allocate_zeroed_typed(KnowHOWREPRInstance); if (st) obj->common.stable = st->stable_pmc; return wrap_object(interp, obj); }
/* Clones the current object; simply copies the value. */ static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) { P6intInstance *obj = mem_allocate_zeroed_typed(P6intInstance); obj->common.stable = STABLE_PMC(to_clone); obj->value = ((P6intInstance *)PMC_data(to_clone))->value; return wrap_object(interp, obj); }
/* Creates a new instance based on the type object. */ static PMC * instance_of(PARROT_INTERP, PMC *WHAT) { P6intInstance *obj = mem_allocate_zeroed_typed(P6intInstance); obj->common.stable = STABLE_PMC(WHAT); obj->value = 0; return wrap_object(interp, obj); }