[pypy-svn] r73005 - in pypy/branch/cpython-extension/pypy/module/cpyext: . include

fijal at codespeak.net fijal at codespeak.net
Sun Mar 28 00:53:30 CET 2010


Author: fijal
Date: Sun Mar 28 00:53:29 2010
New Revision: 73005

Added:
   pypy/branch/cpython-extension/pypy/module/cpyext/include/pyerrors.c
Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/api.py
   pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h
Log:
Copy a bit of stuff from CPython and include it in compilation


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py	Sun Mar 28 00:53:29 2010
@@ -512,7 +512,9 @@
     eci = ExternalCompilationInfo(
         include_dirs=include_dirs,
         separate_module_sources=[code],
-        separate_module_files=[include_dir / "varargwrapper.c"],
+        separate_module_files=[include_dir / "varargwrapper.c",
+                               include_dir / "pyerrors.c",
+                               include_dir / "modsupport.c"],
         export_symbols=['pypyAPI'] + export_symbols,
         )
     eci = eci.convert_sources_to_files()

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h	Sun Mar 28 00:53:29 2010
@@ -386,6 +386,7 @@
 PyAPI_DATA(PyTypeObject *) PyType_Type; /* built-in 'type' */
 PyAPI_DATA(PyTypeObject *) PyBaseObject_Type;
 PyAPI_DATA(PyObject *) PyExc_TypeError;
+PyAPI_DATA(PyObject *) PyExc_SystemError;
 
 /* objimpl.h ----------------------------------------------*/
 

Added: pypy/branch/cpython-extension/pypy/module/cpyext/include/pyerrors.c
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/pyerrors.c	Sun Mar 28 00:53:29 2010
@@ -0,0 +1,54 @@
+
+#include <pypy_rename.h>
+#include <Python.h>
+#include <string.h>
+
+PyObject *
+PyErr_NewException(char *name, PyObject *base, PyObject *dict)
+{
+	char *dot;
+	PyObject *modulename = NULL;
+	PyObject *classname = NULL;
+	PyObject *mydict = NULL;
+	PyObject *bases = NULL;
+	PyObject *result = NULL;
+	dot = strrchr(name, '.');
+	if (dot == NULL) {
+		PyErr_SetString(PyExc_SystemError,
+			"PyErr_NewException: name must be module.class");
+		return NULL;
+	}
+	if (base == NULL)
+		base = PyExc_Exception;
+	if (dict == NULL) {
+		dict = mydict = PyDict_New();
+		if (dict == NULL)
+			goto failure;
+	}
+	if (PyDict_GetItemString(dict, "__module__") == NULL) {
+		modulename = PyString_FromStringAndSize(name,
+						     (Py_ssize_t)(dot-name));
+		if (modulename == NULL)
+			goto failure;
+		if (PyDict_SetItemString(dict, "__module__", modulename) != 0)
+			goto failure;
+	}
+	if (PyTuple_Check(base)) {
+		bases = base;
+		/* INCREF as we create a new ref in the else branch */
+		Py_INCREF(bases);
+	} else {
+		bases = PyTuple_Pack(1, base);
+		if (bases == NULL)
+			goto failure;
+	}
+	/* Create a real new-style class. */
+	result = PyObject_CallFunction((PyObject *)&PyType_Type, "sOO",
+				       dot+1, bases, dict);
+  failure:
+	Py_XDECREF(bases);
+	Py_XDECREF(mydict);
+	Py_XDECREF(classname);
+	Py_XDECREF(modulename);
+	return result;
+}



More information about the Pypy-commit mailing list