Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9ea2f2cf
Commit
9ea2f2cf
authored
Oct 26, 1990
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added reload() functionality.
parent
b42854b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
21 deletions
+66
-21
Python/import.c
Python/import.c
+66
-21
No files found.
Python/import.c
View file @
9ea2f2cf
...
...
@@ -65,28 +65,35 @@ new_module(name)
return
m
;
}
void
static
void
use_module
(
ctx
,
d
)
context
*
ctx
;
object
*
d
;
{
INCREF
(
d
);
DECREF
(
ctx
->
ctx_locals
);
ctx
->
ctx_locals
=
d
;
INCREF
(
d
);
DECREF
(
ctx
->
ctx_globals
);
ctx
->
ctx_globals
=
d
;
}
static
void
define_module
(
ctx
,
name
)
context
*
ctx
;
char
*
name
;
{
object
*
m
,
*
d
;
object
*
m
;
m
=
new_module
(
name
);
if
(
m
==
NULL
)
{
puterrno
(
ctx
);
return
;
}
d
=
getmoduledict
(
m
);
INCREF
(
d
);
DECREF
(
ctx
->
ctx_locals
);
ctx
->
ctx_locals
=
d
;
INCREF
(
d
);
DECREF
(
ctx
->
ctx_globals
);
ctx
->
ctx_globals
=
d
;
use_module
(
ctx
,
getmoduledict
(
m
));
DECREF
(
m
);
}
object
*
static
object
*
parsepath
(
path
,
delim
)
char
*
path
;
int
delim
;
...
...
@@ -179,7 +186,7 @@ load_module(ctx, name)
object
*
m
;
char
**
p
;
FILE
*
fp
;
node
*
n
,
*
mh
;
node
*
n
;
int
err
;
object
*
mtab
;
object
*
save_locals
,
*
save_globals
;
...
...
@@ -190,20 +197,10 @@ load_module(ctx, name)
return
NULL
;
}
fp
=
open_module
(
name
,
".py"
);
if
(
fp
==
NULL
)
{
/* XXX Compatibility hack */
fprintf
(
stderr
,
"Can't find '%s.py' in sys.path, trying '%s'
\n
"
,
name
,
name
);
fp
=
open_module
(
name
,
""
);
}
if
(
fp
==
NULL
)
{
name_error
(
ctx
,
name
);
return
NULL
;
}
#ifdef DEBUG
fprintf
(
stderr
,
"Reading module %s from file '%s'
\n
"
,
name
,
namebuf
);
#endif
err
=
parseinput
(
fp
,
file_input
,
&
n
);
fclose
(
fp
);
if
(
err
!=
E_DONE
)
{
...
...
@@ -250,3 +247,51 @@ import_module(ctx, name)
}
return
m
;
}
object
*
reload_module
(
ctx
,
m
)
context
*
ctx
;
object
*
m
;
{
char
*
name
;
FILE
*
fp
;
node
*
n
;
int
err
;
object
*
d
;
object
*
save_locals
,
*
save_globals
;
if
(
m
==
NULL
||
!
is_moduleobject
(
m
))
{
type_error
(
ctx
,
"reload() argument must be module"
);
return
NULL
;
}
/* XXX Ought to check for builtin module */
name
=
getmodulename
(
m
);
fp
=
open_module
(
name
,
".py"
);
if
(
fp
==
NULL
)
{
error
(
ctx
,
"reload() cannot find module source file"
);
return
NULL
;
}
err
=
parseinput
(
fp
,
file_input
,
&
n
);
fclose
(
fp
);
if
(
err
!=
E_DONE
)
{
input_error
(
ctx
,
err
);
return
NULL
;
}
d
=
newdictobject
();
if
(
d
==
NULL
)
return
NULL
;
setmoduledict
(
m
,
d
);
save_locals
=
ctx
->
ctx_locals
;
INCREF
(
save_locals
);
save_globals
=
ctx
->
ctx_globals
;
INCREF
(
save_globals
);
use_module
(
ctx
,
d
);
exec_node
(
ctx
,
n
);
DECREF
(
ctx
->
ctx_locals
);
ctx
->
ctx_locals
=
save_locals
;
DECREF
(
ctx
->
ctx_globals
);
ctx
->
ctx_globals
=
save_globals
;
if
(
ctx
->
ctx_exception
)
return
NULL
;
INCREF
(
None
);
return
None
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment