示例#1
0
文件: zipimport.c 项目: 3lnc/cpython
/* Check whether we can satisfy the import of the module named by
   'fullname'. Return self if we can, None if we can't. */
static PyObject *
zipimporter_find_module(PyObject *obj, PyObject *args)
{
    ZipImporter *self = (ZipImporter *)obj;
    PyObject *path = NULL;
    PyObject *fullname;
    PyObject *namespace_portion = NULL;
    PyObject *result = NULL;

    if (!PyArg_ParseTuple(args, "U|O:zipimporter.find_module", &fullname, &path))
        return NULL;

    switch (find_loader(self, fullname, &namespace_portion)) {
    case FL_ERROR:
        return NULL;
    case FL_NS_FOUND:
        /* A namespace portion is not allowed via find_module, so return None. */
        Py_DECREF(namespace_portion);
        /* FALL THROUGH */
    case FL_NOT_FOUND:
        result = Py_None;
        break;
    case FL_MODULE_FOUND:
        result = (PyObject *)self;
        break;
    default:
        PyErr_BadInternalCall();
        return NULL;
    }
    Py_INCREF(result);
    return result;
}
示例#2
0
/**
 * Try to load a savefile
 */
static bool try_load(ang_file *f, const struct blockinfo *loaders)
{
	struct blockheader b;
	errr err;

	if (!check_header(f)) {
		note("Savefile is corrupted -- incorrect file header.");
		return false;
	}

	/* Get the next block header */
	while ((err = next_blockheader(f, &b)) == 0) {
		loader_t loader = find_loader(&b, loaders);
		if (!loader) {
			note("Savefile block can't be read.");
			note("Maybe try and load the savefile in an earlier version of Angband.");
			return false;
		}

		if (!load_block(f, &b, loader)) {
			note(format("Savefile corrupted - Couldn't load block %s", b.name));
			return false;
		}
	}

	if (err == -1) {
		note("Savefile is corrupted -- block header mangled.");
		return false;
	}

	return true;
}
示例#3
0
/* Check whether we can satisfy the import of the module named by
   'fullname', or whether it could be a portion of a namespace
   package. Return self if we can load it, a string containing the
   full path if it's a possible namespace portion, None if we
   can't load it. */
static PyObject *
zipimporter_find_loader(PyObject *obj, PyObject *args)
{
    ZipImporter *self = (ZipImporter *)obj;
    PyObject *path = NULL;
    PyObject *fullname;
    PyObject *result = NULL;
    PyObject *namespace_portion = NULL;

    if (!PyArg_ParseTuple(args, "U|O:zipimporter.find_module", &fullname, &path))
        return NULL;

    switch (find_loader(self, fullname, &namespace_portion)) {
    case FL_ERROR:
        return NULL;
    case FL_NOT_FOUND:        /* Not found, return (None, []) */
        result = Py_BuildValue("O[]", Py_None);
        break;
    case FL_MODULE_FOUND:     /* Return (self, []) */
        result = Py_BuildValue("O[]", self);
        break;
    case FL_NS_FOUND:         /* Return (None, [namespace_portion]) */
        result = Py_BuildValue("O[O]", Py_None, namespace_portion);
        Py_DECREF(namespace_portion);
        return result;
    }
    return result;
}
示例#4
0
文件: zipimport.c 项目: 1st1/cpython
static PyObject *
zipimport_zipimporter_find_module_impl(ZipImporter *self, PyObject *fullname,
                                       PyObject *path)
/*[clinic end generated code: output=506087f609466dc7 input=e3528520e075063f]*/
{
    PyObject *namespace_portion = NULL;
    PyObject *result = NULL;

    switch (find_loader(self, fullname, &namespace_portion)) {
    case FL_ERROR:
        return NULL;
    case FL_NS_FOUND:
        /* A namespace portion is not allowed via find_module, so return None. */
        Py_DECREF(namespace_portion);
        /* FALL THROUGH */
    case FL_NOT_FOUND:
        result = Py_None;
        break;
    case FL_MODULE_FOUND:
        result = (PyObject *)self;
        break;
    default:
        PyErr_BadInternalCall();
        return NULL;
    }
    Py_INCREF(result);
    return result;
}
示例#5
0
文件: zipimport.c 项目: 1st1/cpython
static PyObject *
zipimport_zipimporter_find_loader_impl(ZipImporter *self, PyObject *fullname,
                                       PyObject *path)
/*[clinic end generated code: output=601599a43bc0f49a input=dc73f275b0d5be23]*/
{
    PyObject *result = NULL;
    PyObject *namespace_portion = NULL;

    switch (find_loader(self, fullname, &namespace_portion)) {
    case FL_ERROR:
        return NULL;
    case FL_NOT_FOUND:        /* Not found, return (None, []) */
        result = Py_BuildValue("O[]", Py_None);
        break;
    case FL_MODULE_FOUND:     /* Return (self, []) */
        result = Py_BuildValue("O[]", self);
        break;
    case FL_NS_FOUND:         /* Return (None, [namespace_portion]) */
        result = Py_BuildValue("O[O]", Py_None, namespace_portion);
        Py_DECREF(namespace_portion);
        return result;
    default:
        PyErr_BadInternalCall();
        return NULL;
    }
    return result;
}
示例#6
0
文件: simage.c 项目: Alexpux/simage
unsigned char *
simage_read_image(const char *filename,
                  int *width, int *height,
                  int *numComponents)
{
  loader_data *loader;

  simage_error_msg[0] = 0; /* clear error msg */
  add_internal_loaders();

  loader = find_loader(filename);

  if (loader) {
    unsigned char * data =
      loader->funcs.load_func(filename, width,
                              height, numComponents);
    if (data == NULL) {
      (void) loader->funcs.error_func(simage_error_msg, SIMAGE_ERROR_BUFSIZE);
    }
    return data;
  }
  else {
    strcpy(simage_error_msg, "Unsupported image format.");
    return NULL;
  }
}
示例#7
0
static void load_packages(const char *dir, const char *unionmp) {
	// go over the packages in dir in alphapetical order and merge them into unionmp
	// e.g. files in 00-aaa.zip will be shadowed by files in 99-zzz.zip

	size_t numpaks = 0;
	char **paklist = vfs_dir_list_sorted(dir, &numpaks, vfs_dir_list_order_ascending, NULL);

	if(!paklist) {
		log_fatal("VFS error: %s", vfs_get_error());
	}

	for(size_t i = 0; i < numpaks; ++i) {
		const char *entry = paklist[i];
		struct pkg_loader_t *loader = find_loader(entry);

		if(loader == NULL) {
			continue;
		}

		log_info("Adding package: %s", entry);
		assert(loader->mount != NULL);

		char *tmp = strfmt("%s/%s", dir, entry);

		if(!loader->mount(unionmp, tmp)) {
			log_error("VFS error: %s", vfs_get_error());
		}

		free(tmp);
	}

	vfs_dir_list_free(paklist, numpaks);
}
示例#8
0
/* Try to load a savefile */
static bool try_load(ang_file *f, const struct blockinfo *loaders) {
	struct blockheader b;
	errr err;

	if (!check_header(f)) {
		note("Savefile is corrupted -- incorrect file header.");
		return FALSE;
	}

	/* Get the next block header */
	while ((err = next_blockheader(f, &b)) == 0) {
		loader_t loader = find_loader(&b, loaders);
		if (!loader) {
			note("Savefile block can't be read.");
			note("Maybe try and load the savefile in an earlier version of Angband.");
			return FALSE;
		}

		if (!load_block(f, &b, loader)) {
			note(format("Savefile corrupted - Couldn't load block %s", b.name));
			return FALSE;
		}
	}

	if (err == -1) {
		note("Savefile is corrupted -- block header mangled.");
		return FALSE;
	}

	/* XXX Reset cause of death */
	if (p_ptr->chp >= 0)
		my_strcpy(p_ptr->died_from, "(alive and well)", sizeof(p_ptr->died_from));

	return TRUE;
}
示例#9
0
文件: simage.c 项目: Alexpux/simage
s_image *
s_image_open(const char * filename, int oktoreadall)
{
  loader_data * loader;

  simage_error_msg[0] = 0; /* clear error msg */
  add_internal_loaders();

  loader = find_loader(filename);

  /* check if plugin supports open_funcs */
  if (loader && loader->openfuncs.open_func) {
    int w, h, nc;
    void * opendata = loader->openfuncs.open_func(filename, &w, &h, &nc);
    if (opendata) {
      s_image * image = (s_image*) malloc(sizeof(s_image));
      image->width = w;
      image->height = h;
      image->components = nc;
      image->order = SIMAGE_ORDER_RGB;
      image->didalloc = 0;
      image->data = NULL;
      image->opendata = opendata;
      image->oktoreadall = oktoreadall;
      image->openfilename = (char*) malloc(strlen(filename)+1);
      strcpy(image->openfilename, filename);
      memcpy(&image->openfuncs, &loader->openfuncs, sizeof(struct simage_open_funcs));
      return image;
    }
  }

  if (oktoreadall) {
    /* just load everything */
    return s_image_load(filename, NULL);
  }
  return NULL;
}
示例#10
0
文件: simage.c 项目: Alexpux/simage
int
simage_check_supported(const char *filename)
{
  add_internal_loaders();
  return find_loader(filename) != NULL;
}