LCOV - code coverage report
Current view: top level - Modules/_ctypes - _ctypes_test.c (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 2 308 0.6 %
Date: 2023-03-20 08:15:36 Functions: 1 92 1.1 %
Branches: 0 61 0.0 %

           Branch data     Line data    Source code
       1                 :            : #include <Python.h>
       2                 :            : 
       3                 :            : #ifdef MS_WIN32
       4                 :            : #include <windows.h>
       5                 :            : #endif
       6                 :            : 
       7                 :            : #include <stdlib.h>               // qsort()
       8                 :            : 
       9                 :            : #define EXPORT(x) Py_EXPORTED_SYMBOL x
      10                 :            : 
      11                 :            : /* some functions handy for testing */
      12                 :            : 
      13                 :            : EXPORT(int)
      14                 :          0 : _testfunc_cbk_reg_int(int a, int b, int c, int d, int e,
      15                 :            :                       int (*func)(int, int, int, int, int))
      16                 :            : {
      17                 :          0 :     return func(a*a, b*b, c*c, d*d, e*e);
      18                 :            : }
      19                 :            : 
      20                 :            : EXPORT(double)
      21                 :          0 : _testfunc_cbk_reg_double(double a, double b, double c, double d, double e,
      22                 :            :                          double (*func)(double, double, double, double, double))
      23                 :            : {
      24                 :          0 :     return func(a*a, b*b, c*c, d*d, e*e);
      25                 :            : }
      26                 :            : 
      27                 :            : /*
      28                 :            :  * This structure should be the same as in test_callbacks.py and the
      29                 :            :  * method test_callback_large_struct. See issues 17310 and 20160: the
      30                 :            :  * structure must be larger than 8 bytes long.
      31                 :            :  */
      32                 :            : 
      33                 :            : typedef struct {
      34                 :            :     unsigned long first;
      35                 :            :     unsigned long second;
      36                 :            :     unsigned long third;
      37                 :            : } Test;
      38                 :            : 
      39                 :            : EXPORT(void)
      40                 :          0 : _testfunc_cbk_large_struct(Test in, void (*func)(Test))
      41                 :            : {
      42                 :          0 :     func(in);
      43                 :          0 : }
      44                 :            : 
      45                 :            : /*
      46                 :            :  * See issue 29565. Update a structure passed by value;
      47                 :            :  * the caller should not see any change.
      48                 :            :  */
      49                 :            : 
      50                 :            : EXPORT(void)
      51                 :          0 : _testfunc_large_struct_update_value(Test in)
      52                 :            : {
      53                 :          0 :     ((volatile Test *)&in)->first = 0x0badf00d;
      54                 :          0 :     ((volatile Test *)&in)->second = 0x0badf00d;
      55                 :          0 :     ((volatile Test *)&in)->third = 0x0badf00d;
      56                 :          0 : }
      57                 :            : 
      58                 :            : typedef struct {
      59                 :            :     unsigned int first;
      60                 :            :     unsigned int second;
      61                 :            : } TestReg;
      62                 :            : 
      63                 :            : 
      64                 :            : EXPORT(TestReg) last_tfrsuv_arg = {0};
      65                 :            : 
      66                 :            : 
      67                 :            : EXPORT(void)
      68                 :          0 : _testfunc_reg_struct_update_value(TestReg in)
      69                 :            : {
      70                 :          0 :     last_tfrsuv_arg = in;
      71                 :          0 :     ((volatile TestReg *)&in)->first = 0x0badf00d;
      72                 :          0 :     ((volatile TestReg *)&in)->second = 0x0badf00d;
      73                 :          0 : }
      74                 :            : 
      75                 :            : /*
      76                 :            :  * See bpo-22273. Structs containing arrays should work on Linux 64-bit.
      77                 :            :  */
      78                 :            : 
      79                 :            : typedef struct {
      80                 :            :     unsigned char data[16];
      81                 :            : } Test2;
      82                 :            : 
      83                 :            : EXPORT(int)
      84                 :          0 : _testfunc_array_in_struct1(Test2 in)
      85                 :            : {
      86                 :          0 :     int result = 0;
      87                 :            : 
      88         [ #  # ]:          0 :     for (unsigned i = 0; i < 16; i++)
      89                 :          0 :         result += in.data[i];
      90                 :            :     /* As the structure is passed by value, changes to it shouldn't be
      91                 :            :      * reflected in the caller.
      92                 :            :      */
      93                 :          0 :     memset(in.data, 0, sizeof(in.data));
      94                 :          0 :     return result;
      95                 :            : }
      96                 :            : 
      97                 :            : typedef struct {
      98                 :            :     double data[2];
      99                 :            : } Test3;
     100                 :            : 
     101                 :            : typedef struct {
     102                 :            :     float data[2];
     103                 :            :     float more_data[2];
     104                 :            : } Test3B;
     105                 :            : 
     106                 :            : EXPORT(double)
     107                 :          0 : _testfunc_array_in_struct2(Test3 in)
     108                 :            : {
     109                 :          0 :     double result = 0;
     110                 :            : 
     111         [ #  # ]:          0 :     for (unsigned i = 0; i < 2; i++)
     112                 :          0 :         result += in.data[i];
     113                 :            :     /* As the structure is passed by value, changes to it shouldn't be
     114                 :            :      * reflected in the caller.
     115                 :            :      */
     116                 :          0 :     memset(in.data, 0, sizeof(in.data));
     117                 :          0 :     return result;
     118                 :            : }
     119                 :            : 
     120                 :            : EXPORT(double)
     121                 :          0 : _testfunc_array_in_struct2a(Test3B in)
     122                 :            : {
     123                 :          0 :     double result = 0;
     124                 :            : 
     125         [ #  # ]:          0 :     for (unsigned i = 0; i < 2; i++)
     126                 :          0 :         result += in.data[i];
     127         [ #  # ]:          0 :     for (unsigned i = 0; i < 2; i++)
     128                 :          0 :         result += in.more_data[i];
     129                 :            :     /* As the structure is passed by value, changes to it shouldn't be
     130                 :            :      * reflected in the caller.
     131                 :            :      */
     132                 :          0 :     memset(in.data, 0, sizeof(in.data));
     133                 :          0 :     return result;
     134                 :            : }
     135                 :            : 
     136                 :            : typedef union {
     137                 :            :     long a_long;
     138                 :            :     struct {
     139                 :            :         int an_int;
     140                 :            :         int another_int;
     141                 :            :     } a_struct;
     142                 :            : } Test4;
     143                 :            : 
     144                 :            : typedef struct {
     145                 :            :     int an_int;
     146                 :            :     struct {
     147                 :            :         int an_int;
     148                 :            :         Test4 a_union;
     149                 :            :     } nested;
     150                 :            :     int another_int;
     151                 :            : } Test5;
     152                 :            : 
     153                 :            : EXPORT(long)
     154                 :          0 : _testfunc_union_by_value1(Test4 in) {
     155                 :          0 :     long result = in.a_long + in.a_struct.an_int + in.a_struct.another_int;
     156                 :            : 
     157                 :            :     /* As the union/struct are passed by value, changes to them shouldn't be
     158                 :            :      * reflected in the caller.
     159                 :            :      */
     160                 :          0 :     memset(&in, 0, sizeof(in));
     161                 :          0 :     return result;
     162                 :            : }
     163                 :            : 
     164                 :            : EXPORT(long)
     165                 :          0 : _testfunc_union_by_value2(Test5 in) {
     166                 :          0 :     long result = in.an_int + in.nested.an_int;
     167                 :            : 
     168                 :            :     /* As the union/struct are passed by value, changes to them shouldn't be
     169                 :            :      * reflected in the caller.
     170                 :            :      */
     171                 :          0 :     memset(&in, 0, sizeof(in));
     172                 :          0 :     return result;
     173                 :            : }
     174                 :            : 
     175                 :            : EXPORT(long)
     176                 :          0 : _testfunc_union_by_reference1(Test4 *in) {
     177                 :          0 :     long result = in->a_long;
     178                 :            : 
     179                 :          0 :     memset(in, 0, sizeof(Test4));
     180                 :          0 :     return result;
     181                 :            : }
     182                 :            : 
     183                 :            : EXPORT(long)
     184                 :          0 : _testfunc_union_by_reference2(Test4 *in) {
     185                 :          0 :     long result = in->a_struct.an_int + in->a_struct.another_int;
     186                 :            : 
     187                 :          0 :     memset(in, 0, sizeof(Test4));
     188                 :          0 :     return result;
     189                 :            : }
     190                 :            : 
     191                 :            : EXPORT(long)
     192                 :          0 : _testfunc_union_by_reference3(Test5 *in) {
     193                 :          0 :     long result = in->an_int + in->nested.an_int + in->another_int;
     194                 :            : 
     195                 :          0 :     memset(in, 0, sizeof(Test5));
     196                 :          0 :     return result;
     197                 :            : }
     198                 :            : 
     199                 :            : typedef struct {
     200                 :            :     signed int A: 1, B:2, C:3, D:2;
     201                 :            : } Test6;
     202                 :            : 
     203                 :            : EXPORT(long)
     204                 :          0 : _testfunc_bitfield_by_value1(Test6 in) {
     205                 :          0 :     long result = in.A + in.B + in.C + in.D;
     206                 :            : 
     207                 :            :     /* As the struct is passed by value, changes to it shouldn't be
     208                 :            :      * reflected in the caller.
     209                 :            :      */
     210                 :          0 :     memset(&in, 0, sizeof(in));
     211                 :          0 :     return result;
     212                 :            : }
     213                 :            : 
     214                 :            : EXPORT(long)
     215                 :          0 : _testfunc_bitfield_by_reference1(Test6 *in) {
     216                 :          0 :     long result = in->A + in->B + in->C + in->D;
     217                 :            : 
     218                 :          0 :     memset(in, 0, sizeof(Test6));
     219                 :          0 :     return result;
     220                 :            : }
     221                 :            : 
     222                 :            : typedef struct {
     223                 :            :     unsigned int A: 1, B:2, C:3, D:2;
     224                 :            : } Test7;
     225                 :            : 
     226                 :            : EXPORT(long)
     227                 :          0 : _testfunc_bitfield_by_reference2(Test7 *in) {
     228                 :          0 :     long result = in->A + in->B + in->C + in->D;
     229                 :            : 
     230                 :          0 :     memset(in, 0, sizeof(Test7));
     231                 :          0 :     return result;
     232                 :            : }
     233                 :            : 
     234                 :            : typedef union {
     235                 :            :     signed int A: 1, B:2, C:3, D:2;
     236                 :            : } Test8;
     237                 :            : 
     238                 :            : EXPORT(long)
     239                 :          0 : _testfunc_bitfield_by_value2(Test8 in) {
     240                 :          0 :     long result = in.A + in.B + in.C + in.D;
     241                 :            : 
     242                 :            :     /* As the struct is passed by value, changes to it shouldn't be
     243                 :            :      * reflected in the caller.
     244                 :            :      */
     245                 :          0 :     memset(&in, 0, sizeof(in));
     246                 :          0 :     return result;
     247                 :            : }
     248                 :            : 
     249                 :          0 : EXPORT(void)testfunc_array(int values[4])
     250                 :            : {
     251                 :          0 :     printf("testfunc_array %d %d %d %d\n",
     252                 :            :            values[0],
     253                 :          0 :            values[1],
     254                 :          0 :            values[2],
     255                 :          0 :            values[3]);
     256                 :          0 : }
     257                 :            : 
     258                 :          0 : EXPORT(long double)testfunc_Ddd(double a, double b)
     259                 :            : {
     260                 :          0 :     long double result = (long double)(a * b);
     261                 :          0 :     printf("testfunc_Ddd(%p, %p)\n", (void *)&a, (void *)&b);
     262                 :          0 :     printf("testfunc_Ddd(%g, %g)\n", a, b);
     263                 :          0 :     return result;
     264                 :            : }
     265                 :            : 
     266                 :          0 : EXPORT(long double)testfunc_DDD(long double a, long double b)
     267                 :            : {
     268                 :          0 :     long double result = a * b;
     269                 :          0 :     printf("testfunc_DDD(%p, %p)\n", (void *)&a, (void *)&b);
     270                 :          0 :     printf("testfunc_DDD(%Lg, %Lg)\n", a, b);
     271                 :          0 :     return result;
     272                 :            : }
     273                 :            : 
     274                 :          0 : EXPORT(int)testfunc_iii(int a, int b)
     275                 :            : {
     276                 :          0 :     int result = a * b;
     277                 :          0 :     printf("testfunc_iii(%p, %p)\n", (void *)&a, (void *)&b);
     278                 :          0 :     return result;
     279                 :            : }
     280                 :            : 
     281                 :          0 : EXPORT(int)myprintf(char *fmt, ...)
     282                 :            : {
     283                 :            :     int result;
     284                 :            :     va_list argptr;
     285                 :          0 :     va_start(argptr, fmt);
     286                 :          0 :     result = vprintf(fmt, argptr);
     287                 :          0 :     va_end(argptr);
     288                 :          0 :     return result;
     289                 :            : }
     290                 :            : 
     291                 :          0 : EXPORT(char *)my_strtok(char *token, const char *delim)
     292                 :            : {
     293                 :          0 :     return strtok(token, delim);
     294                 :            : }
     295                 :            : 
     296                 :          0 : EXPORT(char *)my_strchr(const char *s, int c)
     297                 :            : {
     298                 :          0 :     return strchr(s, c);
     299                 :            : }
     300                 :            : 
     301                 :            : 
     302                 :          0 : EXPORT(double) my_sqrt(double a)
     303                 :            : {
     304                 :          0 :     return sqrt(a);
     305                 :            : }
     306                 :            : 
     307                 :          0 : EXPORT(void) my_qsort(void *base, size_t num, size_t width, int(*compare)(const void*, const void*))
     308                 :            : {
     309                 :          0 :     qsort(base, num, width, compare);
     310                 :          0 : }
     311                 :            : 
     312                 :          0 : EXPORT(int *) _testfunc_ai8(int a[8])
     313                 :            : {
     314                 :          0 :     return a;
     315                 :            : }
     316                 :            : 
     317                 :          0 : EXPORT(void) _testfunc_v(int a, int b, int *presult)
     318                 :            : {
     319                 :          0 :     *presult = a + b;
     320                 :          0 : }
     321                 :            : 
     322                 :          0 : EXPORT(int) _testfunc_i_bhilfd(signed char b, short h, int i, long l, float f, double d)
     323                 :            : {
     324                 :            : /*      printf("_testfunc_i_bhilfd got %d %d %d %ld %f %f\n",
     325                 :            :                b, h, i, l, f, d);
     326                 :            : */
     327                 :          0 :     return (int)(b + h + i + l + f + d);
     328                 :            : }
     329                 :            : 
     330                 :          0 : EXPORT(float) _testfunc_f_bhilfd(signed char b, short h, int i, long l, float f, double d)
     331                 :            : {
     332                 :            : /*      printf("_testfunc_f_bhilfd got %d %d %d %ld %f %f\n",
     333                 :            :                b, h, i, l, f, d);
     334                 :            : */
     335                 :          0 :     return (float)(b + h + i + l + f + d);
     336                 :            : }
     337                 :            : 
     338                 :          0 : EXPORT(double) _testfunc_d_bhilfd(signed char b, short h, int i, long l, float f, double d)
     339                 :            : {
     340                 :            : /*      printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n",
     341                 :            :                b, h, i, l, f, d);
     342                 :            : */
     343                 :          0 :     return (double)(b + h + i + l + f + d);
     344                 :            : }
     345                 :            : 
     346                 :          0 : EXPORT(long double) _testfunc_D_bhilfD(signed char b, short h, int i, long l, float f, long double d)
     347                 :            : {
     348                 :            : /*      printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n",
     349                 :            :                b, h, i, l, f, d);
     350                 :            : */
     351                 :          0 :     return (long double)(b + h + i + l + f + d);
     352                 :            : }
     353                 :            : 
     354                 :          0 : EXPORT(char *) _testfunc_p_p(void *s)
     355                 :            : {
     356                 :          0 :     return (char *)s;
     357                 :            : }
     358                 :            : 
     359                 :          0 : EXPORT(void *) _testfunc_c_p_p(int *argcp, char **argv)
     360                 :            : {
     361                 :          0 :     return argv[(*argcp)-1];
     362                 :            : }
     363                 :            : 
     364                 :          0 : EXPORT(void *) get_strchr(void)
     365                 :            : {
     366                 :          0 :     return (void *)strchr;
     367                 :            : }
     368                 :            : 
     369                 :          0 : EXPORT(char *) my_strdup(char *src)
     370                 :            : {
     371                 :          0 :     char *dst = (char *)malloc(strlen(src)+1);
     372         [ #  # ]:          0 :     if (!dst)
     373                 :          0 :         return NULL;
     374                 :          0 :     strcpy(dst, src);
     375                 :          0 :     return dst;
     376                 :            : }
     377                 :            : 
     378                 :          0 : EXPORT(void)my_free(void *ptr)
     379                 :            : {
     380                 :          0 :     free(ptr);
     381                 :          0 : }
     382                 :            : 
     383                 :            : #ifdef HAVE_WCHAR_H
     384                 :          0 : EXPORT(wchar_t *) my_wcsdup(wchar_t *src)
     385                 :            : {
     386                 :          0 :     size_t len = wcslen(src);
     387                 :          0 :     wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
     388         [ #  # ]:          0 :     if (ptr == NULL)
     389                 :          0 :         return NULL;
     390                 :          0 :     memcpy(ptr, src, (len+1) * sizeof(wchar_t));
     391                 :          0 :     return ptr;
     392                 :            : }
     393                 :            : 
     394                 :          0 : EXPORT(size_t) my_wcslen(wchar_t *src)
     395                 :            : {
     396                 :          0 :     return wcslen(src);
     397                 :            : }
     398                 :            : #endif
     399                 :            : 
     400                 :            : #ifndef MS_WIN32
     401                 :            : # ifndef __stdcall
     402                 :            : #  define __stdcall /* */
     403                 :            : # endif
     404                 :            : #endif
     405                 :            : 
     406                 :            : typedef struct {
     407                 :            :     int (*c)(int, int);
     408                 :            :     int (__stdcall *s)(int, int);
     409                 :            : } FUNCS;
     410                 :            : 
     411                 :          0 : EXPORT(int) _testfunc_callfuncp(FUNCS *fp)
     412                 :            : {
     413                 :          0 :     fp->c(1, 2);
     414                 :          0 :     fp->s(3, 4);
     415                 :          0 :     return 0;
     416                 :            : }
     417                 :            : 
     418                 :          0 : EXPORT(int) _testfunc_deref_pointer(int *pi)
     419                 :            : {
     420                 :          0 :     return *pi;
     421                 :            : }
     422                 :            : 
     423                 :            : #ifdef MS_WIN32
     424                 :            : EXPORT(int) _testfunc_piunk(IUnknown FAR *piunk)
     425                 :            : {
     426                 :            :     piunk->lpVtbl->AddRef(piunk);
     427                 :            :     return piunk->lpVtbl->Release(piunk);
     428                 :            : }
     429                 :            : #endif
     430                 :            : 
     431                 :          0 : EXPORT(int) _testfunc_callback_with_pointer(int (*func)(int *))
     432                 :            : {
     433                 :          0 :     int table[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
     434                 :            : 
     435                 :          0 :     return (*func)(table);
     436                 :            : }
     437                 :            : 
     438                 :          0 : EXPORT(long long) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f,
     439                 :            :                                       double d, long long q)
     440                 :            : {
     441                 :          0 :     return (long long)(b + h + i + l + f + d + q);
     442                 :            : }
     443                 :            : 
     444                 :          0 : EXPORT(long long) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d)
     445                 :            : {
     446                 :          0 :     return (long long)(b + h + i + l + f + d);
     447                 :            : }
     448                 :            : 
     449                 :          0 : EXPORT(int) _testfunc_callback_i_if(int value, int (*func)(int))
     450                 :            : {
     451                 :          0 :     int sum = 0;
     452         [ #  # ]:          0 :     while (value != 0) {
     453                 :          0 :         sum += func(value);
     454                 :          0 :         value /= 2;
     455                 :            :     }
     456                 :          0 :     return sum;
     457                 :            : }
     458                 :            : 
     459                 :          0 : EXPORT(long long) _testfunc_callback_q_qf(long long value,
     460                 :            :                                           long long (*func)(long long))
     461                 :            : {
     462                 :          0 :     long long sum = 0;
     463                 :            : 
     464         [ #  # ]:          0 :     while (value != 0) {
     465                 :          0 :         sum += func(value);
     466                 :          0 :         value /= 2;
     467                 :            :     }
     468                 :          0 :     return sum;
     469                 :            : }
     470                 :            : 
     471                 :            : typedef struct {
     472                 :            :     char *name;
     473                 :            :     char *value;
     474                 :            : } SPAM;
     475                 :            : 
     476                 :            : typedef struct {
     477                 :            :     char *name;
     478                 :            :     int num_spams;
     479                 :            :     SPAM *spams;
     480                 :            : } EGG;
     481                 :            : 
     482                 :            : SPAM my_spams[2] = {
     483                 :            :     { "name1", "value1" },
     484                 :            :     { "name2", "value2" },
     485                 :            : };
     486                 :            : 
     487                 :            : EGG my_eggs[1] = {
     488                 :            :     { "first egg", 1, my_spams }
     489                 :            : };
     490                 :            : 
     491                 :          0 : EXPORT(int) getSPAMANDEGGS(EGG **eggs)
     492                 :            : {
     493                 :          0 :     *eggs = my_eggs;
     494                 :          0 :     return 1;
     495                 :            : }
     496                 :            : 
     497                 :            : typedef struct tagpoint {
     498                 :            :     int x;
     499                 :            :     int y;
     500                 :            : } point;
     501                 :            : 
     502                 :          0 : EXPORT(int) _testfunc_byval(point in, point *pout)
     503                 :            : {
     504         [ #  # ]:          0 :     if (pout) {
     505                 :          0 :         pout->x = in.x;
     506                 :          0 :         pout->y = in.y;
     507                 :            :     }
     508                 :          0 :     return in.x + in.y;
     509                 :            : }
     510                 :            : 
     511                 :            : EXPORT (int) an_integer = 42;
     512                 :            : 
     513                 :          0 : EXPORT(int) get_an_integer(void)
     514                 :            : {
     515                 :          0 :     return an_integer;
     516                 :            : }
     517                 :            : 
     518                 :            : EXPORT(double)
     519                 :          0 : integrate(double a, double b, double (*f)(double), long nstep)
     520                 :            : {
     521                 :          0 :     double x, sum=0.0, dx=(b-a)/(double)nstep;
     522         [ #  # ]:          0 :     for(x=a+0.5*dx; (b-x)*(x-a)>0.0; x+=dx)
     523                 :          0 :         sum += f(x);
     524                 :          0 :     return sum/(double)nstep;
     525                 :            : }
     526                 :            : 
     527                 :            : typedef struct {
     528                 :            :     void (*initialize)(void *(*)(int), void(*)(void *));
     529                 :            : } xxx_library;
     530                 :            : 
     531                 :          0 : static void _xxx_init(void *(*Xalloc)(int), void (*Xfree)(void *))
     532                 :            : {
     533                 :            :     void *ptr;
     534                 :            : 
     535                 :          0 :     printf("_xxx_init got %p %p\n", (void *)Xalloc, (void *)Xfree);
     536                 :          0 :     printf("calling\n");
     537                 :          0 :     ptr = Xalloc(32);
     538                 :          0 :     Xfree(ptr);
     539                 :          0 :     printf("calls done, ptr was %p\n", ptr);
     540                 :          0 : }
     541                 :            : 
     542                 :            : xxx_library _xxx_lib = {
     543                 :            :     _xxx_init
     544                 :            : };
     545                 :            : 
     546                 :          0 : EXPORT(xxx_library) *library_get(void)
     547                 :            : {
     548                 :          0 :     return &_xxx_lib;
     549                 :            : }
     550                 :            : 
     551                 :            : #ifdef MS_WIN32
     552                 :            : /* See Don Box (german), pp 79ff. */
     553                 :            : EXPORT(void) GetString(BSTR *pbstr)
     554                 :            : {
     555                 :            :     *pbstr = SysAllocString(L"Goodbye!");
     556                 :            : }
     557                 :            : #endif
     558                 :            : 
     559                 :            : /*
     560                 :            :  * Some do-nothing functions, for speed tests
     561                 :            :  */
     562                 :          0 : PyObject *py_func_si(PyObject *self, PyObject *args)
     563                 :            : {
     564                 :            :     char *name;
     565                 :            :     int i;
     566         [ #  # ]:          0 :     if (!PyArg_ParseTuple(args, "si", &name, &i))
     567                 :          0 :         return NULL;
     568                 :          0 :     Py_RETURN_NONE;
     569                 :            : }
     570                 :            : 
     571                 :          0 : EXPORT(void) _py_func_si(char *s, int i)
     572                 :            : {
     573                 :          0 : }
     574                 :            : 
     575                 :          0 : PyObject *py_func(PyObject *self, PyObject *args)
     576                 :            : {
     577                 :          0 :     Py_RETURN_NONE;
     578                 :            : }
     579                 :            : 
     580                 :          0 : EXPORT(void) _py_func(void)
     581                 :            : {
     582                 :          0 : }
     583                 :            : 
     584                 :            : EXPORT(long long) last_tf_arg_s = 0;
     585                 :            : EXPORT(unsigned long long) last_tf_arg_u = 0;
     586                 :            : 
     587                 :            : struct BITS {
     588                 :            :     signed int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9;
     589                 :            : /*
     590                 :            :  * The test case needs/uses "signed short" bitfields, but the
     591                 :            :  * IBM XLC compiler does not support this
     592                 :            :  */
     593                 :            : #ifndef __xlc__
     594                 :            : #define SIGNED_SHORT_BITFIELDS
     595                 :            :      short M: 1, N: 2, O: 3, P: 4, Q: 5, R: 6, S: 7;
     596                 :            : #endif
     597                 :            : };
     598                 :            : 
     599                 :          0 : EXPORT(int) unpack_bitfields(struct BITS *bits, char name)
     600                 :            : {
     601   [ #  #  #  #  :          0 :     switch (name) {
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     602                 :          0 :     case 'A': return bits->A;
     603                 :          0 :     case 'B': return bits->B;
     604                 :          0 :     case 'C': return bits->C;
     605                 :          0 :     case 'D': return bits->D;
     606                 :          0 :     case 'E': return bits->E;
     607                 :          0 :     case 'F': return bits->F;
     608                 :          0 :     case 'G': return bits->G;
     609                 :          0 :     case 'H': return bits->H;
     610                 :          0 :     case 'I': return bits->I;
     611                 :            : 
     612                 :            : #ifdef SIGNED_SHORT_BITFIELDS
     613                 :          0 :     case 'M': return bits->M;
     614                 :          0 :     case 'N': return bits->N;
     615                 :          0 :     case 'O': return bits->O;
     616                 :          0 :     case 'P': return bits->P;
     617                 :          0 :     case 'Q': return bits->Q;
     618                 :          0 :     case 'R': return bits->R;
     619                 :          0 :     case 'S': return bits->S;
     620                 :            : #endif
     621                 :            :     }
     622                 :          0 :     return 999;
     623                 :            : }
     624                 :            : 
     625                 :            : static PyMethodDef module_methods[] = {
     626                 :            : /*      {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS},
     627                 :            :     {"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS},
     628                 :            : */
     629                 :            :     {"func_si", py_func_si, METH_VARARGS},
     630                 :            :     {"func", py_func, METH_NOARGS},
     631                 :            :     { NULL, NULL, 0, NULL},
     632                 :            : };
     633                 :            : 
     634                 :            : #define S last_tf_arg_s = (long long)c
     635                 :            : #define U last_tf_arg_u = (unsigned long long)c
     636                 :            : 
     637                 :          0 : EXPORT(signed char) tf_b(signed char c) { S; return c/3; }
     638                 :          0 : EXPORT(unsigned char) tf_B(unsigned char c) { U; return c/3; }
     639                 :          0 : EXPORT(short) tf_h(short c) { S; return c/3; }
     640                 :          0 : EXPORT(unsigned short) tf_H(unsigned short c) { U; return c/3; }
     641                 :          0 : EXPORT(int) tf_i(int c) { S; return c/3; }
     642                 :          0 : EXPORT(unsigned int) tf_I(unsigned int c) { U; return c/3; }
     643                 :          0 : EXPORT(long) tf_l(long c) { S; return c/3; }
     644                 :          0 : EXPORT(unsigned long) tf_L(unsigned long c) { U; return c/3; }
     645                 :          0 : EXPORT(long long) tf_q(long long c) { S; return c/3; }
     646                 :          0 : EXPORT(unsigned long long) tf_Q(unsigned long long c) { U; return c/3; }
     647                 :          0 : EXPORT(float) tf_f(float c) { S; return c/3; }
     648                 :          0 : EXPORT(double) tf_d(double c) { S; return c/3; }
     649                 :          0 : EXPORT(long double) tf_D(long double c) { S; return c/3; }
     650                 :            : 
     651                 :            : #ifdef MS_WIN32
     652                 :            : EXPORT(signed char) __stdcall s_tf_b(signed char c) { S; return c/3; }
     653                 :            : EXPORT(unsigned char) __stdcall s_tf_B(unsigned char c) { U; return c/3; }
     654                 :            : EXPORT(short) __stdcall s_tf_h(short c) { S; return c/3; }
     655                 :            : EXPORT(unsigned short) __stdcall s_tf_H(unsigned short c) { U; return c/3; }
     656                 :            : EXPORT(int) __stdcall s_tf_i(int c) { S; return c/3; }
     657                 :            : EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { U; return c/3; }
     658                 :            : EXPORT(long) __stdcall s_tf_l(long c) { S; return c/3; }
     659                 :            : EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { U; return c/3; }
     660                 :            : EXPORT(long long) __stdcall s_tf_q(long long c) { S; return c/3; }
     661                 :            : EXPORT(unsigned long long) __stdcall s_tf_Q(unsigned long long c) { U; return c/3; }
     662                 :            : EXPORT(float) __stdcall s_tf_f(float c) { S; return c/3; }
     663                 :            : EXPORT(double) __stdcall s_tf_d(double c) { S; return c/3; }
     664                 :            : EXPORT(long double) __stdcall s_tf_D(long double c) { S; return c/3; }
     665                 :            : #endif
     666                 :            : /*******/
     667                 :            : 
     668                 :          0 : EXPORT(signed char) tf_bb(signed char x, signed char c) { S; return c/3; }
     669                 :          0 : EXPORT(unsigned char) tf_bB(signed char x, unsigned char c) { U; return c/3; }
     670                 :          0 : EXPORT(short) tf_bh(signed char x, short c) { S; return c/3; }
     671                 :          0 : EXPORT(unsigned short) tf_bH(signed char x, unsigned short c) { U; return c/3; }
     672                 :          0 : EXPORT(int) tf_bi(signed char x, int c) { S; return c/3; }
     673                 :          0 : EXPORT(unsigned int) tf_bI(signed char x, unsigned int c) { U; return c/3; }
     674                 :          0 : EXPORT(long) tf_bl(signed char x, long c) { S; return c/3; }
     675                 :          0 : EXPORT(unsigned long) tf_bL(signed char x, unsigned long c) { U; return c/3; }
     676                 :          0 : EXPORT(long long) tf_bq(signed char x, long long c) { S; return c/3; }
     677                 :          0 : EXPORT(unsigned long long) tf_bQ(signed char x, unsigned long long c) { U; return c/3; }
     678                 :          0 : EXPORT(float) tf_bf(signed char x, float c) { S; return c/3; }
     679                 :          0 : EXPORT(double) tf_bd(signed char x, double c) { S; return c/3; }
     680                 :          0 : EXPORT(long double) tf_bD(signed char x, long double c) { S; return c/3; }
     681                 :          0 : EXPORT(void) tv_i(int c) { S; return; }
     682                 :            : 
     683                 :            : #ifdef MS_WIN32
     684                 :            : EXPORT(signed char) __stdcall s_tf_bb(signed char x, signed char c) { S; return c/3; }
     685                 :            : EXPORT(unsigned char) __stdcall s_tf_bB(signed char x, unsigned char c) { U; return c/3; }
     686                 :            : EXPORT(short) __stdcall s_tf_bh(signed char x, short c) { S; return c/3; }
     687                 :            : EXPORT(unsigned short) __stdcall s_tf_bH(signed char x, unsigned short c) { U; return c/3; }
     688                 :            : EXPORT(int) __stdcall s_tf_bi(signed char x, int c) { S; return c/3; }
     689                 :            : EXPORT(unsigned int) __stdcall s_tf_bI(signed char x, unsigned int c) { U; return c/3; }
     690                 :            : EXPORT(long) __stdcall s_tf_bl(signed char x, long c) { S; return c/3; }
     691                 :            : EXPORT(unsigned long) __stdcall s_tf_bL(signed char x, unsigned long c) { U; return c/3; }
     692                 :            : EXPORT(long long) __stdcall s_tf_bq(signed char x, long long c) { S; return c/3; }
     693                 :            : EXPORT(unsigned long long) __stdcall s_tf_bQ(signed char x, unsigned long long c) { U; return c/3; }
     694                 :            : EXPORT(float) __stdcall s_tf_bf(signed char x, float c) { S; return c/3; }
     695                 :            : EXPORT(double) __stdcall s_tf_bd(signed char x, double c) { S; return c/3; }
     696                 :            : EXPORT(long double) __stdcall s_tf_bD(signed char x, long double c) { S; return c/3; }
     697                 :            : EXPORT(void) __stdcall s_tv_i(int c) { S; return; }
     698                 :            : #endif
     699                 :            : 
     700                 :            : /********/
     701                 :            : 
     702                 :            : #ifndef MS_WIN32
     703                 :            : 
     704                 :            : typedef struct {
     705                 :            :     long x;
     706                 :            :     long y;
     707                 :            : } POINT;
     708                 :            : 
     709                 :            : typedef struct {
     710                 :            :     long left;
     711                 :            :     long top;
     712                 :            :     long right;
     713                 :            :     long bottom;
     714                 :            : } RECT;
     715                 :            : 
     716                 :            : #endif
     717                 :            : 
     718                 :          0 : EXPORT(int) PointInRect(RECT *prc, POINT pt)
     719                 :            : {
     720         [ #  # ]:          0 :     if (pt.x < prc->left)
     721                 :          0 :         return 0;
     722         [ #  # ]:          0 :     if (pt.x > prc->right)
     723                 :          0 :         return 0;
     724         [ #  # ]:          0 :     if (pt.y < prc->top)
     725                 :          0 :         return 0;
     726         [ #  # ]:          0 :     if (pt.y > prc->bottom)
     727                 :          0 :         return 0;
     728                 :          0 :     return 1;
     729                 :            : }
     730                 :            : 
     731                 :            : EXPORT(long left = 10);
     732                 :            : EXPORT(long top = 20);
     733                 :            : EXPORT(long right = 30);
     734                 :            : EXPORT(long bottom = 40);
     735                 :            : 
     736                 :          0 : EXPORT(RECT) ReturnRect(int i, RECT ar, RECT* br, POINT cp, RECT dr,
     737                 :            :                         RECT *er, POINT fp, RECT gr)
     738                 :            : {
     739                 :            :     /*Check input */
     740         [ #  # ]:          0 :     if (ar.left + br->left + dr.left + er->left + gr.left != left * 5)
     741                 :            :     {
     742                 :          0 :         ar.left = 100;
     743                 :          0 :         return ar;
     744                 :            :     }
     745         [ #  # ]:          0 :     if (ar.right + br->right + dr.right + er->right + gr.right != right * 5)
     746                 :            :     {
     747                 :          0 :         ar.right = 100;
     748                 :          0 :         return ar;
     749                 :            :     }
     750         [ #  # ]:          0 :     if (cp.x != fp.x)
     751                 :            :     {
     752                 :          0 :         ar.left = -100;
     753                 :            :     }
     754         [ #  # ]:          0 :     if (cp.y != fp.y)
     755                 :            :     {
     756                 :          0 :         ar.left = -200;
     757                 :            :     }
     758   [ #  #  #  # ]:          0 :     switch(i)
     759                 :            :     {
     760                 :          0 :     case 0:
     761                 :          0 :         return ar;
     762                 :            :         break;
     763                 :          0 :     case 1:
     764                 :          0 :         return dr;
     765                 :            :         break;
     766                 :          0 :     case 2:
     767                 :          0 :         return gr;
     768                 :            :         break;
     769                 :            : 
     770                 :            :     }
     771                 :          0 :     return ar;
     772                 :            : }
     773                 :            : 
     774                 :            : typedef struct {
     775                 :            :     short x;
     776                 :            :     short y;
     777                 :            : } S2H;
     778                 :            : 
     779                 :          0 : EXPORT(S2H) ret_2h_func(S2H inp)
     780                 :            : {
     781                 :          0 :     inp.x *= 2;
     782                 :          0 :     inp.y *= 3;
     783                 :          0 :     return inp;
     784                 :            : }
     785                 :            : 
     786                 :            : typedef struct {
     787                 :            :     int a, b, c, d, e, f, g, h;
     788                 :            : } S8I;
     789                 :            : 
     790                 :          0 : EXPORT(S8I) ret_8i_func(S8I inp)
     791                 :            : {
     792                 :          0 :     inp.a *= 2;
     793                 :          0 :     inp.b *= 3;
     794                 :          0 :     inp.c *= 4;
     795                 :          0 :     inp.d *= 5;
     796                 :          0 :     inp.e *= 6;
     797                 :          0 :     inp.f *= 7;
     798                 :          0 :     inp.g *= 8;
     799                 :          0 :     inp.h *= 9;
     800                 :          0 :     return inp;
     801                 :            : }
     802                 :            : 
     803                 :          0 : EXPORT(int) GetRectangle(int flag, RECT *prect)
     804                 :            : {
     805         [ #  # ]:          0 :     if (flag == 0)
     806                 :          0 :         return 0;
     807                 :          0 :     prect->left = (int)flag;
     808                 :          0 :     prect->top = (int)flag + 1;
     809                 :          0 :     prect->right = (int)flag + 2;
     810                 :          0 :     prect->bottom = (int)flag + 3;
     811                 :          0 :     return 1;
     812                 :            : }
     813                 :            : 
     814                 :          0 : EXPORT(void) TwoOutArgs(int a, int *pi, int b, int *pj)
     815                 :            : {
     816                 :          0 :     *pi += a;
     817                 :          0 :     *pj += b;
     818                 :          0 : }
     819                 :            : 
     820                 :            : #ifdef MS_WIN32
     821                 :            : 
     822                 :            : typedef struct {
     823                 :            :     char f1;
     824                 :            : } Size1;
     825                 :            : 
     826                 :            : typedef struct {
     827                 :            :     char f1;
     828                 :            :     char f2;
     829                 :            : } Size2;
     830                 :            : 
     831                 :            : typedef struct {
     832                 :            :     char f1;
     833                 :            :     char f2;
     834                 :            :     char f3;
     835                 :            : } Size3;
     836                 :            : 
     837                 :            : typedef struct {
     838                 :            :     char f1;
     839                 :            :     char f2;
     840                 :            :     char f3;
     841                 :            :     char f4;
     842                 :            : } Size4;
     843                 :            : 
     844                 :            : typedef struct {
     845                 :            :     char f1;
     846                 :            :     char f2;
     847                 :            :     char f3;
     848                 :            :     char f4;
     849                 :            :     char f5;
     850                 :            : } Size5;
     851                 :            : 
     852                 :            : typedef struct {
     853                 :            :     char f1;
     854                 :            :     char f2;
     855                 :            :     char f3;
     856                 :            :     char f4;
     857                 :            :     char f5;
     858                 :            :     char f6;
     859                 :            : } Size6;
     860                 :            : 
     861                 :            : typedef struct {
     862                 :            :     char f1;
     863                 :            :     char f2;
     864                 :            :     char f3;
     865                 :            :     char f4;
     866                 :            :     char f5;
     867                 :            :     char f6;
     868                 :            :     char f7;
     869                 :            : } Size7;
     870                 :            : 
     871                 :            : typedef struct {
     872                 :            :     char f1;
     873                 :            :     char f2;
     874                 :            :     char f3;
     875                 :            :     char f4;
     876                 :            :     char f5;
     877                 :            :     char f6;
     878                 :            :     char f7;
     879                 :            :     char f8;
     880                 :            : } Size8;
     881                 :            : 
     882                 :            : typedef struct {
     883                 :            :     char f1;
     884                 :            :     char f2;
     885                 :            :     char f3;
     886                 :            :     char f4;
     887                 :            :     char f5;
     888                 :            :     char f6;
     889                 :            :     char f7;
     890                 :            :     char f8;
     891                 :            :     char f9;
     892                 :            : } Size9;
     893                 :            : 
     894                 :            : typedef struct {
     895                 :            :     char f1;
     896                 :            :     char f2;
     897                 :            :     char f3;
     898                 :            :     char f4;
     899                 :            :     char f5;
     900                 :            :     char f6;
     901                 :            :     char f7;
     902                 :            :     char f8;
     903                 :            :     char f9;
     904                 :            :     char f10;
     905                 :            : } Size10;
     906                 :            : 
     907                 :            : EXPORT(Size1) TestSize1() {
     908                 :            :     Size1 f;
     909                 :            :     f.f1 = 'a';
     910                 :            :     return f;
     911                 :            : }
     912                 :            : 
     913                 :            : EXPORT(Size2) TestSize2() {
     914                 :            :     Size2 f;
     915                 :            :     f.f1 = 'a';
     916                 :            :     f.f2 = 'b';
     917                 :            :     return f;
     918                 :            : }
     919                 :            : 
     920                 :            : EXPORT(Size3) TestSize3() {
     921                 :            :     Size3 f;
     922                 :            :     f.f1 = 'a';
     923                 :            :     f.f2 = 'b';
     924                 :            :     f.f3 = 'c';
     925                 :            :     return f;
     926                 :            : }
     927                 :            : 
     928                 :            : EXPORT(Size4) TestSize4() {
     929                 :            :     Size4 f;
     930                 :            :     f.f1 = 'a';
     931                 :            :     f.f2 = 'b';
     932                 :            :     f.f3 = 'c';
     933                 :            :     f.f4 = 'd';
     934                 :            :     return f;
     935                 :            : }
     936                 :            : 
     937                 :            : EXPORT(Size5) TestSize5() {
     938                 :            :     Size5 f;
     939                 :            :     f.f1 = 'a';
     940                 :            :     f.f2 = 'b';
     941                 :            :     f.f3 = 'c';
     942                 :            :     f.f4 = 'd';
     943                 :            :     f.f5 = 'e';
     944                 :            :     return f;
     945                 :            : }
     946                 :            : 
     947                 :            : EXPORT(Size6) TestSize6() {
     948                 :            :     Size6 f;
     949                 :            :     f.f1 = 'a';
     950                 :            :     f.f2 = 'b';
     951                 :            :     f.f3 = 'c';
     952                 :            :     f.f4 = 'd';
     953                 :            :     f.f5 = 'e';
     954                 :            :     f.f6 = 'f';
     955                 :            :     return f;
     956                 :            : }
     957                 :            : 
     958                 :            : EXPORT(Size7) TestSize7() {
     959                 :            :     Size7 f;
     960                 :            :     f.f1 = 'a';
     961                 :            :     f.f2 = 'b';
     962                 :            :     f.f3 = 'c';
     963                 :            :     f.f4 = 'd';
     964                 :            :     f.f5 = 'e';
     965                 :            :     f.f6 = 'f';
     966                 :            :     f.f7 = 'g';
     967                 :            :     return f;
     968                 :            : }
     969                 :            : 
     970                 :            : EXPORT(Size8) TestSize8() {
     971                 :            :     Size8 f;
     972                 :            :     f.f1 = 'a';
     973                 :            :     f.f2 = 'b';
     974                 :            :     f.f3 = 'c';
     975                 :            :     f.f4 = 'd';
     976                 :            :     f.f5 = 'e';
     977                 :            :     f.f6 = 'f';
     978                 :            :     f.f7 = 'g';
     979                 :            :     f.f8 = 'h';
     980                 :            :     return f;
     981                 :            : }
     982                 :            : 
     983                 :            : EXPORT(Size9) TestSize9() {
     984                 :            :     Size9 f;
     985                 :            :     f.f1 = 'a';
     986                 :            :     f.f2 = 'b';
     987                 :            :     f.f3 = 'c';
     988                 :            :     f.f4 = 'd';
     989                 :            :     f.f5 = 'e';
     990                 :            :     f.f6 = 'f';
     991                 :            :     f.f7 = 'g';
     992                 :            :     f.f8 = 'h';
     993                 :            :     f.f9 = 'i';
     994                 :            :     return f;
     995                 :            : }
     996                 :            : 
     997                 :            : EXPORT(Size10) TestSize10() {
     998                 :            :     Size10 f;
     999                 :            :     f.f1 = 'a';
    1000                 :            :     f.f2 = 'b';
    1001                 :            :     f.f3 = 'c';
    1002                 :            :     f.f4 = 'd';
    1003                 :            :     f.f5 = 'e';
    1004                 :            :     f.f6 = 'f';
    1005                 :            :     f.f7 = 'g';
    1006                 :            :     f.f8 = 'h';
    1007                 :            :     f.f9 = 'i';
    1008                 :            :     f.f10 = 'j';
    1009                 :            :     return f;
    1010                 :            : }
    1011                 :            : 
    1012                 :            : #endif
    1013                 :            : 
    1014                 :            : #ifdef MS_WIN32
    1015                 :            : EXPORT(S2H) __stdcall s_ret_2h_func(S2H inp) { return ret_2h_func(inp); }
    1016                 :            : EXPORT(S8I) __stdcall s_ret_8i_func(S8I inp) { return ret_8i_func(inp); }
    1017                 :            : #endif
    1018                 :            : 
    1019                 :            : #ifdef MS_WIN32
    1020                 :            : /* Should port this */
    1021                 :            : #include <stdlib.h>
    1022                 :            : #include <search.h>
    1023                 :            : 
    1024                 :            : EXPORT (HRESULT) KeepObject(IUnknown *punk)
    1025                 :            : {
    1026                 :            :     static IUnknown *pobj;
    1027                 :            :     if (punk)
    1028                 :            :         punk->lpVtbl->AddRef(punk);
    1029                 :            :     if (pobj)
    1030                 :            :         pobj->lpVtbl->Release(pobj);
    1031                 :            :     pobj = punk;
    1032                 :            :     return S_OK;
    1033                 :            : }
    1034                 :            : 
    1035                 :            : #endif
    1036                 :            : 
    1037                 :            : #ifdef MS_WIN32
    1038                 :            : 
    1039                 :            : // i38748: c stub for testing stack corruption 
    1040                 :            : // When executing a Python callback with a long and a long long
    1041                 :            : 
    1042                 :            : typedef long(__stdcall *_test_i38748_funcType)(long, long long);
    1043                 :            : 
    1044                 :            : EXPORT(long) _test_i38748_runCallback(_test_i38748_funcType callback, int a, int b) {
    1045                 :            :     return callback(a, b);
    1046                 :            : }
    1047                 :            : 
    1048                 :            : #endif
    1049                 :            : 
    1050                 :            : EXPORT(int)
    1051                 :          0 : _testfunc_pylist_append(PyObject *list, PyObject *item)
    1052                 :            : {
    1053                 :          0 :     return PyList_Append(list, item);
    1054                 :            : }
    1055                 :            : 
    1056                 :            : static struct PyModuleDef_Slot _ctypes_test_slots[] = {
    1057                 :            :     {0, NULL}
    1058                 :            : };
    1059                 :            : 
    1060                 :            : static struct PyModuleDef _ctypes_testmodule = {
    1061                 :            :     PyModuleDef_HEAD_INIT,
    1062                 :            :     "_ctypes_test",
    1063                 :            :     NULL,
    1064                 :            :     0,
    1065                 :            :     module_methods,
    1066                 :            :     _ctypes_test_slots,
    1067                 :            :     NULL,
    1068                 :            :     NULL,
    1069                 :            :     NULL
    1070                 :            : };
    1071                 :            : 
    1072                 :            : PyMODINIT_FUNC
    1073                 :          1 : PyInit__ctypes_test(void)
    1074                 :            : {
    1075                 :          1 :     return PyModuleDef_Init(&_ctypes_testmodule);
    1076                 :            : }

Generated by: LCOV version 1.14