9
9
*/
10
10
11
11
#define NEED_sv_2pv_flags
12
+ #define NEED_newSVpvn_share
12
13
#include "ppport.h"
13
14
14
15
/* see https://rt.cpan.org/Ticket/Display.html?id=80217
20
21
# define _alloca (size ) __builtin_alloca(size)
21
22
#endif
22
23
24
+ /* old (5.8 ish) strawberry perls/Mingws somehow dont ever include malloc.h from
25
+ perl.h, so this include is needed for alloca */
26
+ #include <malloc.h>
27
+
23
28
/* some Mingw GCCs use Static TLS on all DLLs, DisableThreadLibraryCalls fails
24
29
if DLL has Static TLS, todo, figure out how to disable Static TLS on Mingw
25
30
Win32::API never uses it, also Win32::API never uses C++ish exception handling
44
49
45
50
// #define WIN32_API_DEBUG
46
51
52
+ #ifdef WIN32_API_DEBUG
53
+ # define WIN32_API_DEBUGM (x ) x
54
+ #else
55
+ # define WIN32_API_DEBUGM (x )
56
+ #endif
57
+
58
+
59
+ /* turns on profiling, use only for benchmark.t, DO NOT ENABLE in CPAN RELEASE
60
+ not all return paths in Call() get the current time (incomplete
61
+ implementation), VC only
62
+ */
63
+ //#define WIN32_API_PROF
64
+
65
+ #ifdef WIN32_API_PROF
66
+ # define WIN32_API_PROFF (x ) x
67
+ #else
68
+ # define WIN32_API_PROFF (x )
69
+ #endif
70
+
71
+ #ifdef WIN32_API_PROF
72
+ LARGE_INTEGER my_freq = {0 };
73
+ LARGE_INTEGER start = {0 };
74
+ LARGE_INTEGER loopstart = {0 };
75
+ LARGE_INTEGER Call_asm_b4 = {0 };
76
+ LARGE_INTEGER Call_asm_after = {0 };
77
+ LARGE_INTEGER return_time = {0 };
78
+ LARGE_INTEGER return_time2 = {0 };
79
+ # ifndef WIN64
80
+ __declspec( naked ) unsigned __int64 rdtsc () {
81
+ __asm
82
+ {
83
+ mov eax , 80000000 h
84
+ push ebx
85
+ cpuid
86
+ _emit 0xf
87
+ _emit 0x31
88
+ pop ebx
89
+ retn
90
+ }
91
+ }
92
+ /* note: not CPU affinity locked on x86, visually discard high time iternations */
93
+ # define W32A_Prof_GT (x ) ((x)->QuadPart = rdtsc())
94
+ # else
95
+ # define W32A_Prof_GT (x ) (QueryPerformanceCounter(x))
96
+ # endif
97
+ #endif
98
+
47
99
#ifdef _WIN64
48
100
typedef unsigned long long long_ptr ;
49
101
#else
@@ -104,6 +156,22 @@ union {
104
156
unsigned char t ; //1 bytes, union is 8 bytes, put last to avoid padding
105
157
} APIPARAM ;
106
158
159
+ /* a version of APIPARAM without a "t" type member */
160
+ typedef struct {
161
+ union {
162
+ LPBYTE b ;
163
+ char c ;
164
+ short s ;
165
+ char * p ;
166
+ long_ptr l ; // 4 bytes on 32bit; 8 bytes on 64bbit; not sure if it is correct
167
+ float f ;
168
+ double d ;
169
+ #ifdef T_QUAD
170
+ __int64 q ;
171
+ #endif
172
+ };
173
+ } APIPARAM_U ;
174
+
107
175
typedef struct {
108
176
SV * object ;
109
177
int size ;
@@ -114,9 +182,21 @@ typedef struct {
114
182
} APICALLBACK ;
115
183
116
184
#define STATIC_ASSERT (expr ) ((void)sizeof(char[1 - 2*!!!(expr)]))
185
+ /*
186
+ because of unknown alignment where the sentinal is placed after the PV
187
+ buffer, put 2 wide nulls, some permutation will be 1 aligned wide null char
117
188
118
- //because of unknown alignment, put 2 wide nulls,
119
- //some permutation will be 1 wide null char
189
+ http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28679 bug on Strawberry Perl
190
+ 5.8.9 which includes "gcc (GCC) 3.4.5 (mingw-vista special r3)", reported as
191
+
192
+ In file included from API.c:28:
193
+ API.h:122: warning: malformed '#pragma pack(push[, id], <n>)' - ignored
194
+ API.h:130: warning: #pragma pack (pop) encountered without matching #pragma pack
195
+ (push, <n>)
196
+
197
+ This causes 4 extra unused padding bytes to be placed after null2, which can
198
+ be a performance degradation
199
+ */
120
200
#pragma pack(push)
121
201
#pragma pack(push, 1)
122
202
typedef struct {
@@ -183,7 +263,6 @@ S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params)
183
263
Perl_croak_nocontext ("Usage: CODE(0x%" UVxf ")(%s)" , PTR2UV (cv ), params );
184
264
}
185
265
}
186
- #undef PERL_ARGS_ASSERT_CROAK_XS_USAGE
187
266
188
267
#ifdef PERL_IMPLICIT_CONTEXT
189
268
#define croak_xs_usage (a ,b ) S_croak_xs_usage(aTHX_ a,b)
@@ -192,3 +271,7 @@ S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params)
192
271
#endif
193
272
194
273
#endif
274
+
275
+ #define PERL_VERSION_LE (R , V , S ) (PERL_REVISION < (R) || \
276
+ (PERL_REVISION == (R) && (PERL_VERSION < (V) ||\
277
+ (PERL_VERSION == (V) && (PERL_SUBVERSION <= (S))))))
0 commit comments