factored out some wrapping code to avoid name collisions
This commit is contained in:
		
							parent
							
								
									12c9082666
								
							
						
					
					
						commit
						48f62edc39
					
				@ -27,12 +27,34 @@
 | 
			
		||||
#include "ep_init.h"
 | 
			
		||||
#include "ep_types.h"
 | 
			
		||||
 | 
			
		||||
static PyObject *wrap_resource_file_handle(HRESFILE handle)
 | 
			
		||||
{
 | 
			
		||||
  PyObject *rc = NULL, *args, *kwargs;
 | 
			
		||||
  ResFileObject *presfile;
 | 
			
		||||
 | 
			
		||||
  args = PyTuple_New(0);
 | 
			
		||||
  if (args)
 | 
			
		||||
  {
 | 
			
		||||
    kwargs = PyDict_New();
 | 
			
		||||
    if (kwargs)
 | 
			
		||||
    {
 | 
			
		||||
      rc = PyType_GenericNew(&ResFileType, args, kwargs);
 | 
			
		||||
      if (rc)
 | 
			
		||||
      {
 | 
			
		||||
        presfile = (ResFileObject *)rc;
 | 
			
		||||
        presfile->hresfile = handle;
 | 
			
		||||
      }
 | 
			
		||||
      Py_DECREF(kwargs);
 | 
			
		||||
    }
 | 
			
		||||
    Py_DECREF(args);
 | 
			
		||||
  }
 | 
			
		||||
  return rc;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PyObject *resfile_load_classmethod(ResFileType *cls, PyObject *args)
 | 
			
		||||
{
 | 
			
		||||
  const char *filename;
 | 
			
		||||
  PyObject *rc = NULL, *args, *kwargs;
 | 
			
		||||
  ResFileObject *presfile;
 | 
			
		||||
  PyObject *rc = NULL;
 | 
			
		||||
  HRESULT hr;
 | 
			
		||||
  HRESFILE handle;
 | 
			
		||||
 | 
			
		||||
@ -41,23 +63,7 @@ static PyObject *resfile_load_classmethod(ResFileType *cls, PyObject *args)
 | 
			
		||||
  hr = Rsrc_load_file((PCSTR)filename, &handle);
 | 
			
		||||
  if (SUCCEEDED(hr))
 | 
			
		||||
  {
 | 
			
		||||
    args = PyTuple_New(0);
 | 
			
		||||
    if (args)
 | 
			
		||||
    {
 | 
			
		||||
      kwargs = PyDict_New();
 | 
			
		||||
      if (kwargs)
 | 
			
		||||
      {
 | 
			
		||||
        rc = PyType_GenericNew(&ResFileType, args, kwargs);
 | 
			
		||||
        if (rc)
 | 
			
		||||
        {
 | 
			
		||||
          presfile = (ResFileObject *)rc;
 | 
			
		||||
          presfile->hresfile = handle;
 | 
			
		||||
        }
 | 
			
		||||
        Py_DECREF(kwargs);
 | 
			
		||||
      }
 | 
			
		||||
      Py_DECREF(args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    rc = wrap_resource_file_handle(handle);
 | 
			
		||||
    if (!rc)
 | 
			
		||||
    {
 | 
			
		||||
      Rsrc_close_file(handle);
 | 
			
		||||
@ -77,11 +83,34 @@ static PyObject *resfile_close(ResFileObject *self, PyObject *args)
 | 
			
		||||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PyObject *wrap_resource_handle(HRSRC hrsrc)
 | 
			
		||||
{
 | 
			
		||||
  PyObject *rc = NULL, *args, *kwargs;
 | 
			
		||||
  ResourceObject *pres;
 | 
			
		||||
 | 
			
		||||
  args = PyTuple_New(0);
 | 
			
		||||
  if (args)
 | 
			
		||||
  {
 | 
			
		||||
    kwargs = PyDict_New();
 | 
			
		||||
    if (kwargs)
 | 
			
		||||
    {
 | 
			
		||||
      rc = PyType_GenericNew(&ResourceType, args, kwargs);
 | 
			
		||||
      if (rc)
 | 
			
		||||
      {
 | 
			
		||||
        pres = (ResourceObject *)rc;
 | 
			
		||||
        pres->hrsrc = hrsrc;
 | 
			
		||||
      }
 | 
			
		||||
      Py_DECREF(kwargs);
 | 
			
		||||
    }
 | 
			
		||||
    Py_DECREF(args);
 | 
			
		||||
  }
 | 
			
		||||
  return rc;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PyObject *resfile_find_resource(ResFileObject *self, PyObject *args)
 | 
			
		||||
{
 | 
			
		||||
  const char *name;
 | 
			
		||||
  PyObject *rc = NULL, *args, *kwargs;
 | 
			
		||||
  ResourceObject *pres;
 | 
			
		||||
  PyObject *rc = NULL;
 | 
			
		||||
  HRSRC hrsrc;
 | 
			
		||||
  HRESULT hr;
 | 
			
		||||
 | 
			
		||||
@ -90,23 +119,7 @@ static PyObject *resfile_find_resource(ResFileObject *self, PyObject *args)
 | 
			
		||||
  hr = Rsrc_find_resource(self->hresfile, (PCSTR)name, NULL, &hrsrc);
 | 
			
		||||
  if (SUCCEEDED(hr))
 | 
			
		||||
  {
 | 
			
		||||
    args = PyTuple_New(0);
 | 
			
		||||
    if (args)
 | 
			
		||||
    {
 | 
			
		||||
      kwargs = PyDict_New();
 | 
			
		||||
      if (kwargs)
 | 
			
		||||
      {
 | 
			
		||||
        rc = PyType_GenericNew(&ResourceType, args, kwargs);
 | 
			
		||||
        if (rc)
 | 
			
		||||
        {
 | 
			
		||||
          pres = (ResourceObject *)rc;
 | 
			
		||||
          pres->hrsrc = hrsrc;
 | 
			
		||||
        }
 | 
			
		||||
        Py_DECREF(kwargs);
 | 
			
		||||
      }
 | 
			
		||||
      Py_DECREF(args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    rc = wrap_resource_handle(hrsrc);
 | 
			
		||||
    if (!rc)
 | 
			
		||||
    {
 | 
			
		||||
      Rsrc_free_resource(hrsrc);
 | 
			
		||||
@ -114,7 +127,7 @@ static PyObject *resfile_find_resource(ResFileObject *self, PyObject *args)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
    PyErr_Format(PyExc_RuntimeError, "unable to load resource file '%s' (%08x)", filename, hr);
 | 
			
		||||
    PyErr_Format(PyExc_RuntimeError, "unable to load resource ''%s' (%08x)", name, hr);
 | 
			
		||||
  return rc;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user