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 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198
|
#include <stdio.h>
#include <qglobal.h>
#include <qstring.h>
#include <qapplication.h>
#include <qmetaobject.h>
#include <private/qucomextra_p.h>
#include "smoke.h"
#undef DEBUG
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#ifndef __USE_POSIX
#define __USE_POSIX
#endif
#ifndef __USE_XOPEN
#define __USE_XOPEN
#endif
#ifdef _BOOL
#define HAS_BOOL
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifndef QT_VERSION_STR
#define QT_VERSION_STR "Unknown"
#endif
#undef free
#undef malloc
#include "marshall.h"
#include "perlqt.h"
#include "smokeperl.h"
#ifndef IN_BYTES
#define IN_BYTES IN_BYTE
#endif
#ifndef IN_LOCALE
#define IN_LOCALE (PL_curcop->op_private & HINT_LOCALE)
#endif
extern Smoke *qt_Smoke;
extern void init_qt_Smoke();
int do_debug = qtdb_none;
HV *pointer_map = 0;
SV *sv_qapp = 0;
int object_count = 0;
void *_current_object = 0; // TODO: ask myself if this is stupid
bool temporary_virtual_function_success = false;
static QAsciiDict<Smoke::Index> *methcache = 0;
static QAsciiDict<Smoke::Index> *classcache = 0;
SV *sv_this = 0;
Smoke::Index _current_object_class = 0;
Smoke::Index _current_method = 0;
/*
* Type handling by moc is simple.
*
* If the type name matches /^(?:const\s+)?\Q$types\E&?$/, use the
* static_QUType, where $types is join('|', qw(bool int double char* QString);
*
* Everything else is passed as a pointer! There are types which aren't
* Smoke::tf_ptr but will have to be passed as a pointer. Make sure to keep
* track of what's what.
*/
/*
* Simply using typeids isn't enough for signals/slots. It will be possible
* to declare signals and slots which use arguments which can't all be
* found in a single smoke object. Instead, we need to store smoke => typeid
* pairs. We also need additional informatation, such as whether we're passing
* a pointer to the union element.
*/
enum MocArgumentType {
xmoc_ptr,
xmoc_bool,
xmoc_int,
xmoc_double,
xmoc_charstar,
xmoc_QString
};
struct MocArgument {
// smoke object and associated typeid
SmokeType st;
MocArgumentType argType;
};
extern TypeHandler Qt_handlers[];
void install_handlers(TypeHandler *);
void *sv_to_ptr(SV *sv) { // ptr on success, null on fail
smokeperl_object *o = sv_obj_info(sv);
return o ? o->ptr : 0;
}
bool isQObject(Smoke *smoke, Smoke::Index classId) {
if(!strcmp(smoke->classes[classId].className, "QObject"))
return true;
for(Smoke::Index *p = smoke->inheritanceList + smoke->classes[classId].parents;
*p;
p++) {
if(isQObject(smoke, *p))
return true;
}
return false;
}
int isDerivedFrom(Smoke *smoke, Smoke::Index classId, Smoke::Index baseId, int cnt) {
if(classId == baseId)
return cnt;
cnt++;
for(Smoke::Index *p = smoke->inheritanceList + smoke->classes[classId].parents;
*p;
p++) {
if(isDerivedFrom(smoke, *p, baseId, cnt) != -1)
return cnt;
}
return -1;
}
int isDerivedFrom(Smoke *smoke, const char *className, const char *baseClassName, int cnt) {
if(!smoke || !className || !baseClassName)
return -1;
Smoke::Index idClass = smoke->idClass(className);
Smoke::Index idBase = smoke->idClass(baseClassName);
return isDerivedFrom(smoke, idClass, idBase, cnt);
}
SV *getPointerObject(void *ptr) {
HV *hv = pointer_map;
SV *keysv = newSViv((IV)ptr);
STRLEN len;
char *key = SvPV(keysv, len);
SV **svp = hv_fetch(hv, key, len, 0);
if(!svp){
SvREFCNT_dec(keysv);
return 0;
}
if(!SvOK(*svp)){
hv_delete(hv, key, len, G_DISCARD);
SvREFCNT_dec(keysv);
return 0;
}
return *svp;
}
void unmapPointer(smokeperl_object *o, Smoke::Index classId, void *lastptr) {
HV *hv = pointer_map;
void *ptr = o->smoke->cast(o->ptr, o->classId, classId);
if(ptr != lastptr) {
lastptr = ptr;
SV *keysv = newSViv((IV)ptr);
STRLEN len;
char *key = SvPV(keysv, len);
if(hv_exists(hv, key, len))
hv_delete(hv, key, len, G_DISCARD);
SvREFCNT_dec(keysv);
}
for(Smoke::Index *i = o->smoke->inheritanceList + o->smoke->classes[classId].parents;
*i;
i++) {
unmapPointer(o, *i, lastptr);
}
}
// Store pointer in pointer_map hash : "pointer_to_Qt_object" => weak ref to associated Perl object
// Recurse to store it also as casted to its parent classes.
void mapPointer(SV *obj, smokeperl_object *o, HV *hv, Smoke::Index classId, void *lastptr) {
void *ptr = o->smoke->cast(o->ptr, o->classId, classId);
if(ptr != lastptr) {
lastptr = ptr;
SV *keysv = newSViv((IV)ptr);
STRLEN len;
char *key = SvPV(keysv, len);
SV *rv = newSVsv(obj);
sv_rvweaken(rv); // weak reference!
hv_store(hv, key, len, rv, 0);
SvREFCNT_dec(keysv);
}
for(Smoke::Index *i = o->smoke->inheritanceList + o->smoke->classes[classId].parents;
*i;
i++) {
mapPointer(obj, o, hv, *i, lastptr);
}
}
Marshall::HandlerFn getMarshallFn(const SmokeType &type);
class VirtualMethodReturnValue : public Marshall {
Smoke *_smoke;
Smoke::Index _method;
Smoke::Stack _stack;
SmokeType _st;
SV *_retval;
public:
const Smoke::Method &method() { return _smoke->methods[_method]; }
SmokeType type() { return _st; }
Marshall::Action action() { return Marshall::FromSV; }
Smoke::StackItem &item() { return _stack[0]; }
SV *var() { return _retval; }
void unsupported() {
croak("Cannot handle '%s' as return-type of virtual method %s::%s",
type().name(),
_smoke->className(method().classId),
_smoke->methodNames[method().name]);
}
Smoke *smoke() { return _smoke; }
void next() {}
bool cleanup() { return false; }
VirtualMethodReturnValue(Smoke *smoke, Smoke::Index meth, Smoke::Stack stack, SV *retval) :
_smoke(smoke), _method(meth), _stack(stack), _retval(retval) {
_st.set(_smoke, method().ret);
Marshall::HandlerFn fn = getMarshallFn(type());
(*fn)(this);
}
};
class VirtualMethodCall : public Marshall {
Smoke *_smoke;
Smoke::Index _method;
Smoke::Stack _stack;
GV *_gv;
int _cur;
Smoke::Index *_args;
SV **_sp;
bool _called;
SV *_savethis;
public:
SmokeType type() { return SmokeType(_smoke, _args[_cur]); }
Marshall::Action action() { return Marshall::ToSV; }
Smoke::StackItem &item() { return _stack[_cur + 1]; }
SV *var() { return _sp[_cur]; }
const Smoke::Method &method() { return _smoke->methods[_method]; }
void unsupported() {
croak("Cannot handle '%s' as argument of virtual method %s::%s",
type().name(),
_smoke->className(method().classId),
_smoke->methodNames[method().name]);
}
Smoke *smoke() { return _smoke; }
void callMethod() {
dSP;
if(_called) return;
_called = true;
SP = _sp + method().numArgs - 1;
PUTBACK;
int count = call_sv((SV*)GvCV(_gv), G_SCALAR);
SPAGAIN;
VirtualMethodReturnValue r(_smoke, _method, _stack, POPs);
PUTBACK;
FREETMPS;
LEAVE;
}
void next() {
int oldcur = _cur;
_cur++;
while(!_called && _cur < method().numArgs) {
Marshall::HandlerFn fn = getMarshallFn(type());
(*fn)(this);
_cur++;
}
callMethod();
_cur = oldcur;
}
bool cleanup() { return false; } // is this right?
VirtualMethodCall(Smoke *smoke, Smoke::Index meth, Smoke::Stack stack, SV *obj, GV *gv) :
_smoke(smoke), _method(meth), _stack(stack), _gv(gv), _cur(-1), _sp(0), _called(false) {
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
EXTEND(SP, method().numArgs);
_savethis = sv_this;
sv_this = newSVsv(obj);
_sp = SP + 1;
for(int i = 0; i < method().numArgs; i++)
_sp[i] = sv_newmortal();
_args = _smoke->argumentList + method().args;
}
~VirtualMethodCall() {
SvREFCNT_dec(sv_this);
sv_this = _savethis;
}
};
class MethodReturnValue : public Marshall {
Smoke *_smoke;
Smoke::Index _method;
SV *_retval;
Smoke::Stack _stack;
public:
MethodReturnValue(Smoke *smoke, Smoke::Index method, Smoke::Stack stack, SV *retval) :
_smoke(smoke), _method(method), _retval(retval), _stack(stack) {
Marshall::HandlerFn fn = getMarshallFn(type());
(*fn)(this);
}
const Smoke::Method &method() { return _smoke->methods[_method]; }
SmokeType type() { return SmokeType(_smoke, method().ret); }
Marshall::Action action() { return Marshall::ToSV; }
Smoke::StackItem &item() { return _stack[0]; }
SV *var() { return _retval; }
void unsupported() {
croak("Cannot handle '%s' as return-type of %s::%s",
type().name(),
_smoke->className(method().classId),
_smoke->methodNames[method().name]);
}
Smoke *smoke() { return _smoke; }
void next() {}
bool cleanup() { return false; }
};
class MethodCall : public Marshall {
int _cur;
Smoke *_smoke;
Smoke::Stack _stack;
Smoke::Index _method;
Smoke::Index *_args;
SV **_sp;
int _items;
SV *_retval;
bool _called;
public:
MethodCall(Smoke *smoke, Smoke::Index method, SV **sp, int items) :
_smoke(smoke), _method(method), _sp(sp), _items(items), _cur(-1), _called(false) {
_args = _smoke->argumentList + _smoke->methods[_method].args;
_items = _smoke->methods[_method].numArgs;
_stack = new Smoke::StackItem[items + 1];
_retval = newSV(0);
}
~MethodCall() {
delete[] _stack;
SvREFCNT_dec(_retval);
}
SmokeType type() { return SmokeType(_smoke, _args[_cur]); }
Marshall::Action action() { return Marshall::FromSV; }
Smoke::StackItem &item() { return _stack[_cur + 1]; }
SV *var() {
if(_cur < 0) return _retval;
SvGETMAGIC(*(_sp + _cur));
return *(_sp + _cur);
}
inline const Smoke::Method &method() { return _smoke->methods[_method]; }
void unsupported() {
croak("Cannot handle '%s' as argument to %s::%s",
type().name(),
_smoke->className(method().classId),
_smoke->methodNames[method().name]);
}
Smoke *smoke() { return _smoke; }
inline void callMethod() {
if(_called) return;
_called = true;
Smoke::ClassFn fn = _smoke->classes[method().classId].classFn;
void *ptr = _smoke->cast(
_current_object,
_current_object_class,
method().classId
);
_items = -1;
(*fn)(method().method, ptr, _stack);
MethodReturnValue r(_smoke, _method, _stack, _retval);
}
void next() {
int oldcur = _cur;
_cur++;
while(!_called && _cur < _items) {
Marshall::HandlerFn fn = getMarshallFn(type());
(*fn)(this);
_cur++;
}
callMethod();
_cur = oldcur;
}
bool cleanup() { return true; }
};
class UnencapsulatedQObject : public QObject {
public:
QConnectionList *public_receivers(int signal) const { return receivers(signal); }
void public_activate_signal(QConnectionList *clist, QUObject *o) { activate_signal(clist, o); }
};
class EmitSignal : public Marshall {
UnencapsulatedQObject *_qobj;
int _id;
MocArgument *_args;
SV **_sp;
int _items;
int _cur;
Smoke::Stack _stack;
bool _called;
public:
EmitSignal(QObject *qobj, int id, int items, MocArgument *args, SV **sp) :
_qobj((UnencapsulatedQObject*)qobj), _id(id), _items(items), _args(args),
_sp(sp), _cur(-1), _called(false) {
_stack = new Smoke::StackItem[_items];
}
~EmitSignal() {
delete[] _stack;
}
const MocArgument &arg() { return _args[_cur]; }
SmokeType type() { return arg().st; }
Marshall::Action action() { return Marshall::FromSV; }
Smoke::StackItem &item() { return _stack[_cur]; }
SV *var() { return _sp[_cur]; }
void unsupported() {
croak("Cannot handle '%s' as signal argument", type().name());
}
Smoke *smoke() { return type().smoke(); }
void emitSignal() {
if(_called) return;
_called = true;
QConnectionList *clist = _qobj->public_receivers(_id);
if(!clist) return;
QUObject *o = new QUObject[_items + 1];
for(int i = 0; i < _items; i++) {
QUObject *po = o + i + 1;
Smoke::StackItem *si = _stack + i;
switch(_args[i].argType) {
case xmoc_bool:
static_QUType_bool.set(po, si->s_bool);
break;
case xmoc_int:
static_QUType_int.set(po, si->s_int);
break;
case xmoc_double:
static_QUType_double.set(po, si->s_double);
break;
case xmoc_charstar:
static_QUType_charstar.set(po, (char*)si->s_voidp);
break;
case xmoc_QString:
static_QUType_QString.set(po, *(QString*)si->s_voidp);
break;
default:
{
const SmokeType &t = _args[i].st;
void *p;
switch(t.elem()) {
case Smoke::t_bool:
p = &si->s_bool;
break;
case Smoke::t_char:
p = &si->s_char;
break;
case Smoke::t_uchar:
p = &si->s_uchar;
break;
case Smoke::t_short:
p = &si->s_short;
break;
case Smoke::t_ushort:
p = &si->s_ushort;
break;
case Smoke::t_int:
p = &si->s_int;
break;
case Smoke::t_uint:
p = &si->s_uint;
break;
case Smoke::t_long:
p = &si->s_long;
break;
case Smoke::t_ulong:
p = &si->s_ulong;
break;
case Smoke::t_float:
p = &si->s_float;
break;
case Smoke::t_double:
p = &si->s_double;
break;
case Smoke::t_enum:
{
// allocate a new enum value
Smoke::EnumFn fn = SmokeClass(t).enumFn();
if(!fn) {
warn("Unknown enumeration %s\n", t.name());
p = new int((int)si->s_enum);
break;
}
Smoke::Index id = t.typeId();
(*fn)(Smoke::EnumNew, id, p, si->s_enum);
(*fn)(Smoke::EnumFromLong, id, p, si->s_enum);
// FIXME: MEMORY LEAK
}
break;
case Smoke::t_class:
case Smoke::t_voidp:
p = si->s_voidp;
break;
default:
p = 0;
break;
}
static_QUType_ptr.set(po, p);
}
}
}
_qobj->public_activate_signal(clist, o);
delete[] o;
}
void next() {
int oldcur = _cur;
_cur++;
while(!_called && _cur < _items) {
Marshall::HandlerFn fn = getMarshallFn(type());
(*fn)(this);
_cur++;
}
emitSignal();
_cur = oldcur;
}
bool cleanup() { return true; }
};
class InvokeSlot : public Marshall {
QObject *_qobj;
GV *_gv;
int _items;
MocArgument *_args;
QUObject *_o;
int _cur;
bool _called;
SV **_sp;
Smoke::Stack _stack;
public:
const MocArgument &arg() { return _args[_cur]; }
SmokeType type() { return arg().st; }
Marshall::Action action() { return Marshall::ToSV; }
Smoke::StackItem &item() { return _stack[_cur]; }
SV *var() { return _sp[_cur]; }
Smoke *smoke() { return type().smoke(); }
bool cleanup() { return false; }
void unsupported() {
croak("Cannot handle '%s' as slot argument\n", type().name());
}
void copyArguments() {
for(int i = 0; i < _items; i++) {
QUObject *o = _o + i + 1;
switch(_args[i].argType) {
case xmoc_bool:
_stack[i].s_bool = static_QUType_bool.get(o);
break;
case xmoc_int:
_stack[i].s_int = static_QUType_int.get(o);
break;
case xmoc_double:
_stack[i].s_double = static_QUType_double.get(o);
break;
case xmoc_charstar:
_stack[i].s_voidp = static_QUType_charstar.get(o);
break;
case xmoc_QString:
_stack[i].s_voidp = &static_QUType_QString.get(o);
break;
default: // case xmoc_ptr:
{
const SmokeType &t = _args[i].st;
void *p = static_QUType_ptr.get(o);
switch(t.elem()) {
case Smoke::t_bool:
_stack[i].s_bool = *(bool*)p;
break;
case Smoke::t_char:
_stack[i].s_char = *(char*)p;
break;
case Smoke::t_uchar:
_stack[i].s_uchar = *(unsigned char*)p;
break;
case Smoke::t_short:
_stack[i].s_short = *(short*)p;
break;
case Smoke::t_ushort:
_stack[i].s_ushort = *(unsigned short*)p;
break;
case Smoke::t_int:
_stack[i].s_int = *(int*)p;
break;
case Smoke::t_uint:
_stack[i].s_uint = *(unsigned int*)p;
break;
case Smoke::t_long:
_stack[i].s_long = *(long*)p;
break;
case Smoke::t_ulong:
_stack[i].s_ulong = *(unsigned long*)p;
break;
case Smoke::t_float:
_stack[i].s_float = *(float*)p;
break;
case Smoke::t_double:
_stack[i].s_double = *(double*)p;
break;
case Smoke::t_enum:
{
Smoke::EnumFn fn = SmokeClass(t).enumFn();
if(!fn) {
warn("Unknown enumeration %s\n", t.name());
_stack[i].s_enum = *(int*)p;
break;
}
Smoke::Index id = t.typeId();
(*fn)(Smoke::EnumToLong, id, p, _stack[i].s_enum);
}
break;
case Smoke::t_class:
case Smoke::t_voidp:
_stack[i].s_voidp = p;
break;
}
}
}
}
}
void invokeSlot() {
dSP;
if(_called) return;
_called = true;
SP = _sp + _items - 1;
PUTBACK;
int count = call_sv((SV*)GvCV(_gv), G_SCALAR);
SPAGAIN;
SP -= count;
PUTBACK;
FREETMPS;
LEAVE;
}
void next() {
int oldcur = _cur;
_cur++;
while(!_called && _cur < _items) {
Marshall::HandlerFn fn = getMarshallFn(type());
(*fn)(this);
_cur++;
}
invokeSlot();
_cur = oldcur;
}
InvokeSlot(QObject *qobj, GV *gv, int items, MocArgument *args, QUObject *o) :
_qobj(qobj), _gv(gv), _items(items), _args(args), _o(o), _cur(-1), _called(false) {
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
EXTEND(SP, items);
PUTBACK;
_sp = SP + 1;
for(int i = 0; i < _items; i++)
_sp[i] = sv_newmortal();
_stack = new Smoke::StackItem[_items];
copyArguments();
}
~InvokeSlot() {
delete[] _stack;
}
};
class QtSmokeBinding : public SmokeBinding {
public:
QtSmokeBinding(Smoke *s) : SmokeBinding(s) {}
void deleted(Smoke::Index classId, void *ptr) {
SV *obj = getPointerObject(ptr);
smokeperl_object *o = sv_obj_info(obj);
if(do_debug && (do_debug & qtdb_gc)) {
fprintf(stderr, "%p->~%s()\n", ptr, smoke->className(classId));
}
if(!o || !o->ptr) {
return;
}
unmapPointer(o, o->classId, 0);
o->ptr = 0;
}
bool callMethod(Smoke::Index method, void *ptr, Smoke::Stack args, bool isAbstract) {
SV *obj = getPointerObject(ptr);
smokeperl_object *o = sv_obj_info(obj);
if(do_debug && (do_debug & qtdb_virtual)) fprintf(stderr, "virtual %p->%s::%s() called\n", ptr,
smoke->classes[smoke->methods[method].classId].className,
smoke->methodNames[smoke->methods[method].name]
);
if(!o) {
if(!PL_dirty && (do_debug && (do_debug & qtdb_virtual)) ) // if not in global destruction
fprintf(stderr, "Cannot find object for virtual method\n");
return false;
}
HV *stash = SvSTASH(SvRV(obj));
if(*HvNAME(stash) == ' ')
stash = gv_stashpv(HvNAME(stash) + 1, TRUE);
const char *methodName = smoke->methodNames[smoke->methods[method].name];
GV *gv = gv_fetchmethod_autoload(stash, methodName, 0);
if(!gv) return false;
VirtualMethodCall c(smoke, method, args, obj, gv);
// exception variable, just temporary
temporary_virtual_function_success = true;
c.next();
bool ret = temporary_virtual_function_success;
temporary_virtual_function_success = true;
return ret;
}
char *className(Smoke::Index classId) {
const char *className = smoke->className(classId);
char *buf = new char[strlen(className) + 6];
strcpy(buf, " Qt::");
strcat(buf, className + 1);
return buf;
}
};
// ---------------- Helpers -------------------
SV *catArguments(SV** sp, int n)
{
SV* r=newSVpvf("");
for(int i = 0; i < n; i++) {
if(i) sv_catpv(r, ", ");
if(!SvOK(sp[i])) {
sv_catpv(r, "undef");
} else if(SvROK(sp[i])) {
smokeperl_object *o = sv_obj_info(sp[i]);
if(o)
sv_catpv(r, o->smoke->className(o->classId));
else
sv_catsv(r, sp[i]);
} else {
bool isString = SvPOK(sp[i]);
STRLEN len;
char *s = SvPV(sp[i], len);
if(isString) sv_catpv(r, "'");
sv_catpvn(r, s, len > 10 ? 10 : len);
if(len > 10) sv_catpv(r, "...");
if(isString) sv_catpv(r, "'");
}
}
return r;
}
Smoke::Index package_classid(const char *p)
{
Smoke::Index *item = classcache->find(p);
if(item)
return *item;
char *nisa = new char[strlen(p)+6];
strcpy(nisa, p);
strcat(nisa, "::ISA");
AV* isa=get_av(nisa, true);
delete[] nisa;
for(int i=0; i<=av_len(isa); i++) {
SV** np = av_fetch(isa, i, 0);
if(np) {
Smoke::Index ix = package_classid(SvPV_nolen(*np));
if(ix) {
classcache->insert(p, new Smoke::Index(ix));
return ix;
}
}
}
return (Smoke::Index) 0;
}
char *get_SVt(SV *sv)
{
char *r;
if(!SvOK(sv))
r = "u";
else if(SvIOK(sv))
r = "i";
else if(SvNOK(sv))
r = "n";
else if(SvPOK(sv))
r = "s";
else if(SvROK(sv)) {
smokeperl_object *o = sv_obj_info(sv);
if(!o) {
switch (SvTYPE(SvRV(sv))) {
case SVt_PVAV:
r = "a";
break;
// case SVt_PV:
// case SVt_PVMG:
// r = "p";
default:
r = "r";
}
}
else
r = (char*)o->smoke->className(o->classId);
}
else
r = "U";
return r;
}
SV *prettyPrintMethod(Smoke::Index id) {
SV *r = newSVpvf("");
Smoke::Method &meth = qt_Smoke->methods[id];
const char *tname = qt_Smoke->types[meth.ret].name;
if(meth.flags & Smoke::mf_static) sv_catpv(r, "static ");
sv_catpvf(r, "%s ", (tname ? tname:"void"));
sv_catpvf(r, "%s::%s(", qt_Smoke->classes[meth.classId].className, qt_Smoke->methodNames[meth.name]);
for(int i = 0; i < meth.numArgs; i++) {
if(i) sv_catpv(r, ", ");
tname = qt_Smoke->types[qt_Smoke->argumentList[meth.args+i]].name;
sv_catpv(r, (tname ? tname:"void"));
}
sv_catpv(r, ")");
if(meth.flags & Smoke::mf_const) sv_catpv(r, " const");
return r;
}
// --------------- Unary Keywords && Attributes ------------------
// implements unary 'this'
XS(XS_this) {
dXSARGS;
ST(0) = sv_this;
XSRETURN(1);
}
// implements unary attributes: 'foo' means 'this->{foo}'
XS(XS_attr) {
dXSARGS;
char *key = GvNAME(CvGV(cv));
U32 klen = strlen(key);
SV **svp = 0;
if(SvROK(sv_this) && SvTYPE(SvRV(sv_this)) == SVt_PVHV) {
HV *hv = (HV*)SvRV(sv_this);
svp = hv_fetch(hv, key, klen, 1);
}
if(svp) {
ST(0) = *svp;
XSRETURN(1);
}
XSRETURN_UNDEF;
}
// implements unary SUPER attribute: 'SUPER' means ${(CopSTASH)::_INTERNAL_STATIC_}{SUPER}
XS(XS_super) {
dXSARGS;
char *key = "SUPER";
U32 klen = strlen(key);
SV **svp = 0;
if(SvROK(sv_this) && SvTYPE(SvRV(sv_this)) == SVt_PVHV) {
HV *cs = (HV*)CopSTASH(PL_curcop);
if(!cs) XSRETURN_UNDEF;
svp = hv_fetch(cs, "_INTERNAL_STATIC_", 17, 0);
if(!svp) XSRETURN_UNDEF;
cs = GvHV((GV*)*svp);
if(!cs) XSRETURN_UNDEF;
svp = hv_fetch(cs, "SUPER", 5, 0);
}
if(svp) {
ST(0) = *svp;
XSRETURN(1);
}
XSRETURN_UNDEF;
}
//---------- XS Autoload (for all functions except fully qualified statics & enums) ---------
static inline bool isQt(char *p) {
return (p[0] == 'Q' && p[1] && p[1] == 't' && ((p[2] && p[2] == ':') || !p[2]));
}
bool avoid_fetchmethod = false;
XS(XS_AUTOLOAD) {
// Err, XS autoload is borked. Lets try...
dXSARGS;
SV *sv = get_sv("Qt::AutoLoad::AUTOLOAD", TRUE);
char *package = SvPV_nolen(sv);
char *method = 0;
for(char *s = package; *s ; s++)
if(*s == ':') method = s;
if(!method) XSRETURN_NO;
*(method++ - 1) = 0; // sorry for showing off. :)
int withObject = (*package == ' ') ? 1 : 0;
int isSuper = 0;
if(withObject) {
package++;
if(*package == ' ') {
isSuper = 1;
char *super = new char[strlen(package) + 7];
package++;
strcpy(super, package);
strcat(super, "::SUPER");
package = super;
}
} else if( isQt(package) )
avoid_fetchmethod = true;
HV *stash = gv_stashpv(package, TRUE);
if(do_debug && (do_debug & qtdb_autoload))
warn("In XS Autoload for %s::%s()\n", package, method);
// check for user-defined methods in the REAL stash; skip prefix
GV *gv = 0;
if(avoid_fetchmethod)
avoid_fetchmethod = false;
else
gv = gv_fetchmethod_autoload(stash, method, 0);
// If we've made it here, we need to set sv_this
if(gv) {
if(do_debug && (do_debug & qtdb_autoload))
warn("\tfound in %s's Perl stash\n", package);
// call the defined Perl method with new 'this'
SV *old_this;
if(withObject && !isSuper) {
old_this = sv_this;
sv_this = newSVsv(ST(0));
}
ENTER;
SAVETMPS;
PUSHMARK(SP - items + withObject);
PUTBACK;
int count = call_sv((SV*)GvCV(gv), G_SCALAR|G_EVAL);
SPAGAIN;
SV *ret = newSVsv(TOPs);
SP -= count;
PUTBACK;
FREETMPS;
LEAVE;
if(withObject && !isSuper) {
SvREFCNT_dec(sv_this);
sv_this = old_this;
}
else if(isSuper)
delete[] package;
if(SvTRUE(ERRSV))
croak(SvPV_nolen(ERRSV));
ST(0) = sv_2mortal(ret);
XSRETURN(1);
}
else if(!strcmp(method, "DESTROY")) {
SV *old_this;
if(withObject && !isSuper) {
old_this = sv_this;
sv_this = newSVsv(ST(0));
}
smokeperl_object *o = sv_obj_info(sv_this);
if(!(o && o->ptr && (o->allocated || getPointerObject(o->ptr)))) {
if(isSuper)
delete[] package;
if(withObject && !isSuper) {
SvREFCNT_dec(sv_this);
sv_this = old_this;
}
XSRETURN_YES;
}
const char *key = "has been hidden";
U32 klen = 15;
SV **svp = 0;
if(SvROK(sv_this) && SvTYPE(SvRV(sv_this)) == SVt_PVHV) {
HV *hv = (HV*)SvRV(sv_this);
svp = hv_fetch(hv, key, klen, 0);
}
if(svp) {
if(isSuper)
delete[] package;
if(withObject && !isSuper) {
SvREFCNT_dec(sv_this);
sv_this = old_this;
}
XSRETURN_YES;
}
gv = gv_fetchmethod_autoload(stash, "ON_DESTROY", 0);
if( !gv )
croak( "Couldn't find ON_DESTROY method for %s=%p\n", package, o->ptr);
PUSHMARK(SP);
call_sv((SV*)GvCV(gv), G_SCALAR|G_NOARGS);
SPAGAIN;
int ret = POPi;
PUTBACK;
if(withObject && !isSuper) {
SvREFCNT_dec(sv_this);
sv_this = old_this;
}
if( do_debug && ret && (do_debug & qtdb_gc) )
fprintf(stderr, "Increasing refcount in DESTROY for %s=%p (still has a parent)\n", package, o->ptr);
} else {
if( items > 18 ) XSRETURN_NO; // current max number of args in Qt is 13.
// save the stack -- we'll need it
SV **savestack = new SV*[items+1];
SV *saveobj = ST(0);
SV *old_this;
Copy(SP - items + 1 + withObject, savestack, items-withObject, SV*);
// Get the classid (eventually converting SUPER to the right Qt class)
Smoke::Index cid = package_classid(package);
// Look in the cache
char *cname = (char*)qt_Smoke->className(cid);
int lcname = strlen(cname);
int lmethod = strlen(method);
char mcid[256];
strncpy(mcid, cname, lcname);
char *ptr = mcid + lcname;
*(ptr++) = ';';
strncpy(ptr, method, lmethod);
ptr += lmethod;
for(int i=withObject ; i<items ; i++)
{
*(ptr++) = ';';
char *t = get_SVt(ST(i));
int tlen = strlen(t);
strncpy(ptr, t, tlen );
ptr += tlen;
}
*ptr = 0;
Smoke::Index *rcid = methcache->find(mcid);
if(rcid) {
// Got a hit
_current_method = *rcid;
if(withObject && !isSuper) {
old_this = sv_this;
sv_this = newSVsv(ST(0));
}
}
else {
// Find the C++ method to call. I'll do that from Perl for now
ENTER;
SAVETMPS;
PUSHMARK(SP - items + withObject);
EXTEND(SP, 3);
PUSHs(sv_2mortal(newSViv((IV)cid)));
PUSHs(sv_2mortal(newSVpv(method, 0)));
PUSHs(sv_2mortal(newSVpv(package, 0)));
PUTBACK;
if(withObject && !isSuper) {
old_this = sv_this;
sv_this = newSVsv(saveobj);
}
call_pv("Qt::_internal::do_autoload", G_DISCARD|G_EVAL);
FREETMPS;
LEAVE;
// Restore sv_this on error, so that eval{ } works
if(SvTRUE(ERRSV)) {
if(withObject && !isSuper) {
SvREFCNT_dec(sv_this);
sv_this = old_this;
}
else if(isSuper)
delete[] package;
delete[] savestack;
croak(SvPV_nolen(ERRSV));
}
// Success. Cache result.
methcache->insert(mcid, new Smoke::Index(_current_method));
}
// FIXME: I shouldn't have to set the current object
{
smokeperl_object *o = sv_obj_info(sv_this);
if(o && o->ptr) {
_current_object = o->ptr;
_current_object_class = o->classId;
} else {
_current_object = 0;
}
}
// honor debugging channels
if(do_debug && (do_debug & qtdb_calls)) {
warn("Calling method\t%s\n", SvPV_nolen(sv_2mortal(prettyPrintMethod(_current_method))));
if(do_debug & qtdb_verbose)
warn("with arguments (%s)\n", SvPV_nolen(sv_2mortal(catArguments(savestack, items-withObject))));
}
MethodCall c(qt_Smoke, _current_method, savestack, items-withObject);
c.next();
if(savestack)
delete[] savestack;
if(withObject && !isSuper) {
SvREFCNT_dec(sv_this);
sv_this = old_this;
}
else if(isSuper)
delete[] package;
SV *ret = c.var();
SvREFCNT_inc(ret);
ST(0) = sv_2mortal(ret);
XSRETURN(1);
}
if(isSuper)
delete[] package;
XSRETURN_YES;
}
//----------------- Sig/Slot ------------------
MocArgument *getmetainfo(GV *gv, const char *name, int &offset, int &index, int &argcnt) {
char *signalname = GvNAME(gv);
HV *stash = GvSTASH(gv);
// $meta = $stash->{META}
SV **svp = hv_fetch(stash, "META", 4, 0);
if(!svp) return 0;
HV *hv = GvHV((GV*)*svp);
if(!hv) return 0;
// $metaobject = $meta->{object}
// aka. Class->staticMetaObject
svp = hv_fetch(hv, "object", 6, 0);
if(!svp) return 0;
smokeperl_object *ometa = sv_obj_info(*svp);
if(!ometa) return 0;
QMetaObject *metaobject = (QMetaObject*)ometa->ptr;
offset = metaobject->signalOffset();
// $signals = $meta->{signal}
U32 len = strlen(name);
svp = hv_fetch(hv, name, len, 0);
if(!svp) return 0;
HV *signalshv = (HV*)SvRV(*svp);
// $signal = $signals->{$signalname}
len = strlen(signalname);
svp = hv_fetch(signalshv, signalname, len, 0);
if(!svp) return 0;
HV *signalhv = (HV*)SvRV(*svp);
// $index = $signal->{index}
svp = hv_fetch(signalhv, "index", 5, 0);
if(!svp) return 0;;
index = SvIV(*svp);
// $argcnt = $signal->{argcnt}
svp = hv_fetch(signalhv, "argcnt", 6, 0);
if(!svp) return 0;
argcnt = SvIV(*svp);
// $mocargs = $signal->{mocargs}
svp = hv_fetch(signalhv, "mocargs", 7, 0);
if(!svp) return 0;
MocArgument *args = (MocArgument*)SvIV(*svp);
return args;
}
MocArgument *getslotinfo(GV *gv, int id, char *&slotname, int &index, int &argcnt, bool isSignal = false) {
HV *stash = GvSTASH(gv);
// $meta = $stash->{META}
SV **svp = hv_fetch(stash, "META", 4, 0);
if(!svp) return 0;
HV *hv = GvHV((GV*)*svp);
if(!hv) return 0;
// $metaobject = $meta->{object}
// aka. Class->staticMetaObject
svp = hv_fetch(hv, "object", 6, 0);
if(!svp) return 0;
smokeperl_object *ometa = sv_obj_info(*svp);
if(!ometa) return 0;
QMetaObject *metaobject = (QMetaObject*)ometa->ptr;
int offset = isSignal ? metaobject->signalOffset() : metaobject->slotOffset();
index = id - offset; // where we at
// FIXME: make slot inheritance work
if(index < 0) return 0;
// $signals = $meta->{signal}
const char *key = isSignal ? "signals" : "slots";
svp = hv_fetch(hv, key, strlen(key), 0);
if(!svp) return 0;
AV *signalsav = (AV*)SvRV(*svp);
svp = av_fetch(signalsav, index, 0);
if(!svp) return 0;
HV *signalhv = (HV*)SvRV(*svp);
// $argcnt = $signal->{argcnt}
svp = hv_fetch(signalhv, "argcnt", 6, 0);
if(!svp) return 0;
argcnt = SvIV(*svp);
// $mocargs = $signal->{mocargs}
svp = hv_fetch(signalhv, "mocargs", 7, 0);
if(!svp) return 0;
MocArgument *args = (MocArgument*)SvIV(*svp);
svp = hv_fetch(signalhv, "name", 4, 0);
if(!svp) return 0;
slotname = SvPV_nolen(*svp);
return args;
}
XS(XS_signal) {
dXSARGS;
smokeperl_object *o = sv_obj_info(sv_this);
QObject *qobj = (QObject*)o->smoke->cast(
o->ptr,
o->classId,
o->smoke->idClass("QObject")
);
if(qobj->signalsBlocked()) XSRETURN_UNDEF;
int offset;
int index;
int argcnt;
MocArgument *args;
args = getmetainfo(CvGV(cv), "signal", offset, index, argcnt);
if(!args) XSRETURN_UNDEF;
// Okay, we have the signal info. *whew*
if(items < argcnt)
croak("Insufficient arguments to emit signal");
EmitSignal signal(qobj, offset + index, argcnt, args, &ST(0));
signal.next();
XSRETURN_UNDEF;
}
XS(XS_qt_invoke) {
dXSARGS;
// Arguments: int id, QUObject *o
int id = SvIV(ST(0));
QUObject *_o = (QUObject*)SvIV(SvRV(ST(1)));
smokeperl_object *o = sv_obj_info(sv_this);
QObject *qobj = (QObject*)o->smoke->cast(
o->ptr,
o->classId,
o->smoke->idClass("QObject")
);
// Now, I need to find out if this means me
int index;
char *slotname;
int argcnt;
MocArgument *args;
bool isSignal = !strcmp(GvNAME(CvGV(cv)), "qt_emit");
args = getslotinfo(CvGV(cv), id, slotname, index, argcnt, isSignal);
if(!args) {
// throw an exception - evil style
temporary_virtual_function_success = false;
XSRETURN_UNDEF;
}
HV *stash = GvSTASH(CvGV(cv));
GV *gv = gv_fetchmethod_autoload(stash, slotname, 0);
if(!gv) XSRETURN_UNDEF;
InvokeSlot slot(qobj, gv, argcnt, args, _o);
slot.next();
XSRETURN_UNDEF;
}
// ------------------- Tied types ------------------------
MODULE = Qt PACKAGE = Qt::_internal::QString
PROTOTYPES: DISABLE
SV*
FETCH(obj)
SV* obj
CODE:
if (!SvROK(obj))
croak("?");
IV tmp = SvIV((SV*)SvRV(obj));
QString *s = (QString*) tmp;
RETVAL = newSV(0);
if( s )
{
if(!(IN_BYTES))
{
sv_setpv_mg(RETVAL, (const char *)s->utf8());
SvUTF8_on(RETVAL);
}
else if(IN_LOCALE)
sv_setpv_mg(RETVAL, (const char *)s->local8Bit());
else
sv_setpv_mg(RETVAL, (const char *)s->latin1());
}
else
sv_setsv_mg(RETVAL, &PL_sv_undef);
OUTPUT:
RETVAL
void
STORE(obj,what)
SV* obj
SV* what
CODE:
if (!SvROK(obj))
croak("?");
IV tmp = SvIV((SV*)SvRV(obj));
QString *s = (QString*) tmp;
s->truncate(0);
if(SvOK(what)) {
if(SvUTF8(what))
s->append(QString::fromUtf8(SvPV_nolen(what)));
else if(IN_LOCALE)
s->append(QString::fromLocal8Bit(SvPV_nolen(what)));
else
s->append(QString::fromLatin1(SvPV_nolen(what)));
}
void
DESTROY(obj)
SV* obj
CODE:
if (!SvROK(obj))
croak("?");
IV tmp = SvIV((SV*)SvRV(obj));
QString *s = (QString*) tmp;
delete s;
MODULE = Qt PACKAGE = Qt::_internal::QByteArray
PROTOTYPES: DISABLE
SV*
FETCH(obj)
SV* obj
CODE:
if (!SvROK(obj))
croak("?");
IV tmp = SvIV((SV*)SvRV(obj));
QByteArray *s = (QByteArray*) tmp;
RETVAL = newSV(0);
if( s )
{
sv_setpvn_mg(RETVAL, s->data(), s->size());
}
else
sv_setsv_mg(RETVAL, &PL_sv_undef);
OUTPUT:
RETVAL
void
STORE(obj,what)
SV* obj
SV* what
CODE:
if (!SvROK(obj))
croak("?");
IV tmp = SvIV((SV*)SvRV(obj));
QByteArray *s = (QByteArray*) tmp;
if(SvOK(what)) {
STRLEN len;
char* tmp2 = SvPV(what, len);
s->resize(len);
Copy((void*)tmp2, (void*)s->data(), len, char);
} else
s->truncate(0);
void
DESTROY(obj)
SV* obj
CODE:
if (!SvROK(obj))
croak("?");
IV tmp = SvIV((SV*)SvRV(obj));
QByteArray *s = (QByteArray*) tmp;
delete s;
MODULE = Qt PACKAGE = Qt::_internal::QRgbStar
PROTOTYPES: DISABLE
SV*
FETCH(obj)
SV* obj
CODE:
if (!SvROK(obj))
croak("?");
IV tmp = SvIV((SV*)SvRV(obj));
QRgb *s = (QRgb*) tmp;
AV* ar = newAV();
RETVAL = newRV_noinc((SV*)ar);
for(int i=0; s[i] ; i++)
{
SV *item = newSViv((IV)s[i]);
if(!av_store(ar, (I32)i, item))
SvREFCNT_dec( item );
}
OUTPUT:
RETVAL
void
STORE(obj,sv)
SV* obj
SV* sv
CODE:
if (!SvROK(obj))
croak("?");
IV tmp = SvIV((SV*)SvRV(obj));
QRgb *s = (QRgb*) tmp;
if(!SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV ||
av_len((AV*)SvRV(sv)) < 0) {
s = new QRgb[1];
s[0] = 0;
sv_setref_pv(obj, "Qt::_internal::QRgbStar", (void*)s);
return;
}
AV *list = (AV*)SvRV(sv);
int count = av_len(list);
s = new QRgb[count + 2];
int i;
for(i = 0; i <= count; i++) {
SV **item = av_fetch(list, i, 0);
if(!item || !SvOK(*item)) {
s[i] = 0;
continue;
}
s[i] = SvIV(*item);
}
s[i] = 0;
sv_setref_pv(obj, "Qt::_internal::QRgbStar", (void*)s);
void
DESTROY(obj)
SV* obj
CODE:
if (!SvROK(obj))
croak("?");
IV tmp = SvIV((SV*)SvRV(obj));
QRgb *s = (QRgb*) tmp;
delete[] s;
# --------------- XSUBS for Qt::_internal::* helpers ----------------
MODULE = Qt PACKAGE = Qt::_internal
PROTOTYPES: DISABLE
void
getMethStat()
PPCODE:
XPUSHs(sv_2mortal(newSViv((int)methcache->size())));
XPUSHs(sv_2mortal(newSViv((int)methcache->count())));
void
getClassStat()
PPCODE:
XPUSHs(sv_2mortal(newSViv((int)classcache->size())));
XPUSHs(sv_2mortal(newSViv((int)classcache->count())));
void
getIsa(classId)
int classId
PPCODE:
Smoke::Index *parents =
qt_Smoke->inheritanceList +
qt_Smoke->classes[classId].parents;
while(*parents)
XPUSHs(sv_2mortal(newSVpv(qt_Smoke->classes[*parents++].className, 0)));
void
dontRecurse()
CODE:
avoid_fetchmethod = true;
void *
sv_to_ptr(sv)
SV* sv
void *
allocateMocArguments(count)
int count
CODE:
RETVAL = (void*)new MocArgument[count + 1];
OUTPUT:
RETVAL
void
setMocType(ptr, idx, name, static_type)
void *ptr
int idx
char *name
char *static_type
CODE:
Smoke::Index typeId = qt_Smoke->idType(name);
if(!typeId) XSRETURN_NO;
MocArgument *arg = (MocArgument*)ptr;
arg[idx].st.set(qt_Smoke, typeId);
if(!strcmp(static_type, "ptr"))
arg[idx].argType = xmoc_ptr;
else if(!strcmp(static_type, "bool"))
arg[idx].argType = xmoc_bool;
else if(!strcmp(static_type, "int"))
arg[idx].argType = xmoc_int;
else if(!strcmp(static_type, "double"))
arg[idx].argType = xmoc_double;
else if(!strcmp(static_type, "char*"))
arg[idx].argType = xmoc_charstar;
else if(!strcmp(static_type, "QString"))
arg[idx].argType = xmoc_QString;
XSRETURN_YES;
void
installsignal(name)
char *name
CODE:
char *file = __FILE__;
newXS(name, XS_signal, file);
void
installqt_invoke(name)
char *name
CODE:
char *file = __FILE__;
newXS(name, XS_qt_invoke, file);
void
setDebug(on)
int on
CODE:
do_debug = on;
int
debug()
CODE:
RETVAL = do_debug;
OUTPUT:
RETVAL
char *
getTypeNameOfArg(method, idx)
int method
int idx
CODE:
Smoke::Method &m = qt_Smoke->methods[method];
Smoke::Index *args = qt_Smoke->argumentList + m.args;
RETVAL = (char*)qt_Smoke->types[args[idx]].name;
OUTPUT:
RETVAL
int
classIsa(className, base)
char *className
char *base
CODE:
RETVAL = isDerivedFrom(qt_Smoke, className, base, 0);
OUTPUT:
RETVAL
void
insert_pclassid(p, ix)
char *p
int ix
CODE:
classcache->insert(p, new Smoke::Index((Smoke::Index)ix));
int
find_pclassid(p)
char *p
CODE:
Smoke::Index *r = classcache->find(p);
if(r)
RETVAL = (int)*r;
else
RETVAL = 0;
OUTPUT:
RETVAL
void
insert_mcid(mcid, ix)
char *mcid
int ix
CODE:
methcache->insert(mcid, new Smoke::Index((Smoke::Index)ix));
int
find_mcid(mcid)
char *mcid
CODE:
Smoke::Index *r = methcache->find(mcid);
if(r)
RETVAL = (int)*r;
else
RETVAL = 0;
OUTPUT:
RETVAL
char *
getSVt(sv)
SV *sv
CODE:
RETVAL=get_SVt(sv);
OUTPUT:
RETVAL
void *
make_QUParameter(name, type, extra, inout)
char *name
char *type
SV *extra
int inout
CODE:
QUParameter *p = new QUParameter;
p->name = new char[strlen(name) + 1];
strcpy((char*)p->name, name);
if(!strcmp(type, "bool"))
p->type = &static_QUType_bool;
else if(!strcmp(type, "int"))
p->type = &static_QUType_int;
else if(!strcmp(type, "double"))
p->type = &static_QUType_double;
else if(!strcmp(type, "char*") || !strcmp(type, "const char*"))
p->type = &static_QUType_charstar;
else if(!strcmp(type, "QString") || !strcmp(type, "QString&") ||
!strcmp(type, "const QString") || !strcmp(type, "const QString&"))
p->type = &static_QUType_QString;
else
p->type = &static_QUType_ptr;
// Lacking support for several types. Evil.
p->inOut = inout;
p->typeExtra = 0;
RETVAL = (void*)p;
OUTPUT:
RETVAL
void *
make_QMetaData(name, method)
char *name
void *method
CODE:
QMetaData *m = new QMetaData; // will be deleted
m->name = new char[strlen(name) + 1];
strcpy((char*)m->name, name);
m->method = (QUMethod*)method;
m->access = QMetaData::Public;
RETVAL = m;
OUTPUT:
RETVAL
void *
make_QUMethod(name, params)
char *name
SV *params
CODE:
QUMethod *m = new QUMethod; // permanent memory allocation
m->name = new char[strlen(name) + 1]; // this too
strcpy((char*)m->name, name);
m->count = 0;
m->parameters = 0;
if(SvOK(params) && SvRV(params)) {
AV *av = (AV*)SvRV(params);
m->count = av_len(av) + 1;
if(m->count > 0) {
m->parameters = new QUParameter[m->count];
for(int i = 0; i < m->count; i++) {
SV *sv = av_shift(av);
if(!SvOK(sv))
croak("Invalid paramater for QUMethod\n");
QUParameter *p = (QUParameter*)SvIV(sv);
SvREFCNT_dec(sv);
((QUParameter*)m->parameters)[i] = *p;
delete p;
}
} else
m->count = 0;
}
RETVAL = m;
OUTPUT:
RETVAL
void *
make_QMetaData_tbl(list)
SV *list
CODE:
RETVAL = 0;
if(SvOK(list) && SvRV(list)) {
AV *av = (AV*)SvRV(list);
int count = av_len(av) + 1;
QMetaData *m = new QMetaData[count];
for(int i = 0; i < count; i++) {
SV *sv = av_shift(av);
if(!SvOK(sv))
croak("Invalid metadata\n");
QMetaData *old = (QMetaData*)SvIV(sv);
SvREFCNT_dec(sv);
m[i] = *old;
delete old;
}
RETVAL = (void*)m;
}
OUTPUT:
RETVAL
SV *
make_metaObject(className, parent, slot_tbl, slot_count, signal_tbl, signal_count)
char *className
SV *parent
void *slot_tbl
int slot_count
void *signal_tbl
int signal_count
CODE:
smokeperl_object *po = sv_obj_info(parent);
if(!po || !po->ptr) croak("Cannot create metaObject\n");
QMetaObject *meta = QMetaObject::new_metaobject(
className, (QMetaObject*)po->ptr,
(const QMetaData*)slot_tbl, slot_count, // slots
(const QMetaData*)signal_tbl, signal_count, // signals
0, 0, // properties
0, 0, // enums
0, 0);
// this object-creation code is so, so wrong here
HV *hv = newHV();
SV *obj = newRV_noinc((SV*)hv);
smokeperl_object o;
o.smoke = qt_Smoke;
o.classId = qt_Smoke->idClass("QMetaObject");
o.ptr = meta;
o.allocated = true;
sv_magic((SV*)hv, sv_qapp, '~', (char*)&o, sizeof(o));
MAGIC *mg = mg_find((SV*)hv, '~');
mg->mg_virtual = &vtbl_smoke;
char *buf = qt_Smoke->binding->className(o.classId);
sv_bless(obj, gv_stashpv(buf, TRUE));
delete[] buf;
RETVAL = obj;
OUTPUT:
RETVAL
void
dumpObjects()
CODE:
hv_iterinit(pointer_map);
HE *e;
while(e = hv_iternext(pointer_map)) {
STRLEN len;
SV *sv = HeVAL(e);
printf("key = %s, refcnt = %d, weak = %d, ref? %d\n", HePV(e, len), SvREFCNT(sv), SvWEAKREF(sv), SvROK(sv)?1:0);
if(SvRV(sv))
printf("REFCNT = %d\n", SvREFCNT(SvRV(sv)));
//SvREFCNT_dec(HeVAL(e));
//HeVAL(e) = &PL_sv_undef;
}
void
dangle(obj)
SV *obj
CODE:
if(SvRV(obj))
SvREFCNT_inc(SvRV(obj));
void
setAllocated(obj, b)
SV *obj
bool b
CODE:
smokeperl_object *o = sv_obj_info(obj);
if(o) {
o->allocated = b;
}
void
setqapp(obj)
SV *obj
CODE:
if(!obj || !SvROK(obj))
croak("Invalid Qt::Application object. Couldn't set Qt::app()\n");
sv_qapp = SvRV(obj);
void
setThis(obj)
SV *obj
CODE:
sv_setsv_mg(sv_this, obj);
void
deleteObject(obj)
SV *obj
CODE:
smokeperl_object *o = sv_obj_info(obj);
if(!o) { XSRETURN_EMPTY; }
QObject *qobj = (QObject*)o->smoke->cast(o->ptr, o->classId, o->smoke->idClass("QObject"));
delete qobj;
void
mapObject(obj)
SV *obj
CODE:
smokeperl_object *o = sv_obj_info(obj);
if(!o)
XSRETURN_EMPTY;
SmokeClass c( o->smoke, o->classId );
if(!c.hasVirtual() ) {
XSRETURN_EMPTY;
}
mapPointer(obj, o, pointer_map, o->classId, 0);
bool
isQObject(obj)
SV *obj
CODE:
RETVAL = 0;
smokeperl_object *o = sv_obj_info(obj);
if(o && isQObject(o->smoke, o->classId))
RETVAL = 1;
OUTPUT:
RETVAL
bool
isValidAllocatedPointer(obj)
SV *obj
CODE:
RETVAL = 0;
smokeperl_object *o = sv_obj_info(obj);
if(o && o->ptr && o->allocated)
RETVAL = 1;
OUTPUT:
RETVAL
SV*
findAllocatedObjectFor(obj)
SV *obj
CODE:
RETVAL = &PL_sv_undef;
smokeperl_object *o = sv_obj_info(obj);
SV *ret;
if(o && o->ptr && (ret = getPointerObject(o->ptr)))
RETVAL = ret;
OUTPUT:
RETVAL
SV *
getGV(cv)
SV *cv
CODE:
RETVAL = (SvROK(cv) && (SvTYPE(SvRV(cv))==SVt_PVCV) ?
SvREFCNT_inc(CvGV((CV*)SvRV(cv))) : &PL_sv_undef);
OUTPUT:
RETVAL
int
idClass(name)
char *name
CODE:
RETVAL = qt_Smoke->idClass(name);
OUTPUT:
RETVAL
int
idMethodName(name)
char *name
CODE:
RETVAL = qt_Smoke->idMethodName(name);
OUTPUT:
RETVAL
int
idMethod(idclass, idmethodname)
int idclass
int idmethodname
CODE:
RETVAL = qt_Smoke->idMethod(idclass, idmethodname);
OUTPUT:
RETVAL
void
findMethod(c, name)
char *c
char *name
PPCODE:
Smoke::Index meth = qt_Smoke->findMethod(c, name);
// printf("DAMNIT on %s::%s => %d\n", c, name, meth);
if(!meth) {
// empty list
} else if(meth > 0) {
Smoke::Index i = qt_Smoke->methodMaps[meth].method;
if(!i) { // shouldn't happen
croak("Corrupt method %s::%s", c, name);
} else if(i > 0) { // single match
PUSHs(sv_2mortal(newSViv(
(IV)qt_Smoke->methodMaps[meth].method
)));
} else { // multiple match
i = -i; // turn into ambiguousMethodList index
while(qt_Smoke->ambiguousMethodList[i]) {
PUSHs(sv_2mortal(newSViv(
(IV)qt_Smoke->ambiguousMethodList[i]
)));
i++;
}
}
}
void
findMethodFromIds(idclass, idmethodname)
int idclass
int idmethodname
PPCODE:
Smoke::Index meth = qt_Smoke->findMethod(idclass, idmethodname);
if(!meth) {
// empty list
} else if(meth > 0) {
Smoke::Index i = qt_Smoke->methodMaps[meth].method;
if(i >= 0) { // single match
PUSHs(sv_2mortal(newSViv((IV)i)));
} else { // multiple match
i = -i; // turn into ambiguousMethodList index
while(qt_Smoke->ambiguousMethodList[i]) {
PUSHs(sv_2mortal(newSViv(
(IV)qt_Smoke->ambiguousMethodList[i]
)));
i++;
}
}
}
# findAllMethods(classid [, startingWith]) : returns { "mungedName" => [index in methods, ...], ... }
HV*
findAllMethods(classid, ...)
SV* classid
CODE:
RETVAL=newHV();
if(SvIOK(classid)) {
Smoke::Index c = (Smoke::Index) SvIV(classid);
char * pat = 0L;
if(items > 1 && SvPOK(ST(1)))
pat = SvPV_nolen(ST(1));
Smoke::Index imax = qt_Smoke->numMethodMaps;
Smoke::Index imin = 0, icur = -1, methmin = 0, methmax = 0;
int icmp = -1;
while(imax >= imin) {
icur = (imin + imax) / 2;
icmp = qt_Smoke->leg(qt_Smoke->methodMaps[icur].classId, c);
if(!icmp) {
Smoke::Index pos = icur;
while(icur && qt_Smoke->methodMaps[icur-1].classId == c)
icur --;
methmin = icur;
icur = pos;
while(icur < imax && qt_Smoke->methodMaps[icur+1].classId == c)
icur ++;
methmax = icur;
break;
}
if (icmp > 0)
imax = icur - 1;
else
imin = icur + 1;
}
if(!icmp) {
for(Smoke::Index i=methmin ; i <= methmax ; i++) {
Smoke::Index m = qt_Smoke->methodMaps[i].name;
if(!pat || !strncmp(qt_Smoke->methodNames[m], pat, strlen(pat))) {
Smoke::Index ix= qt_Smoke->methodMaps[i].method;
AV* meths = newAV();
if(ix >= 0) { // single match
av_push(meths, newSViv((IV)ix));
} else { // multiple match
ix = -ix; // turn into ambiguousMethodList index
while(qt_Smoke->ambiguousMethodList[ix]) {
av_push(meths, newSViv((IV)qt_Smoke->ambiguousMethodList[ix]));
ix++;
}
}
hv_store(RETVAL, qt_Smoke->methodNames[m],strlen(qt_Smoke->methodNames[m]),newRV_inc((SV*)meths),0);
}
}
}
}
OUTPUT:
RETVAL
SV *
dumpCandidates(rmeths)
SV *rmeths
CODE:
if(SvROK(rmeths) && SvTYPE(SvRV(rmeths)) == SVt_PVAV) {
AV *methods = (AV*)SvRV(rmeths);
SV *errmsg = newSVpvf("");
for(int i = 0; i <= av_len(methods); i++) {
sv_catpv(errmsg, "\t");
IV id = SvIV(*(av_fetch(methods, i, 0)));
Smoke::Method &meth = qt_Smoke->methods[id];
const char *tname = qt_Smoke->types[meth.ret].name;
if(meth.flags & Smoke::mf_static) sv_catpv(errmsg, "static ");
sv_catpvf(errmsg, "%s ", (tname ? tname:"void"));
sv_catpvf(errmsg, "%s::%s(", qt_Smoke->classes[meth.classId].className, qt_Smoke->methodNames[meth.name]);
for(int i = 0; i < meth.numArgs; i++) {
if(i) sv_catpv(errmsg, ", ");
tname = qt_Smoke->types[qt_Smoke->argumentList[meth.args+i]].name;
sv_catpv(errmsg, (tname ? tname:"void"));
}
sv_catpv(errmsg, ")");
if(meth.flags & Smoke::mf_const) sv_catpv(errmsg, " const");
sv_catpv(errmsg, "\n");
}
RETVAL=errmsg;
}
else
RETVAL=newSVpvf("");
OUTPUT:
RETVAL
SV *
catArguments(r_args)
SV* r_args
CODE:
RETVAL=newSVpvf("");
if(SvROK(r_args) && SvTYPE(SvRV(r_args)) == SVt_PVAV) {
AV* args=(AV*)SvRV(r_args);
for(int i = 0; i <= av_len(args); i++) {
SV **arg=av_fetch(args, i, 0);
if(i) sv_catpv(RETVAL, ", ");
if(!arg || !SvOK(*arg)) {
sv_catpv(RETVAL, "undef");
} else if(SvROK(*arg)) {
smokeperl_object *o = sv_obj_info(*arg);
if(o)
sv_catpv(RETVAL, o->smoke->className(o->classId));
else
sv_catsv(RETVAL, *arg);
} else {
bool isString = SvPOK(*arg);
STRLEN len;
char *s = SvPV(*arg, len);
if(isString) sv_catpv(RETVAL, "'");
sv_catpvn(RETVAL, s, len > 10 ? 10 : len);
if(len > 10) sv_catpv(RETVAL, "...");
if(isString) sv_catpv(RETVAL, "'");
}
}
}
OUTPUT:
RETVAL
SV *
callMethod(...)
PPCODE:
if(_current_method) {
MethodCall c(qt_Smoke, _current_method, &ST(0), items);
c.next();
SV *ret = c.var();
SvREFCNT_inc(ret);
PUSHs(sv_2mortal(ret));
} else
PUSHs(sv_newmortal());
bool
isObject(obj)
SV *obj
CODE:
RETVAL = sv_to_ptr(obj) ? TRUE : FALSE;
OUTPUT:
RETVAL
void
setCurrentMethod(meth)
int meth
CODE:
// FIXME: damn, this is lame, and it doesn't handle ambiguous methods
_current_method = meth; //qt_Smoke->methodMaps[meth].method;
SV *
getClassList()
CODE:
AV *av = newAV();
for(int i = 1; i <= qt_Smoke->numClasses; i++) {
//printf("%s => %d\n", qt_Smoke->classes[i].className, i);
av_push(av, newSVpv(qt_Smoke->classes[i].className, 0));
// hv_store(hv, qt_Smoke->classes[i].className, 0, newSViv(i), 0);
}
RETVAL = newRV((SV*)av);
OUTPUT:
RETVAL
void
installthis(package)
char *package
CODE:
if(!package) XSRETURN_EMPTY;
char *name = new char[strlen(package) + 7];
char *file = __FILE__;
strcpy(name, package);
strcat(name, "::this");
// *{ $name } = sub () : lvalue;
CV *thissub = newXS(name, XS_this, file);
sv_setpv((SV*)thissub, ""); // sub this () : lvalue;
delete[] name;
void
installattribute(package, name)
char *package
char *name
CODE:
if(!package || !name) XSRETURN_EMPTY;
char *attr = new char[strlen(package) + strlen(name) + 3];
sprintf(attr, "%s::%s", package, name);
char *file = __FILE__;
// *{ $attr } = sub () : lvalue;
CV *attrsub = newXS(attr, XS_attr, file);
sv_setpv((SV*)attrsub, "");
CvLVALUE_on(attrsub);
CvNODEBUG_on(attrsub);
delete[] attr;
void
installsuper(package)
char *package
CODE:
if(!package) XSRETURN_EMPTY;
char *attr = new char[strlen(package) + 8];
sprintf(attr, "%s::SUPER", package);
char *file = __FILE__;
CV *attrsub = newXS(attr, XS_super, file);
sv_setpv((SV*)attrsub, "");
delete[] attr;
void
installautoload(package)
char *package
CODE:
if(!package) XSRETURN_EMPTY;
char *autoload = new char[strlen(package) + 11];
strcpy(autoload, package);
strcat(autoload, "::_UTOLOAD");
char *file = __FILE__;
// *{ $package."::AUTOLOAD" } = XS_AUTOLOAD
newXS(autoload, XS_AUTOLOAD, file);
delete[] autoload;
# ----------------- XSUBS for Qt:: -----------------
MODULE = Qt PACKAGE = Qt
SV *
this()
CODE:
RETVAL = newSVsv(sv_this);
OUTPUT:
RETVAL
SV *
app()
CODE:
RETVAL = newRV_inc(sv_qapp);
OUTPUT:
RETVAL
SV *
version()
CODE:
RETVAL = newSVpv(QT_VERSION_STR,0);
OUTPUT:
RETVAL
BOOT:
init_qt_Smoke();
qt_Smoke->binding = new QtSmokeBinding(qt_Smoke);
install_handlers(Qt_handlers);
pointer_map = newHV();
sv_this = newSV(0);
methcache = new QAsciiDict<Smoke::Index>(1187);
classcache = new QAsciiDict<Smoke::Index>(827);
methcache->setAutoDelete(1);
classcache->setAutoDelete(1);
|