FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Changes for BeOS, QNX and long long, by Chris Herborth. · python/cpython@1a8791e · GitHub

/ cpython Public

Commit 1a8791e

Browse files
committed
Changes for BeOS, QNX and long long, by Chris Herborth.
1 parent 7d896ab commit 1a8791e

12 files changed

Lines changed: 559 additions & 1 deletion

File tree

‎Include/import.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ int PyImport_ImportFrozenModule Py_PROTO((char *));
5454
extern PyObject *_PyImport_FindExtension Py_PROTO((char *, char *));
5555
extern PyObject *_PyImport_FixupExtension Py_PROTO((char *, char *));
5656

57+
#ifdef __BEOS__
58+
#include <kernel/image.h>
59+
extern image_id PyImport_BeImageID( char *name );
60+
#endif
61+
5762
struct _inittab {
5863
char *name;
5964
void (*initfunc)();

‎Include/longobject.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ extern long PyLong_AsLong Py_PROTO((PyObject *));
5050
extern unsigned long PyLong_AsUnsignedLong Py_PROTO((PyObject *));
5151
extern double PyLong_AsDouble Py_PROTO((PyObject *));
5252

53+
#ifdef HAVE_LONG_LONG
54+
extern PyObject *PyLong_FromLongLong Py_PROTO((long long ));
55+
extern PyObject *PyLong_FromUnsignedLongLong Py_PROTO((unsigned long long));
56+
extern long long PyLong_AsLongLong Py_PROTO((PyObject *));
57+
extern unsigned long long PyLong_AsUnsignedLongLong Py_PROTO((PyObject *));
58+
#endif
59+
5360
PyObject *PyLong_FromString Py_PROTO((char *, char **, int));
5461

5562
#ifdef __cplusplus

‎Include/pythread.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ extern "C" {
2020
#endif
2121

2222
/* Macros defining new names for all these symbols */
23+
/* BeOS note: We have exit_thread(), and no legacy code to
24+
* support, so we won't allow exit_thread and _exit_thread
25+
* in here. Actually, I think these #defines should vanish;
26+
* aren't they cheesy in the face of the Great Renaming? [cjh]
27+
*/
2328
#define init_thread PyThread_init_thread
2429
#define start_new_thread PyThread_start_new_thread
30+
#ifndef __BEOS__
2531
#define exit_thread PyThread_exit_thread
2632
#define _exit_thread PyThread__exit_thread
33+
#endif
2734
#define get_thread_ident PyThread_get_thread_ident
2835
#define allocate_lock PyThread_allocate_lock
2936
#define free_lock PyThread_free_lock
@@ -43,8 +50,13 @@ extern "C" {
4350

4451
void init_thread Py_PROTO((void));
4552
int start_new_thread Py_PROTO((void (*)(void *), void *));
53+
#ifndef __BEOS__
4654
void exit_thread Py_PROTO((void));
4755
void _exit_thread Py_PROTO((void));
56+
#else
57+
void PyThread_exit_thread Py_PROTO((void));
58+
void PyThread__exit_thread Py_PROTO((void));
59+
#endif
4860
long get_thread_ident Py_PROTO((void));
4961

5062
type_lock allocate_lock Py_PROTO((void));

‎Include/thread.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ extern "C" {
2020
#endif
2121

2222
/* Macros defining new names for all these symbols */
23+
/* BeOS note: We have exit_thread(), and no legacy code to
24+
* support, so we won't allow exit_thread and _exit_thread
25+
* in here. Actually, I think these #defines should vanish;
26+
* aren't they cheesy in the face of the Great Renaming? [cjh]
27+
*/
2328
#define init_thread PyThread_init_thread
2429
#define start_new_thread PyThread_start_new_thread
30+
#ifndef __BEOS__
2531
#define exit_thread PyThread_exit_thread
2632
#define _exit_thread PyThread__exit_thread
33+
#endif
2734
#define get_thread_ident PyThread_get_thread_ident
2835
#define allocate_lock PyThread_allocate_lock
2936
#define free_lock PyThread_free_lock
@@ -43,8 +50,13 @@ extern "C" {
4350

4451
void init_thread Py_PROTO((void));
4552
int start_new_thread Py_PROTO((void (*)(void *), void *));
53+
#ifndef __BEOS__
4654
void exit_thread Py_PROTO((void));
4755
void _exit_thread Py_PROTO((void));
56+
#else
57+
void PyThread_exit_thread Py_PROTO((void));
58+
void PyThread__exit_thread Py_PROTO((void));
59+
#endif
4860
long get_thread_ident Py_PROTO((void));
4961

5062
type_lock allocate_lock Py_PROTO((void));

‎Objects/longobject.c‎

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,198 @@ PyLong_AsDouble(vv)
277277
return x * sign;
278278
}
279279

280+
#ifdef HAVE_LONG_LONG
281+
/*
282+
* long long support by Chris Herborth (chrish@qnx.com)
283+
*
284+
* For better or worse :-), I tried to follow the coding style already
285+
* here.
286+
*/
287+
288+
#ifdef HAVE_LIMITS_H
289+
#include <limits.h>
290+
#endif
291+
292+
/* Hopefully this is portable... */
293+
#ifndef LONG_MAX
294+
#define LONG_MAX 2147483647L
295+
#endif
296+
#ifndef ULONG_MAX
297+
#define ULONG_MAX 4294967295U
298+
#endif
299+
#ifndef LONGLONG_MAX
300+
#define LONGLONG_MAX 9223372036854775807LL
301+
#endif
302+
#ifndef ULONGLONG_MAX
303+
#define ULONGLONG_MAX 0xffffffffffffffffULL
304+
#endif
305+
306+
/* Create a new long int object from a C long long int */
307+
308+
PyObject *
309+
PyLong_FromLongLong(ival)
310+
long long ival;
311+
{
312+
#if SIZEOF_LONG_LONG == SIZEOF_LONG
313+
/* In case the compiler is faking it. */
314+
return PyLong_FromLong( (long)ival );
315+
#else
316+
if( ival <= (long long)LONG_MAX ) {
317+
return PyLong_FromLong( (long)ival );
318+
} else if( ival <= (unsigned long long)ULONG_MAX ) {
319+
return PyLong_FromUnsignedLong( (unsigned long)ival );
320+
} else {
321+
/* Assume a C long long fits in at most 10 'digits'.
322+
* Should be OK if we're assuming long fits in 5.
323+
*/
324+
PyLongObject *v = _PyLong_New(10);
325+
326+
if (v != NULL) {
327+
unsigned long long t = ival;
328+
int i;
329+
if (ival < 0) {
330+
t = -ival;
331+
v->ob_size = -(v->ob_size);
332+
}
333+
334+
for (i = 0; i < 10; i++) {
335+
v->ob_digit[i] = (digit) (t & MASK);
336+
t >>= SHIFT;
337+
}
338+
339+
v = long_normalize(v);
340+
}
341+
342+
return (PyObject *)v;
343+
}
344+
345+
/* If we got here, we're confused... */
346+
PyErr_SetString( PyExc_ArithmeticError, "invalid long integer" );
347+
return NULL;
348+
#endif
349+
}
350+
351+
/* Create a new long int object from a C unsigned long long int */
352+
PyObject *
353+
PyLong_FromUnsignedLongLong(ival)
354+
unsigned long long ival;
355+
{
356+
#if SIZEOF_LONG_LONG == SIZEOF_LONG
357+
/* In case the compiler is faking it. */
358+
return PyLong_FromUnsignedLong( (unsigned long)ival );
359+
#else
360+
if( ival <= (unsigned long long)ULONG_MAX ) {
361+
return PyLong_FromUnsignedLong( (unsigned long)ival );
362+
} else {
363+
/* Assume a C long fits in at most 10 'digits'. */
364+
PyLongObject *v = _PyLong_New(10);
365+
366+
if (v != NULL) {
367+
unsigned long long t = ival;
368+
int i;
369+
for (i = 0; i < 10; i++) {
370+
v->ob_digit[i] = (digit) (t & MASK);
371+
t >>= SHIFT;
372+
}
373+
374+
v = long_normalize(v);
375+
}
376+
377+
return (PyObject *)v;
378+
}
379+
380+
/* If we got here, we're confused... */
381+
PyErr_SetString( PyExc_ArithmeticError, "invalid unsigned long integer" );
382+
return NULL;
383+
#endif
384+
}
385+
386+
/* Get a C long long int from a long int object.
387+
Returns -1 and sets an error condition if overflow occurs. */
388+
389+
long long
390+
PyLong_AsLongLong(vv)
391+
PyObject *vv;
392+
{
393+
#if SIZEOF_LONG_LONG == SIZEOF_LONG
394+
/* In case the compiler is faking it. */
395+
return (long long)PyLong_AsLong( vv );
396+
#else
397+
register PyLongObject *v;
398+
long long x, prev;
399+
int i, sign;
400+
401+
if (vv == NULL || !PyLong_Check(vv)) {
402+
PyErr_BadInternalCall();
403+
return -1;
404+
}
405+
406+
v = (PyLongObject *)vv;
407+
i = v->ob_size;
408+
sign = 1;
409+
x = 0;
410+
411+
if (i < 0) {
412+
sign = -1;
413+
i = -(i);
414+
}
415+
416+
while (--i >= 0) {
417+
prev = x;
418+
x = (x << SHIFT) + v->ob_digit[i];
419+
if ((x >> SHIFT) != prev) {
420+
PyErr_SetString(PyExc_OverflowError,
421+
"long int too long to convert");
422+
return -1;
423+
}
424+
}
425+
426+
return x * sign;
427+
#endif
428+
}
429+
430+
unsigned long long
431+
PyLong_AsUnsignedLongLong(vv)
432+
PyObject *vv;
433+
{
434+
#if SIZEOF_LONG_LONG == 4
435+
/* In case the compiler is faking it. */
436+
return (unsigned long long)PyLong_AsUnsignedLong( vv );
437+
#else
438+
register PyLongObject *v;
439+
unsigned long long x, prev;
440+
int i;
441+
442+
if (vv == NULL || !PyLong_Check(vv)) {
443+
PyErr_BadInternalCall();
444+
return (unsigned long long) -1;
445+
}
446+
447+
v = (PyLongObject *)vv;
448+
i = v->ob_size;
449+
x = 0;
450+
451+
if (i < 0) {
452+
PyErr_SetString(PyExc_OverflowError,
453+
"can't convert negative value to unsigned long");
454+
return (unsigned long long) -1;
455+
}
456+
457+
while (--i >= 0) {
458+
prev = x;
459+
x = (x << SHIFT) + v->ob_digit[i];
460+
if ((x >> SHIFT) != prev) {
461+
PyErr_SetString(PyExc_OverflowError,
462+
"long int too long to convert");
463+
return (unsigned long long) -1;
464+
}
465+
}
466+
467+
return x;
468+
#endif
469+
}
470+
#endif /* HAVE_LONG_LONG */
471+
280472
/* Multiply by a single digit, ignoring the sign. */
281473

282474
static PyLongObject *

‎Python/frozenmain.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ extern void PyWinFreeze_ExeTerm();
4242
#include <unistd.h> /* For isatty() */
4343
#endif
4444

45+
/* For isatty()'s proto. - [cjh] */
46+
#ifdef HAVE_UNISTD_H
47+
#include <unistd.h>
48+
#endif
49+
4550
/* Main program */
4651

4752
int

‎Python/getargs.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,20 @@ convertsimple1(arg, p_format, p_va)
499499
break;
500500
}
501501

502+
#if HAVE_LONG_LONG
503+
case 'L': /* long long */
504+
{
505+
long long *p = va_arg( *p_va, long long * );
506+
long long ival = PyLong_AsLongLong( arg );
507+
if( ival == (long long)-1 && PyErr_Occurred() ) {
508+
return "long<L>";
509+
} else {
510+
*p = ival;
511+
}
512+
break;
513+
}
514+
#endif
515+
502516
case 'f': /* float */
503517
{
504518
float *p = va_arg(*p_va, float *);
@@ -988,6 +1002,14 @@ skipitem(p_format, p_va)
9881002
break;
9891003
}
9901004

1005+
#if HAVE_LONG_LONG
1006+
case 'L': /* long long int */
1007+
{
1008+
(void) va_arg(*p_va, long long *);
1009+
break;
1010+
}
1011+
#endif
1012+
9911013
case 'f': /* float */
9921014
{
9931015
(void) va_arg(*p_va, float *);

‎Python/import.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ static PyMethodDef imp_methods[] = {
22742274
{NULL, NULL} /* sentinel */
22752275
};
22762276

2277-
int
2277+
static int
22782278
setint(d, name, value)
22792279
PyObject *d;
22802280
char *name;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL