speedups.c
Go to the documentation of this file.
00001 #define PY_SSIZE_T_CLEAN
00002 #include <Python.h>
00003 
00004 static PyObject* websocket_mask(PyObject* self, PyObject* args) {
00005     const char* mask;
00006     Py_ssize_t mask_len;
00007     const char* data;
00008     Py_ssize_t data_len;
00009     Py_ssize_t i;
00010     PyObject* result;
00011     char* buf;
00012 
00013     if (!PyArg_ParseTuple(args, "s#s#", &mask, &mask_len, &data, &data_len)) {
00014         return NULL;
00015     }
00016 
00017     result = PyBytes_FromStringAndSize(NULL, data_len);
00018     if (!result) {
00019         return NULL;
00020     }
00021     buf = PyBytes_AsString(result);
00022     for (i = 0; i < data_len; i++) {
00023         buf[i] = data[i] ^ mask[i % 4];
00024     }
00025 
00026     return result;
00027 }
00028 
00029 static PyMethodDef methods[] = {
00030     {"websocket_mask",  websocket_mask, METH_VARARGS, ""},
00031     {NULL, NULL, 0, NULL}
00032 };
00033 
00034 #if PY_MAJOR_VERSION >= 3
00035 static struct PyModuleDef speedupsmodule = {
00036    PyModuleDef_HEAD_INIT,
00037    "speedups",
00038    NULL,
00039    -1,
00040    methods
00041 };
00042 
00043 PyMODINIT_FUNC
00044 PyInit_speedups() {
00045     return PyModule_Create(&speedupsmodule);
00046 }
00047 #else  // Python 2.x
00048 PyMODINIT_FUNC
00049 initspeedups() {
00050     Py_InitModule("tornado.speedups", methods);
00051 }
00052 #endif


rosbridge_server
Author(s): Jonathan Mace
autogenerated on Wed Sep 13 2017 03:18:20