1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
|
From: Youhei SASAKI <uwabami@gfd-dennou.org>
Date: Tue, 11 Nov 2025 15:46:25 +0900
Subject: Refactor code generation for GCC 15 compatibility
Forwarded: not-needed
For GCC 15 compatibility,
Update code generation all function types for GCC 15 compatibility.
Changes:
- Extended mkfuncs() in mknafunc.rb to support additional array types
(na_bifunc_t, na_indgenfunc_t, na_inspfunc_t, na_mathfunc_t)
- Updated error function naming from generic TpErr to specific types
(TpErrUnary, TpErrBi, TpErrIndGen, TpErrMath)
- Fixed old-style function definitions in na_random.c (K&R to ANSI C)
Signed-off-by: Youhei SASAKI <uwabami@gfd-dennou.org>
---
src/mkmath.rb | 52 ++++++++++++++-----------
src/mknafunc.rb | 20 ++++++++--
src/mkop.rb | 109 +++++++++++++++++++++++++++++++++--------------------
src/na_array.c | 14 +++----
src/na_func.c | 16 ++++----
src/na_index.c | 14 +++----
src/na_linalg.c | 41 ++++++++++----------
src/na_random.c | 9 ++---
src/narray.c | 20 +++++-----
src/narray_local.h | 32 +++++++++-------
10 files changed, 188 insertions(+), 139 deletions(-)
diff --git a/src/mkmath.rb b/src/mkmath.rb
index e4a48e6..c861fdd 100644
--- a/src/mkmath.rb
+++ b/src/mkmath.rb
@@ -29,7 +29,13 @@ print <<EOM
VALUE rb_mNMath;
-static void TpErr(void) {
+static void TpErrUnary(int n, char *p1, int i1, char *p2, int i2) {
+ rb_raise(rb_eTypeError,"illegal operation with this type");
+}
+static void TpErrBi(int n, char *p1, int i1, char *p2, int i2, char *p3, int i3) {
+ rb_raise(rb_eTypeError,"illegal operation with this type");
+}
+static void TpErrMath(char *p1, char *p2) {
rb_raise(rb_eTypeError,"illegal operation with this type");
}
@@ -424,10 +430,10 @@ data = [
square#code(&x);
x.r = 1 - x.r;
x.i = - x.i;
- sqrt#code(&x,&x);
+ sqrt#code((char*)&x,(char*)&x);
x.r -= p2->i;
x.i += p2->r;
- log#code(&x,&x);
+ log#code((char*)&x,(char*)&x);
p1->r = x.i;
p1->i = -x.r;
}"]*2 +
@@ -441,10 +447,10 @@ data = [
typed x = *p2;
square#code(&x);
x.r += 1;
- sqrt#code(&x,&x);
+ sqrt#code((char*)&x,(char*)&x);
x.r += p2->r;
x.i += p2->i;
- log#code(p1,&x);
+ log#code(p1,(char*)&x);
}"]*2 +
[nil]*1 ],
@@ -458,11 +464,11 @@ data = [
square#code(&x);
x.r = 1 - x.r;
x.i = - x.i;
- sqrt#code(&x,&x);
+ sqrt#code((char*)&x,(char*)&x);
tmp = x.r + p2->i;
x.r = -x.i + p2->r;
x.i = tmp;
- log#code(&x,&x);
+ log#code((char*)&x,(char*)&x);
p1->r = x.i;
p1->i = -x.r;
}"]*2 +
@@ -476,10 +482,10 @@ data = [
typed x = *p2;
square#code(&x);
x.r -= 1;
- sqrt#code(&x,&x);
+ sqrt#code((char*)&x,(char*)&x);
x.r += p2->r;
x.i += p2->i;
- log#code(p1,&x);
+ log#code(p1,(char*)&x);
}"]*2 +
[nil]*1 ],
@@ -491,8 +497,8 @@ data = [
typed x,y;
x.r=-p2->r; x.i=1-p2->i;
y.r= p2->r; y.i=1+p2->i;
- div#code((void*)&y,(void*)&x);
- log#code((void*)&x,(void*)&y);
+ div#code(&y,&x);
+ log#code((char*)&x,(char*)&y);
p1->r = -x.i/2;
p1->i = x.r/2;
}"]*2 +
@@ -506,8 +512,8 @@ data = [
typed x,y;
x.r=1-p2->r; x.i=-p2->i;
y.r=1+p2->r; y.i= p2->i;
- div#code((void*)&y,(void*)&x);
- log#code((void*)&x,(void*)&y);
+ div#code(&y,&x);
+ log#code((char*)&x,(char*)&y);
p1->r = x.r/2;
p1->i = x.i/2;
}"]*2 +
@@ -525,7 +531,7 @@ def mkmathfuncs(bsname,func)
name = bsname
# Function Definition
- head = "static void #{name}#code(void *p1, void *p2)"
+ head = "static void #{name}#code(char *p1, char *p2)"
for i in 0...c.size
if func[i] != nil && func[i]=~/^\{/
f = func[i].
@@ -545,7 +551,7 @@ def mkmathfuncs(bsname,func)
m = []
for i in 0...c.size
if func[i] == nil
- m += ['TpErr']
+ m += ['TpErrMath']
elsif func[i]=='copy'
m += ['Set'+c[i]*2]
elsif !( func[i] =~ /^\{/ )
@@ -624,7 +630,7 @@ def mkpowfuncs(name,funcs)
end
# function pointer array
- print "\nna_setfunc_t "+name+"Funcs = {\n"
+ print "\nna_powfunc_t "+name+"Funcs = {\n"
m = []
for i in 0...n
l = []
@@ -638,7 +644,7 @@ def mkpowfuncs(name,funcs)
end
end
if f
- l += ['TpErr']
+ l += ['TpErrBi']
end
end
m += [' { '+l.join(', ')+' }']
@@ -669,20 +675,20 @@ mkpowfuncs('Pow',
{ p1->r=1; p1->i=0; } else
if (p2->r==0 && p2->i==0 && *p3>0)
{ p1->r=0; p1->i=0; } else {
- log#C(&r, p2);
+ log#C((char*)&r, p2);
r.r *= *p3;
r.i *= *p3;
- exp#C(p1, &r); }"],
+ exp#C(p1, (char*)&r); }"],
[/[XC]/,/[XC]/,
"typed l, r;
if (p3->r==0 && p3->i==0)
{ p1->r=1; p1->i=0; } else
if (p2->r==0 && p2->i==0 && p3->r>0 && p3->i==0)
{ p1->r=0; p1->i=0; } else {
- log#C(&l, p2);
+ log#C((char*)&l, p2);
r.r = p3->r * l.r - p3->i * l.i;
r.i = p3->r * l.i + p3->i * l.r;
- exp#C(p1, &r); }"]
+ exp#C(p1, (char*)&r); }"]
])
@@ -693,7 +699,7 @@ print <<EOM
/* ------------------------- Execution -------------------------- */
static void
- na_exec_math(struct NARRAY *a1, struct NARRAY *a2, void (*func)())
+ na_exec_math(struct NARRAY *a1, struct NARRAY *a2, void (*func)(char*, char*))
{
int i, s1, s2;
char *p1, *p2;
@@ -734,7 +740,7 @@ static VALUE
na_exec_math(a1, a2, funcs[a2->type]);
if (CLASS_OF(self) == cNArrayScalar)
- SetFuncs[NA_ROBJ][a1->type](1,&ans,0,a1->ptr,0);
+ SetFuncs[NA_ROBJ][a1->type](1,(char*)&ans,0,a1->ptr,0);
return ans;
}
diff --git a/src/mknafunc.rb b/src/mknafunc.rb
index be617b0..8b49813 100644
--- a/src/mknafunc.rb
+++ b/src/mknafunc.rb
@@ -90,7 +90,7 @@ def mksetfuncs(name,op,id,funcs)
end
end
if f
- l += ['TpErr']
+ l += ['TpErrUnary']
end
end
m += [' { '+l.join(', ')+' }']
@@ -101,7 +101,7 @@ end
-def mkfuncs(name,t1,t2,func)
+def mkfuncs(name,t1,t2,func,array_type='na_func_t')
print "
/* ------------------------- #{name} --------------------------- */\n"
@@ -130,11 +130,23 @@ def mkfuncs(name,t1,t2,func)
# Function Array
- print "\nna_func_t #{name}Funcs =\n{ "
+ # Determine error function based on array type
+ err_func = case array_type
+ when 'na_bifunc_t'
+ 'TpErrBi'
+ when 'na_indgenfunc_t'
+ 'TpErrIndGen'
+ when 'na_inspfunc_t', 'na_mathfunc_t'
+ 'TpErrMath'
+ else
+ 'TpErrUnary'
+ end
+
+ print "\n#{array_type} #{name}Funcs =\n{ "
m = []
for i in 0...c.size
if func[i] == nil
- m += ['TpErr']
+ m += [err_func]
elsif func[i]=='copy'
m += ['Set'+c[$data_types.index(t1[i])]+c[i]]
else
diff --git a/src/mkop.rb b/src/mkop.rb
index 51bbe17..88fed65 100644
--- a/src/mkop.rb
+++ b/src/mkop.rb
@@ -38,13 +38,22 @@ const int na_cast_byte[NA_NTYPES] =
{ 0, 1, 1, 1, 1, 1, 1, 1, 1 };
-static void TpErr(void) {
- rb_raise(rb_eTypeError,"illegal operation with this type");
-}
static int TpErrI(void) {
rb_raise(rb_eTypeError,"illegal operation with this type");
return 0;
}
+static void TpErrUnary(int n, char *p1, int i1, char *p2, int i2) {
+ rb_raise(rb_eTypeError,"illegal operation with this type");
+}
+static void TpErrBi(int n, char *p1, int i1, char *p2, int i2, char *p3, int i3) {
+ rb_raise(rb_eTypeError,"illegal operation with this type");
+}
+static void TpErrIndGen(int n, char *p1, int i1, int beg, int step) {
+ rb_raise(rb_eTypeError,"illegal operation with this type");
+}
+static void TpErrMath(char *p1, char *p2) {
+ rb_raise(rb_eTypeError,"illegal operation with this type");
+}
static void na_zerodiv() {
rb_raise(rb_eZeroDivError, "divided by 0");
}
@@ -122,20 +131,20 @@ print <<EOM
#ifdef WORDS_BIGENDIAN
na_func_t H2NFuncs =
-{ TpErr, SetBB, SetII, SetLL, SetFF, SetDD, SetXX, SetCC, SetOO };
+{ TpErrUnary, SetBB, SetII, SetLL, SetFF, SetDD, SetXX, SetCC, SetOO };
na_func_t H2VFuncs =
-{ TpErr, SetBB, SwpI, SwpL, SwpF, SwpD, SwpX, SwpC, SetOO };
+{ TpErrUnary, SetBB, SwpI, SwpL, SwpF, SwpD, SwpX, SwpC, SetOO };
#else
#ifdef DYNAMIC_ENDIAN /* not supported yet */
#else /* LITTLE ENDIAN */
na_func_t H2NFuncs =
-{ TpErr, SetBB, SwpI, SwpL, SwpF, SwpD, SwpX, SwpC, SetOO };
+{ TpErrUnary, SetBB, SwpI, SwpL, SwpF, SwpD, SwpX, SwpC, SetOO };
na_func_t H2VFuncs =
-{ TpErr, SetBB, SetII, SetLL, SetFF, SetDD, SetXX, SetCC, SetOO };
+{ TpErrUnary, SetBB, SetII, SetLL, SetFF, SetDD, SetXX, SetCC, SetOO };
#endif
#endif
@@ -313,7 +322,7 @@ mksortfuncs('SortIdx', $data_types, $data_types, [nil] +
)
# indgen
-$func_body =
+$func_body =
"static void #name#C(int n, char *p1, int i1, int p2, int i2)
{
for (; n; --n) {
@@ -322,12 +331,13 @@ $func_body =
}
}
"
-mkfuncs('IndGen',$data_types,[$data_types[3]]*8,
+mkfuncs('IndGen', $data_types, $data_types,
[nil] +
["*p1 = (typef)p2;"]*5 +
["p1->r = (typef)p2;
p1->i = 0;"]*2 +
- ["*p1 = INT2FIX(p2);"]
+ ["*p1 = INT2FIX(p2);"],
+ 'na_indgenfunc_t'
)
@@ -398,13 +408,13 @@ static void na_str_append_fp(char *buf)
}
EOM
-$func_body =
+$func_body =
"static void #name#C(char *p1, char *p2)
{
OPERATION
}
"
-mkfuncs('Insp',['']+[$data_types[8]]*8,$data_types,
+mkfuncs('Insp', ['']+[$data_types[8]]*8, $data_types,
[nil] +
["char buf[22];
sprintf(buf,\"%i\",(int)*p2);
@@ -433,7 +443,8 @@ mkfuncs('Insp',['']+[$data_types[8]]*8,$data_types,
na_str_append_fp(b);
strcat(buf,\"i\");
*p1 = rb_str_new2(buf);"] +
- ["*p1 = rb_inspect(*p2);"]
+ ["*p1 = rb_inspect(*p2);"],
+ 'na_inspfunc_t'
)
@@ -478,27 +489,30 @@ $func_body =
mkfuncs('AddB', $data_types, $data_types,
[nil] +
- ["*p1 = *p2 + *p3;"]*5 +
+ ["*p1 = *p2 + *p3;"]*5 +
["p1->r = p2->r + p3->r;
p1->i = p2->i + p3->i;"]*2 +
- ["*p1 = rb_funcall(*p2,'+',1,*p3);"]
+ ["*p1 = rb_funcall(*p2,'+',1,*p3);"],
+ 'na_bifunc_t'
)
mkfuncs('SbtB', $data_types, $data_types,
[nil] +
- ["*p1 = *p2 - *p3;"]*5 +
+ ["*p1 = *p2 - *p3;"]*5 +
["p1->r = p2->r - p3->r;
p1->i = p2->i - p3->i;"]*2 +
- ["*p1 = rb_funcall(*p2,'-',1,*p3);"]
+ ["*p1 = rb_funcall(*p2,'-',1,*p3);"],
+ 'na_bifunc_t'
)
mkfuncs('MulB', $data_types, $data_types,
[nil] +
- ["*p1 = *p2 * *p3;"]*5 +
+ ["*p1 = *p2 * *p3;"]*5 +
["type1 x = *p2;
p1->r = x.r*p3->r - x.i*p3->i;
p1->i = x.r*p3->i + x.i*p3->r;"]*2 +
- ["*p1 = rb_funcall(*p2,'*',1,*p3);"]
+ ["*p1 = rb_funcall(*p2,'*',1,*p3);"],
+ 'na_bifunc_t'
)
mkfuncs('DivB', $data_types, $data_types,
@@ -510,37 +524,41 @@ mkfuncs('DivB', $data_types, $data_types,
typef a = p3->r*p3->r + p3->i*p3->i;
p1->r = (x.r*p3->r + x.i*p3->i)/a;
p1->i = (x.i*p3->r - x.r*p3->i)/a;"]*2 +
- ["*p1 = rb_funcall(*p2,'/',1,*p3);"]
+ ["*p1 = rb_funcall(*p2,'/',1,*p3);"],
+ 'na_bifunc_t'
)
mkfuncs('ModB', $data_types, $data_types,
[nil] +
["if (*p3==0) {na_zerodiv();};
*p1 = *p2 % *p3;"]*3 +
- ["*p1 = fmod(*p2, *p3);"]*2 +
+ ["*p1 = fmod(*p2, *p3);"]*2 +
[nil]*2 +
- ["*p1 = rb_funcall(*p2,'%',1,*p3);"]
+ ["*p1 = rb_funcall(*p2,'%',1,*p3);"],
+ 'na_bifunc_t'
)
mkfuncs('MulAdd', $data_types, $data_types,
[nil] +
- ["*p1 += *p2 * *p3;"]*5 +
+ ["*p1 += *p2 * *p3;"]*5 +
["type1 x = *p2;
p1->r += x.r*p3->r - x.i*p3->i;
p1->i += x.r*p3->i + x.i*p3->r;"]*2 +
["*p1 = rb_funcall(*p1,'+',1,
- rb_funcall(*p2,'*',1,*p3));"]
+ rb_funcall(*p2,'*',1,*p3));"],
+ 'na_bifunc_t'
)
mkfuncs('MulSbt', $data_types, $data_types,
[nil] +
- ["*p1 -= *p2 * *p3;"]*5 +
+ ["*p1 -= *p2 * *p3;"]*5 +
["type1 x = *p2;
p1->r -= x.r*p3->r - x.i*p3->i;
p1->i -= x.r*p3->i + x.i*p3->r;"]*2 +
["*p1 = rb_funcall(*p1,'-',1,
- rb_funcall(*p2,'*',1,*p3));"]
+ rb_funcall(*p2,'*',1,*p3));"],
+ 'na_bifunc_t'
)
@@ -550,23 +568,26 @@ mkfuncs('MulSbt', $data_types, $data_types,
mkfuncs('BAn', $data_types, $data_types,
[nil] +
- ["*p1 = *p2 & *p3;"]*3 +
+ ["*p1 = *p2 & *p3;"]*3 +
[nil]*4 +
- ["*p1 = rb_funcall(*p2,'&',1,*p3);"]
+ ["*p1 = rb_funcall(*p2,'&',1,*p3);"],
+ 'na_bifunc_t'
)
mkfuncs('BOr', $data_types, $data_types,
[nil] +
- ["*p1 = *p2 | *p3;"]*3 +
+ ["*p1 = *p2 | *p3;"]*3 +
[nil]*4 +
- ["*p1 = rb_funcall(*p2,'|',1,*p3);"]
+ ["*p1 = rb_funcall(*p2,'|',1,*p3);"],
+ 'na_bifunc_t'
)
mkfuncs('BXo', $data_types, $data_types,
[nil] +
- ["*p1 = *p2 ^ *p3;"]*3 +
+ ["*p1 = *p2 ^ *p3;"]*3 +
[nil]*4 +
- ["*p1 = rb_funcall(*p2,'^',1,*p3);"]
+ ["*p1 = rb_funcall(*p2,'^',1,*p3);"],
+ 'na_bifunc_t'
)
@@ -578,7 +599,8 @@ mkfuncs('Eql', [$data_types[1]]*9, $data_types,
[nil] +
["*p1 = (*p2==*p3) ? 1:0;"]*5 +
["*p1 = (p2->r==p3->r) && (p2->i==p3->i) ? 1:0;"]*2 +
- ["*p1 = RTEST(rb_equal(*p2, *p3)) ? 1:0;"]
+ ["*p1 = RTEST(rb_equal(*p2, *p3)) ? 1:0;"],
+ 'na_bifunc_t'
)
mkfuncs('Cmp', [$data_types[1]]*9, $data_types,
@@ -588,28 +610,32 @@ mkfuncs('Cmp', [$data_types[1]]*9, $data_types,
else *p1=0;"]*5 +
[nil]*2 +
["int v = NUM2INT(rb_funcall(*p2,na_id_compare,1,*p3));
- if (v>0) *p1=1; else if (v<0) *p1=2; else *p1=0;"]
+ if (v>0) *p1=1; else if (v<0) *p1=2; else *p1=0;"],
+ 'na_bifunc_t'
)
mkfuncs('And', [$data_types[1]]*9, $data_types,
[nil] +
["*p1 = (*p2!=0 && *p3!=0) ? 1:0;"]*5 +
["*p1 = ((p2->r!=0||p2->i!=0) && (p3->r!=0||p3->i!=0)) ? 1:0;"]*2 +
- ["*p1 = (RTEST(*p2) && RTEST(*p3)) ? 1:0;"]
+ ["*p1 = (RTEST(*p2) && RTEST(*p3)) ? 1:0;"],
+ 'na_bifunc_t'
)
mkfuncs('Or_', [$data_types[1]]*9, $data_types,
[nil] +
["*p1 = (*p2!=0 || *p3!=0) ? 1:0;"]*5 +
["*p1 = ((p2->r!=0||p2->i!=0) || (p3->r!=0||p3->i!=0)) ? 1:0;"]*2 +
- ["*p1 = (RTEST(*p2) || RTEST(*p3)) ? 1:0;"]
+ ["*p1 = (RTEST(*p2) || RTEST(*p3)) ? 1:0;"],
+ 'na_bifunc_t'
)
mkfuncs('Xor', [$data_types[1]]*9, $data_types,
[nil] +
["*p1 = ((*p2!=0) == (*p3!=0)) ? 0:1;"]*5 +
["*p1 = ((p2->r!=0||p2->i!=0) == (p3->r!=0||p3->i!=0)) ? 0:1;"]*2 +
- ["*p1 = (RTEST(*p2) == RTEST(*p3)) ? 0:1;"]
+ ["*p1 = (RTEST(*p2) == RTEST(*p3)) ? 0:1;"],
+ 'na_bifunc_t'
)
@@ -620,7 +646,8 @@ mkfuncs('Xor', [$data_types[1]]*9, $data_types,
mkfuncs('atan2', $data_types, $data_types,
[nil]*4 +
["*p1 = atan2(*p2, *p3);"]*2 +
- [nil]*3
+ [nil]*3,
+ 'na_bifunc_t'
)
@@ -638,11 +665,13 @@ $func_body =
mkfuncs('RefMask',$data_types,$data_types,
[nil] +
["if (*(u_int8_t*)p3) { *p1=*p2; p1+=i1; }
- p3+=i3; p2+=i2;"]*8
+ p3+=i3; p2+=i2;"]*8,
+ 'na_bifunc_t'
)
mkfuncs('SetMask',$data_types,$data_types,
[nil] +
["if (*(u_int8_t*)p3) { *p1=*p2; p2+=i2; }
- p3+=i3; p1+=i1;"]*8
+ p3+=i3; p1+=i1;"]*8,
+ 'na_bifunc_t'
)
diff --git a/src/na_array.c b/src/na_array.c
index 8fdf4f0..78ed4d1 100644
--- a/src/na_array.c
+++ b/src/na_array.c
@@ -290,7 +290,7 @@ static void
/* NIL if empty */
if (v != Qnil) {
pos = na_index_pos(na,idx);
- SetFuncs[type][NA_ROBJ]( 1, NA_PTR(na,pos), 0, &v, 0 );
+ SetFuncs[type][NA_ROBJ]( 1, NA_PTR(na,pos), 0, (char*)&v, 0 );
/* copy here */
}
idx[0] ++;
@@ -325,7 +325,7 @@ static void
}
else {
pos = na_index_pos(na,idx);
- SetFuncs[type][NA_ROBJ]( 1, NA_PTR(na,pos), 0, &(RARRAY_PTR(ary)[i]), 0 );
+ SetFuncs[type][NA_ROBJ]( 1, NA_PTR(na,pos), 0, (char*)&(RARRAY_PTR(ary)[i]), 0 );
++idx[thisrank];
}
/* copy here */
@@ -509,7 +509,7 @@ VALUE
/* convert NArray to Array */
static VALUE
- na_to_array0(struct NARRAY* na, int *idx, int thisrank, void (*func)())
+ na_to_array0(struct NARRAY* na, int *idx, int thisrank, void (*func)(int, char*, int, char*, int))
{
int i, elmsz;
char *ptr;
@@ -522,7 +522,7 @@ static VALUE
ptr = NA_PTR( na, na_index_pos(na,idx) );
elmsz = na_sizeof[na->type];
for (i = na->shape[0]; i; --i) {
- (*func)( 1, &val, 0, ptr, 0 );
+ (*func)( 1, (char*)&val, 0, ptr, 0 );
ptr += elmsz;
rb_ary_push( ary, val );
}
@@ -556,7 +556,7 @@ VALUE
static VALUE
- na_inspect_col( int n, char *p2, int p2step, void (*tostr)(),
+ na_inspect_col( int n, char *p2, int p2step, void (*tostr)(char*, char*),
VALUE sep, int rank )
{
VALUE str=Qnil, tmp;
@@ -564,11 +564,11 @@ static VALUE
int sep_len = RSTRING_LEN(sep);
if (n>0)
- (*tostr)(&str,p2);
+ (*tostr)((char*)&str,p2);
for (n--; n>0; --n) {
p2 += p2step;
- (*tostr)(&tmp,p2);
+ (*tostr)((char*)&tmp,p2);
if (!NIL_P(sep)) rb_str_concat(str, sep);
diff --git a/src/na_func.c b/src/na_func.c
index ba9145a..7e614fb 100644
--- a/src/na_func.c
+++ b/src/na_func.c
@@ -87,7 +87,7 @@ void na_init_slice( struct slice *s, int rank, int *shape, int elmsz )
static void
na_do_loop_unary( int nd, char *p1, char *p2,
- struct slice *s1, struct slice *s2, void (*func)() )
+ struct slice *s1, struct slice *s2, void (*func)(int, char*, int, char*, int) )
{
int *si;
int i;
@@ -122,7 +122,7 @@ static void
static void
na_do_loop_binary( int nd, char *p1, char *p2, char *p3,
struct slice *s1, struct slice *s2, struct slice *s3,
- void (*func)() )
+ void (*func)(int, char*, int, char*, int, char*, int) )
{
int i;
int ps1 = s1[0].pstep;
@@ -161,7 +161,7 @@ static void
void na_loop_index_ref( struct NARRAY *a1, struct NARRAY *a2,
- struct slice *s1, struct slice *s2, void (*func)() )
+ struct slice *s1, struct slice *s2, void (*func)(int, char*, int, char*, int) )
{
char *p1, *p2;
int nr, i, ii;
@@ -227,7 +227,7 @@ void na_loop_index_ref( struct NARRAY *a1, struct NARRAY *a2,
void na_loop_general( struct NARRAY *a1, struct NARRAY *a2,
- struct slice *s1, struct slice *s2, void (*func)() )
+ struct slice *s1, struct slice *s2, void (*func)(int, char*, int, char*, int) )
{
char *p1, *p2;
int nr, i, ii;
@@ -454,7 +454,7 @@ int
static void
- na_exec_unary(struct NARRAY *a1, struct NARRAY *a2, void (*func)())
+ na_exec_unary(struct NARRAY *a1, struct NARRAY *a2, void (*func)(int, char*, int, char*, int))
{
int ndim;
int *shp1, *shp2;
@@ -487,7 +487,7 @@ static void
/* a1 and/or a2 and/or a3 have extensible index */
static void
na_exec_binary( struct NARRAY *a1, struct NARRAY *a2,
- struct NARRAY *a3, void (*func)() )
+ struct NARRAY *a3, void (*func)(int, char*, int, char*, int, char*, int) )
{
int ndim;
int *itr, *shp1, *shp2, *shp3;
@@ -784,7 +784,7 @@ static VALUE na_math_atan2(VALUE module, volatile VALUE y, volatile VALUE x)
GetNArray(ans,aa);
if (CLASS_OF(y) == cNArrayScalar && CLASS_OF(x) == cNArrayScalar)
- SetFuncs[NA_ROBJ][aa->type](1,&ans,0,aa->ptr,0);
+ SetFuncs[NA_ROBJ][aa->type](1,(char*)&ans,0,aa->ptr,0);
return ans;
}
@@ -1266,7 +1266,7 @@ static VALUE
obj = na_make_object(a1->type,a1->rank,shape,klass);
GetNArray(obj,a2);
- SetFuncs[a2->type][NA_LINT](a2->total, a2->ptr, na_sizeof[a2->type], &one, 0);
+ SetFuncs[a2->type][NA_LINT](a2->total, a2->ptr, na_sizeof[a2->type], (char*)&one, 0);
na_exec_unary( a2, a1, MulUFuncs[a1->type] );
diff --git a/src/na_index.c b/src/na_index.c
index 003cf15..c13c316 100644
--- a/src/na_index.c
+++ b/src/na_index.c
@@ -103,7 +103,7 @@ static int
else
/* single element */
if (a1->total==1) {
- SetFuncs[NA_LINT][a1->type](1, &idx, 0, a1->ptr, 0);
+ SetFuncs[NA_LINT][a1->type](1, (char*)&idx, 0, a1->ptr, 0);
if ( idx<0 ) idx += size;
if ( idx<0 || idx>=size )
rb_raise(rb_eIndexError, "index %i out of range %i", idx, size);
@@ -118,7 +118,7 @@ static int
s->step = 1;
s->idx = p = ALLOC_N(na_index_t, a1->total);
SetFuncs[NA_LINT][a1->type]( s->n,
- s->idx, na_sizeof[NA_LINT],
+ (char*)s->idx, na_sizeof[NA_LINT],
a1->ptr, na_sizeof[a1->type] );
for ( i=a1->total; i>0; --i ) {
if ( *p<0 ) *p += size;
@@ -289,7 +289,7 @@ VALUE
ary->rank = j;
if (j==0 && ary->total==1) {
- SetFuncs[NA_ROBJ][ary->type](1, &obj, 0, ary->ptr, 0);
+ SetFuncs[NA_ROBJ][ary->type](1, (char*)&obj, 0, ary->ptr, 0);
}
return obj;
}
@@ -410,7 +410,7 @@ static VALUE
GetNArray(v,arynew);
SetFuncs[ary->type][ary->type](1, arynew->ptr,0, NA_PTR(ary,sl->beg),0);
} else {
- SetFuncs[NA_ROBJ][ary->type](1, &v,0, NA_PTR(ary,sl->beg),0);
+ SetFuncs[NA_ROBJ][ary->type](1, (char*)&v,0, NA_PTR(ary,sl->beg),0);
}
}
else
@@ -452,7 +452,7 @@ static VALUE
pos = pos * ary->shape[i] + sl[i].beg;
}
if (rank==0) {
- SetFuncs[NA_ROBJ][ary->type](1, &v, 0, NA_PTR(ary,pos), 0);
+ SetFuncs[NA_ROBJ][ary->type](1, (char*)&v, 0, NA_PTR(ary,pos), 0);
} else {
VALUE klass;
int class_dim;
@@ -825,7 +825,7 @@ static void
/* Storing single element:
a[1] = 1
*/
- SetFuncs[dst->type][NA_ROBJ](1, NA_PTR(dst,sl->beg),0, &val,0);
+ SetFuncs[dst->type][NA_ROBJ](1, NA_PTR(dst,sl->beg),0, (char*)&val,0);
return;
}
/* Beginning index:
@@ -882,7 +882,7 @@ static void
*/
for ( pos=0, i=dst->rank; i-->0; )
pos = pos * dst->shape[i] + sl[i].beg;
- SetFuncs[dst->type][NA_ROBJ](1, NA_PTR(dst,pos), 0, &val, 0 );
+ SetFuncs[dst->type][NA_ROBJ](1, NA_PTR(dst,pos), 0, (char*)&val, 0 );
xfree(sl);
return;
}
diff --git a/src/na_linalg.c b/src/na_linalg.c
index df54e7b..162a939 100644
--- a/src/na_linalg.c
+++ b/src/na_linalg.c
@@ -24,21 +24,21 @@ typedef struct NARRAY_FUNCSET {
char *zero;
char *one;
char *tiny;
- void (*set)();
- void (*neg)();
- void (*rcp)();
- void (*abs)();
- void (*add)();
- void (*sbt)();
- void (*mul)();
- void (*div)();
- void (*mod)();
- void (*muladd)();
- void (*mulsbt)();
- void (*cmp)();
- int (*sort)();
- void (*min)();
- void (*max)();
+ void (*set)(int, char*, int, char*, int);
+ void (*neg)(int, char*, int, char*, int);
+ void (*rcp)(int, char*, int, char*, int);
+ void (*abs)(int, char*, int, char*, int);
+ void (*add)(int, char*, int, char*, int);
+ void (*sbt)(int, char*, int, char*, int);
+ void (*mul)(int, char*, int, char*, int);
+ void (*div)(int, char*, int, char*, int);
+ void (*mod)(int, char*, int, char*, int);
+ void (*muladd)(int, char*, int, char*, int, char*, int);
+ void (*mulsbt)(int, char*, int, char*, int, char*, int);
+ void (*cmp)(int, char*, int, char*, int, char*, int);
+ int (*sort)(const void*, const void*);
+ void (*min)(int, char*, int, char*, int);
+ void (*max)(int, char*, int, char*, int);
} na_funcset_t;
VALUE cNMatrix, cNVector, cNMatrixLU;
@@ -49,7 +49,7 @@ static ID id_lu, id_pivot;
static void
na_loop_linalg( int nd, char *p1, char *p2, char *p3,
struct slice *s1, struct slice *s2, struct slice *s3,
- void (*func)(), int *shape, int type )
+ void (*func)(int, char*, int, char*, int, char*, int, int*, int), int *shape, int type )
{
int i;
int ps1 = s1[0].pstep;
@@ -103,7 +103,7 @@ na_shape_total( int n, int *shape )
static void
na_exec_linalg( struct NARRAY *a1, struct NARRAY *a2, struct NARRAY *a3,
- int ncd1, int ncd2, int ncd3, void (*func)() )
+ int ncd1, int ncd2, int ncd3, void (*func)(int, char*, int, char*, int, char*, int, int*, int) )
{
int ndim, ncd, nsz1, nsz2, nsz3;
int *itr, *shp1, *shp2, *shp3;
@@ -313,11 +313,10 @@ static VALUE
piv = na_make_object(NA_LINT, ary->rank-1, ary->shape+1, cNVector);
/* prepare pivot index */
- func = IndGenFuncs[NA_LINT];
sz = na_sizeof[NA_LINT];
ptr = idx = ((struct NARRAY *)DATA_PTR(piv))->ptr;
for (i=0; i<total; ++i) {
- func(n,ptr,sz,0,1);
+ IndGenFuncs[NA_LINT](n,ptr,sz,0,1);
ptr += n*sz;
}
@@ -588,10 +587,10 @@ void Init_na_linalg()
for (i=1;i<NA_NTYPES;++i) {
sz = na_funcset[i].elmsz = na_sizeof[i];
sz = (sz>((int)sizeof(int))) ? sz : (int)sizeof(int);
- SetFuncs[i][NA_LINT](1, a,0, &one, 0);
+ SetFuncs[i][NA_LINT](1, a,0, (char*)&one, 0);
na_funcset[i].one = a;
a += sz;
- SetFuncs[i][NA_LINT](1, a,0, &zero,0);
+ SetFuncs[i][NA_LINT](1, a,0, (char*)&zero,0);
na_funcset[i].zero = a;
na_funcset[i].tiny = a;
a += sz;
diff --git a/src/na_random.c b/src/na_random.c
index 1ccf1c1..a9a6450 100644
--- a/src/na_random.c
+++ b/src/na_random.c
@@ -131,8 +131,7 @@ static void
static int first = 1;
static int
-rand_init(seed)
- u_int32_t seed;
+rand_init(u_int32_t seed)
{
static u_int32_t saved_seed;
u_int32_t old;
@@ -146,7 +145,7 @@ rand_init(seed)
}
static u_int32_t
- random_seed()
+random_seed(void)
{
static int n = 0;
struct timeval tv;
@@ -235,7 +234,7 @@ static u_int32_t size_check(double rmax, double limit)
return max;
}
-static void TpErr(void) {
+static void TpErr(int n, char *p1, int i1, double rmax) {
rb_raise(rb_eTypeError,"illegal operation with this type");
}
@@ -370,7 +369,7 @@ static void RndC(int n, char *p1, int i1, double rmax)
}
}
-na_func_t RndFuncs =
+na_randfunc_t RndFuncs =
{ TpErr, RndB, RndI, RndL, RndF, RndD, RndX, RndC, TpErr };
diff --git a/src/narray.c b/src/narray.c
index d3f6890..89908e2 100644
--- a/src/narray.c
+++ b/src/narray.c
@@ -201,7 +201,7 @@ static VALUE
/* Extract element */
if (ary->rank==0 && ary->total==1) {
- SetFuncs[NA_ROBJ][ary->type](1,&v,0,ary->ptr,0);
+ SetFuncs[NA_ROBJ][ary->type](1,(char*)&v,0,ary->ptr,0);
na_free(ary);
return v;
}
@@ -263,7 +263,7 @@ VALUE
v = na_make_object(type,1,&shape,cNArrayScalar);
GetNArray(v,ary);
- SetFuncs[ary->type][NA_ROBJ](1, ary->ptr,0, &obj,0);
+ SetFuncs[ary->type][NA_ROBJ](1, ary->ptr,0, (char*)&obj,0);
return v;
}
@@ -1094,7 +1094,7 @@ static VALUE
VALUE v;
struct NARRAY *ary;
char *p;
- void (*func)();
+ void (*func)(int, char*, int, char*, int);
if (rb_block_given_p()) {
GetNArray(obj,ary);
@@ -1104,7 +1104,7 @@ static VALUE
func = SetFuncs[NA_ROBJ][ary->type];
for ( i=ary->total; i-->0; ) {
- (*func)( 1, &v, 0, p, 0 );
+ (*func)( 1, (char*)&v, 0, p, 0 );
rb_yield(v);
p += sz;
}
@@ -1123,7 +1123,7 @@ static VALUE
VALUE v, obj2;
struct NARRAY *a1, *a2;
char *p1, *p2;
- void (*get)(), (*set)();
+ void (*get)(int, char*, int, char*, int), (*set)(int, char*, int, char*, int);
GetNArray(obj1,a1);
obj2 = na_make_object(a1->type, a1->rank, a1->shape, CLASS_OF(obj1));
@@ -1136,9 +1136,9 @@ static VALUE
set = SetFuncs[a1->type][NA_ROBJ];
for ( i=a1->total; i-->0; ) {
- (*get)( 1, &v, 0, p1, 0 );
+ (*get)( 1, (char*)&v, 0, p1, 0 );
v = rb_yield(v);
- (*set)( 1, p2, 0, &v, 0 );
+ (*set)( 1, p2, 0, (char*)&v, 0 );
p1 += sz;
p2 += sz;
}
@@ -1154,7 +1154,7 @@ static VALUE
VALUE v;
struct NARRAY *a1;
char *p1;
- void (*get)(), (*set)();
+ void (*get)(int, char*, int, char*, int), (*set)(int, char*, int, char*, int);
GetNArray(self,a1);
@@ -1164,9 +1164,9 @@ static VALUE
set = SetFuncs[a1->type][NA_ROBJ];
for ( i=a1->total; i-->0; ) {
- (*get)( 1, &v, 0, p1, 0 );
+ (*get)( 1, (char*)&v, 0, p1, 0 );
v = rb_yield(v);
- (*set)( 1, p1, 0, &v, 0 );
+ (*set)( 1, p1, 0, (char*)&v, 0 );
p1 += sz;
}
return self;
diff --git a/src/narray_local.h b/src/narray_local.h
index 5ccc521..6c35a3a 100644
--- a/src/narray_local.h
+++ b/src/narray_local.h
@@ -23,12 +23,16 @@ struct slice {
na_index_t *idx; /* NULL if normal step */
};
-typedef void (*na_setfunc_t[NA_NTYPES][NA_NTYPES]) ();
-typedef void (*na_func_t[NA_NTYPES]) ();
-typedef void (*na_ufunc_t[NA_NTYPES]) ();
-typedef void (*na_bifunc_t[NA_NTYPES]) ();
-typedef void (*na_mathfunc_t[NA_NTYPES]) ();
+typedef void (*na_setfunc_t[NA_NTYPES][NA_NTYPES]) (int, char*, int, char*, int);
+typedef void (*na_powfunc_t[NA_NTYPES][NA_NTYPES]) (int, char*, int, char*, int, char*, int);
+typedef void (*na_func_t[NA_NTYPES]) (int, char*, int, char*, int);
+typedef void (*na_ufunc_t[NA_NTYPES]) (int, char*, int, char*, int);
+typedef void (*na_bifunc_t[NA_NTYPES]) (int, char*, int, char*, int, char*, int);
+typedef void (*na_mathfunc_t[NA_NTYPES]) (char*, char*);
+typedef void (*na_indgenfunc_t[NA_NTYPES]) (int, char*, int, int, int);
+typedef void (*na_inspfunc_t[NA_NTYPES]) (char*, char*);
typedef int (*na_sortfunc_t[NA_NTYPES]) (const void *, const void *);
+typedef void (*na_randfunc_t[NA_NTYPES]) (int, char*, int, double);
/* function arrays */
extern na_setfunc_t SetFuncs;
@@ -47,8 +51,8 @@ extern na_ufunc_t FloorFuncs;
extern na_ufunc_t CeilFuncs;
extern na_ufunc_t RoundFuncs;
extern na_ufunc_t ToStrFuncs;
-extern na_ufunc_t InspFuncs;
-extern na_ufunc_t IndGenFuncs;
+extern na_inspfunc_t InspFuncs;
+extern na_indgenfunc_t IndGenFuncs;
extern na_ufunc_t AddUFuncs;
extern na_ufunc_t SbtUFuncs;
extern na_ufunc_t MulUFuncs;
@@ -65,14 +69,14 @@ extern na_bifunc_t BAnFuncs;
extern na_bifunc_t BOrFuncs;
extern na_bifunc_t BXoFuncs;
extern na_ufunc_t BRvFuncs;
-extern na_bifunc_t ImgSetFuncs;
-extern na_setfunc_t PowFuncs;
+extern na_ufunc_t ImgSetFuncs;
+extern na_powfunc_t PowFuncs;
extern na_bifunc_t atan2Funcs;
extern na_bifunc_t CmpFuncs;
extern na_bifunc_t EqlFuncs;
-extern na_ufunc_t AndFuncs;
-extern na_ufunc_t Or_Funcs;
-extern na_ufunc_t XorFuncs;
+extern na_bifunc_t AndFuncs;
+extern na_bifunc_t Or_Funcs;
+extern na_bifunc_t XorFuncs;
extern na_ufunc_t NotFuncs;
extern na_ufunc_t MinFuncs;
extern na_ufunc_t MaxFuncs;
@@ -120,9 +124,9 @@ int na_set_slice_3obj( int ndim,
struct slice *s1, struct slice *s2, struct slice *s3,
int *shp1, int *shp2, int *shp3, int *shape );
void na_loop_general(struct NARRAY *a1, struct NARRAY *a2,
- struct slice *s1, struct slice *s2, void (*func)());
+ struct slice *s1, struct slice *s2, void (*func)(int, char*, int, char*, int));
void na_loop_index_ref(struct NARRAY *a1, struct NARRAY *a2,
- struct slice *s1, struct slice *s2, void (*func)());
+ struct slice *s1, struct slice *s2, void (*func)(int, char*, int, char*, int));
/* na_index.c */
void na_aset_slice(struct NARRAY *dst, struct NARRAY *src, struct slice *s1);
|