Ticket #9636: 9636.patch

File 9636.patch, 2.4 KB (added by jdemeyer, 11 years ago)
  • sage/libs/pari/decl.pxi

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1280438801 -7200
    # Node ID 1cb32ccf9ff79603fa67d484674fe8c4799782d1
    # Parent  62aa41d14c1e7d3a77fd9d20afcb5d89ed820764
    #9636: redirect PARI's standard output to sys.stdout.write()
    
    diff -r 62aa41d14c1e -r 1cb32ccf9ff7 sage/libs/pari/decl.pxi
    a b  
    16061606    long *   int_LSW(GEN x)
    16071607    long *   int_precW(long * xp)
    16081608    long *   int_nextW(long * xp)
     1609
     1610cdef extern:   # paristio.h
     1611    ctypedef struct PariOUT:
     1612        void (*putch)(char)
     1613        void (*puts)(char*)
     1614        void (*flush)()
  • sage/libs/pari/gen.pyx

    diff -r 62aa41d14c1e -r 1cb32ccf9ff7 sage/libs/pari/gen.pyx
    a b  
    2626    sage: v[1]
    2727    [1, 1]~   
    2828
    29 Arithmetic obeys the usual coercion rules.
    30 
    31 ::
     29Arithmetic obeys the usual coercion rules::
    3230
    3331    sage: type(pari(1) + 1)
    3432    <type 'sage.libs.pari.gen.gen'>
     
    135133    3.6054636014326520859158205642077267748102690
    136134
    137135Number fields and precision: TODO
     136
     137TESTS:
     138
     139Check that output from PARI's print command is actually seen by
     140Sage (ticket #9636)::
     141
     142    sage: pari('print("test")')
     143    test
     144
    138145"""
    139146
     147import sys
    140148import math
    141149import types
    142150import operator
     
    79387946
    79397947cdef unsigned long num_primes
    79407948
     7949# Callbacks from PARI to print stuff using sys.stdout.write() instead
     7950# of C library functions like puts().
     7951cdef extern:
     7952    PariOUT defaultOut
     7953    PariOUT defaultErr
     7954
     7955cdef void sage_putchar(char c):
     7956    cdef char str[2]
     7957    str[0] = c
     7958    str[1] = 0
     7959    sys.stdout.write(str)
     7960    return
     7961
     7962cdef void sage_puts(char* s):
     7963    sys.stdout.write(s)
     7964    return
     7965
     7966cdef void sage_flush():
     7967    sys.stdout.flush()
     7968    return
     7969
     7970
    79417971cdef class PariInstance(sage.structure.parent_base.ParentWithBase):
    79427972    def __init__(self, long size=16000000, unsigned long maxprime=500000):
    79437973        """
     
    80018031        prec = prec_bits_to_words(53)
    80028032        GP_DATA.fmt.sigd = prec_bits_to_dec(53)
    80038033
     8034        # Set printing functions
     8035        defaultOut.putch = sage_putchar
     8036        defaultOut.puts = sage_puts
     8037        defaultOut.flush = sage_flush
     8038
    80048039        # Take control of SIGSEGV back from PARI.
    80058040        import signal
    80068041        signal.signal(signal.SIGSEGV, signal.SIG_DFL)