Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
d45bc48f
Commit
d45bc48f
authored
Dec 12, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the pwd module, though it crashes on initialization
parent
d5ba641b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
1 deletion
+121
-1
Makefile
Makefile
+2
-1
src/runtime/builtin_modules/posix.cpp
src/runtime/builtin_modules/posix.cpp
+114
-0
src/runtime/types.cpp
src/runtime/types.cpp
+2
-0
test/tests/pwd_test.py
test/tests/pwd_test.py
+3
-0
No files found.
Makefile
View file @
d45bc48f
...
...
@@ -214,6 +214,7 @@ CLANGFLAGS_RELEASE := $(CXXFLAGS_RELEASE) $(CLANG_EXTRA_FLAGS)
EXT_CFLAGS
:=
$(COMMON_CFLAGS)
-fPIC
-Wimplicit
-O2
-I
../include
EXT_CFLAGS
+=
-Wno-missing-field-initializers
EXT_CFLAGS
+=
-Wno-tautological-compare
-Wno-type-limits
ifneq
($(USE_CLANG),0)
EXT_CFLAGS
+=
$(CLANG_EXTRA_FLAGS)
endif
...
...
@@ -276,7 +277,7 @@ SRCS := $(MAIN_SRCS) $(STDLIB_SRCS)
STDLIB_OBJS
:=
stdlib.bc.o stdlib.stripped.bc.o
STDLIB_RELEASE_OBJS
:=
stdlib.release.bc.o
STDMODULE_SRCS
:=
errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c
$(EXTRA_STDMODULE_SRCS)
STDMODULE_SRCS
:=
errnomodule.c shamodule.c sha256module.c sha512module.c _math.c mathmodule.c md5.c md5module.c _randommodule.c _sre.c operator.c binascii.c
pwdmodule.c
$(EXTRA_STDMODULE_SRCS)
STDOBJECT_SRCS
:=
structseq.c
$(EXTRA_STDOBJECT_SRCS)
FROM_CPYTHON_SRCS
:=
$(
addprefix
lib_python/2.7_Modules/,
$(STDMODULE_SRCS)
)
$(
addprefix
lib_python/2.7_Objects/,
$(STDOBJECT_SRCS)
)
$(
wildcard
src/capi/
*
.c
)
...
...
src/runtime/builtin_modules/posix.cpp
View file @
d45bc48f
...
...
@@ -68,3 +68,117 @@ void setupPosix() {
posix_module
->
giveAttr
(
"error"
,
OSError
);
}
}
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
#else
#pragma GCC diagnostic ignored "-Wtype-limits"
#endif
// Copied from CPython/Modules/posixmodule.c:
extern
"C"
{
PyObject
*
_PyInt_FromUid
(
uid_t
uid
)
{
if
(
uid
<=
LONG_MAX
)
return
PyInt_FromLong
(
uid
);
return
PyLong_FromUnsignedLong
(
uid
);
}
PyObject
*
_PyInt_FromGid
(
gid_t
gid
)
{
if
(
gid
<=
LONG_MAX
)
return
PyInt_FromLong
(
gid
);
return
PyLong_FromUnsignedLong
(
gid
);
}
int
_Py_Uid_Converter
(
PyObject
*
obj
,
void
*
p
)
{
int
overflow
;
long
result
;
if
(
PyFloat_Check
(
obj
))
{
PyErr_SetString
(
PyExc_TypeError
,
"integer argument expected, got float"
);
return
0
;
}
result
=
PyLong_AsLongAndOverflow
(
obj
,
&
overflow
);
if
(
overflow
<
0
)
goto
OverflowDown
;
if
(
!
overflow
&&
result
==
-
1
)
{
/* error or -1 */
if
(
PyErr_Occurred
())
return
0
;
*
(
uid_t
*
)
p
=
(
uid_t
)
-
1
;
}
else
{
/* unsigned uid_t */
unsigned
long
uresult
;
if
(
overflow
>
0
)
{
uresult
=
PyLong_AsUnsignedLong
(
obj
);
if
(
PyErr_Occurred
())
{
if
(
PyErr_ExceptionMatches
(
PyExc_OverflowError
))
goto
OverflowUp
;
return
0
;
}
}
else
{
if
(
result
<
0
)
goto
OverflowDown
;
uresult
=
result
;
}
if
(
sizeof
(
uid_t
)
<
sizeof
(
long
)
&&
(
unsigned
long
)(
uid_t
)
uresult
!=
uresult
)
goto
OverflowUp
;
*
(
uid_t
*
)
p
=
(
uid_t
)
uresult
;
}
return
1
;
OverflowDown:
PyErr_SetString
(
PyExc_OverflowError
,
"user id is less than minimum"
);
return
0
;
OverflowUp:
PyErr_SetString
(
PyExc_OverflowError
,
"user id is greater than maximum"
);
return
0
;
}
int
_Py_Gid_Converter
(
PyObject
*
obj
,
void
*
p
)
{
int
overflow
;
long
result
;
if
(
PyFloat_Check
(
obj
))
{
PyErr_SetString
(
PyExc_TypeError
,
"integer argument expected, got float"
);
return
0
;
}
result
=
PyLong_AsLongAndOverflow
(
obj
,
&
overflow
);
if
(
overflow
<
0
)
goto
OverflowDown
;
if
(
!
overflow
&&
result
==
-
1
)
{
/* error or -1 */
if
(
PyErr_Occurred
())
return
0
;
*
(
gid_t
*
)
p
=
(
gid_t
)
-
1
;
}
else
{
/* unsigned gid_t */
unsigned
long
uresult
;
if
(
overflow
>
0
)
{
uresult
=
PyLong_AsUnsignedLong
(
obj
);
if
(
PyErr_Occurred
())
{
if
(
PyErr_ExceptionMatches
(
PyExc_OverflowError
))
goto
OverflowUp
;
return
0
;
}
}
else
{
if
(
result
<
0
)
goto
OverflowDown
;
uresult
=
result
;
}
if
(
sizeof
(
gid_t
)
<
sizeof
(
long
)
&&
(
unsigned
long
)(
gid_t
)
uresult
!=
uresult
)
goto
OverflowUp
;
*
(
gid_t
*
)
p
=
(
gid_t
)
uresult
;
}
return
1
;
OverflowDown:
PyErr_SetString
(
PyExc_OverflowError
,
"group id is less than minimum"
);
return
0
;
OverflowUp:
PyErr_SetString
(
PyExc_OverflowError
,
"group id is greater than maximum"
);
return
0
;
}
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
src/runtime/types.cpp
View file @
d45bc48f
...
...
@@ -43,6 +43,7 @@ extern "C" void init_sre();
extern
"C"
void
initmath
();
extern
"C"
void
initoperator
();
extern
"C"
void
initbinascii
();
extern
"C"
void
initpwd
();
namespace
pyston
{
...
...
@@ -966,6 +967,7 @@ void setupRuntime() {
initmath
();
initoperator
();
initbinascii
();
initpwd
();
setupSysEnd
();
...
...
test/tests/pwd_test.py
0 → 100644
View file @
d45bc48f
import
pwd
import
os
print
pwd
.
getpwuid
(
os
.
getuid
())[
5
]
==
os
.
environ
[
"HOME"
]
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