cython-devel

changeset 3659:63c67976adc6

Restore special method docstrings.
author Robert Bradshaw <robertwb@math.washington.edu>
date Sun Aug 15 00:12:36 2010 -0700 (18 months ago)
parents 98a9d5fd678a
children 9c27a5ba0057
files Cython/Compiler/ModuleNode.py Cython/Compiler/Naming.py Cython/Compiler/Nodes.py
line diff
1.1 --- a/Cython/Compiler/ModuleNode.py Sat Aug 14 16:49:38 2010 -0300 1.2 +++ b/Cython/Compiler/ModuleNode.py Sun Aug 15 00:12:36 2010 -0700 1.3 @@ -2041,6 +2041,29 @@ 1.4 "if (PyType_Ready(&%s) < 0) %s" % ( 1.5 typeobj_cname, 1.6 code.error_goto(entry.pos))) 1.7 + # Fix special method docstrings. This is a bit of a hack, but 1.8 + # unless we let PyType_Ready create the slot wrappers we have 1.9 + # a significant performance hit. (See trac #561.) 1.10 + for func in entry.type.scope.pyfunc_entries: 1.11 + if func.is_special and func.doc: 1.12 + code.putln("{"); 1.13 + code.putln( 1.14 + 'PyObject *wrapper = PyObject_GetAttrString((PyObject *)&%s, "%s"); %s' % ( 1.15 + typeobj_cname, 1.16 + func.name, 1.17 + code.error_goto_if_null('wrapper', entry.pos))); 1.18 + code.putln( 1.19 + "if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {"); 1.20 + code.putln( 1.21 + "%s = *((PyWrapperDescrObject *)wrapper)->d_base;" % ( 1.22 + func.wrapperbase_cname)); 1.23 + code.putln( 1.24 + "%s.doc = %s;" % (func.wrapperbase_cname, func.doc_cname)); 1.25 + code.putln( 1.26 + "((PyWrapperDescrObject *)wrapper)->d_base = &%s;" % ( 1.27 + func.wrapperbase_cname)); 1.28 + code.putln("}"); 1.29 + code.putln("}"); 1.30 if type.vtable_cname: 1.31 code.putln( 1.32 "if (__Pyx_SetVtable(%s.tp_dict, %s) < 0) %s" % (
2.1 --- a/Cython/Compiler/Naming.py Sat Aug 14 16:49:38 2010 -0300 2.2 +++ b/Cython/Compiler/Naming.py Sun Aug 15 00:12:36 2010 -0700 2.3 @@ -35,6 +35,7 @@ 2.4 type_prefix = pyrex_prefix + "t_" 2.5 typeobj_prefix = pyrex_prefix + "type_" 2.6 var_prefix = pyrex_prefix + "v_" 2.7 +wrapperbase_prefix= pyrex_prefix + "wrapperbase_" 2.8 bufstruct_prefix = pyrex_prefix + "bstruct_" 2.9 bufstride_prefix = pyrex_prefix + "bstride_" 2.10 bufshape_prefix = pyrex_prefix + "bshape_"
3.1 --- a/Cython/Compiler/Nodes.py Sat Aug 14 16:49:38 2010 -0300 3.2 +++ b/Cython/Compiler/Nodes.py Sun Aug 15 00:12:36 2010 -0700 3.3 @@ -2110,6 +2110,8 @@ 3.4 entry.doc = embed_position(self.pos, self.doc) 3.5 entry.doc_cname = \ 3.6 Naming.funcdoc_prefix + prefix + name 3.7 + if entry.is_special: 3.8 + entry.wrapperbase_cname = Naming.wrapperbase_prefix + prefix + name 3.9 else: 3.10 entry.doc = None 3.11 3.12 @@ -2224,10 +2226,7 @@ 3.13 if proto_only: 3.14 return 3.15 if (Options.docstrings and self.entry.doc and 3.16 - (not self.entry.is_special or 3.17 - self.entry.signature.method_flags()) and 3.18 - not self.entry.scope.is_property_scope 3.19 - ): 3.20 + not self.entry.scope.is_property_scope): 3.21 docstr = self.entry.doc 3.22 if docstr.is_unicode: 3.23 docstr = docstr.utf8encode() 3.24 @@ -2235,6 +2234,9 @@ 3.25 'static char %s[] = "%s";' % ( 3.26 self.entry.doc_cname, 3.27 split_string_literal(escape_byte_string(docstr)))) 3.28 + if self.entry.is_special: 3.29 + code.putln( 3.30 + "struct wrapperbase %s;" % self.entry.wrapperbase_cname) 3.31 if with_pymethdef: 3.32 code.put( 3.33 "static PyMethodDef %s = " %