Changeset cdbfab0


Ignore:
Timestamp:
Nov 17, 2017, 4:57:57 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
4d5e57b
Parents:
0fe4e62
Message:

Remove unsafe void * constructors and assignment operators from prelude [closes #24] [fixes #51]

Location:
src
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/kernel

    r0fe4e62 rcdbfab0  
    120120#ifdef __CFA_DEBUG__
    121121        // Last function to enable preemption on this processor
    122         char * last_enable;
     122        const char * last_enable;
    123123#endif
    124124};
  • src/libcfa/concurrency/monitor.c

    r0fe4e62 rcdbfab0  
    823823                this.monitor_count = thrd->monitors.size;
    824824
    825                 this.monitors = malloc( this.monitor_count * sizeof( *this.monitors ) );
     825                this.monitors = (monitor_desc **)malloc( this.monitor_count * sizeof( *this.monitors ) );
    826826                for( int i = 0; i < this.monitor_count; i++ ) {
    827827                        this.monitors[i] = thrd->monitors.list[i];
  • src/libcfa/stdhdr/stddef.h

    r0fe4e62 rcdbfab0  
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // stddef.h -- 
    8 // 
     6//
     7// stddef.h --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Mon Jul  4 23:25:26 2016
     
    1212// Last Modified On : Tue Jul  5 20:40:01 2016
    1313// Update Count     : 12
    14 // 
     14//
    1515
    1616extern "C" {
    17 #include_next <stddef.h>                                                                // has internal check for multiple expansion
     17#include_next <stddef.h>                // has internal check for multiple expansion
     18#undef NULL
     19#define NULL 0                          // define NULL as 0 rather than (void*)0 to take advantage of zero_t
    1820} // extern "C"
    1921
  • src/libcfa/stdlib

    r0fe4e62 rcdbfab0  
    7777        //printf( "X8\n" );
    7878        T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
    79     return memset( ptr, (int)fill, sizeof(T) );                 // initial with fill value
     79    return (T *)memset( ptr, (int)fill, sizeof(T) );                    // initial with fill value
    8080} // alloc
    8181
     
    8787        //printf( "X10\n" );
    8888        T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
    89     return memset( ptr, (int)fill, dim * sizeof(T) );
     89    return (T *)memset( ptr, (int)fill, dim * sizeof(T) );
    9090} // alloc
    9191
    9292static inline forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim ) {
    9393        //printf( "X11\n" );
    94         return (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
     94        return (T *)(void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
    9595} // alloc
    9696forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
     
    103103        //printf( "X14\n" );
    104104    T * ptr = (T *)memalign( align, sizeof(T) );
    105     return memset( ptr, (int)fill, sizeof(T) );
     105    return (T *)memset( ptr, (int)fill, sizeof(T) );
    106106} // align_alloc
    107107
     
    113113        //printf( "X16\n" );
    114114    T * ptr = (T *)memalign( align, dim * sizeof(T) );
    115     return memset( ptr, (int)fill, dim * sizeof(T) );
     115    return (T *)memset( ptr, (int)fill, dim * sizeof(T) );
    116116} // align_alloc
    117117
     
    120120static inline forall( dtype T | sized(T) ) T * memset( T * dest, char c ) {
    121121        //printf( "X17\n" );
    122         return memset( dest, c, sizeof(T) );
     122        return (T *)memset( dest, c, sizeof(T) );
    123123} // memset
    124124extern "C" { void * memcpy( void * dest, const void * src, size_t size ); } // use default C routine for void *
    125125static inline forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src ) {
    126126        //printf( "X18\n" );
    127         return memcpy( dest, src, sizeof(T) );
     127        return (T *)memcpy( dest, src, sizeof(T) );
    128128} // memcpy
    129129
     
    131131static inline forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ) {
    132132        //printf( "X19\n" );
    133         return (void *)memset( dest, c, dim * sizeof(T) );      // C memset
     133        return (T *)(void *)memset( dest, c, dim * sizeof(T) ); // C memset
    134134} // memset
    135135static inline forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ) {
    136136        //printf( "X20\n" );
    137         return (void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
     137        return (T *)(void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
    138138} // memcpy
    139139
  • src/prelude/prelude.cf

    r0fe4e62 rcdbfab0  
    403403forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &, const volatile    DT * );
    404404
    405 forall( dtype DT ) DT *                 ?=?(                 DT *          &,                   void * );
    406 forall( dtype DT ) DT *                 ?=?(                 DT * volatile &,                   void * );
    407 forall( dtype DT ) const DT *           ?=?( const           DT *          &,                   void * );
    408 forall( dtype DT ) const DT *           ?=?( const           DT * volatile &,                   void * );
    409 forall( dtype DT ) const DT *           ?=?( const           DT *          &, const             void * );
    410 forall( dtype DT ) const DT *           ?=?( const           DT * volatile &, const             void * );
    411 forall( dtype DT ) volatile DT *        ?=?(       volatile  DT *          &,                   void * );
    412 forall( dtype DT ) volatile DT *        ?=?(       volatile  DT * volatile &,                   void * );
    413 forall( dtype DT ) volatile DT *        ?=?(       volatile  DT *          &,       volatile    void * );
    414 forall( dtype DT ) volatile DT *        ?=?(       volatile  DT * volatile &,       volatile    void * );
    415 
    416 forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &,                   void * );
    417 forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &,                   void * );
    418 forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &, const             void * );
    419 forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &, const             void * );
    420 forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &,       volatile    void * );
    421 forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &,       volatile    void * );
    422 forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &, const volatile    void * );
    423 forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &, const volatile    void * );
    424 
    425405forall( dtype DT ) void *                ?=?(                void *          &,                 DT * );
    426406forall( dtype DT ) void *                ?=?(                void * volatile &,                 DT * );
     
    441421forall( dtype DT ) const volatile void * ?=?( const volatile void *          &, const volatile  DT * );
    442422forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &, const volatile  DT * );
    443 
    444 void *                  ?=?(                void *          &,                void * );
    445 void *                  ?=?(                void * volatile &,                void * );
    446 const void *            ?=?( const          void *          &,                void * );
    447 const void *            ?=?( const          void * volatile &,                void * );
    448 const void *            ?=?( const          void *          &, const          void * );
    449 const void *            ?=?( const          void * volatile &, const          void * );
    450 volatile void *         ?=?(       volatile void *          &,                void * );
    451 volatile void *         ?=?(       volatile void * volatile &,                void * );
    452 volatile void *         ?=?(       volatile void *          &,       volatile void * );
    453 volatile void *         ?=?(       volatile void * volatile &,       volatile void * );
    454 const volatile void *   ?=?( const volatile void *          &,                void * );
    455 const volatile void *   ?=?( const volatile void * volatile &,                void * );
    456 const volatile void *   ?=?( const volatile void *          &, const          void * );
    457 const volatile void *   ?=?( const volatile void * volatile &, const          void * );
    458 const volatile void *   ?=?( const volatile void *          &,       volatile void * );
    459 const volatile void *   ?=?( const volatile void * volatile &,       volatile void * );
    460 const volatile void *   ?=?( const volatile void *          &, const volatile void * );
    461 const volatile void *   ?=?( const volatile void * volatile &, const volatile void * );
    462423
    463424//forall( dtype DT ) DT *                       ?=?(                DT *          &, zero_t );
     
    781742forall( dtype DT ) void ?{}( const volatile  DT *          &, const volatile    DT * );
    782743
    783 forall( dtype DT ) void ?{}(                 DT *          &,                   void * );
    784 forall( dtype DT ) void ?{}( const           DT *          &,                   void * );
    785 forall( dtype DT ) void ?{}( const           DT *          &, const             void * );
    786 forall( dtype DT ) void ?{}(       volatile  DT *          &,                   void * );
    787 forall( dtype DT ) void ?{}(       volatile  DT *          &,       volatile    void * );
    788 
    789 forall( dtype DT ) void ?{}( const volatile  DT *          &,                   void * );
    790 forall( dtype DT ) void ?{}( const volatile  DT *          &, const             void * );
    791 forall( dtype DT ) void ?{}( const volatile  DT *          &,       volatile    void * );
    792 forall( dtype DT ) void ?{}( const volatile  DT *          &, const volatile    void * );
    793 
    794744forall( dtype DT ) void ?{}(                 void *          &,                 DT * );
    795745forall( dtype DT ) void ?{}( const           void *          &,                 DT * );
     
    802752forall( dtype DT ) void ?{}( const volatile void *           &, const volatile  DT * );
    803753
    804 void    ?{}(                void *          &,                void * );
    805 void    ?{}( const          void *          &,                void * );
    806 void    ?{}( const          void *          &, const          void * );
    807 void    ?{}(       volatile void *          &,                void * );
    808 void    ?{}(       volatile void *          &,       volatile void * );
    809 void    ?{}( const volatile void *          &,                void * );
    810 void    ?{}( const volatile void *          &, const          void * );
    811 void    ?{}( const volatile void *          &,       volatile void * );
    812 void    ?{}( const volatile void *          &, const volatile void * );
    813 
    814754//forall( dtype DT ) void ?{}(              DT *          &, zero_t );
    815755//forall( dtype DT ) void ?{}(              DT * volatile &, zero_t );
  • src/tests/Makefile.am

    r0fe4e62 rcdbfab0  
    141141typedefRedef-ERR1: typedefRedef.c @CFA_BINDIR@/@CFA_NAME@
    142142        ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
     143
     144alloc-ERROR: alloc.c @CFA_BINDIR@/@CFA_NAME@
     145        ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
  • src/tests/Makefile.in

    r0fe4e62 rcdbfab0  
    895895        ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
    896896
     897alloc-ERROR: alloc.c @CFA_BINDIR@/@CFA_NAME@
     898        ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
     899
    897900# Tell versions [3.59,3.63) of GNU make to not export all variables.
    898901# Otherwise a system limit (for SysV at least) may be exceeded.
  • src/tests/alloc.c

    r0fe4e62 rcdbfab0  
    3232        // allocation, non-array types
    3333
    34         p = (void *)malloc( sizeof(*p) );                   // C malloc, type unsafe
     34        p = (int *)(void *)malloc( sizeof(*p) );                   // C malloc, type unsafe
    3535        *p = 0xdeadbeef;
    3636        printf( "C   malloc %#x\n", *p );
     
    5454        printf( "\n" );
    5555
    56         p = calloc( dim, sizeof( *p ) );                    // C array calloc, type unsafe
     56        p = (int *)calloc( dim, sizeof( *p ) );                    // C array calloc, type unsafe
    5757        printf( "C   array calloc, fill 0\n" );
    5858        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     
    8383        printf( "\n" );
    8484
    85         p = (void *)realloc( p, dim * sizeof(*p) );         // C realloc
     85        p = (int *)(void *)realloc( p, dim * sizeof(*p) );         // C realloc
    8686        for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; }
    8787        printf( "C   realloc\n" );
     
    256256        stp = malloc();
    257257        printf( "\nSHOULD FAIL\n" );
     258#ifdef ERR1
    258259        p = alloc( stp, dim * sizeof(*stp) );
    259260        p = memset( stp, 10 );
    260261        p = memcpy( &st1, &st );
     262#endif
    261263} // main
    262264
  • src/tests/dtor-early-exit.c

    r0fe4e62 rcdbfab0  
    2222
    2323struct A {
    24         char * name;
     24        const char * name;
    2525        int * x;
    2626};
  • src/tests/init_once.c

    r0fe4e62 rcdbfab0  
    7272        insert( &constructed, &x );
    7373
    74         x.x = malloc(sizeof(int));
     74        x.x = (int *)malloc(sizeof(int));
    7575}
    7676
  • src/tests/multiDimension.c

    r0fe4e62 rcdbfab0  
    77  printf("default constructing\n");
    88  (this.a){ 123 };
    9   this.ptr = malloc(sizeof(int));
     9  this.ptr = (int *)malloc(sizeof(int));
    1010}
    1111
     
    1313  printf("copy constructing\n");
    1414  (this.a){ other.a };
    15   this.ptr = malloc(sizeof(int));
     15  this.ptr = (int *)malloc(sizeof(int));
    1616}
    1717
     
    1919  printf("constructing with %d\n", a);
    2020  (this.a){ a };
    21   this.ptr = malloc(sizeof(int));
     21  this.ptr = (int *)malloc(sizeof(int));
    2222}
    2323
  • src/tests/tupleVariadic.c

    r0fe4e62 rcdbfab0  
    7373        [a0, a1, a2, a3] = args;
    7474        a.size = 4;
    75         a.data = malloc(sizeof(int)*a.size);
     75        a.data = (int *)malloc(sizeof(int)*a.size);
    7676        a.data[0] = a0;
    7777        a.data[1] = a1;
  • src/tests/vector/vector_int.c

    r0fe4e62 rcdbfab0  
    2727        vec.last = -1;
    2828        vec.capacity = reserve;
    29         vec.data = malloc( sizeof( int ) * reserve );
     29        vec.data = (int *)malloc( sizeof( int ) * reserve );
    3030}
    3131
     
    3333        vec.last = other.last;
    3434        vec.capacity = other.capacity;
    35         vec.data = malloc( sizeof( int ) * other.capacity );
     35        vec.data = (int *)malloc( sizeof( int ) * other.capacity );
    3636        for (int i = 0; i < vec.last; i++) {
    3737                vec.data[i] = other.data[i];
     
    4545void reserve( vector_int *vec, int reserve ) {
    4646        if ( reserve > vec->capacity ) {
    47                 vec->data = realloc( vec->data, sizeof( int ) * reserve );
     47                vec->data = (int *)realloc( vec->data, sizeof( int ) * reserve );
    4848                vec->capacity = reserve;
    4949        }
     
    5454        if ( vec->last == vec->capacity ) {
    5555                vec->capacity *= 2;
    56                 vec->data = realloc( vec->data, sizeof( int ) * vec->capacity );
     56                vec->data = (int *)realloc( vec->data, sizeof( int ) * vec->capacity );
    5757        }
    5858        vec->data[ vec->last ] = element;
Note: See TracChangeset for help on using the changeset viewer.