summaryrefslogtreecommitdiff
path: root/Objects/moduleobject.c
AgeCommit message (Collapse)AuthorLines
2009-10-15only clear a module's __dict__ if the module is the only one with a ↵Benjamin Peterson-1/+4
reference to it #7140
2008-06-09This reverts r63675 based on the discussion in this thread:Gregory P. Smith-11/+11
http://mail.python.org/pipermail/python-dev/2008-June/079988.html Python 2.6 should stick with PyString_* in its codebase. The PyBytes_* names in the spirit of 3.0 are available via a #define only. See the email thread.
2008-05-26Renamed PyString to PyBytesChristian Heimes-11/+11
2007-12-19#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and ↵Christian Heimes-1/+1
Py_REFCNT. Macros for b/w compatibility are available.
2007-12-03Implement PEP 366Nick Coghlan-0/+2
2007-07-21PEP 3123: Provide forward compatibility with Python 3.0, while keepingMartin v. Löwis-3/+2
backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and PyVarObject_HEAD_INIT.
2006-04-15Use Py_VISIT in all tp_traverse methods, instead of traversing manually orThomas Wouters-2/+1
using a custom, nearly-identical macro. This probably changes how some of these functions are compiled, which may result in fractionally slower (or faster) execution. Considering the nature of traversal, visiting much of the address space in unpredictable patterns, I'd argue the code readability and maintainability is well worth it ;P
2006-02-27Revert backwards-incompatible const changes.Martin v. Löwis-1/+1
2006-02-15Merge ssize_t branch.Martin v. Löwis-1/+1
2005-12-10Add const to several API functions that take char *.Jeremy Hylton-4/+4
In C++, it's an error to pass a string literal to a char* function without a const_cast(). Rather than require every C++ extension module to put a cast around string literals, fix the API to state the const-ness. I focused on parts of the API where people usually pass literals: PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type slots, etc. Predictably, there were a large set of functions that needed to be fixed as a result of these changes. The most pervasive change was to make the keyword args list passed to PyArg_ParseTupleAndKewords() to be a const char *kwlist[]. One cast was required as a result of the changes: A type object mallocs the memory for its tp_doc slot and later frees it. PyTypeObject says that tp_doc is const char *; but if the type was created by type_new(), we know it is safe to cast to char *.
2004-09-14Make the word "module" appear in the error string for calling theMichael W. Hudson-1/+1
module type with silly arguments. (The exact name can be quibbled over, if you care). This was partially inspired by bug #1014215 and so on, but is also just a good idea.
2003-07-16Remove code that tried to warn about shadowing builtin names after aNeil Schemenauer-66/+1
module had been compiled. It gives too many spurious warnings.
2003-06-09Warn about creating global variables by __setattr__ that shadow builtinNeil Schemenauer-1/+66
names. Unfortunately, this is not bulletproof since the module dictionary can be modified directly.
2002-06-13Patch #568124: Add doc string macros.Martin v. Löwis-2/+2
2002-06-04Add a docstring to the module type.Guido van Rossum-1/+7
2002-06-04Surprising fix for SF bug 563060: module can be used as base class.Guido van Rossum-3/+16
Change the module constructor (module_init) to have the signature __init__(name:str, doc=None); this prevents the call from type_new() to succeed. While we're at it, prevent repeated calling of module_init for the same module from leaking the dict, changing the semantics so that __dict__ is only initialized if NULL. Also adding a unittest, test_module.py. This is an incompatibility with 2.2, if anybody was instantiating the module class before, their argument list was probably empty; so this can't be backported to 2.2.x.
2002-04-12PyObject_GC_Del can now be used as a function designator.Neil Schemenauer-1/+1
2002-03-12Fix for SF bug #529050 - ModuleType.__new__ crash.Guido van Rossum-7/+19
There were several places that assumed the md_dict field was always set, but it needn't be. Fixed these to be more careful. I changed PyModule_GetDict() to initialize md_dict to a new dictionary if it's NULL. Bugfix candidate.
2001-10-21Add missing "static" declarations (found by "make smelly").Neil Schemenauer-1/+1
2001-10-05Enable GC for new-style instances. This touches lots of files, sinceGuido van Rossum-1/+2
many types were subclassable but had a xxx_dealloc function that called PyObject_DEL(self) directly instead of deferring to self->ob_type->tp_free(self). It is permissible to set tp_free in the type object directly to _PyObject_Del, for non-GC types, or to _PyObject_GC_Del, for GC types. Still, PyObject_DEL was a tad faster, so I'm fearing that our pystone rating is going down again. I'm not sure if doing something like void xxx_dealloc(PyObject *self) { if (PyXxxCheckExact(self)) PyObject_DEL(self); else self->ob_type->tp_free(self); } is any faster than always calling the else branch, so I haven't attempted that -- however those types whose own dealloc is fancier (int, float, unicode) do use this pattern.
2001-09-20Add optional docstrings to member descriptors. For backwardsGuido van Rossum-1/+1
compatibility, this required all places where an array of "struct memberlist" structures was declared that is referenced from a type's tp_members slot to change the type of the structure to PyMemberDef; "struct memberlist" is now only used by old code that still calls PyMember_Get/Set. The code in PyObject_GenericGetAttr/SetAttr now calls the new APIs PyMember_GetOne/SetOne, which take a PyMemberDef argument. As examples, I added actual docstrings to the attributes of a few types: file, complex, instance method, super, and xxsubtype.spamlist. Also converted the symtable to new style getattr.
2001-08-29Use new GC API.Neil Schemenauer-6/+6
2001-08-24repr's converted to using PyString_FromFormat() instead of sprintf'ingBarry Warsaw-17/+2
into a hardcoded char* buffer. Closes patch #454743.
2001-08-16module_repr(): Instead of fixing the maximum buf size to 400,Barry Warsaw-6/+18
calculate it on the fly. This way even modules with long package names get an accurate repr instead of a truncated one. The extra malloc/free cost shouldn't be a problem in a repr function. Closes SF bug #437984
2001-08-02Merge of descr-branch back into trunk.Tim Peters-61/+40
2001-05-12Repair "module has no attribute xxx" error msg; bug introduced whenTim Peters-1/+1
switching from tp_getattr to tp_getattro.
2001-05-11Variant of patch #423262: Change module attribute get & setTim Peters-34/+35
Allow module getattr and setattr to exploit string interning, via the previously null module object tp_getattro and tp_setattro slots. Yields a very nice speedup for things like random.random and os.path etc.
2001-01-02Add garbage collection for module objects. Closes patch #102939 andNeil Schemenauer-2/+27
fixes bug #126345.
2000-10-24Ka-Ping Yee <ping@lfw.org>:Fred Drake-5/+22
Changes to error messages to increase consistency & clarity. This (mostly) closes SourceForge patch #101839.
2000-09-01REMOVED all CWI, CNRI and BeOpen copyright markings.Guido van Rossum-9/+0
This should match the situation in the 1.6b1 tree.
2000-07-09ANSI-fication of the sources.Fred Drake-21/+9
2000-06-30Change copyright notice - 2nd try.Guido van Rossum-6/+0
2000-06-30Change copyright notice.Guido van Rossum-21/+6
2000-05-03Vladimir Marangozov's long-awaited malloc restructuring.Guido van Rossum-1/+1
For more comments, read the patches@python.org archives. For documentation read the comments in mymalloc.h and objimpl.h. (This is not exactly what Vladimir posted to the patches list; I've made a few changes, and Vladimir sent me a fix in private email for a problem that only occurs in debug mode. I'm also holding back on his change to main.c, which seems unnecessary to me.)
1999-02-15Patch by Chris Petrilli to display the origin of a module in itsGuido van Rossum-3/+30
repr() -- either "(builtin)" or "from '<filename>'".
1998-10-12Replace fprintf(stderr, ...) with PySys_WriteStderr(...).Guido van Rossum-2/+2
1998-02-19Add internal routine _PyModule_Clear(), which does approximately whatGuido van Rossum-1/+50
clear_carefully() used to do in import.c. Differences: leave only __builtins__ alone in the 2nd pass; and don't clear the dictionary (on the theory that as long as there are references left to the dictionary, those might be destructors that might expect __builtins__ to be alive when they run; and __builtins__ can't normally be part of a cycle).
1997-05-09removed last #ifdef SUPPORT_OBSOLETE_ACCESS bits.Guido van Rossum-16/+2
1997-05-02Quickly renamed the last directory.Guido van Rossum-63/+64
1996-10-25New permission notice, includes CNRI.Guido van Rossum-12/+19
1996-08-12Disable support for access statementGuido van Rossum-0/+6
1995-01-26apply dictclear to dict of deleted modulesGuido van Rossum-1/+3
1995-01-07initialize __doc__ to NoneGuido van Rossum-0/+2
1995-01-04Added 1995 to copyright message.Guido van Rossum-2/+2
floatobject.c: fix hash(). methodobject.c: support METH_FREENAME flag bit.
1994-08-30Merge back to main trunkGuido van Rossum-5/+5
1993-11-17* import.c (get_module): total rewrite, to ensure proper search order: forGuido van Rossum-21/+30
each dir in sys.path, try each possible extension. (Note: C extensions are loaded before Python modules in the same directory, to allow having a C version used when dynamic loading is supported and a Python version as a back-up.) * import.c (reload_module): test for error from getmodulename() * moduleobject.c: implement module name as dict entry '__name__' instead of special-casing it in module_getattr(); this way a module (or function!) can access its own module name, and programs that know what they are doing can rename modules. * stdwinmodule.c (initstdwin): strip ".py" suffix of argv[0].
1993-05-25* classobject.c: in instance_getattr, don't make a method out of aGuido van Rossum-2/+2
function found as instance data. * socketmodule.c: added 'flags' argument sendto/recvfrom, rewrite argument parsing in send/recv. * More changes related to access (terminology change: owner instead of class; allow any object as owner; local/global variables are owned by their dictionary, only class/instance data is owned by the class; "from...import *" now only imports objects with public access; etc.)
1993-05-20Access checks now work, at least for instance data (not for methodsGuido van Rossum-2/+3
yet). The class is now passed to eval_code and stored in the current frame. It is also stored in instance method objects. An "unbound" instance method is now returned when a function is retrieved through "classname.funcname", which when called passes the class to eval_code.
1993-05-19Several changes in one:Guido van Rossum-5/+16
(1) dictionaries/mappings now have attributes values() and items() as well as keys(); at the C level, use the new function mappinggetnext() to iterate over a dictionary. (2) "class C(): ..." is now illegal; you must write "class C: ...". (3) Class objects now know their own name (finally!); and minor improvements to the way how classes, functions and methods are represented as strings. (4) Added an "access" statement and semantics. (This is still experimental -- as long as you don't use the keyword 'access' nothing should be changed.)
1993-03-29* Changed all copyright messages to include 1993.Guido van Rossum-2/+2
* Stubs for faster implementation of local variables (not yet finished) * Added function name to code object. Print it for code and function objects. THIS MAKES THE .PYC FILE FORMAT INCOMPATIBLE (the version number has changed accordingly) * Print address of self for built-in methods * New internal functions getattro and setattro (getattr/setattr with string object arg) * Replaced "dictobject" with more powerful "mappingobject" * New per-type functio tp_hash to implement arbitrary object hashing, and hashobject() to interface to it * Added built-in functions hash(v) and hasattr(v, 'name') * classobject: made some functions static that accidentally weren't; added __hash__ special instance method to implement hash() * Added proper comparison for built-in methods and functions