Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54cf3dc

Browse files
author
Fredrik Lundh
committed
-- ANSI-fying, names
(patch #100762 by Peter Schneider-Kamp, minus the indentation changes) -- added INT_PTR workaround to make it build under VC 5.0
1 parent c0348ac commit 54cf3dc

1 file changed

Lines changed: 61 additions & 82 deletions

File tree

Modules/mmapmodule.c

Lines changed: 61 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
#ifdef MS_WIN32
2626
#include <windows.h>
27+
#if _MSC_VER < 1200
28+
#define INT_PTR unsigned long
29+
#endif
2730
#endif
2831

2932
#ifdef UNIX
@@ -55,7 +58,7 @@ typedef struct {
5558
} mmap_object;
5659

5760
static void
58-
mmap_object_dealloc(mmap_object * m_obj)
61+
mmap_object_dealloc(mmap_object *m_obj)
5962
{
6063
#ifdef MS_WIN32
6164
UnmapViewOfFile (m_obj->data);
@@ -74,7 +77,7 @@ mmap_object_dealloc(mmap_object * m_obj)
7477
}
7578

7679
static PyObject *
77-
mmap_close_method (mmap_object * self, PyObject * args)
80+
mmap_close_method(mmap_object *self, PyObject *args)
7881
{
7982
if (!PyArg_ParseTuple(args, ":close"))
8083
return NULL;
@@ -115,11 +118,11 @@ do { \
115118
#endif /* UNIX */
116119

117120
static PyObject *
118-
mmap_read_byte_method (mmap_object * self,
119-
PyObject * args)
121+
mmap_read_byte_method(mmap_object *self,
122+
PyObject *args)
120123
{
121124
char value;
122-
char * where;
125+
char *where;
123126
CHECK_VALID(NULL);
124127
if (!PyArg_ParseTuple(args, ":read_byte"))
125128
return NULL;
@@ -135,13 +138,13 @@ mmap_read_byte_method (mmap_object * self,
135138
}
136139

137140
static PyObject *
138-
mmap_read_line_method (mmap_object * self,
139-
PyObject * args)
141+
mmap_read_line_method(mmap_object *self,
142+
PyObject *args)
140143
{
141-
char * start = self->data+self->pos;
142-
char * eof = self->data+self->size;
143-
char * eol;
144-
PyObject * result;
144+
char *start = self->data+self->pos;
145+
char *eof = self->data+self->size;
146+
char *eol;
147+
PyObject *result;
145148

146149
CHECK_VALID(NULL);
147150
if (!PyArg_ParseTuple(args, ":readline"))
@@ -159,14 +162,14 @@ mmap_read_line_method (mmap_object * self,
159162
}
160163

161164
static PyObject *
162-
mmap_read_method (mmap_object * self,
163-
PyObject * args)
165+
mmap_read_method(mmap_object *self,
166+
PyObject *args)
164167
{
165168
long num_bytes;
166169
PyObject *result;
167170

168171
CHECK_VALID(NULL);
169-
if (!PyArg_ParseTuple (args, "l", &num_bytes))
172+
if (!PyArg_ParseTuple(args, "l:read", &num_bytes))
170173
return(NULL);
171174

172175
/* silently 'adjust' out-of-range requests */
@@ -179,22 +182,22 @@ mmap_read_method (mmap_object * self,
179182
}
180183

181184
static PyObject *
182-
mmap_find_method (mmap_object *self,
183-
PyObject *args)
185+
mmap_find_method(mmap_object *self,
186+
PyObject *args)
184187
{
185188
int start = self->pos;
186-
char * needle;
189+
char *needle;
187190
int len;
188191

189192
CHECK_VALID(NULL);
190-
if (!PyArg_ParseTuple (args, "s#|i", &needle, &len, &start)) {
193+
if (!PyArg_ParseTuple (args, "s#|i:find", &needle, &len, &start)) {
191194
return NULL;
192195
} else {
193-
char * p = self->data+self->pos;
194-
char * e = self->data+self->size;
196+
char *p = self->data+self->pos;
197+
char *e = self->data+self->size;
195198
while (p < e) {
196-
char * s = p;
197-
char * n = needle;
199+
char *s = p;
200+
char *n = needle;
198201
while ((s<e) && (*n) && !(*s-*n)) {
199202
s++, n++;
200203
}
@@ -210,14 +213,14 @@ mmap_find_method (mmap_object *self,
210213
}
211214

212215
static PyObject *
213-
mmap_write_method (mmap_object * self,
214-
PyObject * args)
216+
mmap_write_method(mmap_object *self,
217+
PyObject *args)
215218
{
216219
long length;
217-
char * data;
220+
char *data;
218221

219222
CHECK_VALID(NULL);
220-
if (!PyArg_ParseTuple (args, "s#", &data, &length))
223+
if (!PyArg_ParseTuple (args, "s#:write", &data, &length))
221224
return(NULL);
222225

223226
if ((self->pos + length) > self->size) {
@@ -231,13 +234,13 @@ mmap_write_method (mmap_object * self,
231234
}
232235

233236
static PyObject *
234-
mmap_write_byte_method (mmap_object * self,
235-
PyObject * args)
237+
mmap_write_byte_method(mmap_object *self,
238+
PyObject *args)
236239
{
237240
char value;
238241

239242
CHECK_VALID(NULL);
240-
if (!PyArg_ParseTuple (args, "c", &value))
243+
if (!PyArg_ParseTuple (args, "c:write_byte", &value))
241244
return(NULL);
242245

243246
*(self->data+self->pos) = value;
@@ -247,8 +250,8 @@ mmap_write_byte_method (mmap_object * self,
247250
}
248251

249252
static PyObject *
250-
mmap_size_method (mmap_object * self,
251-
PyObject * args)
253+
mmap_size_method(mmap_object *self,
254+
PyObject *args)
252255
{
253256
CHECK_VALID(NULL);
254257
if (!PyArg_ParseTuple(args, ":size"))
@@ -286,12 +289,12 @@ mmap_size_method (mmap_object * self,
286289
*/
287290

288291
static PyObject *
289-
mmap_resize_method (mmap_object * self,
290-
PyObject * args)
292+
mmap_resize_method(mmap_object *self,
293+
PyObject *args)
291294
{
292295
unsigned long new_size;
293296
CHECK_VALID(NULL);
294-
if (!PyArg_ParseTuple (args, "l", &new_size)) {
297+
if (!PyArg_ParseTuple (args, "l:resize", &new_size)) {
295298
return NULL;
296299
#ifdef MS_WIN32
297300
} else {
@@ -363,7 +366,7 @@ mmap_resize_method (mmap_object * self,
363366
}
364367

365368
static PyObject *
366-
mmap_tell_method (mmap_object * self, PyObject * args)
369+
mmap_tell_method(mmap_object *self, PyObject *args)
367370
{
368371
CHECK_VALID(NULL);
369372
if (!PyArg_ParseTuple(args, ":tell"))
@@ -372,12 +375,12 @@ mmap_tell_method (mmap_object * self, PyObject * args)
372375
}
373376

374377
static PyObject *
375-
mmap_flush_method (mmap_object * self, PyObject * args)
378+
mmap_flush_method(mmap_object *self, PyObject *args)
376379
{
377380
size_t offset = 0;
378381
size_t size = self->size;
379382
CHECK_VALID(NULL);
380-
if (!PyArg_ParseTuple (args, "|ll", &offset, &size)) {
383+
if (!PyArg_ParseTuple (args, "|ll:flush", &offset, &size)) {
381384
return NULL;
382385
} else if ((offset + size) > self->size) {
383386
PyErr_SetString (PyExc_ValueError,
@@ -403,12 +406,12 @@ mmap_flush_method (mmap_object * self, PyObject * args)
403406
}
404407

405408
static PyObject *
406-
mmap_seek_method (mmap_object * self, PyObject * args)
409+
mmap_seek_method(mmap_object *self, PyObject *args)
407410
{
408411
int dist;
409412
int how=0;
410413
CHECK_VALID(NULL);
411-
if (!PyArg_ParseTuple (args, "i|i", &dist, &how)) {
414+
if (!PyArg_ParseTuple (args, "i|i:seek", &dist, &how)) {
412415
return(NULL);
413416
} else {
414417
size_t where;
@@ -446,11 +449,11 @@ mmap_seek_method (mmap_object * self, PyObject * args)
446449
}
447450

448451
static PyObject *
449-
mmap_move_method (mmap_object * self, PyObject * args)
452+
mmap_move_method(mmap_object *self, PyObject *args)
450453
{
451454
unsigned long dest, src, count;
452455
CHECK_VALID(NULL);
453-
if (!PyArg_ParseTuple (args, "iii", &dest, &src, &count)) {
456+
if (!PyArg_ParseTuple (args, "iii:move", &dest, &src, &count)) {
454457
return NULL;
455458
} else {
456459
/* bounds check the values */
@@ -502,10 +505,7 @@ mmap_buffer_getreadbuf(mmap_object *self, int index, const void **ptr)
502505
}
503506

504507
static int
505-
mmap_buffer_getwritebuf(self, index, ptr)
506-
mmap_object *self;
507-
int index;
508-
const void **ptr;
508+
mmap_buffer_getwritebuf(mmap_object *self, int index, const void **ptr)
509509
{
510510
CHECK_VALID(-1);
511511
if ( index != 0 ) {
@@ -518,9 +518,7 @@ mmap_buffer_getwritebuf(self, index, ptr)
518518
}
519519

520520
static int
521-
mmap_buffer_getsegcount(self, lenp)
522-
mmap_object *self;
523-
int *lenp;
521+
mmap_buffer_getsegcount(mmap_object *self, int *lenp)
524522
{
525523
CHECK_VALID(-1);
526524
if (lenp)
@@ -529,10 +527,7 @@ mmap_buffer_getsegcount(self, lenp)
529527
}
530528

531529
static int
532-
mmap_buffer_getcharbuffer(self, index, ptr)
533-
mmap_object *self;
534-
int index;
535-
const void **ptr;
530+
mmap_buffer_getcharbuffer(mmap_object *self, int index, const void **ptr)
536531
{
537532
if ( index != 0 ) {
538533
PyErr_SetString(PyExc_SystemError,
@@ -544,23 +539,20 @@ mmap_buffer_getcharbuffer(self, index, ptr)
544539
}
545540

546541
static PyObject *
547-
mmap_object_getattr(mmap_object * self, char * name)
542+
mmap_object_getattr(mmap_object *self, char *name)
548543
{
549544
return Py_FindMethod (mmap_object_methods, (PyObject *)self, name);
550545
}
551546

552547
static int
553-
mmap_length(self)
554-
mmap_object *self;
548+
mmap_length(mmap_object *self)
555549
{
556550
CHECK_VALID(-1);
557551
return self->size;
558552
}
559553

560554
static PyObject *
561-
mmap_item(self, i)
562-
mmap_object *self;
563-
int i;
555+
mmap_item(mmap_object *self, int i)
564556
{
565557
CHECK_VALID(NULL);
566558
if (i < 0 || (size_t)i >= self->size) {
@@ -571,9 +563,7 @@ mmap_item(self, i)
571563
}
572564

573565
static PyObject *
574-
mmap_slice(self, ilow, ihigh)
575-
mmap_object *self;
576-
int ilow, ihigh;
566+
mmap_slice(mmap_object *self, int ilow, int ihigh)
577567
{
578568
CHECK_VALID(NULL);
579569
if (ilow < 0)
@@ -591,9 +581,7 @@ mmap_slice(self, ilow, ihigh)
591581
}
592582

593583
static PyObject *
594-
mmap_concat(self, bb)
595-
mmap_object *self;
596-
PyObject *bb;
584+
mmap_concat(mmap_object *self, PyObject *bb)
597585
{
598586
CHECK_VALID(NULL);
599587
PyErr_SetString(PyExc_SystemError,
@@ -602,9 +590,7 @@ mmap_concat(self, bb)
602590
}
603591

604592
static PyObject *
605-
mmap_repeat(self, n)
606-
mmap_object *self;
607-
int n;
593+
mmap_repeat(mmap_object *self, int n)
608594
{
609595
CHECK_VALID(NULL);
610596
PyErr_SetString(PyExc_SystemError,
@@ -613,10 +599,7 @@ mmap_repeat(self, n)
613599
}
614600

615601
static int
616-
mmap_ass_slice(self, ilow, ihigh, v)
617-
mmap_object *self;
618-
int ilow, ihigh;
619-
PyObject *v;
602+
mmap_ass_slice(mmap_object *self, int ilow, int ihigh, PyObject *v)
620603
{
621604
const char *buf;
622605

@@ -648,10 +631,7 @@ mmap_ass_slice(self, ilow, ihigh, v)
648631
}
649632

650633
static int
651-
mmap_ass_item(self, i, v)
652-
mmap_object *self;
653-
int i;
654-
PyObject *v;
634+
mmap_ass_item(mmap_object *self, int i, PyObject *v)
655635
{
656636
const char *buf;
657637

@@ -724,8 +704,7 @@ static PyTypeObject mmap_object_type = {
724704
Returns -1 on error, with an apprpriate Python exception raised. On
725705
success, the map size is returned. */
726706
static int
727-
_GetMapSize(o)
728-
PyObject *o;
707+
_GetMapSize(PyObject *o)
729708
{
730709
if (PyInt_Check(o)) {
731710
long i = PyInt_AsLong(o);
@@ -772,9 +751,9 @@ _GetMapSize(o)
772751

773752
#ifdef UNIX
774753
static PyObject *
775-
new_mmap_object (PyObject * self, PyObject * args, PyObject *kwdict)
754+
new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
776755
{
777-
mmap_object * m_obj;
756+
mmap_object *m_obj;
778757
PyObject *map_size_obj = NULL;
779758
int map_size;
780759
int fd, flags = MAP_SHARED, prot = PROT_WRITE | PROT_READ;
@@ -809,12 +788,12 @@ new_mmap_object (PyObject * self, PyObject * args, PyObject *kwdict)
809788

810789
#ifdef MS_WIN32
811790
static PyObject *
812-
new_mmap_object (PyObject * self, PyObject * args)
791+
new_mmap_object(PyObject *self, PyObject *args)
813792
{
814-
mmap_object * m_obj;
793+
mmap_object *m_obj;
815794
PyObject *map_size_obj = NULL;
816795
int map_size;
817-
char * tagname = "";
796+
char *tagname = "";
818797

819798
DWORD dwErr = 0;
820799
int fileno;

0 commit comments

Comments
 (0)