Skip to content

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jul 24, 2016

From the sqlite3_open docs:

| If the filename is an empty string, then a private, temporary on-disk
| database will be created. This private database will be automatically
| deleted as soon as the database connection is closed.

We make that facility available to userland.

From the [sqlite3_open](https://www.sqlite.org/c3ref/open.html) docs:

| If the filename is an empty string, then a private, temporary on-disk
| database will be created. This private database will be automatically
| deleted as soon as the database connection is closed.

We make that facility available to userland.
@cmb69
Copy link
Member Author

cmb69 commented Jul 25, 2016

The failing checks are unrelated to this PR.

@KalleZ
Copy link
Member

KalleZ commented Jul 27, 2016

Seems like a fairly small self contained case, could probably be merged to at least 7.0, maybe even 5.6.

cc @weltling @jpauli

@@ -117,7 +117,10 @@ PHP_METHOD(sqlite3, open)
if (strlen(filename) != filename_len) {
return;
}
if (filename_len != sizeof(":memory:")-1 ||
if (filename_len == 0) {
fullpath = emalloc(1);
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 fullpath = NULL here ?
Would work, and prevent a one byte allocation.

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 agree that the emalloc(1) is silly, but I'm not sure that fullpath = NULL would work (it does now, but that might be an implementation detail). The SQLite3 docs say "empty filename".

What about using a stack allocated empty string instead?

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, but you'll have to track that to be sure not to free it.
Otherwise : change the whole code to use a stack allocated buffer instead of a heap allocated one ;-)

@jpauli
Copy link
Member

jpauli commented Jul 27, 2016

Yep, OK to merge that in 5.6 and 7.0 once comments are addressed

@cmb69
Copy link
Member Author

cmb69 commented Jul 27, 2016

The issue with emalloc(1) should be solved now. I can "merge" later to PHP 5.6+.

@jpauli
Copy link
Member

jpauli commented Jul 27, 2016

Great 👍

@nikic
Copy link
Member

nikic commented Jul 27, 2016

Imho empty_string is an unnecessary microoptimization, it just makes the code dirty.

@nikic
Copy link
Member

nikic commented Jul 27, 2016

If we're going down that route lets make it generic and cover :memory: as well, by setting fullpath = filename and checking for that.

@cmb69
Copy link
Member Author

cmb69 commented Jul 27, 2016

Imho empty_string is an unnecessary microoptimization, it just makes the code dirty.

Okay, so we either want only the first or all three commits.

@@ -117,8 +117,8 @@ PHP_METHOD(sqlite3, open)
if (strlen(filename) != filename_len) {
return;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Can't this if be removed as were ZPP'ing for p (not s) anyway?

Copy link
Member

@jpauli jpauli Jul 27, 2016

Choose a reason for hiding this comment

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

I would say yes, it can be removed.

Also, why not use a "P" , to be given a zend_string ? Just a small refactor, zend_string should really be prefered over C strings as much as possible.
The comparaisons would then use zend_string_equals_literal().
I can patch it if you want

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, why not use a "P" , to be given a zend_string ?

AIUI, that would be PHP 7 only.

I can patch it if you want.

Yes, go for it. :-)

Copy link
Member

Choose a reason for hiding this comment

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

Separate PR then, as it will obviously be PHP 7 only ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I'll commit this one first to PHP 5.6+.

@@ -114,11 +114,8 @@ PHP_METHOD(sqlite3, open)
zend_throw_exception(zend_ce_exception, "Already initialised DB Object", 0);
Copy link
Member

Choose a reason for hiding this comment

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

It's unrelated to this PR, but there's a return missing here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I'll fix it as well.

@php-pulls
Copy link

Comment on behalf of cmb at php.net:

"Merged" with cc125f2.

@php-pulls php-pulls closed this Jul 27, 2016
@cmb69 cmb69 deleted the sqlite3-open-empty branch September 7, 2016 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants