Skip to content

Fix GH-8750: Can not create VT_ERROR variant type #8840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/com_dotnet/com_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@
#define PHP_DISP_E_DIVBYZERO ((zend_long) (ULONG) DISP_E_DIVBYZERO)
#define PHP_DISP_E_OVERFLOW ((zend_long) (ULONG) DISP_E_OVERFLOW)
#define PHP_DISP_E_BADINDEX ((zend_long) (ULONG) DISP_E_BADINDEX)
#define PHP_DISP_E_PARAMNOTFOUND ((zend_long) (ULONG) DISP_E_PARAMNOTFOUND)
#define PHP_MK_E_UNAVAILABLE ((zend_long) (ULONG) MK_E_UNAVAILABLE)
#else
#define PHP_DISP_E_DIVBYZERO DISP_E_DIVBYZERO
#define PHP_DISP_E_OVERFLOW DISP_E_OVERFLOW
#define PHP_DISP_E_BADINDEX DISP_E_BADINDEX
#define PHP_DISP_E_PARAMNOTFOUND DISP_E_PARAMNOTFOUND
#define PHP_MK_E_UNAVAILABLE MK_E_UNAVAILABLE
#endif

Expand Down
6 changes: 6 additions & 0 deletions ext/com_dotnet/com_extension.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@
* @cname PHP_DISP_E_BADINDEX
*/
const DISP_E_BADINDEX = UNKNOWN;
/**
* @var int
* @cname PHP_DISP_E_PARAMNOTFOUND
*/
const DISP_E_PARAMNOTFOUND = UNKNOWN;
/**
* @var int
* @cname PHP_MK_E_UNAVAILABLE
Expand Down Expand Up @@ -351,6 +356,7 @@ function com_load_typelib(string $typelib, bool $case_insensitive = true): bool
class variant
{
public function __construct(mixed $value = null, int $type = VT_EMPTY, int $codepage = CP_ACP) {}
public static function createError(int $scode): variant {}
}

class com extends variant
Expand Down
9 changes: 8 additions & 1 deletion ext/com_dotnet/com_extension_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions ext/com_dotnet/com_variant.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,21 @@ PHP_METHOD(variant, __construct)
}
/* }}} */

PHP_METHOD(variant, createError)
{
zend_long scode;
VARIANT vres;

if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &scode)) {
RETURN_THROWS();
}

VariantInit(&vres);
V_VT(&vres) = VT_ERROR;
V_ERROR(&vres) = scode;
php_com_wrap_variant(return_value, &vres, CP_ACP);
}

/* {{{ Assigns a new value for a variant object */
PHP_FUNCTION(variant_set)
{
Expand Down
47 changes: 47 additions & 0 deletions ext/com_dotnet/tests/gh8750.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--TEST--

--EXTENSIONS--
com_dotnet
--SKIPIF--
<?php
$provider = "Microsoft.ACE.OLEDB.12.0";
$filename = __DIR__ . "\\gh8750.mdb";
$catalog = new com("ADOX.Catalog");
try {
$catalog->Create("Provider=$provider;Data Source=$filename");
} catch (com_exception) {
die("skip $provider provider not available");
}
$catalog = null;
@unlink($filename);
?>
--FILE--
<?php
$filename = __DIR__ . "\\gh8750.mdb";

$catalog = new com("ADOX.Catalog");
$catalog->Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$filename");
$catalog = null;

$db = new com("ADODB.Connection");
$db->ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$filename";
$db->Mode = 1; // adModeRead
$db->Open();
// adSchemaProviderSpecific, *missing*, JET_SCHEMA_USERROSTER
$rs = $db->OpenSchema(-1, variant::createError(DISP_E_PARAMNOTFOUND), "{947bb102-5d43-11d1-bdbf-00c04fb92675}");
// manual counting since rs.RecordCount is -1 (not supported)
$i = 0;
while (!$rs->EOF) {
$rs->MoveNext();
$i++;
}
$rs->Close();
$db->Close();
var_dump($i);
?>
--EXPECT--
int(1)
--CLEAN--
<?php
unlink(__DIR__ . "/gh8750.mdb");
?>