Skip to content
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

Migrate ext/dba resources to objects #14239

Merged
merged 5 commits into from
May 17, 2024
Merged

Conversation

kocsismate
Copy link
Member

@kocsismate
Copy link
Member Author

kocsismate commented May 15, 2024

We'll be in trouble with the libxml_get_external_entity_loader_error_callback_name.phpt test soon as the number of resources is shrinking ^^

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a cursory look, as I'm not on my main desktop so don't have all the DBA drivers install, can test it early next week.

Some questions:

  • Wasn't there a request for it to implement cast to int?
  • Is it really necessary to keep the persistent resource?

Maybe @nielsdos also wants to have a look as they reviewed the ODBC PR.

Comment on lines +19 to +21
$descriptors = [["pty"], ["pty"], ["pty"], ["pipe", "w"]];
$pipes = [];
return proc_open('echo "foo";', $descriptors, $pipes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if it makes sense to create a resource in ext/zend_test for those sorts of purposes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Gina, I'd use zend_test for this unless that would be too cumbersome.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a dedicated test-only resource is our last resort as soon as we run out of regular non-stream resources. Until 9.0, we are fine with proc_open(), so I'd postpone this hassle until then, if you are ok with it.

Comment on lines +564 to +567
char *resource_key;
size_t resource_key_len = spprintf(&resource_key, 0,
"dba_%d_%s_%s_%s", persistent, ZSTR_VAL(path), ZSTR_VAL(mode), handler_str ? ZSTR_VAL(handler_str) : ""
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not strpprintf()/zend_strpprintf() to get a zend_string directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy-pasted this piece of code from ext/odbc :) But I didn't really know about these APIs to be honest, so that's the main reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW we sometimes need to create persistent strings, which this API doesn't support as far as I saw, so at the end of the day, we would have to create a new zend_string in any case when dealing with persistent resources.

ext/dba/dba.c Outdated
Comment on lines 592 to 594
zend_hash_add_new(&DBA_G(connections), connection->hash, return_value);
FREE_RESOURCE_KEY();
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused here, can't we get rid of the persistent resource by storing the pointer for the DBH in the zval instead of the constructed object?

@nielsdos
Copy link
Member

I can't have a proper look today, maybe tomorrow.

@kocsismate
Copy link
Member Author

I can't have a proper look today, maybe tomorrow.

Ah, that's still more than sufficient :) I appreciate your help!

@kocsismate
Copy link
Member Author

Wasn't there a request for it to implement cast to int?

Oh yes, thanks for reminding me. I'll create a followup for odbc as well.

Is it really necessary to keep the persistent resource?

Hmm, I don't know what the proper way would be to migrate persistent resources would be... For now, I went with the usual implementation. But I'm fine to do followups if we come up with a universal solution.

Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only have nits. Looks good overall.
I tested with GDBM.

ext/dba/dba.c Outdated
@@ -469,13 +521,12 @@ static zend_always_inline zend_string *php_dba_zend_string_dup_safe(zend_string
}


#define FREE_PERSISTENT_RESOURCE_KEY() if (persistent_resource_key) {zend_string_release_ex(persistent_resource_key, false);}
#define FREE_RESOURCE_KEY() efree(resource_key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this macro.

ext/dba/dba.c Outdated
if ((le = zend_hash_index_find_ptr(&EG(regular_list), i)) == NULL) {
continue;
zval *zv;
ZEND_HASH_FOREACH_VAL(&DBA_G(connections), zv) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the keys in the connections HashTable are all strings, the underlying structure will be an actual hashmap.
So you can use ZEND_HASH_MAP_FOREACH_VAL for better looping performance and better code compaction.
The same holds for other loops over the connections able too.

ext/dba/dba.c Outdated
}
*/
static zend_class_entry *dba_connection_ce;
static zend_object_handlers dba_connection_object_handlers;
/* }}} */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dangling }}} folding marker that may be removed.

ext/dba/dba.c Outdated
}
*/
static zend_class_entry *dba_connection_ce;
static zend_object_handlers dba_connection_object_handlers;
/* }}} */

/* {{{ dba_close */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dangling folding marker that may be removed.

@kocsismate kocsismate merged commit 2097237 into php:master May 17, 2024
10 checks passed
@kocsismate kocsismate deleted the dba-resource branch May 17, 2024 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants