Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
73363b52
Kaydet (Commit)
73363b52
authored
Agu 19, 1996
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added _xdr module
üst
40006cfd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
168 additions
and
0 deletions
+168
-0
Setup.in
Modules/Setup.in
+1
-0
_xdrmodule.c
Modules/_xdrmodule.c
+167
-0
No files found.
Modules/Setup.in
Dosyayı görüntüle @
73363b52
...
...
@@ -134,6 +134,7 @@ errno errnomodule.c # posix (UNIX) errno values
#dbm dbmmodule.c # dbm(3) may require -lndbm or similar
#nis nismodule.c # Sun yellow pages -- not everywhere
#termios termios.c # Steen Lumholt's termios module
#_xdr xdrmodule.c # -lnsl # Helper for xdrlib.py
# Multimedia modules -- on by default.
...
...
Modules/_xdrmodule.c
0 → 100644
Dosyayı görüntüle @
73363b52
/* This module exports part of the C API to the XDR routines into Python.
* XDR is Sun's eXternal Data Representation, as described in RFC 1014. This
* module is used by xdrlib.py to support the float and double data types
* which are too much of a pain to support in Python directly. It is
* not required by xdrlib.py -- when not available, these types aren't
* supported at the Python layer. Note that representations that can be
* implemented solely in Python, are *not* reproduced here.
*
* Module version number: 1.0
*
* See xdrlib.py for usage notes.
*
* Note: this has so far, only been tested on Solaris 2.5 and SGI IRIX 5.3.
* On these systems, you will need to link with -lnsl for these
* symbols to be defined.
*/
#include "Python.h"
#include <netconfig.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
static
PyObject
*
xdr_error
;
static
PyObject
*
pack_float
(
self
,
args
)
PyObject
*
self
;
PyObject
*
args
;
{
XDR
xdr
;
float
value
;
union
{
/* guarantees proper alignment */
long
dummy
;
char
buffer
[
4
];
}
addr
;
PyObject
*
rtn
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"f"
,
&
value
))
return
NULL
;
xdrmem_create
(
&
xdr
,
addr
.
buffer
,
4
,
XDR_ENCODE
);
if
(
xdr_float
(
&
xdr
,
&
value
))
rtn
=
PyString_FromStringAndSize
(
addr
.
buffer
,
4
);
else
PyErr_SetString
(
xdr_error
,
"conversion from float failed"
);
xdr_destroy
(
&
xdr
);
return
rtn
;
}
static
PyObject
*
pack_double
(
self
,
args
)
PyObject
*
self
;
PyObject
*
args
;
{
XDR
xdr
;
double
value
;
union
{
/* guarantees proper alignment */
long
dummy
;
char
buffer
[
8
];
}
addr
;
PyObject
*
rtn
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"d"
,
&
value
))
return
NULL
;
xdrmem_create
(
&
xdr
,
addr
.
buffer
,
8
,
XDR_ENCODE
);
if
(
xdr_double
(
&
xdr
,
&
value
))
rtn
=
PyString_FromStringAndSize
(
addr
.
buffer
,
8
);
else
PyErr_SetString
(
xdr_error
,
"conversion from double failed"
);
xdr_destroy
(
&
xdr
);
return
rtn
;
}
static
PyObject
*
unpack_float
(
self
,
args
)
PyObject
*
self
;
PyObject
*
args
;
{
XDR
xdr
;
float
value
;
char
*
string
;
int
strlen
;
PyObject
*
rtn
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"s#"
,
&
string
,
&
strlen
))
return
NULL
;
if
(
strlen
!=
4
)
{
PyErr_SetString
(
PyExc_ValueError
,
"4 byte string expected"
);
return
NULL
;
}
/* Python guarantees that the string is 4 byte aligned */
xdrmem_create
(
&
xdr
,
(
caddr_t
)
string
,
4
,
XDR_DECODE
);
if
(
xdr_float
(
&
xdr
,
&
value
))
rtn
=
Py_BuildValue
(
"f"
,
value
);
else
PyErr_SetString
(
xdr_error
,
"conversion to float failed"
);
xdr_destroy
(
&
xdr
);
return
rtn
;
}
static
PyObject
*
unpack_double
(
self
,
args
)
PyObject
*
self
;
PyObject
*
args
;
{
XDR
xdr
;
double
value
;
char
*
string
;
int
strlen
;
PyObject
*
rtn
;
if
(
!
PyArg_ParseTuple
(
args
,
"s#"
,
&
string
,
&
strlen
))
return
NULL
;
if
(
strlen
!=
8
)
{
PyErr_SetString
(
PyExc_ValueError
,
"8 byte string expected"
);
return
NULL
;
}
/* Python guarantees that the string is 4 byte aligned */
xdrmem_create
(
&
xdr
,
(
caddr_t
)
string
,
8
,
XDR_DECODE
);
if
(
xdr_double
(
&
xdr
,
&
value
))
rtn
=
Py_BuildValue
(
"d"
,
value
);
else
PyErr_SetString
(
xdr_error
,
"conversion to double failed"
);
xdr_destroy
(
&
xdr
);
return
rtn
;
}
static
struct
PyMethodDef
xdr_methods
[]
=
{
{
"pack_float"
,
pack_float
,
1
},
{
"pack_double"
,
pack_double
,
1
},
{
"unpack_float"
,
unpack_float
,
1
},
{
"unpack_double"
,
unpack_double
,
1
},
{
NULL
,
NULL
,
0
}
/* sentinel */
};
void
init_xdr
()
{
PyObject
*
module
;
PyObject
*
dict
;
module
=
Py_InitModule
(
"_xdr"
,
xdr_methods
);
dict
=
PyModule_GetDict
(
module
);
xdr_error
=
PyString_FromString
(
"_xdr.error"
);
PyDict_SetItemString
(
dict
,
"error"
,
xdr_error
);
}
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