Skip to content

Commit f2ff235

Browse files
committed
Drop some unnecessary comparisons as NIL == 0
1 parent f2ce544 commit f2ff235

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

ext/imap/php_imap.c

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,12 @@ PHP_MINFO_FUNCTION(imap)
704704
PHP_FUNCTION(imap_open)
705705
{
706706
zend_string *mailbox, *user, *passwd;
707-
zend_long retries = 0, flags = NIL, cl_flags = NIL;
707+
zend_long retries = 0, flags = 0, cl_flags = 0;
708708
MAILSTREAM *imap_stream;
709709
pils *imap_le_struct;
710710
HashTable *params = NULL;
711-
int argc = ZEND_NUM_ARGS();
712711

713-
if (zend_parse_parameters(argc, "PSS|llh", &mailbox, &user, &passwd, &flags, &retries, &params) == FAILURE) {
712+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "PSS|llh", &mailbox, &user, &passwd, &flags, &retries, &params) == FAILURE) {
714713
RETURN_THROWS();
715714
}
716715

@@ -726,7 +725,7 @@ PHP_FUNCTION(imap_open)
726725
RETURN_THROWS();
727726
}
728727

729-
if (argc >= 4) {
728+
if (flags) {
730729
if (flags & PHP_EXPUNGE) {
731730
cl_flags = CL_EXPUNGE;
732731
flags ^= PHP_EXPUNGE;
@@ -795,7 +794,7 @@ PHP_FUNCTION(imap_open)
795794
IMAPG(imap_password) = estrndup(ZSTR_VAL(passwd), ZSTR_LEN(passwd));
796795

797796
#ifdef SET_MAXLOGINTRIALS
798-
if (argc >= 5) {
797+
if (retries) {
799798
mail_parameters(NIL, SET_MAXLOGINTRIALS, (void *) retries);
800799
}
801800
#endif
@@ -1168,7 +1167,6 @@ PHP_FUNCTION(imap_close)
11681167
pils *imap_le_struct=NULL;
11691168
zend_long options = 0, flags = NIL;
11701169

1171-
/* TODO Change options to a boolean expunge flag? As it is the only valid flag. */
11721170
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &streamind, &options) == FAILURE) {
11731171
RETURN_THROWS();
11741172
}
@@ -1258,11 +1256,11 @@ PHP_FUNCTION(imap_body)
12581256
zval *streamind;
12591257
zend_long msgno, flags = 0;
12601258
pils *imap_le_struct;
1261-
int msgindex, argc = ZEND_NUM_ARGS();
1259+
int msgindex;
12621260
char *body;
12631261
unsigned long body_len = 0;
12641262

1265-
if (zend_parse_parameters(argc, "rl|l", &streamind, &msgno, &flags) == FAILURE) {
1263+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &streamind, &msgno, &flags) == FAILURE) {
12661264
RETURN_THROWS();
12671265
}
12681266

@@ -1293,7 +1291,7 @@ PHP_FUNCTION(imap_body)
12931291
PHP_IMAP_CHECK_MSGNO(msgindex, 2);
12941292

12951293
/* TODO Shouldn't this pass msgindex??? */
1296-
body = mail_fetchtext_full (imap_le_struct->imap_stream, msgno, &body_len, (argc == 3 ? flags : NIL));
1294+
body = mail_fetchtext_full (imap_le_struct->imap_stream, msgno, &body_len, flags);
12971295
if (body_len == 0) {
12981296
RETVAL_EMPTY_STRING();
12991297
} else {
@@ -1308,10 +1306,9 @@ PHP_FUNCTION(imap_mail_copy)
13081306
zval *streamind;
13091307
zend_long options = 0;
13101308
zend_string *seq, *folder;
1311-
int argc = ZEND_NUM_ARGS();
13121309
pils *imap_le_struct;
13131310

1314-
if (zend_parse_parameters(argc, "rSS|l", &streamind, &seq, &folder, &options) == FAILURE) {
1311+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|l", &streamind, &seq, &folder, &options) == FAILURE) {
13151312
RETURN_THROWS();
13161313
}
13171314

@@ -1324,7 +1321,7 @@ PHP_FUNCTION(imap_mail_copy)
13241321
RETURN_THROWS();
13251322
}
13261323

1327-
if (mail_copy_full(imap_le_struct->imap_stream, ZSTR_VAL(seq), ZSTR_VAL(folder), (argc == 4 ? options : NIL)) == T) {
1324+
if (mail_copy_full(imap_le_struct->imap_stream, ZSTR_VAL(seq), ZSTR_VAL(folder), options) == T) {
13281325
RETURN_TRUE;
13291326
} else {
13301327
RETURN_FALSE;
@@ -1339,9 +1336,8 @@ PHP_FUNCTION(imap_mail_move)
13391336
zend_string *seq, *folder;
13401337
zend_long options = 0;
13411338
pils *imap_le_struct;
1342-
int argc = ZEND_NUM_ARGS();
13431339

1344-
if (zend_parse_parameters(argc, "rSS|l", &streamind, &seq, &folder, &options) == FAILURE) {
1340+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|l", &streamind, &seq, &folder, &options) == FAILURE) {
13451341
RETURN_THROWS();
13461342
}
13471343

@@ -1354,7 +1350,10 @@ PHP_FUNCTION(imap_mail_move)
13541350
RETURN_THROWS();
13551351
}
13561352

1357-
if (mail_copy_full(imap_le_struct->imap_stream, ZSTR_VAL(seq), ZSTR_VAL(folder), (argc == 4 ? (options | CP_MOVE) : CP_MOVE)) == T) {
1353+
/* Add CP_MOVE flag */
1354+
options = (options | CP_MOVE);
1355+
1356+
if (mail_copy_full(imap_le_struct->imap_stream, ZSTR_VAL(seq), ZSTR_VAL(folder), options) == T) {
13581357
RETURN_TRUE;
13591358
} else {
13601359
RETURN_FALSE;
@@ -1592,9 +1591,8 @@ PHP_FUNCTION(imap_delete)
15921591
pils *imap_le_struct;
15931592
zend_string *sequence;
15941593
zend_long flags = 0;
1595-
int argc = ZEND_NUM_ARGS();
15961594

1597-
if (zend_parse_parameters(argc, "rS|l", &streamind, &sequence, &flags) == FAILURE) {
1595+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS|l", &streamind, &sequence, &flags) == FAILURE) {
15981596
RETURN_THROWS();
15991597
}
16001598

@@ -1607,7 +1605,7 @@ PHP_FUNCTION(imap_delete)
16071605
RETURN_THROWS();
16081606
}
16091607

1610-
mail_setflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), "\\DELETED", (argc == 3 ? flags : NIL));
1608+
mail_setflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), "\\DELETED", flags);
16111609
RETVAL_TRUE;
16121610
}
16131611
/* }}} */
@@ -1619,9 +1617,8 @@ PHP_FUNCTION(imap_undelete)
16191617
zend_string *sequence;
16201618
zend_long flags = 0;
16211619
pils *imap_le_struct;
1622-
int argc = ZEND_NUM_ARGS();
16231620

1624-
if (zend_parse_parameters(argc, "rS|l", &streamind, &sequence, &flags) == FAILURE) {
1621+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS|l", &streamind, &sequence, &flags) == FAILURE) {
16251622
RETURN_THROWS();
16261623
}
16271624

@@ -1631,7 +1628,9 @@ PHP_FUNCTION(imap_undelete)
16311628

16321629
/* TODO Check if flags are valid (documentation is not present on php.net so need to check this first) */
16331630

1634-
mail_clearflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), "\\DELETED", (argc == 3 ? flags : NIL));
1631+
mail_clearflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), "\\DELETED", flags);
1632+
1633+
// TODO Return void?
16351634
RETVAL_TRUE;
16361635
}
16371636
/* }}} */
@@ -1928,9 +1927,8 @@ PHP_FUNCTION(imap_fetchbody)
19281927
char *body;
19291928
zend_string *sec;
19301929
unsigned long len;
1931-
int argc = ZEND_NUM_ARGS();
19321930

1933-
if (zend_parse_parameters(argc, "rlS|l", &streamind, &msgno, &sec, &flags) == FAILURE) {
1931+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlS|l", &streamind, &msgno, &sec, &flags) == FAILURE) {
19341932
RETURN_THROWS();
19351933
}
19361934

@@ -1953,7 +1951,7 @@ PHP_FUNCTION(imap_fetchbody)
19531951
PHP_IMAP_CHECK_MSGNO(msgno, 2);
19541952
}
19551953

1956-
body = mail_fetchbody_full(imap_le_struct->imap_stream, msgno, ZSTR_VAL(sec), &len, (argc == 4 ? flags : NIL));
1954+
body = mail_fetchbody_full(imap_le_struct->imap_stream, msgno, ZSTR_VAL(sec), &len, flags);
19571955

19581956
if (!body) {
19591957
php_error_docref(NULL, E_WARNING, "No body information available");
@@ -1974,9 +1972,8 @@ PHP_FUNCTION(imap_fetchmime)
19741972
char *body;
19751973
zend_string *sec;
19761974
unsigned long len;
1977-
int argc = ZEND_NUM_ARGS();
19781975

1979-
if (zend_parse_parameters(argc, "rlS|l", &streamind, &msgno, &sec, &flags) == FAILURE) {
1976+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlS|l", &streamind, &msgno, &sec, &flags) == FAILURE) {
19801977
RETURN_THROWS();
19811978
}
19821979

@@ -1999,7 +1996,7 @@ PHP_FUNCTION(imap_fetchmime)
19991996
PHP_IMAP_CHECK_MSGNO(msgno, 2);
20001997
}
20011998

2002-
body = mail_fetch_mime(imap_le_struct->imap_stream, msgno, ZSTR_VAL(sec), &len, (argc == 4 ? flags : NIL));
1999+
body = mail_fetch_mime(imap_le_struct->imap_stream, msgno, ZSTR_VAL(sec), &len, flags);
20032000

20042001
if (!body) {
20052002
php_error_docref(NULL, E_WARNING, "No body MIME information available");
@@ -2673,9 +2670,8 @@ PHP_FUNCTION(imap_clearflag_full)
26732670
zend_string *sequence, *flag;
26742671
zend_long flags = 0;
26752672
pils *imap_le_struct;
2676-
int argc = ZEND_NUM_ARGS();
26772673

2678-
if (zend_parse_parameters(argc, "rSS|l", &streamind, &sequence, &flag, &flags) ==FAILURE) {
2674+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|l", &streamind, &sequence, &flag, &flags) ==FAILURE) {
26792675
RETURN_THROWS();
26802676
}
26812677

@@ -2688,7 +2684,7 @@ PHP_FUNCTION(imap_clearflag_full)
26882684
RETURN_THROWS();
26892685
}
26902686

2691-
mail_clearflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), ZSTR_VAL(flag), (argc == 4 ? flags : NIL));
2687+
mail_clearflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), ZSTR_VAL(flag), flags);
26922688
RETURN_TRUE;
26932689
}
26942690
/* }}} */
@@ -2739,7 +2735,7 @@ PHP_FUNCTION(imap_sort)
27392735
mypgm->function = (short) sort;
27402736
mypgm->next = NIL;
27412737

2742-
slst = mail_sort(imap_le_struct->imap_stream, (argc == 6 ? ZSTR_VAL(charset) : NIL), spg, mypgm, (argc >= 4 ? flags : NIL));
2738+
slst = mail_sort(imap_le_struct->imap_stream, (argc == 6 ? ZSTR_VAL(charset) : NIL), spg, mypgm, flags);
27432739

27442740
if (spg && !(flags & SE_FREE)) {
27452741
mail_free_searchpgm(&spg);

0 commit comments

Comments
 (0)