Skip to content

Commit 6f3407d

Browse files
committed
Merge branch 'winbuild'
2 parents a2d83cc + 90c0d88 commit 6f3407d

File tree

8 files changed

+118
-73
lines changed

8 files changed

+118
-73
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ tests/*.sh
7171
# coverage
7272
/coverage.info
7373
/reports
74+
win_build_scripts
75+
.vscode-win

build_scripts/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ Make sure ``git`` is in you PATH
1616
2. Set up Firebird 32-bit and 64-bit installations or libraries.
1717
3. Set up PHP-SDK according to https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2
1818
4. Clone php-firebird extension source somewhere.
19-
4. Copy these build scripts to C:\php-sdk\
2019
5. Adjust php-fb-config.bat.
21-
2220
``Note: PFB_SOURCE_DIR should point one level up. For example
2321
PFB_SOURCE_DIR=D:\php-firebird\ then your source should reside in D:\php-firebird\php-firebird\
2422
``
25-
6. Run ``php-fb-build-all.bat`` to build for all PHP versions or run ``php-fb-build.bat 7.4 vc15`` to build for particular version.
23+
6. cd into php-sdk and from there run ``<path_to>\php-fb-build-all.bat`` to build for all PHP versions or run ``php-fb-build.bat 7.4 vc15`` to build for particular version.

build_scripts/php-fb-build-all.bat

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
@echo off
22

3-
call php-fb-build.bat 7.3 vc15 || exit /B %ERRORLEVEL%
4-
call php-fb-build.bat 7.4 vc15 || exit /B %ERRORLEVEL%
5-
call php-fb-build.bat 8.0 vs16 || exit /B %ERRORLEVEL%
6-
call php-fb-build.bat 8.1 vs16 || exit /B %ERRORLEVEL%
7-
call php-fb-build.bat 8.2 vs16 || exit /B %ERRORLEVEL%
8-
call php-fb-build.bat 8.3 vs16 || exit /B %ERRORLEVEL%
9-
call php-fb-build.bat 8.4 vs17 || exit /B %ERRORLEVEL%
10-
call php-fb-build.bat master vs17 || exit /B %ERRORLEVEL%
3+
call %~dp0php-fb-build.bat php-7.3.33 vc15 || exit %ERRORLEVEL%
4+
call %~dp0php-fb-build.bat php-7.4.13 vc15 || exit %ERRORLEVEL%
5+
call %~dp0php-fb-build.bat php-8.0.30 vs16 || exit %ERRORLEVEL%
6+
call %~dp0php-fb-build.bat php-8.1.33 vs16 || exit %ERRORLEVEL%
7+
call %~dp0php-fb-build.bat php-8.2.29 vs16 || exit %ERRORLEVEL%
8+
call %~dp0php-fb-build.bat php-8.3.26 vs16 || exit %ERRORLEVEL%
9+
call %~dp0php-fb-build.bat php-8.4.13 vs17 || exit %ERRORLEVEL%
10+
call %~dp0php-fb-build.bat php-8.5.0RC2 vs17 || exit %ERRORLEVEL%

build_scripts/php-fb-build.bat

Lines changed: 80 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@echo off
22

33
@REM config ======================================================================================
4-
call php-fb-config.bat
4+
call %~dp0php-fb-config.bat
55

66
goto :MAIN
77

@@ -15,69 +15,114 @@ goto :MAIN
1515
echo ---------------------------------------------------------------------
1616
exit /B
1717

18+
@REM usage =======================================================================================
1819
:usage
19-
call :log "Usage: %~nx0 php_vers cpp_vers"
20+
call :log "Usage: %~nx0 php_tag cpp_vers"
21+
exit /B
22+
23+
@REM validate_build ===============================================================================
24+
@REM validate_build <path_to_php_exe>:string <arch>:string <ts>:int
25+
:validate_build
26+
setlocal disabledelayedexpansion
27+
set vb_php=%~1
28+
set vb_arch=%~2
29+
set vb_ts=%~3
30+
31+
set vb_check_code=^
32+
if(!extension_loaded('interbase')){ print \"Extension not loaded\n\"; exit(1); }^
33+
if('php-'.PHP_VERSION != '%pfb_php_tag%'){ printf(\"Version mismatch: expected '%pfb_php_tag%', but got '%%s' \n\", 'php-'.PHP_VERSION); exit(1); }^
34+
if((int)ZEND_THREAD_SAFE != %vb_ts%){ printf(\"Thread Safety mismatch: expected %vb_ts%, but got %%d \n\", ZEND_THREAD_SAFE); exit(1); }^
35+
if((PHP_INT_SIZE == 8 ? 'x64' : 'x86') != '%vb_arch%'){ printf(\"Architecture mismatch: expected '%vb_arch%', but got '%%s' \n\", (PHP_INT_SIZE == 8 ? 'x64' : 'x86')); exit(1); }
36+
37+
if "%vb_arch%" == "x86" (
38+
set vb_libs=%PFB_FB32_DIR%
39+
) else (
40+
set vb_libs=%PFB_FB64_DIR%
41+
)
42+
43+
call :log "Validating %pfb_php_tag% %vb_arch% Thread Safety %vb_ts%"
44+
45+
set vb_cmd=cmd /c set "PATH=%vb_libs%;%PATH%" %php_exe% -dextension=.\php_interbase.dll -r "%vb_check_code%"
46+
%vb_cmd% || exit /B 1
47+
48+
echo Validated OK
49+
echo ---------------------------------------------------------------------
50+
2051
exit /B
2152

2253
:MAIN
23-
set pfb_php_vers=%1
54+
55+
set pfb_php_tag=%1
2456
set pfb_cpp_vers=%2
2557

26-
if [%pfb_php_vers%] == [] (
58+
if "%pfb_php_tag%" == "" (
2759
call :usage
28-
echo pfb_php_vers varible not set
60+
echo pfb_php_tag varible not set
2961
exit 1
3062
)
3163

32-
if [%pfb_cpp_vers%] == [] (
64+
if "%pfb_cpp_vers%" == "" (
3365
call :usage
3466
echo pfb_cpp_vers varible not set
3567
exit 1
3668
)
3769

70+
@REM Convert php-8.4.13 -> 8.4
71+
for /f "tokens=2,3 delims=-." %%a in ("%pfb_php_tag%") do set pfb_php_vers=%%a.%%b
72+
73+
if "%pfb_php_vers%" == "" (
74+
echo BUG: pfb_php_vers should be set at this point
75+
exit 1
76+
)
77+
3878
set pfb_build_root=php%pfb_php_vers%\%pfb_cpp_vers%\
3979

40-
(for %%a in (x86 x64) do (
41-
@REM check out or pull PHP version of interest
42-
if exist %pfb_build_root%\%%a\php-src\.git\ (
43-
call :log "Checking out PHP-%pfb_php_vers% %%a"
44-
git -C %pfb_build_root%\%%a\php-src pull || goto :error
80+
(for %%a in (x64 x86) do (
81+
set pfb_arch=%%a
82+
83+
if not exist "%pfb_build_root%\%%a\php-src\.git\" (
84+
call :log "Cloning %pfb_php_tag% %%a"
85+
call phpsdk-%pfb_cpp_vers%-%%a.bat -t %~dp0php-fb-sdk-init.bat || goto :error
86+
)
87+
88+
if "%%a" == "x86" (
89+
set php_exe_arch=%pfb_build_root%%%a\php-src\
4590
) else (
46-
call :log "Cloning PHP-%pfb_php_vers% %%a"
47-
call phpsdk-%pfb_cpp_vers%-%%a.bat -t php-fb-sdk-init.bat || goto :error
91+
set php_exe_arch=%pfb_build_root%%%a\php-src\x64\
4892
)
4993

50-
if %%a EQU x86 ( set pfb_x86=1 ) else ( set pfb_x86=0 )
94+
setlocal enabledelayedexpansion
95+
(for %%t in (0 1) do (
96+
set pfb_ts=%%t
97+
if "%%t" equ "1" (
98+
set php_exe="!php_exe_arch!Release_TS\php.exe"
99+
) else (
100+
set php_exe="!php_exe_arch!Release\php.exe"
101+
)
51102

52-
(for %%n in (0 1) do (
53-
set pfb_nts=%%n
54-
call phpsdk-%pfb_cpp_vers%-%%a.bat -t php-fb-sdk-build.bat || goto :error
55-
))
56-
))
103+
if "!php_exe!" == "" (
104+
echo BUG: php_exe should be set at this point
105+
exit 1
106+
)
57107

58-
@REM check if ibase_connect() function exists in newly compiled extension
59-
set check_code="if(!function_exists('ibase_connect'))exit(1);"
108+
call phpsdk-%pfb_cpp_vers%-%%a.bat -t %~dp0php-fb-sdk-build.bat || goto :error
60109

61-
set TPATH=%PATH%
62-
set PATH=%FB64_DIR%;%TPATH%
63-
"%pfb_build_root%x64\php-src\x64\Release_TS\php.exe" -dextension=.\php_interbase.dll -r %check_code% || goto :error
64-
"%pfb_build_root%x64\php-src\x64\Release\php.exe" -dextension=.\php_interbase.dll -r %check_code% || goto :error
65-
set PATH=%FB32_DIR%;%TPATH%
66-
"%pfb_build_root%x86\php-src\Release_TS\php.exe" -dextension=.\php_interbase.dll -r %check_code% || goto :error
67-
"%pfb_build_root%x86\php-src\Release\php.exe" -dextension=.\php_interbase.dll -r %check_code% || goto :error
68-
set PATH=%TPATH%
110+
call :validate_build !php_exe! !pfb_arch! !pfb_ts! || goto :error
111+
))
112+
))
69113

70-
call :log "PHP %pfb_php_vers% build OK"
114+
echo.
115+
call :log "%pfb_php_tag% build OK"
71116

72117
@REM copy compiled extension to target directory
73-
copy %pfb_build_root%x64\php-src\x64\Release_TS\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%-x86_64.dll>nul
74-
copy %pfb_build_root%x64\php-src\x64\Release\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%-nts-x86_64.dll>nul
75-
copy %pfb_build_root%x86\php-src\Release_TS\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%.dll>nul
76-
copy %pfb_build_root%x86\php-src\Release\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%-nts.dll>nul
118+
copy %pfb_build_root%x64\php-src\x64\Release_TS\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%-x64.dll
119+
copy %pfb_build_root%x64\php-src\x64\Release\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%-nts-x64.dll
120+
copy %pfb_build_root%x86\php-src\Release_TS\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%.dll
121+
copy %pfb_build_root%x86\php-src\Release\php_interbase.dll %PFB_OUTPUT_DIR%php_interbase-%PFB_VERS%-%pfb_php_vers%-%pfb_cpp_vers%-nts.dll
77122

78123
exit /B 0
79124

80125
:error
81-
call :log "PHP %pfb_php_vers% build FAILED"
126+
call :log "%pfb_php_tag% build FAILED"
82127

83128
exit /B 1

build_scripts/php-fb-config.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ set PFB_VERS=3.0.1-%GIT_HASH%
1414
set PFB_OUTPUT_DIR=D:\php-firebird\releases\
1515

1616
@REM FB 32-bit and 64-bit libraries
17-
set FB32_DIR=C:\Program Files\Firebird\Firebird_5_0-x86
18-
set FB64_DIR=C:\Program Files\Firebird\Firebird_5_0
17+
set PFB_FB32_DIR=C:\Program Files\Firebird\Firebird_5_0-x86
18+
set PFB_FB64_DIR=C:\Program Files\Firebird\Firebird_5_0

build_scripts/php-fb-sdk-build.bat

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
@REM Must be called under phpsdk-<php_vers>-<arch>.bat
44
@REM
55
@REM Calling script should set variables:
6-
@REM <FB32_DIR> <FB64_DIR> <PFB_SOURCE_DIR> <pfb_php_vers> [pfb_nts] [pfb_x86]
6+
@REM <PFB_FB32_DIR> <PFB_FB64_DIR> <PFB_SOURCE_DIR> <pfb_php_vers> [pfb_ts] [pfb_arch]
77
@REM
88
@REM set pfb_php_vers=7.4
9-
@REM set pfb_nts=1 if nts expected, 0 if ts
10-
@REM set pfb_x86=1 if linking to x86 fbclient, o if x64
9+
@REM set pfb_ts=1 if thread safety enabled, 0 if not
10+
@REM set pfb_arch=x86 to build agains 32-bit, otherwise 64-bit
1111
@REM
12-
@REM <FB32_DIR> <FB64_DIR> <PFB_SOURCE_DIR> all set in php-fb-config.bat
12+
@REM <PFB_FB32_DIR> <PFB_FB64_DIR> <PFB_SOURCE_DIR> all set in php-fb-config.bat
1313
@REM
1414

1515
goto :MAIN
@@ -25,26 +25,26 @@ goto :MAIN
2525
exit /B
2626

2727
:MAIN
28-
if [%pfb_php_vers%] == [] (
28+
if "%pfb_php_vers%" == "" (
2929
echo pfb_php_vers varible not set
3030
exit 1
3131
)
3232

3333
set build_msg=Building PHP-%pfb_php_vers%
3434

35-
if "%pfb_nts%" gtr "0" (
35+
if "%pfb_ts%" gtr "0" (
3636
set build_msg=%build_msg% non-TS
3737
set extra_args=--disable-zts
3838
) else (
3939
set build_msg=%build_msg% TS
4040
set extra_args=
4141
)
4242

43-
if "%pfb_x86%" gtr "0" (
44-
set with_interbase="shared,%FB32_DIR%"
43+
if "%pfb_arch%" == "x86" (
44+
set with_interbase="shared,%PFB_FB32_DIR%"
4545
set build_msg=%build_msg% x86
4646
) else (
47-
set with_interbase="shared,%FB64_DIR%"
47+
set with_interbase="shared,%PFB_FB64_DIR%"
4848
set build_msg=%build_msg% x86_64
4949
)
5050

build_scripts/php-fb-sdk-init.bat

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22
@REM
33
@REM Must be called under phpsdk-<php_vers>-<arch>.bat
44
@REM
5-
@REM Calling script should set variables: <pfb_php_vers>
5+
@REM Calling script should set variables: <pfb_php_vers> <pfb_php_tag>
66
@REM
7-
@REM set pfb_php_vers=7.4
7+
@REM Example: pfb_php_tag=7.4.13
8+
@REM Example: pfb_php_vers=7.4
89

9-
if [%pfb_php_vers%] == [] (
10+
if "%pfb_php_vers%" == "" (
1011
echo pfb_php_vers varible not set
1112
exit 1
1213
)
1314

14-
@REM Handle current master branch
15-
if "%pfb_php_vers%" == "master" (
16-
set pfb_git_args=
17-
) else (
18-
set pfb_git_args=--branch PHP-%pfb_php_vers%
15+
if "%pfb_php_tag%" == "" (
16+
echo pfb_php_tag varible not set
17+
exit 1
1918
)
2019

2120
call phpsdk_buildtree php%pfb_php_vers%
22-
git clone --depth 1 %pfb_git_args% https://github.com/php/php-src.git
21+
git clone --depth 1 --branch %pfb_php_tag% https://github.com/php/php-src.git
2322
cd php-src
2423

2524
@REM Remove built-in extension

ibase_service.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,20 +210,21 @@ PHP_FUNCTION(ibase_delete_user)
210210
}
211211
/* }}} */
212212

213-
/* {{{ proto resource ibase_service_attach(string host, string dba_username, string dba_password)
213+
/* {{{ proto resource ibase_service_attach([string host [, string dba_username [, string dba_password]]])
214214
Connect to the service manager */
215215
PHP_FUNCTION(ibase_service_attach)
216216
{
217217
size_t hlen = 0, ulen = 0, plen = 0;
218218
ibase_service *svm;
219-
char buf[350], *host, *user, *pass;
219+
char *host = NULL, *user = NULL, *pass = NULL;
220+
char buf[350];
220221
char loc[128] = "service_mgr";
221222
isc_svc_handle handle = 0;
222223
unsigned short p = 0;
223224

224225
RESET_ERRMSG;
225226

226-
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|sss",
227+
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!s!",
227228
&host, &hlen, &user, &ulen, &pass, &plen)) {
228229

229230
RETURN_FALSE;
@@ -251,14 +252,14 @@ PHP_FUNCTION(ibase_service_attach)
251252
if(ulen > 0){
252253
buf[p++] = isc_spb_user_name;
253254
buf[p++] = (char)ulen;
254-
memcpy(&buf[p], &user, ulen);
255+
memcpy(&buf[p], user, ulen);
255256
p += ulen;
256257
}
257258

258259
if(plen > 0){
259260
buf[p++] = isc_spb_password;
260261
buf[p++] = (char)plen;
261-
memcpy(&buf[p], &pass, plen);
262+
memcpy(&buf[p], pass, plen);
262263
p += plen;
263264
}
264265

@@ -274,8 +275,8 @@ PHP_FUNCTION(ibase_service_attach)
274275

275276
svm = (ibase_service*)emalloc(sizeof(ibase_service));
276277
svm->handle = handle;
277-
svm->hostname = estrdup(host);
278-
svm->username = estrdup(user);
278+
svm->hostname = hlen > 0 ? estrdup(host) : NULL;
279+
svm->username = ulen > 0 ? estrdup(user) : NULL;
279280

280281
RETVAL_RES(zend_register_resource(svm, le_service));
281282
Z_TRY_ADDREF_P(return_value);

0 commit comments

Comments
 (0)