Changes in / [9509d67a:c8ec58e]


Ignore:
Files:
2 added
2 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • libcfa/prelude/extras.c

    r9509d67a rc8ec58e  
    33#include <uchar.h>                                      // char16_t, char32_t
    44#include <wchar.h>                                      // wchar_t
    5 #include <stdlib.h>                                     // malloc, free, exit, atexit, abort
     5#include <stdlib.h>                                     // malloc, free, getenv, exit, atexit, abort, printf
    66#include <stdio.h>                                      // printf
     7#include <string.h>                                     // strlen, strcmp, strncmp
  • libcfa/prelude/extras.regx2

    r9509d67a rc8ec58e  
    11extern void \*malloc[^;]*;
    22extern void free[^;]*;
     3extern char \*getenv[^;]*;
    34extern void exit[^;]*;
    45extern int atexit[^;]*;
    56extern void abort[^;]*;
    67extern int printf[^;]*;
     8int strcmp[^;]*;
     9int strncmp[^;]*;
     10size_t strlen[^;]*;
  • libcfa/src/clock.hfa

    r9509d67a rc8ec58e  
    1010// Created On       : Thu Apr 12 14:36:06 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Apr 18 08:12:16 2021
    13 // Update Count     : 28
     12// Last Modified On : Sat Sep  9 14:07:17 2023
     13// Update Count     : 30
    1414//
    1515
     
    9191        // discontinuous jumps when the OS is not running the kernal thread. A duration is returned because the value is
    9292        // relative and cannot be converted to real-time (wall-clock) time.
    93         Duration processor() {                                                          // non-monotonic duration of kernel thread
     93        Duration processor_cpu() {                                                      // non-monotonic duration of kernel thread
    9494                timespec ts;
    9595                clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts );
    9696                return (Duration){ ts };
    97         } // processor
     97        } // processor_cpu
    9898
    9999        // Program CPU-time watch measures CPU time consumed by all processors (kernel threads) in the UNIX process.  This
    100100        // watch is affected by discontinuous jumps when the OS is not running the kernel threads. A duration is returned
    101101        // because the value is relative and cannot be converted to real-time (wall-clock) time.
    102         Duration program() {                                                            // non-monotonic duration of program CPU
     102        Duration program_cpu() {                                                        // non-monotonic duration of program CPU
    103103                timespec ts;
    104104                clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts );
    105105                return (Duration){ ts };
    106         } // program
     106        } // program_cpu
    107107
    108108        // Monotonic duration from machine boot and including system suspension. This watch is unaffected by discontinuous
  • libcfa/src/concurrency/kernel/cluster.hfa

    r9509d67a rc8ec58e  
    3131
    3232// warn normally all ints
    33 #define warn_large_before warnf( !strict || old_avg < 33_000_000_000, "Suspiciously large previous average: %'llu (%llx), %'" PRId64 "ms \n", old_avg, old_avg, program()`ms )
    34 #define warn_large_after warnf( !strict || ret < 33_000_000_000, "Suspiciously large new average after %'" PRId64 "ms cputime: %'llu (%llx) from %'llu-%'llu (%'llu, %'llu) and %'llu\n", program()`ms, ret, ret, currtsc, intsc, new_val, new_val / 1000000, old_avg )
     33#define warn_large_before warnf( !strict || old_avg < 33_000_000_000, "Suspiciously large previous average: %'llu (%llx), %'" PRId64 "ms \n", old_avg, old_avg, program_cpu()`ms )
     34#define warn_large_after warnf( !strict || ret < 33_000_000_000, "Suspiciously large new average after %'" PRId64 "ms cputime: %'llu (%llx) from %'llu-%'llu (%'llu, %'llu) and %'llu\n", program_cpu()`ms, ret, ret, currtsc, intsc, new_val, new_val / 1000000, old_avg )
    3535
    3636// 8X linear factor is just 8 * x
     
    4242static inline __readyQ_avg_t __to_readyQ_avg(unsigned long long intsc) { if(unlikely(0 == intsc)) return 0.0; else return log2((__readyQ_avg_t)intsc); }
    4343
    44 #define warn_large_before warnf( !strict || old_avg < 35.0, "Suspiciously large previous average: %'lf, %'" PRId64 "ms \n", old_avg, program()`ms )
    45 #define warn_large_after warnf( !strict || ret < 35.3, "Suspiciously large new average after %'" PRId64 "ms cputime: %'lf from %'llu-%'llu (%'llu, %'llu) and %'lf\n", program()`ms, ret, currtsc, intsc, new_val, new_val / 1000000, old_avg ); \
     44#define warn_large_before warnf( !strict || old_avg < 35.0, "Suspiciously large previous average: %'lf, %'" PRId64 "ms \n", old_avg, program_cpu()`ms )
     45#define warn_large_after warnf( !strict || ret < 35.3, "Suspiciously large new average after %'" PRId64 "ms cputime: %'lf from %'llu-%'llu (%'llu, %'llu) and %'lf\n", program_cpu()`ms, ret, currtsc, intsc, new_val, new_val / 1000000, old_avg ); \
    4646verify(ret >= 0)
    4747
  • libcfa/src/heap.cfa

    r9509d67a rc8ec58e  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug  2 18:48:30 2023
    13 // Update Count     : 1614
     12// Last Modified On : Mon Sep 11 11:21:10 2023
     13// Update Count     : 1615
    1414//
    1515
     
    691691        return stats;
    692692} // collectStats
     693
     694static inline void clearStats() {
     695        lock( mgrLock );
     696
     697        // Zero the heap master and all active thread heaps.
     698        HeapStatisticsCtor( heapMaster.stats );
     699        for ( Heap * heap = heapMaster.heapManagersList; heap; heap = heap->nextHeapManager ) {
     700                HeapStatisticsCtor( heap->stats );
     701        } // for
     702
     703        unlock( mgrLock );
     704} // clearStats
    693705#endif // __STATISTICS__
    694706
     
    15561568
    15571569
     1570        // Zero the heap master and all active thread heaps.
     1571        void malloc_stats_clear() {
     1572                #ifdef __STATISTICS__
     1573                clearStats();
     1574                #else
     1575                #define MALLOC_STATS_MSG "malloc_stats statistics disabled.\n"
     1576                if ( write( STDERR_FILENO, MALLOC_STATS_MSG, sizeof( MALLOC_STATS_MSG ) - 1 /* size includes '\0' */ ) == -1 ) {
     1577                        abort( "**** Error **** write failed in malloc_stats" );
     1578                } // if
     1579                #endif // __STATISTICS__
     1580        } // malloc_stats_clear
     1581
     1582
    15581583        // Changes the file descriptor where malloc_stats() writes statistics.
    15591584        int malloc_stats_fd( int fd __attribute__(( unused )) ) libcfa_public {
  • libcfa/src/heap.hfa

    r9509d67a rc8ec58e  
    1010// Created On       : Tue May 26 11:23:55 2020
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Oct  4 19:08:55 2022
    13 // Update Count     : 23
     12// Last Modified On : Mon Sep 11 11:18:18 2023
     13// Update Count     : 24
    1414//
    1515
     
    4343        size_t malloc_mmap_start();                                                     // crossover allocation size from sbrk to mmap
    4444        size_t malloc_unfreed();                                                        // heap unfreed size (bytes)
     45        void malloc_stats_clear();                                                      // clear heap statistics
    4546} // extern "C"
    4647
  • libcfa/src/iostream.cfa

    r9509d67a rc8ec58e  
     1
    12//
    23// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     
    976977                if ( f.flags.ignore ) { fmtstr[1] = '*'; start += 1; }
    977978                // no maximum width necessary because text ignored => width is read width
    978                 if ( f.wd != -1 ) { start += sprintf( &fmtstr[start], "%d", f.wd ); }
     979                if ( f.wd != -1 ) {
     980                        // wd is buffer bytes available (for input chars + null terminator)
     981                        // rwd is count of input chars
     982                        int rwd = f.flags.rwd ? f.wd : (f.wd - 1);
     983                        start += sprintf( &fmtstr[start], "%d", rwd );
     984                }
    979985
    980986                if ( ! scanset ) {
     
    993999                } // if
    9941000
    995                 int check = f.wd - 1;
     1001                int check = f.wd - 2;
    9961002                if ( ! f.flags.rwd ) f.s[check] = '\0';                 // insert sentinel
    9971003                len = fmt( is, fmtstr, f.s );
  • src/ControlStruct/MultiLevelExit.cpp

    r9509d67a rc8ec58e  
    1010// Created On       : Mon Nov  1 13:48:00 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Sep  6 12:00:00 2023
    13 // Update Count     : 35
     12// Last Modified On : Fri Sep  8 17:04:00 2023
     13// Update Count     : 36
    1414//
    1515
     
    2727
    2828namespace {
     29
     30/// The return context is used to remember if returns are allowed and if
     31/// not, why not. It is the nearest local control flow blocking construct.
     32enum ReturnContext {
     33        MayReturn,
     34        InTryWithHandler,
     35        InResumeHandler,
     36        InTerminateHandler,
     37        InFinally,
     38};
    2939
    3040class Entry {
     
    126136        void previsit( const TryStmt * );
    127137        void postvisit( const TryStmt * );
     138        void previsit( const CatchClause * );
    128139        void previsit( const FinallyClause * );
    129140
     
    134145        vector<Entry> enclosing_control_structures;
    135146        Label break_label;
    136         bool inFinally;
     147        ReturnContext ret_context;
    137148
    138149        template<typename LoopNode>
     
    144155                const list<ptr<Stmt>> & kids, bool caseClause );
    145156
     157        void enterSealedContext( ReturnContext );
     158
    146159        template<typename UnaryPredicate>
    147160        auto findEnclosingControlStructure( UnaryPredicate pred ) {
     
    157170MultiLevelExitCore::MultiLevelExitCore( const LabelToStmt & lt ) :
    158171        target_table( lt ), break_label( CodeLocation(), "" ),
    159         inFinally( false )
     172        ret_context( ReturnContext::MayReturn )
    160173{}
    161174
     
    488501
    489502void MultiLevelExitCore::previsit( const ReturnStmt * stmt ) {
    490         if ( inFinally ) {
    491                 SemanticError( stmt->location, "'return' may not appear in a finally clause" );
    492         }
     503        char const * context;
     504        switch ( ret_context ) {
     505        case ReturnContext::MayReturn:
     506                return;
     507        case ReturnContext::InTryWithHandler:
     508                context = "try statement with a catch clause";
     509                break;
     510        case ReturnContext::InResumeHandler:
     511                context = "catchResume clause";
     512                break;
     513        case ReturnContext::InTerminateHandler:
     514                context = "catch clause";
     515                break;
     516        case ReturnContext::InFinally:
     517                context = "finally clause";
     518                break;
     519        default:
     520                assert(0);
     521        }
     522        SemanticError( stmt->location, toString( "'return' may not appear in a ", context ) );
    493523}
    494524
     
    500530                GuardAction([this](){ enclosing_control_structures.pop_back(); } );
    501531        }
     532
     533        // Try statements/try blocks are only sealed with a termination handler.
     534        for ( auto clause : stmt->handlers ) {
     535                if ( ast::Terminate == clause->kind ) {
     536                        return enterSealedContext( ReturnContext::InTryWithHandler );
     537                }
     538        }
    502539}
    503540
     
    512549}
    513550
     551void MultiLevelExitCore::previsit( const CatchClause * clause ) {
     552        ReturnContext context = ( ast::Terminate == clause->kind )
     553                ? ReturnContext::InTerminateHandler : ReturnContext::InResumeHandler;
     554        enterSealedContext( context );
     555}
     556
    514557void MultiLevelExitCore::previsit( const FinallyClause * ) {
    515         GuardAction([this, old = std::move( enclosing_control_structures)](){ enclosing_control_structures = std::move(old); });
    516         enclosing_control_structures = vector<Entry>();
    517         GuardValue( inFinally ) = true;
     558        enterSealedContext( ReturnContext::InFinally );
    518559}
    519560
     
    617658}
    618659
     660void MultiLevelExitCore::enterSealedContext( ReturnContext enter_context ) {
     661        GuardAction([this, old = std::move(enclosing_control_structures)](){ enclosing_control_structures = std::move(old); });
     662        enclosing_control_structures = vector<Entry>();
     663        GuardValue( ret_context ) = enter_context;
     664}
     665
    619666} // namespace
    620667
  • tests/concurrency/waituntil/locks.cfa

    r9509d67a rc8ec58e  
    7373    printf("done\n");
    7474}
     75
  • tests/io/.expect/manipulatorsInput.arm64.txt

    r9509d67a rc8ec58e  
     1pre1 "123456", canary ok
     2pre2a "1234567", exception occurred, canary ok
     3pre2b "89", canary ok
    141 yyyyyyyyyyyyyyyyyyyy
    252 abcxxx
  • tests/io/.expect/manipulatorsInput.x64.txt

    r9509d67a rc8ec58e  
     1pre1 "123456", canary ok
     2pre2a "1234567", exception occurred, canary ok
     3pre2b "89", canary ok
    141 yyyyyyyyyyyyyyyyyyyy
    252 abcxxx
  • tests/io/.expect/manipulatorsInput.x86.txt

    r9509d67a rc8ec58e  
     1pre1 "123456", canary ok
     2pre2a "1234567", exception occurred, canary ok
     3pre2b "89", canary ok
    141 yyyyyyyyyyyyyyyyyyyy
    252 abcxxx
  • tests/io/.in/manipulatorsInput.txt

    r9509d67a rc8ec58e  
     1123456
     2123456789
    13abc
    24abc
  • tests/io/manipulatorsInput.cfa

    r9509d67a rc8ec58e  
    1515
    1616int main() {
     17        {
     18                // Upfront checks to ensure buffer safety.  Once these pass, the simpler `wdi(sizeof(s),s)`
     19                // usage, as in the scanf alignment cases below, is justified.
     20                struct {
     21                        char buf[8];
     22                        char canary;
     23                } data;
     24                static_assert( sizeof(data.buf) == 8 );
     25                static_assert( &data.buf[8] == &data.canary );  // canary comes right after buf
     26
     27                void rep(const char* casename) {
     28                        data.canary = 42;
     29                        bool caught = false;
     30                        try {
     31                                sin | wdi( sizeof(data.buf), data.buf );
     32                        } catch (cstring_length*) {
     33                                caught = true;
     34                        }
     35                        printf( "%s \"%s\"", casename, data.buf );
     36                        if ( caught ) {
     37                                printf(", exception occurred");
     38                        }
     39                        if ( data.canary == 42 ) {
     40                                printf(", canary ok");
     41                        } else {
     42                                printf(", canary overwritten to %d", data.canary);
     43                        }
     44                        printf("\n");
     45                }
     46
     47                rep("pre1");
     48                rep("pre2a");
     49                rep("pre2b");
     50                scanf("\n");  // next test does not start with %s so does not tolerate leading whitespace
     51        }
    1752        {
    1853                char s[] = "yyyyyyyyyyyyyyyyyyyy";
Note: See TracChangeset for help on using the changeset viewer.