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
8b43b19e
Commit
8b43b19e
authored
Dec 09, 1996
by
Barry Warsaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed
parent
5817f8f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
90 deletions
+87
-90
Modules/mathmodule.c
Modules/mathmodule.c
+42
-43
Modules/md5module.c
Modules/md5module.c
+45
-47
No files found.
Modules/mathmodule.c
View file @
8b43b19e
...
...
@@ -31,21 +31,19 @@ PERFORMANCE OF THIS SOFTWARE.
/* Math module -- standard C math library functions, pi and e */
#include "
allobjects
.h"
#include "
Python
.h"
#include <errno.h>
#define getdoublearg(v, a) getargs(v, "d", a)
#define get2doublearg(v, a, b) getargs(v, "(dd)", a, b)
#define getdoublearg(v, a) PyArg_Parse(v, "d", a)
#define get2doublearg(v, a, b) PyArg_Parse(v, "(dd)", a, b)
#include "mymath.h"
#ifndef _MSC_VER
#ifndef __STDC__
extern
double
fmod
PROTO
((
double
,
double
));
extern
double
frexp
PROTO
((
double
,
int
*
));
extern
double
ldexp
PROTO
((
double
,
int
));
extern
double
modf
PROTO
((
double
,
double
*
));
extern
double
fmod
P
y_P
ROTO
((
double
,
double
));
extern
double
frexp
P
y_P
ROTO
((
double
,
int
*
));
extern
double
ldexp
P
y_P
ROTO
((
double
,
int
));
extern
double
modf
P
y_P
ROTO
((
double
,
double
*
));
#endif
/* __STDC__ */
#endif
/* _MSC_VER */
...
...
@@ -63,22 +61,23 @@ extern double modf PROTO((double, double *));
#define CHECK(x)
/* Don't know how to check */
#endif
static
o
bject
*
static
PyO
bject
*
math_error
()
{
if
(
errno
==
EDOM
)
err_setstr
(
ValueError
,
"math domain error"
);
PyErr_SetString
(
PyExc_
ValueError
,
"math domain error"
);
else
if
(
errno
==
ERANGE
)
err_setstr
(
OverflowError
,
"math range error"
);
PyErr_SetString
(
PyExc_
OverflowError
,
"math range error"
);
else
err_errno
(
ValueError
);
/* Unexpected math error */
/* Unexpected math error */
PyErr_SetFromErrno
(
PyExc_ValueError
);
return
NULL
;
}
static
o
bject
*
static
PyO
bject
*
math_1
(
args
,
func
)
o
bject
*
args
;
double
(
*
func
)
FPROTO
((
double
));
PyO
bject
*
args
;
double
(
*
func
)
Py_
FPROTO
((
double
));
{
double
x
;
if
(
!
getdoublearg
(
args
,
&
x
))
...
...
@@ -89,13 +88,13 @@ math_1(args, func)
if
(
errno
!=
0
)
return
math_error
();
else
return
newfloatobject
(
x
);
return
PyFloat_FromDouble
(
x
);
}
static
o
bject
*
static
PyO
bject
*
math_2
(
args
,
func
)
o
bject
*
args
;
double
(
*
func
)
FPROTO
((
double
,
double
));
PyO
bject
*
args
;
double
(
*
func
)
Py_
FPROTO
((
double
,
double
));
{
double
x
,
y
;
if
(
!
get2doublearg
(
args
,
&
x
,
&
y
))
...
...
@@ -106,16 +105,16 @@ math_2(args, func)
if
(
errno
!=
0
)
return
math_error
();
else
return
newfloatobject
(
x
);
return
PyFloat_FromDouble
(
x
);
}
#define FUNC1(stubname, func) \
static
object * stubname(self, args) o
bject *self, *args; { \
static
PyObject * stubname(self, args) PyO
bject *self, *args; { \
return math_1(args, func); \
}
#define FUNC2(stubname, func) \
static
object * stubname(self, args) o
bject *self, *args; { \
static
PyObject * stubname(self, args) PyO
bject *self, *args; { \
return math_2(args, func); \
}
...
...
@@ -150,10 +149,10 @@ FUNC1(math_tan, tan)
FUNC1
(
math_tanh
,
tanh
)
static
o
bject
*
static
PyO
bject
*
math_frexp
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
double
x
;
int
i
;
...
...
@@ -164,13 +163,13 @@ math_frexp(self, args)
CHECK
(
x
);
if
(
errno
!=
0
)
return
math_error
();
return
mkv
alue
(
"(di)"
,
x
,
i
);
return
Py_BuildV
alue
(
"(di)"
,
x
,
i
);
}
static
o
bject
*
static
PyO
bject
*
math_ldexp
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
double
x
,
y
;
/* Cheat -- allow float as second argument */
...
...
@@ -182,13 +181,13 @@ math_ldexp(self, args)
if
(
errno
!=
0
)
return
math_error
();
else
return
newfloatobject
(
x
);
return
PyFloat_FromDouble
(
x
);
}
static
o
bject
*
static
PyO
bject
*
math_modf
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
double
x
,
y
;
if
(
!
getdoublearg
(
args
,
&
x
))
...
...
@@ -206,10 +205,10 @@ math_modf(self, args)
CHECK
(
x
);
if
(
errno
!=
0
)
return
math_error
();
return
mkv
alue
(
"(dd)"
,
x
,
y
);
return
Py_BuildV
alue
(
"(dd)"
,
x
,
y
);
}
static
struct
methodlist
math_methods
[]
=
{
static
PyMethodDef
math_methods
[]
=
{
{
"acos"
,
math_acos
},
{
"asin"
,
math_asin
},
{
"atan"
,
math_atan
},
...
...
@@ -239,12 +238,12 @@ static struct methodlist math_methods[] = {
void
initmath
()
{
o
bject
*
m
,
*
d
,
*
v
;
PyO
bject
*
m
,
*
d
,
*
v
;
m
=
initm
odule
(
"math"
,
math_methods
);
d
=
getmoduled
ict
(
m
);
dictinsert
(
d
,
"pi"
,
v
=
newfloatobject
(
atan
(
1
.
0
)
*
4
.
0
));
DECREF
(
v
);
dictinsert
(
d
,
"e"
,
v
=
newfloatobject
(
exp
(
1
.
0
)));
DECREF
(
v
);
m
=
Py_InitM
odule
(
"math"
,
math_methods
);
d
=
PyModule_GetD
ict
(
m
);
PyDict_SetItemString
(
d
,
"pi"
,
v
=
PyFloat_FromDouble
(
atan
(
1
.
0
)
*
4
.
0
));
Py_
DECREF
(
v
);
PyDict_SetItemString
(
d
,
"e"
,
v
=
PyFloat_FromDouble
(
exp
(
1
.
0
)));
Py_
DECREF
(
v
);
}
Modules/md5module.c
View file @
8b43b19e
...
...
@@ -39,17 +39,15 @@ PERFORMANCE OF THIS SOFTWARE.
/* MD5 objects */
#include "allobjects.h"
#include "modsupport.h"
#include "Python.h"
#include "md5.h"
typedef
struct
{
OB
_HEAD
PyObject
_HEAD
MD5_CTX
md5
;
/* the context holder */
}
md5object
;
staticforward
typeo
bject
MD5type
;
staticforward
PyTypeO
bject
MD5type
;
#define is_md5object(v) ((v)->ob_type == &MD5type)
...
...
@@ -58,7 +56,7 @@ newmd5object()
{
md5object
*
md5p
;
md5p
=
NEWOBJ
(
md5object
,
&
MD5type
);
md5p
=
PyObject_NEW
(
md5object
,
&
MD5type
);
if
(
md5p
==
NULL
)
return
NULL
;
...
...
@@ -73,56 +71,56 @@ static void
md5_dealloc
(
md5p
)
md5object
*
md5p
;
{
DEL
(
md5p
);
PyMem_
DEL
(
md5p
);
}
/* MD5 methods-as-attributes */
static
o
bject
*
static
PyO
bject
*
md5_update
(
self
,
args
)
md5object
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
unsigned
char
*
cp
;
int
len
;
if
(
!
getargs
(
args
,
"s#"
,
&
cp
,
&
len
))
if
(
!
PyArg_Parse
(
args
,
"s#"
,
&
cp
,
&
len
))
return
NULL
;
MD5Update
(
&
self
->
md5
,
cp
,
len
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
md5_digest
(
self
,
args
)
md5object
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
MD5_CTX
mdContext
;
unsigned
char
aDigest
[
16
];
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
/* make a temporary copy, and perform the final */
mdContext
=
self
->
md5
;
MD5Final
(
aDigest
,
&
mdContext
);
return
newsizedstringobject
((
char
*
)
aDigest
,
16
);
return
PyString_FromStringAndSize
((
char
*
)
aDigest
,
16
);
}
static
o
bject
*
static
PyO
bject
*
md5_copy
(
self
,
args
)
md5object
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
md5object
*
md5p
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
((
md5p
=
newmd5object
())
==
NULL
)
...
...
@@ -130,53 +128,53 @@ md5_copy(self, args)
md5p
->
md5
=
self
->
md5
;
return
(
o
bject
*
)
md5p
;
return
(
PyO
bject
*
)
md5p
;
}
static
struct
methodlist
md5_methods
[]
=
{
{
"update"
,
(
method
)
md5_update
},
{
"digest"
,
(
method
)
md5_digest
},
{
"copy"
,
(
method
)
md5_copy
},
static
PyMethodDef
md5_methods
[]
=
{
{
"update"
,
(
PyCFunction
)
md5_update
},
{
"digest"
,
(
PyCFunction
)
md5_digest
},
{
"copy"
,
(
PyCFunction
)
md5_copy
},
{
NULL
,
NULL
}
/* sentinel */
};
static
o
bject
*
static
PyO
bject
*
md5_getattr
(
self
,
name
)
md5object
*
self
;
char
*
name
;
{
return
findmethod
(
md5_methods
,
(
o
bject
*
)
self
,
name
);
return
Py_FindMethod
(
md5_methods
,
(
PyO
bject
*
)
self
,
name
);
}
statichere
typeo
bject
MD5type
=
{
OB_HEAD_INIT
(
&
Typet
ype
)
0
,
/*ob_size*/
"md5"
,
/*tp_name*/
sizeof
(
md5object
),
/*tp_size*/
0
,
/*tp_itemsize*/
statichere
PyTypeO
bject
MD5type
=
{
PyObject_HEAD_INIT
(
&
PyType_T
ype
)
0
,
/*ob_size*/
"md5"
,
/*tp_name*/
sizeof
(
md5object
),
/*tp_size*/
0
,
/*tp_itemsize*/
/* methods */
(
destructor
)
md5_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
(
destructor
)
md5_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
(
getattrfunc
)
md5_getattr
,
/*tp_getattr*/
0
,
/*tp_setattr*/
0
,
/*tp_compare*/
0
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_setattr*/
0
,
/*tp_compare*/
0
,
/*tp_repr*/
0
,
/*tp_as_number*/
};
/* MD5 functions */
static
o
bject
*
static
PyO
bject
*
MD5_new
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
md5object
*
md5p
;
unsigned
char
*
cp
=
NULL
;
int
len
=
0
;
if
(
!
newgetargs
(
args
,
"|s#"
,
&
cp
,
&
len
))
if
(
!
PyArg_ParseTuple
(
args
,
"|s#"
,
&
cp
,
&
len
))
return
NULL
;
if
((
md5p
=
newmd5object
())
==
NULL
)
...
...
@@ -185,15 +183,15 @@ MD5_new(self, args)
if
(
cp
)
MD5Update
(
&
md5p
->
md5
,
cp
,
len
);
return
(
o
bject
*
)
md5p
;
return
(
PyO
bject
*
)
md5p
;
}
/* List of functions exported by this module */
static
struct
methodlist
md5_functions
[]
=
{
{
"new"
,
(
method
)
MD5_new
,
1
},
{
"md5"
,
(
method
)
MD5_new
,
1
},
/* Backward compatibility */
static
PyMethodDef
md5_functions
[]
=
{
{
"new"
,
(
PyCFunction
)
MD5_new
,
1
},
{
"md5"
,
(
PyCFunction
)
MD5_new
,
1
},
/* Backward compatibility */
{
NULL
,
NULL
}
/* Sentinel */
};
...
...
@@ -203,5 +201,5 @@ static struct methodlist md5_functions[] = {
void
initmd5
()
{
(
void
)
initm
odule
(
"md5"
,
md5_functions
);
(
void
)
Py_InitM
odule
(
"md5"
,
md5_functions
);
}
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