Skip to content

Commit 4b782f1

Browse files
author
Gal Ben David
committed
- replace FASTCALL calling convention with METH_O to support pypy
1 parent 98853c0 commit 4b782f1

File tree

1 file changed

+9
-30
lines changed

1 file changed

+9
-30
lines changed

src/pydomainextractor.cpp

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,9 @@ PyObject * domain_key_py = PyUnicode_FromString("domain");
324324
PyObject * suffix_key_py = PyUnicode_FromString("suffix");
325325
static PyObject * DomainExtractor_extract(
326326
DomainExtractorObject * self,
327-
PyObject * const* args,
328-
Py_ssize_t nargs
327+
PyObject * arg
329328
) {
330-
if (nargs != 1) {
331-
PyErr_SetString(PyExc_ValueError, "wrong number of arguments");
332-
333-
return NULL;
334-
}
335-
336-
const char * input = PyUnicode_AsUTF8(args[0]);
329+
const char * input = PyUnicode_AsUTF8(arg);
337330

338331
try {
339332
auto extracted_domain = self->domain_extractor->extract(input);
@@ -387,16 +380,9 @@ static PyObject * DomainExtractor_extract(
387380

388381
static PyObject * DomainExtractor_extract_from_url(
389382
DomainExtractorObject * self,
390-
PyObject * const* args,
391-
Py_ssize_t nargs
383+
PyObject * arg
392384
) {
393-
if (nargs != 1) {
394-
PyErr_SetString(PyExc_ValueError, "wrong number of arguments");
395-
396-
return NULL;
397-
}
398-
399-
const char * input = PyUnicode_AsUTF8(args[0]);
385+
const char * input = PyUnicode_AsUTF8(arg);
400386
std::string_view url(input);
401387

402388
std::size_t scheme_separator_position = url.find("//");
@@ -475,16 +461,9 @@ static PyObject * DomainExtractor_extract_from_url(
475461

476462
static PyObject * DomainExtractor_is_valid_domain(
477463
DomainExtractorObject * self,
478-
PyObject * const* args,
479-
Py_ssize_t nargs
464+
PyObject * arg
480465
) {
481-
if (nargs != 1) {
482-
PyErr_SetString(PyExc_ValueError, "wrong number of arguments");
483-
484-
return NULL;
485-
}
486-
487-
const char * input = PyUnicode_AsUTF8(args[0]);
466+
const char * input = PyUnicode_AsUTF8(arg);
488467

489468
auto valid_domain = self->domain_extractor->is_valid_domain(std::string(input));
490469
if (valid_domain == true) {
@@ -514,19 +493,19 @@ static PyMethodDef DomainExtractor_methods[] = {
514493
{
515494
"extract",
516495
(PyCFunction)DomainExtractor_extract,
517-
METH_FASTCALL,
496+
METH_O,
518497
"Extract a domain string into its parts\n\nextract(domain)\nArguments:\n\tdomain(str): the domain string to extract\nReturn:\n\tdict[str, str] -> The extracted parts as 'subdomain', 'domain', 'suffix'\n\n"
519498
},
520499
{
521500
"extract_from_url",
522501
(PyCFunction)DomainExtractor_extract_from_url,
523-
METH_FASTCALL,
502+
METH_O,
524503
"Extract a domain from a url into its parts\n\nextract_from_url(url)\nArguments:\n\turl(str): the url string to extract\nReturn:\n\tdict[str, str] -> The extracted parts as 'subdomain', 'domain', 'suffix'\n\n"
525504
},
526505
{
527506
"is_valid_domain",
528507
(PyCFunction)DomainExtractor_is_valid_domain,
529-
METH_FASTCALL,
508+
METH_O,
530509
"Checks whether a domain is a valid domain\n\nis_valid_domain(domain)\nArguments:\n\tdomain(str): the domain string to validate\nReturn:\n\tbool: True if valid or False if invalid\n\n"
531510
},
532511
{

0 commit comments

Comments
 (0)